From b342da50b29c9716ddac131308160b19c2763b50 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Wed, 22 Jan 2020 16:28:01 +0530 Subject: [PATCH] tests for value & VM transaction instance fix --- remix-lib/src/execution/txRunner.js | 15 ++++++++------- remix-tests/tests/testRunner.ts | 12 ++++++------ ...ender_test.sol => sender_and_value_test.sol} | 17 +++++++++++------ 3 files changed, 25 insertions(+), 19 deletions(-) rename remix-tests/tests/various_sender/{sender_test.sol => sender_and_value_test.sol} (50%) diff --git a/remix-lib/src/execution/txRunner.js b/remix-lib/src/execution/txRunner.js index c470d6c61a..e01340ad8b 100644 --- a/remix-lib/src/execution/txRunner.js +++ b/remix-lib/src/execution/txRunner.js @@ -95,7 +95,7 @@ class TxRunner { runInVm (from, to, data, value, gasLimit, useCall, timestamp, callback) { const self = this - var account = self.vmaccounts[from] + const account = self.vmaccounts[from] if (!account) { return callback('Invalid account selected') } @@ -104,19 +104,20 @@ class TxRunner { if (err) { callback('Account not found') } else { - var tx = new EthJSTX({ - timestamp: timestamp, - nonce: new BN(res.nonce), - gasPrice: new BN(1), + // See https://github.com/ethereumjs/ethereumjs-tx/blob/master/docs/classes/transaction.md#constructor + // for initialization fields and their types + const tx = new EthJSTX({ + nonce: '0x' + res.nonce.toString('hex'), + gasPrice: '0x1', gasLimit: gasLimit, to: to, - value: new BN(value, 10), + value: value, data: Buffer.from(data.slice(2), 'hex') }) tx.sign(account.privateKey) const coinbases = ['0x0e9281e9c6a0808672eaba6bd1220e144c9bb07a', '0x8945a1288dc78a6d8952a92c77aee6730b414778', '0x94d76e24f818426ae84aa404140e8d5f60e10e7e'] const difficulties = [new BN('69762765929000', 10), new BN('70762765929000', 10), new BN('71762765929000', 10)] - var block = new EthJSBlock({ + const block = new EthJSBlock({ header: { timestamp: timestamp || (new Date().getTime() / 1000 | 0), number: self.blockNumber, diff --git a/remix-tests/tests/testRunner.ts b/remix-tests/tests/testRunner.ts index 307fa595a0..efe34cbf98 100644 --- a/remix-tests/tests/testRunner.ts +++ b/remix-tests/tests/testRunner.ts @@ -234,22 +234,22 @@ describe('testRunner', () => { }) }) - // Test Transaction with different sender + // Test Transaction with custom sender & value describe('various sender', function () { - const filename: string = 'tests/various_sender/sender_test.sol' + const filename: string = 'tests/various_sender/sender_and_value_test.sol' before(function (done) { compileAndDeploy(filename, function (_err: Error | null | undefined, compilationData: object, contracts: any, asts: any, accounts: string[]) { - runTest('SenderTest', contracts.SenderTest, compilationData[filename]['SenderTest'], asts[filename], { accounts }, testCallback, resultsCallback(done)) + runTest('SenderAndValueTest', contracts.SenderAndValueTest, compilationData[filename]['SenderAndValueTest'], asts[filename], { accounts }, testCallback, resultsCallback(done)) }) }) after(() => { tests = [] }) - it('should have 4 passing tests', function () { - assert.equal(results.passingNum, 4) + it('should have 5 passing tests', function () { + assert.equal(results.passingNum, 5) }) - it('should have 1 failing tests', function () { + it('should have 0 failing tests', function () { assert.equal(results.failureNum, 0) }) }) diff --git a/remix-tests/tests/various_sender/sender_test.sol b/remix-tests/tests/various_sender/sender_and_value_test.sol similarity index 50% rename from remix-tests/tests/various_sender/sender_test.sol rename to remix-tests/tests/various_sender/sender_and_value_test.sol index e146e51c0d..6b4d2c78d9 100644 --- a/remix-tests/tests/various_sender/sender_test.sol +++ b/remix-tests/tests/various_sender/sender_and_value_test.sol @@ -1,7 +1,7 @@ import "remix_tests.sol"; // this import is automatically injected by Remix. import "remix_accounts.sol"; -contract SenderTest { +contract SenderAndValueTest { function beforeAll () public {} /// #sender: account-1 @@ -11,16 +11,21 @@ contract SenderTest { /// #sender: account-0 /// #value: 10 - function checkSenderIs0 () public payable{ - Assert.equal(msg.sender, TestsAccounts.getAccount(0), "wrong sender in checkSenderIs0"); + function checkSenderIs0AndValueis10 () public payable{ + Assert.equal(msg.sender, TestsAccounts.getAccount(0), "wrong sender in checkSenderIs0AndValueis10"); + Assert.equal(msg.value, 10, "wrong value in checkSenderIs0AndValueis10"); } /// #value: 100 - function checkSenderIsNt0 () public payable{ - Assert.equal(msg.sender, TestsAccounts.getAccount(0), "wrong sender in checkSenderIsNot0"); + function checkValueIs100 () public payable{ + Assert.equal(msg.value, 100, "wrong value in checkValueIs100"); } function checkSenderIsnt2 () public { - Assert.notEqual(msg.sender, TestsAccounts.getAccount(1), "wrong sender in checkSenderIsnt2"); + Assert.notEqual(msg.sender, TestsAccounts.getAccount(2), "wrong sender in checkSenderIsnt2"); + } + + function checkValueIsnt10 () public payable{ + Assert.notEqual(msg.value, 10, "wrong value in checkValueIsnt10"); } }