|
| 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