From 40535a26aab65f951623bdaf7d0fb4bd48535a9d Mon Sep 17 00:00:00 2001 From: Yogi Xun Date: Sun, 6 May 2018 13:52:56 +0800 Subject: [PATCH] contract: update test cases --- .../contract/contract.feature.date.test.js | 29 ++++++++++++++++++- .../contract/contract.feature.random.test.js | 2 +- nf/nvm/test/contract_accept_func_with_args.js | 28 ++++++++++++++++++ nf/nvm/test/contract_date_and_random.js | 9 +++++- 4 files changed, 65 insertions(+), 3 deletions(-) diff --git a/nebtestkit/cases/contract/contract.feature.date.test.js b/nebtestkit/cases/contract/contract.feature.date.test.js index fb618c0ee..4fba6e3d6 100644 --- a/nebtestkit/cases/contract/contract.feature.date.test.js +++ b/nebtestkit/cases/contract/contract.feature.date.test.js @@ -285,7 +285,15 @@ function runTest(testInput, testExpect, done) { } }); }).catch(function (err) { - console.log("send tx err"); + if (err.error && err.error.error && testExpect.eventErr) { + try { + expect(err.error.error).to.equal(testExpect.eventErr) + done(); + } catch (err) { + done(err); + } + return; + } done(err); }); } @@ -335,6 +343,25 @@ var caseGroup = { status: 1, equalBlockTime: false } + }, + { + "name": "0-3. test unsupported method", + "testInput": { + value: "0", + nonce: 1, + gasPrice: 1000000, + gasLimit: 2000000, + contract: { + function: "testDate2", + args: "" + } + }, + "testExpect": { + canExcuteTx: false, + toBalanceChange: "0", + status: 0, + eventErr: "Call: Error: Unsupported method!" + } } ] }; diff --git a/nebtestkit/cases/contract/contract.feature.random.test.js b/nebtestkit/cases/contract/contract.feature.random.test.js index dad9c35eb..9252ed3b8 100644 --- a/nebtestkit/cases/contract/contract.feature.random.test.js +++ b/nebtestkit/cases/contract/contract.feature.random.test.js @@ -322,7 +322,7 @@ var caseGroup = { canExcuteTx: false, toBalanceChange: "0", status: 0, - eventErr: "Call: Error: random seed must be a string" + eventErr: "Call: Error: input seed must be a string" } }, { diff --git a/nf/nvm/test/contract_accept_func_with_args.js b/nf/nvm/test/contract_accept_func_with_args.js index 7ab08cd57..87dcb602a 100644 --- a/nf/nvm/test/contract_accept_func_with_args.js +++ b/nf/nvm/test/contract_accept_func_with_args.js @@ -1,6 +1,34 @@ "use strict"; +var DepositeContent = function (text) { + if (text) { + var o = JSON.parse(text); + this.balance = new BigNumber(o.balance); + this.expiryHeight = new BigNumber(o.expiryHeight); + } else { + this.balance = new BigNumber(0); + this.expiryHeight = new BigNumber(0); + } +}; + +DepositeContent.prototype = { + toString: function () { + return JSON.stringify(this); + } +}; + +var BankVaultContract = function () { + LocalContractStorage.defineMapProperty(this, "bankVault", { + parse: function (text) { + return new DepositeContent(text); + }, + stringify: function (o) { + return o.toString(); + } + }); +}; + // save value to contract, only after height of block, users can takeout BankVaultContract.prototype = { init: function () { diff --git a/nf/nvm/test/contract_date_and_random.js b/nf/nvm/test/contract_date_and_random.js index e5cad9212..1e2a7c45b 100644 --- a/nf/nvm/test/contract_date_and_random.js +++ b/nf/nvm/test/contract_date_and_random.js @@ -22,7 +22,6 @@ Contract.prototype = { now: Date.now(), parse: Date.parse('04 Dec 1995 00:12:00 GMT'), getUTCDate: date.getUTCDate(), - timeZone: date.getTimezoneOffset(), toJSON: date.toJSON(), setFullYear: date2.toString(), height: Blockchain.block.height, @@ -51,6 +50,14 @@ Contract.prototype = { return data; }, + testDate2: function() { + var date = new Date(); + + Event.Trigger("Date.TZ", { + timezone: date.getTimezoneOffset() + }); + }, + testRandom: function(userseed) { var r1 = Math.random(); var r12 = Math.random();