Skip to content

Commit e974f39

Browse files
committed
Add server integration tests for 0.4.11 (pass) and 0.4.10 (fail)
1 parent 06c8c86 commit e974f39

File tree

4 files changed

+223
-0
lines changed

4 files changed

+223
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"abi": [
3+
{
4+
"constant": false,
5+
"inputs": [],
6+
"name": "retrieve",
7+
"outputs": [
8+
{
9+
"name": "",
10+
"type": "uint256"
11+
}
12+
],
13+
"payable": false,
14+
"type": "function",
15+
"stateMutability": "nonpayable"
16+
},
17+
{
18+
"constant": false,
19+
"inputs": [
20+
{
21+
"name": "num",
22+
"type": "uint256"
23+
}
24+
],
25+
"name": "store",
26+
"outputs": [],
27+
"payable": false,
28+
"type": "function",
29+
"stateMutability": "nonpayable"
30+
}
31+
],
32+
"bytecode": "0x6060604052341561000c57fe5b5b60c68061001b6000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680632e64cec11460445780636057361d146067575bfe5b3415604b57fe5b60516084565b6040518082815260200191505060405180910390f35b3415606e57fe5b60826004808035906020019091905050608f565b005b600060005490505b90565b806000819055505b505600a165627a7a7230582061e948a5785f0bce6470f275ac915e61c1f4f799e4a3b41bb3d7d3648da0caa80029"
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"abi": [
3+
{
4+
"constant": false,
5+
"inputs": [],
6+
"name": "retrieve",
7+
"outputs": [
8+
{
9+
"name": "",
10+
"type": "uint256"
11+
}
12+
],
13+
"payable": false,
14+
"type": "function",
15+
"stateMutability": "nonpayable"
16+
},
17+
{
18+
"constant": false,
19+
"inputs": [
20+
{
21+
"name": "num",
22+
"type": "uint256"
23+
}
24+
],
25+
"name": "store",
26+
"outputs": [],
27+
"payable": false,
28+
"type": "function",
29+
"stateMutability": "nonpayable"
30+
}
31+
],
32+
"bytecode": "0x6060604052341561000c57fe5b5b60c68061001b6000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680632e64cec11460445780636057361d146067575bfe5b3415604b57fe5b60516084565b6040518082815260200191505060405180910390f35b3415606e57fe5b60826004808035906020019091905050608f565b005b600060005490505b90565b806000819055505b505600a165627a7a7230582061e948a5785f0bce6470f275ac915e61c1f4f799e4a3b41bb3d7d3648da0caa80029"
33+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
pragma solidity >=0.1.0;
2+
3+
// SPDX-License-Identifier: GPL-3.0
4+
5+
contract Storage {
6+
uint256 number;
7+
8+
/**
9+
* @dev Store value in variable
10+
* @param num value to store
11+
*/
12+
function store(uint256 num) public {
13+
number = num;
14+
}
15+
16+
/**
17+
* @dev Return value
18+
* @return value of 'number'
19+
*/
20+
function retrieve() public returns (uint256) {
21+
return number;
22+
}
23+
}
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
import chai from "chai";
2+
import chaiHttp from "chai-http";
3+
import { SolidityJsonInput } from "@ethereum-sourcify/compilers-types";
4+
import {
5+
deployFromAbiAndBytecodeForCreatorTxHash,
6+
hookIntoVerificationWorkerRun,
7+
} from "../../../../helpers/helpers";
8+
import { LocalChainFixture } from "../../../../helpers/LocalChainFixture";
9+
import { ServerFixture } from "../../../../helpers/ServerFixture";
10+
import { assertJobVerification } from "../../../../helpers/assertions";
11+
import sinon from "sinon";
12+
import path from "path";
13+
import fs from "fs";
14+
15+
chai.use(chaiHttp);
16+
17+
describe("POST /v2/verify/:chainId/:address - Compiler Version Tests", function () {
18+
const chainFixture = new LocalChainFixture();
19+
const serverFixture = new ServerFixture();
20+
const sandbox = sinon.createSandbox();
21+
const makeWorkersWait = hookIntoVerificationWorkerRun(sandbox, serverFixture);
22+
23+
// Test cases for minimum supported version boundary
24+
const COMPILER_VERSION_TESTS = [
25+
// 0.4.11 - minimum supported version (should pass)
26+
// !! IMPORTANT
27+
// THIS TEST FOR 0.4.11 gets stuck on certain environmetns because of the execution of solc-json get stuck
28+
{
29+
version: "0.4.11+commit.68ef5810",
30+
expectMatch: "match" as const,
31+
shouldPass: true,
32+
},
33+
// 0.4.10 - unsupported version (should fail)
34+
{
35+
version: "0.4.10+commit.f0d539ae",
36+
expectMatch: null,
37+
shouldPass: false,
38+
},
39+
];
40+
41+
// Universal contract that compiles across all Solidity versions
42+
const SIMPLE_STORAGE_SOURCE = fs.readFileSync(
43+
path.join(__dirname, "Storage.sol"),
44+
"utf8",
45+
);
46+
47+
afterEach(async () => {
48+
sandbox.restore();
49+
});
50+
51+
// Helper function to create standard JSON input for a given version
52+
function createSolcJsonInput(): SolidityJsonInput {
53+
return {
54+
language: "Solidity",
55+
sources: {
56+
"Storage.sol": {
57+
content: SIMPLE_STORAGE_SOURCE,
58+
},
59+
},
60+
settings: {},
61+
};
62+
}
63+
64+
COMPILER_VERSION_TESTS.forEach(({ version, expectMatch, shouldPass }) => {
65+
const testTitle = shouldPass
66+
? `should verify SimpleStorage compiled with Solidity ${version} (minimum supported)`
67+
: `should reject unsupported Solidity ${version} with compilation error`;
68+
69+
it(testTitle, async function () {
70+
// Increase timeout for compilation and verification
71+
this.timeout(120000);
72+
73+
const { resolveWorkers } = makeWorkersWait();
74+
75+
const compilationArtifacts = JSON.parse(
76+
fs.readFileSync(path.join(__dirname, `${version}.json`), "utf8"),
77+
);
78+
79+
try {
80+
// Deploy the compiled contract
81+
const { contractAddress, txHash } =
82+
await deployFromAbiAndBytecodeForCreatorTxHash(
83+
chainFixture.localSigner,
84+
compilationArtifacts.abi,
85+
compilationArtifacts.bytecode,
86+
);
87+
88+
// Verify via API v2
89+
const verifyRes = await chai
90+
.request(serverFixture.server.app)
91+
.post(`/v2/verify/${chainFixture.chainId}/${contractAddress}`)
92+
.send({
93+
stdJsonInput: createSolcJsonInput(),
94+
compilerVersion: version,
95+
contractIdentifier: "Storage.sol:Storage",
96+
creationTransactionHash: txHash,
97+
});
98+
99+
if (shouldPass) {
100+
// Assert successful verification with correct match type
101+
await assertJobVerification(
102+
serverFixture,
103+
verifyRes,
104+
resolveWorkers,
105+
chainFixture.chainId,
106+
contractAddress,
107+
expectMatch!,
108+
);
109+
} else {
110+
// Initial request should return 202 (accepted)
111+
chai.expect(verifyRes.status).to.equal(202);
112+
chai.expect(verifyRes.body).to.have.property("verificationId");
113+
114+
await resolveWorkers();
115+
116+
// Check job status to see it failed with unsupported_compiler_version
117+
const jobStatusRes = await chai
118+
.request(serverFixture.server.app)
119+
.get(`/v2/verify/${verifyRes.body.verificationId}`);
120+
121+
chai.expect(jobStatusRes.status).to.equal(200);
122+
chai.expect(jobStatusRes.body.isJobCompleted).to.equal(true);
123+
chai.expect(jobStatusRes.body.error).to.exist;
124+
chai
125+
.expect(jobStatusRes.body.error.customCode)
126+
.to.equal("unsupported_compiler_version");
127+
}
128+
} catch (error) {
129+
console.error(`Test failed for Solidity version ${version}:`, error);
130+
throw error;
131+
}
132+
});
133+
});
134+
});

0 commit comments

Comments
 (0)