Sfoglia il codice sorgente

add more limit tests to LimitBalance

Manuel Araoz 9 anni fa
parent
commit
4cd8aa7900
2 ha cambiato i file con 27 aggiunte e 1 eliminazioni
  1. 1 1
      contracts/LimitBalance.sol
  2. 26 0
      test/LimitBalance.js

+ 1 - 1
contracts/LimitBalance.sol

@@ -8,7 +8,7 @@ contract LimitBalance {
   }
 
   modifier limitedPayable() { 
-    if (this.balance + msg.value > limit) {
+    if (this.balance > limit) {
       throw;
     }
     _;

+ 26 - 0
test/LimitBalance.js

@@ -35,4 +35,30 @@ contract('LimitBalance', function(accounts) {
       .then(done)
   });
 
+  it("should allow multiple sends below limit", function(done) {
+    var amount = 500;
+    return lb.limitedDeposit({value: amount})
+      .then(function() { 
+        assert.equal(web3.eth.getBalance(lb.address), amount);
+        return lb.limitedDeposit({value: amount})
+      })
+      .then(function() { 
+        assert.equal(web3.eth.getBalance(lb.address), amount*2);
+      })
+      .then(done)
+  });
+
+  it("shouldnt allow multiple sends above limit", function(done) {
+    var amount = 500;
+    return lb.limitedDeposit({value: amount})
+      .then(function() { 
+        assert.equal(web3.eth.getBalance(lb.address), amount);
+        return lb.limitedDeposit({value: amount+1})
+      })
+      .catch(function(error) {
+        if (error.message.search('invalid JUMP') == -1) throw error;
+      })
+      .then(done)
+  });
+
 });