From 5dbad00a8e7de84f0df9906da3c4ec3ffe79cb75 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Fri, 30 Sep 2016 18:12:28 -0300 Subject: [PATCH 1/5] Fix indenting in ownable --- test/{ownable.js => Ownable.js} | 36 ++++++++++++++++----------------- 1 file changed, 18 insertions(+), 18 deletions(-) rename test/{ownable.js => Ownable.js} (55%) diff --git a/test/ownable.js b/test/Ownable.js similarity index 55% rename from test/ownable.js rename to test/Ownable.js index 163e985e3..83ae4b93e 100644 --- a/test/ownable.js +++ b/test/Ownable.js @@ -2,36 +2,36 @@ contract('Ownable', function(accounts) { it("should have an owner", function(done) { var ownable = Ownable.deployed(); return ownable.owner() - .then(function(owner) { - assert.isTrue(owner != 0); - }) - .then(done) + .then(function(owner) { + assert.isTrue(owner != 0); + }) + .then(done) }); it("changes owner after transfer", function(done) { var ownable = Ownable.deployed(); var other = accounts[1]; return ownable.transfer(other) - .then(function() { - return ownable.owner(); - }) - .then(function(owner) { - assert.isTrue(owner === other); - }) - .then(done) + .then(function() { + return ownable.owner(); + }) + .then(function(owner) { + assert.isTrue(owner === other); + }) + .then(done) }); it("should prevent non-owners from transfering" ,function(done) { var ownable = Ownable.deployed(); var other = accounts[2]; return ownable.transfer(other, {from: accounts[2]}) - .then(function() { - return ownable.owner(); - }) - .then(function(owner) { - assert.isFalse(owner === other); - }) - .then(done) + .then(function() { + return ownable.owner(); + }) + .then(function(owner) { + assert.isFalse(owner === other); + }) + .then(done) }); }); From 9c268990103f35bcd69a33fc05bb1fbdd6756e53 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Fri, 30 Sep 2016 18:12:53 -0300 Subject: [PATCH 2/5] Add public to PullPaymentCapable data --- contracts/PullPaymentCapable.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/PullPaymentCapable.sol b/contracts/PullPaymentCapable.sol index 637a24277..c1c48f056 100644 --- a/contracts/PullPaymentCapable.sol +++ b/contracts/PullPaymentCapable.sol @@ -4,7 +4,7 @@ * Inherit from this contract and use asyncSend instead of send. */ contract PullPaymentCapable { - mapping(address => uint) payments; + mapping(address => uint) public payments; // store sent amount as credit to be pulled, called by payer function asyncSend(address dest, uint amount) internal { From 8f4027cdf6408355afb28b6225b32de39d31c9f1 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Fri, 30 Sep 2016 18:13:10 -0300 Subject: [PATCH 3/5] add PullPaymentCapable test --- test/PullPaymentCapable.js | 26 ++++++++++++++++++++++++++ test/PullPaymentCapableExample.sol | 9 +++++++++ 2 files changed, 35 insertions(+) create mode 100644 test/PullPaymentCapable.js create mode 100644 test/PullPaymentCapableExample.sol diff --git a/test/PullPaymentCapable.js b/test/PullPaymentCapable.js new file mode 100644 index 000000000..92c41a3d0 --- /dev/null +++ b/test/PullPaymentCapable.js @@ -0,0 +1,26 @@ +contract('PullPaymentCapable', function(accounts) { + + it("can't call asyncSend externally", function(done) { + var ppc = PullPaymentCapable.new(); + assert.isUndefined(ppc.asyncSend); + done(); + }); + + it("can record an async payment correctly", function(done) { + var ppce; + var AMOUNT = 1000; + return PullPaymentCapableExample.new() + .then(function(_ppce) { + ppce = _ppce; + ppce.callSend(accounts[0], AMOUNT) + }) + .then(function() { + return ppce.payments(accounts[0]); + }) + .then(function(paymentsToAccount0) { + assert.equal(paymentsToAccount0, AMOUNT); + }) + .then(done); + }); + +}); diff --git a/test/PullPaymentCapableExample.sol b/test/PullPaymentCapableExample.sol new file mode 100644 index 000000000..e467f09da --- /dev/null +++ b/test/PullPaymentCapableExample.sol @@ -0,0 +1,9 @@ +import '../contracts/PullPaymentCapable.sol'; + +// Example class using PullPaymentCapable +contract PullPaymentCapableExample is PullPaymentCapable { + // test helper function to call asyncSend + function callSend(address dest, uint amount) external { + asyncSend(dest, amount); + } +} From 8b921dc6ecca92511a024583b0837614ca926e1a Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Fri, 30 Sep 2016 18:51:42 -0300 Subject: [PATCH 4/5] fix pullpaymentcapable test --- .../examples}/PullPaymentCapableExample.sol | 2 +- test/PullPaymentCapable.js | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) rename {test => contracts/examples}/PullPaymentCapableExample.sol (83%) diff --git a/test/PullPaymentCapableExample.sol b/contracts/examples/PullPaymentCapableExample.sol similarity index 83% rename from test/PullPaymentCapableExample.sol rename to contracts/examples/PullPaymentCapableExample.sol index e467f09da..1925d69d6 100644 --- a/test/PullPaymentCapableExample.sol +++ b/contracts/examples/PullPaymentCapableExample.sol @@ -1,4 +1,4 @@ -import '../contracts/PullPaymentCapable.sol'; +import '../PullPaymentCapable.sol'; // Example class using PullPaymentCapable contract PullPaymentCapableExample is PullPaymentCapable { diff --git a/test/PullPaymentCapable.js b/test/PullPaymentCapable.js index 92c41a3d0..161d1c896 100644 --- a/test/PullPaymentCapable.js +++ b/test/PullPaymentCapable.js @@ -1,14 +1,17 @@ contract('PullPaymentCapable', function(accounts) { it("can't call asyncSend externally", function(done) { - var ppc = PullPaymentCapable.new(); - assert.isUndefined(ppc.asyncSend); - done(); + var ppc; + return PullPaymentCapableExample.new() + .then(function(ppc) { + assert.isUndefined(ppc.asyncSend); + }) + .then(done); }); it("can record an async payment correctly", function(done) { var ppce; - var AMOUNT = 1000; + var AMOUNT = 100; return PullPaymentCapableExample.new() .then(function(_ppce) { ppce = _ppce; From 503faa051d7eb27c444958fecb499b25b00ece05 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Wed, 5 Oct 2016 17:08:40 -0300 Subject: [PATCH 5/5] rename PullPaymentCapable=>PullPayment --- contracts/{PullPaymentCapable.sol => PullPayment.sol} | 0 contracts/test-helpers/PullPaymentMock.sol | 9 +++++++++ test/{PullPaymentCapable.js => PullPayment.js} | 0 3 files changed, 9 insertions(+) rename contracts/{PullPaymentCapable.sol => PullPayment.sol} (100%) create mode 100644 contracts/test-helpers/PullPaymentMock.sol rename test/{PullPaymentCapable.js => PullPayment.js} (100%) diff --git a/contracts/PullPaymentCapable.sol b/contracts/PullPayment.sol similarity index 100% rename from contracts/PullPaymentCapable.sol rename to contracts/PullPayment.sol diff --git a/contracts/test-helpers/PullPaymentMock.sol b/contracts/test-helpers/PullPaymentMock.sol new file mode 100644 index 000000000..ddf5c5f96 --- /dev/null +++ b/contracts/test-helpers/PullPaymentMock.sol @@ -0,0 +1,9 @@ +import '../PullPayment.sol'; + +// mock class using PullPayment +contract PullPaymentMock is PullPayment { + // test helper function to call asyncSend + function callSend(address dest, uint amount) external { + asyncSend(dest, amount); + } +} diff --git a/test/PullPaymentCapable.js b/test/PullPayment.js similarity index 100% rename from test/PullPaymentCapable.js rename to test/PullPayment.js