diff --git a/tests/conftest.py b/tests/conftest.py index ca021ba8c..b7a615db1 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -13,14 +13,19 @@ def testerchain(): @pytest.fixture() def token(testerchain): - return NuCypherKMSToken(blockchain=testerchain) + token = NuCypherKMSToken(blockchain=testerchain) + token.arm().deploy() + return token @pytest.fixture() def escrow(testerchain, token): - return Escrow(blockchain=testerchain, token=token) + escrow = Escrow(blockchain=testerchain, token=token) + escrow.arm().deploy() + return escrow @pytest.fixture() def miner(testerchain, escrow, token): - return Miner(blockchain=testerchain, token=token, escrow=escrow) + address = testerchain.web3.eth.accounts[1] + return Miner(blockchain=testerchain, token=token, escrow=escrow, address=address) diff --git a/tests/test_escrow.py b/tests/test_escrow.py index ae5a63998..d77804a90 100644 --- a/tests/test_escrow.py +++ b/tests/test_escrow.py @@ -8,16 +8,30 @@ from nkms_eth.token import NuCypherKMSToken def test_create_escrow(testerchain): with raises(NoKnownAddress): NuCypherKMSToken.get(blockchain=testerchain) + token = NuCypherKMSToken(blockchain=testerchain) + token.arm() + token.deploy() + same_token = NuCypherKMSToken.get(blockchain=testerchain) + with raises(NuCypherKMSToken.ContractDeploymentError): + same_token.arm() + same_token.deploy() assert len(token.contract.address) == 42 assert token.contract.address == same_token.contract.address with raises(NoKnownAddress): Escrow.get(blockchain=testerchain, token=token) + escrow = Escrow(blockchain=testerchain, token=token) + escrow.arm() + escrow.deploy() + same_escrow = Escrow.get(blockchain=testerchain, token=token) + with raises(Escrow.ContractDeploymentError): + same_escrow.arm() + same_escrow.deploy() assert len(escrow.contract.address) == 42 assert escrow.contract.address == same_escrow.contract.address \ No newline at end of file diff --git a/tests/test_miner.py b/tests/test_miner.py index a3a66717b..8589bf784 100644 --- a/tests/test_miner.py +++ b/tests/test_miner.py @@ -10,16 +10,17 @@ M = 10 ** 6 def test_deposit(testerchain, miner, token): - token._airdrop() - miner.lock(amount=1000*M, locktime=100, address=testerchain.web3.eth.accounts[1]) + token._airdrop(amount=10000) + miner.lock(amount=1000*M, locktime=100) -def test_select_ursulas(testerchain, token, escrow, miner): - - token._airdrop() +def test_select_ursulas(testerchain, token, escrow): + token._airdrop(amount=10000) # 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) + miner = Miner(blockchain=testerchain, token=token, escrow=escrow, address=u) + amount = (10 + random.randrange(9000))*M + miner.lock(amount=amount, locktime=100) testerchain.wait_time(escrow.hours_per_period) miners = escrow.sample(quantity=3) @@ -30,20 +31,24 @@ def test_select_ursulas(testerchain, token, escrow, miner): escrow.sample(quantity=100) # Waay more than we have deployed -def test_mine_withdraw(testerchain, miner, token, escrow): - token._airdrop() +def test_mine_withdraw(testerchain, token, miner, escrow): + token._airdrop(amount=10000) - addr = testerchain.web3.eth.accounts[1] - initial_balance = token.balance(address=addr) + ursula = miner + initial_balance = token.balance(address=ursula.address) # Create a random set of miners (we have 9 in total) for address in testerchain.web3.eth.accounts[1:]: - miner.lock(amount=(10 + random.randrange(9000))*M, locktime=1, address=address) + miner = Miner(blockchain=testerchain, token=token, + escrow=escrow, address=address) + + amount = (10+random.randrange(9000)) * M + miner.lock(amount=amount, locktime=1) testerchain.wait_time(escrow.hours_per_period*2) - miner.mine(addr) - miner.withdraw(addr) - final_balance = token.balance(addr) + ursula.mint() + ursula.withdraw() + final_balance = token.balance(ursula.address) assert final_balance > initial_balance diff --git a/tests/test_nucypher_kms_token.py b/tests/test_nucypher_kms_token.py index e8bc240f9..7bcef701a 100644 --- a/tests/test_nucypher_kms_token.py +++ b/tests/test_nucypher_kms_token.py @@ -12,6 +12,9 @@ def test_get_token_before_creation(testerchain): def test_create_nucypher_kms_token(testerchain): token = NuCypherKMSToken(blockchain=testerchain) + token.arm() + token.deploy() + assert len(token.contract.address) == 42 assert token.contract.call().totalSupply() != 0 assert token.contract.call().totalSupply() == 1000000000000000000000000000 @@ -23,6 +26,8 @@ def test_create_then_get_nucypher_kms_token(testerchain): NuCypherKMSToken.get(blockchain=testerchain) token = NuCypherKMSToken(blockchain=testerchain) + token.arm() + token.deploy() assert len(token.contract.address) == 42 assert token.contract.call().totalSupply() != 0