Skip to content
This repository has been archived by the owner on May 22, 2023. It is now read-only.

Commit

Permalink
Extracted common tests for bonding abstract contract
Browse files Browse the repository at this point in the history
  • Loading branch information
nkuba committed Aug 11, 2020
1 parent b3931e4 commit 15614dc
Show file tree
Hide file tree
Showing 7 changed files with 1,009 additions and 655 deletions.
11 changes: 6 additions & 5 deletions solidity/contracts/AbstractBonding.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import "@keep-network/keep-core/contracts/StakeDelegatable.sol";
import "@keep-network/sortition-pools/contracts/api/IBonding.sol";
import "openzeppelin-solidity/contracts/math/SafeMath.sol";


/// @title Keep Bonding
/// @notice Contract holding deposits from keeps' operators.
contract AbstractBonding is IBonding {
Expand Down Expand Up @@ -189,11 +190,11 @@ contract AbstractBonding is IBonding {
/// @param holder Address of the holder of the bond.
/// @param referenceID Reference ID of the bond.
/// @return Amount of wei in the selected bond.
function bondAmount(
address operator,
address holder,
uint256 referenceID
) public view returns (uint256) {
function bondAmount(address operator, address holder, uint256 referenceID)
public
view
returns (uint256)
{
bytes32 bondID = keccak256(
abi.encodePacked(operator, holder, referenceID)
);
Expand Down
1 change: 1 addition & 0 deletions solidity/contracts/KeepBonding.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import "./AbstractBonding.sol";
import "@keep-network/keep-core/contracts/TokenGrant.sol";
import "@keep-network/keep-core/contracts/libraries/RolesLookup.sol";


/// @title Keep Bonding
/// @notice Contract holding deposits from keeps' operators.
contract KeepBonding is AbstractBonding {
Expand Down
26 changes: 26 additions & 0 deletions solidity/contracts/test/AbstractBondingStub.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
pragma solidity 0.5.17;

import "../../contracts/AbstractBonding.sol";

contract AbstractBondingStub is AbstractBonding {
constructor(
address registryAddress,
address authorizationsAddress,
address stakeDelegatableAddress
)
public
AbstractBonding(
registryAddress,
authorizationsAddress,
stakeDelegatableAddress
)
{}

function withdraw(uint256 amount, address operator) public {
revert("abstract function");
}

function withdrawBondExposed(uint256 amount, address operator) public {
withdrawBond(amount, operator);
}
}
38 changes: 38 additions & 0 deletions solidity/contracts/test/AuthorizationsStub.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
pragma solidity 0.5.17;

import "@keep-network/keep-core/contracts/Authorizations.sol";
import "@keep-network/keep-core/contracts/KeepRegistry.sol";
import "openzeppelin-solidity/contracts/math/SafeMath.sol";

/// @title Authorizations Stub
/// @dev This contract is for testing purposes only.
contract AuthorizationsStub is Authorizations {
// Authorized operator contracts.
mapping(address => mapping(address => bool)) internal authorizations;

address public delegatedAuthority;

constructor(KeepRegistry _registry) public Authorizations(_registry) {}

function authorizeOperatorContract(
address _operator,
address _operatorContract
) public {
authorizations[_operatorContract][_operator] = true;
}

function isAuthorizedForOperator(
address _operator,
address _operatorContract
) public view returns (bool) {
return authorizations[_operatorContract][_operator];
}

function authorizerOf(address _operator) public view returns (address) {
revert("abstract function");
}

function claimDelegatedAuthority(address delegatedAuthoritySource) public {
delegatedAuthority = delegatedAuthoritySource;
}
}
51 changes: 51 additions & 0 deletions solidity/contracts/test/StakeDelegetableStub.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
pragma solidity 0.5.17;

import "@keep-network/keep-core/contracts/StakeDelegatable.sol";

/// @title Stake Delegatable Stub
/// @dev This contract is for testing purposes only.
contract StakeDelegatableStub is StakeDelegatable {
mapping(address => uint256) stakes;

mapping(address => address) operatorToOwner;
mapping(address => address payable) operatorToBeneficiary;
mapping(address => address) operatorToAuthorizer;

function setBalance(address _operator, uint256 _balance) public {
stakes[_operator] = _balance;
}

function balanceOf(address _address) public view returns (uint256 balance) {
return stakes[_address];
}

function setOwner(address _operator, address _owner) public {
operatorToOwner[_operator] = _owner;
}

function ownerOf(address _operator) public view returns (address) {
return operatorToOwner[_operator];
}

function setBeneficiary(address _operator, address payable _beneficiary)
public
{
operatorToBeneficiary[_operator] = _beneficiary;
}

function beneficiaryOf(address _operator)
public
view
returns (address payable)
{
return operatorToBeneficiary[_operator];
}

function setAuthorizer(address _operator, address _authorizer) public {
operatorToAuthorizer[_operator] = _authorizer;
}

function authorizerOf(address _operator) public view returns (address) {
return operatorToAuthorizer[_operator];
}
}
Loading

0 comments on commit 15614dc

Please sign in to comment.