LimitBalance.test.js 1.5 KB

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