Skip to content

Commit

Permalink
Fix dryrun bug when verifying multiple contracts
Browse files Browse the repository at this point in the history
This fix needs to be applied into the `server` service,
hence we apply a patch to do so.
Moreover, a test case has been included to assert the fix works
properly.

Signed-off-by: Luis Mastrangelo <[email protected]>
  • Loading branch information
acuarica committed May 21, 2024
1 parent 750cfb7 commit 252223b
Show file tree
Hide file tree
Showing 6 changed files with 8,154 additions and 7 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: 18
- name: Apply Sourcify patch customizations
run: npm run sourcify:patch

- name: Compile Sourcify server
working-directory: ./sourcify
run: |
Expand All @@ -31,10 +34,12 @@ jobs:
- uses: actions/checkout@v3
with:
submodules: true

- uses: actions/setup-node@v3
with:
node-version: 18
- name: Apply Sourcify patch customizations
run: npm run sourcify:patch

- run: npm ci

- name: Start Hedera Local Node
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"scripts": {
"test:server": "mocha test/server.test.js --exit",
"test:hedera": "mocha test/hedera.test.js --exit",
"sourcify:patch": "cd sourcify && git apply --verbose ../server.patch",
"sourcify:build": "cd sourcify && npm run build:lerna",
"sourcify:start": "cd sourcify && npm run server:start",
"server:reset-previewnet": "./scripts/hedera-reset.sh previewnet",
Expand Down
13 changes: 13 additions & 0 deletions server.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/services/server/src/server/controllers/verification/verification.common.ts b/services/server/src/server/controllers/verification/verification.common.ts
index d9317900..e9a0b13c 100644
--- a/services/server/src/server/controllers/verification/verification.common.ts
+++ b/services/server/src/server/controllers/verification/verification.common.ts
@@ -460,7 +460,7 @@ export const verifyContractsInSession = async (
logger.info("dryRun verification", {
sessionId: session.id,
});
- return;
+ continue;
}
if (match.runtimeMatch || match.creationMatch) {
await storageService.storeMatch(checkedContract, match);
51 changes: 46 additions & 5 deletions test/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -966,10 +966,7 @@ describe("Server", function () {

it("should fail if too many files uploaded, but should succeed after deletion", async () => {
const MAX_FILE_SIZE = config.get("server.maxFileSize");

const MAX_SESSION_SIZE =
// require("../dist/server/controllers/verification/verification.common").MAX_SESSION_SIZE;
require("../sourcify/services/server/dist/server/controllers/verification/verification.common").MAX_SESSION_SIZE;
const MAX_SESSION_SIZE = require("../sourcify/services/server/dist/server/controllers/verification/verification.common").MAX_SESSION_SIZE;

const agent = chai.request.agent(server.app);
let res;
Expand Down Expand Up @@ -1003,7 +1000,7 @@ const MAX_SESSION_SIZE =
expectedStatus,
shouldHaveTimestamp
) => {
chai.expect(res.status).to.equal(StatusCodes.OK);
chai.expect(res.status, JSON.stringify(res, null, 2)).to.equal(StatusCodes.OK);
chai.expect(res.body).to.haveOwnProperty("contracts");
const contracts = res.body.contracts;
chai.expect(contracts).to.have.a.lengthOf(1);
Expand Down Expand Up @@ -1135,6 +1132,49 @@ const MAX_SESSION_SIZE =
});
});
});

it('should not store the successful verification of multi-contract hardhat build-info when dryrun=true', done => {
const hardhatOutputJSON = require("./sources/hardhat-output/multiContracts.json");
const {abi, evm} = hardhatOutputJSON.output.contracts["contracts/SupraOracle.sol"].SupraOracle;
deployFromAbiAndBytecode(localSigner, abi, evm.bytecode.object).then(address => waitSecs(3).then(() => {
const agent = chai.request.agent(server.app);
agent
.post("/session/input-files?dryrun=true")
.attach("files", Buffer.from(JSON.stringify(hardhatOutputJSON)))
.then(res => {
chai.expect(res.status).to.equal(StatusCodes.OK);
chai.expect(res.body).to.haveOwnProperty("contracts");
const contracts = res.body.contracts;
console.log(contracts);

chai.expect(contracts).to.have.lengthOf(3);
contracts.forEach(contract => {
chai.expect(contract.status).to.equal("error");
contract.address = address;
contract.chainId = CHAIN_ID;
});

agent
.post("/session/verify-checked?dryrun=true")
.send({contracts})
.then(res => {
console.log(res.body);

chai.expect(res.status).to.equal(StatusCodes.OK);
chai.expect(res.body).to.haveOwnProperty("contracts");
const contracts = res.body.contracts;

chai.expect(contracts[0].status).to.equal("error");
chai.expect(contracts[1].status).to.equal("error");
chai.expect(contracts[2].status).to.equal("perfect");
chai.expect(contracts[2].name).to.equal("SupraOracle");

assertContractNotSaved(address, CHAIN_ID);
done();
});
});
}));
});
});

it("should fetch missing sources", (done) => {
Expand Down Expand Up @@ -1188,6 +1228,7 @@ const MAX_SESSION_SIZE =
chai.expect(res.body.contracts).to.have.lengthOf(3);
done();
});

it("should correctly handle when uploaded 0/2 and then 1/2 sources", (done) => {
const metadataPath = path.join("test", "sources", "metadata", "child-contract.meta.object.json");
const metadataBuffer = fs.readFileSync(metadataPath);
Expand Down
Loading

0 comments on commit 252223b

Please sign in to comment.