Fixes sampling and miner datastore logic from contract API updates

pull/270/head
Kieran Prasch 2018-05-09 18:14:23 -07:00 committed by Kieran R Prasch
parent e6f212a1cc
commit 8cde41da70
4 changed files with 17 additions and 42 deletions

View File

@ -207,18 +207,14 @@ class Miner(TokenActor):
def fetch_data(self) -> tuple:
"""Retrieve all asosciated contract data for this miner."""
count_bytes = self.miner_agent.contract.functions.getMinerInfo(self.miner_agent.MinerInfo.MINER_IDS_LENGTH.value,
self.address, 0).call()
count_bytes = self.miner_agent.contract.functions.getMinerIdsLength(self.address).call()
count = self.blockchain._chain.web3.toInt(count_bytes)
count = self.blockchain.provider.w3.toInt(count_bytes)
miner_ids = list()
for index in range(count):
miner_id = self.miner_agent.contract.functions.getMinerInfo(self.miner_agent.MinerInfo.MINER_ID.value,
self.address, index).call()
encoded_miner_id = miner_id.encode('latin-1')
miner_ids.append(encoded_miner_id)
miner_id = self.miner_agent.contract.functions.getMinerId(self.address, index).call()
miner_ids.append(miner_id)
return tuple(miner_ids)

View File

@ -103,15 +103,9 @@ class MinerAgent(EthereumContractAgent, NuCypherMinerConfig):
Miner addresses will be returned in the order in which they were added to the MinersEscrow's ledger
"""
info_reader = partial(self.contract.functions.getMinerInfo,
self.MinerInfo.MINERS_LENGTH.value, constants.NULL_ADDRESS
# ___,
)
count_bytes = info_reader(0).call()
count = self.blockchain.provider.w3.toInt(count_bytes)
count = self.contract.functions.getMinersLength().call()
for index in range(count):
addr = info_reader(index).call()
addr = self.contract.functions.miners(index).call()
yield self.blockchain.provider.w3.toChecksumAddress(addr)
def sample(self, quantity: int=10, additional_ursulas: float=1.7, attempts: int=5, duration: int=10) -> List[str]:

View File

@ -55,15 +55,14 @@ def test_miner_collects_staking_reward_tokens(chain, miner, mock_token_agent, mo
assert final_balance > initial_balance
@pytest.mark.skip("Last 5 stubborn blockchain tests.")
def test_sample_miners(chain, mock_miner_agent):
def test_sample_miners(chain, mock_miner_agent, mock_token_agent):
mock_token_agent.token_airdrop(amount=100000 * mock_token_agent._M)
_origin, *everyone_else = chain.provider.w3.eth.accounts[1:]
# Have other address lock tokens
_origin, ursula, *everybody_else = chain.provider.w3.eth.accounts
mock_miner_agent.spawn_random_miners(addresses=everybody_else)
chain.spawn_miners(addresses=everyone_else, locktime=100,
miner_agent=mock_miner_agent, m=mock_miner_agent.token_agent._deployer._M)
chain.time_travel(mock_miner_agent._deployer._hours_per_period)
chain.time_travel(periods=1)
with pytest.raises(MinerAgent.NotEnoughUrsulas):
mock_miner_agent.sample(quantity=100) # Waay more than we have deployed
@ -73,15 +72,7 @@ def test_sample_miners(chain, mock_miner_agent):
assert len(set(miners)) == 3
@pytest.mark.skip("Last 5 stubborn blockchain tests.")
def test_publish_miner_datastore(chain, mock_miner_agent):
miner_addr = chain.provider.w3.eth.accounts[1]
miner = Miner(miner_agent=mock_miner_agent, address=miner_addr)
balance = miner.token_balance()
miner.stake(amount=balance, locktime=1)
def test_publish_miner_datastore(miner):
# Publish Miner IDs to the DHT
some_data = os.urandom(32)
@ -102,9 +93,5 @@ def test_publish_miner_datastore(chain, mock_miner_agent):
assert len(stored_miner_ids) == 2
assert another_mock_miner_id == stored_miner_ids[1]
supposedly_the_same_miner_id = mock_miner_agent.contract.functions \
.getMinerInfo(mock_miner_agent.MinerInfoField.MINER_ID.value,
miner_addr, 1).call()
supposedly_the_same_miner_id = miner.miner_agent.contract.functions.getMinerId(miner.address, 1).call()
assert another_mock_miner_id == supposedly_the_same_miner_id

View File

@ -1,6 +1,5 @@
import pytest
from tests.blockchain.eth.utilities import MockNuCypherMinerConfig
M = 10 ** 6
@ -8,14 +7,13 @@ M = 10 ** 6
@pytest.mark.skip("Last 5 stubborn blockchain tests.")
def test_get_swarm(chain, mock_token_agent, mock_miner_agent):
mock_token_agent._token_airdrop(amount=10000)
mock_token_agent.token_airdrop(amount=100000 * mock_token_agent._M)
creator, *addresses = chain.provider.w3.eth.accounts
chain.spawn_miners(addresses=addresses, miner_agent=mock_miner_agent, locktime=1)
mock_miner_agent.spawn_random_miners(addresses=addresses)
default_period_duration = MockNuCypherMinerConfig._hours_per_period
chain.time_travel(default_period_duration)
chain.time_travel(periods=1)
swarm = mock_miner_agent.swarm()
swarm_addresses = list(swarm)