Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libs/remix-lib/src/execution/txRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ function run (self, tx, stamp, confirmationCb, gasEstimationForceSend, promptCb,
self.queusTxs.push({ tx, stamp, callback })
} else {
self.pendingTxs[stamp] = tx
self.execute(tx, confirmationCb, gasEstimationForceSend, promptCb, (error, result) => {
self.execute(tx, confirmationCb, gasEstimationForceSend, promptCb, function(error, result) {
delete self.pendingTxs[stamp]
callback(error, result)
if (self.queusTxs.length) {
Expand Down
2 changes: 1 addition & 1 deletion libs/remix-solidity/src/compiler/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class Compiler {

onInternalCompilerLoaded (): void {
if (this.state.worker === null) {
const compiler: any = typeof (window) === 'undefined' ? require('solc') : require('solc/wrapper')(window['Module'])
const compiler: any = typeof (window) !== 'undefined' && window['Module'] ? require('solc/wrapper')(window['Module']) : require('solc')
this.state.compileJSON = (source: SourceWithTarget) => {
const missingInputs: string[] = []
const missingInputsCallback = (path: string) => {
Expand Down
23 changes: 23 additions & 0 deletions libs/remix-tests/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = {
name: 'remix-tests',
preset: '../../jest.config.js',
verbose: true,
silent: true, // Silent console messages, specially the 'remix-simulator' ones
transform: {
'^.+\\.[tj]sx?$': 'ts-jest',
},
rootDir: "./",
testTimeout: 30000,
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html', 'json'],
// Coverage
collectCoverage: true,
coverageReporters: ['text', 'text-summary'],
collectCoverageFrom: [
"**/*.ts",
"!**/sol/**",
"!src/types.ts",
"!src/logger.ts"
],
coverageDirectory: '../../coverage/libs/remix-tests',
};

2 changes: 1 addition & 1 deletion libs/remix-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"scripts": {
"build": "tsc",
"test": "./../../node_modules/.bin/mocha --require ts-node/register --require tsconfig-paths/register tests/*.ts -t 300000"
"test": "./../../node_modules/.bin/jest"
},
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'mocha'
import * as async from 'async'
import Web3 from 'web3';
import * as assert from 'assert'
Expand Down Expand Up @@ -41,7 +40,7 @@ function deepEqualExcluding(a: any, b: any, excludedKeys: string[]) {
}

let accounts: string[]
let provider = new Provider()
let provider: any = new Provider()

async function compileAndDeploy(filename: string, callback: Function) {
let web3: Web3 = new Web3()
Expand Down Expand Up @@ -102,28 +101,28 @@ describe('testRunner', () => {

describe('#runTest', () => {
describe('test with beforeAll', () => {
const filename: string = 'tests/examples_1/simple_storage_test.sol'
const filename: string = __dirname + '/examples_1/simple_storage_test.sol'

before((done) => {
beforeAll((done) => {
compileAndDeploy(filename, (_err: Error | null | undefined, compilationData: object, contracts: any, asts: any, accounts: string[]) => {
runTest('MyTest', contracts.MyTest, compilationData[filename]['MyTest'], asts[filename], { accounts }, testCallback, resultsCallback(done))
})
})

after(() => { tests = [] })
afterAll(() => { tests = [] })

it('should have 3 passing test', function () {
it('should have 3 passing test', () => {
assert.equal(results.passingNum, 3)
})

it('should have 1 failing test', function () {
it('should have 1 failing test', () => {
assert.equal(results.failureNum, 1)
})

it('should return 6 messages', function () {
it('should return 6 messages', () => {
deepEqualExcluding(tests, [
{ type: 'accountList', value: accounts },
{ type: 'contract', value: 'MyTest', filename: 'tests/examples_1/simple_storage_test.sol' },
{ type: 'contract', value: 'MyTest', filename: __dirname + '/examples_1/simple_storage_test.sol' },
{ type: 'testPass', value: 'Initial value should be100', context: 'MyTest' },
{ type: 'testPass', value: 'Initial value should not be200', context: 'MyTest' },
{ type: 'testFailure', value: 'Should trigger one fail', errMsg: 'uint test 1 fails', context: 'MyTest' },
Expand All @@ -132,81 +131,81 @@ describe('testRunner', () => {
})
})

describe('test with beforeEach', function () {
const filename: string = 'tests/examples_2/simple_storage_test.sol'
describe('test with beforeEach', () => {
const filename: string = __dirname + '/examples_2/simple_storage_test.sol'

before(function (done) {
beforeAll(done => {
compileAndDeploy(filename, function (_err: Error | null | undefined, compilationData: object, contracts: any, asts: any, accounts: string[]) {
runTest('MyTest', contracts.MyTest, compilationData[filename]['MyTest'], asts[filename], { accounts }, testCallback, resultsCallback(done))
})
})

after(() => { tests = [] })
afterAll(() => { tests = [] })

it('should have 2 passing tests', function () {
it('should have 2 passing tests', () => {
assert.equal(results.passingNum, 2)
})

it('should 0 failing tests', function () {
it('should 0 failing tests', () => {
assert.equal(results.failureNum, 0)
})

it('should return 4 messages', function () {
it('should return 4 messages', () => {
deepEqualExcluding(tests, [
{ type: 'accountList', value: accounts },
{ type: 'contract', value: 'MyTest', filename: 'tests/examples_2/simple_storage_test.sol' },
{ type: 'contract', value: 'MyTest', filename: __dirname + '/examples_2/simple_storage_test.sol' },
{ type: 'testPass', value: 'Initial value should be100', context: 'MyTest' },
{ type: 'testPass', value: 'Value is set200', context: 'MyTest' }
], ['time'])
})
})

// Test string equality
describe('test string equality', function () {
const filename: string = 'tests/examples_3/simple_string_test.sol'
describe('test string equality', () => {
const filename: string = __dirname + '/examples_3/simple_string_test.sol'

before(function (done) {
beforeAll(done => {
compileAndDeploy(filename, function (_err: Error | null | undefined, compilationData: object, contracts: any, asts: any, accounts: string[]) {
runTest('StringTest', contracts.StringTest, compilationData[filename]['StringTest'], asts[filename], { accounts }, testCallback, resultsCallback(done))
})
})

after(() => { tests = [] })
afterAll(() => { tests = [] })

it('should 2 passing tests', function () {
it('should 2 passing tests', () => {
assert.equal(results.passingNum, 2)
})

it('should return 4 messages', function () {
it('should return 4 messages', () => {
deepEqualExcluding(tests, [
{ type: 'accountList', value: accounts },
{ type: 'contract', value: 'StringTest', filename: 'tests/examples_3/simple_string_test.sol' },
{ type: 'contract', value: 'StringTest', filename: __dirname + '/examples_3/simple_string_test.sol' },
{ type: 'testPass', value: 'Initial value should be hello world', context: 'StringTest' },
{ type: 'testPass', value: 'Value should not be hello wordl', context: 'StringTest' }
], ['time'])
})
})

// Test multiple directory import in test contract
describe('test multiple directory import in test contract', function () {
const filename: string = 'tests/examples_5/test/simple_storage_test.sol'
describe('test multiple directory import in test contract', () => {
const filename: string = __dirname + '/examples_5/test/simple_storage_test.sol'

before(function (done) {
beforeAll(done => {
compileAndDeploy(filename, function (_err: Error | null | undefined, compilationData: object, contracts: any, asts: any, accounts: string[]) {
runTest('StorageResolveTest', contracts.StorageResolveTest, compilationData[filename]['StorageResolveTest'], asts[filename], { accounts }, testCallback, resultsCallback(done))
})
})

after(() => { tests = [] })
afterAll(() => { tests = [] })

it('should 3 passing tests', function () {
it('should 3 passing tests', () => {
assert.equal(results.passingNum, 3)
})

it('should return 4 messages', function () {
it('should return 4 messages', () => {
deepEqualExcluding(tests, [
{ type: 'accountList', value: accounts },
{ type: 'contract', value: 'StorageResolveTest', filename: 'tests/examples_5/test/simple_storage_test.sol' },
{ type: 'contract', value: 'StorageResolveTest', filename: __dirname + '/examples_5/test/simple_storage_test.sol' },
{ type: 'testPass', value: 'Initial value should be100', context: 'StorageResolveTest' },
{ type: 'testPass', value: 'Check if even', context: 'StorageResolveTest' },
{ type: 'testPass', value: 'Check if odd', context: 'StorageResolveTest' }
Expand All @@ -215,48 +214,48 @@ describe('testRunner', () => {
})

//Test signed/unsigned integer weight
describe('test number weight', function () {
const filename: string = 'tests/number/number_test.sol'
describe('test number weight', () => {
const filename: string = __dirname + '/number/number_test.sol'

before(function (done) {
beforeAll(done => {
compileAndDeploy(filename, function (_err: Error | null | undefined, compilationData: object, contracts: any, asts: any, accounts: string[]) {
runTest('IntegerTest', contracts.IntegerTest, compilationData[filename]['IntegerTest'], asts[filename], { accounts }, testCallback, resultsCallback(done))
})
})

after(() => { tests = [] })
afterAll(() => { tests = [] })

it('should have 6 passing tests', function () {
it('should have 6 passing tests', () => {
assert.equal(results.passingNum, 6)
})
it('should have 2 failing tests', function () {
it('should have 2 failing tests', () => {
assert.equal(results.failureNum, 2)
})
})

// Test Transaction with custom sender & value
describe('various sender', function () {
const filename: string = 'tests/various_sender/sender_and_value_test.sol'
describe('various sender', () => {
const filename: string = __dirname + '/various_sender/sender_and_value_test.sol'

before(function (done) {
beforeAll(done => {
compileAndDeploy(filename, function (_err: Error | null | undefined, compilationData: object, contracts: any, asts: any, accounts: string[]) {
runTest('SenderAndValueTest', contracts.SenderAndValueTest, compilationData[filename]['SenderAndValueTest'], asts[filename], { accounts }, testCallback, resultsCallback(done))
})
})

after(() => { tests = [] })
afterAll(() => { tests = [] })

it('should have 17 passing tests', function () {
it('should have 17 passing tests', () => {
assert.equal(results.passingNum, 17)
})
it('should have 0 failing tests', function () {
it('should have 0 failing tests', () => {
assert.equal(results.failureNum, 0)
})
})

// Test `runTest` method without sending contract object (should throw error)
describe('runTest method without contract json interface', function () {
const filename: string = 'tests/various_sender/sender_and_value_test.sol'
describe('runTest method without contract json interface', () => {
const filename: string = __dirname + '/various_sender/sender_and_value_test.sol'
const errorCallback: Function = (done) => {
return (err, _results) => {
if (err && err.message.includes('Contract interface not available')) {
Expand All @@ -266,16 +265,16 @@ describe('testRunner', () => {
else throw err
}
}
before(function (done) {
beforeAll(done => {
compileAndDeploy(filename, function (_err: Error | null | undefined, compilationData: object, contracts: any, asts: any, accounts: string[]) {
runTest('SenderAndValueTest', undefined, compilationData[filename]['SenderAndValueTest'], asts[filename], { accounts }, testCallback, errorCallback(done))
})
})

it('should have 0 passing tests', function () {
it('should have 0 passing tests', () => {
assert.equal(results.passingNum, 0)
})
it('should have 0 failing tests', function () {
it('should have 0 failing tests', () => {
assert.equal(results.failureNum, 0)
})
})
Expand Down
4 changes: 3 additions & 1 deletion libs/remix-tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"types": ["node"],
"types": ["node", "jest"],
"module": "commonjs",
"allowJs": true,
"rootDir": "./",
"esModuleInterop": true
},
"include": ["**/*.ts"]
Expand Down
16 changes: 16 additions & 0 deletions libs/remix-tests/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": [
"**/*.spec.ts",
"**/*.spec.tsx",
"**/*.spec.js",
"**/*.spec.jsx",
"**/*.d.ts"
]
}

Loading