diff --git a/nkms_eth/blockchain.py b/nkms_eth/blockchain.py index 78043fe44..705484adb 100644 --- a/nkms_eth/blockchain.py +++ b/nkms_eth/blockchain.py @@ -64,9 +64,8 @@ class Blockchain: def wait_time(self, wait_hours, step=50): end_timestamp = self.web3.eth.getBlock(self.web3.eth.blockNumber).timestamp + wait_hours * 60 * 60 - time_yet = self.web3.eth.getBlock(self.web3.eth.blockNumber).timestamp < end_timestamp - while not time_yet: - self.chain.wait.for_block(self.web3.eth.blockNumber+step) + while self.web3.eth.getBlock(self.web3.eth.blockNumber).timestamp < end_timestamp: + self.chain.wait.for_block(self.web3.eth.blockNumber + step) class TesterBlockchain(Blockchain): diff --git a/tests/test_miner.py b/tests/test_miner.py index b66285b89..7b417ce58 100644 --- a/tests/test_miner.py +++ b/tests/test_miner.py @@ -15,12 +15,18 @@ def test_deposit(testerchain, miner, token): def test_select_ursulas(testerchain, token, escrow, miner): + def wait_time(chain, wait_hours): + web3 = chain.web3 + step = 50 + end_timestamp = web3.eth.getBlock(web3.eth.blockNumber).timestamp + wait_hours * 60 * 60 + while web3.eth.getBlock(web3.eth.blockNumber).timestamp < end_timestamp: + chain.wait.for_block(web3.eth.blockNumber + step) token._airdrop() # Create a random set of miners (we have 9 in total) for u in testerchain.web3.eth.accounts[1:]: miner.lock((10 + random.randrange(9000))*M, 100, u) - testerchain.chain.wait.for_block(testerchain.web3.eth.blockNumber+escrow.hours_per_period) + testerchain.wait_time(escrow.hours_per_period) miners = escrow.sample(quantity=3) assert len(miners) == 3