From 67536f45804791e29a35011c36882bf1e36c9ae4 Mon Sep 17 00:00:00 2001 From: v1rtl Date: Thu, 16 Feb 2023 14:58:14 +0200 Subject: [PATCH] add more tests --- examples/erc20/MyToken.sol | 2 +- types.ts | 4 +++- wrapper_test.ts | 40 ++++++++++++++++++++++++++++++++++++-- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/examples/erc20/MyToken.sol b/examples/erc20/MyToken.sol index 06083b9..0c82391 100644 --- a/examples/erc20/MyToken.sol +++ b/examples/erc20/MyToken.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: AGPL-3.0-only +// SPDX-License-Identifier: MIT pragma solidity >=0.8; import {ERC20} from "./ERC20.sol"; diff --git a/types.ts b/types.ts index ea334da..89fe440 100644 --- a/types.ts +++ b/types.ts @@ -1,4 +1,4 @@ -import { LibraryAddresses } from './deps.ts' +import type { LibraryAddresses, Wrapper as SolcWrapper } from './deps.ts' export type Input = { language: 'Solidity' | 'Yul' @@ -147,3 +147,5 @@ export type Output = { sourceList?: string[] sources?: Record } + +export type Wrapper = Omit diff --git a/wrapper_test.ts b/wrapper_test.ts index 8bee2c8..6af2298 100644 --- a/wrapper_test.ts +++ b/wrapper_test.ts @@ -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()