Skip to content

Commit 878898c

Browse files
committed
Add server integration tests for 0.4.11 (pass) and 0.4.10 (fail)
1 parent c72be2d commit 878898c

File tree

4 files changed

+221
-0
lines changed

4 files changed

+221
-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: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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.only("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+
{
27+
version: "0.4.11+commit.68ef5810",
28+
expectMatch: "match" as const,
29+
shouldPass: true,
30+
},
31+
// 0.4.10 - unsupported version (should fail)
32+
{
33+
version: "0.4.10+commit.f0d539ae",
34+
expectMatch: null,
35+
shouldPass: false,
36+
},
37+
];
38+
39+
// Universal contract that compiles across all Solidity versions
40+
const SIMPLE_STORAGE_SOURCE = fs.readFileSync(
41+
path.join(__dirname, "Storage.sol"),
42+
"utf8",
43+
);
44+
45+
afterEach(async () => {
46+
sandbox.restore();
47+
});
48+
49+
// Helper function to create standard JSON input for a given version
50+
function createSolcJsonInput(): SolidityJsonInput {
51+
return {
52+
language: "Solidity",
53+
sources: {
54+
"Storage.sol": {
55+
content: SIMPLE_STORAGE_SOURCE,
56+
},
57+
},
58+
settings: {},
59+
};
60+
}
61+
62+
COMPILER_VERSION_TESTS.forEach(({ version, expectMatch, shouldPass }) => {
63+
const testTitle = shouldPass
64+
? `should verify SimpleStorage compiled with Solidity ${version} (minimum supported)`
65+
: `should reject unsupported Solidity ${version} with compilation error`;
66+
67+
it(testTitle, async function () {
68+
// Increase timeout for compilation and verification
69+
this.timeout(120000);
70+
71+
const { resolveWorkers } = makeWorkersWait();
72+
73+
const compilationArtifacts = JSON.parse(
74+
fs.readFileSync(path.join(__dirname, `${version}.json`), "utf8"),
75+
);
76+
77+
try {
78+
// Deploy the compiled contract
79+
const { contractAddress, txHash } =
80+
await deployFromAbiAndBytecodeForCreatorTxHash(
81+
chainFixture.localSigner,
82+
compilationArtifacts.abi,
83+
compilationArtifacts.bytecode,
84+
);
85+
86+
// Verify via API v2
87+
const verifyRes = await chai
88+
.request(serverFixture.server.app)
89+
.post(`/v2/verify/${chainFixture.chainId}/${contractAddress}`)
90+
.send({
91+
stdJsonInput: createSolcJsonInput(),
92+
compilerVersion: version,
93+
contractIdentifier: "Storage.sol:Storage",
94+
creationTransactionHash: txHash,
95+
});
96+
97+
if (shouldPass) {
98+
// Assert successful verification with correct match type
99+
await assertJobVerification(
100+
serverFixture,
101+
verifyRes,
102+
resolveWorkers,
103+
chainFixture.chainId,
104+
contractAddress,
105+
expectMatch!,
106+
);
107+
} else {
108+
// Initial request should return 202 (accepted)
109+
chai.expect(verifyRes.status).to.equal(202);
110+
chai.expect(verifyRes.body).to.have.property("verificationId");
111+
112+
await resolveWorkers();
113+
114+
// Check job status to see it failed with unsupported_compiler_version
115+
const jobStatusRes = await chai
116+
.request(serverFixture.server.app)
117+
.get(`/v2/verify/${verifyRes.body.verificationId}`);
118+
119+
chai.expect(jobStatusRes.status).to.equal(200);
120+
chai.expect(jobStatusRes.body.isJobCompleted).to.equal(true);
121+
chai.expect(jobStatusRes.body.error).to.exist;
122+
chai
123+
.expect(jobStatusRes.body.error.customCode)
124+
.to.equal("unsupported_compiler_version");
125+
}
126+
} catch (error) {
127+
console.error(`Test failed for Solidity version ${version}:`, error);
128+
throw error;
129+
}
130+
});
131+
});
132+
});

0 commit comments

Comments
 (0)