parent
c920c40507
commit
f2142545c7
@ -1,49 +1,29 @@ |
||||
contract('BasicToken', function(accounts) { |
||||
|
||||
it("should return the correct totalSupply after construction", function(done) { |
||||
return BasicTokenMock.new(accounts[0], 100) |
||||
.then(function(token) { |
||||
return token.totalSupply(); |
||||
}) |
||||
.then(function(totalSupply) { |
||||
assert.equal(totalSupply, 100); |
||||
}) |
||||
.then(done); |
||||
it("should return the correct totalSupply after construction", async function() { |
||||
let token = await BasicTokenMock.new(accounts[0], 100); |
||||
let totalSupply = await token.totalSupply(); |
||||
assert.equal(totalSupply, 100); |
||||
}) |
||||
|
||||
it("should return correct balances after transfer", function(done) { |
||||
var token; |
||||
return BasicTokenMock.new(accounts[0], 100) |
||||
.then(function(_token) { |
||||
token = _token; |
||||
return token.transfer(accounts[1], 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 return correct balances after transfer", async function(){ |
||||
let token = await BasicTokenMock.new(accounts[0], 100); |
||||
let transfer = await token.transfer(accounts[1], 100); |
||||
let firstAccountBalance = await token.balanceOf(accounts[0]); |
||||
assert.equal(firstAccountBalance, 0); |
||||
let secondAccountBalance = await token.balanceOf(accounts[1]); |
||||
assert.equal(secondAccountBalance, 100); |
||||
}); |
||||
|
||||
it("should throw an error when trying to transfer more than balance", function(done) { |
||||
var token; |
||||
return BasicTokenMock.new(accounts[0], 100) |
||||
.then(function(_token) { |
||||
token = _token; |
||||
return token.transfer(accounts[1], 101); |
||||
}) |
||||
.catch(function(error) { |
||||
if (error.message.search('invalid JUMP') == -1) throw error |
||||
}) |
||||
.then(done); |
||||
it("should throw an error when trying to transfer more than balance", async function() { |
||||
|
||||
let token = await BasicTokenMock.new(accounts[0], 100); |
||||
try { |
||||
let transfer = await token.transfer(accounts[1], 101); |
||||
} catch(error) { |
||||
if (error.message.search('invalid JUMP') === -1) throw error |
||||
assert.isAbove(error.message.search('invalid JUMP'), -1, 'Invalid JUMP error must be returned'); |
||||
} |
||||
}); |
||||
|
||||
}); |
||||
|
@ -1,71 +1,46 @@ |
||||
contract('Claimable', function(accounts) { |
||||
var claimable; |
||||
|
||||
beforeEach(function() { |
||||
return Claimable.new().then(function(deployed) { |
||||
claimable = deployed; |
||||
}); |
||||
beforeEach(async function() { |
||||
claimable = await Claimable.new(); |
||||
}); |
||||
|
||||
it("should have an owner", function(done) { |
||||
return claimable.owner() |
||||
.then(function(owner) { |
||||
assert.isTrue(owner != 0); |
||||
}) |
||||
.then(done) |
||||
it("should have an owner", async function() { |
||||
let owner = await claimable.owner(); |
||||
assert.isTrue(owner != 0); |
||||
}); |
||||
|
||||
it("changes pendingOwner after transfer", function(done) { |
||||
var newOwner = accounts[1]; |
||||
return claimable.transfer(newOwner) |
||||
.then(function() { |
||||
return claimable.pendingOwner(); |
||||
}) |
||||
.then(function(pendingOwner) { |
||||
assert.isTrue(pendingOwner === newOwner); |
||||
}) |
||||
.then(done) |
||||
it("changes pendingOwner after transfer", async function() { |
||||
let newOwner = accounts[1]; |
||||
let transfer = await claimable.transfer(newOwner); |
||||
let pendingOwner = await claimable.pendingOwner(); |
||||
assert.isTrue(pendingOwner === newOwner); |
||||
}); |
||||
|
||||
it("should prevent to claimOwnership from no pendingOwner", function(done) { |
||||
return claimable.claimOwnership({from: accounts[2]}) |
||||
.then(function() { |
||||
return claimable.owner(); |
||||
}) |
||||
.then(function(owner) { |
||||
assert.isTrue(owner != accounts[2]); |
||||
}) |
||||
.then(done) |
||||
it("should prevent to claimOwnership from no pendingOwner", async function() { |
||||
let claimedOwner = await claimable.claimOwnership({from: accounts[2]}); |
||||
let owner = await claimable.owner(); |
||||
assert.isTrue(owner != accounts[2]); |
||||
}); |
||||
|
||||
it("should prevent non-owners from transfering" ,function(done) { |
||||
return claimable.transfer(accounts[2], {from: accounts[2]}) |
||||
.then(function() { |
||||
return claimable.pendingOwner(); |
||||
}) |
||||
.then(function(pendingOwner) { |
||||
assert.isFalse(pendingOwner === accounts[2]); |
||||
}) |
||||
.then(done) |
||||
it("should prevent non-owners from transfering", async function() { |
||||
let transfer = await claimable.transfer(accounts[2], {from: accounts[2]}); |
||||
let pendingOwner = await claimable.pendingOwner(); |
||||
assert.isFalse(pendingOwner === accounts[2]); |
||||
}); |
||||
|
||||
describe("after initiating a transfer", function () { |
||||
var newOwner; |
||||
let newOwner; |
||||
|
||||
beforeEach(function () { |
||||
newOwner = accounts[1]; |
||||
return claimable.transfer(newOwner); |
||||
}); |
||||
|
||||
it("changes allow pending owner to claim ownership", function(done) { |
||||
return claimable.claimOwnership({from: newOwner}) |
||||
.then(function() { |
||||
return claimable.owner(); |
||||
}) |
||||
.then(function(owner) { |
||||
assert.isTrue(owner === newOwner); |
||||
}) |
||||
.then(done) |
||||
it("changes allow pending owner to claim ownership", async function() { |
||||
let claimedOwner = await claimable.claimOwnership({from: newOwner}) |
||||
let owner = await claimable.owner(); |
||||
assert.isTrue(owner === newOwner); |
||||
}); |
||||
}); |
||||
}); |
||||
|
@ -1,64 +1,55 @@ |
||||
contract('LimitBalance', function(accounts) { |
||||
var lb; |
||||
|
||||
beforeEach(function() { |
||||
return LimitBalanceMock.new().then(function(deployed) { |
||||
lb = deployed; |
||||
}); |
||||
beforeEach(async function() { |
||||
lb = await LimitBalanceMock.new(); |
||||
}); |
||||
|
||||
var LIMIT = 1000; |
||||
let LIMIT = 1000; |
||||
|
||||
it("should expose limit", function(done) { |
||||
return lb.limit() |
||||
.then(function(limit) {
|
||||
assert.equal(limit, LIMIT); |
||||
}) |
||||
.then(done) |
||||
it("should expose limit", async function() { |
||||
let limit = await lb.limit(); |
||||
assert.equal(limit, LIMIT); |
||||
}); |
||||
|
||||
it("should allow sending below limit", function(done) { |
||||
var amount = 1; |
||||
return lb.limitedDeposit({value: amount}) |
||||
.then(function() {
|
||||
assert.equal(web3.eth.getBalance(lb.address), amount); |
||||
}) |
||||
.then(done) |
||||
it("should allow sending below limit", async function() { |
||||
let amount = 1; |
||||
let limDeposit = await lb.limitedDeposit({value: amount}); |
||||
assert.equal(web3.eth.getBalance(lb.address), amount); |
||||
}); |
||||
|
||||
it("shouldnt allow sending above limit", function(done) { |
||||
var amount = 1100; |
||||
return lb.limitedDeposit({value: amount}) |
||||
.catch(function(error) { |
||||
if (error.message.search('invalid JUMP') == -1) throw error |
||||
}) |
||||
.then(done) |
||||
it("shouldnt allow sending above limit", async function() { |
||||
|
||||
let amount = 1110; |
||||
try { |
||||
let limDeposit = await lb.limitedDeposit({value: amount}); |
||||
} catch(error) { |
||||
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) { |
||||
var amount = 500; |
||||
return lb.limitedDeposit({value: amount}) |
||||
.then(function() {
|
||||
assert.equal(web3.eth.getBalance(lb.address), amount); |
||||
return lb.limitedDeposit({value: amount}) |
||||
}) |
||||
.then(function() {
|
||||
assert.equal(web3.eth.getBalance(lb.address), amount*2); |
||||
}) |
||||
.then(done) |
||||
it("should allow multiple sends below limit", async function() { |
||||
let amount = 500; |
||||
|
||||
let limDeposit = await lb.limitedDeposit({value: amount}); |
||||
assert.equal(web3.eth.getBalance(lb.address), amount); |
||||
let limDeposit2 = await lb.limitedDeposit({value: amount}); |
||||
assert.equal(web3.eth.getBalance(lb.address), amount*2); |
||||
}); |
||||
|
||||
it("shouldnt allow multiple sends above limit", function(done) { |
||||
var amount = 500; |
||||
return lb.limitedDeposit({value: amount}) |
||||
.then(function() {
|
||||
assert.equal(web3.eth.getBalance(lb.address), amount); |
||||
return lb.limitedDeposit({value: amount+1}) |
||||
}) |
||||
.catch(function(error) { |
||||
if (error.message.search('invalid JUMP') == -1) throw error; |
||||
}) |
||||
.then(done) |
||||
it("shouldnt allow multiple sends above limit", async function() { |
||||
let amount = 500; |
||||
|
||||
|
||||
let limDeposit = await lb.limitedDeposit({value: amount}); |
||||
assert.equal(web3.eth.getBalance(lb.address), amount); |
||||
try { |
||||
lb.limitedDeposit({value: amount+1}) |
||||
} catch(error) { |
||||
if (error.message.search('invalid JUMP') == -1) throw error |
||||
assert.isAbove(error.message.search('invalid JUMP'), -1, 'Invalid JUMP error must be returned'); |
||||
} |
||||
}); |
||||
|
||||
}); |
||||
|
@ -1,58 +1,35 @@ |
||||
contract('Ownable', function(accounts) { |
||||
var ownable; |
||||
|
||||
beforeEach(function() { |
||||
return Ownable.new().then(function(deployed) { |
||||
ownable = deployed; |
||||
}); |
||||
beforeEach(async function() { |
||||
ownable = await Ownable.new(); |
||||
}); |
||||
|
||||
it("should have an owner", function(done) { |
||||
return ownable.owner() |
||||
.then(function(owner) { |
||||
assert.isTrue(owner != 0); |
||||
}) |
||||
.then(done) |
||||
it("should have an owner", async function() { |
||||
let owner = await ownable.owner(); |
||||
assert.isTrue(owner != 0); |
||||
}); |
||||
|
||||
it("changes owner after transfer", function(done) { |
||||
var other = accounts[1]; |
||||
return ownable.transfer(other) |
||||
.then(function() { |
||||
return ownable.owner(); |
||||
}) |
||||
.then(function(owner) { |
||||
assert.isTrue(owner === other); |
||||
}) |
||||
.then(done) |
||||
it("changes owner after transfer", async function() { |
||||
let other = accounts[1]; |
||||
let transfer = await ownable.transfer(other); |
||||
let owner = await ownable.owner(); |
||||
assert.isTrue(owner === other); |
||||
}); |
||||
|
||||
it("should prevent non-owners from transfering" ,function(done) { |
||||
var other = accounts[2]; |
||||
return ownable.transfer(other, {from: accounts[2]}) |
||||
.then(function() { |
||||
return ownable.owner(); |
||||
}) |
||||
.then(function(owner) { |
||||
assert.isFalse(owner === other); |
||||
}) |
||||
.then(done) |
||||
it("should prevent non-owners from transfering", async function() { |
||||
let other = accounts[2]; |
||||
let transfer = await ownable.transfer(other, {from: accounts[2]}); |
||||
let owner = await ownable.owner(); |
||||
assert.isFalse(owner === other); |
||||
}); |
||||
|
||||
it("should guard ownership against stuck state" ,function(done) { |
||||
var ownable = Ownable.deployed(); |
||||
|
||||
return ownable.owner() |
||||
.then(function (originalOwner) { |
||||
return ownable.transfer(null, {from: originalOwner}) |
||||
.then(function() { |
||||
return ownable.owner(); |
||||
}) |
||||
.then(function(newOwner) { |
||||
assert.equal(originalOwner, newOwner); |
||||
}) |
||||
.then(done); |
||||
}); |
||||
it("should guard ownership against stuck state", async function() { |
||||
let ownable = Ownable.deployed(); |
||||
let originalOwner = await ownable.owner(); |
||||
let transfer = await ownable.transfer(null, {from: originalOwner}); |
||||
let newOwner = await ownable.owner(); |
||||
assert.equal(originalOwner, newOwner); |
||||
}); |
||||
|
||||
}); |
||||
|
@ -1,102 +1,50 @@ |
||||
contract('PullPayment', function(accounts) { |
||||
|
||||
it("can't call asyncSend externally", function(done) { |
||||
return PullPaymentMock.new() |
||||
.then(function(ppc) { |
||||
assert.isUndefined(ppc.asyncSend); |
||||
}) |
||||
.then(done); |
||||
it("can't call asyncSend externally", async function() { |
||||
let ppc = await PullPaymentMock.new(); |
||||
assert.isUndefined(ppc.asyncSend); |
||||
}); |
||||
|
||||
it("can record an async payment correctly", function(done) { |
||||
var ppce; |
||||
var AMOUNT = 100; |
||||
return PullPaymentMock.new() |
||||
.then(function(_ppce) { |
||||
ppce = _ppce; |
||||
ppce.callSend(accounts[0], AMOUNT) |
||||
}) |
||||
.then(function() { |
||||
return ppce.payments(accounts[0]); |
||||
}) |
||||
.then(function(paymentsToAccount0) { |
||||
assert.equal(paymentsToAccount0, AMOUNT); |
||||
}) |
||||
.then(done); |
||||
it("can record an async payment correctly", async function() { |
||||
let AMOUNT = 100; |
||||
let ppce = await PullPaymentMock.new(); |
||||
let callSend = await ppce.callSend(accounts[0], AMOUNT); |
||||
let paymentsToAccount0 = await ppce.payments(accounts[0]); |
||||
assert.equal(paymentsToAccount0, AMOUNT); |
||||
}); |
||||
|
||||
it("can add multiple balances on one account", function(done) { |
||||
var ppce; |
||||
return PullPaymentMock.new() |
||||
.then(function(_ppce) { |
||||
ppce = _ppce; |
||||
return ppce.callSend(accounts[0], 200) |
||||
}) |
||||
.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 multiple balances on one account", async function() { |
||||
let ppce = await PullPaymentMock.new(); |
||||
let call1 = await ppce.callSend(accounts[0], 200); |
||||
let call2 = await ppce.callSend(accounts[0], 300) |
||||
let paymentsToAccount0 = await ppce.payments(accounts[0]); |
||||
assert.equal(paymentsToAccount0, 500); |
||||
}); |
||||
|
||||
it("can add balances on multiple accounts", function(done) { |
||||
var ppce; |
||||
return PullPaymentMock.new() |
||||
.then(function(_ppce) { |
||||
ppce = _ppce; |
||||
return ppce.callSend(accounts[0], 200) |
||||
}) |
||||
.then(function() { |
||||
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 add balances on multiple accounts", async function() { |
||||
let ppce = await PullPaymentMock.new(); |
||||
let call1 = await ppce.callSend(accounts[0], 200); |
||||
let call2 = await ppce.callSend(accounts[1], 300); |
||||
let paymentsToAccount0 = await ppce.payments(accounts[0]); |
||||
assert.equal(paymentsToAccount0, 200); |
||||
let paymentsToAccount1 = await ppce.payments(accounts[1]); |
||||
assert.equal(paymentsToAccount1, 300); |
||||
}); |
||||
|
||||
it("can withdraw payment", function(done) { |
||||
var ppce; |
||||
var AMOUNT = 17*1e18; |
||||
var payee = accounts[1]; |
||||
var initialBalance = web3.eth.getBalance(payee); |
||||
return PullPaymentMock.new({value: AMOUNT}) |
||||
.then(function(_ppce) { |
||||
ppce = _ppce; |
||||
return ppce.callSend(payee, AMOUNT); |
||||
}) |
||||
.then(function() { |
||||
return ppce.payments(payee); |
||||
}) |
||||
.then(function(paymentsToAccount0) { |
||||
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); |
||||
it("can withdraw payment", async function() { |
||||
let AMOUNT = 17*1e18; |
||||
let payee = accounts[1]; |
||||
let initialBalance = web3.eth.getBalance(payee); |
||||
|
||||
let ppce = await PullPaymentMock.new({value: AMOUNT}); |
||||
let call1 = await ppce.callSend(payee, AMOUNT); |
||||
let payment1 = await ppce.payments(payee); |
||||
assert.equal(payment1, AMOUNT); |
||||
let withdraw = await ppce.withdrawPayments({from: payee}); |
||||
let payment2 = await ppce.payments(payee); |
||||
assert.equal(payment2, 0); |
||||
let balance = web3.eth.getBalance(payee); |
||||
assert(Math.abs(balance-initialBalance-AMOUNT) < 1e16); |
||||
}); |
||||
|
||||
}); |
||||
|
@ -1,108 +1,61 @@ |
||||
contract('StandardToken', function(accounts) { |
||||
|
||||
it("should return the correct totalSupply after construction", function(done) { |
||||
return StandardTokenMock.new(accounts[0], 100) |
||||
.then(function(token) { |
||||
return token.totalSupply(); |
||||
}) |
||||
.then(function(totalSupply) { |
||||
assert.equal(totalSupply, 100); |
||||
}) |
||||
.then(done); |
||||
it("should return the correct totalSupply after construction", async function() { |
||||
let token = await StandardTokenMock.new(accounts[0], 100); |
||||
let totalSupply = await token.totalSupply(); |
||||
assert.equal(totalSupply, 100); |
||||
}) |
||||
|
||||
it("should return the correct allowance amount after approval", function(done) { |
||||
var token; |
||||
return StandardTokenMock.new() |
||||
.then(function(_token) { |
||||
token = _token; |
||||
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 the correct allowance amount after approval", async function() { |
||||
let token = await StandardTokenMock.new(); |
||||
let approve = await token.approve(accounts[1], 100); |
||||
let allowance = await token.allowance(accounts[0], accounts[1]); |
||||
assert.equal(allowance, 100); |
||||
}); |
||||
|
||||
it("should return correct balances after transfer", function(done) { |
||||
var token; |
||||
return StandardTokenMock.new(accounts[0], 100) |
||||
.then(function(_token) { |
||||
token = _token; |
||||
return token.transfer(accounts[1], 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 return correct balances after transfer", async function() { |
||||
let token = await StandardTokenMock.new(accounts[0], 100); |
||||
let transfer = await token.transfer(accounts[1], 100); |
||||
let balance0 = await token.balanceOf(accounts[0]); |
||||
assert.equal(balance0, 0); |
||||
let balance1 = await token.balanceOf(accounts[1]); |
||||
assert.equal(balance1, 100); |
||||
}); |
||||
|
||||
it("should throw an error when trying to transfer more than balance", function(done) { |
||||
var token; |
||||
return StandardTokenMock.new(accounts[0], 100) |
||||
.then(function(_token) { |
||||
token = _token; |
||||
return token.transfer(accounts[1], 101); |
||||
}) |
||||
.catch(function(error) { |
||||
if (error.message.search('invalid JUMP') == -1) throw error |
||||
}) |
||||
.then(done); |
||||
it("should throw an error when trying to transfer more than balance", async function() { |
||||
let token = await StandardTokenMock.new(accounts[0], 100); |
||||
try { |
||||
let transfer = await token.transfer(accounts[1], 101); |
||||
} catch(error) { |
||||
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 return correct balances after transfering from another account", function(done) { |
||||
var token; |
||||
return StandardTokenMock.new(accounts[0], 100) |
||||
.then(function(_token) { |
||||
token = _token; |
||||
return token.approve(accounts[1], 100); |
||||
}) |
||||
.then(function() { |
||||
return token.transferFrom(accounts[0], accounts[2], 100, {from: accounts[1]}); |
||||
}) |
||||
.then(function() { |
||||
return token.balanceOf(accounts[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 return correct balances after transfering from another account", async function() { |
||||
let token = await StandardTokenMock.new(accounts[0], 100); |
||||
let approve = await token.approve(accounts[1], 100); |
||||
let transferFrom = await token.transferFrom(accounts[0], accounts[2], 100, {from: accounts[1]}); |
||||
|
||||
let balance0 = await token.balanceOf(accounts[0]); |
||||
assert.equal(balance0, 0); |
||||
|
||||
let balance1 = await token.balanceOf(accounts[2]); |
||||
assert.equal(balance1, 100); |
||||
|
||||
let balance2 = await token.balanceOf(accounts[1]); |
||||
assert.equal(balance2, 0); |
||||
}); |
||||
|
||||
it("should throw an error when trying to transfer more than allowed", function(done) { |
||||
var token; |
||||
return StandardTokenMock.new(accounts[0], 100) |
||||
.then(function(_token) { |
||||
token = _token; |
||||
return token.approve(accounts[1], 99); |
||||
}) |
||||
.then(function() { |
||||
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); |
||||
it("should throw an error when trying to transfer more than allowed", async function() { |
||||
let token = await StandardTokenMock.new(); |
||||
let approve = await token.approve(accounts[1], 99); |
||||
try { |
||||
let transfer = await token.transferFrom(accounts[0], accounts[2], 100, {from: accounts[1]}); |
||||
} catch (error) { |
||||
if (error.message.search('invalid JUMP') == -1) throw error |
||||
assert.isAbove(error.message.search('invalid JUMP'), -1, 'Invalid JUMP error must be returned'); |
||||
} |
||||
}); |
||||
|
||||
}); |
||||
|
@ -1,108 +1,47 @@ |
||||
contract('Stoppable', function(accounts) { |
||||
|
||||
it("can perform normal process in non-emergency", function(done) { |
||||
var stoppable; |
||||
return StoppableMock.new() |
||||
.then(function(_stoppable) { |
||||
stoppable = _stoppable; |
||||
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, 1); |
||||
}) |
||||
.then(done); |
||||
it("can perform normal process in non-emergency", async function() { |
||||
let stoppable = await StoppableMock.new(); |
||||
let count0 = await stoppable.count(); |
||||
assert.equal(count0, 0); |
||||
let normalProcess = await stoppable.normalProcess(); |
||||
let count1 = await stoppable.count(); |
||||
assert.equal(count1, 1); |
||||
}); |
||||
|
||||
it("can not perform normal process in emergency", function(done) { |
||||
var stoppable; |
||||
return StoppableMock.new() |
||||
.then(function(_stoppable) { |
||||
stoppable = _stoppable; |
||||
return stoppable.emergencyStop(); |
||||
}) |
||||
.then(function () { |
||||
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 perform normal process in emergency", async function() { |
||||
let stoppable = await StoppableMock.new(); |
||||
let emergencyStop = await stoppable.emergencyStop(); |
||||
let count0 = await stoppable.count(); |
||||
assert.equal(count0, 0); |
||||
let normalProcess = await stoppable.normalProcess(); |
||||
let count1 = await stoppable.count(); |
||||
assert.equal(count1, 0); |
||||
}); |
||||
|
||||
|
||||
it("can not take drastic measure in non-emergency", function(done) { |
||||
var stoppable; |
||||
return StoppableMock.new() |
||||
.then(function(_stoppable) { |
||||
stoppable = _stoppable; |
||||
return stoppable.drasticMeasure(); |
||||
}) |
||||
.then(function() { |
||||
return stoppable.drasticMeasureTaken(); |
||||
}) |
||||
.then(function(taken) { |
||||
assert.isFalse(taken); |
||||
}) |
||||
.then(done); |
||||
it("can not take drastic measure in non-emergency", async function() { |
||||
let stoppable = await StoppableMock.new(); |
||||
let drasticMeasure = await stoppable.drasticMeasure(); |
||||
let drasticMeasureTaken = await stoppable.drasticMeasureTaken(); |
||||
assert.isFalse(drasticMeasureTaken); |
||||
}); |
||||
|
||||
it("can take a drastic measure in an emergency", function(done) { |
||||
var stoppable; |
||||
return StoppableMock.new() |
||||
.then(function(_stoppable) { |
||||
stoppable = _stoppable; |
||||
return stoppable.emergencyStop(); |
||||
}) |
||||
.then(function() { |
||||
return stoppable.drasticMeasure(); |
||||
}) |
||||
.then(function() { |
||||
return stoppable.drasticMeasureTaken(); |
||||
}) |
||||
.then(function(taken) { |
||||
assert.isTrue(taken); |
||||
}) |
||||
.then(done); |
||||
it("can take a drastic measure in an emergency", async function() { |
||||
let stoppable = await StoppableMock.new(); |
||||
let emergencyStop = await stoppable.emergencyStop(); |
||||
let drasticMeasure = await stoppable.drasticMeasure(); |
||||
let drasticMeasureTaken = await stoppable.drasticMeasureTaken(); |
||||
assert.isTrue(drasticMeasureTaken); |
||||
}); |
||||
|
||||
it("should resume allowing normal process after emergency is over", function(done) { |
||||
var stoppable; |
||||
return StoppableMock.new() |
||||
.then(function(_stoppable) { |
||||
stoppable = _stoppable; |
||||
return stoppable.emergencyStop(); |
||||
}) |
||||
.then(function () { |
||||
return stoppable.release(); |
||||
}) |
||||
.then(function() { |
||||
return stoppable.normalProcess(); |
||||
}) |
||||
.then(function() { |
||||
return stoppable.count(); |
||||
}) |
||||
.then(function(count) { |
||||
assert.equal(count, 1); |
||||
}) |
||||
.then(done); |
||||
it("should resume allowing normal process after emergency is over", async function() { |
||||
let stoppable = await StoppableMock.new(); |
||||
let emergencyStop = await stoppable.emergencyStop(); |
||||
let release = await stoppable.release(); |
||||
let normalProcess = await stoppable.normalProcess(); |
||||
let count0 = await stoppable.count(); |
||||
assert.equal(count0, 1); |
||||
}); |
||||
|
||||
}); |
||||
|
Loading…
Reference in new issue