Skip to content

Commit 7881236

Browse files
committed
Add test with non-zero PUSH #[$] to solc-js tests
1 parent 36e6199 commit 7881236

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const tape = require('tape');
2+
const fs = require('fs');
3+
const solc = require('../index.js');
4+
5+
tape('ASM Json output consistency', function (t) {
6+
t.test('Nested structure', function(st) {
7+
const testdir = 'test/';
8+
const output = JSON.parse(solc.compile(JSON.stringify({
9+
language: 'Solidity',
10+
settings: {
11+
viaIR: true,
12+
outputSelection: {
13+
'*': {
14+
'*': ['evm.legacyAssembly']
15+
}
16+
}
17+
},
18+
sources: {
19+
C: {
20+
content: fs.readFileSync(testdir + 'code_access_runtime.sol', 'utf8')
21+
}
22+
}
23+
})));
24+
st.ok(output);
25+
26+
function containsTarget(obj, target) {
27+
if (Array.isArray(obj))
28+
return obj.some(item => containsTarget(item, target));
29+
else if (typeof obj === 'object' && obj !== null) {
30+
if (obj.name === target.name && obj.value === target.value)
31+
return true;
32+
return Object.values(obj).some(value => containsTarget(value, target));
33+
}
34+
return false;
35+
}
36+
37+
// regression test that there is indeed a negative subassembly index in there
38+
// and it is based on a 64 bit uint
39+
const targetObject = {
40+
"name": "PUSH #[$]",
41+
"value": "000000000000000000000000000000000000000000000000ffffffffffffffff"
42+
};
43+
st.equal(containsTarget(output, targetObject), true)
44+
});
45+
});

test/externalTests/solc-js/solc-js.sh

+3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ function solcjs_test
4848
printLog "Copying contracts..."
4949
cp -Rf "$SOLCJS_INPUT_DIR/DAO" test/
5050

51+
printLog "Copying test with non-zero subassembly access"
52+
cp -f "$TEST_DIR"/test/libsolidity/semanticTests/various/code_access_runtime.sol test/
53+
5154
printLog "Copying SMTChecker tests..."
5255
# We do not copy all tests because that takes too long.
5356
cp -Rf "$TEST_DIR"/test/libsolidity/smtCheckerTests/external_calls test/smtCheckerTests/

0 commit comments

Comments
 (0)