From 480dba725ff67acd35b74bda9d02493a977d589b Mon Sep 17 00:00:00 2001 From: moebius <132487952+0xmoebius@users.noreply.github.com> Date: Fri, 15 Dec 2023 09:31:31 -0300 Subject: [PATCH] feat: `validateParameters` (#38) --- package.json | 2 +- .../modules/dispute/BondEscalationModule.sol | 13 ++++++++ .../modules/dispute/BondedDisputeModule.sol | 12 +++++++ .../modules/dispute/CircuitResolverModule.sol | 12 +++++++ .../dispute/RootVerificationModule.sol | 13 ++++++++ .../modules/finality/CallbackModule.sol | 11 +++++++ .../finality/MultipleCallbacksModule.sol | 25 +++++++++++++++ .../request/ContractCallRequestModule.sol | 12 +++++++ .../modules/request/HttpRequestModule.sol | 12 +++++++ .../request/SparseMerkleTreeRequestModule.sol | 13 ++++++++ .../modules/resolution/ArbitratorModule.sol | 11 +++++++ .../BondEscalationResolutionModule.sol | 13 ++++++++ .../resolution/ERC20ResolutionModule.sol | 12 +++++++ .../PrivateERC20ResolutionModule.sol | 12 +++++++ .../modules/response/BondedResponseModule.sol | 12 +++++++ .../dispute/BondEscalationModule.t.sol | 15 +++++++++ .../modules/dispute/BondedDisputeModule.t.sol | 20 ++++++++++-- .../dispute/CircuitResolverModule.t.sol | 14 ++++++++ .../dispute/RootVerificationModule.t.sol | 15 +++++++++ .../modules/finality/CallbackModule.t.sol | 11 +++++++ .../finality/MultipleCallbacksModule.t.sol | 24 ++++++++++++++ .../request/ContractCallRequestModule.t.sol | 14 ++++++++ .../modules/request/HttpRequestModule.t.sol | 32 +++++++++++++++++++ .../SparseMerkleTreeRequestModule.t.sol | 15 +++++++++ .../modules/resolution/ArbitratorModule.t.sol | 11 +++++++ .../BondEscalationResolutionModule.t.sol | 15 +++++++++ .../resolution/ERC20ResolutionModule.t.sol | 14 ++++++++ .../PrivateERC20ResolutionModule.t.sol | 14 ++++++++ .../response/BondedResponseModule.t.sol | 14 ++++++++ yarn.lock | 8 ++--- 30 files changed, 413 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index d5bfcb1a..b9b0df5d 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "package.json": "sort-package-json" }, "dependencies": { - "@defi-wonderland/prophet-core-contracts": "0.0.0-49fc8fa6", + "@defi-wonderland/prophet-core-contracts": "0.0.0-6ac0f50d", "@openzeppelin/contracts": "^4.9.3", "solmate": "https://github.com/transmissions11/solmate.git#bfc9c25865a274a7827fea5abf6e4fb64fc64e6c" }, diff --git a/solidity/contracts/modules/dispute/BondEscalationModule.sol b/solidity/contracts/modules/dispute/BondEscalationModule.sol index 1917b648..6ed1e747 100644 --- a/solidity/contracts/modules/dispute/BondEscalationModule.sol +++ b/solidity/contracts/modules/dispute/BondEscalationModule.sol @@ -295,4 +295,17 @@ contract BondEscalationModule is Module, IBondEscalationModule { function getEscalation(bytes32 _requestId) public view returns (BondEscalation memory _escalation) { _escalation = _escalations[_requestId]; } + + /// @inheritdoc IModule + function validateParameters(bytes calldata _encodedParameters) + external + pure + override(Module, IModule) + returns (bool _valid) + { + RequestParameters memory _params = decodeRequestData(_encodedParameters); + _valid = address(_params.accountingExtension) != address(0) && address(_params.bondToken) != address(0) + && _params.bondSize != 0 && _params.bondEscalationDeadline != 0 && _params.maxNumberOfEscalations != 0 + && _params.tyingBuffer != 0 && _params.disputeWindow != 0; + } } diff --git a/solidity/contracts/modules/dispute/BondedDisputeModule.sol b/solidity/contracts/modules/dispute/BondedDisputeModule.sol index b0c5d0f1..9c43ea64 100644 --- a/solidity/contracts/modules/dispute/BondedDisputeModule.sol +++ b/solidity/contracts/modules/dispute/BondedDisputeModule.sol @@ -103,4 +103,16 @@ contract BondedDisputeModule is Module, IBondedDisputeModule { emit DisputeStatusChanged({_disputeId: _disputeId, _dispute: _dispute, _status: _status}); } + + /// @inheritdoc IModule + function validateParameters(bytes calldata _encodedParameters) + external + pure + override(Module, IModule) + returns (bool _valid) + { + RequestParameters memory _params = decodeRequestData(_encodedParameters); + _valid = address(_params.accountingExtension) != address(0) && address(_params.bondToken) != address(0) + && _params.bondSize != 0; + } } diff --git a/solidity/contracts/modules/dispute/CircuitResolverModule.sol b/solidity/contracts/modules/dispute/CircuitResolverModule.sol index 6f74d340..bb305518 100644 --- a/solidity/contracts/modules/dispute/CircuitResolverModule.sol +++ b/solidity/contracts/modules/dispute/CircuitResolverModule.sol @@ -89,4 +89,16 @@ contract CircuitResolverModule is Module, ICircuitResolverModule { ORACLE.updateDisputeStatus(_request, _response, _dispute, _status); } + + /// @inheritdoc IModule + function validateParameters(bytes calldata _encodedParameters) + external + pure + override(Module, IModule) + returns (bool _valid) + { + RequestParameters memory _params = decodeRequestData(_encodedParameters); + _valid = address(_params.accountingExtension) != address(0) && address(_params.bondToken) != address(0) + && _params.bondSize != 0 && address(_params.verifier) != address(0) && _params.callData.length != 0; + } } diff --git a/solidity/contracts/modules/dispute/RootVerificationModule.sol b/solidity/contracts/modules/dispute/RootVerificationModule.sol index 7454ad90..dadd45a4 100644 --- a/solidity/contracts/modules/dispute/RootVerificationModule.sol +++ b/solidity/contracts/modules/dispute/RootVerificationModule.sol @@ -89,4 +89,17 @@ contract RootVerificationModule is Module, IRootVerificationModule { ORACLE.updateDisputeStatus(_request, _response, _dispute, _status); } + + /// @inheritdoc IModule + function validateParameters(bytes calldata _encodedParameters) + external + pure + override(Module, IModule) + returns (bool _valid) + { + RequestParameters memory _params = decodeRequestData(_encodedParameters); + _valid = address(_params.accountingExtension) != address(0) && address(_params.bondToken) != address(0) + && address(_params.treeVerifier) != address(0) && _params.bondSize != 0 && _params.treeData.length != 0 + && _params.leavesToInsert.length != 0; + } } diff --git a/solidity/contracts/modules/finality/CallbackModule.sol b/solidity/contracts/modules/finality/CallbackModule.sol index 56c5d880..879633b3 100644 --- a/solidity/contracts/modules/finality/CallbackModule.sol +++ b/solidity/contracts/modules/finality/CallbackModule.sol @@ -31,4 +31,15 @@ contract CallbackModule is Module, ICallbackModule { emit Callback(_response.requestId, _params.target, _params.data); emit RequestFinalized(_response.requestId, _response, _finalizer); } + + /// @inheritdoc IModule + function validateParameters(bytes calldata _encodedParameters) + external + pure + override(Module, IModule) + returns (bool _valid) + { + RequestParameters memory _params = decodeRequestData(_encodedParameters); + _valid = address(_params.target) != address(0) && _params.data.length != 0; + } } diff --git a/solidity/contracts/modules/finality/MultipleCallbacksModule.sol b/solidity/contracts/modules/finality/MultipleCallbacksModule.sol index f9a4302b..948ad7f7 100644 --- a/solidity/contracts/modules/finality/MultipleCallbacksModule.sol +++ b/solidity/contracts/modules/finality/MultipleCallbacksModule.sol @@ -39,4 +39,29 @@ contract MultipleCallbacksModule is Module, IMultipleCallbacksModule { emit RequestFinalized(_response.requestId, _response, _finalizer); } + + /// @inheritdoc IModule + function validateParameters(bytes calldata _encodedParameters) + external + pure + override(Module, IModule) + returns (bool _valid) + { + RequestParameters memory _params = decodeRequestData(_encodedParameters); + _valid = true; + + for (uint256 _i; _i < _params.targets.length; ++_i) { + if (_params.targets[_i] == address(0)) { + _valid = false; + break; + } + } + + for (uint256 _i; _i < _params.data.length; ++_i) { + if (_params.data[_i].length == 0) { + _valid = false; + break; + } + } + } } diff --git a/solidity/contracts/modules/request/ContractCallRequestModule.sol b/solidity/contracts/modules/request/ContractCallRequestModule.sol index 90966cf2..27b22a50 100644 --- a/solidity/contracts/modules/request/ContractCallRequestModule.sol +++ b/solidity/contracts/modules/request/ContractCallRequestModule.sol @@ -59,4 +59,16 @@ contract ContractCallRequestModule is Module, IContractCallRequestModule { emit RequestFinalized(_response.requestId, _response, _finalizer); } + + /// @inheritdoc IModule + function validateParameters(bytes calldata _encodedParameters) + external + pure + override(Module, IModule) + returns (bool _valid) + { + RequestParameters memory _params = decodeRequestData(_encodedParameters); + _valid = address(_params.accountingExtension) != address(0) && address(_params.paymentToken) != address(0) + && _params.target != address(0) && _params.paymentAmount != 0 && _params.functionSelector != bytes4(0); + } } diff --git a/solidity/contracts/modules/request/HttpRequestModule.sol b/solidity/contracts/modules/request/HttpRequestModule.sol index e924edc5..97f41ede 100644 --- a/solidity/contracts/modules/request/HttpRequestModule.sol +++ b/solidity/contracts/modules/request/HttpRequestModule.sol @@ -59,4 +59,16 @@ contract HttpRequestModule is Module, IHttpRequestModule { emit RequestFinalized(_response.requestId, _response, _finalizer); } + + /// @inheritdoc IModule + function validateParameters(bytes calldata _encodedParameters) + external + pure + override(Module, IModule) + returns (bool _valid) + { + RequestParameters memory _params = decodeRequestData(_encodedParameters); + _valid = address(_params.accountingExtension) != address(0) && address(_params.paymentToken) != address(0) + && _params.paymentAmount != 0 && bytes(_params.url).length != 0 && bytes(_params.body).length != 0; + } } diff --git a/solidity/contracts/modules/request/SparseMerkleTreeRequestModule.sol b/solidity/contracts/modules/request/SparseMerkleTreeRequestModule.sol index 18585fbd..03834b43 100644 --- a/solidity/contracts/modules/request/SparseMerkleTreeRequestModule.sol +++ b/solidity/contracts/modules/request/SparseMerkleTreeRequestModule.sol @@ -59,4 +59,17 @@ contract SparseMerkleTreeRequestModule is Module, ISparseMerkleTreeRequestModule emit RequestFinalized(_response.requestId, _response, _finalizer); } + + /// @inheritdoc IModule + function validateParameters(bytes calldata _encodedParameters) + external + pure + override(Module, IModule) + returns (bool _valid) + { + RequestParameters memory _params = decodeRequestData(_encodedParameters); + _valid = address(_params.accountingExtension) != address(0) && address(_params.paymentToken) != address(0) + && address(_params.treeVerifier) != address(0) && _params.paymentAmount != 0 && _params.treeData.length != 0 + && _params.leavesToInsert.length != 0; + } } diff --git a/solidity/contracts/modules/resolution/ArbitratorModule.sol b/solidity/contracts/modules/resolution/ArbitratorModule.sol index c8276abf..8d4af435 100644 --- a/solidity/contracts/modules/resolution/ArbitratorModule.sol +++ b/solidity/contracts/modules/resolution/ArbitratorModule.sol @@ -66,4 +66,15 @@ contract ArbitratorModule is Module, IArbitratorModule { emit DisputeResolved(_dispute.requestId, _disputeId, _status); } + + /// @inheritdoc IModule + function validateParameters(bytes calldata _encodedParameters) + external + pure + override(Module, IModule) + returns (bool _valid) + { + RequestParameters memory _params = decodeRequestData(_encodedParameters); + _valid = _params.arbitrator != address(0); + } } diff --git a/solidity/contracts/modules/resolution/BondEscalationResolutionModule.sol b/solidity/contracts/modules/resolution/BondEscalationResolutionModule.sol index d0b456e5..f58c234b 100644 --- a/solidity/contracts/modules/resolution/BondEscalationResolutionModule.sol +++ b/solidity/contracts/modules/resolution/BondEscalationResolutionModule.sol @@ -339,4 +339,17 @@ contract BondEscalationResolutionModule is Module, IBondEscalationResolutionModu _resolution: _resolution }); } + + /// @inheritdoc IModule + function validateParameters(bytes calldata _encodedParameters) + external + pure + override(Module, IModule) + returns (bool _valid) + { + RequestParameters memory _params = decodeRequestData(_encodedParameters); + _valid = address(_params.accountingExtension) != address(0) && address(_params.bondToken) != address(0) + && _params.percentageDiff != 0 && _params.pledgeThreshold != 0 && _params.timeUntilDeadline != 0 + && _params.timeToBreakInequality != 0; + } } diff --git a/solidity/contracts/modules/resolution/ERC20ResolutionModule.sol b/solidity/contracts/modules/resolution/ERC20ResolutionModule.sol index 382dd40e..6917b9f7 100644 --- a/solidity/contracts/modules/resolution/ERC20ResolutionModule.sol +++ b/solidity/contracts/modules/resolution/ERC20ResolutionModule.sol @@ -130,4 +130,16 @@ contract ERC20ResolutionModule is Module, IERC20ResolutionModule { function getVoters(bytes32 _disputeId) external view returns (address[] memory __voters) { __voters = _voters[_disputeId].values(); } + + /// @inheritdoc IModule + function validateParameters(bytes calldata _encodedParameters) + external + pure + override(Module, IModule) + returns (bool _valid) + { + RequestParameters memory _params = decodeRequestData(_encodedParameters); + _valid = address(_params.accountingExtension) != address(0) && address(_params.votingToken) != address(0) + && _params.minVotesForQuorum != 0 && _params.timeUntilDeadline != 0; + } } diff --git a/solidity/contracts/modules/resolution/PrivateERC20ResolutionModule.sol b/solidity/contracts/modules/resolution/PrivateERC20ResolutionModule.sol index 9cb8522d..4019f307 100644 --- a/solidity/contracts/modules/resolution/PrivateERC20ResolutionModule.sol +++ b/solidity/contracts/modules/resolution/PrivateERC20ResolutionModule.sol @@ -159,4 +159,16 @@ contract PrivateERC20ResolutionModule is Module, IPrivateERC20ResolutionModule { ) external view returns (bytes32 _commitment) { _commitment = keccak256(abi.encode(msg.sender, _disputeId, _numberOfVotes, _salt)); } + + /// @inheritdoc IModule + function validateParameters(bytes calldata _encodedParameters) + external + pure + override(Module, IModule) + returns (bool _valid) + { + RequestParameters memory _params = decodeRequestData(_encodedParameters); + _valid = address(_params.accountingExtension) != address(0) && address(_params.votingToken) != address(0) + && _params.minVotesForQuorum != 0 && _params.committingTimeWindow != 0 && _params.revealingTimeWindow != 0; + } } diff --git a/solidity/contracts/modules/response/BondedResponseModule.sol b/solidity/contracts/modules/response/BondedResponseModule.sol index 44697545..fd0ffa52 100644 --- a/solidity/contracts/modules/response/BondedResponseModule.sol +++ b/solidity/contracts/modules/response/BondedResponseModule.sol @@ -87,4 +87,16 @@ contract BondedResponseModule is Module, IBondedResponseModule { emit RequestFinalized(_response.requestId, _response, _finalizer); } + + /// @inheritdoc IModule + function validateParameters(bytes calldata _encodedParameters) + external + pure + override(Module, IModule) + returns (bool _valid) + { + RequestParameters memory _params = decodeRequestData(_encodedParameters); + _valid = address(_params.accountingExtension) != address(0) && address(_params.bondToken) != address(0) + && _params.bondSize != 0 && _params.disputeWindow != 0 && _params.deadline != 0; + } } diff --git a/solidity/test/unit/modules/dispute/BondEscalationModule.t.sol b/solidity/test/unit/modules/dispute/BondEscalationModule.t.sol index bcfb9477..01c156d9 100644 --- a/solidity/test/unit/modules/dispute/BondEscalationModule.t.sol +++ b/solidity/test/unit/modules/dispute/BondEscalationModule.t.sol @@ -183,6 +183,21 @@ contract BondEscalationModule_Unit_ModuleData is BaseTest { assertEq(_params.tyingBuffer, _decodedParams.tyingBuffer); assertEq(_params.disputeWindow, _decodedParams.disputeWindow); } + + /** + * @notice Test that the validateParameters function correctly checks the parameters + */ + function test_validateParameters(IBondEscalationModule.RequestParameters calldata _params) public { + if ( + address(_params.accountingExtension) == address(0) || address(_params.bondToken) == address(0) + || _params.bondSize == 0 || _params.bondEscalationDeadline == 0 || _params.maxNumberOfEscalations == 0 + || _params.tyingBuffer == 0 || _params.disputeWindow == 0 + ) { + assertFalse(bondEscalationModule.validateParameters(abi.encode(_params))); + } else { + assertTrue(bondEscalationModule.validateParameters(abi.encode(_params))); + } + } } contract BondEscalationModule_Unit_EscalateDispute is BaseTest { diff --git a/solidity/test/unit/modules/dispute/BondedDisputeModule.t.sol b/solidity/test/unit/modules/dispute/BondedDisputeModule.t.sol index f25d41e4..4f663538 100644 --- a/solidity/test/unit/modules/dispute/BondedDisputeModule.t.sol +++ b/solidity/test/unit/modules/dispute/BondedDisputeModule.t.sol @@ -49,7 +49,7 @@ contract BaseTest is Test, Helpers { } } -contract BondedResponseModule_Unit_ModuleData is BaseTest { +contract BondedDisputeModule_Unit_ModuleData is BaseTest { /** * @notice Test that the decodeRequestData function returns the correct values */ @@ -76,9 +76,23 @@ contract BondedResponseModule_Unit_ModuleData is BaseTest { function test_moduleNameReturnsName() public { assertEq(bondedDisputeModule.moduleName(), 'BondedDisputeModule'); } + + /** + * @notice Test that the validateParameters function correctly checks the parameters + */ + function test_validateParameters(IBondedDisputeModule.RequestParameters calldata _params) public { + if ( + address(_params.accountingExtension) == address(0) || address(_params.bondToken) == address(0) + || _params.bondSize == 0 + ) { + assertFalse(bondedDisputeModule.validateParameters(abi.encode(_params))); + } else { + assertTrue(bondedDisputeModule.validateParameters(abi.encode(_params))); + } + } } -contract BondedResponseModule_Unit_OnDisputeStatusChange is BaseTest { +contract BondedDisputeModule_Unit_OnDisputeStatusChange is BaseTest { /** * @notice Dispute lost by disputer */ @@ -221,7 +235,7 @@ contract BondedResponseModule_Unit_OnDisputeStatusChange is BaseTest { } } -contract BondedResponseModule_Unit_DisputeResponse is BaseTest { +contract BondedDisputeModule_Unit_DisputeResponse is BaseTest { /** * @notice Test if dispute response returns the correct status */ diff --git a/solidity/test/unit/modules/dispute/CircuitResolverModule.t.sol b/solidity/test/unit/modules/dispute/CircuitResolverModule.t.sol index 3ca5b3cd..cb387a4e 100644 --- a/solidity/test/unit/modules/dispute/CircuitResolverModule.t.sol +++ b/solidity/test/unit/modules/dispute/CircuitResolverModule.t.sol @@ -102,6 +102,20 @@ contract CircuitResolverModule_Unit_ModuleData is BaseTest { function test_moduleName() public { assertEq(circuitResolverModule.moduleName(), 'CircuitResolverModule'); } + + /** + * @notice Test that the validateParameters function correctly checks the parameters + */ + function test_validateParameters(ICircuitResolverModule.RequestParameters calldata _params) public { + if ( + address(_params.accountingExtension) == address(0) || address(_params.bondToken) == address(0) + || _params.bondSize == 0 || address(_params.verifier) == address(0) || _params.callData.length == 0 + ) { + assertFalse(circuitResolverModule.validateParameters(abi.encode(_params))); + } else { + assertTrue(circuitResolverModule.validateParameters(abi.encode(_params))); + } + } } contract CircuitResolverModule_Unit_DisputeResponse is BaseTest { diff --git a/solidity/test/unit/modules/dispute/RootVerificationModule.t.sol b/solidity/test/unit/modules/dispute/RootVerificationModule.t.sol index 442a6599..63268009 100644 --- a/solidity/test/unit/modules/dispute/RootVerificationModule.t.sol +++ b/solidity/test/unit/modules/dispute/RootVerificationModule.t.sol @@ -144,6 +144,21 @@ contract RootVerificationModule_Unit_ModuleData is BaseTest { assertEq(address(_params.bondToken), _randomToken, 'Mismatch: decoded token'); assertEq(_params.bondSize, _bondSize, 'Mismatch: decoded bond size'); } + + /** + * @notice Test that the validateParameters function correctly checks the parameters + */ + function test_validateParameters(IRootVerificationModule.RequestParameters calldata _params) public { + if ( + address(_params.accountingExtension) == address(0) || address(_params.bondToken) == address(0) + || address(_params.treeVerifier) == address(0) || _params.bondSize == 0 || _params.treeData.length == 0 + || _params.leavesToInsert.length == 0 + ) { + assertFalse(rootVerificationModule.validateParameters(abi.encode(_params))); + } else { + assertTrue(rootVerificationModule.validateParameters(abi.encode(_params))); + } + } } contract RootVerificationModule_Unit_DisputeResponse is BaseTest { diff --git a/solidity/test/unit/modules/finality/CallbackModule.t.sol b/solidity/test/unit/modules/finality/CallbackModule.t.sol index 35c35e80..999255be 100644 --- a/solidity/test/unit/modules/finality/CallbackModule.t.sol +++ b/solidity/test/unit/modules/finality/CallbackModule.t.sol @@ -55,6 +55,17 @@ contract CallbackModule_Unit_ModuleData is BaseTest { assertEq(_params.target, _target); assertEq(_params.data, _data); } + + /** + * @notice Test that the validateParameters function correctly checks the parameters + */ + function test_validateParameters(ICallbackModule.RequestParameters calldata _params) public { + if (address(_params.target) == address(0) || _params.data.length == 0) { + assertFalse(callbackModule.validateParameters(abi.encode(_params))); + } else { + assertTrue(callbackModule.validateParameters(abi.encode(_params))); + } + } } contract CallbackModule_Unit_FinalizeRequest is BaseTest { diff --git a/solidity/test/unit/modules/finality/MultipleCallbacksModule.t.sol b/solidity/test/unit/modules/finality/MultipleCallbacksModule.t.sol index 7f91e73b..a3fe909d 100644 --- a/solidity/test/unit/modules/finality/MultipleCallbacksModule.t.sol +++ b/solidity/test/unit/modules/finality/MultipleCallbacksModule.t.sol @@ -43,6 +43,30 @@ contract MultipleCallbacksModule_Unit_ModuleData is BaseTest { function test_moduleNameReturnsName() public { assertEq(multipleCallbackModule.moduleName(), 'MultipleCallbacksModule'); } + + /** + * @notice Test that the validateParameters function correctly checks the parameters + */ + function test_validateParameters(IMultipleCallbacksModule.RequestParameters calldata _params) public { + bool _valid = true; + for (uint256 _i; _i < _params.targets.length; ++_i) { + if (_params.targets[_i] == address(0)) { + _valid = false; + } + } + + for (uint256 _i; _i < _params.data.length; ++_i) { + if (_params.data[_i].length == 0) { + _valid = false; + } + } + + if (!_valid) { + assertFalse(multipleCallbackModule.validateParameters(abi.encode(_params))); + } else { + assertTrue(multipleCallbackModule.validateParameters(abi.encode(_params))); + } + } } contract MultipleCallbacksModule_Unit_FinalizeRequests is BaseTest { diff --git a/solidity/test/unit/modules/request/ContractCallRequestModule.t.sol b/solidity/test/unit/modules/request/ContractCallRequestModule.t.sol index 2848360d..26fdbd13 100644 --- a/solidity/test/unit/modules/request/ContractCallRequestModule.t.sol +++ b/solidity/test/unit/modules/request/ContractCallRequestModule.t.sol @@ -86,6 +86,20 @@ contract ContractCallRequestModule_Unit_ModuleData is BaseTest { assertEq(address(_params.paymentToken), address(_paymentToken), 'Mismatch: decoded payment token'); assertEq(_params.paymentAmount, _paymentAmount, 'Mismatch: decoded payment amount'); } + + /** + * @notice Test that the validateParameters function correctly checks the parameters + */ + function test_validateParameters(IContractCallRequestModule.RequestParameters calldata _params) public { + if ( + address(_params.accountingExtension) == address(0) || address(_params.paymentToken) == address(0) + || _params.target == address(0) || _params.paymentAmount == 0 || _params.functionSelector == bytes4(0) + ) { + assertFalse(contractCallRequestModule.validateParameters(abi.encode(_params))); + } else { + assertTrue(contractCallRequestModule.validateParameters(abi.encode(_params))); + } + } } contract ContractCallRequestModule_Unit_CreateRequest is BaseTest { diff --git a/solidity/test/unit/modules/request/HttpRequestModule.t.sol b/solidity/test/unit/modules/request/HttpRequestModule.t.sol index 3c9a460d..b69ebcd6 100644 --- a/solidity/test/unit/modules/request/HttpRequestModule.t.sol +++ b/solidity/test/unit/modules/request/HttpRequestModule.t.sol @@ -76,6 +76,38 @@ contract HttpRequestModule_Unit_ModuleData is BaseTest { assertEq(address(_params.paymentToken), address(_token)); assertEq(_params.paymentAmount, _amount); } + + /** + * @notice Test that the validateParameters function correctly checks the parameters + */ + function test_validateParameters( + string memory _url, + string memory _body, + uint256 _method, + address _accountingExtension, + address _paymentToken, + uint256 _paymentAmount + ) public { + _method = bound(_method, 0, 1); + + IHttpRequestModule.RequestParameters memory _params = IHttpRequestModule.RequestParameters({ + url: _url, + body: _body, + method: IHttpRequestModule.HttpMethod(_method), + accountingExtension: IAccountingExtension(_accountingExtension), + paymentToken: IERC20(_paymentToken), + paymentAmount: _paymentAmount + }); + + if ( + address(_params.accountingExtension) == address(0) || address(_params.paymentToken) == address(0) + || _params.paymentAmount == 0 || bytes(_params.url).length == 0 || bytes(_params.body).length == 0 + ) { + assertFalse(httpRequestModule.validateParameters(abi.encode(_params))); + } else { + assertTrue(httpRequestModule.validateParameters(abi.encode(_params))); + } + } } contract HttpRequestModule_Unit_FinalizeRequest is BaseTest { diff --git a/solidity/test/unit/modules/request/SparseMerkleTreeRequestModule.t.sol b/solidity/test/unit/modules/request/SparseMerkleTreeRequestModule.t.sol index 14a59cc5..56ca229c 100644 --- a/solidity/test/unit/modules/request/SparseMerkleTreeRequestModule.t.sol +++ b/solidity/test/unit/modules/request/SparseMerkleTreeRequestModule.t.sol @@ -124,6 +124,21 @@ contract SparseMerkleTreeRequestModule_Unit_ModuleData is BaseTest { assertEq(address(_params.paymentToken), address(_paymentToken), 'Mismatch: decoded payment token'); assertEq(_params.paymentAmount, _paymentAmount, 'Mismatch: decoded payment amount'); } + + /** + * @notice Test that the validateParameters function correctly checks the parameters + */ + function test_validateParameters(ISparseMerkleTreeRequestModule.RequestParameters calldata _params) public { + if ( + address(_params.accountingExtension) == address(0) || address(_params.paymentToken) == address(0) + || address(_params.treeVerifier) == address(0) || _params.paymentAmount == 0 || _params.treeData.length == 0 + || _params.leavesToInsert.length == 0 + ) { + assertFalse(sparseMerkleTreeRequestModule.validateParameters(abi.encode(_params))); + } else { + assertTrue(sparseMerkleTreeRequestModule.validateParameters(abi.encode(_params))); + } + } } contract SparseMerkleTreeRequestModule_Unit_FinalizeRequest is BaseTest { diff --git a/solidity/test/unit/modules/resolution/ArbitratorModule.t.sol b/solidity/test/unit/modules/resolution/ArbitratorModule.t.sol index a6dcade9..254aca94 100644 --- a/solidity/test/unit/modules/resolution/ArbitratorModule.t.sol +++ b/solidity/test/unit/modules/resolution/ArbitratorModule.t.sol @@ -89,6 +89,17 @@ contract ArbitratorModule_Unit_ModuleData is BaseTest { // Check: The correct status is returned? assertEq(uint256(arbitratorModule.getStatus(_disputeId)), uint256(_status)); } + + /** + * @notice Test that the validateParameters function correctly checks the parameters + */ + function test_validateParameters(IArbitratorModule.RequestParameters calldata _params) public { + if (_params.arbitrator == address(0)) { + assertFalse(arbitratorModule.validateParameters(abi.encode(_params))); + } else { + assertTrue(arbitratorModule.validateParameters(abi.encode(_params))); + } + } } contract ArbitratorModule_Unit_StartResolution is BaseTest { diff --git a/solidity/test/unit/modules/resolution/BondEscalationResolutionModule.t.sol b/solidity/test/unit/modules/resolution/BondEscalationResolutionModule.t.sol index 2b7b1118..d8ef56fe 100644 --- a/solidity/test/unit/modules/resolution/BondEscalationResolutionModule.t.sol +++ b/solidity/test/unit/modules/resolution/BondEscalationResolutionModule.t.sol @@ -193,6 +193,21 @@ contract BondEscalationResolutionModule_Unit_ModuleData is BaseTest { function test_moduleName() public { assertEq(module.moduleName(), 'BondEscalationResolutionModule'); } + + /** + * @notice Test that the validateParameters function correctly checks the parameters + */ + function test_validateParameters(IBondEscalationResolutionModule.RequestParameters calldata _params) public { + if ( + address(_params.accountingExtension) == address(0) || address(_params.bondToken) == address(0) + || _params.percentageDiff == 0 || _params.pledgeThreshold == 0 || _params.timeUntilDeadline == 0 + || _params.timeToBreakInequality == 0 + ) { + assertFalse(module.validateParameters(abi.encode(_params))); + } else { + assertTrue(module.validateParameters(abi.encode(_params))); + } + } } contract BondEscalationResolutionModule_Unit_StartResolution is BaseTest { diff --git a/solidity/test/unit/modules/resolution/ERC20ResolutionModule.t.sol b/solidity/test/unit/modules/resolution/ERC20ResolutionModule.t.sol index b9beaa43..45ad4563 100644 --- a/solidity/test/unit/modules/resolution/ERC20ResolutionModule.t.sol +++ b/solidity/test/unit/modules/resolution/ERC20ResolutionModule.t.sol @@ -105,6 +105,20 @@ contract ERC20ResolutionModule_Unit_ModuleData is BaseTest { assertEq(_params.minVotesForQuorum, _minVotesForQuorum); assertEq(_params.timeUntilDeadline, _votingTimeWindow); } + + /** + * @notice Test that the validateParameters function correctly checks the parameters + */ + function test_validateParameters(IERC20ResolutionModule.RequestParameters calldata _params) public { + if ( + address(_params.accountingExtension) == address(0) || address(_params.votingToken) == address(0) + || _params.minVotesForQuorum == 0 || _params.timeUntilDeadline == 0 + ) { + assertFalse(module.validateParameters(abi.encode(_params))); + } else { + assertTrue(module.validateParameters(abi.encode(_params))); + } + } } contract ERC20ResolutionModule_Unit_StartResolution is BaseTest { diff --git a/solidity/test/unit/modules/resolution/PrivateERC20ResolutionModule.t.sol b/solidity/test/unit/modules/resolution/PrivateERC20ResolutionModule.t.sol index 448c052f..11ebc992 100644 --- a/solidity/test/unit/modules/resolution/PrivateERC20ResolutionModule.t.sol +++ b/solidity/test/unit/modules/resolution/PrivateERC20ResolutionModule.t.sol @@ -115,6 +115,20 @@ contract PrivateERC20ResolutionModule_Unit_ModuleData is BaseTest { function test_moduleName() public { assertEq(module.moduleName(), 'PrivateERC20ResolutionModule'); } + + /** + * @notice Test that the validateParameters function correctly checks the parameters + */ + function test_validateParameters(IPrivateERC20ResolutionModule.RequestParameters calldata _params) public { + if ( + address(_params.accountingExtension) == address(0) || address(_params.votingToken) == address(0) + || _params.minVotesForQuorum == 0 || _params.committingTimeWindow == 0 || _params.revealingTimeWindow == 0 + ) { + assertFalse(module.validateParameters(abi.encode(_params))); + } else { + assertTrue(module.validateParameters(abi.encode(_params))); + } + } } contract PrivateERC20ResolutionModule_Unit_StartResolution is BaseTest { diff --git a/solidity/test/unit/modules/response/BondedResponseModule.t.sol b/solidity/test/unit/modules/response/BondedResponseModule.t.sol index a53d12f2..becc97b1 100644 --- a/solidity/test/unit/modules/response/BondedResponseModule.t.sol +++ b/solidity/test/unit/modules/response/BondedResponseModule.t.sol @@ -71,6 +71,20 @@ contract BondedResponseModule_Unit_ModuleData is BaseTest { assertEq(_params.deadline, _deadline, 'Mismatch: deadline'); assertEq(_params.disputeWindow, _disputeWindow, 'Mismatch: dispute window'); } + + /** + * @notice Test that the validateParameters function correctly checks the parameters + */ + function test_validateParameters(IBondedResponseModule.RequestParameters calldata _params) public { + if ( + address(_params.accountingExtension) == address(0) || address(_params.bondToken) == address(0) + || _params.bondSize == 0 || _params.disputeWindow == 0 || _params.deadline == 0 + ) { + assertFalse(bondedResponseModule.validateParameters(abi.encode(_params))); + } else { + assertTrue(bondedResponseModule.validateParameters(abi.encode(_params))); + } + } } contract BondedResponseModule_Unit_Propose is BaseTest { diff --git a/yarn.lock b/yarn.lock index ff1d0fbe..ea9a5e38 100644 --- a/yarn.lock +++ b/yarn.lock @@ -192,10 +192,10 @@ dependencies: "@jridgewell/trace-mapping" "0.3.9" -"@defi-wonderland/prophet-core-contracts@0.0.0-49fc8fa6": - version "0.0.0-49fc8fa6" - resolved "https://registry.yarnpkg.com/@defi-wonderland/prophet-core-contracts/-/prophet-core-contracts-0.0.0-49fc8fa6.tgz#53d3488a1f0c1513d7887ae5647210900b4d7dd9" - integrity sha512-FAmCxlnLGJk7pK1R0PYSNBay7Fqk4CUBJPoua6dvUw/q/RsZJeK8IVAoYII2OOXIn0XqFRysXIMAK/SV71wQQw== +"@defi-wonderland/prophet-core-contracts@0.0.0-6ac0f50d": + version "0.0.0-6ac0f50d" + resolved "https://registry.yarnpkg.com/@defi-wonderland/prophet-core-contracts/-/prophet-core-contracts-0.0.0-6ac0f50d.tgz#64c903e6d529628f192e3d083959cdec7105bf99" + integrity sha512-FsiOHl4h1s64CoNpCmuSB+Q0v6Mg4PLAcT4v9x5FA7iTMpexVy8dq+GyXDNch82bpaOojic8rwh4jm+eB4bT8g== "@defi-wonderland/solidity-utils@0.0.0-3e9c8e8b": version "0.0.0-3e9c8e8b"