fix: made code cleaner. added helper. removed done from most tests.

This commit is contained in:
Angello Pozo
2016-12-01 08:42:05 -08:00
parent 688106e9c3
commit eb41a81faa
11 changed files with 116 additions and 127 deletions

View File

@ -1,59 +1,55 @@
const assertJump = require('./helpers/assertJump');
contract('LimitBalance', function(accounts) {
let lb;
beforeEach(async function(done) {
beforeEach(async function() {
lb = await LimitBalanceMock.new();
done();
});
let LIMIT = 1000;
it("should expose limit", async function(done) {
it("should expose limit", async function() {
let limit = await lb.limit();
assert.equal(limit, LIMIT);
done();
});
it("should allow sending below limit", async function(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);
done();
});
it("shouldnt allow sending above limit", async function(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');
done();
assertJump(error);
}
});
it("should allow multiple sends below limit", async function(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);
done();
});
it("shouldnt allow multiple sends above limit", async function(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 {
await 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');
done();
assertJump(error);
}
});