From 348593f46fcea8a5fcb1a569b94a135d5f4ed71f Mon Sep 17 00:00:00 2001 From: Facu Spagnuolo Date: Wed, 15 Jul 2020 10:07:43 -0300 Subject: [PATCH] Disputable: Support payable actions (#593) * Chore: Bump v5.0.0-beta.2 * disputables: support payable actions * disputable: enhance test case description Co-authored-by: Brett Sun Co-authored-by: Brett Sun --- contracts/apps/disputable/DisputableAragonApp.sol | 2 +- contracts/apps/disputable/IAgreement.sol | 2 +- .../test/mocks/apps/disputable/AgreementMock.sol | 4 ++-- .../mocks/apps/disputable/DisputableAppMock.sol | 2 +- test/contracts/apps/disputable/disputable_app.js | 13 ++++++++++++- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/contracts/apps/disputable/DisputableAragonApp.sol b/contracts/apps/disputable/DisputableAragonApp.sol index cf13062dd..8e2907e18 100644 --- a/contracts/apps/disputable/DisputableAragonApp.sol +++ b/contracts/apps/disputable/DisputableAragonApp.sol @@ -129,7 +129,7 @@ contract DisputableAragonApp is IDisputable, AragonApp { */ function _newAgreementAction(uint256 _disputableActionId, bytes _context, address _submitter) internal returns (uint256) { IAgreement agreement = _ensureAgreement(); - return agreement.newAction(_disputableActionId, _context, _submitter); + return agreement.newAction.value(msg.value)(_disputableActionId, _context, _submitter); } /** diff --git a/contracts/apps/disputable/IAgreement.sol b/contracts/apps/disputable/IAgreement.sol index 0fc264d6d..18285fa85 100644 --- a/contracts/apps/disputable/IAgreement.sol +++ b/contracts/apps/disputable/IAgreement.sol @@ -48,7 +48,7 @@ contract IAgreement is IArbitrable, IACLOracle { function deactivate(address _disputable) external; - function newAction(uint256 _disputableActionId, bytes _context, address _submitter) external returns (uint256); + function newAction(uint256 _disputableActionId, bytes _context, address _submitter) external payable returns (uint256); function closeAction(uint256 _actionId) external; diff --git a/contracts/test/mocks/apps/disputable/AgreementMock.sol b/contracts/test/mocks/apps/disputable/AgreementMock.sol index 8254e328f..fef426545 100644 --- a/contracts/test/mocks/apps/disputable/AgreementMock.sol +++ b/contracts/test/mocks/apps/disputable/AgreementMock.sol @@ -2,12 +2,12 @@ pragma solidity 0.4.24; contract AgreementMock { - function newAction(uint256 _disputableActionId, bytes _context, address _submitter) external returns (uint256) { + function newAction(uint256 /* _disputableActionId */, bytes /* _context */, address /* _submitter */) external payable returns (uint256) { // do nothing return 0; } - function closeAction(uint256 _actionId) external { + function closeAction(uint256 /* _actionId */) external { // do nothing } } diff --git a/contracts/test/mocks/apps/disputable/DisputableAppMock.sol b/contracts/test/mocks/apps/disputable/DisputableAppMock.sol index 9a96655d9..65c08d209 100644 --- a/contracts/test/mocks/apps/disputable/DisputableAppMock.sol +++ b/contracts/test/mocks/apps/disputable/DisputableAppMock.sol @@ -16,7 +16,7 @@ contract DisputableAppMock is DisputableAragonApp { initialized(); } - function newAction(uint256 _disputableActionId, bytes _context, address _submitter) external { + function newAction(uint256 _disputableActionId, bytes _context, address _submitter) external payable { _newAgreementAction(_disputableActionId, _context, _submitter); } diff --git a/test/contracts/apps/disputable/disputable_app.js b/test/contracts/apps/disputable/disputable_app.js index 4f08896b9..6096657a2 100644 --- a/test/contracts/apps/disputable/disputable_app.js +++ b/test/contracts/apps/disputable/disputable_app.js @@ -135,14 +135,25 @@ contract('DisputableApp', ([_, owner, agreement, anotherAgreement, someone]) => }) context('when the agreement is set', () => { + let agreement + beforeEach('set agreement', async () => { - const agreement = await AgreementMock.new() + agreement = await AgreementMock.new() await disputable.setAgreement(agreement.address, { from: owner }) }) it('does not revert', async () => { await disputable.newAction(0, '0x00', owner) }) + + it('receives ETH when sent', async () => { + const previousBalance = await web3.eth.getBalance(agreement.address) + + await disputable.newAction(0, '0x00', owner, { value: 1e18 }) + + const currentBalance = await web3.eth.getBalance(agreement.address) + assert.equal(currentBalance.sub(previousBalance).toString(), 1e18, 'agreement balance does not match') + }) }) })