Skip to content

Commit 3eba136

Browse files
Handle vyper compiler warnings in asyncExec function (#2291)
* handle vyper compiler warnings in asyncExec function * Handle Vyper compiler warnings for versions <0.4.0 and add tests for Vyper 0.3.10 and 0.4.1 * Fix test description Co-authored-by: Manuel Wedler <[email protected]> * Added test to check vyper warnings and errors for 0.3.10 --------- Co-authored-by: Manuel Wedler <[email protected]>
1 parent 7dd6878 commit 3eba136

File tree

2 files changed

+123
-3
lines changed

2 files changed

+123
-3
lines changed

packages/compilers/src/lib/common.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,15 @@ export function asyncExec(
7474
if (error) {
7575
reject(error);
7676
} else if (stderr) {
77-
reject(
78-
new Error(`Compiler process returned with errors:\n ${stderr}`),
79-
);
77+
// Vyper compilers <0.4.0 outputs warnings to stderr
78+
// we handle this by checking if the stderr starts with "Warning:"
79+
if (stderr.startsWith('Warning:')) {
80+
resolve(stdout);
81+
} else {
82+
reject(
83+
new Error(`Compiler process returned with errors:\n ${stderr}`),
84+
);
85+
}
8086
} else {
8187
resolve(stdout);
8288
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import { expect } from 'chai';
2+
import { useVyperCompiler } from '../src/lib/vyperCompiler';
3+
import path from 'path';
4+
5+
describe('Verify Vyper Compiler', () => {
6+
const vyperRepoPath = path.join('/tmp', 'vyper-repo');
7+
8+
it('Should compile with vyper', async function () {
9+
const compiledJSON = await useVyperCompiler(
10+
vyperRepoPath,
11+
'0.3.7+commit.6020b8bb',
12+
{
13+
language: 'Vyper',
14+
sources: {
15+
'test.vy': {
16+
content: '@external\ndef test() -> uint256:\n return 42',
17+
},
18+
},
19+
settings: {
20+
outputSelection: {
21+
'*': ['*'],
22+
},
23+
},
24+
},
25+
);
26+
expect(compiledJSON?.contracts?.['test.vy']?.test).to.not.equal(undefined);
27+
});
28+
29+
it('Should handle vyper 0.3.10 warnings', async function () {
30+
const compiledJSON = await useVyperCompiler(
31+
vyperRepoPath,
32+
'0.3.10+commit.91361694',
33+
{
34+
language: 'Vyper',
35+
sources: {
36+
'test.vy': {
37+
content: `@external
38+
@view
39+
def foo(x: uint256, y: int128) -> uint256:
40+
return shift(x, y)`,
41+
},
42+
},
43+
settings: {
44+
outputSelection: {
45+
'*': ['*'],
46+
},
47+
},
48+
},
49+
);
50+
expect(compiledJSON?.contracts?.['test.vy']?.test).to.not.equal(undefined);
51+
// 0.3.10 doesn't include the warnings in the standardJson output
52+
expect(compiledJSON?.errors).to.be.undefined;
53+
});
54+
55+
it('Should handle vyper 0.3.10 warnings and errors', async function () {
56+
try {
57+
const compiledJSON = await useVyperCompiler(
58+
vyperRepoPath,
59+
'0.3.10+commit.91361694',
60+
{
61+
language: 'Vyper',
62+
sources: {
63+
'test.vy': {
64+
content: `@exernal
65+
@view
66+
def foo(x: uint256, y: int128) -> uint256:
67+
return shift(x, y)`,
68+
},
69+
},
70+
settings: {
71+
outputSelection: {
72+
'*': ['*'],
73+
},
74+
},
75+
},
76+
);
77+
expect(compiledJSON?.contracts?.['test.vy']?.test).to.not.equal(
78+
undefined,
79+
);
80+
} catch (error: any) {
81+
// 0.3.10 doesn't include the warnings in the standardJson output but in the errors
82+
expect(error.errors?.some((e: any) => e.severity === 'warning')).to.be
83+
.false;
84+
expect(error.errors?.some((e: any) => e.severity === 'error')).to.be.true;
85+
}
86+
});
87+
88+
it('Should handle vyper 0.4.0 warnings', async function () {
89+
const compiledJSON = await useVyperCompiler(
90+
vyperRepoPath,
91+
'0.4.0+commit.e9db8d9f',
92+
{
93+
language: 'Vyper',
94+
sources: {
95+
'test.vy': {
96+
content: `@external
97+
@view
98+
def foo(x: uint256, y: int128) -> uint256:
99+
return shift(x, y)`,
100+
},
101+
},
102+
settings: {
103+
outputSelection: {
104+
'*': ['*'],
105+
},
106+
},
107+
},
108+
);
109+
expect(compiledJSON?.contracts?.['test.vy']?.test).to.not.equal(undefined);
110+
// Should still compile successfully despite warnings
111+
expect(compiledJSON?.errors?.some((e) => e.severity === 'warning')).to.be
112+
.true;
113+
});
114+
});

0 commit comments

Comments
 (0)