mirror of https://github.com/nucypher/nucypher.git
Changed miner id size
parent
4d3496bfa7
commit
50981799c6
|
@ -64,7 +64,7 @@ contract MinersEscrow is Issuer {
|
|||
uint256 lastActivePeriod;
|
||||
Downtime[] downtime;
|
||||
StakeInfo[] stakes;
|
||||
bytes32[] minerIds;
|
||||
bytes[] minerIds;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -624,14 +624,14 @@ contract MinersEscrow is Issuer {
|
|||
/**
|
||||
* @notice Return the miner id
|
||||
**/
|
||||
function getMinerId(address _miner, uint256 _index) public view returns (bytes32) {
|
||||
function getMinerId(address _miner, uint256 _index) public view returns (bytes) {
|
||||
return minerInfo[_miner].minerIds[_index];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Set the miner id
|
||||
**/
|
||||
function setMinerId(bytes32 _minerId) public {
|
||||
function setMinerId(bytes _minerId) public {
|
||||
MinerInfo storage info = minerInfo[msg.sender];
|
||||
info.minerIds.push(_minerId);
|
||||
}
|
||||
|
@ -723,6 +723,18 @@ contract MinersEscrow is Issuer {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Get miner id bytes by delegatecall
|
||||
**/
|
||||
function delegateGetMinerId(address _target, string _signature, address _miner, uint256 _index)
|
||||
internal returns (bytes memory result)
|
||||
{
|
||||
bytes32 memoryAddress = delegateGetData(_target, _signature, 2, bytes32(_miner), bytes32(_index));
|
||||
assembly {
|
||||
result := add(memoryAddress, mload(memoryAddress))
|
||||
}
|
||||
}
|
||||
|
||||
function verifyState(address _testTarget) public onlyOwner {
|
||||
super.verifyState(_testTarget);
|
||||
require(uint256(delegateGet(_testTarget, "minLockedPeriods()")) ==
|
||||
|
@ -769,7 +781,11 @@ contract MinersEscrow is Issuer {
|
|||
|
||||
require(uint256(delegateGet(_testTarget, "getMinerIdsLength(address)", miner)) == info.minerIds.length);
|
||||
for (i = 0; i < info.minerIds.length && i < MAX_CHECKED_VALUES; i++) {
|
||||
require(delegateGet(_testTarget, "getMinerId(address,uint256)", miner, bytes32(i)) == info.minerIds[i]);
|
||||
bytes memory minerIdToCheck =
|
||||
delegateGetMinerId(_testTarget, "getMinerId(address,uint256)", minerAddress, i);
|
||||
bytes storage minerId = info.minerIds[i];
|
||||
require(minerIdToCheck.length == minerId.length &&
|
||||
keccak256(minerIdToCheck) == keccak256(minerId));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -128,7 +128,7 @@ contract ContractV1 is ContractInterface, Upgradeable {
|
|||
require(uint(delegateGet(_testTarget, "storageValue()")) == storageValue);
|
||||
bytes memory value = delegateGetBytes(_testTarget, "dynamicallySizedValue()");
|
||||
require(value.length == bytes(dynamicallySizedValue).length &&
|
||||
keccak256(bytes(value)) == keccak256(bytes(dynamicallySizedValue)));
|
||||
keccak256(value) == keccak256(bytes(dynamicallySizedValue)));
|
||||
|
||||
require(uint(delegateGet(_testTarget, "getArrayValueLength()")) == arrayValues.length);
|
||||
for (uint i = 0; i < arrayValues.length; i++) {
|
||||
|
|
|
@ -137,7 +137,7 @@ contract ContractV2 is ContractInterface, Upgradeable {
|
|||
require(uint(delegateGet(_testTarget, "storageValue()")) == storageValue);
|
||||
bytes memory value = delegateGetBytes(_testTarget, "dynamicallySizedValue()");
|
||||
require(value.length == bytes(dynamicallySizedValue).length &&
|
||||
keccak256(bytes(value)) == keccak256(bytes(dynamicallySizedValue)));
|
||||
keccak256(value) == keccak256(bytes(dynamicallySizedValue)));
|
||||
|
||||
require(uint(delegateGet(_testTarget, "getArrayValueLength()")) == arrayValues.length);
|
||||
for (uint i = 0; i < arrayValues.length; i++) {
|
||||
|
|
|
@ -889,13 +889,13 @@ def test_miner_id(web3, chain, token, escrow_contract):
|
|||
chain.wait_for_receipt(tx)
|
||||
|
||||
# Set miner ids
|
||||
miner_id = os.urandom(32)
|
||||
miner_id = os.urandom(33)
|
||||
tx = escrow.functions.setMinerId(miner_id).transact({'from': miner})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert 1 == escrow.functions.getMinerIdsLength(miner).call()
|
||||
|
||||
assert miner_id == escrow.functions.getMinerId(miner, 0).call()
|
||||
miner_id = os.urandom(32)
|
||||
miner_id = os.urandom(66)
|
||||
tx = escrow.functions.setMinerId(miner_id).transact({'from': miner})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert 2 == escrow.functions.getMinerIdsLength(miner).call()
|
||||
|
@ -940,6 +940,8 @@ def test_verifying_state(web3, chain, token):
|
|||
chain.wait_for_receipt(tx)
|
||||
tx = contract.functions.deposit(balance, 1000).transact({'from': miner})
|
||||
chain.wait_for_receipt(tx)
|
||||
tx = contract.functions.setMinerId(web3.toBytes(111)).transact({'from': miner})
|
||||
chain.wait_for_receipt(tx)
|
||||
|
||||
# Upgrade to the second version
|
||||
tx = dispatcher.functions.upgrade(contract_library_v2.address).transact({'from': creator})
|
||||
|
@ -949,6 +951,8 @@ def test_verifying_state(web3, chain, token):
|
|||
assert 1500 == contract.functions.maxAllowableLockedTokens().call()
|
||||
assert policy_manager.address == contract.functions.policyManager().call()
|
||||
assert 2 == contract.functions.valueToCheck().call()
|
||||
assert 1 == web3.toInt(contract.functions.getMinerIdsLength(miner).call())
|
||||
assert 111 == web3.toInt(contract.functions.getMinerId(miner, 0).call())
|
||||
tx = contract.functions.setValueToCheck(3).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert 3 == contract.functions.valueToCheck().call()
|
||||
|
|
Loading…
Reference in New Issue