Skip to content

Commit

Permalink
contract: update test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
bibibong committed May 6, 2018
1 parent b2171e1 commit 40535a2
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
29 changes: 28 additions & 1 deletion nebtestkit/cases/contract/contract.feature.date.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down Expand Up @@ -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!"
}
}
]
};
Expand Down
2 changes: 1 addition & 1 deletion nebtestkit/cases/contract/contract.feature.random.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
},
{
Expand Down
28 changes: 28 additions & 0 deletions nf/nvm/test/contract_accept_func_with_args.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand Down
9 changes: 8 additions & 1 deletion nf/nvm/test/contract_date_and_random.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 40535a2

Please sign in to comment.