mirror of https://github.com/nucypher/nucypher.git
Update contract test to kms provider api usage
parent
33a166bb20
commit
227c8493ef
|
@ -43,9 +43,7 @@ NULL_ADDR = '0x' + '0' * 40
|
|||
def token(web3, chain):
|
||||
creator = web3.eth.accounts[0]
|
||||
# Create an ERC20 token
|
||||
contract, _ = chain.provider.get_or_deploy_contract(
|
||||
'NuCypherKMSToken', deploy_args=[2 * 10 ** 9],
|
||||
deploy_transaction={'from': creator})
|
||||
contract, _ = chain.provider.get_or_deploy_contract('NuCypherKMSToken', 2 * 10 ** 9)
|
||||
return contract
|
||||
|
||||
|
||||
|
@ -54,19 +52,20 @@ def escrow(web3, chain, token):
|
|||
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, 2000],
|
||||
deploy_transaction={'from': creator})
|
||||
'MinersEscrow',
|
||||
token.address,
|
||||
1,
|
||||
4 * 2 * 10 ** 7,
|
||||
4,
|
||||
4,
|
||||
2,
|
||||
100,
|
||||
2000)
|
||||
|
||||
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(
|
||||
contract.abi,
|
||||
dispatcher.address,
|
||||
ContractFactoryClass=Contract)
|
||||
contract = web3.eth.contract(contract.abi, dispatcher.address, ContractFactoryClass=Contract)
|
||||
return contract
|
||||
|
||||
|
||||
|
@ -75,19 +74,11 @@ def policy_manager(web3, chain, escrow):
|
|||
creator = web3.eth.accounts[0]
|
||||
|
||||
# Creator deploys the policy manager
|
||||
contract, _ = chain.provider.get_or_deploy_contract(
|
||||
'PolicyManager', deploy_args=[escrow.address],
|
||||
deploy_transaction={'from': creator})
|
||||
|
||||
dispatcher, _ = chain.provider.deploy_contract(
|
||||
'Dispatcher', deploy_args=[contract.address],
|
||||
deploy_transaction={'from': creator})
|
||||
contract, _ = chain.provider.get_or_deploy_contract('PolicyManager', escrow.address)
|
||||
dispatcher, _ = chain.provider.deploy_contract('Dispatcher', contract.address)
|
||||
|
||||
# Deploy second version of the government contract
|
||||
contract = web3.eth.contract(
|
||||
contract.abi,
|
||||
dispatcher.address,
|
||||
ContractFactoryClass=Contract)
|
||||
contract = web3.eth.contract(contract.abi, dispatcher.address, ContractFactoryClass=Contract)
|
||||
|
||||
tx = escrow.transact({'from': creator}).setPolicyManager(contract.address)
|
||||
chain.wait.for_receipt(tx)
|
||||
|
@ -142,18 +133,14 @@ def test_all(web3, chain, token, escrow, policy_manager):
|
|||
chain.wait.for_receipt(tx)
|
||||
|
||||
# Deposit some tokens to the user escrow and lock them
|
||||
user_escrow_1, _ = chain.provider.deploy_contract(
|
||||
'UserEscrow', deploy_args=[token.address, escrow.address, policy_manager.address],
|
||||
deploy_transaction={'from': creator})
|
||||
user_escrow_1, _ = chain.provider.deploy_contract('UserEscrow', token.address, escrow.address, policy_manager.address)
|
||||
tx = user_escrow_1.transact({'from': creator}).transferOwnership(ursula3)
|
||||
chain.wait.for_receipt(tx)
|
||||
tx = token.transact({'from': creator}).approve(user_escrow_1.address, 10000)
|
||||
chain.wait.for_receipt(tx)
|
||||
tx = user_escrow_1.transact({'from': creator}).initialDeposit(10000, 20 * 60 * 60)
|
||||
chain.wait.for_receipt(tx)
|
||||
user_escrow_2, _ = chain.provider.deploy_contract(
|
||||
'UserEscrow', deploy_args=[token.address, escrow.address, policy_manager.address],
|
||||
deploy_transaction={'from': creator})
|
||||
user_escrow_2, _ = chain.provider.deploy_contract('UserEscrow', token.address, escrow.address, policy_manager.address)
|
||||
tx = user_escrow_2.transact({'from': creator}).transferOwnership(ursula4)
|
||||
chain.wait.for_receipt(tx)
|
||||
tx = token.transact({'from': creator}).approve(user_escrow_2.address, 10000)
|
||||
|
|
|
@ -7,9 +7,7 @@ from web3.contract import Contract
|
|||
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 ** 40],
|
||||
deploy_transaction={'from': creator})
|
||||
token, _ = chain.provider.get_or_deploy_contract('NuCypherKMSToken', 2 * 10 ** 40)
|
||||
return token
|
||||
|
||||
|
||||
|
@ -19,8 +17,7 @@ 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, 10 ** 7, 10 ** 7)
|
||||
|
||||
# Give Miner tokens for reward and initialize contract
|
||||
reserved_reward = 2 * 10 ** 40 - 10 ** 30
|
||||
|
|
|
@ -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', 2 * 10 ** 9)
|
||||
return token
|
||||
|
||||
|
||||
|
@ -38,21 +36,13 @@ 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', deploy_args=[
|
||||
token.address, 1, 4 * 2 * 10 ** 7, 4, 4, 2, 100, max_allowed_locked_tokens],
|
||||
deploy_transaction={'from': creator})
|
||||
contract, _ = chain.provider.get_or_deploy_contract('MinersEscrow', token.address, 1, 4 * 2 * 10 ** 7, 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(
|
||||
contract.abi,
|
||||
dispatcher.address,
|
||||
ContractFactoryClass=Contract)
|
||||
contract = web3.eth.contract(contract.abi, dispatcher.address, ContractFactoryClass=Contract)
|
||||
return contract
|
||||
|
||||
return make_escrow
|
||||
|
@ -430,8 +420,7 @@ 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 +735,13 @@ 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})
|
||||
'MinersEscrow', token.address, 1, 4 * 2 * 10 ** 7, 4, 4, 2, 100, 1500)
|
||||
dispatcher, _ = chain.provider.deploy_contract(
|
||||
'Dispatcher', deploy_args=[contract_library_v1.address],
|
||||
deploy_transaction={'from': creator})
|
||||
'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 +750,7 @@ 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 +775,7 @@ 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)
|
||||
|
|
|
@ -14,10 +14,7 @@ def test_create_token(web3, chain):
|
|||
account2 = web3.eth.accounts[2]
|
||||
|
||||
# Create an ERC20 token
|
||||
token, txhash = chain.provider.get_or_deploy_contract(
|
||||
'NuCypherKMSToken', deploy_args=[10 ** 9],
|
||||
deploy_transaction={
|
||||
'from': creator})
|
||||
token, txhash = chain.provider.get_or_deploy_contract('NuCypherKMSToken', 10 ** 9)
|
||||
assert txhash is not None
|
||||
|
||||
# Account balances
|
||||
|
|
|
@ -6,9 +6,7 @@ from ethereum.tester import TransactionFailed
|
|||
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', 2 * 10 ** 9)
|
||||
return token
|
||||
|
||||
|
||||
|
@ -16,9 +14,7 @@ def token(web3, chain):
|
|||
def escrow(web3, chain, token):
|
||||
creator = web3.eth.accounts[0]
|
||||
# Creator deploys the escrow
|
||||
contract, _ = chain.provider.get_or_deploy_contract(
|
||||
'MinersEscrowForUserEscrowMock', deploy_args=[token.address],
|
||||
deploy_transaction={'from': creator})
|
||||
contract, _ = chain.provider.get_or_deploy_contract('MinersEscrowForUserEscrowMock', token.address)
|
||||
|
||||
# Give escrow some coins
|
||||
tx = token.transact({'from': creator}).transfer(contract.address, 10000)
|
||||
|
@ -39,9 +35,7 @@ def user_escrow(web3, chain, token, escrow, policy_manager):
|
|||
user = web3.eth.accounts[1]
|
||||
|
||||
# Creator deploys the user escrow
|
||||
contract, _ = chain.provider.get_or_deploy_contract(
|
||||
'UserEscrow', deploy_args=[token.address, escrow.address, policy_manager.address],
|
||||
deploy_transaction={'from': creator})
|
||||
contract, _ = chain.provider.get_or_deploy_contract('UserEscrow', token.address, escrow.address, policy_manager.address)
|
||||
|
||||
# Transfer ownership
|
||||
tx = contract.transact({'from': creator}).transferOwnership(user)
|
||||
|
|
Loading…
Reference in New Issue