Renaming ChallengeOverseer to MiningAdjudicator everywhere

pull/507/head
David Núñez 2018-12-05 15:11:17 +01:00 committed by szotov
parent 4d9c0e794e
commit 2f8e956f5c
8 changed files with 48 additions and 48 deletions

View File

@ -16,9 +16,9 @@ contract PolicyManagerInterface {
/**
* @notice ChallengeOverseer interface
* @notice MiningAdjudicator interface
**/
contract ChallengeOverseerInterface {
contract MiningAdjudicatorInterface {
function escrow() public view returns (address);
}
@ -99,7 +99,7 @@ contract MinersEscrow is Issuer {
uint256 public minAllowableLockedTokens;
uint256 public maxAllowableLockedTokens;
PolicyManagerInterface public policyManager;
ChallengeOverseerInterface public challengeOverseer;
MiningAdjudicatorInterface public miningAdjudicator;
/**
* @notice Constructor sets address of token contract and coefficients for mining
@ -159,13 +159,13 @@ contract MinersEscrow is Issuer {
}
/**
* @notice Set challenge overseer address
* @notice Set mining adjudicator address
**/
function setChallengeOverseer(ChallengeOverseerInterface _challengeOverseer) external onlyOwner {
require(address(challengeOverseer) == 0x0 &&
address(_challengeOverseer) != 0x0 &&
_challengeOverseer.escrow() == address(this));
challengeOverseer = _challengeOverseer;
function setMiningAdjudicator(MiningAdjudicatorInterface _miningAdjudicator) external onlyOwner {
require(address(miningAdjudicator) == 0x0 &&
address(_miningAdjudicator) != 0x0 &&
_miningAdjudicator.escrow() == address(this));
miningAdjudicator = _miningAdjudicator;
}
//------------------------Main getters------------------------
@ -775,7 +775,7 @@ contract MinersEscrow is Issuer {
)
public
{
require(msg.sender == address(challengeOverseer));
require(msg.sender == address(miningAdjudicator));
require(_penalty > 0);
MinerInfo storage info = minerInfo[_miner];
if (info.value <= _penalty) {
@ -1116,7 +1116,7 @@ contract MinersEscrow is Issuer {
require(delegateGet(_testTarget, "maxAllowableLockedTokens()") ==
maxAllowableLockedTokens);
require(address(uint160(delegateGet(_testTarget, "policyManager()"))) == address(policyManager));
require(address(delegateGet(_testTarget, "challengeOverseer()")) == address(challengeOverseer));
require(address(delegateGet(_testTarget, "miningAdjudicator()")) == address(miningAdjudicator));
require(delegateGet(_testTarget, "lockedPerPeriod(uint16)",
bytes32(bytes2(RESERVED_PERIOD))) == lockedPerPeriod[RESERVED_PERIOD]);

View File

@ -8,9 +8,9 @@ import "./MinersEscrow.sol";
/**
* @notice Challenges for NuCypher net characters
* @notice Supervises miners' behavior and punishes when something's wrong.
**/
contract ChallengeOverseer {
contract MiningAdjudicator {
uint8 public constant UMBRAL_PARAMETER_U_SIGN = 0x02;
uint256 public constant UMBRAL_PARAMETER_U_XCOORD = 0x03c98795773ff1c241fc0b1cced85e80f8366581dda5c9452175ebd41385fa1f;

View File

@ -2,9 +2,9 @@ pragma solidity ^0.4.25;
/**
* @notice Contract for testing the ChallengeOverseer contract
* @notice Contract for testing the MiningAdjudicator contract
**/
contract MinersEscrowForChallengeOverseerMock {
contract MinersEscrowForMiningAdjudicatorMock {
struct MinerInfo {
uint256 value;

View File

@ -133,7 +133,7 @@ contract PolicyManagerForMinersEscrowMock {
/**
* @notice Contract for testing miners escrow contract
**/
contract ChallengeOverseerForMinersEscrowMock {
contract MiningAdjudicatorForMinersEscrowMock {
MinersEscrow public escrow;

View File

@ -115,7 +115,7 @@ def overseer(testerchain, escrow):
# Creator deploys the contract
# TODO change to the normal contract
contract, _ = testerchain.interface.deploy_contract('ChallengeOverseerForMinersEscrowMock', escrow.address)
contract, _ = testerchain.interface.deploy_contract('MiningAdjudicatorForMinersEscrowMock', escrow.address)
# dispatcher, _ = testerchain.interface.deploy_contract('Dispatcher', contract.address, secret_hash)
# # Wrap dispatcher contract
@ -124,7 +124,7 @@ def overseer(testerchain, escrow):
# address=dispatcher.address,
# ContractFactoryClass=Contract)
tx = escrow.functions.setChallengeOverseer(contract.address).transact({'from': creator})
tx = escrow.functions.setMiningAdjudicator(contract.address).transact({'from': creator})
testerchain.wait_for_receipt(tx)
return contract # , dispatcher

View File

@ -305,9 +305,9 @@ def test_mining(testerchain, token, escrow_contract):
def test_slashing(testerchain, token, escrow_contract):
escrow = escrow_contract(1500)
overseer, _ = testerchain.interface.deploy_contract(
'ChallengeOverseerForMinersEscrowMock', escrow.address
'MiningAdjudicatorForMinersEscrowMock', escrow.address
)
tx = escrow.functions.setChallengeOverseer(overseer.address).transact()
tx = escrow.functions.setMiningAdjudicator(overseer.address).transact()
testerchain.wait_for_receipt(tx)
creator = testerchain.interface.w3.eth.accounts[0]
ursula = testerchain.interface.w3.eth.accounts[1]

View File

@ -26,16 +26,16 @@ secret = (123456).to_bytes(32, byteorder='big')
@pytest.fixture()
def escrow(testerchain):
escrow, _ = testerchain.interface.deploy_contract('MinersEscrowForChallengeOverseerMock')
escrow, _ = testerchain.interface.deploy_contract('MinersEscrowForMiningAdjudicatorMock')
return escrow
# @pytest.fixture(params=[False, True])
@pytest.fixture()
def challenge_contract(testerchain, escrow, request):
def adjudicator_contract(testerchain, escrow, request):
# creator, client, bad_node, node1, node2, node3, *everyone_else = testerchain.interface.w3.eth.accounts
contract, _ = testerchain.interface.deploy_contract('ChallengeOverseer', escrow.address, ALGORITHM_SHA256)
contract, _ = testerchain.interface.deploy_contract('MiningAdjudicator', escrow.address, ALGORITHM_SHA256)
# if request.param:
# secret_hash = testerchain.interface.w3.sha3(secret)

View File

@ -80,15 +80,15 @@ def fragments(metadata):
@pytest.mark.slow
def test_challenge_cfrag(testerchain, escrow, challenge_contract):
def test_challenge_cfrag(testerchain, escrow, adjudicator_contract):
creator, miner, wrong_miner, *everyone_else = testerchain.interface.w3.eth.accounts
# TODO: Move this to an integration test
umbral_params = default_params()
u_xcoord, u_ycoord = umbral_params.u.to_affine()
u_sign = 2 + (u_ycoord % 2)
assert u_sign == challenge_contract.functions.UMBRAL_PARAMETER_U_SIGN().call()
assert u_xcoord == challenge_contract.functions.UMBRAL_PARAMETER_U_XCOORD().call()
assert u_sign == adjudicator_contract.functions.UMBRAL_PARAMETER_U_SIGN().call()
assert u_xcoord == adjudicator_contract.functions.UMBRAL_PARAMETER_U_XCOORD().call()
# TODO: Move this to an integration test
test_data = os.urandom(40)
@ -96,7 +96,7 @@ def test_challenge_cfrag(testerchain, escrow, challenge_contract):
params=umbral_params,
hash_class=ExtendedKeccak)
h = int(h)
h2 = challenge_contract.functions.extendedKeccakToBN(test_data).call()
h2 = adjudicator_contract.functions.extendedKeccakToBN(test_data).call()
assert h == h2
# Prepare one miner
@ -132,13 +132,13 @@ def test_challenge_cfrag(testerchain, escrow, challenge_contract):
assert len(some_data) == 14 * 32
proof_signature = int(evidence.get_proof_challenge_scalar())
assert proof_signature == challenge_contract.functions.computeProofChallengeScalar(capsule_bytes, cfrag_bytes).call()
assert proof_signature == adjudicator_contract.functions.computeProofChallengeScalar(capsule_bytes, cfrag_bytes).call()
hash_ctx = hashes.Hash(hashes.SHA256(), backend=backend)
hash_ctx.update(capsule_bytes + cfrag_bytes)
data_hash = hash_ctx.finalize()
# This capsule and cFrag are not yet challenged
assert not challenge_contract.functions.challengedCFrags(data_hash).call()
assert not adjudicator_contract.functions.challengedCFrags(data_hash).call()
# Generate requester's Umbral key
requester_umbral_private_key = UmbralPrivateKey.gen_key()
@ -159,15 +159,15 @@ def test_challenge_cfrag(testerchain, escrow, challenge_contract):
miner_umbral_public_key_bytes,
signed_miner_umbral_public_key,
some_data)
tx = challenge_contract.functions.challengeCFrag(*args).transact()
tx = adjudicator_contract.functions.challengeCFrag(*args).transact()
testerchain.wait_for_receipt(tx)
# Hash of the data is saved and miner was not slashed
assert challenge_contract.functions.challengedCFrags(data_hash).call()
assert adjudicator_contract.functions.challengedCFrags(data_hash).call()
assert 1000 == escrow.functions.minerInfo(miner).call()[0]
# Can't challenge miner with data that already was checked
with pytest.raises((TransactionFailed, ValueError)):
tx = challenge_contract.functions.challengeCFrag(*args).transact()
tx = adjudicator_contract.functions.challengeCFrag(*args).transact()
testerchain.wait_for_receipt(tx)
# TODO: Fix test for challenge using bad data
@ -192,11 +192,11 @@ def test_challenge_cfrag(testerchain, escrow, challenge_contract):
# signed_miner_umbral_public_key,
# some_data)
#
# assert not challenge_contract.functions.challengedCFrags(data_hash).call()
# tx = challenge_contract.functions.challengeCFrag(*args).transact()
# assert not adjudicator_contract.functions.challengedCFrags(data_hash).call()
# tx = adjudicator_contract.functions.challengeCFrag(*args).transact()
# testerchain.wait_for_receipt(tx)
# # Hash of the data is saved and miner was slashed
# assert challenge_contract.functions.challengedCFrags(data_hash).call()
# assert adjudicator_contract.functions.challengedCFrags(data_hash).call()
# assert 900 == escrow.functions.minerInfo(miner).call()[0]
#
# Prepare hash of the data
@ -219,40 +219,40 @@ def test_challenge_cfrag(testerchain, escrow, challenge_contract):
miner_umbral_public_key_bytes,
signed_miner_umbral_public_key,
some_data]
assert not challenge_contract.functions.challengedCFrags(data_hash).call()
assert not adjudicator_contract.functions.challengedCFrags(data_hash).call()
# Can't challenge miner using broken signatures
wrong_args = args[:]
wrong_args[1] = capsule_signature_by_requester[1:]
with pytest.raises((TransactionFailed, ValueError)):
tx = challenge_contract.functions.challengeCFrag(*wrong_args).transact()
tx = adjudicator_contract.functions.challengeCFrag(*wrong_args).transact()
testerchain.wait_for_receipt(tx)
wrong_args = args[:]
wrong_args[2] = capsule_signature_by_requester_and_miner[1:]
with pytest.raises((TransactionFailed, ValueError)):
tx = challenge_contract.functions.challengeCFrag(*wrong_args).transact()
tx = adjudicator_contract.functions.challengeCFrag(*wrong_args).transact()
testerchain.wait_for_receipt(tx)
wrong_args = args[:]
wrong_args[4] = cfrag_signature_by_miner[1:]
with pytest.raises((TransactionFailed, ValueError)):
tx = challenge_contract.functions.challengeCFrag(*wrong_args).transact()
tx = adjudicator_contract.functions.challengeCFrag(*wrong_args).transact()
testerchain.wait_for_receipt(tx)
wrong_args = args[:]
wrong_args[7] = signed_miner_umbral_public_key[1:]
with pytest.raises((TransactionFailed, ValueError)):
tx = challenge_contract.functions.challengeCFrag(*wrong_args).transact()
tx = adjudicator_contract.functions.challengeCFrag(*wrong_args).transact()
testerchain.wait_for_receipt(tx)
# Can't challenge miner using wrong keys
wrong_args = args[:]
wrong_args[5] = UmbralPrivateKey.gen_key().get_pubkey().to_bytes(is_compressed=False)
with pytest.raises((TransactionFailed, ValueError)):
tx = challenge_contract.functions.challengeCFrag(*wrong_args).transact()
tx = adjudicator_contract.functions.challengeCFrag(*wrong_args).transact()
testerchain.wait_for_receipt(tx)
wrong_args = args[:]
wrong_args[6] = UmbralPrivateKey.gen_key().get_pubkey().to_bytes(is_compressed=False)
with pytest.raises((TransactionFailed, ValueError)):
tx = challenge_contract.functions.challengeCFrag(*wrong_args).transact()
tx = adjudicator_contract.functions.challengeCFrag(*wrong_args).transact()
testerchain.wait_for_receipt(tx)
# TODO: Fix remaining tests
@ -260,12 +260,12 @@ def test_challenge_cfrag(testerchain, escrow, challenge_contract):
# wrong_args = args[:]
# wrong_args[0] = bytes(args[0][0] + 1) + args[0][1:]
# with pytest.raises((TransactionFailed, ValueError)):
# tx = challenge_contract.functions.challengeCFrag(*wrong_args).transact()
# tx = adjudicator_contract.functions.challengeCFrag(*wrong_args).transact()
# testerchain.wait_for_receipt(tx)
# wrong_args = args[:]
# wrong_args[3] = bytes(args[3][0] + 1) + args[3][1:]
# with pytest.raises((TransactionFailed, ValueError)):
# tx = challenge_contract.functions.challengeCFrag(*wrong_args).transact()
# tx = adjudicator_contract.functions.challengeCFrag(*wrong_args).transact()
# testerchain.wait_for_receipt(tx)
#
# # Can't challenge nonexistent miner
@ -275,13 +275,13 @@ def test_challenge_cfrag(testerchain, escrow, challenge_contract):
# wrong_args = args[:]
# wrong_args[7] = signed_miner_umbral_public_key
# with pytest.raises((TransactionFailed, ValueError)):
# tx = challenge_contract.functions.challengeCFrag(*wrong_args).transact()
# tx = adjudicator_contract.functions.challengeCFrag(*wrong_args).transact()
# testerchain.wait_for_receipt(tx)
#
# # Initial arguments were correct
# assert not challenge_contract.functions.challengedCFrags(data_hash).call()
# tx = challenge_contract.functions.challengeCFrag(*args).transact()
# assert not adjudicator_contract.functions.challengedCFrags(data_hash).call()
# tx = adjudicator_contract.functions.challengeCFrag(*args).transact()
# testerchain.wait_for_receipt(tx)
# assert challenge_contract.functions.challengedCFrags(data_hash).call()
# assert adjudicator_contract.functions.challengedCFrags(data_hash).call()
# assert 800 == escrow.functions.minerInfo(miner).call()[0]