LimitBalance.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. contract('LimitBalance', function(accounts) {
  2. var lb;
  3. beforeEach(function() {
  4. return LimitBalanceMock.new().then(function(deployed) {
  5. lb = deployed;
  6. });
  7. });
  8. var LIMIT = 1000;
  9. it("should expose limit", function(done) {
  10. return lb.limit()
  11. .then(function(limit) {
  12. assert.equal(limit, LIMIT);
  13. })
  14. .then(done)
  15. });
  16. it("should allow sending below limit", function(done) {
  17. var amount = 1;
  18. return lb.limitedDeposit({value: amount})
  19. .then(function() {
  20. assert.equal(web3.eth.getBalance(lb.address), amount);
  21. })
  22. .then(done)
  23. });
  24. it("shouldnt allow sending above limit", function(done) {
  25. var amount = 1100;
  26. return lb.limitedDeposit({value: amount})
  27. .catch(function(error) {
  28. if (error.message.search('invalid JUMP') == -1) throw error
  29. })
  30. .then(done)
  31. });
  32. it("should allow multiple sends below limit", function(done) {
  33. var amount = 500;
  34. return lb.limitedDeposit({value: amount})
  35. .then(function() {
  36. assert.equal(web3.eth.getBalance(lb.address), amount);
  37. return lb.limitedDeposit({value: amount})
  38. })
  39. .then(function() {
  40. assert.equal(web3.eth.getBalance(lb.address), amount*2);
  41. })
  42. .then(done)
  43. });
  44. it("shouldnt allow multiple sends above limit", function(done) {
  45. var amount = 500;
  46. return lb.limitedDeposit({value: amount})
  47. .then(function() {
  48. assert.equal(web3.eth.getBalance(lb.address), amount);
  49. return lb.limitedDeposit({value: amount+1})
  50. })
  51. .catch(function(error) {
  52. if (error.message.search('invalid JUMP') == -1) throw error;
  53. })
  54. .then(done)
  55. });
  56. });