diff --git a/contracts/PullPaymentCapable.sol b/contracts/PullPayment.sol similarity index 93% rename from contracts/PullPaymentCapable.sol rename to contracts/PullPayment.sol index 637a24277..c1c48f056 100644 --- a/contracts/PullPaymentCapable.sol +++ b/contracts/PullPayment.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 { diff --git a/contracts/examples/PullPaymentCapableExample.sol b/contracts/examples/PullPaymentCapableExample.sol new file mode 100644 index 000000000..1925d69d6 --- /dev/null +++ b/contracts/examples/PullPaymentCapableExample.sol @@ -0,0 +1,9 @@ +import '../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); + } +} 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/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) }); }); diff --git a/test/PullPayment.js b/test/PullPayment.js new file mode 100644 index 000000000..161d1c896 --- /dev/null +++ b/test/PullPayment.js @@ -0,0 +1,29 @@ +contract('PullPaymentCapable', function(accounts) { + + it("can't call asyncSend externally", function(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 = 100; + 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); + }); + +});