Skip to content

Commit 9f62fd5

Browse files
committed
moving text bytecode compare to its own file
1 parent d6cddb8 commit 9f62fd5

2 files changed

Lines changed: 56 additions & 45 deletions

File tree

tests/config/run-test.js

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import path from "node:path";
2-
import createEsmUtils from "esm-utils";
31
import { FULL_TEST } from "./constants.js";
42
import * as failedTests from "./failed-format-tests.js";
53
import { format } from "./run-prettier.js";
@@ -10,48 +8,12 @@ import * as testAstCompare from "./test-ast-compare.js";
108
import * as testBom from "./test-bom.js";
119
import * as testEndOfLine from "./test-end-of-line.js";
1210
import * as testSecondFormat from "./test-second-format.js";
11+
import * as testBytecodeCompare from "./test-bytecode-compare.js";
1312
import { shouldThrowOnFormat } from "./utilities.js";
1413
import getPrettier from "./get-prettier.js";
1514
import getCreateParser from "./get-create-parser.js";
1615
import getVariantCoverage from "./get-variant-coverage.js";
1716
import getPlugins from "./get-plugins.js";
18-
import compileContract from "./utils/compile-contract.js";
19-
20-
const { __dirname } = createEsmUtils(import.meta);
21-
22-
const testsWithAstChanges = new Map(
23-
[
24-
"Parentheses/AddNoParentheses.sol",
25-
"Parentheses/SubNoParentheses.sol",
26-
"Parentheses/MulNoParentheses.sol",
27-
"Parentheses/DivNoParentheses.sol",
28-
"Parentheses/ModNoParentheses.sol",
29-
"Parentheses/ExpNoParentheses.sol",
30-
"Parentheses/ShiftLNoParentheses.sol",
31-
"Parentheses/ShiftRNoParentheses.sol",
32-
"Parentheses/BitAndNoParentheses.sol",
33-
"Parentheses/BitOrNoParentheses.sol",
34-
"Parentheses/BitXorNoParentheses.sol",
35-
"Parentheses/LogicNoParentheses.sol",
36-
"HexLiteral/HexLiteral.sol",
37-
"ModifierInvocations/ModifierInvocations.sol",
38-
].map((fixture) => {
39-
const [file, compareBytecode = () => true] = Array.isArray(fixture)
40-
? fixture
41-
: [fixture];
42-
return [path.join(__dirname, "../format/", file), compareBytecode];
43-
}),
44-
);
45-
46-
const shouldCompareBytecode = (filename, options) => {
47-
const testFunction = testsWithAstChanges.get(filename);
48-
49-
if (!testFunction) {
50-
return false;
51-
}
52-
53-
return testFunction(options);
54-
};
5517

5618
async function runTest({
5719
parsers,
@@ -134,12 +96,7 @@ async function runTest({
13496
await testEndOfLine.run(code, formatResult, filename, formatOptions, "\r\n");
13597
await testEndOfLine.run(code, formatResult, filename, formatOptions, "\r");
13698
await testBom.run(code, formatResult, filename, formatOptions);
137-
138-
if (shouldCompareBytecode(filename, formatOptions)) {
139-
const output = compileContract(filename, formatResult.output);
140-
const expected = compileContract(filename, formatResult.input);
141-
expect(output).toEqual(expected);
142-
}
99+
await testBytecodeCompare.run(code, formatResult, filename, formatOptions);
143100
}
144101

145102
export { runTest };
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import path from "node:path";
2+
import createEsmUtils from "esm-utils";
3+
import compileContract from "./utils/compile-contract.js";
4+
5+
async function testBytecodeCompare(
6+
_source,
7+
formatResult,
8+
filename,
9+
formatOptions,
10+
) {
11+
if (shouldCompareBytecode(filename, formatOptions)) {
12+
const output = compileContract(filename, formatResult.output);
13+
const expected = compileContract(filename, formatResult.input);
14+
expect(output).toEqual(expected);
15+
}
16+
}
17+
18+
const { __dirname } = createEsmUtils(import.meta);
19+
20+
const testsWithAstChanges = new Map(
21+
[
22+
"Parentheses/AddNoParentheses.sol",
23+
"Parentheses/SubNoParentheses.sol",
24+
"Parentheses/MulNoParentheses.sol",
25+
"Parentheses/DivNoParentheses.sol",
26+
"Parentheses/ModNoParentheses.sol",
27+
"Parentheses/ExpNoParentheses.sol",
28+
"Parentheses/ShiftLNoParentheses.sol",
29+
"Parentheses/ShiftRNoParentheses.sol",
30+
"Parentheses/BitAndNoParentheses.sol",
31+
"Parentheses/BitOrNoParentheses.sol",
32+
"Parentheses/BitXorNoParentheses.sol",
33+
"Parentheses/LogicNoParentheses.sol",
34+
"HexLiteral/HexLiteral.sol",
35+
"ModifierInvocations/ModifierInvocations.sol",
36+
].map((fixture) => {
37+
const [file, compareBytecode = () => true] = Array.isArray(fixture)
38+
? fixture
39+
: [fixture];
40+
return [path.join(__dirname, "../format/", file), compareBytecode];
41+
}),
42+
);
43+
44+
const shouldCompareBytecode = (filename, options) => {
45+
const testFunction = testsWithAstChanges.get(filename);
46+
47+
if (!testFunction) {
48+
return false;
49+
}
50+
51+
return testFunction(options);
52+
};
53+
54+
export { testBytecodeCompare as run };

0 commit comments

Comments
 (0)