Implemented ECDSAKeepStub functions
Implemented some of ECDSAKeepStub functions from IBondedECDSAKeep
interface for testing.
@@ -4,11 +4,17 @@ import {
IBondedECDSAKeep
} from "@keep-network/keep-ecdsa/contracts/api/IBondedECDSAKeep.sol";
+import "openzeppelin-solidity/contracts/math/SafeMath.sol";
+
/// @notice Implementation of ECDSAKeep interface used in tests only
/// @dev This is a stub used in tests, so we don't have to call actual ECDSAKeep
contract ECDSAKeepStub is IBondedECDSAKeep {
+ using SafeMath for uint256;
+
bytes publicKey;
bool success;
+ uint256 memberCount = 3;
+ bool isActive = true;
uint256 bondAmount = 10000;
// Notification that the keep was requested to sign a digest.
@@ -27,26 +33,34 @@ contract ECDSAKeepStub is IBondedECDSAKeep {
return bondAmount;
}
- function sign(bytes32 _digest) external {
+ function sign(bytes32 _digest) external onlyWhenActive {
emit SignatureRequested(_digest);
}
function distributeETHReward() external payable {
- // solium-disable-previous-line no-empty-blocks
+ uint256 dividend = msg.value.div(memberCount);
+
+ require(dividend > 0, "Dividend value must be non-zero");
}
function distributeERC20Reward(address _asset, uint256 _value) external {
- // solium-disable-previous-line no-empty-blocks
+ uint256 dividend = _value.div(memberCount);
+
+ require(dividend > 0, "Dividend value must be non-zero");
}
- function seizeSignerBonds() external {
+ function seizeSignerBonds() external onlyWhenActive {
+ isActive = false;
+
if (address(this).balance > 0) {
msg.sender.transfer(address(this).balance);
}
}
function returnPartialSignerBonds() external payable {
- // solium-disable-previous-line no-empty-blocks
+ uint256 bondPerMember = msg.value.div(memberCount);
+
+ require(bondPerMember > 0, "Partial signer bond must be non-zero");
}
function submitSignatureFraud(
@@ -61,12 +75,22 @@ contract ECDSAKeepStub is IBondedECDSAKeep {
return success;
}
- function closeKeep() external {
- // solium-disable-previous-line no-empty-blocks
+ function closeKeep() external onlyWhenActive {
+ isActive = false;
+ }
+
+ modifier onlyWhenActive() {
+ require(isActive, "Keep is not active");
+ _;
}
// Functions to set data for tests.
+ function reset() public {
+ success = true;
+ isActive = true;
+ }
+
function setPublicKey(bytes memory _publicKey) public {
publicKey = _publicKey;
}
@@ -75,6 +99,10 @@ contract ECDSAKeepStub is IBondedECDSAKeep {
success = _success;
}
+ function setMemberCount(uint256 _memberCount) public {
+ memberCount = _memberCount;
+ }
+
function setBondAmount(uint256 _bondAmount) public {
bondAmount = _bondAmount;
}
