fix: made all the tests consistent. now with done.

pull/97/head
Angello Pozo 8 years ago
parent f2142545c7
commit 688106e9c3
  1. 9
      test/BasicToken.js
  2. 19
      test/Bounty.js
  3. 25
      test/Claimable.js
  4. 3
      test/Killable.js
  5. 23
      test/LimitBalance.js
  6. 17
      test/Ownable.js
  7. 15
      test/PullPayment.js
  8. 23
      test/SafeMath.js
  9. 18
      test/StandardToken.js
  10. 15
      test/Stoppable.js

@ -1,21 +1,23 @@
contract('BasicToken', function(accounts) { contract('BasicToken', function(accounts) {
it("should return the correct totalSupply after construction", async function() { it("should return the correct totalSupply after construction", async function(done) {
let token = await BasicTokenMock.new(accounts[0], 100); let token = await BasicTokenMock.new(accounts[0], 100);
let totalSupply = await token.totalSupply(); let totalSupply = await token.totalSupply();
assert.equal(totalSupply, 100); assert.equal(totalSupply, 100);
done();
}) })
it("should return correct balances after transfer", async function(){ it("should return correct balances after transfer", async function(done){
let token = await BasicTokenMock.new(accounts[0], 100); let token = await BasicTokenMock.new(accounts[0], 100);
let transfer = await token.transfer(accounts[1], 100); let transfer = await token.transfer(accounts[1], 100);
let firstAccountBalance = await token.balanceOf(accounts[0]); let firstAccountBalance = await token.balanceOf(accounts[0]);
assert.equal(firstAccountBalance, 0); assert.equal(firstAccountBalance, 0);
let secondAccountBalance = await token.balanceOf(accounts[1]); let secondAccountBalance = await token.balanceOf(accounts[1]);
assert.equal(secondAccountBalance, 100); assert.equal(secondAccountBalance, 100);
done();
}); });
it("should throw an error when trying to transfer more than balance", async function() { it("should throw an error when trying to transfer more than balance", async function(done) {
let token = await BasicTokenMock.new(accounts[0], 100); let token = await BasicTokenMock.new(accounts[0], 100);
try { try {
@ -23,6 +25,7 @@ contract('BasicToken', function(accounts) {
} catch(error) { } catch(error) {
if (error.message.search('invalid JUMP') === -1) throw error if (error.message.search('invalid JUMP') === -1) throw error
assert.isAbove(error.message.search('invalid JUMP'), -1, 'Invalid JUMP error must be returned'); assert.isAbove(error.message.search('invalid JUMP'), -1, 'Invalid JUMP error must be returned');
done();
} }
}); });

@ -8,16 +8,17 @@ let sendReward = function(sender, receiver, value){
contract('Bounty', function(accounts) { contract('Bounty', function(accounts) {
it("sets reward", async function(){ it("sets reward", async function(done){
let owner = accounts[0]; let owner = accounts[0];
let reward = web3.toWei(1, "ether"); let reward = web3.toWei(1, "ether");
let bounty = await SecureTargetBounty.new(); let bounty = await SecureTargetBounty.new();
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());
done();
}) })
it("empties itself when killed", async function(){ it("empties itself when killed", async function(done){
let owner = accounts[0]; let owner = accounts[0];
let reward = web3.toWei(1, "ether"); let reward = web3.toWei(1, "ether");
@ -25,16 +26,18 @@ contract('Bounty', function(accounts) {
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())
await bounty.kill(); await bounty.kill();
assert.equal(0, web3.eth.getBalance(bounty.address).toNumber()) assert.equal(0, web3.eth.getBalance(bounty.address).toNumber());
done();
}) })
describe("Against secure contract", function(){ describe("Against secure contract", function(){
it("checkInvariant returns true", async function(){ it("checkInvariant returns true", async function(done){
let bounty = await SecureTargetBounty.new(); let bounty = await SecureTargetBounty.new();
let target = await bounty.createTarget(); let target = await bounty.createTarget();
let check = await bounty.checkInvariant.call(); let check = await bounty.checkInvariant.call();
assert.isTrue(check); assert.isTrue(check);
done();
}) })
it("cannot claim reward", async function(done){ it("cannot claim reward", async function(done){
@ -72,14 +75,15 @@ contract('Bounty', function(accounts) {
}) })
describe("Against broken contract", function(){ describe("Against broken contract", function(){
it("checkInvariant returns false", async function(){ it("checkInvariant returns false", async function(done){
let bounty = await InsecureTargetBounty.new(); let bounty = await InsecureTargetBounty.new();
let target = await bounty.createTarget(); let target = await bounty.createTarget();
let invarriantCall = await bounty.checkInvariant.call(); let invarriantCall = await bounty.checkInvariant.call();
assert.isFalse(invarriantCall); assert.isFalse(invarriantCall);
done();
}) })
it("claims reward", async function(){ it("claims reward", async function(done){
let owner = accounts[0]; let owner = accounts[0];
let researcher = accounts[1]; let researcher = accounts[1];
let reward = web3.toWei(1, "ether"); let reward = web3.toWei(1, "ether");
@ -100,6 +104,7 @@ contract('Bounty', function(accounts) {
assert.isTrue(claim); assert.isTrue(claim);
let payment = await bounty.withdrawPayments({from:researcher}); let payment = await bounty.withdrawPayments({from:researcher});
assert.equal(0, web3.eth.getBalance(bounty.address).toNumber()); assert.equal(0, web3.eth.getBalance(bounty.address).toNumber());
done();
}) })
bounty.createTarget({from:researcher}); bounty.createTarget({from:researcher});
}) })

@ -1,46 +1,53 @@
contract('Claimable', function(accounts) { contract('Claimable', function(accounts) {
var claimable; let claimable;
beforeEach(async function() { beforeEach(async function(done) {
claimable = await Claimable.new(); claimable = await Claimable.new();
done();
}); });
it("should have an owner", async function() { it("should have an owner", async function(done) {
let owner = await claimable.owner(); let owner = await claimable.owner();
assert.isTrue(owner != 0); assert.isTrue(owner != 0);
done();
}); });
it("changes pendingOwner after transfer", async function() { it("changes pendingOwner after transfer", async function(done) {
let newOwner = accounts[1]; let newOwner = accounts[1];
let transfer = await claimable.transfer(newOwner); let transfer = await claimable.transfer(newOwner);
let pendingOwner = await claimable.pendingOwner(); let pendingOwner = await claimable.pendingOwner();
assert.isTrue(pendingOwner === newOwner); assert.isTrue(pendingOwner === newOwner);
done();
}); });
it("should prevent to claimOwnership from no pendingOwner", async function() { it("should prevent to claimOwnership from no pendingOwner", async function(done) {
let claimedOwner = await claimable.claimOwnership({from: accounts[2]}); let claimedOwner = await claimable.claimOwnership({from: accounts[2]});
let owner = await claimable.owner(); let owner = await claimable.owner();
assert.isTrue(owner != accounts[2]); assert.isTrue(owner != accounts[2]);
done();
}); });
it("should prevent non-owners from transfering", async function() { it("should prevent non-owners from transfering", async function(done) {
let transfer = await claimable.transfer(accounts[2], {from: accounts[2]}); let transfer = await claimable.transfer(accounts[2], {from: accounts[2]});
let pendingOwner = await claimable.pendingOwner(); let pendingOwner = await claimable.pendingOwner();
assert.isFalse(pendingOwner === accounts[2]); assert.isFalse(pendingOwner === accounts[2]);
done();
}); });
describe("after initiating a transfer", function () { describe("after initiating a transfer", function () {
let newOwner; let newOwner;
beforeEach(function () { beforeEach(async function (done) {
newOwner = accounts[1]; newOwner = accounts[1];
return claimable.transfer(newOwner); await claimable.transfer(newOwner);
done();
}); });
it("changes allow pending owner to claim ownership", async function() { it("changes allow pending owner to claim ownership", async function(done) {
let claimedOwner = await claimable.claimOwnership({from: newOwner}) let claimedOwner = await claimable.claimOwnership({from: newOwner})
let owner = await claimable.owner(); let owner = await claimable.owner();
assert.isTrue(owner === newOwner); assert.isTrue(owner === newOwner);
done();
}); });
}); });
}); });

@ -32,7 +32,7 @@ contract('Killable', function(accounts) {
} }
}; };
it("should send balance to owner after death", async function() { it("should send balance to owner after death", async function(done) {
let initBalance, newBalance, owner, address, killable, kBalance, txnHash, receiptMined; 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)
@ -50,6 +50,7 @@ contract('Killable', function(accounts) {
receiptMined = await web3.eth.getTransactionReceiptMined(txnHash); receiptMined = await web3.eth.getTransactionReceiptMined(txnHash);
newBalance = web3.eth.getBalance(owner); newBalance = web3.eth.getBalance(owner);
assert.isTrue(newBalance > initBalance); assert.isTrue(newBalance > initBalance);
done();
}); });
}); });

@ -1,24 +1,27 @@
contract('LimitBalance', function(accounts) { contract('LimitBalance', function(accounts) {
var lb; let lb;
beforeEach(async function() { beforeEach(async function(done) {
lb = await LimitBalanceMock.new(); lb = await LimitBalanceMock.new();
done();
}); });
let LIMIT = 1000; let LIMIT = 1000;
it("should expose limit", async function() { it("should expose limit", async function(done) {
let limit = await lb.limit(); let limit = await lb.limit();
assert.equal(limit, LIMIT); assert.equal(limit, LIMIT);
done();
}); });
it("should allow sending below limit", async function() { it("should allow sending below limit", async function(done) {
let amount = 1; let amount = 1;
let limDeposit = await lb.limitedDeposit({value: amount}); let limDeposit = await lb.limitedDeposit({value: amount});
assert.equal(web3.eth.getBalance(lb.address), amount); assert.equal(web3.eth.getBalance(lb.address), amount);
done();
}); });
it("shouldnt allow sending above limit", async function() { it("shouldnt allow sending above limit", async function(done) {
let amount = 1110; let amount = 1110;
try { try {
@ -26,29 +29,31 @@ contract('LimitBalance', function(accounts) {
} catch(error) { } catch(error) {
if (error.message.search('invalid JUMP') == -1) throw error if (error.message.search('invalid JUMP') == -1) throw error
assert.isAbove(error.message.search('invalid JUMP'), -1, 'Invalid JUMP error must be returned'); assert.isAbove(error.message.search('invalid JUMP'), -1, 'Invalid JUMP error must be returned');
done();
} }
}); });
it("should allow multiple sends below limit", async function() { it("should allow multiple sends below limit", async function(done) {
let amount = 500; let amount = 500;
let limDeposit = await lb.limitedDeposit({value: amount}); let limDeposit = await lb.limitedDeposit({value: amount});
assert.equal(web3.eth.getBalance(lb.address), amount); assert.equal(web3.eth.getBalance(lb.address), amount);
let limDeposit2 = await lb.limitedDeposit({value: amount}); let limDeposit2 = await lb.limitedDeposit({value: amount});
assert.equal(web3.eth.getBalance(lb.address), amount*2); assert.equal(web3.eth.getBalance(lb.address), amount*2);
done();
}); });
it("shouldnt allow multiple sends above limit", async function() { it("shouldnt allow multiple sends above limit", async function(done) {
let amount = 500; let amount = 500;
let limDeposit = await lb.limitedDeposit({value: amount}); let limDeposit = await lb.limitedDeposit({value: amount});
assert.equal(web3.eth.getBalance(lb.address), amount); assert.equal(web3.eth.getBalance(lb.address), amount);
try { try {
lb.limitedDeposit({value: amount+1}) await lb.limitedDeposit({value: amount+1})
} catch(error) { } catch(error) {
if (error.message.search('invalid JUMP') == -1) throw error if (error.message.search('invalid JUMP') == -1) throw error
assert.isAbove(error.message.search('invalid JUMP'), -1, 'Invalid JUMP error must be returned'); assert.isAbove(error.message.search('invalid JUMP'), -1, 'Invalid JUMP error must be returned');
done();
} }
}); });

@ -1,35 +1,40 @@
contract('Ownable', function(accounts) { contract('Ownable', function(accounts) {
var ownable; let ownable;
beforeEach(async function() { beforeEach(async function(done) {
ownable = await Ownable.new(); ownable = await Ownable.new();
done();
}); });
it("should have an owner", async function() { it("should have an owner", async function(done) {
let owner = await ownable.owner(); let owner = await ownable.owner();
assert.isTrue(owner != 0); assert.isTrue(owner != 0);
done();
}); });
it("changes owner after transfer", async function() { it("changes owner after transfer", async function(done) {
let other = accounts[1]; let other = accounts[1];
let transfer = await ownable.transfer(other); let transfer = await ownable.transfer(other);
let owner = await ownable.owner(); let owner = await ownable.owner();
assert.isTrue(owner === other); assert.isTrue(owner === other);
done();
}); });
it("should prevent non-owners from transfering", async function() { it("should prevent non-owners from transfering", async function(done) {
let other = accounts[2]; let other = accounts[2];
let transfer = await ownable.transfer(other, {from: accounts[2]}); let transfer = await ownable.transfer(other, {from: accounts[2]});
let owner = await ownable.owner(); let owner = await ownable.owner();
assert.isFalse(owner === other); assert.isFalse(owner === other);
done();
}); });
it("should guard ownership against stuck state", async function() { it("should guard ownership against stuck state", async function(done) {
let ownable = Ownable.deployed(); let ownable = Ownable.deployed();
let originalOwner = await ownable.owner(); let originalOwner = await ownable.owner();
let transfer = await ownable.transfer(null, {from: originalOwner}); let transfer = await ownable.transfer(null, {from: originalOwner});
let newOwner = await ownable.owner(); let newOwner = await ownable.owner();
assert.equal(originalOwner, newOwner); assert.equal(originalOwner, newOwner);
done();
}); });
}); });

@ -1,27 +1,30 @@
contract('PullPayment', function(accounts) { contract('PullPayment', function(accounts) {
it("can't call asyncSend externally", async function() { it("can't call asyncSend externally", async function(done) {
let ppc = await PullPaymentMock.new(); let ppc = await PullPaymentMock.new();
assert.isUndefined(ppc.asyncSend); assert.isUndefined(ppc.asyncSend);
done();
}); });
it("can record an async payment correctly", async function() { it("can record an async payment correctly", async function(done) {
let AMOUNT = 100; let AMOUNT = 100;
let ppce = await PullPaymentMock.new(); let ppce = await PullPaymentMock.new();
let callSend = await ppce.callSend(accounts[0], AMOUNT); let callSend = await ppce.callSend(accounts[0], AMOUNT);
let paymentsToAccount0 = await ppce.payments(accounts[0]); let paymentsToAccount0 = await ppce.payments(accounts[0]);
assert.equal(paymentsToAccount0, AMOUNT); assert.equal(paymentsToAccount0, AMOUNT);
done();
}); });
it("can add multiple balances on one account", async function() { it("can add multiple balances on one account", async function(done) {
let ppce = await PullPaymentMock.new(); let ppce = await PullPaymentMock.new();
let call1 = await ppce.callSend(accounts[0], 200); let call1 = await ppce.callSend(accounts[0], 200);
let call2 = await ppce.callSend(accounts[0], 300) let call2 = await ppce.callSend(accounts[0], 300)
let paymentsToAccount0 = await ppce.payments(accounts[0]); let paymentsToAccount0 = await ppce.payments(accounts[0]);
assert.equal(paymentsToAccount0, 500); assert.equal(paymentsToAccount0, 500);
done();
}); });
it("can add balances on multiple accounts", async function() { it("can add balances on multiple accounts", async function(done) {
let ppce = await PullPaymentMock.new(); let ppce = await PullPaymentMock.new();
let call1 = await ppce.callSend(accounts[0], 200); let call1 = await ppce.callSend(accounts[0], 200);
let call2 = await ppce.callSend(accounts[1], 300); let call2 = await ppce.callSend(accounts[1], 300);
@ -29,9 +32,10 @@ contract('PullPayment', function(accounts) {
assert.equal(paymentsToAccount0, 200); assert.equal(paymentsToAccount0, 200);
let paymentsToAccount1 = await ppce.payments(accounts[1]); let paymentsToAccount1 = await ppce.payments(accounts[1]);
assert.equal(paymentsToAccount1, 300); assert.equal(paymentsToAccount1, 300);
done();
}); });
it("can withdraw payment", async function() { it("can withdraw payment", async function(done) {
let AMOUNT = 17*1e18; let AMOUNT = 17*1e18;
let payee = accounts[1]; let payee = accounts[1];
let initialBalance = web3.eth.getBalance(payee); let initialBalance = web3.eth.getBalance(payee);
@ -45,6 +49,7 @@ contract('PullPayment', function(accounts) {
assert.equal(payment2, 0); assert.equal(payment2, 0);
let balance = web3.eth.getBalance(payee); let balance = web3.eth.getBalance(payee);
assert(Math.abs(balance-initialBalance-AMOUNT) < 1e16); assert(Math.abs(balance-initialBalance-AMOUNT) < 1e16);
done();
}); });
}); });

@ -1,37 +1,41 @@
contract('SafeMath', function(accounts) { contract('SafeMath', function(accounts) {
var safeMath; let safeMath;
before(async function() { before(async function(done) {
safeMath = await SafeMathMock.new(); safeMath = await SafeMathMock.new();
done();
}); });
it("multiplies correctly", async function() { it("multiplies correctly", async function(done) {
let a = 5678; let a = 5678;
let b = 1234; let b = 1234;
let mult = await safeMath.multiply(a, b); let mult = await safeMath.multiply(a, b);
let result = await safeMath.result(); let result = await safeMath.result();
assert.equal(result, a*b); assert.equal(result, a*b);
done();
}); });
it("adds correctly", async function() { it("adds correctly", async function(done) {
let a = 5678; let a = 5678;
let b = 1234; let b = 1234;
let add = await safeMath.add(a, b); let add = await safeMath.add(a, b);
let result = await safeMath.result(); let result = await safeMath.result();
assert.equal(result, a+b); assert.equal(result, a+b);
done();
}); });
it("subtracts correctly", async function() { it("subtracts correctly", async function(done) {
let a = 5678; let a = 5678;
let b = 1234; let b = 1234;
let subtract = await safeMath.subtract(a, b); let subtract = await safeMath.subtract(a, b);
let result = await safeMath.result(); let result = await safeMath.result();
assert.equal(result, a-b); assert.equal(result, a-b);
done();
}); });
it("should throw an error if subtraction result would be negative", async function () { it("should throw an error if subtraction result would be negative", async function (done) {
let a = 1234; let a = 1234;
let b = 5678; let b = 5678;
try { try {
@ -39,10 +43,11 @@ contract('SafeMath', function(accounts) {
} catch(error) { } catch(error) {
if (error.message.search('invalid JUMP') == -1) throw error if (error.message.search('invalid JUMP') == -1) throw error
assert.isAbove(error.message.search('invalid JUMP'), -1, 'Invalid JUMP error must be returned'); assert.isAbove(error.message.search('invalid JUMP'), -1, 'Invalid JUMP error must be returned');
done();
} }
}); });
it("should throw an error on addition overflow", async function() { it("should throw an error on addition overflow", async function(done) {
let a = 115792089237316195423570985008687907853269984665640564039457584007913129639935; let a = 115792089237316195423570985008687907853269984665640564039457584007913129639935;
let b = 1; let b = 1;
try { try {
@ -50,10 +55,11 @@ contract('SafeMath', function(accounts) {
} catch(error) { } catch(error) {
if (error.message.search('invalid JUMP') == -1) throw error if (error.message.search('invalid JUMP') == -1) throw error
assert.isAbove(error.message.search('invalid JUMP'), -1, 'Invalid JUMP error must be returned'); assert.isAbove(error.message.search('invalid JUMP'), -1, 'Invalid JUMP error must be returned');
done();
} }
}); });
it("should throw an error on multiplication overflow", async function() { it("should throw an error on multiplication overflow", async function(done) {
let a = 115792089237316195423570985008687907853269984665640564039457584007913129639933; let a = 115792089237316195423570985008687907853269984665640564039457584007913129639933;
let b = 2; let b = 2;
try { try {
@ -61,6 +67,7 @@ contract('SafeMath', function(accounts) {
} catch(error) { } catch(error) {
if (error.message.search('invalid JUMP') == -1) throw error if (error.message.search('invalid JUMP') == -1) throw error
assert.isAbove(error.message.search('invalid JUMP'), -1, 'Invalid JUMP error must be returned'); assert.isAbove(error.message.search('invalid JUMP'), -1, 'Invalid JUMP error must be returned');
done();
} }
}); });

@ -1,38 +1,42 @@
contract('StandardToken', function(accounts) { contract('StandardToken', function(accounts) {
it("should return the correct totalSupply after construction", async function() { it("should return the correct totalSupply after construction", async function(done) {
let token = await StandardTokenMock.new(accounts[0], 100); let token = await StandardTokenMock.new(accounts[0], 100);
let totalSupply = await token.totalSupply(); let totalSupply = await token.totalSupply();
assert.equal(totalSupply, 100); assert.equal(totalSupply, 100);
done();
}) })
it("should return the correct allowance amount after approval", async function() { it("should return the correct allowance amount after approval", async function(done) {
let token = await StandardTokenMock.new(); let token = await StandardTokenMock.new();
let approve = await token.approve(accounts[1], 100); let approve = await token.approve(accounts[1], 100);
let allowance = await token.allowance(accounts[0], accounts[1]); let allowance = await token.allowance(accounts[0], accounts[1]);
assert.equal(allowance, 100); assert.equal(allowance, 100);
done();
}); });
it("should return correct balances after transfer", async function() { it("should return correct balances after transfer", async function(done) {
let token = await StandardTokenMock.new(accounts[0], 100); let token = await StandardTokenMock.new(accounts[0], 100);
let transfer = await token.transfer(accounts[1], 100); let transfer = await token.transfer(accounts[1], 100);
let balance0 = await token.balanceOf(accounts[0]); let balance0 = await token.balanceOf(accounts[0]);
assert.equal(balance0, 0); assert.equal(balance0, 0);
let balance1 = await token.balanceOf(accounts[1]); let balance1 = await token.balanceOf(accounts[1]);
assert.equal(balance1, 100); assert.equal(balance1, 100);
done();
}); });
it("should throw an error when trying to transfer more than balance", async function() { it("should throw an error when trying to transfer more than balance", async function(done) {
let token = await StandardTokenMock.new(accounts[0], 100); let token = await StandardTokenMock.new(accounts[0], 100);
try { try {
let transfer = await token.transfer(accounts[1], 101); let transfer = await token.transfer(accounts[1], 101);
} catch(error) { } catch(error) {
if (error.message.search('invalid JUMP') == -1) throw error if (error.message.search('invalid JUMP') == -1) throw error
assert.isAbove(error.message.search('invalid JUMP'), -1, 'Invalid JUMP error must be returned'); assert.isAbove(error.message.search('invalid JUMP'), -1, 'Invalid JUMP error must be returned');
done();
} }
}); });
it("should return correct balances after transfering from another account", async function() { it("should return correct balances after transfering from another account", async function(done) {
let token = await StandardTokenMock.new(accounts[0], 100); let token = await StandardTokenMock.new(accounts[0], 100);
let approve = await token.approve(accounts[1], 100); let approve = await token.approve(accounts[1], 100);
let transferFrom = await token.transferFrom(accounts[0], accounts[2], 100, {from: accounts[1]}); let transferFrom = await token.transferFrom(accounts[0], accounts[2], 100, {from: accounts[1]});
@ -45,9 +49,10 @@ contract('StandardToken', function(accounts) {
let balance2 = await token.balanceOf(accounts[1]); let balance2 = await token.balanceOf(accounts[1]);
assert.equal(balance2, 0); assert.equal(balance2, 0);
done();
}); });
it("should throw an error when trying to transfer more than allowed", async function() { it("should throw an error when trying to transfer more than allowed", async function(done) {
let token = await StandardTokenMock.new(); let token = await StandardTokenMock.new();
let approve = await token.approve(accounts[1], 99); let approve = await token.approve(accounts[1], 99);
try { try {
@ -55,6 +60,7 @@ contract('StandardToken', function(accounts) {
} catch (error) { } catch (error) {
if (error.message.search('invalid JUMP') == -1) throw error if (error.message.search('invalid JUMP') == -1) throw error
assert.isAbove(error.message.search('invalid JUMP'), -1, 'Invalid JUMP error must be returned'); assert.isAbove(error.message.search('invalid JUMP'), -1, 'Invalid JUMP error must be returned');
done();
} }
}); });

@ -1,15 +1,16 @@
contract('Stoppable', function(accounts) { contract('Stoppable', function(accounts) {
it("can perform normal process in non-emergency", async function() { it("can perform normal process in non-emergency", async function(done) {
let stoppable = await StoppableMock.new(); let stoppable = await StoppableMock.new();
let count0 = await stoppable.count(); let count0 = await stoppable.count();
assert.equal(count0, 0); assert.equal(count0, 0);
let normalProcess = await stoppable.normalProcess(); let normalProcess = await stoppable.normalProcess();
let count1 = await stoppable.count(); let count1 = await stoppable.count();
assert.equal(count1, 1); assert.equal(count1, 1);
done();
}); });
it("can not perform normal process in emergency", async function() { it("can not perform normal process in emergency", async function(done) {
let stoppable = await StoppableMock.new(); let stoppable = await StoppableMock.new();
let emergencyStop = await stoppable.emergencyStop(); let emergencyStop = await stoppable.emergencyStop();
let count0 = await stoppable.count(); let count0 = await stoppable.count();
@ -17,31 +18,35 @@ contract('Stoppable', function(accounts) {
let normalProcess = await stoppable.normalProcess(); let normalProcess = await stoppable.normalProcess();
let count1 = await stoppable.count(); let count1 = await stoppable.count();
assert.equal(count1, 0); assert.equal(count1, 0);
done();
}); });
it("can not take drastic measure in non-emergency", async function() { it("can not take drastic measure in non-emergency", async function(done) {
let stoppable = await StoppableMock.new(); let stoppable = await StoppableMock.new();
let drasticMeasure = await stoppable.drasticMeasure(); let drasticMeasure = await stoppable.drasticMeasure();
let drasticMeasureTaken = await stoppable.drasticMeasureTaken(); let drasticMeasureTaken = await stoppable.drasticMeasureTaken();
assert.isFalse(drasticMeasureTaken); assert.isFalse(drasticMeasureTaken);
done();
}); });
it("can take a drastic measure in an emergency", async function() { it("can take a drastic measure in an emergency", async function(done) {
let stoppable = await StoppableMock.new(); let stoppable = await StoppableMock.new();
let emergencyStop = await stoppable.emergencyStop(); let emergencyStop = await stoppable.emergencyStop();
let drasticMeasure = await stoppable.drasticMeasure(); let drasticMeasure = await stoppable.drasticMeasure();
let drasticMeasureTaken = await stoppable.drasticMeasureTaken(); let drasticMeasureTaken = await stoppable.drasticMeasureTaken();
assert.isTrue(drasticMeasureTaken); assert.isTrue(drasticMeasureTaken);
done();
}); });
it("should resume allowing normal process after emergency is over", async function() { it("should resume allowing normal process after emergency is over", async function(done) {
let stoppable = await StoppableMock.new(); let stoppable = await StoppableMock.new();
let emergencyStop = await stoppable.emergencyStop(); let emergencyStop = await stoppable.emergencyStop();
let release = await stoppable.release(); let release = await stoppable.release();
let normalProcess = await stoppable.normalProcess(); let normalProcess = await stoppable.normalProcess();
let count0 = await stoppable.count(); let count0 = await stoppable.count();
assert.equal(count0, 1); assert.equal(count0, 1);
done();
}); });
}); });

Loading…
Cancel
Save