modified test to use async await pattern.
This commit is contained in:
@ -4,6 +4,9 @@
|
|||||||
"description": "Secure Smart Contract library for Solidity",
|
"description": "Secure Smart Contract library for Solidity",
|
||||||
"main": "truffle.js",
|
"main": "truffle.js",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"babel-preset-es2015": "^6.18.0",
|
||||||
|
"babel-preset-stage-2": "^6.18.0",
|
||||||
|
"babel-preset-stage-3": "^6.17.0",
|
||||||
"ethereumjs-testrpc": "^3.0.2",
|
"ethereumjs-testrpc": "^3.0.2",
|
||||||
"truffle": "^2.1.1"
|
"truffle": "^2.1.1"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,49 +1,29 @@
|
|||||||
contract('BasicToken', function(accounts) {
|
contract('BasicToken', function(accounts) {
|
||||||
|
|
||||||
it("should return the correct totalSupply after construction", function(done) {
|
it("should return the correct totalSupply after construction", async function() {
|
||||||
return BasicTokenMock.new(accounts[0], 100)
|
let token = await BasicTokenMock.new(accounts[0], 100);
|
||||||
.then(function(token) {
|
let totalSupply = await token.totalSupply();
|
||||||
return token.totalSupply();
|
assert.equal(totalSupply, 100);
|
||||||
})
|
|
||||||
.then(function(totalSupply) {
|
|
||||||
assert.equal(totalSupply, 100);
|
|
||||||
})
|
|
||||||
.then(done);
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should return correct balances after transfer", function(done) {
|
it("should return correct balances after transfer", async function(){
|
||||||
var token;
|
let token = await BasicTokenMock.new(accounts[0], 100);
|
||||||
return BasicTokenMock.new(accounts[0], 100)
|
let transfer = await token.transfer(accounts[1], 100);
|
||||||
.then(function(_token) {
|
let firstAccountBalance = await token.balanceOf(accounts[0]);
|
||||||
token = _token;
|
assert.equal(firstAccountBalance, 0);
|
||||||
return token.transfer(accounts[1], 100);
|
let secondAccountBalance = await token.balanceOf(accounts[1]);
|
||||||
})
|
assert.equal(secondAccountBalance, 100);
|
||||||
.then(function() {
|
|
||||||
return token.balanceOf(accounts[0]);
|
|
||||||
})
|
|
||||||
.then(function(balance) {
|
|
||||||
assert.equal(balance, 0);
|
|
||||||
})
|
|
||||||
.then(function() {
|
|
||||||
return token.balanceOf(accounts[1]);
|
|
||||||
})
|
|
||||||
.then(function(balance) {
|
|
||||||
assert.equal(balance, 100);
|
|
||||||
})
|
|
||||||
.then(done);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should throw an error when trying to transfer more than balance", function(done) {
|
it("should throw an error when trying to transfer more than balance", async function() {
|
||||||
var token;
|
|
||||||
return BasicTokenMock.new(accounts[0], 100)
|
let token = await BasicTokenMock.new(accounts[0], 100);
|
||||||
.then(function(_token) {
|
try {
|
||||||
token = _token;
|
let transfer = await token.transfer(accounts[1], 101);
|
||||||
return token.transfer(accounts[1], 101);
|
} catch(error) {
|
||||||
})
|
if (error.message.search('invalid JUMP') === -1) throw error
|
||||||
.catch(function(error) {
|
assert.isAbove(error.message.search('invalid JUMP'), -1, 'Invalid JUMP error must be returned');
|
||||||
if (error.message.search('invalid JUMP') == -1) throw error
|
}
|
||||||
})
|
|
||||||
.then(done);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
188
test/Bounty.js
188
test/Bounty.js
@ -1,4 +1,4 @@
|
|||||||
var sendReward = function(sender, receiver, value){
|
let sendReward = function(sender, receiver, value){
|
||||||
web3.eth.sendTransaction({
|
web3.eth.sendTransaction({
|
||||||
from:sender,
|
from:sender,
|
||||||
to:receiver,
|
to:receiver,
|
||||||
@ -8,134 +8,100 @@ var sendReward = function(sender, receiver, value){
|
|||||||
|
|
||||||
contract('Bounty', function(accounts) {
|
contract('Bounty', function(accounts) {
|
||||||
|
|
||||||
it("sets reward", function(done){
|
it("sets reward", async function(){
|
||||||
var owner = accounts[0];
|
let owner = accounts[0];
|
||||||
var reward = web3.toWei(1, "ether");
|
let reward = web3.toWei(1, "ether");
|
||||||
|
|
||||||
SecureTargetBounty.new().
|
let bounty = await SecureTargetBounty.new();
|
||||||
then(function(bounty){
|
sendReward(owner, bounty.address, reward);
|
||||||
sendReward(owner, bounty.address, reward);
|
assert.equal(reward, web3.eth.getBalance(bounty.address).toNumber())
|
||||||
assert.equal(reward, web3.eth.getBalance(bounty.address).toNumber())
|
|
||||||
}).
|
|
||||||
then(done);
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it("empties itself when killed", function(done){
|
it("empties itself when killed", async function(){
|
||||||
var owner = accounts[0];
|
let owner = accounts[0];
|
||||||
var reward = web3.toWei(1, "ether");
|
let reward = web3.toWei(1, "ether");
|
||||||
var bounty;
|
|
||||||
|
|
||||||
SecureTargetBounty.new().
|
let bounty = await SecureTargetBounty.new();
|
||||||
then(function(_bounty){
|
sendReward(owner, bounty.address, reward);
|
||||||
bounty = _bounty;
|
assert.equal(reward, web3.eth.getBalance(bounty.address).toNumber())
|
||||||
sendReward(owner, bounty.address, reward);
|
await bounty.kill();
|
||||||
assert.equal(reward, web3.eth.getBalance(bounty.address).toNumber())
|
assert.equal(0, web3.eth.getBalance(bounty.address).toNumber())
|
||||||
return bounty.kill()
|
|
||||||
}).
|
|
||||||
then(function(){
|
|
||||||
assert.equal(0, web3.eth.getBalance(bounty.address).toNumber())
|
|
||||||
}).
|
|
||||||
then(done);
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("Against secure contract", function(){
|
describe("Against secure contract", function(){
|
||||||
it("checkInvariant returns true", function(done){
|
it("checkInvariant returns true", async function(){
|
||||||
var bounty;
|
|
||||||
|
|
||||||
SecureTargetBounty.new().
|
let bounty = await SecureTargetBounty.new();
|
||||||
then(function(_bounty) {
|
let target = await bounty.createTarget();
|
||||||
bounty = _bounty;
|
let check = await bounty.checkInvariant.call();
|
||||||
return bounty.createTarget();
|
assert.isTrue(check);
|
||||||
}).
|
|
||||||
then(function() {
|
|
||||||
return bounty.checkInvariant.call()
|
|
||||||
}).
|
|
||||||
then(function(result) {
|
|
||||||
assert.isTrue(result);
|
|
||||||
}).
|
|
||||||
then(done);
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it("cannot claim reward", function(done){
|
it("cannot claim reward", async function(done){
|
||||||
var owner = accounts[0];
|
let owner = accounts[0];
|
||||||
var researcher = accounts[1];
|
let researcher = accounts[1];
|
||||||
var reward = web3.toWei(1, "ether");
|
let reward = web3.toWei(1, "ether");
|
||||||
|
|
||||||
SecureTargetBounty.new().
|
let bounty = await SecureTargetBounty.new();
|
||||||
then(function(bounty) {
|
let event = bounty.TargetCreated({});
|
||||||
var event = bounty.TargetCreated({});
|
|
||||||
event.watch(function(err, result) {
|
event.watch(async function(err, result) {
|
||||||
event.stopWatching();
|
event.stopWatching();
|
||||||
if (err) { throw err }
|
if (err) { throw err }
|
||||||
var targetAddress = result.args.createdAddress;
|
var targetAddress = result.args.createdAddress;
|
||||||
sendReward(owner, bounty.address, reward);
|
sendReward(owner, bounty.address, reward);
|
||||||
assert.equal(reward, web3.eth.getBalance(bounty.address).toNumber())
|
assert.equal(reward, web3.eth.getBalance(bounty.address).toNumber())
|
||||||
bounty.claim(targetAddress, {from:researcher}).
|
|
||||||
then(function(){ throw("should not come here")}).
|
try {
|
||||||
catch(function() {
|
let tmpClain = await bounty.claim(targetAddress, {from:researcher});
|
||||||
return bounty.claimed.call();
|
done("should not come here");
|
||||||
}).
|
} catch(error) {
|
||||||
then(function(result) {
|
let reClaimedBounty = await bounty.claimed.call();
|
||||||
assert.isFalse(result);
|
assert.isFalse(reClaimedBounty);
|
||||||
bounty.withdrawPayments({from:researcher}).
|
try {
|
||||||
then(function(){ throw("should not come here")}).
|
let withdraw = await bounty.withdrawPayments({from:researcher});
|
||||||
catch(function() {
|
done("should not come here")
|
||||||
assert.equal(reward, web3.eth.getBalance(bounty.address).toNumber())
|
} catch (err) {
|
||||||
done();
|
assert.equal(reward, web3.eth.getBalance(bounty.address).toNumber())
|
||||||
})
|
}
|
||||||
})
|
done();
|
||||||
})
|
}//end of first try catch
|
||||||
bounty.createTarget({from:researcher});
|
});
|
||||||
})
|
bounty.createTarget({from:researcher});
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("Against broken contract", function(){
|
describe("Against broken contract", function(){
|
||||||
it("checkInvariant returns false", function(done){
|
it("checkInvariant returns false", async function(){
|
||||||
var bounty;
|
let bounty = await InsecureTargetBounty.new();
|
||||||
|
let target = await bounty.createTarget();
|
||||||
InsecureTargetBounty.new().
|
let invarriantCall = await bounty.checkInvariant.call();
|
||||||
then(function(_bounty) {
|
assert.isFalse(invarriantCall);
|
||||||
bounty = _bounty;
|
|
||||||
return bounty.createTarget();
|
|
||||||
}).
|
|
||||||
then(function() {
|
|
||||||
return bounty.checkInvariant.call()
|
|
||||||
}).
|
|
||||||
then(function(result) {
|
|
||||||
assert.isFalse(result);
|
|
||||||
}).
|
|
||||||
then(done);
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it("claims reward", function(done){
|
it("claims reward", async function(){
|
||||||
var owner = accounts[0];
|
let owner = accounts[0];
|
||||||
var researcher = accounts[1];
|
let researcher = accounts[1];
|
||||||
var reward = web3.toWei(1, "ether");
|
let reward = web3.toWei(1, "ether");
|
||||||
|
|
||||||
InsecureTargetBounty.new().
|
let bounty = await InsecureTargetBounty.new();
|
||||||
then(function(bounty) {
|
|
||||||
var event = bounty.TargetCreated({});
|
let event = bounty.TargetCreated({});
|
||||||
event.watch(function(err, result) {
|
|
||||||
event.stopWatching();
|
event.watch(async function(err, result) {
|
||||||
if (err) { throw err }
|
event.stopWatching();
|
||||||
var targetAddress = result.args.createdAddress;
|
if (err) { throw err }
|
||||||
sendReward(owner, bounty.address, reward);
|
let targetAddress = result.args.createdAddress;
|
||||||
assert.equal(reward, web3.eth.getBalance(bounty.address).toNumber())
|
sendReward(owner, bounty.address, reward);
|
||||||
bounty.claim(targetAddress, {from:researcher}).
|
assert.equal(reward, web3.eth.getBalance(bounty.address).toNumber());
|
||||||
then(function() {
|
|
||||||
return bounty.claimed.call();
|
let bountyClaim = await bounty.claim(targetAddress, {from:researcher});
|
||||||
}).
|
let claim = await bounty.claimed.call();
|
||||||
then(function(result) {
|
assert.isTrue(claim);
|
||||||
assert.isTrue(result);
|
let payment = await bounty.withdrawPayments({from:researcher});
|
||||||
return bounty.withdrawPayments({from:researcher})
|
assert.equal(0, web3.eth.getBalance(bounty.address).toNumber());
|
||||||
}).
|
})
|
||||||
then(function() {
|
bounty.createTarget({from:researcher});
|
||||||
assert.equal(0, web3.eth.getBalance(bounty.address).toNumber())
|
|
||||||
}).then(done);
|
|
||||||
})
|
|
||||||
bounty.createTarget({from:researcher});
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,71 +1,46 @@
|
|||||||
contract('Claimable', function(accounts) {
|
contract('Claimable', function(accounts) {
|
||||||
var claimable;
|
var claimable;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(async function() {
|
||||||
return Claimable.new().then(function(deployed) {
|
claimable = await Claimable.new();
|
||||||
claimable = deployed;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should have an owner", function(done) {
|
it("should have an owner", async function() {
|
||||||
return claimable.owner()
|
let owner = await claimable.owner();
|
||||||
.then(function(owner) {
|
assert.isTrue(owner != 0);
|
||||||
assert.isTrue(owner != 0);
|
|
||||||
})
|
|
||||||
.then(done)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("changes pendingOwner after transfer", function(done) {
|
it("changes pendingOwner after transfer", async function() {
|
||||||
var newOwner = accounts[1];
|
let newOwner = accounts[1];
|
||||||
return claimable.transfer(newOwner)
|
let transfer = await claimable.transfer(newOwner);
|
||||||
.then(function() {
|
let pendingOwner = await claimable.pendingOwner();
|
||||||
return claimable.pendingOwner();
|
assert.isTrue(pendingOwner === newOwner);
|
||||||
})
|
|
||||||
.then(function(pendingOwner) {
|
|
||||||
assert.isTrue(pendingOwner === newOwner);
|
|
||||||
})
|
|
||||||
.then(done)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should prevent to claimOwnership from no pendingOwner", function(done) {
|
it("should prevent to claimOwnership from no pendingOwner", async function() {
|
||||||
return claimable.claimOwnership({from: accounts[2]})
|
let claimedOwner = await claimable.claimOwnership({from: accounts[2]});
|
||||||
.then(function() {
|
let owner = await claimable.owner();
|
||||||
return claimable.owner();
|
assert.isTrue(owner != accounts[2]);
|
||||||
})
|
|
||||||
.then(function(owner) {
|
|
||||||
assert.isTrue(owner != accounts[2]);
|
|
||||||
})
|
|
||||||
.then(done)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should prevent non-owners from transfering" ,function(done) {
|
it("should prevent non-owners from transfering", async function() {
|
||||||
return claimable.transfer(accounts[2], {from: accounts[2]})
|
let transfer = await claimable.transfer(accounts[2], {from: accounts[2]});
|
||||||
.then(function() {
|
let pendingOwner = await claimable.pendingOwner();
|
||||||
return claimable.pendingOwner();
|
assert.isFalse(pendingOwner === accounts[2]);
|
||||||
})
|
|
||||||
.then(function(pendingOwner) {
|
|
||||||
assert.isFalse(pendingOwner === accounts[2]);
|
|
||||||
})
|
|
||||||
.then(done)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("after initiating a transfer", function () {
|
describe("after initiating a transfer", function () {
|
||||||
var newOwner;
|
let newOwner;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
newOwner = accounts[1];
|
newOwner = accounts[1];
|
||||||
return claimable.transfer(newOwner);
|
return claimable.transfer(newOwner);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("changes allow pending owner to claim ownership", function(done) {
|
it("changes allow pending owner to claim ownership", async function() {
|
||||||
return claimable.claimOwnership({from: newOwner})
|
let claimedOwner = await claimable.claimOwnership({from: newOwner})
|
||||||
.then(function() {
|
let owner = await claimable.owner();
|
||||||
return claimable.owner();
|
assert.isTrue(owner === newOwner);
|
||||||
})
|
|
||||||
.then(function(owner) {
|
|
||||||
assert.isTrue(owner === newOwner);
|
|
||||||
})
|
|
||||||
.then(done)
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -32,38 +32,24 @@ contract('Killable', function(accounts) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
it("should send balance to owner after death", function(done) {
|
it("should send balance to owner after death", async function() {
|
||||||
var initBalance, newBalance, owner, address, killable, kBalance;
|
let initBalance, newBalance, owner, address, killable, kBalance, txnHash, receiptMined;
|
||||||
web3.eth.sendTransaction({from: web3.eth.coinbase, to: accounts[0], value: web3.toWei('50','ether')}, function(err, result) {
|
web3.eth.sendTransaction({from: web3.eth.coinbase, to: accounts[0], value: web3.toWei('50','ether')}, function(err, result) {
|
||||||
if(err)
|
if(err)
|
||||||
console.log("ERROR:" + err);
|
console.log("ERROR:" + err);
|
||||||
else {
|
else {
|
||||||
console.log(result);
|
console.log(result);
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
return Killable.new({from: accounts[0], value: web3.toWei('10','ether')})
|
|
||||||
.then(function(_killable) {
|
killable = await Killable.new({from: accounts[0], value: web3.toWei('10','ether')});
|
||||||
killable = _killable;
|
owner = await killable.owner();
|
||||||
return killable.owner();
|
initBalance = web3.eth.getBalance(owner);
|
||||||
})
|
kBalance = web3.eth.getBalance(killable.address);
|
||||||
.then(function(_owner) {
|
txnHash = await killable.kill({from: owner});
|
||||||
owner = _owner;
|
receiptMined = await web3.eth.getTransactionReceiptMined(txnHash);
|
||||||
initBalance = web3.eth.getBalance(owner);
|
newBalance = web3.eth.getBalance(owner);
|
||||||
kBalance = web3.eth.getBalance(killable.address);
|
assert.isTrue(newBalance > initBalance);
|
||||||
})
|
|
||||||
.then(function() {
|
|
||||||
return killable.kill({from: owner});
|
|
||||||
})
|
|
||||||
.then(function (txnHash) {
|
|
||||||
return web3.eth.getTransactionReceiptMined(txnHash);
|
|
||||||
})
|
|
||||||
.then(function() {
|
|
||||||
newBalance = web3.eth.getBalance(owner);
|
|
||||||
})
|
|
||||||
.then(function() {
|
|
||||||
assert.isTrue(newBalance > initBalance);
|
|
||||||
})
|
|
||||||
.then(done);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,64 +1,55 @@
|
|||||||
contract('LimitBalance', function(accounts) {
|
contract('LimitBalance', function(accounts) {
|
||||||
var lb;
|
var lb;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(async function() {
|
||||||
return LimitBalanceMock.new().then(function(deployed) {
|
lb = await LimitBalanceMock.new();
|
||||||
lb = deployed;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var LIMIT = 1000;
|
let LIMIT = 1000;
|
||||||
|
|
||||||
it("should expose limit", function(done) {
|
it("should expose limit", async function() {
|
||||||
return lb.limit()
|
let limit = await lb.limit();
|
||||||
.then(function(limit) {
|
assert.equal(limit, LIMIT);
|
||||||
assert.equal(limit, LIMIT);
|
|
||||||
})
|
|
||||||
.then(done)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should allow sending below limit", function(done) {
|
it("should allow sending below limit", async function() {
|
||||||
var amount = 1;
|
let amount = 1;
|
||||||
return lb.limitedDeposit({value: amount})
|
let limDeposit = await lb.limitedDeposit({value: amount});
|
||||||
.then(function() {
|
assert.equal(web3.eth.getBalance(lb.address), amount);
|
||||||
assert.equal(web3.eth.getBalance(lb.address), amount);
|
|
||||||
})
|
|
||||||
.then(done)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("shouldnt allow sending above limit", function(done) {
|
it("shouldnt allow sending above limit", async function() {
|
||||||
var amount = 1100;
|
|
||||||
return lb.limitedDeposit({value: amount})
|
let amount = 1110;
|
||||||
.catch(function(error) {
|
try {
|
||||||
if (error.message.search('invalid JUMP') == -1) throw error
|
let limDeposit = await lb.limitedDeposit({value: amount});
|
||||||
})
|
} catch(error) {
|
||||||
.then(done)
|
if (error.message.search('invalid JUMP') == -1) throw error
|
||||||
|
assert.isAbove(error.message.search('invalid JUMP'), -1, 'Invalid JUMP error must be returned');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should allow multiple sends below limit", function(done) {
|
it("should allow multiple sends below limit", async function() {
|
||||||
var amount = 500;
|
let amount = 500;
|
||||||
return lb.limitedDeposit({value: amount})
|
|
||||||
.then(function() {
|
let limDeposit = await lb.limitedDeposit({value: amount});
|
||||||
assert.equal(web3.eth.getBalance(lb.address), amount);
|
assert.equal(web3.eth.getBalance(lb.address), amount);
|
||||||
return lb.limitedDeposit({value: amount})
|
let limDeposit2 = await lb.limitedDeposit({value: amount});
|
||||||
})
|
assert.equal(web3.eth.getBalance(lb.address), amount*2);
|
||||||
.then(function() {
|
|
||||||
assert.equal(web3.eth.getBalance(lb.address), amount*2);
|
|
||||||
})
|
|
||||||
.then(done)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("shouldnt allow multiple sends above limit", function(done) {
|
it("shouldnt allow multiple sends above limit", async function() {
|
||||||
var amount = 500;
|
let amount = 500;
|
||||||
return lb.limitedDeposit({value: amount})
|
|
||||||
.then(function() {
|
|
||||||
assert.equal(web3.eth.getBalance(lb.address), amount);
|
let limDeposit = await lb.limitedDeposit({value: amount});
|
||||||
return lb.limitedDeposit({value: amount+1})
|
assert.equal(web3.eth.getBalance(lb.address), amount);
|
||||||
})
|
try {
|
||||||
.catch(function(error) {
|
lb.limitedDeposit({value: amount+1})
|
||||||
if (error.message.search('invalid JUMP') == -1) throw error;
|
} catch(error) {
|
||||||
})
|
if (error.message.search('invalid JUMP') == -1) throw error
|
||||||
.then(done)
|
assert.isAbove(error.message.search('invalid JUMP'), -1, 'Invalid JUMP error must be returned');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,58 +1,35 @@
|
|||||||
contract('Ownable', function(accounts) {
|
contract('Ownable', function(accounts) {
|
||||||
var ownable;
|
var ownable;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(async function() {
|
||||||
return Ownable.new().then(function(deployed) {
|
ownable = await Ownable.new();
|
||||||
ownable = deployed;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should have an owner", function(done) {
|
it("should have an owner", async function() {
|
||||||
return ownable.owner()
|
let owner = await ownable.owner();
|
||||||
.then(function(owner) {
|
assert.isTrue(owner != 0);
|
||||||
assert.isTrue(owner != 0);
|
|
||||||
})
|
|
||||||
.then(done)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("changes owner after transfer", function(done) {
|
it("changes owner after transfer", async function() {
|
||||||
var other = accounts[1];
|
let other = accounts[1];
|
||||||
return ownable.transfer(other)
|
let transfer = await ownable.transfer(other);
|
||||||
.then(function() {
|
let owner = await ownable.owner();
|
||||||
return ownable.owner();
|
assert.isTrue(owner === other);
|
||||||
})
|
|
||||||
.then(function(owner) {
|
|
||||||
assert.isTrue(owner === other);
|
|
||||||
})
|
|
||||||
.then(done)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should prevent non-owners from transfering" ,function(done) {
|
it("should prevent non-owners from transfering", async function() {
|
||||||
var other = accounts[2];
|
let other = accounts[2];
|
||||||
return ownable.transfer(other, {from: accounts[2]})
|
let transfer = await ownable.transfer(other, {from: accounts[2]});
|
||||||
.then(function() {
|
let owner = await ownable.owner();
|
||||||
return ownable.owner();
|
assert.isFalse(owner === other);
|
||||||
})
|
|
||||||
.then(function(owner) {
|
|
||||||
assert.isFalse(owner === other);
|
|
||||||
})
|
|
||||||
.then(done)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should guard ownership against stuck state" ,function(done) {
|
it("should guard ownership against stuck state", async function() {
|
||||||
var ownable = Ownable.deployed();
|
let ownable = Ownable.deployed();
|
||||||
|
let originalOwner = await ownable.owner();
|
||||||
return ownable.owner()
|
let transfer = await ownable.transfer(null, {from: originalOwner});
|
||||||
.then(function (originalOwner) {
|
let newOwner = await ownable.owner();
|
||||||
return ownable.transfer(null, {from: originalOwner})
|
assert.equal(originalOwner, newOwner);
|
||||||
.then(function() {
|
|
||||||
return ownable.owner();
|
|
||||||
})
|
|
||||||
.then(function(newOwner) {
|
|
||||||
assert.equal(originalOwner, newOwner);
|
|
||||||
})
|
|
||||||
.then(done);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,102 +1,50 @@
|
|||||||
contract('PullPayment', function(accounts) {
|
contract('PullPayment', function(accounts) {
|
||||||
|
|
||||||
it("can't call asyncSend externally", function(done) {
|
it("can't call asyncSend externally", async function() {
|
||||||
return PullPaymentMock.new()
|
let ppc = await PullPaymentMock.new();
|
||||||
.then(function(ppc) {
|
assert.isUndefined(ppc.asyncSend);
|
||||||
assert.isUndefined(ppc.asyncSend);
|
|
||||||
})
|
|
||||||
.then(done);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can record an async payment correctly", function(done) {
|
it("can record an async payment correctly", async function() {
|
||||||
var ppce;
|
let AMOUNT = 100;
|
||||||
var AMOUNT = 100;
|
let ppce = await PullPaymentMock.new();
|
||||||
return PullPaymentMock.new()
|
let callSend = await ppce.callSend(accounts[0], AMOUNT);
|
||||||
.then(function(_ppce) {
|
let paymentsToAccount0 = await ppce.payments(accounts[0]);
|
||||||
ppce = _ppce;
|
assert.equal(paymentsToAccount0, AMOUNT);
|
||||||
ppce.callSend(accounts[0], AMOUNT)
|
|
||||||
})
|
|
||||||
.then(function() {
|
|
||||||
return ppce.payments(accounts[0]);
|
|
||||||
})
|
|
||||||
.then(function(paymentsToAccount0) {
|
|
||||||
assert.equal(paymentsToAccount0, AMOUNT);
|
|
||||||
})
|
|
||||||
.then(done);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can add multiple balances on one account", function(done) {
|
it("can add multiple balances on one account", async function() {
|
||||||
var ppce;
|
let ppce = await PullPaymentMock.new();
|
||||||
return PullPaymentMock.new()
|
let call1 = await ppce.callSend(accounts[0], 200);
|
||||||
.then(function(_ppce) {
|
let call2 = await ppce.callSend(accounts[0], 300)
|
||||||
ppce = _ppce;
|
let paymentsToAccount0 = await ppce.payments(accounts[0]);
|
||||||
return ppce.callSend(accounts[0], 200)
|
assert.equal(paymentsToAccount0, 500);
|
||||||
})
|
|
||||||
.then(function() {
|
|
||||||
return ppce.callSend(accounts[0], 300)
|
|
||||||
})
|
|
||||||
.then(function() {
|
|
||||||
return ppce.payments(accounts[0]);
|
|
||||||
})
|
|
||||||
.then(function(paymentsToAccount0) {
|
|
||||||
assert.equal(paymentsToAccount0, 500);
|
|
||||||
})
|
|
||||||
.then(done);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can add balances on multiple accounts", function(done) {
|
it("can add balances on multiple accounts", async function() {
|
||||||
var ppce;
|
let ppce = await PullPaymentMock.new();
|
||||||
return PullPaymentMock.new()
|
let call1 = await ppce.callSend(accounts[0], 200);
|
||||||
.then(function(_ppce) {
|
let call2 = await ppce.callSend(accounts[1], 300);
|
||||||
ppce = _ppce;
|
let paymentsToAccount0 = await ppce.payments(accounts[0]);
|
||||||
return ppce.callSend(accounts[0], 200)
|
assert.equal(paymentsToAccount0, 200);
|
||||||
})
|
let paymentsToAccount1 = await ppce.payments(accounts[1]);
|
||||||
.then(function() {
|
assert.equal(paymentsToAccount1, 300);
|
||||||
return ppce.callSend(accounts[1], 300)
|
|
||||||
})
|
|
||||||
.then(function() {
|
|
||||||
return ppce.payments(accounts[0]);
|
|
||||||
})
|
|
||||||
.then(function(paymentsToAccount0) {
|
|
||||||
assert.equal(paymentsToAccount0, 200);
|
|
||||||
})
|
|
||||||
.then(function() {
|
|
||||||
return ppce.payments(accounts[1]);
|
|
||||||
})
|
|
||||||
.then(function(paymentsToAccount0) {
|
|
||||||
assert.equal(paymentsToAccount0, 300);
|
|
||||||
})
|
|
||||||
.then(done);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can withdraw payment", function(done) {
|
it("can withdraw payment", async function() {
|
||||||
var ppce;
|
let AMOUNT = 17*1e18;
|
||||||
var AMOUNT = 17*1e18;
|
let payee = accounts[1];
|
||||||
var payee = accounts[1];
|
let initialBalance = web3.eth.getBalance(payee);
|
||||||
var initialBalance = web3.eth.getBalance(payee);
|
|
||||||
return PullPaymentMock.new({value: AMOUNT})
|
let ppce = await PullPaymentMock.new({value: AMOUNT});
|
||||||
.then(function(_ppce) {
|
let call1 = await ppce.callSend(payee, AMOUNT);
|
||||||
ppce = _ppce;
|
let payment1 = await ppce.payments(payee);
|
||||||
return ppce.callSend(payee, AMOUNT);
|
assert.equal(payment1, AMOUNT);
|
||||||
})
|
let withdraw = await ppce.withdrawPayments({from: payee});
|
||||||
.then(function() {
|
let payment2 = await ppce.payments(payee);
|
||||||
return ppce.payments(payee);
|
assert.equal(payment2, 0);
|
||||||
})
|
let balance = web3.eth.getBalance(payee);
|
||||||
.then(function(paymentsToAccount0) {
|
assert(Math.abs(balance-initialBalance-AMOUNT) < 1e16);
|
||||||
assert.equal(paymentsToAccount0, AMOUNT);
|
|
||||||
})
|
|
||||||
.then(function() {
|
|
||||||
return ppce.withdrawPayments({from: payee});
|
|
||||||
})
|
|
||||||
.then(function() {
|
|
||||||
return ppce.payments(payee);
|
|
||||||
})
|
|
||||||
.then(function(paymentsToAccount0) {
|
|
||||||
assert.equal(paymentsToAccount0, 0);
|
|
||||||
var balance = web3.eth.getBalance(payee);
|
|
||||||
assert(Math.abs(balance-initialBalance-AMOUNT) < 1e16);
|
|
||||||
})
|
|
||||||
.then(done);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
109
test/SafeMath.js
109
test/SafeMath.js
@ -3,80 +3,65 @@ contract('SafeMath', function(accounts) {
|
|||||||
|
|
||||||
var safeMath;
|
var safeMath;
|
||||||
|
|
||||||
before(function() {
|
before(async function() {
|
||||||
return SafeMathMock.new()
|
safeMath = await SafeMathMock.new();
|
||||||
.then(function(_safeMath) {
|
|
||||||
safeMath = _safeMath;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("multiplies correctly", function(done) {
|
it("multiplies correctly", async function() {
|
||||||
var a = 5678;
|
let a = 5678;
|
||||||
var b = 1234;
|
let b = 1234;
|
||||||
return safeMath.multiply(a, b)
|
let mult = await safeMath.multiply(a, b);
|
||||||
.then(function() {
|
let result = await safeMath.result();
|
||||||
return safeMath.result();
|
assert.equal(result, a*b);
|
||||||
})
|
|
||||||
.then(function(result) {
|
|
||||||
assert.equal(result, a*b);
|
|
||||||
})
|
|
||||||
.then(done);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("adds correctly", function(done) {
|
it("adds correctly", async function() {
|
||||||
var a = 5678;
|
let a = 5678;
|
||||||
var b = 1234;
|
let b = 1234;
|
||||||
return safeMath.add(a, b)
|
let add = await safeMath.add(a, b);
|
||||||
.then(function() {
|
let result = await safeMath.result();
|
||||||
return safeMath.result();
|
assert.equal(result, a+b);
|
||||||
})
|
|
||||||
.then(function(result) {
|
|
||||||
assert.equal(result, a+b);
|
|
||||||
})
|
|
||||||
.then(done);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("subtracts correctly", function(done) {
|
it("subtracts correctly", async function() {
|
||||||
var a = 5678;
|
let a = 5678;
|
||||||
var b = 1234;
|
let b = 1234;
|
||||||
return safeMath.subtract(a, b)
|
let subtract = await safeMath.subtract(a, b);
|
||||||
.then(function() {
|
let result = await safeMath.result();
|
||||||
return safeMath.result();
|
assert.equal(result, a-b);
|
||||||
})
|
|
||||||
.then(function(result) {
|
|
||||||
assert.equal(result, a-b);
|
|
||||||
})
|
|
||||||
.then(done);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should throw an error if subtraction result would be negative", function (done) {
|
it("should throw an error if subtraction result would be negative", async function () {
|
||||||
var a = 1234;
|
let a = 1234;
|
||||||
var b = 5678;
|
let b = 5678;
|
||||||
return safeMath.subtract(a, b)
|
try {
|
||||||
.catch(function(error) {
|
let subtract = await safeMath.subtract(a, b);
|
||||||
if (error.message.search('invalid JUMP') == -1) throw error
|
} catch(error) {
|
||||||
})
|
if (error.message.search('invalid JUMP') == -1) throw error
|
||||||
.then(done);
|
assert.isAbove(error.message.search('invalid JUMP'), -1, 'Invalid JUMP error must be returned');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should throw an error on addition overflow", function(done) {
|
it("should throw an error on addition overflow", async function() {
|
||||||
var a = 115792089237316195423570985008687907853269984665640564039457584007913129639935;
|
let a = 115792089237316195423570985008687907853269984665640564039457584007913129639935;
|
||||||
var b = 1;
|
let b = 1;
|
||||||
return safeMath.add(a, b)
|
try {
|
||||||
.catch(function(error) {
|
let add = await safeMath.add(a, b);
|
||||||
if (error.message.search('invalid JUMP') == -1) throw error
|
} catch(error) {
|
||||||
})
|
if (error.message.search('invalid JUMP') == -1) throw error
|
||||||
.then(done);
|
assert.isAbove(error.message.search('invalid JUMP'), -1, 'Invalid JUMP error must be returned');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should throw an error on multiplication overflow", function(done) {
|
it("should throw an error on multiplication overflow", async function() {
|
||||||
var a = 115792089237316195423570985008687907853269984665640564039457584007913129639933;
|
let a = 115792089237316195423570985008687907853269984665640564039457584007913129639933;
|
||||||
var b = 2;
|
let b = 2;
|
||||||
return safeMath.multiply(a, b)
|
try {
|
||||||
.catch(function(error) {
|
let multiply = await safeMath.multiply(a, b);
|
||||||
if (error.message.search('invalid JUMP') == -1) throw error
|
} catch(error) {
|
||||||
})
|
if (error.message.search('invalid JUMP') == -1) throw error
|
||||||
.then(done);
|
assert.isAbove(error.message.search('invalid JUMP'), -1, 'Invalid JUMP error must be returned');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,108 +1,61 @@
|
|||||||
contract('StandardToken', function(accounts) {
|
contract('StandardToken', function(accounts) {
|
||||||
|
|
||||||
it("should return the correct totalSupply after construction", function(done) {
|
it("should return the correct totalSupply after construction", async function() {
|
||||||
return StandardTokenMock.new(accounts[0], 100)
|
let token = await StandardTokenMock.new(accounts[0], 100);
|
||||||
.then(function(token) {
|
let totalSupply = await token.totalSupply();
|
||||||
return token.totalSupply();
|
assert.equal(totalSupply, 100);
|
||||||
})
|
|
||||||
.then(function(totalSupply) {
|
|
||||||
assert.equal(totalSupply, 100);
|
|
||||||
})
|
|
||||||
.then(done);
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should return the correct allowance amount after approval", function(done) {
|
it("should return the correct allowance amount after approval", async function() {
|
||||||
var token;
|
let token = await StandardTokenMock.new();
|
||||||
return StandardTokenMock.new()
|
let approve = await token.approve(accounts[1], 100);
|
||||||
.then(function(_token) {
|
let allowance = await token.allowance(accounts[0], accounts[1]);
|
||||||
token = _token;
|
assert.equal(allowance, 100);
|
||||||
return token.approve(accounts[1], 100);
|
|
||||||
})
|
|
||||||
.then(function() {
|
|
||||||
return token.allowance(accounts[0], accounts[1]);
|
|
||||||
})
|
|
||||||
.then(function(allowance) {
|
|
||||||
assert.equal(allowance, 100);
|
|
||||||
})
|
|
||||||
.then(done);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return correct balances after transfer", function(done) {
|
it("should return correct balances after transfer", async function() {
|
||||||
var token;
|
let token = await StandardTokenMock.new(accounts[0], 100);
|
||||||
return StandardTokenMock.new(accounts[0], 100)
|
let transfer = await token.transfer(accounts[1], 100);
|
||||||
.then(function(_token) {
|
let balance0 = await token.balanceOf(accounts[0]);
|
||||||
token = _token;
|
assert.equal(balance0, 0);
|
||||||
return token.transfer(accounts[1], 100);
|
let balance1 = await token.balanceOf(accounts[1]);
|
||||||
})
|
assert.equal(balance1, 100);
|
||||||
.then(function() {
|
|
||||||
return token.balanceOf(accounts[0]);
|
|
||||||
})
|
|
||||||
.then(function(balance) {
|
|
||||||
assert.equal(balance, 0);
|
|
||||||
})
|
|
||||||
.then(function() {
|
|
||||||
return token.balanceOf(accounts[1]);
|
|
||||||
})
|
|
||||||
.then(function(balance) {
|
|
||||||
assert.equal(balance, 100);
|
|
||||||
})
|
|
||||||
.then(done);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should throw an error when trying to transfer more than balance", function(done) {
|
it("should throw an error when trying to transfer more than balance", async function() {
|
||||||
var token;
|
let token = await StandardTokenMock.new(accounts[0], 100);
|
||||||
return StandardTokenMock.new(accounts[0], 100)
|
try {
|
||||||
.then(function(_token) {
|
let transfer = await token.transfer(accounts[1], 101);
|
||||||
token = _token;
|
} catch(error) {
|
||||||
return token.transfer(accounts[1], 101);
|
if (error.message.search('invalid JUMP') == -1) throw error
|
||||||
})
|
assert.isAbove(error.message.search('invalid JUMP'), -1, 'Invalid JUMP error must be returned');
|
||||||
.catch(function(error) {
|
}
|
||||||
if (error.message.search('invalid JUMP') == -1) throw error
|
|
||||||
})
|
|
||||||
.then(done);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return correct balances after transfering from another account", function(done) {
|
it("should return correct balances after transfering from another account", async function() {
|
||||||
var token;
|
let token = await StandardTokenMock.new(accounts[0], 100);
|
||||||
return StandardTokenMock.new(accounts[0], 100)
|
let approve = await token.approve(accounts[1], 100);
|
||||||
.then(function(_token) {
|
let transferFrom = await token.transferFrom(accounts[0], accounts[2], 100, {from: accounts[1]});
|
||||||
token = _token;
|
|
||||||
return token.approve(accounts[1], 100);
|
let balance0 = await token.balanceOf(accounts[0]);
|
||||||
})
|
assert.equal(balance0, 0);
|
||||||
.then(function() {
|
|
||||||
return token.transferFrom(accounts[0], accounts[2], 100, {from: accounts[1]});
|
let balance1 = await token.balanceOf(accounts[2]);
|
||||||
})
|
assert.equal(balance1, 100);
|
||||||
.then(function() {
|
|
||||||
return token.balanceOf(accounts[0]);
|
let balance2 = await token.balanceOf(accounts[1]);
|
||||||
})
|
assert.equal(balance2, 0);
|
||||||
.then(function(balance) {
|
|
||||||
assert.equal(balance, 0);
|
|
||||||
return token.balanceOf(accounts[2]);
|
|
||||||
})
|
|
||||||
.then(function(balance) {
|
|
||||||
assert.equal(balance, 100)
|
|
||||||
return token.balanceOf(accounts[1]);
|
|
||||||
})
|
|
||||||
.then(function(balance) {
|
|
||||||
assert.equal(balance, 0);
|
|
||||||
})
|
|
||||||
.then(done);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should throw an error when trying to transfer more than allowed", function(done) {
|
it("should throw an error when trying to transfer more than allowed", async function() {
|
||||||
var token;
|
let token = await StandardTokenMock.new();
|
||||||
return StandardTokenMock.new(accounts[0], 100)
|
let approve = await token.approve(accounts[1], 99);
|
||||||
.then(function(_token) {
|
try {
|
||||||
token = _token;
|
let transfer = await token.transferFrom(accounts[0], accounts[2], 100, {from: accounts[1]});
|
||||||
return token.approve(accounts[1], 99);
|
} catch (error) {
|
||||||
})
|
if (error.message.search('invalid JUMP') == -1) throw error
|
||||||
.then(function() {
|
assert.isAbove(error.message.search('invalid JUMP'), -1, 'Invalid JUMP error must be returned');
|
||||||
return token.transferFrom(accounts[0], accounts[2], 100, {from: accounts[1]});
|
}
|
||||||
})
|
|
||||||
.catch(function(error) {
|
|
||||||
if (error.message.search('invalid JUMP') == -1) throw error
|
|
||||||
})
|
|
||||||
.then(done);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,108 +1,47 @@
|
|||||||
contract('Stoppable', function(accounts) {
|
contract('Stoppable', function(accounts) {
|
||||||
|
|
||||||
it("can perform normal process in non-emergency", function(done) {
|
it("can perform normal process in non-emergency", async function() {
|
||||||
var stoppable;
|
let stoppable = await StoppableMock.new();
|
||||||
return StoppableMock.new()
|
let count0 = await stoppable.count();
|
||||||
.then(function(_stoppable) {
|
assert.equal(count0, 0);
|
||||||
stoppable = _stoppable;
|
let normalProcess = await stoppable.normalProcess();
|
||||||
return stoppable.count();
|
let count1 = await stoppable.count();
|
||||||
})
|
assert.equal(count1, 1);
|
||||||
.then(function(count) {
|
|
||||||
assert.equal(count, 0);
|
|
||||||
})
|
|
||||||
.then(function () {
|
|
||||||
return stoppable.normalProcess();
|
|
||||||
})
|
|
||||||
.then(function() {
|
|
||||||
return stoppable.count();
|
|
||||||
})
|
|
||||||
.then(function(count) {
|
|
||||||
assert.equal(count, 1);
|
|
||||||
})
|
|
||||||
.then(done);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can not perform normal process in emergency", function(done) {
|
it("can not perform normal process in emergency", async function() {
|
||||||
var stoppable;
|
let stoppable = await StoppableMock.new();
|
||||||
return StoppableMock.new()
|
let emergencyStop = await stoppable.emergencyStop();
|
||||||
.then(function(_stoppable) {
|
let count0 = await stoppable.count();
|
||||||
stoppable = _stoppable;
|
assert.equal(count0, 0);
|
||||||
return stoppable.emergencyStop();
|
let normalProcess = await stoppable.normalProcess();
|
||||||
})
|
let count1 = await stoppable.count();
|
||||||
.then(function () {
|
assert.equal(count1, 0);
|
||||||
return stoppable.count();
|
|
||||||
})
|
|
||||||
.then(function(count) {
|
|
||||||
assert.equal(count, 0);
|
|
||||||
})
|
|
||||||
.then(function () {
|
|
||||||
return stoppable.normalProcess();
|
|
||||||
})
|
|
||||||
.then(function() {
|
|
||||||
return stoppable.count();
|
|
||||||
})
|
|
||||||
.then(function(count) {
|
|
||||||
assert.equal(count, 0);
|
|
||||||
})
|
|
||||||
.then(done);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it("can not take drastic measure in non-emergency", function(done) {
|
it("can not take drastic measure in non-emergency", async function() {
|
||||||
var stoppable;
|
let stoppable = await StoppableMock.new();
|
||||||
return StoppableMock.new()
|
let drasticMeasure = await stoppable.drasticMeasure();
|
||||||
.then(function(_stoppable) {
|
let drasticMeasureTaken = await stoppable.drasticMeasureTaken();
|
||||||
stoppable = _stoppable;
|
assert.isFalse(drasticMeasureTaken);
|
||||||
return stoppable.drasticMeasure();
|
|
||||||
})
|
|
||||||
.then(function() {
|
|
||||||
return stoppable.drasticMeasureTaken();
|
|
||||||
})
|
|
||||||
.then(function(taken) {
|
|
||||||
assert.isFalse(taken);
|
|
||||||
})
|
|
||||||
.then(done);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can take a drastic measure in an emergency", function(done) {
|
it("can take a drastic measure in an emergency", async function() {
|
||||||
var stoppable;
|
let stoppable = await StoppableMock.new();
|
||||||
return StoppableMock.new()
|
let emergencyStop = await stoppable.emergencyStop();
|
||||||
.then(function(_stoppable) {
|
let drasticMeasure = await stoppable.drasticMeasure();
|
||||||
stoppable = _stoppable;
|
let drasticMeasureTaken = await stoppable.drasticMeasureTaken();
|
||||||
return stoppable.emergencyStop();
|
assert.isTrue(drasticMeasureTaken);
|
||||||
})
|
|
||||||
.then(function() {
|
|
||||||
return stoppable.drasticMeasure();
|
|
||||||
})
|
|
||||||
.then(function() {
|
|
||||||
return stoppable.drasticMeasureTaken();
|
|
||||||
})
|
|
||||||
.then(function(taken) {
|
|
||||||
assert.isTrue(taken);
|
|
||||||
})
|
|
||||||
.then(done);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should resume allowing normal process after emergency is over", function(done) {
|
it("should resume allowing normal process after emergency is over", async function() {
|
||||||
var stoppable;
|
let stoppable = await StoppableMock.new();
|
||||||
return StoppableMock.new()
|
let emergencyStop = await stoppable.emergencyStop();
|
||||||
.then(function(_stoppable) {
|
let release = await stoppable.release();
|
||||||
stoppable = _stoppable;
|
let normalProcess = await stoppable.normalProcess();
|
||||||
return stoppable.emergencyStop();
|
let count0 = await stoppable.count();
|
||||||
})
|
assert.equal(count0, 1);
|
||||||
.then(function () {
|
|
||||||
return stoppable.release();
|
|
||||||
})
|
|
||||||
.then(function() {
|
|
||||||
return stoppable.normalProcess();
|
|
||||||
})
|
|
||||||
.then(function() {
|
|
||||||
return stoppable.count();
|
|
||||||
})
|
|
||||||
.then(function(count) {
|
|
||||||
assert.equal(count, 1);
|
|
||||||
})
|
|
||||||
.then(done);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user