From b47dc5e6ae5e5ef8ab49d8ec0992fc370f1d8cf7 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 15 Feb 2019 17:36:19 -0500 Subject: [PATCH] create initial class to hold test tab logic --- src/app/tabs/test-tab.js | 119 +++++++++++++++++++++------------------ 1 file changed, 65 insertions(+), 54 deletions(-) diff --git a/src/app/tabs/test-tab.js b/src/app/tabs/test-tab.js index 3ff71ce636..8c5f7e23f5 100644 --- a/src/app/tabs/test-tab.js +++ b/src/app/tabs/test-tab.js @@ -8,6 +8,69 @@ var remixTests = require('remix-tests') import { ApiFactory } from 'remix-plugin' +class TestTabLogic { + + constructor (fileManager) { + this.fileManager = fileManager + } + + generateTestFile () { + var path = this.fileManager.currentPath() + var fileProvider = this.fileManager.fileProviderOf(path) + if (!fileProvider) return + helper.createNonClashingNameWithPrefix(path + '/test.sol', fileProvider, '_test', (error, newFile) => { + if (error) return modalDialogCustom.alert('Failed to create file. ' + newFile + ' ' + error) + if (!fileProvider.set(newFile, this.generateTestContractSample())) return modalDialogCustom.alert('Failed to create test file ' + newFile) + this.fileManager.switchFile(newFile) + }) + } + + generateTestContractSample () { + return `pragma solidity >=0.4.0 <0.6.0; + import "remix_tests.sol"; // this import is automatically injected by Remix. + + // file name has to end with '_test.sol' + contract test_1 { + + function beforeAll() public { + // here should instantiate tested contract + Assert.equal(uint(4), uint(3), "error in before all function"); + } + + function check1() public { + // use 'Assert' to test the contract + Assert.equal(uint(2), uint(1), "error message"); + Assert.equal(uint(2), uint(2), "error message"); + } + + function check2() public view returns (bool) { + // use the return value (true or false) to test the contract + return true; + } + } + + contract test_2 { + + function beforeAll() public { + // here should instantiate tested contract + Assert.equal(uint(4), uint(3), "error in before all function"); + } + + function check1() public { + // use 'Assert' to test the contract + Assert.equal(uint(2), uint(1), "error message"); + Assert.equal(uint(2), uint(2), "error message"); + } + + function check2() public view returns (bool) { + // use the return value (true or false) to test the contract + return true; + } + }` + } + +} + module.exports = class TestTab extends ApiFactory { constructor (fileManager, filePanel, compileTab) { super() @@ -15,6 +78,7 @@ module.exports = class TestTab extends ApiFactory { this._view = { el: null } this.fileManager = fileManager this.filePanel = filePanel + this.testTabLogic = new TestTabLogic(fileManager) this.data = {} this.testList = yo`
` this.listenToEvents() @@ -165,17 +229,6 @@ module.exports = class TestTab extends ApiFactory { async.eachOfSeries(tests, (value, key, callback) => { this.runTest(value, callback) }) } - generateTestFile () { - var path = this.fileManager.currentPath() - var fileProvider = this.fileManager.fileProviderOf(path) - if (!fileProvider) return - helper.createNonClashingNameWithPrefix(path + '/test.sol', fileProvider, '_test', (error, newFile) => { - if (error) return modalDialogCustom.alert('Failed to create file. ' + newFile + ' ' + error) - if (!fileProvider.set(newFile, testContractSample)) return modalDialogCustom.alert('Failed to create test file ' + newFile) - this.fileManager.switchFile(newFile) - }) - } - render () { this.testsOutput = yo`` this.testsSummary = yo`` @@ -191,7 +244,7 @@ module.exports = class TestTab extends ApiFactory {
For more details, see How to test smart contracts guide in our documentation. -
Generate test file
+
Generate test file
${this.testList} @@ -216,45 +269,3 @@ module.exports = class TestTab extends ApiFactory { } } - -var testContractSample = `pragma solidity >=0.4.0 <0.6.0; -import "remix_tests.sol"; // this import is automatically injected by Remix. - -// file name has to end with '_test.sol' -contract test_1 { - - function beforeAll() public { - // here should instantiate tested contract - Assert.equal(uint(4), uint(3), "error in before all function"); - } - - function check1() public { - // use 'Assert' to test the contract - Assert.equal(uint(2), uint(1), "error message"); - Assert.equal(uint(2), uint(2), "error message"); - } - - function check2() public view returns (bool) { - // use the return value (true or false) to test the contract - return true; - } -} - -contract test_2 { - - function beforeAll() public { - // here should instantiate tested contract - Assert.equal(uint(4), uint(3), "error in before all function"); - } - - function check1() public { - // use 'Assert' to test the contract - Assert.equal(uint(2), uint(1), "error message"); - Assert.equal(uint(2), uint(2), "error message"); - } - - function check2() public view returns (bool) { - // use the return value (true or false) to test the contract - return true; - } -}`