mirror of https://github.com/nucypher/nucypher.git
Update contract test api calls
commit
1a7fa8e75c
|
@ -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)
|
||||
|
|
|
@ -17,7 +17,8 @@ def test_issuer(web3, chain, token):
|
|||
|
||||
# Creator deploys the issuer
|
||||
issuer, _ = chain.provider.get_or_deploy_contract(
|
||||
'IssuerMock', token.address, 1, 10 ** 46, 10 ** 7, 10 ** 7)
|
||||
'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
|
||||
|
@ -64,8 +65,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)
|
||||
|
@ -106,16 +107,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,
|
||||
|
@ -141,9 +138,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)
|
||||
|
|
|
@ -27,7 +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', 2 * 10 ** 9)
|
||||
token, _ = chain.provider.get_or_deploy_contract('NuCypherKMSToken', int(2e9))
|
||||
return token
|
||||
|
||||
|
||||
|
@ -36,7 +36,11 @@ def escrow_contract(web3, chain, token, request):
|
|||
def make_escrow(max_allowed_locked_tokens):
|
||||
creator = web3.eth.accounts[0]
|
||||
# Creator deploys the escrow
|
||||
contract, _ = chain.provider.get_or_deploy_contract('MinersEscrow', token.address, 1, 4 * 2 * 10 ** 7, 4, 4, 2, 100, max_allowed_locked_tokens)
|
||||
|
||||
contract, _ = chain.provider.get_or_deploy_contract(
|
||||
'MinersEscrow', token.address, 1, int(8e7), 4, 4, 2, 100,
|
||||
max_allowed_locked_tokens
|
||||
)
|
||||
|
||||
if request.param:
|
||||
dispatcher, _ = chain.provider.deploy_contract('Dispatcher', contract.address)
|
||||
|
@ -420,7 +424,8 @@ def test_mining(web3, chain, token, escrow_contract):
|
|||
chain.wait.for_receipt(tx)
|
||||
|
||||
policy_manager, _ = chain.provider.get_or_deploy_contract(
|
||||
'PolicyManagerForMinersEscrowMock', token.address, escrow.address)
|
||||
'PolicyManagerForMinersEscrowMock', token.address, escrow.address
|
||||
)
|
||||
tx = escrow.transact({'from': creator}).setPolicyManager(policy_manager.address)
|
||||
chain.wait.for_receipt(tx)
|
||||
|
||||
|
@ -735,13 +740,14 @@ def test_verifying_state(web3, chain, token):
|
|||
|
||||
# Deploy contract
|
||||
contract_library_v1, _ = chain.provider.get_or_deploy_contract(
|
||||
'MinersEscrow', token.address, 1, 4 * 2 * 10 ** 7, 4, 4, 2, 100, 1500)
|
||||
dispatcher, _ = chain.provider.deploy_contract(
|
||||
'Dispatcher', contract_library_v1.address)
|
||||
'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', token.address, 2, 2, 2, 2, 2, 2, 2, 2)
|
||||
'MinersEscrowV2Mock', token.address, 2, 2, 2, 2, 2, 2, 2, 2
|
||||
)
|
||||
contract = web3.eth.contract(
|
||||
contract_library_v2.abi,
|
||||
dispatcher.address,
|
||||
|
@ -749,8 +755,8 @@ def test_verifying_state(web3, chain, token):
|
|||
assert 1500 == contract.call().maxAllowableLockedTokens()
|
||||
|
||||
# Initialize contract and miner
|
||||
policy_manager, _ = chain.provider.get_or_deploy_contract(
|
||||
'PolicyManagerForMinersEscrowMock', token.address, contract.address)
|
||||
policy_manager, _ = chain.provider.get_or_deploy_contract('PolicyManagerForMinersEscrowMock', token.address, contract.address)
|
||||
|
||||
tx = contract.transact({'from': creator}).setPolicyManager(policy_manager.address)
|
||||
chain.wait.for_receipt(tx)
|
||||
tx = contract.transact().initialize()
|
||||
|
@ -774,8 +780,8 @@ 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(
|
||||
'MinersEscrowBad', token.address, 2, 2, 2, 2, 2, 2, 2)
|
||||
contract_library_bad, _ = chain.provider.deploy_contract('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)
|
||||
|
|
|
@ -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)
|
||||
chain.wait.for_receipt(tx)
|
||||
|
|
Loading…
Reference in New Issue