parent
688106e9c3
commit
eb41a81faa
@ -1,53 +1,50 @@ |
|||||||
contract('Claimable', function(accounts) { |
contract('Claimable', function(accounts) { |
||||||
let claimable; |
let claimable; |
||||||
|
|
||||||
beforeEach(async function(done) { |
beforeEach(async function() { |
||||||
claimable = await Claimable.new(); |
claimable = await Claimable.new(); |
||||||
done(); |
|
||||||
}); |
}); |
||||||
|
|
||||||
it("should have an owner", async function(done) { |
it("should have an owner", async function() { |
||||||
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(done) { |
it("changes pendingOwner after transfer", async function() { |
||||||
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(done) { |
it("should prevent to claimOwnership from no pendingOwner", async function() { |
||||||
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(done) { |
it("should prevent non-owners from transfering", async function() { |
||||||
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(async function (done) { |
beforeEach(async function () { |
||||||
newOwner = accounts[1]; |
newOwner = accounts[1]; |
||||||
await claimable.transfer(newOwner); |
await claimable.transfer(newOwner); |
||||||
done(); |
|
||||||
}); |
}); |
||||||
|
|
||||||
it("changes allow pending owner to claim ownership", async function(done) { |
it("changes allow pending owner to claim ownership", async function() { |
||||||
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(); |
|
||||||
}); |
}); |
||||||
}); |
}); |
||||||
}); |
}); |
||||||
|
@ -1,40 +1,38 @@ |
|||||||
contract('Ownable', function(accounts) { |
contract('Ownable', function(accounts) { |
||||||
let ownable; |
let ownable; |
||||||
|
|
||||||
beforeEach(async function(done) { |
beforeEach(async function() { |
||||||
ownable = await Ownable.new(); |
ownable = await Ownable.new(); |
||||||
done(); |
|
||||||
}); |
}); |
||||||
|
|
||||||
it("should have an owner", async function(done) { |
it("should have an owner", async function() { |
||||||
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(done) { |
it("changes owner after transfer", async function() { |
||||||
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(done) { |
it("should prevent non-owners from transfering", async function() { |
||||||
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(done) { |
it("should guard ownership against stuck state", async function() { |
||||||
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,55 +1,57 @@ |
|||||||
contract('PullPayment', function(accounts) { |
contract('PullPayment', function(accounts) { |
||||||
|
|
||||||
it("can't call asyncSend externally", async function(done) { |
it("can't call asyncSend externally", async function() { |
||||||
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(done) { |
it("can record an async payment correctly", async function() { |
||||||
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(done) { |
it("can add multiple balances on one account", async function() { |
||||||
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(done) { |
it("can add balances on multiple accounts", async function() { |
||||||
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); |
||||||
|
|
||||||
let paymentsToAccount0 = await ppce.payments(accounts[0]); |
let paymentsToAccount0 = await ppce.payments(accounts[0]); |
||||||
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(done) { |
it("can withdraw payment", async function() { |
||||||
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); |
||||||
|
|
||||||
let ppce = await PullPaymentMock.new({value: AMOUNT}); |
let ppce = await PullPaymentMock.new({value: AMOUNT}); |
||||||
let call1 = await ppce.callSend(payee, AMOUNT); |
let call1 = await ppce.callSend(payee, AMOUNT); |
||||||
|
|
||||||
let payment1 = await ppce.payments(payee); |
let payment1 = await ppce.payments(payee); |
||||||
assert.equal(payment1, AMOUNT); |
assert.equal(payment1, AMOUNT); |
||||||
|
|
||||||
let withdraw = await ppce.withdrawPayments({from: payee}); |
let withdraw = await ppce.withdrawPayments({from: payee}); |
||||||
let payment2 = await ppce.payments(payee); |
let payment2 = await ppce.payments(payee); |
||||||
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,52 +1,52 @@ |
|||||||
contract('Stoppable', function(accounts) { |
contract('Stoppable', function(accounts) { |
||||||
|
|
||||||
it("can perform normal process in non-emergency", async function(done) { |
it("can perform normal process in non-emergency", async function() { |
||||||
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(done) { |
it("can not perform normal process in emergency", async function() { |
||||||
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(); |
||||||
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, 0); |
assert.equal(count1, 0); |
||||||
done(); |
|
||||||
}); |
}); |
||||||
|
|
||||||
|
|
||||||
it("can not take drastic measure in non-emergency", async function(done) { |
it("can not take drastic measure in non-emergency", async function() { |
||||||
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(done) { |
it("can take a drastic measure in an emergency", async function() { |
||||||
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(done) { |
it("should resume allowing normal process after emergency is over", async function() { |
||||||
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(); |
|
||||||
}); |
}); |
||||||
|
|
||||||
}); |
}); |
||||||
|
@ -0,0 +1,3 @@ |
|||||||
|
module.exports = function(error) { |
||||||
|
assert.isAbove(error.message.search('invalid JUMP'), -1, 'Invalid JUMP error must be returned'); |
||||||
|
} |
Loading…
Reference in new issue