LimitBalance.test.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. const { assertRevert } = require('./helpers/assertRevert');
  2. const { ethGetBalance } = require('./helpers/web3');
  3. const LimitBalanceMock = artifacts.require('LimitBalanceMock');
  4. const BigNumber = web3.BigNumber;
  5. require('chai')
  6. .use(require('chai-bignumber')(BigNumber))
  7. .should();
  8. contract('LimitBalance', function () {
  9. let limitBalance;
  10. beforeEach(async function () {
  11. limitBalance = await LimitBalanceMock.new();
  12. });
  13. const LIMIT = 1000;
  14. it('should expose limit', async function () {
  15. const limit = await limitBalance.limit();
  16. limit.should.be.bignumber.equal(LIMIT);
  17. });
  18. it('should allow sending below limit', async function () {
  19. const amount = 1;
  20. await limitBalance.limitedDeposit({ value: amount });
  21. const balance = await ethGetBalance(limitBalance.address);
  22. balance.should.be.bignumber.equal(amount);
  23. });
  24. it('shouldnt allow sending above limit', async function () {
  25. const amount = 1110;
  26. await assertRevert(limitBalance.limitedDeposit({ value: amount }));
  27. });
  28. it('should allow multiple sends below limit', async function () {
  29. const amount = 500;
  30. await limitBalance.limitedDeposit({ value: amount });
  31. const balance = await ethGetBalance(limitBalance.address);
  32. balance.should.be.bignumber.equal(amount);
  33. await limitBalance.limitedDeposit({ value: amount });
  34. const updatedBalance = await ethGetBalance(limitBalance.address);
  35. updatedBalance.should.be.bignumber.equal(amount * 2);
  36. });
  37. it('shouldnt allow multiple sends above limit', async function () {
  38. const amount = 500;
  39. await limitBalance.limitedDeposit({ value: amount });
  40. const balance = await ethGetBalance(limitBalance.address);
  41. balance.should.be.bignumber.equal(amount);
  42. await assertRevert(limitBalance.limitedDeposit({ value: amount + 1 }));
  43. });
  44. });