You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.5 KiB
60 lines
1.5 KiB
8 years ago
|
|
||
|
var LimitBalanceMock = artifacts.require('helpers/LimitBalanceMock.sol');
|
||
7 years ago
|
const assertRevert = require('./helpers/assertRevert');
|
||
8 years ago
|
|
||
7 years ago
|
contract('LimitBalance', function (accounts) {
|
||
8 years ago
|
let lb;
|
||
8 years ago
|
|
||
7 years ago
|
beforeEach(async function () {
|
||
8 years ago
|
lb = await LimitBalanceMock.new();
|
||
8 years ago
|
});
|
||
|
|
||
8 years ago
|
let LIMIT = 1000;
|
||
8 years ago
|
|
||
7 years ago
|
it('should expose limit', async function () {
|
||
8 years ago
|
let limit = await lb.limit();
|
||
|
assert.equal(limit, LIMIT);
|
||
8 years ago
|
});
|
||
|
|
||
7 years ago
|
it('should allow sending below limit', async function () {
|
||
8 years ago
|
let amount = 1;
|
||
7 years ago
|
await lb.limitedDeposit({ value: amount });
|
||
8 years ago
|
|
||
8 years ago
|
assert.equal(web3.eth.getBalance(lb.address), amount);
|
||
8 years ago
|
});
|
||
|
|
||
7 years ago
|
it('shouldnt allow sending above limit', async function () {
|
||
8 years ago
|
let amount = 1110;
|
||
|
try {
|
||
7 years ago
|
await lb.limitedDeposit({ value: amount });
|
||
8 years ago
|
assert.fail('should have thrown before');
|
||
7 years ago
|
} catch (error) {
|
||
7 years ago
|
assertRevert(error);
|
||
7 years ago
|
}
|
||
8 years ago
|
});
|
||
|
|
||
7 years ago
|
it('should allow multiple sends below limit', async function () {
|
||
8 years ago
|
let amount = 500;
|
||
7 years ago
|
await lb.limitedDeposit({ value: amount });
|
||
8 years ago
|
|
||
8 years ago
|
assert.equal(web3.eth.getBalance(lb.address), amount);
|
||
8 years ago
|
|
||
7 years ago
|
await lb.limitedDeposit({ value: amount });
|
||
|
assert.equal(web3.eth.getBalance(lb.address), amount * 2);
|
||
8 years ago
|
});
|
||
|
|
||
7 years ago
|
it('shouldnt allow multiple sends above limit', async function () {
|
||
8 years ago
|
let amount = 500;
|
||
7 years ago
|
await lb.limitedDeposit({ value: amount });
|
||
8 years ago
|
|
||
8 years ago
|
assert.equal(web3.eth.getBalance(lb.address), amount);
|
||
8 years ago
|
|
||
8 years ago
|
try {
|
||
7 years ago
|
await lb.limitedDeposit({ value: amount + 1 });
|
||
8 years ago
|
assert.fail('should have thrown before');
|
||
7 years ago
|
} catch (error) {
|
||
7 years ago
|
assertRevert(error);
|
||
7 years ago
|
}
|
||
8 years ago
|
});
|
||
8 years ago
|
});
|