Time Travel Fixes, Remove skips, fixes post-rebase

pull/270/head
Kieran Prasch 2018-05-10 09:07:36 -07:00 committed by Kieran R Prasch
parent e176ba82b7
commit b546c7159b
7 changed files with 26 additions and 16 deletions

View File

@ -85,18 +85,24 @@ class TesterBlockchain(TheBlockchain, NuCypherMinerConfig):
result = self.provider.w3.eth.waitForTransactionReceipt(txhash, timeout=timeout)
return result
def time_travel(self, hours: int=None, periods: int=None):
def time_travel(self, hours: int=None, seconds: int=None, periods: int=None):
"""
Wait the specified number of wait_hours by comparing
block timestamps and mines a single block.
"""
if hours and periods or (hours is None and periods is None):
raise ValueError("Specify either hours or periods.")
querytime = list(filter(lambda t: bool(t), (hours, seconds, periods)))
if len(querytime) > 1:
raise ValueError("Specify hours, seconds, or periods, not a combination")
if periods:
hours = (self._hours_per_period * periods)
duration = hours * (60 * 60)
duration = (self._hours_per_period * periods) * (60 * 60)
elif hours:
duration = hours * (60 * 60)
elif seconds:
duration = seconds
else:
raise ValueError("Specify either hours, seconds, or periods.")
end_timestamp = self.provider.w3.eth.getBlock(block_identifier='latest').timestamp + duration
self.provider.w3.eth.web3.testing.timeTravel(timestamp=end_timestamp)

View File

@ -53,10 +53,6 @@ def policy_manager(web3, chain, escrow, request):
return contract
def wait_time(chain, wait_periods):
chain.time_travel(seconds=wait_periods * 60 * MINUTES_IN_PERIOD)
MINUTES_IN_PERIOD = 10
policy_id = os.urandom(20)
policy_id_2 = os.urandom(20)
@ -66,6 +62,14 @@ number_of_periods = 10
value = rate * number_of_periods
def wait_time(chain, wait_periods):
seconds = wait_periods * 60 * MINUTES_IN_PERIOD
end_timestamp = chain.provider.w3.eth.getBlock(block_identifier='latest').timestamp + seconds
chain.provider.w3.eth.web3.testing.timeTravel(timestamp=end_timestamp)
chain.provider.w3.eth.web3.testing.mine(1)
@pytest.mark.slow
def test_create_revoke(web3, chain, escrow, policy_manager):
creator, client, bad_node, node1, node2, node3, *everyone_else = web3.eth.accounts

View File

@ -56,6 +56,7 @@ def test_miner_collects_staking_reward_tokens(chain, miner, mock_token_agent, mo
assert final_balance > initial_balance
@pytest.mark.slow()
def test_sample_miners(chain, mock_miner_agent, mock_token_agent):
mock_token_agent.token_airdrop(amount=100000 * mock_token_agent._M)

View File

@ -4,7 +4,6 @@ import pytest
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=100000 * mock_token_agent._M)

View File

@ -1,4 +1,5 @@
import pytest
from pytest import raises
from nucypher.blockchain.eth.agents import NuCypherTokenAgent, MinerAgent
from nucypher.blockchain.eth.deployers import NuCypherTokenDeployer, MinerEscrowDeployer, PolicyManagerDeployer
@ -43,7 +44,6 @@ def test_token_deployer_and_agent(chain):
assert token_agent == same_token_agent # __eq__
@pytest.mark.slow
def test_deploy_ethereum_contracts(chain):
"""
Launch all ethereum contracts:

View File

@ -66,9 +66,9 @@ class MockMinerAgent(MinerAgent, MockNuCypherMinerConfig):
return miners
class MockNuCypherKMSTokenDeployer(NuCypherTokenDeployer):
class MockNuCypherTokenDeployer(NuCypherTokenDeployer):
"""Mock deployer with mock agency"""
# agency = MockTokenAgent
agency = MockTokenAgent
class MockMinerEscrowDeployer(MinerEscrowDeployer, MockNuCypherMinerConfig):

View File

@ -14,11 +14,11 @@ from web3.middleware import geth_poa_middleware
from nucypher.blockchain.eth.agents import PolicyAgent
from nucypher.blockchain.eth.chains import TheBlockchain, TesterBlockchain
from nucypher.blockchain.eth.deployers import PolicyManagerDeployer, NuCypherTokenDeployer
from nucypher.blockchain.eth.deployers import PolicyManagerDeployer
from nucypher.blockchain.eth.interfaces import Registrar, ContractProvider
from nucypher.blockchain.eth.sol.compile import SolidityCompiler
from tests.blockchain.eth import contracts, utilities
from tests.blockchain.eth.utilities import MockMinerEscrowDeployer, TesterPyEVMBackend
from tests.blockchain.eth.utilities import MockMinerEscrowDeployer, TesterPyEVMBackend, MockNuCypherTokenDeployer
#
@ -171,7 +171,7 @@ def chain(contract_provider, airdrop=False):
@pytest.fixture(scope='module')
def mock_token_deployer(chain):
token_deployer = NuCypherTokenDeployer(blockchain=chain)
token_deployer = MockNuCypherTokenDeployer(blockchain=chain)
token_deployer.arm()
token_deployer.deploy()
yield token_deployer