Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
v1rtl committed Feb 16, 2023
1 parent 4406676 commit 67536f4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/erc20/MyToken.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-only
// SPDX-License-Identifier: MIT
pragma solidity >=0.8;

import {ERC20} from "./ERC20.sol";
Expand Down
4 changes: 3 additions & 1 deletion types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LibraryAddresses } from './deps.ts'
import type { LibraryAddresses, Wrapper as SolcWrapper } from './deps.ts'

export type Input = {
language: 'Solidity' | 'Yul'
Expand Down Expand Up @@ -147,3 +147,5 @@ export type Output = {
sourceList?: string[]
sources?: Record<string, { id: number; AST?: any }>
}

export type Wrapper = Omit<SolcWrapper, 'loadRemoteVersion' | 'setupMethods'>
40 changes: 38 additions & 2 deletions wrapper_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,57 @@ import { it, describe, run, expect, beforeAll, afterAll } from 'https://deno.lan
import { wrapper } from './wrapper.ts'
import { createRequire } from './deps.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', async () => {
const solc = wrapper(require('./soljson_test.js'))

expect(solc.compile).toBeDefined()
expect(solc.version()).toBe('0.8.18+commit.87f61d96.Emscripten.clang')
expect(solc.semver()).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', async () => {
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'
}
])
})
})

run()

0 comments on commit 67536f4

Please sign in to comment.