From ee2432661976fe4780b40de595d86b73d581233d Mon Sep 17 00:00:00 2001 From: tuxxy Date: Fri, 13 Apr 2018 17:53:47 -0600 Subject: [PATCH] Remove Populus API calls and use new API --- .../eth/contracts/test_government.py | 62 +++++++++---------- tests/blockchain/eth/contracts/test_issuer.py | 24 +++---- .../eth/contracts/test_miners_escrow.py | 38 +++++------- .../eth/contracts/test_policy_manager.py | 31 +++------- 4 files changed, 63 insertions(+), 92 deletions(-) diff --git a/tests/blockchain/eth/contracts/test_government.py b/tests/blockchain/eth/contracts/test_government.py index 972eed4ce..a64a4d4fa 100644 --- a/tests/blockchain/eth/contracts/test_government.py +++ b/tests/blockchain/eth/contracts/test_government.py @@ -35,12 +35,11 @@ def escrow(web3, chain): # Creator deploys the escrow escrow_library, _ = chain.provider.get_or_deploy_contract( - 'MinersEscrowV1Mock', deploy_args=[ - [node1, node2, node3], [1, 2, 3]], - deploy_transaction={'from': creator}) + 'MinersEscrowV1Mock', [node1, node2, node3], [1, 2, 3] + ) escrow_dispatcher, _ = chain.provider.deploy_contract( - 'Dispatcher', deploy_args=[escrow_library.address], - deploy_transaction={'from': creator}) + 'Dispatcher', escrow_library.address + ) escrow = web3.eth.contract( escrow_library.abi, escrow_dispatcher.address, @@ -52,11 +51,8 @@ def escrow(web3, chain): def policy_manager(web3, chain): creator = web3.eth.accounts[0] # Creator deploys the escrow - policy_manager, _ = chain.provider.get_or_deploy_contract( - 'PolicyManagerV1Mock', deploy_transaction={'from': creator}) - dispatcher, _ = chain.provider.deploy_contract( - 'Dispatcher', deploy_args=[policy_manager.address], - deploy_transaction={'from': creator}) + policy_manager, _ = chain.provider.get_or_deploy_contract('PolicyManagerV1Mock') + dispatcher, _ = chain.provider.deploy_contract('Dispatcher', policy_manager.address) return dispatcher @@ -68,11 +64,11 @@ def test_voting(web3, chain, escrow, policy_manager): # Deploy contract government_library, _ = chain.provider.get_or_deploy_contract( - 'Government', deploy_args=[escrow.address, policy_manager.address, 1], - deploy_transaction={'from': creator}) + 'Government', escrow.address, policy_manager.address, 1, + ) government_dispatcher, _ = chain.provider.deploy_contract( - 'Dispatcher', deploy_args=[government_library.address], - deploy_transaction={'from': creator}) + 'Dispatcher', government_library.address + ) government = web3.eth.contract( government_library.abi, government_dispatcher.address, @@ -93,8 +89,8 @@ def test_voting(web3, chain, escrow, policy_manager): # Deploy second version of the government contract government_library_v2, _ = chain.provider.deploy_contract( - 'Government', deploy_args=[escrow.address, policy_manager.address, 1], - deploy_transaction={'from': creator}) + 'Government', escrow.address, policy_manager.address, 1, + ) assert government_library.address.lower() != government_library_v2.address.lower() # Only tokens owner can create voting @@ -242,11 +238,11 @@ def test_upgrade(web3, chain, escrow, policy_manager): # Deploy contract government_library_v1, _ = chain.provider.get_or_deploy_contract( - 'Government', deploy_args=[escrow.address, policy_manager.address, 1], - deploy_transaction={'from': creator}) + 'Government', escrow.address, policy_manager.address, 1, + ) government_dispatcher, _ = chain.provider.deploy_contract( - 'Dispatcher', deploy_args=[government_library_v1.address], - deploy_transaction={'from': creator}) + 'Dispatcher', government_library_v1.address, + ) government = web3.eth.contract( government_library_v1.abi, government_dispatcher.address, @@ -254,19 +250,18 @@ def test_upgrade(web3, chain, escrow, policy_manager): # Deploy second version of the government contract government_library_v2, _ = chain.provider.deploy_contract( - 'Government', deploy_args=[escrow.address, policy_manager.address, 1], - deploy_transaction={'from': creator}) + 'Government', escrow.address, policy_manager.address, 1, + ) # Get first version of the escrow contract escrow_library_v1 = chain.provider.get_contract('MinersEscrowV1Mock') # Deploy second version of the escrow contract escrow_library_v2, _ = chain.provider.deploy_contract( - 'MinersEscrowV1Mock', deploy_args=[[node1], [1]], - deploy_transaction={'from': creator}) + 'MinersEscrowV1Mock', [node1], [1], + ) # Get first version of the policy manager contract policy_manager_library_v1 = chain.provider.get_contract('PolicyManagerV1Mock') # Deploy second version of the policy manager contract - policy_manager_library_v2, _ = chain.provider.deploy_contract( - 'PolicyManagerV1Mock', deploy_transaction={'from': creator}) + policy_manager_library_v2, _ = chain.provider.deploy_contract('PolicyManagerV1Mock') # Transfer ownership tx = government.transact({'from': creator}).transferOwnership(government.address) @@ -437,16 +432,16 @@ def test_verifying_state(web3, chain): # Deploy contract government_library_v1, _ = chain.provider.get_or_deploy_contract( - 'Government', deploy_args=[address1, address2, 1], - deploy_transaction={'from': creator}) + 'Government', address1, address2, 1, + ) government_dispatcher, _ = chain.provider.deploy_contract( - 'Dispatcher', deploy_args=[government_library_v1.address], - deploy_transaction={'from': creator}) + 'Dispatcher', government_library_v1.address, + ) # Deploy second version of the government contract government_library_v2, _ = chain.provider.deploy_contract( - 'GovernmentV2Mock', deploy_args=[address2, address1, 2], - deploy_transaction={'from': creator}) + 'GovernmentV2Mock', address2, address1, 2, + ) government = web3.eth.contract( government_library_v2.abi, government_dispatcher.address, @@ -464,8 +459,7 @@ def test_verifying_state(web3, chain): assert 3 == government.call().valueToCheck() # Can't upgrade to the previous version or to the bad version - government_library_bad, _ = chain.provider.deploy_contract( - 'GovernmentBad', deploy_transaction={'from': creator}) + government_library_bad, _ = chain.provider.deploy_contract('GovernmentBad') with pytest.raises(TransactionFailed): tx = government_dispatcher.transact({'from': creator}).upgrade(government_library_v1.address) chain.wait.for_receipt(tx) diff --git a/tests/blockchain/eth/contracts/test_issuer.py b/tests/blockchain/eth/contracts/test_issuer.py index 5c82f2d88..e1e8f0cb7 100644 --- a/tests/blockchain/eth/contracts/test_issuer.py +++ b/tests/blockchain/eth/contracts/test_issuer.py @@ -19,8 +19,8 @@ def test_issuer(web3, chain, token): # Creator deploys the issuer issuer, _ = chain.provider.get_or_deploy_contract( - 'IssuerMock', deploy_args=[token.address, 1, 10 ** 46, 10 ** 7, 10 ** 7], - deploy_transaction={'from': creator}) + 'IssuerMock', token.address, 1, 10 ** 46, int(1e7), int(1e7) + ) # Give Miner tokens for reward and initialize contract reserved_reward = 2 * 10 ** 40 - 10 ** 30 @@ -67,8 +67,8 @@ def test_inflation_rate(web3, chain, token): # Creator deploys the miner issuer, _ = chain.provider.get_or_deploy_contract( - 'IssuerMock', deploy_args=[token.address, 1, 2 * 10 ** 19, 1, 1], - deploy_transaction={'from': creator}) + 'IssuerMock', token.address, 1, 2 * 10 ** 19, 1, 1 + ) # Give Miner tokens for reward and initialize contract tx = token.transact({'from': creator}).transfer(issuer.address, 2 * 10 ** 40 - 10 ** 30) @@ -109,16 +109,12 @@ def test_verifying_state(web3, chain, token): # Deploy contract contract_library_v1, _ = chain.provider.get_or_deploy_contract( - 'Issuer', deploy_args=[token.address, 1, 1, 1, 1], - deploy_transaction={'from': creator}) - dispatcher, _ = chain.provider.deploy_contract( - 'Dispatcher', deploy_args=[contract_library_v1.address], - deploy_transaction={'from': creator}) + 'Issuer', token.address, 1, 1, 1, 1 + ) + dispatcher, _ = chain.provider.deploy_contract('Dispatcher', contract_library_v1.address) # Deploy second version of the contract - contract_library_v2, _ = chain.provider.deploy_contract( - 'IssuerV2Mock', deploy_args=[token.address, 2, 2, 2, 2], - deploy_transaction={'from': creator}) + contract_library_v2, _ = chain.provider.deploy_contract('IssuerV2Mock', token.address, 2, 2, 2, 2) contract = web3.eth.contract( contract_library_v2.abi, dispatcher.address, @@ -144,9 +140,7 @@ def test_verifying_state(web3, chain, token): assert 3 == contract.call().valueToCheck() # Can't upgrade to the previous version or to the bad version - contract_library_bad, _ = chain.provider.deploy_contract( - 'IssuerBad', deploy_args=[token.address, 2, 2, 2, 2], - deploy_transaction={'from': creator}) + contract_library_bad, _ = chain.provider.deploy_contract('IssuerBad', token.address, 2, 2, 2, 2) with pytest.raises(TransactionFailed): tx = dispatcher.transact({'from': creator}).upgrade(contract_library_v1.address) chain.wait.for_receipt(tx) diff --git a/tests/blockchain/eth/contracts/test_miners_escrow.py b/tests/blockchain/eth/contracts/test_miners_escrow.py index 6d1b3ccc4..3a9d4a86c 100644 --- a/tests/blockchain/eth/contracts/test_miners_escrow.py +++ b/tests/blockchain/eth/contracts/test_miners_escrow.py @@ -27,9 +27,7 @@ MINER_ID_FIELD = 16 def token(web3, chain): creator = web3.eth.accounts[0] # Create an ERC20 token - token, _ = chain.provider.get_or_deploy_contract( - 'NuCypherKMSToken', deploy_args=[2 * 10 ** 9], - deploy_transaction={'from': creator}) + token, _ = chain.provider.get_or_deploy_contract('NuCypherKMSToken', int(2e9)) return token @@ -39,14 +37,12 @@ def escrow_contract(web3, chain, token, request): creator = web3.eth.accounts[0] # Creator deploys the escrow contract, _ = chain.provider.get_or_deploy_contract( - 'MinersEscrow', deploy_args=[ - token.address, 1, 4 * 2 * 10 ** 7, 4, 4, 2, 100, max_allowed_locked_tokens], - deploy_transaction={'from': creator}) + 'MinersEscrow', token.address, 1, int(8e7), 4, 4, 2, 100, + max_allowed_locked_tokens + ) if request.param: - dispatcher, _ = chain.provider.deploy_contract( - 'Dispatcher', deploy_args=[contract.address], - deploy_transaction={'from': creator}) + dispatcher, _ = chain.provider.deploy_contract('Dispatcher', contract.address) # Deploy second version of the government contract contract = web3.eth.contract( @@ -430,8 +426,8 @@ def test_mining(web3, chain, token, escrow_contract): chain.wait.for_receipt(tx) policy_manager, _ = chain.provider.get_or_deploy_contract( - 'PolicyManagerForMinersEscrowMock', deploy_args=[token.address, escrow.address], - deploy_transaction={'from': creator}) + 'PolicyManagerForMinersEscrowMock', token.address, escrow.address + ) tx = escrow.transact({'from': creator}).setPolicyManager(policy_manager.address) chain.wait.for_receipt(tx) @@ -746,16 +742,14 @@ def test_verifying_state(web3, chain, token): # Deploy contract contract_library_v1, _ = chain.provider.get_or_deploy_contract( - 'MinersEscrow', deploy_args=[token.address, 1, 4 * 2 * 10 ** 7, 4, 4, 2, 100, 1500], - deploy_transaction={'from': creator}) - dispatcher, _ = chain.provider.deploy_contract( - 'Dispatcher', deploy_args=[contract_library_v1.address], - deploy_transaction={'from': creator}) + 'MinersEscrow', token.address, 1, int(8e7), 4, 4, 2, 100, 1500 + ) + dispatcher, _ = chain.provider.deploy_contract('Dispatcher', contract_library_v1.address) # Deploy second version of the contract contract_library_v2, _ = chain.provider.deploy_contract( - 'MinersEscrowV2Mock', deploy_args=[token.address, 2, 2, 2, 2, 2, 2, 2, 2], - deploy_transaction={'from': creator}) + 'MinersEscrowV2Mock', token.address, 2, 2, 2, 2, 2, 2, 2, 2 + ) contract = web3.eth.contract( contract_library_v2.abi, dispatcher.address, @@ -764,8 +758,8 @@ def test_verifying_state(web3, chain, token): # Initialize contract and miner policy_manager, _ = chain.provider.get_or_deploy_contract( - 'PolicyManagerForMinersEscrowMock', deploy_args=[token.address, contract.address], - deploy_transaction={'from': creator}) + 'PolicyManagerForMinersEscrowMock', token.address, contract.address + ) tx = contract.transact({'from': creator}).setPolicyManager(policy_manager.address) chain.wait.for_receipt(tx) tx = contract.transact().initialize() @@ -790,8 +784,8 @@ def test_verifying_state(web3, chain, token): # Can't upgrade to the previous version or to the bad version contract_library_bad, _ = chain.provider.deploy_contract( - 'MinersEscrowBad', deploy_args=[token.address, 2, 2, 2, 2, 2, 2, 2], - deploy_transaction={'from': creator}) + 'MinersEscrowBad', token.address, 2, 2, 2, 2, 2, 2, 2 + ) with pytest.raises(TransactionFailed): tx = dispatcher.transact({'from': creator}).upgrade(contract_library_v1.address) chain.wait.for_receipt(tx) diff --git a/tests/blockchain/eth/contracts/test_policy_manager.py b/tests/blockchain/eth/contracts/test_policy_manager.py index 2b507ea6a..251004fab 100644 --- a/tests/blockchain/eth/contracts/test_policy_manager.py +++ b/tests/blockchain/eth/contracts/test_policy_manager.py @@ -29,9 +29,8 @@ def escrow(web3, chain): node3 = web3.eth.accounts[5] # Creator deploys the escrow escrow, _ = chain.provider.get_or_deploy_contract( - 'MinersEscrowForPolicyMock', - deploy_args=[[node1, node2, node3], MINUTES_IN_PERIOD], - deploy_transaction={'from': creator}) + 'MinersEscrowForPolicyMock', [node1, node2, node3], MINUTES_IN_PERIOD + ) return escrow @@ -42,17 +41,15 @@ def policy_manager(web3, chain, escrow, request): # Creator deploys the policy manager contract, _ = chain.provider.get_or_deploy_contract( - 'PolicyManager', deploy_args=[escrow.address], - deploy_transaction={'from': creator}) + 'PolicyManager', escrow.address + ) # Give client some ether tx = web3.eth.sendTransaction({'from': web3.eth.coinbase, 'to': client, 'value': 10000}) chain.wait.for_receipt(tx) if request.param: - dispatcher, _ = chain.provider.deploy_contract( - 'Dispatcher', deploy_args=[contract.address], - deploy_transaction={'from': creator}) + dispatcher, _ = chain.provider.deploy_contract('Dispatcher', contract.address) # Deploy second version of the government contract contract = web3.eth.contract( @@ -594,17 +591,11 @@ def test_verifying_state(web3, chain): address2 = web3.eth.accounts[2].lower() # Deploy contract - contract_library_v1, _ = chain.provider.get_or_deploy_contract( - 'PolicyManager', deploy_args=[address1], - deploy_transaction={'from': creator}) - dispatcher, _ = chain.provider.deploy_contract( - 'Dispatcher', deploy_args=[contract_library_v1.address], - deploy_transaction={'from': creator}) + contract_library_v1, _ = chain.provider.get_or_deploy_contract('PolicyManager', address1) + dispatcher, _ = chain.provider.deploy_contract('Dispatcher', contract_library_v1.address) # Deploy second version of the contract - contract_library_v2, _ = chain.provider.deploy_contract( - 'PolicyManagerV2Mock', deploy_args=[address2], - deploy_transaction={'from': creator}) + contract_library_v2, _ = chain.provider.deploy_contract('PolicyManagerV2Mock', address2) contract = web3.eth.contract( contract_library_v2.abi, dispatcher.address, @@ -621,9 +612,7 @@ def test_verifying_state(web3, chain): assert 3 == contract.call().valueToCheck() # Can't upgrade to the previous version or to the bad version - contract_library_bad, _ = chain.provider.deploy_contract( - 'PolicyManagerBad', deploy_args=[address2], - deploy_transaction={'from': creator}) + contract_library_bad, _ = chain.provider.deploy_contract('PolicyManagerBad', address2) with pytest.raises(TransactionFailed): tx = dispatcher.transact({'from': creator}).upgrade(contract_library_v1.address) chain.wait.for_receipt(tx) @@ -643,4 +632,4 @@ def test_verifying_state(web3, chain): # Try to upgrade to the bad version with pytest.raises(TransactionFailed): tx = dispatcher.transact({'from': creator}).upgrade(contract_library_bad.address) - chain.wait.for_receipt(tx) \ No newline at end of file + chain.wait.for_receipt(tx)