-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathtest-bytecode-compare.js
More file actions
52 lines (44 loc) · 1.59 KB
/
test-bytecode-compare.js
File metadata and controls
52 lines (44 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import path from "node:path";
import createEsmUtils from "esm-utils";
import compileContract from "./utils/compile-contract.js";
async function testBytecodeCompare(testCase) {
const { filepath, formatOptions } = testCase;
const formatResult = await testCase.runFormat();
if (shouldCompareBytecode(filepath, formatOptions)) {
const output = compileContract(filepath, formatResult.output);
const expected = compileContract(filepath, formatResult.input);
expect(output).toEqual(expected);
}
}
const { __dirname } = createEsmUtils(import.meta);
const testsWithAstChanges = new Map(
[
"Parentheses/AddNoParentheses.sol",
"Parentheses/SubNoParentheses.sol",
"Parentheses/MulNoParentheses.sol",
"Parentheses/DivNoParentheses.sol",
"Parentheses/ModNoParentheses.sol",
"Parentheses/ExpNoParentheses.sol",
"Parentheses/ShiftLNoParentheses.sol",
"Parentheses/ShiftRNoParentheses.sol",
"Parentheses/BitAndNoParentheses.sol",
"Parentheses/BitOrNoParentheses.sol",
"Parentheses/BitXorNoParentheses.sol",
"Parentheses/LogicNoParentheses.sol",
"HexLiteral/HexLiteral.sol",
"ModifierInvocations/ModifierInvocations.sol",
].map((fixture) => {
const [file, compareBytecode = () => true] = Array.isArray(fixture)
? fixture
: [fixture];
return [path.join(__dirname, "../format/", file), compareBytecode];
}),
);
const shouldCompareBytecode = (filepath, options) => {
const testFunction = testsWithAstChanges.get(filepath);
if (!testFunction) {
return false;
}
return testFunction(options);
};
export { testBytecodeCompare as run };