-
Notifications
You must be signed in to change notification settings - Fork 1
/
mod_test.ts
56 lines (52 loc) · 1.65 KB
/
mod_test.ts
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
53
54
55
56
import { beforeAll, describe, it } from 'https://deno.land/[email protected]/testing/bdd.ts'
import { expect } from 'https://deno.land/[email protected]/expect/mod.ts'
import { wrapper } from 'solc'
import { createRequire } from './helpers_test.ts'
import { download } from 'solc/download'
import type { Input, Output, Wrapper } from 'solc/types'
const require = createRequire(import.meta.url)
const contract = `
// SPDX-License-Identifier: MIT
pragma solidity >=0.8;
contract HelloWorld {
string public greet = "Hello World!";
}
`
describe('solc/wrapper.ts', () => {
let solc: Wrapper
beforeAll(async () => {
await download('./soljson_test.js', '0.8.18')
solc = wrapper(require('./soljson_test.js'))
})
it('returns JS interface', () => {
expect(solc.compile).toBeDefined()
expect(solc.version()).toBe('0.8.18+commit.87f61d96.Emscripten.clang')
expect(solc.license()).toContain('Most of the code is licensed under GPLv3 (see below), the license for individual')
})
it('compiles a Solidity file', () => {
const input: Input = {
language: 'Solidity',
sources: {
'Hello.sol': { content: contract },
},
settings: {
outputSelection: {
'*': {
'*': ['*'],
},
},
},
}
const output: Output = JSON.parse(solc.compile(JSON.stringify(input)))
expect(output.sources!['Hello.sol'].id).toEqual(0)
expect(output.contracts!['Hello.sol']['HelloWorld'].abi).toEqual([
{
inputs: [],
name: 'greet',
outputs: [{ internalType: 'string', name: '', type: 'string' }],
stateMutability: 'view',
type: 'function',
},
])
})
})