From e795cf5cde9a18753057929a4c5e4abdebe02669 Mon Sep 17 00:00:00 2001 From: jMyles Date: Sun, 24 Feb 2019 21:46:35 -0700 Subject: [PATCH] Some comments and require messages. --- .../blockchain/eth/sol/source/contracts/MinersEscrow.sol | 7 ++++--- .../eth/sol/source/contracts/MiningAdjudicator.sol | 9 ++++++--- .../eth/contracts/main/miners_escrow/conftest.py | 3 ++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/nucypher/blockchain/eth/sol/source/contracts/MinersEscrow.sol b/nucypher/blockchain/eth/sol/source/contracts/MinersEscrow.sol index c24cbcc9d..0e69da3c7 100644 --- a/nucypher/blockchain/eth/sol/source/contracts/MinersEscrow.sol +++ b/nucypher/blockchain/eth/sol/source/contracts/MinersEscrow.sol @@ -162,9 +162,10 @@ contract MinersEscrow is Issuer { * @notice Set mining adjudicator address **/ function setMiningAdjudicator(MiningAdjudicatorInterface _miningAdjudicator) external onlyOwner { - require(address(miningAdjudicator) == address(0) && - address(_miningAdjudicator) != address(0) && - _miningAdjudicator.escrow() == address(this)); + // Three-part require... + require(address(miningAdjudicator) == address(0) && // Can't adjudicator once it is set. + address(_miningAdjudicator) != address(0) && // Check to make sure that we're setting it somewhere. + _miningAdjudicator.escrow() == address(this)); // This is the escrow for the new adjudicator. miningAdjudicator = _miningAdjudicator; } diff --git a/nucypher/blockchain/eth/sol/source/contracts/MiningAdjudicator.sol b/nucypher/blockchain/eth/sol/source/contracts/MiningAdjudicator.sol index a5834299e..dc2044891 100644 --- a/nucypher/blockchain/eth/sol/source/contracts/MiningAdjudicator.sol +++ b/nucypher/blockchain/eth/sol/source/contracts/MiningAdjudicator.sol @@ -61,7 +61,9 @@ contract MiningAdjudicator is Upgradeable { ) public { - require(address(_escrow) != address(0) && + // Sanity checks. + require(address(_escrow) != address(0) && // This contract has an escrow, and it's not the null address. + // The reward and penalty coefficients are set. _percentagePenaltyCoefficient != 0 && _rewardCoefficient != 0); escrow = _escrow; @@ -98,12 +100,13 @@ contract MiningAdjudicator is Upgradeable { ) public { - require(_minerPublicKey.length == 65 && _requesterPublicKey.length == 65); + require(_minerPublicKey.length == 65 && _requesterPublicKey.length == 65, + "Either the requester or miner had an incorrect key length (ie, not 65)"); // Check that CFrag is not evaluated yet bytes32 evaluationHash = SignatureVerifier.hash( abi.encodePacked(_capsuleBytes, _cFragBytes), hashAlgorithm); - require(!evaluatedCFrags[evaluationHash]); + require(!evaluatedCFrags[evaluationHash], "This CFrag has already been evaluated."); // Verify requester's signature of Capsule bytes memory preparedPublicKey = new bytes(64); diff --git a/tests/blockchain/eth/contracts/main/miners_escrow/conftest.py b/tests/blockchain/eth/contracts/main/miners_escrow/conftest.py index cbc61afbe..bde3a5029 100644 --- a/tests/blockchain/eth/contracts/main/miners_escrow/conftest.py +++ b/tests/blockchain/eth/contracts/main/miners_escrow/conftest.py @@ -40,8 +40,9 @@ def token(testerchain): def escrow_contract(testerchain, token, request): def make_escrow(max_allowed_locked_tokens): # Creator deploys the escrow + _mining_coefficient = 2 * 10 ** 7 contract, _ = testerchain.interface.deploy_contract( - 'MinersEscrow', token.address, 1, 4 * 2 * 10 ** 7, 4, 4, 2, 100, max_allowed_locked_tokens) + 'MinersEscrow', token.address, 1, 4 * _mining_coefficient, 4, 4, 2, 100, max_allowed_locked_tokens) if request.param: secret_hash = testerchain.interface.w3.keccak(secret)