diff --git a/libs/remix-simulator/package.json b/libs/remix-simulator/package.json index 098e5cfa81..62630ecadb 100644 --- a/libs/remix-simulator/package.json +++ b/libs/remix-simulator/package.json @@ -43,7 +43,7 @@ "mocha": "^5.2.0" }, "scripts": { - "test": "./../../node_modules/.bin/mocha --require tsconfig-paths/register test/" + "test": "./../../node_modules/.bin/ts-node --require tsconfig-paths/register ./../../node_modules/.bin/mocha test/*.ts" }, "publishConfig": { "access": "public" diff --git a/libs/remix-simulator/src/genesis.ts b/libs/remix-simulator/src/genesis.ts index 84b97526ff..efd8e0f65d 100644 --- a/libs/remix-simulator/src/genesis.ts +++ b/libs/remix-simulator/src/genesis.ts @@ -1,7 +1,7 @@ import EthJSBlock from 'ethereumjs-block' import { BN } from 'ethereumjs-util' -function generateBlock (executionContext) { +export function generateBlock (executionContext) { const block = new EthJSBlock({ header: { timestamp: (new Date().getTime() / 1000 | 0), @@ -19,4 +19,3 @@ function generateBlock (executionContext) { }) } -module.exports = generateBlock diff --git a/libs/remix-simulator/src/index.ts b/libs/remix-simulator/src/index.ts index 042022eef5..d09d8216a8 100644 --- a/libs/remix-simulator/src/index.ts +++ b/libs/remix-simulator/src/index.ts @@ -1,3 +1,3 @@ import { Provider } from './provider' -export { Provider } +export default { Provider } diff --git a/libs/remix-simulator/src/provider.ts b/libs/remix-simulator/src/provider.ts index c735a66674..d125516e2e 100644 --- a/libs/remix-simulator/src/provider.ts +++ b/libs/remix-simulator/src/provider.ts @@ -9,11 +9,10 @@ import merge from 'merge' import { Accounts } from './methods/accounts' import { Filters } from './methods/filters' import { Misc } from './methods/misc' -import { Net } from './methods/net.js' -import { Transactions } from './methods/transactions.js' -import { Debug } from './methods/debug.js' - -const generateBlock = require('./genesis.js') +import { Net } from './methods/net' +import { Transactions } from './methods/transactions' +import { Debug } from './methods/debug' +import { generateBlock } from './genesis' export class Provider { options diff --git a/libs/remix-simulator/test/accounts.ts b/libs/remix-simulator/test/accounts.ts index fbe0e6e1eb..28c4dffbba 100644 --- a/libs/remix-simulator/test/accounts.ts +++ b/libs/remix-simulator/test/accounts.ts @@ -1,12 +1,12 @@ /* global describe, before, it */ -const Web3 = require('web3') -const RemixSim = require('../index.js') +import Web3 from 'web3' +import RemixSim from '../src/index' const web3 = new Web3() -const assert = require('assert') +import * as assert from 'assert' describe('Accounts', () => { before(function () { - const provider = new RemixSim.Provider() + const provider: any = new RemixSim.Provider() web3.setProvider(provider) }) diff --git a/libs/remix-simulator/test/blocks.ts b/libs/remix-simulator/test/blocks.ts index fb048764de..300774c79a 100644 --- a/libs/remix-simulator/test/blocks.ts +++ b/libs/remix-simulator/test/blocks.ts @@ -1,12 +1,12 @@ /* global describe, before, it */ -const Web3 = require('web3') -const RemixSim = require('../index.js') +import Web3 from 'web3' +import RemixSim from '../src/index' const web3 = new Web3() -const assert = require('assert') +import * as assert from 'assert' describe('blocks', () => { before(() => { - const provider = new RemixSim.Provider({ + const provider: any = new RemixSim.Provider({ coinbase: '0x0000000000000000000000000000000000000001' }) web3.setProvider(provider) @@ -21,7 +21,7 @@ describe('blocks', () => { extraData: '0x0', gasLimit: 8000000, gasUsed: 0, - hash: block.hash.toString('hex'), + hash: block.hash.toString(), logsBloom: '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331', miner: '0x0000000000000000000000000000000000000001', nonce: '0x0000000000000000', @@ -92,7 +92,7 @@ describe('blocks', () => { it('should get block given its hash', async () => { const correctBlock = await web3.eth.getBlock(0) const numberTransactions = await (new Promise((resolve, reject) => { - web3._requestManager.send({method: 'eth_getUncleCountByBlockHash', params: [correctBlock.hash]}, (err, numberTransactions) => { + web3['_requestManager'].send({method: 'eth_getUncleCountByBlockHash', params: [correctBlock.hash]}, (err, numberTransactions) => { if (err) return reject(err) resolve(numberTransactions) }) @@ -105,7 +105,7 @@ describe('blocks', () => { it('should get block given its number', async () => { const correctBlock = await web3.eth.getBlock(0) const numberTransactions = await (new Promise((resolve, reject) => { - web3._requestManager.send({method: 'eth_getUncleCountByBlockHash', params: [0]}, (err, numberTransactions) => { + web3['_requestManager'].send({method: 'eth_getUncleCountByBlockHash', params: [0]}, (err, numberTransactions) => { if (err) return reject(err) resolve(numberTransactions) }) @@ -116,7 +116,7 @@ describe('blocks', () => { describe('eth_getStorageAt', () => { it('should get storage at position at given address', async () => { - const abi = [ + const abi: any = [ { 'constant': false, 'inputs': [ @@ -203,7 +203,7 @@ describe('blocks', () => { const contract = new web3.eth.Contract(abi) const accounts = await web3.eth.getAccounts() - const contractInstance = await contract.deploy({ data: code, arguments: [100] }).send({ from: accounts[0], gas: 400000 }) + const contractInstance: any = await contract.deploy({ data: code, arguments: [100] }).send({ from: accounts[0], gas: 400000 }) contractInstance.currentProvider = web3.eth.currentProvider contractInstance.givenProvider = web3.eth.currentProvider @@ -223,7 +223,7 @@ describe('blocks', () => { describe('eth_call', () => { it('should get a value', async () => { - const abi = [ + const abi: any = [ { 'constant': false, 'inputs': [ @@ -310,7 +310,7 @@ describe('blocks', () => { const contract = new web3.eth.Contract(abi) const accounts = await web3.eth.getAccounts() - const contractInstance = await contract.deploy({ data: code, arguments: [100] }).send({ from: accounts[0], gas: 400000 }) + const contractInstance: any = await contract.deploy({ data: code, arguments: [100] }).send({ from: accounts[0], gas: 400000 }) contractInstance.currentProvider = web3.eth.currentProvider contractInstance.givenProvider = web3.eth.currentProvider diff --git a/libs/remix-simulator/test/misc.ts b/libs/remix-simulator/test/misc.ts index 134eb90461..8ccefbc27e 100644 --- a/libs/remix-simulator/test/misc.ts +++ b/libs/remix-simulator/test/misc.ts @@ -1,18 +1,18 @@ /* global describe, before, it */ -const Web3 = require('web3') -const RemixSim = require('../index.js') +import Web3 from 'web3' +import RemixSim from '../src/index' const web3 = new Web3() -const assert = require('assert') +import * as assert from 'assert' describe('Misc', () => { before(() => { - const provider = new RemixSim.Provider() + const provider: any = new RemixSim.Provider() web3.setProvider(provider) }) describe('web3_clientVersion', () => { it('should get correct remix simulator version', async (done) => { - web3._requestManager.send({ method: 'web3_clientVersion', params: [] }, (err, version) => { + web3['_requestManager'].send({ method: 'web3_clientVersion', params: [] }, (err, version) => { if (err) { throw new Error(err) } @@ -25,7 +25,7 @@ describe('Misc', () => { describe('eth_protocolVersion', () => { it('should get protocol version', async () => { - web3._requestManager.send({ method: 'eth_protocolVersion', params: [] }, (err, result) => { + web3['_requestManager'].send({ method: 'eth_protocolVersion', params: [] }, (err, result) => { if (err) { throw new Error(err) } @@ -57,7 +57,7 @@ describe('Misc', () => { describe('web3_sha3', () => { it('should get result of a sha3', async () => { - web3._requestManager.send({ method: 'web3_sha3', params: ['0x68656c6c6f20776f726c64'] }, (err, result) => { + web3['_requestManager'].send({ method: 'web3_sha3', params: ['0x68656c6c6f20776f726c64'] }, (err, result) => { if (err) { throw new Error(err) } @@ -68,7 +68,7 @@ describe('Misc', () => { describe('eth_getCompilers', () => { it('should get list of compilers', async () => { - web3._requestManager.send({ method: 'eth_getCompilers', params: [] }, (err, result) => { + web3['_requestManager'].send({ method: 'eth_getCompilers', params: [] }, (err, result) => { if (err) { throw new Error(err) } @@ -79,7 +79,7 @@ describe('Misc', () => { describe('eth_compileSolidity', () => { it('get unsupported result when requesting solidity compiler', async () => { - web3._requestManager.send({ method: 'eth_compileSolidity', params: [] }, (err, result) => { + web3['_requestManager'].send({ method: 'eth_compileSolidity', params: [] }, (err, result) => { if (err) { throw new Error(err) } @@ -90,7 +90,7 @@ describe('Misc', () => { describe('eth_compileLLL', () => { it('get unsupported result when requesting LLL compiler', async () => { - web3._requestManager.send({ method: 'eth_compileLLL', params: [] }, (err, result) => { + web3['_requestManager'].send({ method: 'eth_compileLLL', params: [] }, (err, result) => { if (err) { throw new Error(err) } @@ -101,7 +101,7 @@ describe('Misc', () => { describe('eth_compileSerpent', () => { it('get unsupported result when requesting serpent compiler', async () => { - web3._requestManager.send({ method: 'eth_compileSerpent', params: [] }, (err, result) => { + web3['_requestManager'].send({ method: 'eth_compileSerpent', params: [] }, (err, result) => { if (err) { throw new Error(err) } diff --git a/libs/remix-simulator/tsconfig.json b/libs/remix-simulator/tsconfig.json index 4f27566be2..f19ef7e5a8 100644 --- a/libs/remix-simulator/tsconfig.json +++ b/libs/remix-simulator/tsconfig.json @@ -1,7 +1,8 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - "types": ["node"] + "types": ["node", "mocha"], + "esModuleInterop": true }, "include": ["**/*.ts"] } \ No newline at end of file diff --git a/libs/remix-simulator/tsconfig.lib.json b/libs/remix-simulator/tsconfig.lib.json index f8c817af2a..dcbbfc63c2 100644 --- a/libs/remix-simulator/tsconfig.lib.json +++ b/libs/remix-simulator/tsconfig.lib.json @@ -5,7 +5,7 @@ "outDir": "../../dist/out-tsc", "declaration": true, "rootDir": "./src", - "types": ["node"] + "types": ["node", "mocha"] }, "exclude": [ "**/*.spec.ts",