mirror of https://github.com/nucypher/nucypher.git
Deprecated compadability fixtures, updates contract tests to testechain.interface api
parent
043e158c2c
commit
8a65ca14f2
|
@ -38,16 +38,16 @@ ROLLBACK_POLICY_MANAGER = 5
|
|||
|
||||
|
||||
@pytest.fixture()
|
||||
def token(chain):
|
||||
def token(testerchain):
|
||||
# Create an ERC20 token
|
||||
contract, _ = chain.interface.deploy_contract('NuCypherToken', 2 * 10 ** 9)
|
||||
contract, _ = testerchain.interface.deploy_contract('NuCypherToken', 2 * 10 ** 9)
|
||||
return contract
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def escrow(web3, chain, token):
|
||||
def escrow(testerchain, token):
|
||||
# Creator deploys the escrow
|
||||
contract, _ = chain.interface.deploy_contract(
|
||||
contract, _ = testerchain.interface.deploy_contract(
|
||||
'MinersEscrow',
|
||||
token.address,
|
||||
1,
|
||||
|
@ -58,108 +58,108 @@ def escrow(web3, chain, token):
|
|||
100,
|
||||
2000)
|
||||
|
||||
dispatcher, _ = chain.interface.deploy_contract('Dispatcher', contract.address)
|
||||
dispatcher, _ = testerchain.interface.deploy_contract('Dispatcher', contract.address)
|
||||
|
||||
# Wrap dispatcher contract
|
||||
contract = web3.eth.contract(abi=contract.abi, address=dispatcher.address, ContractFactoryClass=Contract)
|
||||
contract = testerchain.interface.w3.eth.contract(abi=contract.abi, address=dispatcher.address, ContractFactoryClass=Contract)
|
||||
return contract
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def policy_manager(web3, chain, escrow):
|
||||
creator = web3.eth.accounts[0]
|
||||
def policy_manager(testerchain, escrow):
|
||||
creator = testerchain.interface.w3.eth.accounts[0]
|
||||
|
||||
# Creator deploys the policy manager
|
||||
contract, _ = chain.interface.deploy_contract('PolicyManager', escrow.address)
|
||||
dispatcher, _ = chain.interface.deploy_contract('Dispatcher', contract.address)
|
||||
contract, _ = testerchain.interface.deploy_contract('PolicyManager', escrow.address)
|
||||
dispatcher, _ = testerchain.interface.deploy_contract('Dispatcher', contract.address)
|
||||
|
||||
# Wrap dispatcher contract
|
||||
contract = web3.eth.contract(abi=contract.abi, address=dispatcher.address, ContractFactoryClass=Contract)
|
||||
contract = testerchain.interface.w3.eth.contract(abi=contract.abi, address=dispatcher.address, ContractFactoryClass=Contract)
|
||||
|
||||
tx = escrow.functions.setPolicyManager(contract.address).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
return contract
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def government(web3, chain, escrow, policy_manager):
|
||||
creator = web3.eth.accounts[0]
|
||||
def government(testerchain, escrow, policy_manager):
|
||||
creator = testerchain.interface.w3.eth.accounts[0]
|
||||
|
||||
# Creator deploys the government
|
||||
contract, _ = chain.interface.deploy_contract('Government', escrow.address, policy_manager.address, 1)
|
||||
dispatcher, _ = chain.interface.deploy_contract('Dispatcher', contract.address)
|
||||
contract, _ = testerchain.interface.deploy_contract('Government', escrow.address, policy_manager.address, 1)
|
||||
dispatcher, _ = testerchain.interface.deploy_contract('Dispatcher', contract.address)
|
||||
|
||||
# Wrap dispatcher contract
|
||||
contract = web3.eth.contract(abi=contract.abi, address=dispatcher.address, ContractFactoryClass=Contract)
|
||||
contract = testerchain.interface.w3.eth.contract(abi=contract.abi, address=dispatcher.address, ContractFactoryClass=Contract)
|
||||
|
||||
# Transfer ownership
|
||||
tx = contract.functions.transferOwnership(contract.address).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.transferOwnership(contract.address).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = policy_manager.functions.transferOwnership(contract.address).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
return contract
|
||||
|
||||
|
||||
@pytest.mark.slow
|
||||
def test_all(web3, chain, token, escrow, policy_manager, government):
|
||||
creator, ursula1, ursula2, ursula3, ursula4, alice1, alice2, *everyone_else = web3.eth.accounts
|
||||
def test_all(testerchain, token, escrow, policy_manager, government):
|
||||
creator, ursula1, ursula2, ursula3, ursula4, alice1, alice2, *everyone_else = testerchain.interface.w3.eth.accounts
|
||||
|
||||
# Give clients some ether
|
||||
tx = web3.eth.sendTransaction({'from': web3.eth.coinbase, 'to': alice1, 'value': 10 ** 10})
|
||||
chain.wait_for_receipt(tx)
|
||||
tx = web3.eth.sendTransaction({'from': web3.eth.coinbase, 'to': alice2, 'value': 10 ** 10})
|
||||
chain.wait_for_receipt(tx)
|
||||
tx = testerchain.interface.w3.eth.sendTransaction({'from': testerchain.interface.w3.eth.coinbase, 'to': alice1, 'value': 10 ** 10})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = testerchain.interface.w3.eth.sendTransaction({'from': testerchain.interface.w3.eth.coinbase, 'to': alice2, 'value': 10 ** 10})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Give Ursula and Alice some coins
|
||||
tx = token.functions.transfer(ursula1, 10000).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = token.functions.transfer(alice1, 10000).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = token.functions.transfer(alice2, 10000).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 10000 == token.functions.balanceOf(ursula1).call()
|
||||
assert 10000 == token.functions.balanceOf(alice1).call()
|
||||
assert 10000 == token.functions.balanceOf(alice2).call()
|
||||
|
||||
# Ursula give Escrow rights to transfer
|
||||
tx = token.functions.approve(escrow.address, 10000).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = token.functions.approve(escrow.address, 10000).transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Ursula can't deposit tokens before Escrow initialization
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.deposit(1, 1).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Initialize escrow
|
||||
reward = 10 ** 9
|
||||
tx = token.functions.transfer(escrow.address, reward).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.initialize().transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Deposit some tokens to the user escrow and lock them
|
||||
user_escrow_1, _ = chain.interface.deploy_contract('UserEscrow', token.address, escrow.address, policy_manager.address, government.address)
|
||||
user_escrow_1, _ = testerchain.interface.deploy_contract('UserEscrow', token.address, escrow.address, policy_manager.address, government.address)
|
||||
|
||||
tx = user_escrow_1.functions.transferOwnership(ursula3).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = token.functions.approve(user_escrow_1.address, 10000).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = user_escrow_1.functions.initialDeposit(10000, 20 * 60 * 60).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
user_escrow_2, _ = chain.interface.deploy_contract('UserEscrow', token.address, escrow.address, policy_manager.address, government.address)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
user_escrow_2, _ = testerchain.interface.deploy_contract('UserEscrow', token.address, escrow.address, policy_manager.address, government.address)
|
||||
|
||||
tx = user_escrow_2.functions.transferOwnership(ursula4).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = token.functions.approve(user_escrow_2.address, 10000).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = user_escrow_2.functions.initialDeposit(10000, 20 * 60 * 60).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 10000 == token.functions.balanceOf(user_escrow_1.address).call()
|
||||
assert ursula3 == user_escrow_1.functions.owner().call()
|
||||
assert 10000 >= user_escrow_1.functions.getLockedTokens().call()
|
||||
|
@ -172,12 +172,12 @@ def test_all(web3, chain, token, escrow, policy_manager, government):
|
|||
# Ursula's withdrawal attempt won't succeed because nothing to withdraw
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.withdraw(100).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# And can't lock because nothing to lock
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.lock(500, 2).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Check that nothing is locked
|
||||
assert 0 == escrow.functions.getLockedTokens(ursula1).call()
|
||||
|
@ -191,20 +191,20 @@ def test_all(web3, chain, token, escrow, policy_manager, government):
|
|||
# Ursula can't deposit and lock too low value
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.deposit(1, 1).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# And can't deposit and lock too high value
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.deposit(2001, 1).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Grant access to transfer tokens
|
||||
tx = token.functions.approve(escrow.address, 10000).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Deposit tokens for 1 owner
|
||||
tx = escrow.functions.preDeposit([ursula2], [1000], [9]).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert reward + 1000 == token.functions.balanceOf(escrow.address).call()
|
||||
assert 1000 == escrow.functions.minerInfo(ursula2).call()[VALUE_FIELD]
|
||||
assert 0 == escrow.functions.getLockedTokens(ursula2).call()
|
||||
|
@ -215,22 +215,22 @@ def test_all(web3, chain, token, escrow, policy_manager, government):
|
|||
# Can't pre-deposit tokens again for the same owner
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.preDeposit([ursula2], [1000], [9]).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Can't pre-deposit tokens with too low or too high value
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.preDeposit([ursula3], [1], [10]).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.preDeposit([ursula3], [10**6], [10]).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.preDeposit([ursula3], [500], [1]).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Ursula transfer some tokens to the escrow and lock them
|
||||
tx = escrow.functions.deposit(1000, 10).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert reward + 2000 == token.functions.balanceOf(escrow.address).call()
|
||||
assert 9000 == token.functions.balanceOf(ursula1).call()
|
||||
assert 0 == escrow.functions.getLockedTokens(ursula1).call()
|
||||
|
@ -239,9 +239,9 @@ def test_all(web3, chain, token, escrow, policy_manager, government):
|
|||
assert 0 == escrow.functions.getLockedTokens(ursula1, 11).call()
|
||||
|
||||
# Wait 1 period and deposit from one more Ursula
|
||||
chain.time_travel(hours=1)
|
||||
testerchain.time_travel(hours=1)
|
||||
tx = user_escrow_1.functions.minerDeposit(1000, 10).transact({'from': ursula3})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 1000 == escrow.functions.minerInfo(user_escrow_1.address).call()[VALUE_FIELD]
|
||||
assert 0 == escrow.functions.getLockedTokens(user_escrow_1.address).call()
|
||||
assert 1000 == escrow.functions.getLockedTokens(user_escrow_1.address, 1).call()
|
||||
|
@ -253,159 +253,159 @@ def test_all(web3, chain, token, escrow, policy_manager, government):
|
|||
# Only user can deposit tokens to the miner escrow
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = user_escrow_1.functions.minerDeposit(1000, 5).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
# Can't deposit more than amount in the user escrow
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = user_escrow_1.functions.minerDeposit(10000, 5).transact({'from': ursula3})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Divide stakes
|
||||
tx = escrow.functions.divideStake(1000, escrow.functions.getCurrentPeriod().call() + 9, 500, 6).transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.divideStake(1000, escrow.functions.getCurrentPeriod().call() + 9, 500, 9).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = user_escrow_1.functions.divideStake(1000, escrow.functions.getCurrentPeriod().call() + 10, 500, 6).transact({'from': ursula3})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Confirm activity
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
chain.time_travel(hours=1)
|
||||
testerchain.time_travel(hours=1)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = user_escrow_1.functions.confirmActivity().transact({'from': ursula3})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
chain.time_travel(hours=1)
|
||||
testerchain.time_travel(hours=1)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = user_escrow_1.functions.confirmActivity().transact({'from': ursula3})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Create policies
|
||||
policy_id_1 = os.urandom(20)
|
||||
tx = policy_manager.functions.createPolicy(policy_id_1, 5, 44, [ursula1, ursula2]).transact({'from': alice1, 'value': 2 * 1000 + 2 * 44, 'gas_price': 0})
|
||||
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
policy_id_2 = os.urandom(20)
|
||||
tx = policy_manager.functions.createPolicy(policy_id_2, 5, 44, [ursula2, user_escrow_1.address]).transact({'from': alice1, 'value': 2 * 1000 + 2 * 44, 'gas_price': 0})
|
||||
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
policy_id_3 = os.urandom(20)
|
||||
tx = policy_manager.functions.createPolicy(policy_id_3, 5, 44, [ursula1, user_escrow_1.address]).transact({'from': alice2, 'value': 2 * 1000 + 2 * 44, 'gas_price': 0})
|
||||
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
policy_id_4 = os.urandom(20)
|
||||
tx = policy_manager.functions.createPolicy(policy_id_4, 5, 44, [ursula2, user_escrow_1.address]).transact({'from': alice2, 'value': 2 * 1000 + 2 * 44, 'gas_price': 0})
|
||||
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
policy_id_5 = os.urandom(20)
|
||||
tx = policy_manager.functions.createPolicy(policy_id_5, 5, 44, [ursula1, ursula2]).transact({'from': alice2, 'value': 2 * 1000 + 2 * 44, 'gas_price': 0})
|
||||
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Only Alice can revoke policy
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = policy_manager.functions.revokePolicy(policy_id_5).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
alice2_balance = web3.eth.getBalance(alice2)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
alice2_balance = testerchain.interface.w3.eth.getBalance(alice2)
|
||||
tx = policy_manager.functions.revokePolicy(policy_id_5).transact({'from': alice2, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert 8440 == web3.eth.getBalance(policy_manager.address)
|
||||
assert alice2_balance + 2000 == web3.eth.getBalance(alice2)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 8440 == testerchain.interface.w3.eth.getBalance(policy_manager.address)
|
||||
assert alice2_balance + 2000 == testerchain.interface.w3.eth.getBalance(alice2)
|
||||
assert policy_manager.functions.policies(policy_id_5).call()[DISABLED_FIELD]
|
||||
|
||||
# Can't revoke again
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = policy_manager.functions.revokePolicy(policy_id_5).transact({'from': alice2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = policy_manager.functions.revokeArrangement(policy_id_5, ursula1).transact({'from': alice2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
alice1_balance = web3.eth.getBalance(alice1)
|
||||
alice1_balance = testerchain.interface.w3.eth.getBalance(alice1)
|
||||
tx = policy_manager.functions.revokeArrangement(policy_id_2, ursula2).transact({'from': alice1, 'gas_price': 0})
|
||||
|
||||
chain.wait_for_receipt(tx)
|
||||
assert 7440 == web3.eth.getBalance(policy_manager.address)
|
||||
assert alice1_balance + 1000 == web3.eth.getBalance(alice1)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 7440 == testerchain.interface.w3.eth.getBalance(policy_manager.address)
|
||||
assert alice1_balance + 1000 == testerchain.interface.w3.eth.getBalance(alice1)
|
||||
assert not policy_manager.functions.policies(policy_id_2).call()[DISABLED_FIELD]
|
||||
|
||||
# Can't revoke again
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = policy_manager.functions.revokeArrangement(policy_id_2, ursula2).transact({'from': alice1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Wait, confirm activity, mint
|
||||
chain.time_travel(hours=1)
|
||||
testerchain.time_travel(hours=1)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = user_escrow_1.functions.confirmActivity().transact({'from': ursula3})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
chain.time_travel(hours=1)
|
||||
testerchain.time_travel(hours=1)
|
||||
tx = policy_manager.functions.revokeArrangement(policy_id_3, user_escrow_1.address).transact({'from': alice2, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = user_escrow_1.functions.confirmActivity().transact({'from': ursula3})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
chain.time_travel(hours=1)
|
||||
testerchain.time_travel(hours=1)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
chain.time_travel(hours=1)
|
||||
testerchain.time_travel(hours=1)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Withdraw reward and refund
|
||||
chain.time_travel(hours=3)
|
||||
ursula1_balance = web3.eth.getBalance(ursula1)
|
||||
testerchain.time_travel(hours=3)
|
||||
ursula1_balance = testerchain.interface.w3.eth.getBalance(ursula1)
|
||||
tx = policy_manager.functions.withdraw().transact({'from': ursula1, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert ursula1_balance < web3.eth.getBalance(ursula1)
|
||||
ursula2_balance = web3.eth.getBalance(ursula2)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert ursula1_balance < testerchain.interface.w3.eth.getBalance(ursula1)
|
||||
ursula2_balance = testerchain.interface.w3.eth.getBalance(ursula2)
|
||||
tx = policy_manager.functions.withdraw().transact({'from': ursula2, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert ursula2_balance < web3.eth.getBalance(ursula2)
|
||||
user_escrow_1_balance = web3.eth.getBalance(user_escrow_1.address)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert ursula2_balance < testerchain.interface.w3.eth.getBalance(ursula2)
|
||||
user_escrow_1_balance = testerchain.interface.w3.eth.getBalance(user_escrow_1.address)
|
||||
tx = user_escrow_1.functions.policyRewardWithdraw().transact({'from': ursula3, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert user_escrow_1_balance < web3.eth.getBalance(user_escrow_1.address)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert user_escrow_1_balance < testerchain.interface.w3.eth.getBalance(user_escrow_1.address)
|
||||
|
||||
alice1_balance = web3.eth.getBalance(alice1)
|
||||
alice1_balance = testerchain.interface.w3.eth.getBalance(alice1)
|
||||
tx = policy_manager.functions.refund(policy_id_1).transact({'from': alice1, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert alice1_balance < web3.eth.getBalance(alice1)
|
||||
alice1_balance = web3.eth.getBalance(alice1)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert alice1_balance < testerchain.interface.w3.eth.getBalance(alice1)
|
||||
alice1_balance = testerchain.interface.w3.eth.getBalance(alice1)
|
||||
tx = policy_manager.functions.refund(policy_id_2).transact({'from': alice1, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert alice1_balance < web3.eth.getBalance(alice1)
|
||||
alice2_balance = web3.eth.getBalance(alice2)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert alice1_balance < testerchain.interface.w3.eth.getBalance(alice1)
|
||||
alice2_balance = testerchain.interface.w3.eth.getBalance(alice2)
|
||||
tx = policy_manager.functions.refund(policy_id_3).transact({'from': alice2, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert alice2_balance == web3.eth.getBalance(alice2)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert alice2_balance == testerchain.interface.w3.eth.getBalance(alice2)
|
||||
tx = policy_manager.functions.refund(policy_id_4).transact({'from': alice2, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert alice2_balance < web3.eth.getBalance(alice2)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert alice2_balance < testerchain.interface.w3.eth.getBalance(alice2)
|
||||
|
||||
# Voting for upgrade
|
||||
escrow_v1 = escrow.functions.target().call()
|
||||
policy_manager_v1 = policy_manager.functions.target().call()
|
||||
government_v1 = government.functions.target().call()
|
||||
# Creator deploys the contracts as the second versions
|
||||
escrow_v2, _ = chain.interface.deploy_contract(
|
||||
escrow_v2, _ = testerchain.interface.deploy_contract(
|
||||
'MinersEscrow',
|
||||
token.address,
|
||||
1,
|
||||
|
@ -415,184 +415,184 @@ def test_all(web3, chain, token, escrow, policy_manager, government):
|
|||
2,
|
||||
100,
|
||||
2000)
|
||||
policy_manager_v2, _ = chain.interface.deploy_contract('PolicyManager', escrow.address)
|
||||
government_v2, _ = chain.interface.deploy_contract('Government', escrow.address, policy_manager.address, 1)
|
||||
policy_manager_v2, _ = testerchain.interface.deploy_contract('PolicyManager', escrow.address)
|
||||
government_v2, _ = testerchain.interface.deploy_contract('Government', escrow.address, policy_manager.address, 1)
|
||||
assert FINISHED_STATE == government.functions.getVotingState().call()
|
||||
|
||||
# Alice can't create voting
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = government.functions.createVoting(UPGRADE_GOVERNMENT, government_v2.address).transact({'from': alice1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = government.functions.createVoting(UPGRADE_GOVERNMENT, government_v2.address).transact({'from': alice2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Vote and upgrade government contract
|
||||
tx = government.functions.createVoting(UPGRADE_GOVERNMENT, government_v2.address).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert ACTIVE_STATE == government.functions.getVotingState().call()
|
||||
# Alice can't vote
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = government.functions.vote(False).transact({'from': alice1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = government.functions.vote(False).transact({'from': alice2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
tx = government.functions.vote(True).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = government.functions.vote(False).transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = user_escrow_1.functions.vote(True).transact({'from': ursula3})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Can't vote again
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = government.functions.vote(False).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
chain.time_travel(seconds=3600)
|
||||
testerchain.time_travel(seconds=3600)
|
||||
assert UPGRADE_WAITING_STATE == government.functions.getVotingState().call()
|
||||
tx = government.functions.commitUpgrade().transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert FINISHED_STATE == government.functions.getVotingState().call()
|
||||
assert government_v2.address == government.functions.target().call()
|
||||
|
||||
# Vote and upgrade escrow contract
|
||||
tx = government.functions.createVoting(UPGRADE_ESCROW, escrow_v2.address).transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert ACTIVE_STATE == government.functions.getVotingState().call()
|
||||
tx = government.functions.vote(False).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = government.functions.vote(True).transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = user_escrow_1.functions.vote(True).transact({'from': ursula3})
|
||||
chain.wait_for_receipt(tx)
|
||||
chain.time_travel(seconds=3600)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(seconds=3600)
|
||||
assert UPGRADE_WAITING_STATE == government.functions.getVotingState().call()
|
||||
tx = government.functions.commitUpgrade().transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert FINISHED_STATE == government.functions.getVotingState().call()
|
||||
assert escrow_v2.address == escrow.functions.target().call()
|
||||
|
||||
# Vote and upgrade policy manager contract
|
||||
tx = government.functions.createVoting(UPGRADE_POLICY_MANAGER, policy_manager_v2.address).transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert ACTIVE_STATE == government.functions.getVotingState().call()
|
||||
tx = government.functions.vote(False).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = government.functions.vote(True).transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = user_escrow_1.functions.vote(True).transact({'from': ursula3})
|
||||
chain.wait_for_receipt(tx)
|
||||
chain.time_travel(seconds=3600)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(seconds=3600)
|
||||
assert UPGRADE_WAITING_STATE == government.functions.getVotingState().call()
|
||||
tx = government.functions.commitUpgrade().transact({'from': ursula3})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert FINISHED_STATE == government.functions.getVotingState().call()
|
||||
assert policy_manager_v2.address == policy_manager.functions.target().call()
|
||||
|
||||
# Voting against rollback
|
||||
tx = government.functions.createVoting(ROLLBACK_GOVERNMENT, NULL_ADDR).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert ACTIVE_STATE == government.functions.getVotingState().call()
|
||||
tx = government.functions.vote(True).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = user_escrow_1.functions.vote(False).transact({'from': ursula3})
|
||||
chain.wait_for_receipt(tx)
|
||||
chain.time_travel(seconds=3600)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(seconds=3600)
|
||||
assert FINISHED_STATE == government.functions.getVotingState().call()
|
||||
assert government_v2.address == government.functions.target().call()
|
||||
|
||||
tx = government.functions.createVoting(ROLLBACK_ESCROW, NULL_ADDR).transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert ACTIVE_STATE == government.functions.getVotingState().call()
|
||||
tx = government.functions.vote(True).transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = user_escrow_1.functions.vote(False).transact({'from': ursula3})
|
||||
chain.wait_for_receipt(tx)
|
||||
chain.time_travel(seconds=3600)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(seconds=3600)
|
||||
assert FINISHED_STATE == government.functions.getVotingState().call()
|
||||
assert escrow_v2.address == escrow.functions.target().call()
|
||||
|
||||
tx = government.functions.createVoting(ROLLBACK_ESCROW, NULL_ADDR).transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert ACTIVE_STATE == government.functions.getVotingState().call()
|
||||
tx = government.functions.vote(True).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = government.functions.vote(False).transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
chain.time_travel(seconds=3600)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(seconds=3600)
|
||||
assert FINISHED_STATE == government.functions.getVotingState().call()
|
||||
assert policy_manager_v2.address == policy_manager.functions.target().call()
|
||||
|
||||
# Voting for upgrade with errors
|
||||
tx = government.functions.createVoting(UPGRADE_GOVERNMENT, escrow_v2.address).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = government.functions.vote(True).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
chain.time_travel(seconds=3600)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(seconds=3600)
|
||||
assert UPGRADE_WAITING_STATE == government.functions.getVotingState().call()
|
||||
tx = government.functions.commitUpgrade().transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert FINISHED_STATE == government.functions.getVotingState().call()
|
||||
assert government_v2.address == government.functions.target().call()
|
||||
|
||||
# Some activity
|
||||
for index in range(5):
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = user_escrow_1.functions.confirmActivity().transact({'from': ursula3})
|
||||
chain.wait_for_receipt(tx)
|
||||
chain.time_travel(hours=1)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=1)
|
||||
|
||||
# Vote and rollback all contracts
|
||||
tx = government.functions.createVoting(ROLLBACK_GOVERNMENT, NULL_ADDR).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = government.functions.vote(True).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
chain.time_travel(seconds=3600)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(seconds=3600)
|
||||
tx = government.functions.commitUpgrade().transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert government_v1 == government.functions.target().call()
|
||||
|
||||
tx = government.functions.createVoting(ROLLBACK_ESCROW, NULL_ADDR).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = government.functions.vote(True).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
chain.time_travel(seconds=3600)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(seconds=3600)
|
||||
tx = government.functions.commitUpgrade().transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert escrow_v1 == escrow.functions.target().call()
|
||||
|
||||
tx = government.functions.createVoting(ROLLBACK_POLICY_MANAGER, NULL_ADDR).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = government.functions.vote(True).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
chain.time_travel(seconds=3600)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(seconds=3600)
|
||||
tx = government.functions.commitUpgrade().transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert policy_manager_v1 == policy_manager.functions.target().call()
|
||||
|
||||
# Unlock and withdraw all tokens in MinersEscrow
|
||||
for index in range(6):
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = user_escrow_1.functions.confirmActivity().transact({'from': ursula3})
|
||||
chain.wait_for_receipt(tx)
|
||||
chain.time_travel(hours=1)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=1)
|
||||
|
||||
chain.time_travel(hours=1)
|
||||
testerchain.time_travel(hours=1)
|
||||
tx = escrow.functions.mint().transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.mint().transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = user_escrow_1.functions.mint().transact({'from': ursula3})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
assert 0 == escrow.functions.getLockedTokens(ursula1).call()
|
||||
assert 0 == escrow.functions.getLockedTokens(ursula2).call()
|
||||
|
@ -603,26 +603,26 @@ def test_all(web3, chain, token, escrow, policy_manager, government):
|
|||
|
||||
tokens_amount = escrow.functions.minerInfo(ursula1).call()[VALUE_FIELD]
|
||||
tx = escrow.functions.withdraw(tokens_amount).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tokens_amount = escrow.functions.minerInfo(ursula2).call()[VALUE_FIELD]
|
||||
tx = escrow.functions.withdraw(tokens_amount).transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tokens_amount = escrow.functions.minerInfo(user_escrow_1.address).call()[VALUE_FIELD]
|
||||
tx = user_escrow_1.functions.minerWithdraw(tokens_amount).transact({'from': ursula3})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 10000 < token.functions.balanceOf(ursula1).call()
|
||||
assert 1000 < token.functions.balanceOf(ursula2).call()
|
||||
assert 10000 < token.functions.balanceOf(user_escrow_1.address).call()
|
||||
|
||||
# Unlock and withdraw all tokens in UserEscrow
|
||||
chain.time_travel(hours=1)
|
||||
testerchain.time_travel(hours=1)
|
||||
assert 0 == user_escrow_1.functions.getLockedTokens().call()
|
||||
assert 0 == user_escrow_2.functions.getLockedTokens().call()
|
||||
tokens_amount = token.functions.balanceOf(user_escrow_1.address).call()
|
||||
tx = user_escrow_1.functions.withdraw(tokens_amount).transact({'from': ursula3})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tokens_amount = token.functions.balanceOf(user_escrow_2.address).call()
|
||||
tx = user_escrow_2.functions.withdraw(tokens_amount).transact({'from': ursula4})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 10000 < token.functions.balanceOf(ursula3).call()
|
||||
assert 10000 == token.functions.balanceOf(ursula4).call()
|
||||
|
|
|
@ -4,19 +4,19 @@ from web3.contract import Contract
|
|||
|
||||
|
||||
@pytest.mark.slow
|
||||
def test_dispatcher(web3, chain):
|
||||
creator = web3.eth.accounts[0]
|
||||
account = web3.eth.accounts[1]
|
||||
def test_dispatcher(testerchain):
|
||||
creator = testerchain.interface.w3.eth.accounts[0]
|
||||
account = testerchain.interface.w3.eth.accounts[1]
|
||||
|
||||
# Load contract interface
|
||||
contract_interface = chain.interface.get_contract_factory('ContractInterface')
|
||||
contract_interface = testerchain.interface.get_contract_factory('ContractInterface')
|
||||
|
||||
# Deploy contracts and dispatcher for them
|
||||
contract1_lib, _ = chain.interface.deploy_contract('ContractV1', 1)
|
||||
contract2_lib, _ = chain.interface.deploy_contract('ContractV2', 1)
|
||||
contract3_lib, _ = chain.interface.deploy_contract('ContractV3', 2)
|
||||
contract2_bad_lib, _ = chain.interface.deploy_contract('ContractV2Bad')
|
||||
dispatcher, _ = chain.interface.deploy_contract('Dispatcher', contract1_lib.address)
|
||||
contract1_lib, _ = testerchain.interface.deploy_contract('ContractV1', 1)
|
||||
contract2_lib, _ = testerchain.interface.deploy_contract('ContractV2', 1)
|
||||
contract3_lib, _ = testerchain.interface.deploy_contract('ContractV3', 2)
|
||||
contract2_bad_lib, _ = testerchain.interface.deploy_contract('ContractV2Bad')
|
||||
dispatcher, _ = testerchain.interface.deploy_contract('Dispatcher', contract1_lib.address)
|
||||
|
||||
upgrades = dispatcher.events.Upgraded.createFilter(fromBlock=0)
|
||||
assert dispatcher.functions.target().call() == contract1_lib.address
|
||||
|
@ -30,62 +30,62 @@ def test_dispatcher(web3, chain):
|
|||
|
||||
# Assign dispatcher address as contract.
|
||||
# In addition to the interface can be used ContractV1, ContractV2 or ContractV3 ABI
|
||||
contract_instance = web3.eth.contract(
|
||||
contract_instance = testerchain.interface.w3.eth.contract(
|
||||
abi=contract_interface.abi,
|
||||
address=dispatcher.address,
|
||||
ContractFactoryClass=Contract)
|
||||
|
||||
# Only owner can change target address for dispatcher
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = dispatcher.functions.upgrade(contract2_lib.address).transact({'from': account})
|
||||
chain.wait_for_receipt(tx)
|
||||
tx = dispatcher.functions.upgrade(contract2_lib.address).transact({'from': account})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert dispatcher.functions.target().call() == contract1_lib.address
|
||||
|
||||
# Check values before upgrade
|
||||
assert contract_instance.functions.getStorageValue().call() == 1
|
||||
assert contract_instance.functions.returnValue().call() == 10
|
||||
tx = contract_instance.functions.setStorageValue(5).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert contract_instance.functions.getStorageValue().call() == 5
|
||||
tx = contract_instance.functions.pushArrayValue(12).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert contract_instance.functions.getArrayValueLength().call() == 1
|
||||
assert contract_instance.functions.getArrayValue(0).call() == 12
|
||||
tx = contract_instance.functions.pushArrayValue(232).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert contract_instance.functions.getArrayValueLength().call() == 2
|
||||
assert contract_instance.functions.getArrayValue(1).call() == 232
|
||||
tx = contract_instance.functions.setMappingValue(14, 41).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert contract_instance.functions.getMappingValue(14).call() == 41
|
||||
tx = contract_instance.functions.pushStructureValue1(3).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert contract_instance.functions.getStructureValue1(0).call() == 3
|
||||
tx = contract_instance.functions.pushStructureArrayValue1(0, 11).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = contract_instance.functions.pushStructureArrayValue1(0, 111).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert contract_instance.functions.getStructureArrayValue1(0, 0).call() == 11
|
||||
assert contract_instance.functions.getStructureArrayValue1(0, 1).call() == 111
|
||||
tx = contract_instance.functions.pushStructureValue2(4).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert contract_instance.functions.getStructureValue2(0).call() == 4
|
||||
tx = contract_instance.functions.pushStructureArrayValue2(0, 12).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert contract_instance.functions.getStructureArrayValue2(0, 0).call() == 12
|
||||
tx = contract_instance.functions.setDynamicallySizedValue('Hola').transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert contract_instance.functions.getDynamicallySizedValue().call() == 'Hola'
|
||||
|
||||
# Can't upgrade to bad version
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = dispatcher.functions.upgrade(contract2_bad_lib.address).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert dispatcher.functions.target().call() == contract1_lib.address
|
||||
|
||||
# Upgrade contract
|
||||
tx = dispatcher.functions.upgrade(contract2_lib.address).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert dispatcher.functions.target().call() == contract2_lib.address
|
||||
|
||||
events = upgrades.get_all_entries()
|
||||
|
@ -100,39 +100,39 @@ def test_dispatcher(web3, chain):
|
|||
assert contract_instance.functions.returnValue().call() == 20
|
||||
assert contract_instance.functions.getStorageValue().call() == 5
|
||||
tx = contract_instance.functions.setStorageValue(5).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert contract_instance.functions.getStorageValue().call() == 10
|
||||
assert contract_instance.functions.getArrayValueLength().call() == 2
|
||||
assert contract_instance.functions.getArrayValue(0).call() == 12
|
||||
assert contract_instance.functions.getArrayValue(1).call() == 232
|
||||
tx = contract_instance.functions.setMappingValue(13, 31).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert contract_instance.functions.getMappingValue(14).call() == 41
|
||||
assert contract_instance.functions.getMappingValue(13).call() == 31
|
||||
tx = contract_instance.functions.pushStructureValue1(4).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert contract_instance.functions.getStructureValue1(0).call() == 3
|
||||
assert contract_instance.functions.getStructureValue1(1).call() == 4
|
||||
tx = contract_instance.functions.pushStructureArrayValue1(0, 12).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert contract_instance.functions.getStructureArrayValue1(0, 0).call() == 11
|
||||
assert contract_instance.functions.getStructureArrayValue1(0, 1).call() == 111
|
||||
assert contract_instance.functions.getStructureArrayValue1(0, 2).call() == 12
|
||||
tx = contract_instance.functions.pushStructureValue2(5).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert contract_instance.functions.getStructureValue2(0).call() == 4
|
||||
assert contract_instance.functions.getStructureValue2(1).call() == 5
|
||||
tx = contract_instance.functions.pushStructureArrayValue2(0, 13).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert contract_instance.functions.getStructureArrayValue2(0, 0).call() == 12
|
||||
assert contract_instance.functions.getStructureArrayValue2(0, 1).call() == 13
|
||||
assert contract_instance.functions.getDynamicallySizedValue().call() == 'Hola'
|
||||
tx = contract_instance.functions.setDynamicallySizedValue('Hello').transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert contract_instance.functions.getDynamicallySizedValue().call() == 'Hello'
|
||||
|
||||
# Changes ABI to ContractV2 for using additional methods
|
||||
contract_instance = web3.eth.contract(
|
||||
contract_instance = testerchain.interface.w3.eth.contract(
|
||||
abi=contract2_lib.abi,
|
||||
address=dispatcher.address,
|
||||
ContractFactoryClass=Contract)
|
||||
|
@ -140,32 +140,32 @@ def test_dispatcher(web3, chain):
|
|||
# Check new method and finish upgrade method
|
||||
assert contract_instance.functions.storageValueToCheck().call() == 1
|
||||
tx = contract_instance.functions.setStructureValueToCheck2(0, 55).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert contract_instance.functions.getStructureValueToCheck2(0).call() == 55
|
||||
|
||||
# Can't downgrade to first version due to storage
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = dispatcher.functions.upgrade(contract1_lib.address).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# And can't upgrade to bad version
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = dispatcher.functions.upgrade(contract2_bad_lib.address).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert dispatcher.functions.target().call() == contract2_lib.address
|
||||
|
||||
rollbacks = dispatcher.events.RolledBack.createFilter(fromBlock='latest')
|
||||
|
||||
# But can rollback
|
||||
tx = dispatcher.functions.rollback().transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert dispatcher.functions.target().call() == contract1_lib.address
|
||||
assert contract_instance.functions.getArrayValueLength().call() == 2
|
||||
assert contract_instance.functions.getArrayValue(0).call() == 12
|
||||
assert contract_instance.functions.getArrayValue(1).call() == 232
|
||||
assert contract_instance.functions.getStorageValue().call() == 1
|
||||
tx = contract_instance.functions.setStorageValue(5).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert contract_instance.functions.getStorageValue().call() == 5
|
||||
|
||||
events = rollbacks.get_all_entries()
|
||||
|
@ -178,27 +178,27 @@ def test_dispatcher(web3, chain):
|
|||
# Can't upgrade to the bad version
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = dispatcher.functions.upgrade(contract2_bad_lib.address).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert dispatcher.functions.target().call() == contract1_lib.address
|
||||
|
||||
# Create Event
|
||||
contract_instance = web3.eth.contract(
|
||||
contract_instance = testerchain.interface.w3.eth.contract(
|
||||
abi=contract1_lib.abi,
|
||||
address=dispatcher.address,
|
||||
ContractFactoryClass=Contract)
|
||||
test_events = contract_instance.events.EventV1.createFilter(fromBlock=0)
|
||||
tx = contract_instance.functions.createEvent(33).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
events = test_events.get_all_entries()
|
||||
assert 1 == len(events)
|
||||
assert 33 == events[0]['args']['value']
|
||||
|
||||
# Upgrade to version 3
|
||||
tx = dispatcher.functions.upgrade(contract2_lib.address).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = dispatcher.functions.upgrade(contract3_lib.address).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
contract_instance = web3.eth.contract(
|
||||
testerchain.wait_for_receipt(tx)
|
||||
contract_instance = testerchain.interface.w3.eth.contract(
|
||||
abi=contract2_lib.abi,
|
||||
address=dispatcher.address,
|
||||
ContractFactoryClass=Contract)
|
||||
|
@ -239,13 +239,13 @@ def test_dispatcher(web3, chain):
|
|||
|
||||
# Create and check events
|
||||
tx = contract_instance.functions.createEvent(22).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
test_eventv2_log = contract_instance.events.EventV2.createFilter(fromBlock=0)
|
||||
events = test_eventv2_log.get_all_entries()
|
||||
assert 1 == len(events)
|
||||
assert 22 == events[0]['args']['value']
|
||||
|
||||
contract_instance = web3.eth.contract(
|
||||
contract_instance = testerchain.interface.w3.eth.contract(
|
||||
abi=contract1_lib.abi,
|
||||
address=dispatcher.address,
|
||||
ContractFactoryClass=Contract)
|
||||
|
|
|
@ -18,20 +18,20 @@ ROLLBACK_POLICY_MANAGER = 5
|
|||
|
||||
|
||||
@pytest.fixture()
|
||||
def escrow(web3, chain):
|
||||
node1 = web3.eth.accounts[1]
|
||||
node2 = web3.eth.accounts[2]
|
||||
node3 = web3.eth.accounts[3]
|
||||
def escrow(testerchain):
|
||||
node1 = testerchain.interface.w3.eth.accounts[1]
|
||||
node2 = testerchain.interface.w3.eth.accounts[2]
|
||||
node3 = testerchain.interface.w3.eth.accounts[3]
|
||||
|
||||
# Creator deploys the escrow
|
||||
escrow_library, _ = chain.interface.deploy_contract(
|
||||
escrow_library, _ = testerchain.interface.deploy_contract(
|
||||
'MinersEscrowV1Mock', [node1, node2, node3], [1, 2, 3]
|
||||
)
|
||||
|
||||
escrow_dispatcher, _ = chain.interface.deploy_contract(
|
||||
escrow_dispatcher, _ = testerchain.interface.deploy_contract(
|
||||
'Dispatcher', escrow_library.address
|
||||
)
|
||||
contract = web3.eth.contract(
|
||||
contract = testerchain.interface.w3.eth.contract(
|
||||
abi=escrow_library.abi,
|
||||
address=escrow_dispatcher.address,
|
||||
ContractFactoryClass=Contract)
|
||||
|
@ -39,11 +39,11 @@ def escrow(web3, chain):
|
|||
|
||||
|
||||
@pytest.fixture()
|
||||
def policy_manager(web3, chain):
|
||||
def policy_manager(testerchain):
|
||||
# Creator deploys the escrow
|
||||
contract, _ = chain.interface.deploy_contract('PolicyManagerV1Mock')
|
||||
dispatcher, _ = chain.interface.deploy_contract('Dispatcher', contract.address)
|
||||
contract = web3.eth.contract(
|
||||
contract, _ = testerchain.interface.deploy_contract('PolicyManagerV1Mock')
|
||||
dispatcher, _ = testerchain.interface.deploy_contract('Dispatcher', contract.address)
|
||||
contract = testerchain.interface.w3.eth.contract(
|
||||
abi=contract.abi,
|
||||
address=dispatcher.address,
|
||||
ContractFactoryClass=Contract)
|
||||
|
@ -51,17 +51,17 @@ def policy_manager(web3, chain):
|
|||
|
||||
|
||||
@pytest.mark.slow
|
||||
def test_voting(web3, chain, escrow, policy_manager):
|
||||
creator, node1, node2, node3, *everyone_else = web3.eth.accounts
|
||||
def test_voting(testerchain, escrow, policy_manager):
|
||||
creator, node1, node2, node3, *everyone_else = testerchain.interface.w3.eth.accounts
|
||||
|
||||
# Deploy contract
|
||||
government_library, _ = chain.interface.deploy_contract(
|
||||
government_library, _ = testerchain.interface.deploy_contract(
|
||||
'Government', escrow.address, policy_manager.address, 1,
|
||||
)
|
||||
government_dispatcher, _ = chain.interface.deploy_contract(
|
||||
government_dispatcher, _ = testerchain.interface.deploy_contract(
|
||||
'Dispatcher', government_library.address
|
||||
)
|
||||
government = web3.eth.contract(
|
||||
government = testerchain.interface.w3.eth.contract(
|
||||
abi=government_library.abi,
|
||||
address=government_dispatcher.address,
|
||||
ContractFactoryClass=Contract
|
||||
|
@ -72,19 +72,19 @@ def test_voting(web3, chain, escrow, policy_manager):
|
|||
|
||||
# Transfer ownership
|
||||
tx = government.functions.transferOwnership(government.address).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Check that there are no voting before it's creation
|
||||
assert FINISHED_STATE == government.functions.getVotingState().call()
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = government.functions.vote(True).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = government.functions.commitUpgrade().transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Deploy second version of the government contract
|
||||
government_library_v2, _ = chain.interface.deploy_contract(
|
||||
government_library_v2, _ = testerchain.interface.deploy_contract(
|
||||
'Government', escrow.address, policy_manager.address, 1,
|
||||
)
|
||||
assert government_library.address != government_library_v2.address
|
||||
|
@ -92,11 +92,11 @@ def test_voting(web3, chain, escrow, policy_manager):
|
|||
# Only tokens owner can create voting
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = government.functions.createVoting(UPGRADE_GOVERNMENT, government_library_v2.address).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Create voting for update Government contract
|
||||
tx = government.functions.createVoting(UPGRADE_GOVERNMENT, government_library_v2.address).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
assert 1 == government.functions.votingNumber().call()
|
||||
assert UPGRADE_GOVERNMENT == government.functions.votingType().call()
|
||||
|
@ -108,19 +108,19 @@ def test_voting(web3, chain, escrow, policy_manager):
|
|||
# Can't commit upgrade before end of voting
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = government.functions.commitUpgrade().transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
# Can't create new voting before end of previous voting
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = government.functions.createVoting(UPGRADE_GOVERNMENT, government_library_v2.address).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Nodes vote against update
|
||||
tx = government.functions.vote(True).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 1 == government.functions.votesFor().call()
|
||||
assert 0 == government.functions.votesAgainst().call()
|
||||
tx = government.functions.vote(False).transact({'from': node2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 1 == government.functions.votesFor().call()
|
||||
assert 2 == government.functions.votesAgainst().call()
|
||||
assert ACTIVE_STATE == government.functions.getVotingState().call()
|
||||
|
@ -128,10 +128,10 @@ def test_voting(web3, chain, escrow, policy_manager):
|
|||
# Can't vote again
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = government.functions.vote(False).transact({'from': node2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Wait until the end of voting
|
||||
chain.time_travel(seconds=3600)
|
||||
testerchain.time_travel(seconds=3600)
|
||||
assert FINISHED_STATE == government.functions.getVotingState().call()
|
||||
assert government_library.address == government_dispatcher.functions.target().call()
|
||||
assert 1 == government.functions.votingNumber().call()
|
||||
|
@ -139,16 +139,16 @@ def test_voting(web3, chain, escrow, policy_manager):
|
|||
# Can't vote after the ending
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = government.functions.vote(False).transact({'from': node3})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
# Can't commit upgrade because nodes votes against upgrade
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = government.functions.commitUpgrade().transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Create voting for update Government contract again
|
||||
tx = government.functions.createVoting(UPGRADE_GOVERNMENT, government_library_v2.address).transact({'from': node1})
|
||||
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 2 == government.functions.votingNumber().call()
|
||||
assert UPGRADE_GOVERNMENT == government.functions.votingType().call()
|
||||
assert government_library_v2.address == government.functions.newAddress().call()
|
||||
|
@ -158,15 +158,15 @@ def test_voting(web3, chain, escrow, policy_manager):
|
|||
|
||||
# Nodes vote for update
|
||||
tx = government.functions.vote(False).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = government.functions.vote(True).transact({'from': node2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 2 == government.functions.votesFor().call()
|
||||
assert 1 == government.functions.votesAgainst().call()
|
||||
assert ACTIVE_STATE == government.functions.getVotingState().call()
|
||||
|
||||
# Wait until the end of voting
|
||||
chain.time_travel(seconds=3600)
|
||||
testerchain.time_travel(seconds=3600)
|
||||
assert UPGRADE_WAITING_STATE == government.functions.getVotingState().call()
|
||||
assert government_library.address == government_dispatcher.functions.target().call()
|
||||
assert 2 == government.functions.votingNumber().call()
|
||||
|
@ -174,48 +174,48 @@ def test_voting(web3, chain, escrow, policy_manager):
|
|||
# Can't vote after the ending
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = government.functions.vote(True).transact({'from': node3})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
# Can't create new voting before upgrading
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = government.functions.createVoting(UPGRADE_GOVERNMENT, government_library_v2.address)\
|
||||
.transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Commit upgrade
|
||||
tx = government.functions.commitUpgrade().transact({'from': node2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert FINISHED_STATE == government.functions.getVotingState().call()
|
||||
assert government_library_v2.address == government_dispatcher.functions.target().call()
|
||||
|
||||
# Create voting for update Government contract again without voting
|
||||
tx = government.functions.createVoting(UPGRADE_GOVERNMENT, government_library.address).transact({'from': node2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 3 == government.functions.votingNumber().call()
|
||||
assert ACTIVE_STATE == government.functions.getVotingState().call()
|
||||
assert 0 == government.functions.votesFor().call()
|
||||
assert 0 == government.functions.votesAgainst().call()
|
||||
|
||||
# Wait until the end of voting
|
||||
chain.time_travel(seconds=3600)
|
||||
testerchain.time_travel(seconds=3600)
|
||||
assert FINISHED_STATE == government.functions.getVotingState().call()
|
||||
|
||||
# Create voting for update Government contract again with equal voting
|
||||
tx = government.functions.createVoting(UPGRADE_GOVERNMENT, government_library.address).transact({'from': node3})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
assert 4 == government.functions.votingNumber().call()
|
||||
assert ACTIVE_STATE == government.functions.getVotingState().call()
|
||||
tx = government.functions.vote(False).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = government.functions.vote(False).transact({'from': node2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = government.functions.vote(True).transact({'from': node3})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 3 == government.functions.votesFor().call()
|
||||
assert 3 == government.functions.votesAgainst().call()
|
||||
|
||||
# Wait until the end of voting
|
||||
chain.time_travel(seconds=3600)
|
||||
testerchain.time_travel(seconds=3600)
|
||||
assert FINISHED_STATE == government.functions.getVotingState().call()
|
||||
|
||||
# Check events
|
||||
|
@ -226,18 +226,18 @@ def test_voting(web3, chain, escrow, policy_manager):
|
|||
|
||||
|
||||
@pytest.mark.slow
|
||||
def test_upgrade(web3, chain, escrow, policy_manager):
|
||||
creator = web3.eth.accounts[0]
|
||||
node1 = web3.eth.accounts[1]
|
||||
def test_upgrade(testerchain, escrow, policy_manager):
|
||||
creator = testerchain.interface.w3.eth.accounts[0]
|
||||
node1 = testerchain.interface.w3.eth.accounts[1]
|
||||
|
||||
# Deploy contract
|
||||
government_library_v1, _ = chain.interface.deploy_contract(
|
||||
government_library_v1, _ = testerchain.interface.deploy_contract(
|
||||
'Government', escrow.address, policy_manager.address, 1,
|
||||
)
|
||||
government_dispatcher, _ = chain.interface.deploy_contract(
|
||||
government_dispatcher, _ = testerchain.interface.deploy_contract(
|
||||
'Dispatcher', government_library_v1.address,
|
||||
)
|
||||
government = web3.eth.contract(
|
||||
government = testerchain.interface.w3.eth.contract(
|
||||
abi=government_library_v1.abi,
|
||||
address=government_dispatcher.address,
|
||||
ContractFactoryClass=Contract
|
||||
|
@ -247,54 +247,54 @@ def test_upgrade(web3, chain, escrow, policy_manager):
|
|||
upgrade_committed_log = government.events.UpgradeCommitted.createFilter(fromBlock='latest')
|
||||
|
||||
# Deploy second version of the government contract
|
||||
government_library_v2, _ = chain.interface.deploy_contract(
|
||||
government_library_v2, _ = testerchain.interface.deploy_contract(
|
||||
'Government', escrow.address, policy_manager.address, 1,
|
||||
)
|
||||
# Get first version of the escrow contract
|
||||
escrow_library_v1 = escrow.functions.target().call()
|
||||
# Deploy second version of the escrow contract
|
||||
escrow_library_v2, _ = chain.interface.deploy_contract(
|
||||
escrow_library_v2, _ = testerchain.interface.deploy_contract(
|
||||
'MinersEscrowV1Mock', [node1], [1]
|
||||
)
|
||||
escrow_library_v2 = escrow_library_v2.address
|
||||
# Get first version of the policy manager contract
|
||||
policy_manager_library_v1 = policy_manager.functions.target().call()
|
||||
# Deploy second version of the policy manager contract
|
||||
policy_manager_library_v2, _ = chain.interface.deploy_contract('PolicyManagerV1Mock')
|
||||
policy_manager_library_v2, _ = testerchain.interface.deploy_contract('PolicyManagerV1Mock')
|
||||
policy_manager_library_v2 = policy_manager_library_v2.address
|
||||
|
||||
# Transfer ownership
|
||||
tx = government.functions.transferOwnership(government.address).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.transferOwnership(government.address).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = policy_manager.functions.transferOwnership(government.address).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Can't create upgrade to the zero address
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = government.functions.createVoting(UPGRADE_GOVERNMENT, NULL_ADDR).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = government.functions.createVoting(UPGRADE_ESCROW, NULL_ADDR).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = government.functions.createVoting(UPGRADE_POLICY_MANAGER, NULL_ADDR).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
# Can't rollback if no previous version
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = government.functions.createVoting(ROLLBACK_GOVERNMENT, NULL_ADDR).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = government.functions.createVoting(ROLLBACK_ESCROW, NULL_ADDR).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = government.functions.createVoting(ROLLBACK_POLICY_MANAGER, NULL_ADDR).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Vote and upgrade government contract
|
||||
tx = government.functions.createVoting(UPGRADE_GOVERNMENT, government_library_v2.address).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
events = voting_created_log.get_all_entries()
|
||||
assert 1 == len(events)
|
||||
|
@ -304,10 +304,10 @@ def test_upgrade(web3, chain, escrow, policy_manager):
|
|||
assert government_library_v2.address == event_args['newAddress']
|
||||
|
||||
tx = government.functions.vote(True).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
chain.time_travel(seconds=3600)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(seconds=3600)
|
||||
tx = government.functions.commitUpgrade().transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert government_library_v2.address == government.functions.target().call()
|
||||
|
||||
events = upgrade_committed_log.get_all_entries()
|
||||
|
@ -320,7 +320,7 @@ def test_upgrade(web3, chain, escrow, policy_manager):
|
|||
|
||||
# Vote and rollback government contract
|
||||
tx = government.functions.createVoting(ROLLBACK_GOVERNMENT, NULL_ADDR).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
events = voting_created_log.get_all_entries()
|
||||
assert 2 == len(events)
|
||||
|
@ -330,10 +330,10 @@ def test_upgrade(web3, chain, escrow, policy_manager):
|
|||
assert NULL_ADDR == event_args['newAddress']
|
||||
|
||||
tx = government.functions.vote(True).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
chain.time_travel(seconds=3600)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(seconds=3600)
|
||||
tx = government.functions.commitUpgrade().transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert government_library_v1.address == government_dispatcher.functions.target().call()
|
||||
|
||||
events = upgrade_committed_log.get_all_entries()
|
||||
|
@ -346,7 +346,7 @@ def test_upgrade(web3, chain, escrow, policy_manager):
|
|||
|
||||
# Vote and upgrade escrow contract
|
||||
tx = government.functions.createVoting(UPGRADE_ESCROW, escrow_library_v2).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
events = voting_created_log.get_all_entries()
|
||||
assert 3 == len(events)
|
||||
|
@ -356,10 +356,10 @@ def test_upgrade(web3, chain, escrow, policy_manager):
|
|||
assert escrow_library_v2 == event_args['newAddress']
|
||||
|
||||
tx = government.functions.vote(True).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
chain.time_travel(seconds=3600)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(seconds=3600)
|
||||
tx = government.functions.commitUpgrade().transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert escrow_library_v2 == escrow.functions.target().call()
|
||||
|
||||
events = upgrade_committed_log.get_all_entries()
|
||||
|
@ -372,7 +372,7 @@ def test_upgrade(web3, chain, escrow, policy_manager):
|
|||
|
||||
# Vote and rollback escrow contract
|
||||
tx = government.functions.createVoting(ROLLBACK_ESCROW, NULL_ADDR).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
events = voting_created_log.get_all_entries()
|
||||
assert 4 == len(events)
|
||||
|
@ -382,10 +382,10 @@ def test_upgrade(web3, chain, escrow, policy_manager):
|
|||
assert NULL_ADDR == event_args['newAddress']
|
||||
|
||||
tx = government.functions.vote(True).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
chain.time_travel(seconds=3600)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(seconds=3600)
|
||||
tx = government.functions.commitUpgrade().transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
assert escrow_library_v1 == escrow.functions.target().call()
|
||||
|
||||
|
@ -399,7 +399,7 @@ def test_upgrade(web3, chain, escrow, policy_manager):
|
|||
|
||||
# Vote and upgrade policy manager contract
|
||||
tx = government.functions.createVoting(UPGRADE_POLICY_MANAGER, policy_manager_library_v2).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
events = voting_created_log.get_all_entries()
|
||||
assert 5 == len(events)
|
||||
|
@ -409,10 +409,10 @@ def test_upgrade(web3, chain, escrow, policy_manager):
|
|||
assert policy_manager_library_v2 == event_args['newAddress']
|
||||
|
||||
tx = government.functions.vote(True).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
chain.time_travel(seconds=3600)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(seconds=3600)
|
||||
tx = government.functions.commitUpgrade().transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert policy_manager_library_v2 == policy_manager.functions.target().call()
|
||||
|
||||
events = upgrade_committed_log.get_all_entries()
|
||||
|
@ -425,7 +425,7 @@ def test_upgrade(web3, chain, escrow, policy_manager):
|
|||
|
||||
# Vote and rollback policy manager contract
|
||||
tx = government.functions.createVoting(ROLLBACK_POLICY_MANAGER, NULL_ADDR).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
events = voting_created_log.get_all_entries()
|
||||
assert 6 == len(events)
|
||||
|
@ -435,10 +435,10 @@ def test_upgrade(web3, chain, escrow, policy_manager):
|
|||
assert NULL_ADDR == event_args['newAddress']
|
||||
|
||||
tx = government.functions.vote(True).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
chain.time_travel(seconds=3600)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(seconds=3600)
|
||||
tx = government.functions.commitUpgrade().transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert policy_manager_library_v1 == policy_manager.functions.target().call()
|
||||
|
||||
events = upgrade_committed_log.get_all_entries()
|
||||
|
@ -451,39 +451,39 @@ def test_upgrade(web3, chain, escrow, policy_manager):
|
|||
|
||||
|
||||
@pytest.mark.slow()
|
||||
def test_cancel_upgrading(web3, chain, escrow, policy_manager):
|
||||
creator = web3.eth.accounts[0]
|
||||
node1 = web3.eth.accounts[1]
|
||||
def test_cancel_upgrading(testerchain, escrow, policy_manager):
|
||||
creator = testerchain.interface.w3.eth.accounts[0]
|
||||
node1 = testerchain.interface.w3.eth.accounts[1]
|
||||
|
||||
# Deploy contract
|
||||
government_library, _ = chain.interface.deploy_contract(
|
||||
government_library, _ = testerchain.interface.deploy_contract(
|
||||
'GovernmentV2Mock', escrow.address, policy_manager.address, 1,
|
||||
)
|
||||
government_dispatcher, _ = chain.interface.deploy_contract(
|
||||
government_dispatcher, _ = testerchain.interface.deploy_contract(
|
||||
'Dispatcher', government_library.address
|
||||
)
|
||||
government = web3.eth.contract(
|
||||
government = testerchain.interface.w3.eth.contract(
|
||||
abi=government_library.abi,
|
||||
address=government_dispatcher.address,
|
||||
ContractFactoryClass=Contract
|
||||
)
|
||||
escrow_library = escrow.functions.target().call()
|
||||
policy_manager_library = policy_manager.functions.target().call()
|
||||
upgradeable_bad, _ = chain.interface.deploy_contract('UpgradeableBad')
|
||||
upgradeable_bad, _ = testerchain.interface.deploy_contract('UpgradeableBad')
|
||||
upgrade_committed_log = government.events.UpgradeCommitted.createFilter(fromBlock=0)
|
||||
tx = government.functions.transferOwnership(government.address).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Vote to upgrade to the bad government contract
|
||||
tx = government.functions.createVoting(UPGRADE_GOVERNMENT, upgradeable_bad.address).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = government.functions.vote(True).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
chain.time_travel(seconds=3600)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(seconds=3600)
|
||||
|
||||
# Upgrading failed and canceled
|
||||
tx = government.functions.commitUpgrade().transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert FINISHED_STATE == government.functions.getVotingState().call()
|
||||
assert government_library.address == government_dispatcher.functions.target().call()
|
||||
|
||||
|
@ -497,16 +497,16 @@ def test_cancel_upgrading(web3, chain, escrow, policy_manager):
|
|||
|
||||
# Vote to bad rollback
|
||||
tx = government.functions.setPreviousTarget(upgradeable_bad.address).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = government.functions.createVoting(ROLLBACK_GOVERNMENT, NULL_ADDR).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = government.functions.vote(True).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
chain.time_travel(seconds=3600)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(seconds=3600)
|
||||
|
||||
# Rollback failed and canceled
|
||||
tx = government.functions.commitUpgrade().transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert FINISHED_STATE == government.functions.getVotingState().call()
|
||||
assert government_library.address == government.functions.target().call()
|
||||
|
||||
|
@ -519,14 +519,14 @@ def test_cancel_upgrading(web3, chain, escrow, policy_manager):
|
|||
|
||||
# Vote to upgrade to the bad escrow contract
|
||||
tx = government.functions.createVoting(UPGRADE_ESCROW, upgradeable_bad.address).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = government.functions.vote(True).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
chain.time_travel(seconds=3600)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(seconds=3600)
|
||||
|
||||
# Upgrading failed and canceled
|
||||
tx = government.functions.commitUpgrade().transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert FINISHED_STATE == government.functions.getVotingState().call()
|
||||
assert escrow_library == escrow.functions.target().call()
|
||||
|
||||
|
@ -540,16 +540,16 @@ def test_cancel_upgrading(web3, chain, escrow, policy_manager):
|
|||
|
||||
# Vote to bad rollback
|
||||
tx = escrow.functions.setPreviousTarget(upgradeable_bad.address).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = government.functions.createVoting(ROLLBACK_ESCROW, NULL_ADDR).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = government.functions.vote(True).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
chain.time_travel(seconds=3600)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(seconds=3600)
|
||||
|
||||
# Rollback failed and canceled
|
||||
tx = government.functions.commitUpgrade().transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert FINISHED_STATE == government.functions.getVotingState().call()
|
||||
assert escrow_library == escrow.functions.target().call()
|
||||
|
||||
|
@ -562,14 +562,14 @@ def test_cancel_upgrading(web3, chain, escrow, policy_manager):
|
|||
|
||||
# Vote to upgrade to the bad policy manager contract
|
||||
tx = government.functions.createVoting(UPGRADE_POLICY_MANAGER, upgradeable_bad.address).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = government.functions.vote(True).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
chain.time_travel(seconds=3600)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(seconds=3600)
|
||||
|
||||
# Upgrading failed and canceled
|
||||
tx = government.functions.commitUpgrade().transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert FINISHED_STATE == government.functions.getVotingState().call()
|
||||
assert policy_manager_library == policy_manager.functions.target().call()
|
||||
|
||||
|
@ -583,16 +583,16 @@ def test_cancel_upgrading(web3, chain, escrow, policy_manager):
|
|||
|
||||
# Vote to bad rollback
|
||||
tx = policy_manager.functions.setPreviousTarget(upgradeable_bad.address).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = government.functions.createVoting(ROLLBACK_POLICY_MANAGER, NULL_ADDR).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = government.functions.vote(True).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
chain.time_travel(seconds=3600)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(seconds=3600)
|
||||
|
||||
# Rollback failed and canceled
|
||||
tx = government.functions.commitUpgrade().transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert FINISHED_STATE == government.functions.getVotingState().call()
|
||||
assert policy_manager_library == policy_manager.functions.target().call()
|
||||
|
||||
|
@ -605,60 +605,60 @@ def test_cancel_upgrading(web3, chain, escrow, policy_manager):
|
|||
|
||||
|
||||
@pytest.mark.slow
|
||||
def test_verifying_state(web3, chain):
|
||||
creator = web3.eth.accounts[0]
|
||||
address1 = web3.eth.accounts[1]
|
||||
address2 = web3.eth.accounts[2]
|
||||
def test_verifying_state(testerchain):
|
||||
creator = testerchain.interface.w3.eth.accounts[0]
|
||||
address1 = testerchain.interface.w3.eth.accounts[1]
|
||||
address2 = testerchain.interface.w3.eth.accounts[2]
|
||||
|
||||
# Deploy contract
|
||||
government_library_v1, _ = chain.interface.deploy_contract(
|
||||
government_library_v1, _ = testerchain.interface.deploy_contract(
|
||||
'Government', address1, address2, 1,
|
||||
)
|
||||
government_dispatcher, _ = chain.interface.deploy_contract(
|
||||
government_dispatcher, _ = testerchain.interface.deploy_contract(
|
||||
'Dispatcher', government_library_v1.address
|
||||
)
|
||||
|
||||
# Deploy second version of the government contract
|
||||
government_library_v2, _ = chain.interface.deploy_contract(
|
||||
government_library_v2, _ = testerchain.interface.deploy_contract(
|
||||
'GovernmentV2Mock', address2, address1, 2,
|
||||
)
|
||||
government = web3.eth.contract(
|
||||
government = testerchain.interface.w3.eth.contract(
|
||||
abi=government_library_v2.abi,
|
||||
address=government_dispatcher.address,
|
||||
ContractFactoryClass=Contract)
|
||||
|
||||
# Upgrade to the second version
|
||||
tx = government_dispatcher.functions.upgrade(government_library_v2.address).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert government_library_v2.address == government_dispatcher.functions.target().call()
|
||||
assert address2 == government.functions.escrow().call()
|
||||
assert address1 == government.functions.policyManager().call()
|
||||
assert 2 * 60 * 60 == government.functions.votingDurationSeconds().call()
|
||||
tx = government.functions.setValueToCheck(3).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 3 == government.functions.valueToCheck().call()
|
||||
|
||||
# Can't upgrade to the previous version or to the bad version
|
||||
government_library_bad, _ = chain.interface.deploy_contract('GovernmentBad')
|
||||
government_library_bad, _ = testerchain.interface.deploy_contract('GovernmentBad')
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = government_dispatcher.functions.upgrade(government_library_v1.address).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = government_dispatcher.functions.upgrade(government_library_bad.address).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# But can rollback
|
||||
tx = government_dispatcher.functions.rollback().transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert government_library_v1.address == government_dispatcher.functions.target().call()
|
||||
assert address1 == government.functions.escrow().call()
|
||||
assert address2 == government.functions.policyManager().call()
|
||||
assert 60 * 60 == government.functions.votingDurationSeconds().call()
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = government.functions.setValueToCheck(2).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Try to upgrade to the bad version
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = government_dispatcher.functions.upgrade(government_library_bad.address).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
|
|
@ -4,18 +4,18 @@ from eth_tester.exceptions import TransactionFailed
|
|||
|
||||
|
||||
@pytest.fixture()
|
||||
def token(chain):
|
||||
def token(testerchain):
|
||||
# Create an ERC20 token
|
||||
token, _ = chain.interface.deploy_contract('NuCypherToken', 2 * 10 ** 40)
|
||||
token, _ = testerchain.interface.deploy_contract('NuCypherToken', 2 * 10 ** 40)
|
||||
return token
|
||||
|
||||
@pytest.mark.slow
|
||||
def test_issuer(web3, chain, token):
|
||||
creator = web3.eth.accounts[0]
|
||||
ursula = web3.eth.accounts[1]
|
||||
def test_issuer(testerchain, token):
|
||||
creator = testerchain.interface.w3.eth.accounts[0]
|
||||
ursula = testerchain.interface.w3.eth.accounts[1]
|
||||
|
||||
# Creator deploys the issuer
|
||||
issuer, _ = chain.interface.deploy_contract(
|
||||
issuer, _ = testerchain.interface.deploy_contract(
|
||||
'IssuerMock', token.address, 1, 10 ** 46, int(1e7), int(1e7)
|
||||
)
|
||||
|
||||
|
@ -24,10 +24,10 @@ def test_issuer(web3, chain, token):
|
|||
# Give Miner tokens for reward and initialize contract
|
||||
reserved_reward = 2 * 10 ** 40 - 10 ** 30
|
||||
tx = token.functions.transfer(issuer.address, reserved_reward).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
tx = issuer.functions.initialize().transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
events = events.get_all_entries()
|
||||
|
||||
assert 1 == len(events)
|
||||
|
@ -37,103 +37,106 @@ def test_issuer(web3, chain, token):
|
|||
# Can't initialize second time
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = issuer.functions.initialize().transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Mint some tokens
|
||||
tx = issuer.functions.testMint(0, 1000, 2000, 0).transact({'from': ursula})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 10 == token.functions.balanceOf(ursula).call()
|
||||
assert balance - 10 == token.functions.balanceOf(issuer.address).call()
|
||||
|
||||
# Mint more tokens
|
||||
tx = issuer.functions.testMint(0, 500, 500, 0).transact({'from': ursula})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 30 == token.functions.balanceOf(ursula).call()
|
||||
assert balance - 30 == token.functions.balanceOf(issuer.address).call()
|
||||
|
||||
tx = issuer.functions.testMint(0, 500, 500, 10 ** 7).transact({'from': ursula})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 70 == token.functions.balanceOf(ursula).call()
|
||||
assert balance - 70 == token.functions.balanceOf(issuer.address).call()
|
||||
|
||||
tx = issuer.functions.testMint(0, 500, 500, 2 * 10 ** 7).transact({'from': ursula})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
assert 110 == token.functions.balanceOf(ursula).call()
|
||||
assert balance - 110 == token.functions.balanceOf(issuer.address).call()
|
||||
|
||||
|
||||
@pytest.mark.slow
|
||||
def test_inflation_rate(web3, chain, token):
|
||||
creator = web3.eth.accounts[0]
|
||||
ursula = web3.eth.accounts[1]
|
||||
def test_inflation_rate(testerchain, token):
|
||||
creator = testerchain.interface.w3.eth.accounts[0]
|
||||
ursula = testerchain.interface.w3.eth.accounts[1]
|
||||
|
||||
# Creator deploys the miner
|
||||
issuer, _ = chain.interface.deploy_contract(
|
||||
issuer, _ = testerchain.interface.deploy_contract(
|
||||
'IssuerMock', token.address, 1, 2 * 10 ** 19, 1, 1
|
||||
)
|
||||
|
||||
# Give Miner tokens for reward and initialize contract
|
||||
tx = token.functions.transfer(issuer.address, 2 * 10 ** 40 - 10 ** 30).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = issuer.functions.initialize().transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Mint some tokens
|
||||
period = issuer.functions.getCurrentPeriod().call()
|
||||
tx = issuer.functions.testMint(period + 1, 1, 1, 0).transact({'from': ursula})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
one_period = token.functions.balanceOf(ursula).call()
|
||||
|
||||
# Mint more tokens in the same period
|
||||
tx = issuer.functions.testMint(period + 1, 1, 1, 0).transact({'from': ursula})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 2 * one_period == token.functions.balanceOf(ursula).call()
|
||||
|
||||
# Mint tokens in the next period
|
||||
tx = issuer.functions.testMint(period + 2, 1, 1, 0).transact({'from': ursula})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
assert 3 * one_period > token.functions.balanceOf(ursula).call()
|
||||
minted_amount = token.functions.balanceOf(ursula).call() - 2 * one_period
|
||||
|
||||
# Mint tokens in the next period
|
||||
tx = issuer.functions.testMint(period + 1, 1, 1, 0).transact({'from': ursula})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 2 * one_period + 2 * minted_amount == token.functions.balanceOf(ursula).call()
|
||||
|
||||
# Mint tokens in the next period
|
||||
tx = issuer.functions.testMint(period + 3, 1, 1, 0).transact({'from': ursula})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
assert 2 * one_period + 3 * minted_amount > token.functions.balanceOf(ursula).call()
|
||||
|
||||
|
||||
@pytest.mark.slow
|
||||
def test_verifying_state(web3, chain, token):
|
||||
creator = web3.eth.accounts[0]
|
||||
def test_verifying_state(testerchain, token):
|
||||
creator = testerchain.interface.w3.eth.accounts[0]
|
||||
|
||||
# Deploy contract
|
||||
contract_library_v1, _ = chain.interface.deploy_contract(
|
||||
contract_library_v1, _ = testerchain.interface.deploy_contract(
|
||||
'Issuer', token.address, 1, 1, 1, 1
|
||||
)
|
||||
dispatcher, _ = chain.interface.deploy_contract('Dispatcher', contract_library_v1.address)
|
||||
dispatcher, _ = testerchain.interface.deploy_contract('Dispatcher', contract_library_v1.address)
|
||||
|
||||
# Deploy second version of the contract
|
||||
contract_library_v2, _ = chain.interface.deploy_contract('IssuerV2Mock', token.address, 2, 2, 2, 2)
|
||||
contract = web3.eth.contract(
|
||||
contract_library_v2, _ = testerchain.interface.deploy_contract('IssuerV2Mock', token.address, 2, 2, 2, 2)
|
||||
contract = testerchain.interface.w3.eth.contract(
|
||||
abi=contract_library_v2.abi,
|
||||
address=dispatcher.address,
|
||||
ContractFactoryClass=Contract)
|
||||
|
||||
# Give Miner tokens for reward and initialize contract
|
||||
tx = token.functions.transfer(contract.address, 10000).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = contract.functions.initialize().transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Upgrade to the second version
|
||||
period = contract.functions.lastMintedPeriod().call()
|
||||
assert 1 == contract.functions.miningCoefficient().call()
|
||||
tx = dispatcher.functions.upgrade(contract_library_v2.address).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert contract_library_v2.address == dispatcher.functions.target().call()
|
||||
assert 2 == contract.functions.miningCoefficient().call()
|
||||
assert 2 * 3600 == contract.functions.secondsPerPeriod().call()
|
||||
|
@ -142,21 +145,21 @@ def test_verifying_state(web3, chain, token):
|
|||
assert period == contract.functions.lastMintedPeriod().call()
|
||||
assert 2 * 10 ** 40 == contract.functions.totalSupply().call()
|
||||
tx = contract.functions.setValueToCheck(3).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 3 == contract.functions.valueToCheck().call()
|
||||
|
||||
# Can't upgrade to the previous version or to the bad version
|
||||
contract_library_bad, _ = chain.interface.deploy_contract('IssuerBad', token.address, 2, 2, 2, 2)
|
||||
contract_library_bad, _ = testerchain.interface.deploy_contract('IssuerBad', token.address, 2, 2, 2, 2)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = dispatcher.functions.upgrade(contract_library_v1.address).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = dispatcher.functions.upgrade(contract_library_bad.address).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# But can rollback
|
||||
tx = dispatcher.functions.rollback().transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert contract_library_v1.address == dispatcher.functions.target().call()
|
||||
assert 1 == contract.functions.miningCoefficient().call()
|
||||
assert 3600 == contract.functions.secondsPerPeriod().call()
|
||||
|
@ -166,9 +169,9 @@ def test_verifying_state(web3, chain, token):
|
|||
assert 2 * 10 ** 40 == contract.functions.totalSupply().call()
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = contract.functions.setValueToCheck(2).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Try to upgrade to the bad version
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = dispatcher.functions.upgrade(contract_library_bad.address).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
|
|
@ -12,31 +12,31 @@ LAST_ACTIVE_PERIOD_FIELD = 4
|
|||
|
||||
|
||||
@pytest.fixture()
|
||||
def token(chain):
|
||||
def token(testerchain):
|
||||
# Create an ERC20 token
|
||||
token, _ = chain.interface.deploy_contract('NuCypherToken', 2 * 10 ** 9)
|
||||
token, _ = testerchain.interface.deploy_contract('NuCypherToken', 2 * 10 ** 9)
|
||||
return token
|
||||
|
||||
|
||||
@pytest.fixture(params=[False, True])
|
||||
def escrow_contract(web3, chain, token, request):
|
||||
def escrow_contract(testerchain, token, request):
|
||||
def make_escrow(max_allowed_locked_tokens):
|
||||
# Creator deploys the escrow
|
||||
contract, _ = chain.interface.deploy_contract(
|
||||
contract, _ = testerchain.interface.deploy_contract(
|
||||
'MinersEscrow', token.address, 1, 4 * 2 * 10 ** 7, 4, 4, 2, 100, max_allowed_locked_tokens)
|
||||
|
||||
if request.param:
|
||||
dispatcher, _ = chain.interface.deploy_contract('Dispatcher', contract.address)
|
||||
contract = web3.eth.contract(
|
||||
dispatcher, _ = testerchain.interface.deploy_contract('Dispatcher', contract.address)
|
||||
contract = testerchain.interface.w3.eth.contract(
|
||||
abi=contract.abi,
|
||||
address=dispatcher.address,
|
||||
ContractFactoryClass=Contract)
|
||||
|
||||
policy_manager, _ = chain.interface.deploy_contract(
|
||||
policy_manager, _ = testerchain.interface.deploy_contract(
|
||||
'PolicyManagerForMinersEscrowMock', token.address, contract.address
|
||||
)
|
||||
tx = contract.functions.setPolicyManager(policy_manager.address).transact()
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert policy_manager.address == contract.functions.policyManager().call()
|
||||
return contract
|
||||
|
||||
|
@ -44,11 +44,11 @@ def escrow_contract(web3, chain, token, request):
|
|||
|
||||
|
||||
@pytest.mark.slow
|
||||
def test_escrow(web3, chain, token, escrow_contract):
|
||||
def test_escrow(testerchain, token, escrow_contract):
|
||||
escrow = escrow_contract(1500)
|
||||
creator = web3.eth.accounts[0]
|
||||
ursula1 = web3.eth.accounts[1]
|
||||
ursula2 = web3.eth.accounts[2]
|
||||
creator = testerchain.interface.w3.eth.accounts[0]
|
||||
ursula1 = testerchain.interface.w3.eth.accounts[1]
|
||||
ursula2 = testerchain.interface.w3.eth.accounts[2]
|
||||
deposit_log = escrow.events.Deposited.createFilter(fromBlock='latest')
|
||||
lock_log = escrow.events.Locked.createFilter(fromBlock='latest')
|
||||
activity_log = escrow.events.ActivityConfirmed.createFilter(fromBlock='latest')
|
||||
|
@ -57,69 +57,69 @@ def test_escrow(web3, chain, token, escrow_contract):
|
|||
|
||||
# Give Ursula and Ursula(2) some coins
|
||||
tx = token.functions.transfer(ursula1, 10000).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = token.functions.transfer(ursula2, 10000).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 10000 == token.functions.balanceOf(ursula1).call()
|
||||
assert 10000 == token.functions.balanceOf(ursula2).call()
|
||||
|
||||
# Ursula and Ursula(2) give Escrow rights to transfer
|
||||
tx = token.functions.approve(escrow.address, 1100).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 1100 == token.functions.allowance(ursula1, escrow.address).call()
|
||||
tx = token.functions.approve(escrow.address, 500).transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 500 == token.functions.allowance(ursula2, escrow.address).call()
|
||||
|
||||
# Ursula's withdrawal attempt won't succeed because nothing to withdraw
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.withdraw(100).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# And can't lock because nothing to lock
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.lock(500, 2).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Check that nothing is locked
|
||||
assert 0 == escrow.functions.getLockedTokens(ursula1).call()
|
||||
assert 0 == escrow.functions.getLockedTokens(ursula2).call()
|
||||
assert 0 == escrow.functions.getLockedTokens(web3.eth.accounts[3]).call()
|
||||
assert 0 == escrow.functions.getLockedTokens(testerchain.interface.w3.eth.accounts[3]).call()
|
||||
|
||||
# Ursula can't deposit tokens before Escrow initialization
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.deposit(1, 1).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Initialize Escrow contract
|
||||
tx = escrow.functions.initialize().transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Ursula can't deposit and lock too low value
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.deposit(1, 10).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = token.functions.approveAndCall(escrow.address, 1, web3.toBytes(10)).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
tx = token.functions.approveAndCall(escrow.address, 1, testerchain.interface.w3.toBytes(10)).transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
# And can't deposit and lock too high value
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.deposit(1501, 10).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = token.functions.approveAndCall(escrow.address, 1501, web3.toBytes(10)).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
tx = token.functions.approveAndCall(escrow.address, 1501, testerchain.interface.w3.toBytes(10)).transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
# And can't deposit for too short a period
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.deposit(1000, 1).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = token.functions.approveAndCall(escrow.address, 1000, web3.toBytes(1)).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
tx = token.functions.approveAndCall(escrow.address, 1000, testerchain.interface.w3.toBytes(1)).transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Ursula and Ursula(2) transfer some tokens to the escrow and lock them
|
||||
tx = escrow.functions.deposit(1000, 2).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 1000 == token.functions.balanceOf(escrow.address).call()
|
||||
assert 9000 == token.functions.balanceOf(ursula1).call()
|
||||
assert 0 == escrow.functions.getLockedTokens(ursula1).call()
|
||||
|
@ -149,7 +149,7 @@ def test_escrow(web3, chain, token, escrow_contract):
|
|||
assert 1000 == event_args['value']
|
||||
|
||||
tx = escrow.functions.deposit(500, 2).transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 1500 == token.functions.balanceOf(escrow.address).call()
|
||||
assert 9500 == token.functions.balanceOf(ursula2).call()
|
||||
assert 0 == escrow.functions.getLockedTokens(ursula2).call()
|
||||
|
@ -177,7 +177,7 @@ def test_escrow(web3, chain, token, escrow_contract):
|
|||
assert 500 == event_args['value']
|
||||
|
||||
# Checks locked tokens in next period
|
||||
chain.time_travel(hours=1)
|
||||
testerchain.time_travel(hours=1)
|
||||
assert 1000 == escrow.functions.getLockedTokens(ursula1).call()
|
||||
assert 500 == escrow.functions.getLockedTokens(ursula2).call()
|
||||
assert 1500 == escrow.functions.getAllLockedTokens().call()
|
||||
|
@ -185,14 +185,15 @@ def test_escrow(web3, chain, token, escrow_contract):
|
|||
# Ursula's withdrawal attempt won't succeed
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.withdraw(100).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 1500 == token.functions.balanceOf(escrow.address).call()
|
||||
assert 9000 == token.functions.balanceOf(ursula1).call()
|
||||
|
||||
# Ursula can deposit more tokens
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert escrow.functions.getCurrentPeriod().call() + 1 == escrow.functions.getLastActivePeriod(ursula1).call()
|
||||
|
||||
assert 1000 == escrow.functions.getLockedTokens(ursula1, 1).call()
|
||||
assert 0 == escrow.functions.getLockedTokens(ursula1, 2).call()
|
||||
events = activity_log.get_all_entries()
|
||||
|
@ -202,8 +203,8 @@ def test_escrow(web3, chain, token, escrow_contract):
|
|||
assert escrow.functions.getCurrentPeriod().call() + 1 == event_args['period']
|
||||
assert 1000 == event_args['value']
|
||||
|
||||
tx = token.functions.approveAndCall(escrow.address, 500, web3.toBytes(2)).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
tx = token.functions.approveAndCall(escrow.address, 500, testerchain.interface.w3.toBytes(2)).transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 2000 == token.functions.balanceOf(escrow.address).call()
|
||||
assert 8500 == token.functions.balanceOf(ursula1).call()
|
||||
assert 1500 == escrow.functions.getLockedTokens(ursula1, 1).call()
|
||||
|
@ -220,19 +221,19 @@ def test_escrow(web3, chain, token, escrow_contract):
|
|||
# But can't deposit too high value
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.deposit(100, 2).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = token.functions.approveAndCall(escrow.address, 100, web3.toBytes(2)).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
tx = token.functions.approveAndCall(escrow.address, 100, testerchain.interface.w3.toBytes(2)).transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Wait 1 period and checks locking
|
||||
chain.time_travel(hours=1)
|
||||
testerchain.time_travel(hours=1)
|
||||
assert 1500 == escrow.functions.getLockedTokens(ursula1).call()
|
||||
|
||||
# Confirm activity and wait 1 period
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
chain.time_travel(hours=1)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=1)
|
||||
assert 500 == escrow.functions.getLockedTokens(ursula1).call()
|
||||
assert 0 == escrow.functions.getLockedTokens(ursula1, 1).call()
|
||||
|
||||
|
@ -245,7 +246,7 @@ def test_escrow(web3, chain, token, escrow_contract):
|
|||
|
||||
# And Ursula can withdraw some tokens
|
||||
tx = escrow.functions.withdraw(100).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 1900 == token.functions.balanceOf(escrow.address).call()
|
||||
assert 8600 == token.functions.balanceOf(ursula1).call()
|
||||
events = withdraw_log.get_all_entries()
|
||||
|
@ -257,16 +258,16 @@ def test_escrow(web3, chain, token, escrow_contract):
|
|||
# But Ursula can't withdraw all without mining for locked value
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.withdraw(1400).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# And Ursula can't lock again too low value
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.lock(1, 1).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Ursula can deposit and lock more tokens
|
||||
tx = token.functions.approveAndCall(escrow.address, 500, web3.toBytes(2)).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
tx = token.functions.approveAndCall(escrow.address, 500, testerchain.interface.w3.toBytes(2)).transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
events = activity_log.get_all_entries()
|
||||
assert 6 == len(events)
|
||||
|
@ -276,7 +277,7 @@ def test_escrow(web3, chain, token, escrow_contract):
|
|||
assert 500 == event_args['value']
|
||||
|
||||
tx = escrow.functions.lock(100, 2).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
events = activity_log.get_all_entries()
|
||||
assert 7 == len(events)
|
||||
|
@ -291,35 +292,36 @@ def test_escrow(web3, chain, token, escrow_contract):
|
|||
assert 600 == escrow.functions.getLockedTokens(ursula1, 1).call()
|
||||
assert 600 == escrow.functions.getLockedTokens(ursula1, 2).call()
|
||||
assert 0 == escrow.functions.getLockedTokens(ursula1, 3).call()
|
||||
chain.time_travel(hours=1)
|
||||
testerchain.time_travel(hours=1)
|
||||
assert 600 == escrow.functions.getLockedTokens(ursula1).call()
|
||||
assert 600 == escrow.functions.getLockedTokens(ursula1, 1).call()
|
||||
assert 0 == escrow.functions.getLockedTokens(ursula1, 2).call()
|
||||
|
||||
# Ursula can increase lock
|
||||
tx = escrow.functions.lock(500, 2).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 600 == escrow.functions.getLockedTokens(ursula1).call()
|
||||
assert 1100 == escrow.functions.getLockedTokens(ursula1, 1).call()
|
||||
assert 500 == escrow.functions.getLockedTokens(ursula1, 2).call()
|
||||
assert 0 == escrow.functions.getLockedTokens(ursula1, 3).call()
|
||||
chain.time_travel(hours=1)
|
||||
testerchain.time_travel(hours=1)
|
||||
assert 1100 == escrow.functions.getLockedTokens(ursula1).call()
|
||||
|
||||
# Ursula(2) increases lock by deposit more tokens using approveAndCall
|
||||
tx = token.functions.approveAndCall(escrow.address, 500, web3.toBytes(2)).transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
tx = token.functions.approveAndCall(escrow.address, 500, testerchain.interface.w3.toBytes(2)).transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 500 == escrow.functions.getLockedTokens(ursula2).call()
|
||||
assert 1000 == escrow.functions.getLockedTokens(ursula2, 1).call()
|
||||
assert 500 == escrow.functions.getLockedTokens(ursula2, 2).call()
|
||||
assert 0 == escrow.functions.getLockedTokens(ursula2, 3).call()
|
||||
chain.time_travel(hours=1)
|
||||
testerchain.time_travel(hours=1)
|
||||
|
||||
# And increases locked time
|
||||
period = escrow.functions.getCurrentPeriod().call()
|
||||
tx = escrow.functions.divideStake(500, period + 1, 200, 1).transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 1000 == escrow.functions.getLockedTokens(ursula2).call()
|
||||
|
||||
assert 500 == escrow.functions.getLockedTokens(ursula2, 1).call()
|
||||
assert 200 == escrow.functions.getLockedTokens(ursula2, 2).call()
|
||||
assert 0 == escrow.functions.getLockedTokens(ursula2, 3).call()
|
||||
|
@ -341,11 +343,12 @@ def test_escrow(web3, chain, token, escrow_contract):
|
|||
assert 1 == event_args['periods']
|
||||
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
chain.time_travel(hours=1)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=1)
|
||||
period = escrow.functions.getCurrentPeriod().call()
|
||||
tx = escrow.functions.divideStake(300, period, 200, 2).transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
assert 500 == escrow.functions.getLockedTokens(ursula2).call()
|
||||
assert 400 == escrow.functions.getLockedTokens(ursula2, 1).call()
|
||||
assert 200 == escrow.functions.getLockedTokens(ursula2, 2).call()
|
||||
|
@ -361,7 +364,8 @@ def test_escrow(web3, chain, token, escrow_contract):
|
|||
assert 2 == event_args['periods']
|
||||
|
||||
tx = escrow.functions.divideStake(200, period + 1, 100, 2).transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
assert 500 == escrow.functions.getLockedTokens(ursula2).call()
|
||||
assert 400 == escrow.functions.getLockedTokens(ursula2, 1).call()
|
||||
assert 300 == escrow.functions.getLockedTokens(ursula2, 2).call()
|
||||
|
@ -378,22 +382,22 @@ def test_escrow(web3, chain, token, escrow_contract):
|
|||
assert 2 == event_args['periods']
|
||||
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
chain.time_travel(hours=1)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=1)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
chain.time_travel(hours=1)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=1)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Can't divide old stake
|
||||
period = escrow.functions.getCurrentPeriod().call()
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.divideStake(500, period - 3, 200, 10).transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
tx = escrow.functions.divideStake(200, period, 100, 1).transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
events = divides_log.get_all_entries()
|
||||
assert 4 == len(events)
|
||||
|
@ -425,34 +429,34 @@ def test_escrow(web3, chain, token, escrow_contract):
|
|||
|
||||
|
||||
@pytest.mark.slow
|
||||
def test_locked_distribution(web3, chain, token, escrow_contract):
|
||||
def test_locked_distribution(testerchain, token, escrow_contract):
|
||||
escrow = escrow_contract(5 * 10 ** 8)
|
||||
NULL_ADDR = '0x' + '0' * 40
|
||||
creator = web3.eth.accounts[0]
|
||||
creator = testerchain.interface.w3.eth.accounts[0]
|
||||
|
||||
# Give Escrow tokens for reward and initialize contract
|
||||
tx = token.functions.transfer(escrow.address, 10 ** 9).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.initialize().transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
miners = web3.eth.accounts[1:]
|
||||
miners = testerchain.interface.w3.eth.accounts[1:]
|
||||
amount = token.functions.balanceOf(creator).call() // 2
|
||||
largest_locked = amount
|
||||
|
||||
# Airdrop
|
||||
for miner in miners:
|
||||
tx = token.functions.transfer(miner, amount).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
amount = amount // 2
|
||||
|
||||
# Lock
|
||||
for index, miner in enumerate(miners):
|
||||
balance = token.functions.balanceOf(miner).call()
|
||||
tx = token.functions.approve(escrow.address, balance).transact({'from': miner})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.deposit(balance, index + 2).transact({'from': miner})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Check current period
|
||||
address_stop, index_stop, shift = escrow.functions.findCumSum(0, 1, 1).call()
|
||||
|
@ -461,14 +465,14 @@ def test_locked_distribution(web3, chain, token, escrow_contract):
|
|||
assert 0 == shift
|
||||
|
||||
# Wait next period
|
||||
chain.time_travel(hours=1)
|
||||
testerchain.time_travel(hours=1)
|
||||
n_locked = escrow.functions.getAllLockedTokens().call()
|
||||
assert n_locked > 0
|
||||
|
||||
# And confirm activity
|
||||
for miner in miners:
|
||||
tx = escrow.functions.confirmActivity().transact({'from': miner})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
address_stop, index_stop, shift = escrow.functions.findCumSum(0, n_locked // 3, 1).call()
|
||||
assert miners[0] == address_stop
|
||||
|
@ -507,16 +511,17 @@ def test_locked_distribution(web3, chain, token, escrow_contract):
|
|||
|
||||
|
||||
@pytest.mark.slow
|
||||
def test_mining(web3, chain, token, escrow_contract):
|
||||
def test_mining(testerchain, token, escrow_contract):
|
||||
escrow = escrow_contract(1500)
|
||||
policy_manager_interface = chain.interface.get_contract_factory('PolicyManagerForMinersEscrowMock')
|
||||
policy_manager = web3.eth.contract(
|
||||
policy_manager_interface = testerchain.interface.get_contract_factory('PolicyManagerForMinersEscrowMock')
|
||||
policy_manager = testerchain.interface.w3.eth.contract(
|
||||
abi=policy_manager_interface.abi,
|
||||
address=escrow.functions.policyManager().call(),
|
||||
ContractFactoryClass=Contract)
|
||||
creator = web3.eth.accounts[0]
|
||||
ursula1 = web3.eth.accounts[1]
|
||||
ursula2 = web3.eth.accounts[2]
|
||||
creator = testerchain.interface.w3.eth.accounts[0]
|
||||
ursula1 = testerchain.interface.w3.eth.accounts[1]
|
||||
ursula2 = testerchain.interface.w3.eth.accounts[2]
|
||||
|
||||
|
||||
mining_log = escrow.events.Mined.createFilter(fromBlock='latest')
|
||||
deposit_log = escrow.events.Deposited.createFilter(fromBlock='latest')
|
||||
|
@ -527,35 +532,36 @@ def test_mining(web3, chain, token, escrow_contract):
|
|||
|
||||
# Give Escrow tokens for reward and initialize contract
|
||||
tx = token.functions.transfer(escrow.address, 10 ** 9).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.initialize().transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Give Ursula and Ursula(2) some coins
|
||||
tx = token.functions.transfer(ursula1, 10000).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = token.functions.transfer(ursula2, 10000).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Ursula can't confirm and mint because no locked tokens
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.mint().transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Ursula and Ursula(2) give Escrow rights to transfer
|
||||
tx = token.functions.approve(escrow.address, 2000).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = token.functions.approve(escrow.address, 750).transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Ursula and Ursula(2) transfer some tokens to the escrow and lock them
|
||||
tx = escrow.functions.deposit(1000, 2).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.deposit(500, 2).transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
|
||||
testerchain.wait_for_receipt(tx)
|
||||
period = escrow.functions.getCurrentPeriod().call()
|
||||
assert 1 == policy_manager.functions.getPeriodsLength(ursula1).call()
|
||||
assert 1 == policy_manager.functions.getPeriodsLength(ursula2).call()
|
||||
|
@ -574,7 +580,7 @@ def test_mining(web3, chain, token, escrow_contract):
|
|||
|
||||
# Ursula divides her stake
|
||||
tx = escrow.functions.divideStake(1000, period + 2, 500, 1).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Using locked tokens starts from next period
|
||||
assert 0 == escrow.functions.getAllLockedTokens().call()
|
||||
|
@ -582,28 +588,31 @@ def test_mining(web3, chain, token, escrow_contract):
|
|||
# Ursula can't use method from Issuer contract
|
||||
with pytest.raises(Exception):
|
||||
tx = escrow.functions.mint(1, 1, 1, 1).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Only Ursula confirm next period
|
||||
chain.time_travel(hours=1)
|
||||
testerchain.time_travel(hours=1)
|
||||
assert 1500 == escrow.functions.getAllLockedTokens().call()
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 1 == escrow.functions.getDowntimeLength(ursula1).call()
|
||||
|
||||
# Checks that no error
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Ursula and Ursula(2) mint tokens for last periods
|
||||
# And only Ursula confirm activity for next period
|
||||
chain.time_travel(hours=1)
|
||||
testerchain.time_travel(hours=1)
|
||||
assert 1000 == escrow.functions.getAllLockedTokens().call()
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.mint().transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
|
||||
testerchain.wait_for_receipt(tx)
|
||||
period = escrow.functions.getCurrentPeriod().call()
|
||||
|
||||
assert 1046 == escrow.functions.minerInfo(ursula1).call()[VALUE_FIELD]
|
||||
assert 525 == escrow.functions.minerInfo(ursula2).call()[VALUE_FIELD]
|
||||
assert 1 == escrow.functions.getDowntimeLength(ursula1).call()
|
||||
|
@ -630,22 +639,23 @@ def test_mining(web3, chain, token, escrow_contract):
|
|||
|
||||
# Ursula try to mint again
|
||||
tx = escrow.functions.mint().transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 1046 == escrow.functions.minerInfo(ursula1).call()[VALUE_FIELD]
|
||||
events = mining_log.get_all_entries()
|
||||
assert 2 == len(events)
|
||||
|
||||
# Ursula can't confirm next period
|
||||
chain.time_travel(hours=1)
|
||||
testerchain.time_travel(hours=1)
|
||||
assert 500 == escrow.functions.getAllLockedTokens().call()
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
# But Ursula(2) can
|
||||
period = escrow.functions.getCurrentPeriod().call()
|
||||
assert period - 2 == escrow.functions.getLastActivePeriod(ursula2).call()
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert period + 1 == escrow.functions.getLastActivePeriod(ursula2).call()
|
||||
assert 2 == escrow.functions.getDowntimeLength(ursula2).call()
|
||||
downtime = escrow.functions.getDowntime(ursula2, 1).call()
|
||||
|
@ -653,13 +663,13 @@ def test_mining(web3, chain, token, escrow_contract):
|
|||
assert period == downtime[1]
|
||||
|
||||
# Ursula mint tokens
|
||||
chain.time_travel(hours=1)
|
||||
testerchain.time_travel(hours=1)
|
||||
assert 500 == escrow.functions.getAllLockedTokens().call()
|
||||
tx = escrow.functions.mint().transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
# But Ursula(2) can't get reward because she did not confirm activity
|
||||
tx = escrow.functions.mint().transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 1152 == escrow.functions.minerInfo(ursula1).call()[VALUE_FIELD]
|
||||
assert 525 == escrow.functions.minerInfo(ursula2).call()[VALUE_FIELD]
|
||||
|
||||
|
@ -676,10 +686,10 @@ def test_mining(web3, chain, token, escrow_contract):
|
|||
assert period == policy_manager.functions.getPeriod(ursula1, 3).call()
|
||||
|
||||
# Ursula(2) mint tokens
|
||||
chain.time_travel(hours=1)
|
||||
testerchain.time_travel(hours=1)
|
||||
assert 0 == escrow.functions.getAllLockedTokens().call()
|
||||
tx = escrow.functions.mint().transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 1152 == escrow.functions.minerInfo(ursula1).call()[VALUE_FIELD]
|
||||
assert 575 == escrow.functions.minerInfo(ursula2).call()[VALUE_FIELD]
|
||||
|
||||
|
@ -698,34 +708,37 @@ def test_mining(web3, chain, token, escrow_contract):
|
|||
# Ursula(2) can't more confirm activity
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Ursula can't confirm and get reward because no locked tokens
|
||||
tx = escrow.functions.mint().transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
period = escrow.functions.getCurrentPeriod().call()
|
||||
assert period - 2 == escrow.functions.getLastActivePeriod(ursula1).call()
|
||||
|
||||
assert 1152 == escrow.functions.minerInfo(ursula1).call()[VALUE_FIELD]
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Ursula(2) deposits and locks more tokens
|
||||
tx = escrow.functions.deposit(250, 4).transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.lock(500, 2).transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 3 == escrow.functions.getDowntimeLength(ursula2).call()
|
||||
downtime = escrow.functions.getDowntime(ursula2, 2).call()
|
||||
assert period == downtime[0]
|
||||
assert period == downtime[1]
|
||||
|
||||
# Ursula(2) mint only one period (by using deposit/approveAndCall function)
|
||||
chain.time_travel(hours=5)
|
||||
testerchain.time_travel(hours=5)
|
||||
period = escrow.functions.getCurrentPeriod().call()
|
||||
assert period - 4 == escrow.functions.getLastActivePeriod(ursula2).call()
|
||||
tx = token.functions.approveAndCall(escrow.address, 100, web3.toBytes(2)).transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
tx = token.functions.approveAndCall(escrow.address, 100, testerchain.interface.w3.toBytes(2)).transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
assert 1152 == escrow.functions.minerInfo(ursula1).call()[VALUE_FIELD]
|
||||
assert 1025 == escrow.functions.minerInfo(ursula2).call()[VALUE_FIELD]
|
||||
assert 4 == escrow.functions.getDowntimeLength(ursula2).call()
|
||||
|
@ -744,19 +757,20 @@ def test_mining(web3, chain, token, escrow_contract):
|
|||
assert escrow.functions.getCurrentPeriod().call() - 1 == event_args['period']
|
||||
|
||||
# Ursula(2) confirm activity for remaining periods
|
||||
chain.time_travel(hours=1)
|
||||
testerchain.time_travel(hours=1)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 4 == escrow.functions.getDowntimeLength(ursula2).call()
|
||||
chain.time_travel(hours=1)
|
||||
testerchain.time_travel(hours=1)
|
||||
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Ursula(2) can withdraw all
|
||||
chain.time_travel(hours=2)
|
||||
testerchain.time_travel(hours=2)
|
||||
assert 0 == escrow.functions.getLockedTokens(ursula2).call()
|
||||
tx = escrow.functions.withdraw(1083).transact({'from': ursula2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 0 == escrow.functions.minerInfo(ursula2).call()[VALUE_FIELD]
|
||||
assert 10233 == token.functions.balanceOf(ursula2).call()
|
||||
|
||||
|
@ -773,28 +787,29 @@ def test_mining(web3, chain, token, escrow_contract):
|
|||
|
||||
|
||||
@pytest.mark.slow
|
||||
def test_pre_deposit(web3, chain, token, escrow_contract):
|
||||
def test_pre_deposit(testerchain, token, escrow_contract):
|
||||
escrow = escrow_contract(1500)
|
||||
policy_manager_interface = chain.interface.get_contract_factory('PolicyManagerForMinersEscrowMock')
|
||||
policy_manager = web3.eth.contract(
|
||||
policy_manager_interface = testerchain.interface.get_contract_factory('PolicyManagerForMinersEscrowMock')
|
||||
policy_manager = testerchain.interface.w3.eth.contract(
|
||||
abi=policy_manager_interface.abi,
|
||||
address=escrow.functions.policyManager().call(),
|
||||
ContractFactoryClass=Contract)
|
||||
creator = web3.eth.accounts[0]
|
||||
creator = testerchain.interface.w3.eth.accounts[0]
|
||||
|
||||
deposit_log = escrow.events.Deposited.createFilter(fromBlock='latest')
|
||||
|
||||
# Initialize Escrow contract
|
||||
tx = escrow.functions.initialize().transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Grant access to transfer tokens
|
||||
tx = token.functions.approve(escrow.address, 10000).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Deposit tokens for 1 owner
|
||||
owner = web3.eth.accounts[1]
|
||||
owner = testerchain.interface.w3.eth.accounts[1]
|
||||
tx = escrow.functions.preDeposit([owner], [1000], [10]).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 1000 == token.functions.balanceOf(escrow.address).call()
|
||||
assert 1000 == escrow.functions.minerInfo(owner).call()[VALUE_FIELD]
|
||||
assert 0 == escrow.functions.getLockedTokens(owner).call()
|
||||
|
@ -809,27 +824,27 @@ def test_pre_deposit(web3, chain, token, escrow_contract):
|
|||
|
||||
# Can't pre-deposit tokens again for same owner
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.preDeposit([web3.eth.accounts[1]], [1000], [10]).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.preDeposit([testerchain.interface.w3.eth.accounts[1]], [1000], [10]).transact({'from': creator})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Can't pre-deposit tokens with too low or too high value
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.preDeposit([web3.eth.accounts[2]], [1], [10]).transact({'from': creator})
|
||||
tx = escrow.functions.preDeposit([testerchain.interface.w3.eth.accounts[2]], [1], [10]).transact({'from': creator})
|
||||
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.preDeposit([web3.eth.accounts[2]], [1501], [10]).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.preDeposit([testerchain.interface.w3.eth.accounts[2]], [1501], [10]).transact({'from': creator})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.preDeposit([web3.eth.accounts[2]], [500], [1]).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.preDeposit([testerchain.interface.w3.eth.accounts[2]], [500], [1]).transact({'from': creator})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Deposit tokens for multiple owners
|
||||
owners = web3.eth.accounts[2:7]
|
||||
owners = testerchain.interface.w3.eth.accounts[2:7]
|
||||
tx = escrow.functions.preDeposit(
|
||||
owners, [100, 200, 300, 400, 500], [50, 100, 150, 200, 250]).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
assert 2500 == token.functions.balanceOf(escrow.address).call()
|
||||
period = escrow.functions.getCurrentPeriod().call()
|
||||
|
@ -846,7 +861,7 @@ def test_pre_deposit(web3, chain, token, escrow_contract):
|
|||
events = deposit_log.get_all_entries()
|
||||
assert 6 == len(events)
|
||||
event_args = events[0]['args']
|
||||
assert web3.eth.accounts[1] == event_args['owner']
|
||||
assert testerchain.interface.w3.eth.accounts[1] == event_args['owner']
|
||||
assert 1000 == event_args['value']
|
||||
assert 10 == event_args['periods']
|
||||
event_args = events[1]['args']
|
||||
|
@ -872,114 +887,116 @@ def test_pre_deposit(web3, chain, token, escrow_contract):
|
|||
|
||||
|
||||
@pytest.mark.slow
|
||||
def test_miner_id(web3, chain, token, escrow_contract):
|
||||
def test_miner_id(testerchain, token, escrow_contract):
|
||||
escrow = escrow_contract(5 * 10 ** 8)
|
||||
creator = web3.eth.accounts[0]
|
||||
miner = web3.eth.accounts[1]
|
||||
creator = testerchain.interface.w3.eth.accounts[0]
|
||||
miner = testerchain.interface.w3.eth.accounts[1]
|
||||
|
||||
# Initialize contract and miner
|
||||
tx = escrow.functions.initialize().transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = token.functions.transfer(miner, 1000).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
balance = token.functions.balanceOf(miner).call()
|
||||
tx = token.functions.approve(escrow.address, balance).transact({'from': miner})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.deposit(balance, 2).transact({'from': miner})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Set miner ids
|
||||
miner_id = os.urandom(33)
|
||||
tx = escrow.functions.setMinerId(miner_id).transact({'from': miner})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 1 == escrow.functions.getMinerIdsLength(miner).call()
|
||||
|
||||
assert miner_id == escrow.functions.getMinerId(miner, 0).call()
|
||||
miner_id = os.urandom(66)
|
||||
tx = escrow.functions.setMinerId(miner_id).transact({'from': miner})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 2 == escrow.functions.getMinerIdsLength(miner).call()
|
||||
|
||||
assert miner_id == escrow.functions.getMinerId(miner, 1).call()
|
||||
|
||||
|
||||
@pytest.mark.slow
|
||||
def test_verifying_state(web3, chain, token):
|
||||
creator = web3.eth.accounts[0]
|
||||
miner = web3.eth.accounts[1]
|
||||
def test_verifying_state(testerchain, token):
|
||||
creator = testerchain.interface.w3.eth.accounts[0]
|
||||
miner = testerchain.interface.w3.eth.accounts[1]
|
||||
|
||||
# Deploy contract
|
||||
contract_library_v1, _ = chain.interface.deploy_contract(
|
||||
contract_library_v1, _ = testerchain.interface.deploy_contract(
|
||||
'MinersEscrow', token.address, 1, int(8e7), 4, 4, 2, 100, 1500
|
||||
)
|
||||
dispatcher, _ = chain.interface.deploy_contract('Dispatcher', contract_library_v1.address)
|
||||
dispatcher, _ = testerchain.interface.deploy_contract('Dispatcher', contract_library_v1.address)
|
||||
|
||||
# Deploy second version of the contract
|
||||
contract_library_v2, _ = chain.interface.deploy_contract(
|
||||
contract_library_v2, _ = testerchain.interface.deploy_contract(
|
||||
'MinersEscrowV2Mock', token.address, 2, 2, 2, 2, 2, 2, 2, 2
|
||||
)
|
||||
|
||||
contract = web3.eth.contract(
|
||||
contract = testerchain.interface.w3.eth.contract(
|
||||
abi=contract_library_v2.abi,
|
||||
address=dispatcher.address,
|
||||
ContractFactoryClass=Contract)
|
||||
assert 1500 == contract.functions.maxAllowableLockedTokens().call()
|
||||
|
||||
# Initialize contract and miner
|
||||
policy_manager, _ = chain.interface.deploy_contract(
|
||||
policy_manager, _ = testerchain.interface.deploy_contract(
|
||||
'PolicyManagerForMinersEscrowMock', token.address, contract.address
|
||||
)
|
||||
tx = contract.functions.setPolicyManager(policy_manager.address).transact()
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
tx = contract.functions.initialize().transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = token.functions.transfer(miner, 1000).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
balance = token.functions.balanceOf(miner).call()
|
||||
tx = token.functions.approve(contract.address, balance).transact({'from': miner})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = contract.functions.deposit(balance, 1000).transact({'from': miner})
|
||||
chain.wait_for_receipt(tx)
|
||||
tx = contract.functions.setMinerId(web3.toBytes(111)).transact({'from': miner})
|
||||
chain.wait_for_receipt(tx)
|
||||
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = contract.functions.setMinerId(testerchain.interface.w3.toBytes(111)).transact({'from': miner})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Upgrade to the second version
|
||||
tx = dispatcher.functions.upgrade(contract_library_v2.address).transact({'from': creator})
|
||||
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert contract_library_v2.address == dispatcher.functions.target().call()
|
||||
assert 1500 == contract.functions.maxAllowableLockedTokens().call()
|
||||
assert policy_manager.address == contract.functions.policyManager().call()
|
||||
assert 2 == contract.functions.valueToCheck().call()
|
||||
assert 1 == web3.toInt(contract.functions.getMinerIdsLength(miner).call())
|
||||
assert 111 == web3.toInt(contract.functions.getMinerId(miner, 0).call())
|
||||
assert 1 == testerchain.interface.w3.toInt(contract.functions.getMinerIdsLength(miner).call())
|
||||
assert 111 == testerchain.interface.w3.toInt(contract.functions.getMinerId(miner, 0).call())
|
||||
tx = contract.functions.setValueToCheck(3).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 3 == contract.functions.valueToCheck().call()
|
||||
|
||||
# Can't upgrade to the previous version or to the bad version
|
||||
contract_library_bad, _ = chain.interface.deploy_contract(
|
||||
contract_library_bad, _ = testerchain.interface.deploy_contract(
|
||||
'MinersEscrowBad', token.address, 2, 2, 2, 2, 2, 2, 2
|
||||
)
|
||||
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = dispatcher.functions.upgrade(contract_library_v1.address).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = dispatcher.functions.upgrade(contract_library_bad.address).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# But can rollback
|
||||
tx = dispatcher.functions.rollback().transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert contract_library_v1.address == dispatcher.functions.target().call()
|
||||
assert policy_manager.address == contract.functions.policyManager().call()
|
||||
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = contract.functions.setValueToCheck(2).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Try to upgrade to the bad version
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = dispatcher.functions.upgrade(contract_library_bad.address).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
|
|
@ -20,42 +20,42 @@ MIN_REWARD_RATE_FIELD = 3
|
|||
|
||||
|
||||
@pytest.fixture()
|
||||
def escrow(chain):
|
||||
def escrow(testerchain):
|
||||
# Creator deploys the escrow
|
||||
escrow, _ = chain.interface.deploy_contract('MinersEscrowForPolicyMock', 1)
|
||||
escrow, _ = testerchain.interface.deploy_contract('MinersEscrowForPolicyMock', 1)
|
||||
return escrow
|
||||
|
||||
|
||||
@pytest.fixture(params=[False, True])
|
||||
def policy_manager(web3, chain, escrow, request):
|
||||
creator, client, bad_node, node1, node2, node3, *everyone_else = web3.eth.accounts
|
||||
def policy_manager(testerchain, escrow, request):
|
||||
creator, client, bad_node, node1, node2, node3, *everyone_else = testerchain.interface.w3.eth.accounts
|
||||
|
||||
# Creator deploys the policy manager
|
||||
contract, _ = chain.interface.deploy_contract('PolicyManager', escrow.address)
|
||||
contract, _ = testerchain.interface.deploy_contract('PolicyManager', escrow.address)
|
||||
|
||||
# Give client some ether
|
||||
tx = web3.eth.sendTransaction({'from': web3.eth.coinbase, 'to': client, 'value': 10000})
|
||||
chain.wait_for_receipt(tx)
|
||||
tx = testerchain.interface.w3.eth.sendTransaction({'from': testerchain.interface.w3.eth.coinbase, 'to': client, 'value': 10000})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
if request.param:
|
||||
dispatcher, _ = chain.interface.deploy_contract('Dispatcher', contract.address)
|
||||
dispatcher, _ = testerchain.interface.deploy_contract('Dispatcher', contract.address)
|
||||
|
||||
# Deploy second version of the government contract
|
||||
contract = web3.eth.contract(
|
||||
contract = testerchain.interface.w3.eth.contract(
|
||||
abi=contract.abi,
|
||||
address=dispatcher.address,
|
||||
ContractFactoryClass=Contract)
|
||||
|
||||
tx = escrow.functions.setPolicyManager(contract.address).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Register nodes
|
||||
tx = escrow.functions.register(node1).transact()
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.register(node2).transact()
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.register(node3).transact()
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
return contract
|
||||
|
||||
|
@ -69,10 +69,10 @@ value = rate * number_of_periods
|
|||
|
||||
|
||||
@pytest.mark.slow
|
||||
def test_create_revoke(web3, chain, escrow, policy_manager):
|
||||
creator, client, bad_node, node1, node2, node3, *everyone_else = web3.eth.accounts
|
||||
def test_create_revoke(testerchain, escrow, policy_manager):
|
||||
creator, client, bad_node, node1, node2, node3, *everyone_else = testerchain.interface.w3.eth.accounts
|
||||
|
||||
client_balance = web3.eth.getBalance(client)
|
||||
client_balance = testerchain.interface.w3.eth.getBalance(client)
|
||||
policy_created_log = policy_manager.events.PolicyCreated.createFilter(fromBlock='latest')
|
||||
arrangement_revoked_log = policy_manager.events.ArrangementRevoked.createFilter(fromBlock='latest')
|
||||
policy_revoked_log = policy_manager.events.PolicyRevoked.createFilter(fromBlock='latest')
|
||||
|
@ -88,23 +88,24 @@ def test_create_revoke(web3, chain, escrow, policy_manager):
|
|||
# Try create policy for bad node
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = policy_manager.functions.createPolicy(policy_id, 1, 0, [bad_node]).transact({'from': client, 'value': value})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = policy_manager.functions.createPolicy(policy_id, 1, 0, [node1, bad_node]).transact({'from': client, 'value': value})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Try create policy with no ETH
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = policy_manager.functions.createPolicy(policy_id, 1, 0, [node1]).transact({'from': client})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Create policy
|
||||
period = escrow.functions.getCurrentPeriod().call()
|
||||
tx = policy_manager.functions.createPolicy(policy_id, number_of_periods, 0, [node1]).transact({'from': client, 'value': value, 'gas_price': 0})
|
||||
|
||||
chain.wait_for_receipt(tx)
|
||||
assert value == web3.eth.getBalance(policy_manager.address)
|
||||
assert client_balance - 200 == web3.eth.getBalance(client)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert value == testerchain.interface.w3.eth.getBalance(policy_manager.address)
|
||||
assert client_balance - 200 == testerchain.interface.w3.eth.getBalance(client)
|
||||
policy = policy_manager.functions.policies(policy_id).call()
|
||||
assert client == policy[CLIENT_FIELD]
|
||||
assert rate == policy[RATE_FIELD]
|
||||
|
@ -125,14 +126,14 @@ def test_create_revoke(web3, chain, escrow, policy_manager):
|
|||
# Try to create policy again
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = policy_manager.functions.createPolicy(policy_id, number_of_periods, 0, [node1]).transact({'from': client, 'value': value})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Only client can revoke policy
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = policy_manager.functions.revokePolicy(policy_id).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = policy_manager.functions.revokePolicy(policy_id).transact({'from': client, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert policy_manager.functions.policies(policy_id).call()[DISABLED_FIELD]
|
||||
|
||||
events = policy_revoked_log.get_all_entries()
|
||||
|
@ -153,17 +154,17 @@ def test_create_revoke(web3, chain, escrow, policy_manager):
|
|||
# Can't revoke again
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = policy_manager.functions.revokePolicy(policy_id).transact({'from': client})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = policy_manager.functions.revokeArrangement(policy_id, node1).transact({'from': client})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Create another policy
|
||||
period = escrow.functions.getCurrentPeriod().call()
|
||||
tx = policy_manager.functions.createPolicy(policy_id_2, number_of_periods, 0, [node1, node2, node3]).transact({'from': client, 'value': 6 * value, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert 6 * value == web3.eth.getBalance(policy_manager.address)
|
||||
assert client_balance - 6 * value == web3.eth.getBalance(client)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 6 * value == testerchain.interface.w3.eth.getBalance(policy_manager.address)
|
||||
assert client_balance - 6 * value == testerchain.interface.w3.eth.getBalance(client)
|
||||
policy = policy_manager.functions.policies(policy_id_2).call()
|
||||
assert client == policy[CLIENT_FIELD]
|
||||
assert 2 * rate == policy[RATE_FIELD]
|
||||
|
@ -181,16 +182,16 @@ def test_create_revoke(web3, chain, escrow, policy_manager):
|
|||
|
||||
# Can't revoke nonexistent arrangement
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = policy_manager.functions.revokeArrangement(policy_id_2, web3.eth.accounts[6]).transact({'from': client})
|
||||
chain.wait_for_receipt(tx)
|
||||
tx = policy_manager.functions.revokeArrangement(policy_id_2, testerchain.interface.w3.eth.accounts[6]).transact({'from': client})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = policy_manager.functions.revokeArrangement(policy_id_2, NULL_ADDR).transact({'from': client})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
tx = policy_manager.functions.revokeArrangement(policy_id_2, node1).transact({'from': client, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert 4 * value == web3.eth.getBalance(policy_manager.address)
|
||||
assert client_balance - 4 * value == web3.eth.getBalance(client)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 4 * value == testerchain.interface.w3.eth.getBalance(policy_manager.address)
|
||||
assert client_balance - 4 * value == testerchain.interface.w3.eth.getBalance(client)
|
||||
assert not policy_manager.functions.policies(policy_id_2).call()[DISABLED_FIELD]
|
||||
|
||||
events = arrangement_revoked_log.get_all_entries()
|
||||
|
@ -204,15 +205,15 @@ def test_create_revoke(web3, chain, escrow, policy_manager):
|
|||
# Can't revoke again
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = policy_manager.functions.revokeArrangement(policy_id_2, node1).transact({'from': client})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = policy_manager.functions.revokeArrangement(policy_id_2, NULL_ADDR).transact({'from': client})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
tx = policy_manager.functions.revokePolicy(policy_id_2).transact({'from': client, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert 0 == web3.eth.getBalance(policy_manager.address)
|
||||
assert client_balance == web3.eth.getBalance(client)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 0 == testerchain.interface.w3.eth.getBalance(policy_manager.address)
|
||||
assert client_balance == testerchain.interface.w3.eth.getBalance(client)
|
||||
assert policy_manager.functions.policies(policy_id_2).call()[DISABLED_FIELD]
|
||||
|
||||
events = arrangement_revoked_log.get_all_entries()
|
||||
|
@ -239,37 +240,37 @@ def test_create_revoke(web3, chain, escrow, policy_manager):
|
|||
# Can't revoke again
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = policy_manager.functions.revokePolicy(policy_id_2).transact({'from': client})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = policy_manager.functions.revokeArrangement(policy_id_2, node1).transact({'from': client})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Try to create policy with wrong value
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = policy_manager.functions.createPolicy(policy_id_3, 10, 0, [node1]).transact({'from': client, 'value': 11})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = policy_manager.functions.createPolicy(policy_id_3, 10, 1, [node1]).transact({'from': client, 'value': 22})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = policy_manager.functions.createPolicy(policy_id_3, 10, 1, [node1]).transact({'from': client, 'value': 11})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Set minimum reward rate for nodes
|
||||
tx = policy_manager.functions.setMinRewardRate(10).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = policy_manager.functions.setMinRewardRate(20).transact({'from': node2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 10 == policy_manager.functions.nodes(node1).call()[MIN_REWARD_RATE_FIELD]
|
||||
assert 20 == policy_manager.functions.nodes(node2).call()[MIN_REWARD_RATE_FIELD]
|
||||
|
||||
# Try to create policy with low rate
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = policy_manager.functions.createPolicy(policy_id_3, 1, 0, [node1]).transact({'from': client, 'value': 5})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = policy_manager.functions.createPolicy(policy_id_3, 1, 0, [node1, node2]).transact({'from': client, 'value': 30})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Create another policy with pay for first period
|
||||
# Reward rate is calculated as (firstReward + rewardRate * numberOfPeriods) * numberOfNodes
|
||||
|
@ -278,9 +279,9 @@ def test_create_revoke(web3, chain, escrow, policy_manager):
|
|||
.transact({'from': client,
|
||||
'value': int((0.5 * rate + rate * number_of_periods) * 3),
|
||||
'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert 3 * value + 1.5 * rate == web3.eth.getBalance(policy_manager.address)
|
||||
assert client_balance - int(3 * value + 1.5 * rate) == web3.eth.getBalance(client)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 3 * value + 1.5 * rate == testerchain.interface.w3.eth.getBalance(policy_manager.address)
|
||||
assert client_balance - int(3 * value + 1.5 * rate) == testerchain.interface.w3.eth.getBalance(client)
|
||||
policy = policy_manager.functions.policies(policy_id_3).call()
|
||||
assert client == policy[CLIENT_FIELD]
|
||||
assert rate == policy[RATE_FIELD]
|
||||
|
@ -297,9 +298,9 @@ def test_create_revoke(web3, chain, escrow, policy_manager):
|
|||
# assert node == event_args['node']
|
||||
|
||||
tx = policy_manager.functions.revokeArrangement(policy_id_3, node1).transact({'from': client, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert 2 * value + rate == web3.eth.getBalance(policy_manager.address)
|
||||
assert client_balance - (2 * value + rate) == web3.eth.getBalance(client)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 2 * value + rate == testerchain.interface.w3.eth.getBalance(policy_manager.address)
|
||||
assert client_balance - (2 * value + rate) == testerchain.interface.w3.eth.getBalance(client)
|
||||
assert not policy_manager.functions.policies(policy_id_3).call()[DISABLED_FIELD]
|
||||
|
||||
events = arrangement_revoked_log.get_all_entries()
|
||||
|
@ -311,9 +312,9 @@ def test_create_revoke(web3, chain, escrow, policy_manager):
|
|||
assert value + 0.5 * rate == event_args['value']
|
||||
|
||||
tx = policy_manager.functions.revokePolicy(policy_id_3).transact({'from': client, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert 0 == web3.eth.getBalance(policy_manager.address)
|
||||
assert client_balance == web3.eth.getBalance(client)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 0 == testerchain.interface.w3.eth.getBalance(policy_manager.address)
|
||||
assert client_balance == testerchain.interface.w3.eth.getBalance(client)
|
||||
assert policy_manager.functions.policies(policy_id_3).call()[DISABLED_FIELD]
|
||||
|
||||
events = arrangement_revoked_log.get_all_entries()
|
||||
|
@ -344,46 +345,46 @@ def test_create_revoke(web3, chain, escrow, policy_manager):
|
|||
|
||||
|
||||
@pytest.mark.slow
|
||||
def test_reward(web3, chain, escrow, policy_manager):
|
||||
creator, client, bad_node, node1, node2, node3, *everyone_else = web3.eth.accounts
|
||||
node_balance = web3.eth.getBalance(node1)
|
||||
def test_reward(testerchain, escrow, policy_manager):
|
||||
creator, client, bad_node, node1, node2, node3, *everyone_else = testerchain.interface.w3.eth.accounts
|
||||
node_balance = testerchain.interface.w3.eth.getBalance(node1)
|
||||
withdraw_log = policy_manager.events.Withdrawn.createFilter(fromBlock='latest')
|
||||
|
||||
# Mint period without policies
|
||||
period = escrow.functions.getCurrentPeriod().call()
|
||||
tx = escrow.functions.mint(period, 1).transact({'from': node1, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 0 == policy_manager.functions.nodes(node1).call()[REWARD_FIELD]
|
||||
|
||||
# Create policy
|
||||
tx = policy_manager.functions.createPolicy(policy_id, number_of_periods, 0, [node1, node3]).transact({'from': client, 'value': 2 * value})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Nothing to withdraw
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = policy_manager.functions.withdraw().transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Can't update reward directly
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = policy_manager.functions.updateReward(node1, period + 1).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
# Can't register directly
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = policy_manager.functions.register(bad_node, period).transact({'from': bad_node})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Mint some periods
|
||||
tx = escrow.functions.mint(period, 5).transact({'from': node1, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
period += 5
|
||||
assert 80 == policy_manager.functions.nodes(node1).call()[REWARD_FIELD]
|
||||
|
||||
# Withdraw
|
||||
tx = policy_manager.functions.withdraw().transact({'from': node1, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert node_balance + 80 == web3.eth.getBalance(node1)
|
||||
assert 120 + value == web3.eth.getBalance(policy_manager.address)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert node_balance + 80 == testerchain.interface.w3.eth.getBalance(node1)
|
||||
assert 120 + value == testerchain.interface.w3.eth.getBalance(policy_manager.address)
|
||||
|
||||
events = withdraw_log.get_all_entries()
|
||||
assert 1 == len(events)
|
||||
|
@ -394,18 +395,18 @@ def test_reward(web3, chain, escrow, policy_manager):
|
|||
# Mint more periods
|
||||
for x in range(6):
|
||||
tx = escrow.functions.mint(period, 1).transact({'from': node1, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
period += 1
|
||||
assert 120 == policy_manager.functions.nodes(node1).call()[REWARD_FIELD]
|
||||
tx = escrow.functions.mint(period, 1).transact({'from': node1, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 120 == policy_manager.functions.nodes(node1).call()[REWARD_FIELD]
|
||||
|
||||
# Withdraw
|
||||
tx = policy_manager.functions.withdraw().transact({'from': node1, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert node_balance + value == web3.eth.getBalance(node1)
|
||||
assert value == web3.eth.getBalance(policy_manager.address)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert node_balance + value == testerchain.interface.w3.eth.getBalance(node1)
|
||||
assert value == testerchain.interface.w3.eth.getBalance(policy_manager.address)
|
||||
|
||||
events = withdraw_log.get_all_entries()
|
||||
assert 2 == len(events)
|
||||
|
@ -416,31 +417,31 @@ def test_reward(web3, chain, escrow, policy_manager):
|
|||
# Create policy
|
||||
tx = policy_manager.functions.createPolicy(policy_id_2, number_of_periods, int(0.5 * rate), [node2, node3]) \
|
||||
.transact({'from': client, 'value': int(2 * value + rate)})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Mint some periods
|
||||
period = escrow.functions.getCurrentPeriod().call()
|
||||
tx = escrow.functions.mint(period, 5).transact({'from': node2, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
period += 5
|
||||
assert 90 == policy_manager.functions.nodes(node2).call()[REWARD_FIELD]
|
||||
|
||||
# Mint more periods
|
||||
for x in range(6):
|
||||
tx = escrow.functions.mint(period, 1).transact({'from': node2, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
period += 1
|
||||
assert 210 == policy_manager.functions.nodes(node2).call()[REWARD_FIELD]
|
||||
|
||||
|
||||
@pytest.mark.slow
|
||||
def test_refund(web3, chain, escrow, policy_manager):
|
||||
creator = web3.eth.accounts[0]
|
||||
client = web3.eth.accounts[1]
|
||||
node1 = web3.eth.accounts[3]
|
||||
node2 = web3.eth.accounts[4]
|
||||
node3 = web3.eth.accounts[5]
|
||||
client_balance = web3.eth.getBalance(client)
|
||||
def test_refund(testerchain, escrow, policy_manager):
|
||||
creator = testerchain.interface.w3.eth.accounts[0]
|
||||
client = testerchain.interface.w3.eth.accounts[1]
|
||||
node1 = testerchain.interface.w3.eth.accounts[3]
|
||||
node2 = testerchain.interface.w3.eth.accounts[4]
|
||||
node3 = testerchain.interface.w3.eth.accounts[5]
|
||||
client_balance = testerchain.interface.w3.eth.getBalance(client)
|
||||
policy_created_log = policy_manager.events.PolicyCreated.createFilter(fromBlock='latest')
|
||||
arrangement_revoked_log = policy_manager.events.ArrangementRevoked.createFilter(fromBlock='latest')
|
||||
policy_revoked_log = policy_manager.events.PolicyRevoked.createFilter(fromBlock='latest')
|
||||
|
@ -450,25 +451,26 @@ def test_refund(web3, chain, escrow, policy_manager):
|
|||
# Create policy
|
||||
tx = policy_manager.functions.createPolicy(policy_id, number_of_periods, int(0.5 * rate), [node1]) \
|
||||
.transact({'from': client, 'value': int(value + 0.5 * rate), 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.setLastActivePeriod(escrow.functions.getCurrentPeriod().call() - 1).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Wait and refund all
|
||||
chain.time_travel(hours=9)
|
||||
testerchain.time_travel(hours=9)
|
||||
# Check that methods only calculates value
|
||||
tx = policy_manager.functions.calculateRefundValue(policy_id).transact({'from': client, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = policy_manager.functions.calculateRefundValue(policy_id, node1).transact({'from': client, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert 210 == web3.eth.getBalance(policy_manager.address)
|
||||
assert client_balance - 210 == web3.eth.getBalance(client)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 210 == testerchain.interface.w3.eth.getBalance(policy_manager.address)
|
||||
assert client_balance - 210 == testerchain.interface.w3.eth.getBalance(client)
|
||||
assert 190 == policy_manager.functions.calculateRefundValue(policy_id, node1).call({'from': client})
|
||||
assert 190 == policy_manager.functions.calculateRefundValue(policy_id).call({'from': client})
|
||||
|
||||
tx = policy_manager.functions.refund(policy_id).transact({'from': client, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert 20 == web3.eth.getBalance(policy_manager.address)
|
||||
assert client_balance - 20 == web3.eth.getBalance(client)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 20 == testerchain.interface.w3.eth.getBalance(policy_manager.address)
|
||||
assert client_balance - 20 == testerchain.interface.w3.eth.getBalance(client)
|
||||
assert client == policy_manager.functions.policies(policy_id).call()[CLIENT_FIELD]
|
||||
|
||||
events = arrangement_refund_log.get_all_entries()
|
||||
|
@ -486,13 +488,14 @@ def test_refund(web3, chain, escrow, policy_manager):
|
|||
assert client == event_args['client']
|
||||
assert 190 == event_args['value']
|
||||
|
||||
chain.time_travel(hours=1)
|
||||
testerchain.time_travel(hours=1)
|
||||
assert 20 == policy_manager.functions.calculateRefundValue(policy_id).call({'from': client})
|
||||
assert 20 == policy_manager.functions.calculateRefundValue(policy_id, node1).call({'from': client})
|
||||
|
||||
tx = policy_manager.functions.refund(policy_id).transact({'from': client, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert 0 == web3.eth.getBalance(policy_manager.address)
|
||||
assert client_balance == web3.eth.getBalance(client)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 0 == testerchain.interface.w3.eth.getBalance(policy_manager.address)
|
||||
assert client_balance == testerchain.interface.w3.eth.getBalance(client)
|
||||
assert policy_manager.functions.policies(policy_id).call()[DISABLED_FIELD]
|
||||
|
||||
events = arrangement_refund_log.get_all_entries()
|
||||
|
@ -517,13 +520,13 @@ def test_refund(web3, chain, escrow, policy_manager):
|
|||
# Can't refund again
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = policy_manager.functions.refund(policy_id).transact({'from': client})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = policy_manager.functions.refund(policy_id, node1).transact({'from': client})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = policy_manager.functions.refund(policy_id, NULL_ADDR).transact({'from': client})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
policy_manager.functions.calculateRefundValue(policy_id).call({'from': client})
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
|
@ -532,23 +535,23 @@ def test_refund(web3, chain, escrow, policy_manager):
|
|||
policy_manager.functions.calculateRefundValue(policy_id, NULL_ADDR).call({'from': client})
|
||||
|
||||
# Create policy again
|
||||
chain.time_travel(hours=1)
|
||||
testerchain.time_travel(hours=1)
|
||||
period = escrow.call().getCurrentPeriod()
|
||||
tx = escrow.transact().setLastActivePeriod(period)
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = policy_manager.functions.createPolicy(policy_id_2, number_of_periods, int(0.5 * rate), [node1, node2, node3]) \
|
||||
.transact({'from': client, 'value': int(3 * value + 1.5 * rate), 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Nothing to refund
|
||||
assert 0 == policy_manager.functions.calculateRefundValue(policy_id_2).call({'from': client})
|
||||
assert 0 == policy_manager.functions.calculateRefundValue(policy_id_2, node1).call({'from': client})
|
||||
tx = policy_manager.functions.refund(policy_id_2).transact({'from': client, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = policy_manager.functions.refund(policy_id_2, node1).transact({'from': client, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert 3 * value + 1.5 * rate == web3.eth.getBalance(policy_manager.address)
|
||||
assert client_balance - int(3 * value + 1.5 * rate) == web3.eth.getBalance(client)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 3 * value + 1.5 * rate == testerchain.interface.w3.eth.getBalance(policy_manager.address)
|
||||
assert client_balance - int(3 * value + 1.5 * rate) == testerchain.interface.w3.eth.getBalance(client)
|
||||
|
||||
events = arrangement_refund_log.get_all_entries()
|
||||
assert 5 == len(events)
|
||||
|
@ -586,42 +589,43 @@ def test_refund(web3, chain, escrow, policy_manager):
|
|||
# Try to refund nonexistent policy
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = policy_manager.functions.refund(policy_id_3).transact({'from': client})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
policy_manager.functions.calculateRefundValue(policy_id_3).call({'from': client})
|
||||
# Node try to refund by node
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = policy_manager.functions.refund(policy_id_2).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
policy_manager.functions.calculateRefundValue(policy_id_2).call({'from': node1})
|
||||
|
||||
# Mint some periods and mark others as downtime periods
|
||||
tx = escrow.functions.mint(period, 1).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
period += 1
|
||||
tx = escrow.functions.mint(period, 2).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.pushDowntimePeriod(period + 2, period + 3).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.mint(period + 4, 1).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.pushDowntimePeriod(period + 5, period + 7).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.mint(period + 8, 1).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.setLastActivePeriod(period + 8).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 90 == policy_manager.functions.nodes(node1).call()[REWARD_FIELD]
|
||||
|
||||
# Wait and refund
|
||||
chain.time_travel(hours=10)
|
||||
testerchain.time_travel(hours=10)
|
||||
assert 360 == policy_manager.functions.calculateRefundValue(policy_id_2).call({'from': client})
|
||||
assert 120 == policy_manager.functions.calculateRefundValue(policy_id_2, node1).call({'from': client})
|
||||
|
||||
tx = policy_manager.functions.refund(policy_id_2, node1).transact({'from': client, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert 2 * value + 90 + rate == web3.eth.getBalance(policy_manager.address)
|
||||
assert client_balance - (2 * value + 90 + rate) == web3.eth.getBalance(client)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 2 * value + 90 + rate == testerchain.interface.w3.eth.getBalance(policy_manager.address)
|
||||
assert client_balance - (2 * value + 90 + rate) == testerchain.interface.w3.eth.getBalance(client)
|
||||
assert not policy_manager.functions.policies(policy_id_2).call()[DISABLED_FIELD]
|
||||
|
||||
events = arrangement_refund_log.get_all_entries()
|
||||
|
@ -640,23 +644,24 @@ def test_refund(web3, chain, escrow, policy_manager):
|
|||
# Can't refund arrangement again
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = policy_manager.functions.refund(policy_id_2, node1).transact({'from': client})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = policy_manager.functions.refund(policy_id_2, NULL_ADDR).transact({'from': client})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
policy_manager.functions.calculateRefundValue(policy_id_2, node1).call({'from': client})
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
policy_manager.functions.calculateRefundValue(policy_id_2, NULL_ADDR).call({'from': client})
|
||||
|
||||
|
||||
# But can refund others
|
||||
assert 240 == policy_manager.functions.calculateRefundValue(policy_id_2).call({'from': client})
|
||||
assert 120 == policy_manager.functions.calculateRefundValue(policy_id_2, node2).call({'from': client})
|
||||
assert 120 == policy_manager.functions.calculateRefundValue(policy_id_2, node3).call({'from': client})
|
||||
tx = policy_manager.functions.refund(policy_id_2).transact({'from': client, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert 3 * 90 == web3.eth.getBalance(policy_manager.address)
|
||||
assert client_balance - 3 * 90 == web3.eth.getBalance(client)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 3 * 90 == testerchain.interface.w3.eth.getBalance(policy_manager.address)
|
||||
assert client_balance - 3 * 90 == testerchain.interface.w3.eth.getBalance(client)
|
||||
assert policy_manager.functions.policies(policy_id_2).call()[DISABLED_FIELD]
|
||||
|
||||
events = arrangement_refund_log.get_all_entries()
|
||||
|
@ -688,28 +693,29 @@ def test_refund(web3, chain, escrow, policy_manager):
|
|||
period = escrow.functions.getCurrentPeriod().call()
|
||||
tx = policy_manager.functions.createPolicy(policy_id_3, number_of_periods, int(0.5 * rate), [node1])\
|
||||
.transact({'from': client, 'value': int(value + 0.5 * rate), 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Mint some periods
|
||||
period += 1
|
||||
tx = escrow.functions.pushDowntimePeriod(period - 1, period).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
for x in range(3):
|
||||
period += 1
|
||||
tx = escrow.functions.mint(period, 1).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.setLastActivePeriod(period).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 150 == policy_manager.functions.nodes(node1).call()[REWARD_FIELD]
|
||||
|
||||
# Client revokes policy
|
||||
chain.time_travel(hours=4)
|
||||
testerchain.time_travel(hours=4)
|
||||
assert 30 == policy_manager.functions.calculateRefundValue(policy_id_3).call({'from': client})
|
||||
assert 30 == policy_manager.functions.calculateRefundValue(policy_id_3, node1).call({'from': client})
|
||||
|
||||
tx = policy_manager.functions.revokePolicy(policy_id_3).transact({'from': client, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert 60 + 3 * 90 == web3.eth.getBalance(policy_manager.address)
|
||||
assert client_balance - (60 + 3 * 90) == web3.eth.getBalance(client)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 60 + 3 * 90 == testerchain.interface.w3.eth.getBalance(policy_manager.address)
|
||||
assert client_balance - (60 + 3 * 90) == testerchain.interface.w3.eth.getBalance(client)
|
||||
assert policy_manager.functions.policies(policy_id_3).call()[DISABLED_FIELD]
|
||||
|
||||
events = arrangement_refund_log.get_all_entries()
|
||||
|
@ -736,7 +742,7 @@ def test_refund(web3, chain, escrow, policy_manager):
|
|||
for x in range(20):
|
||||
period += 1
|
||||
tx = escrow.functions.mint(period, 1).transact({'from': node1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 150 == policy_manager.functions.nodes(node1).call()[REWARD_FIELD]
|
||||
|
||||
events = policy_created_log.get_all_entries()
|
||||
|
@ -744,20 +750,20 @@ def test_refund(web3, chain, escrow, policy_manager):
|
|||
|
||||
|
||||
@pytest.mark.slow
|
||||
def test_verifying_state(web3, chain):
|
||||
creator = web3.eth.accounts[0]
|
||||
def test_verifying_state(testerchain):
|
||||
creator = testerchain.interface.w3.eth.accounts[0]
|
||||
|
||||
# Deploy contracts
|
||||
escrow1, _ = chain.interface.deploy_contract('MinersEscrowForPolicyMock', 1)
|
||||
escrow2, _ = chain.interface.deploy_contract('MinersEscrowForPolicyMock', 1)
|
||||
escrow1, _ = testerchain.interface.deploy_contract('MinersEscrowForPolicyMock', 1)
|
||||
escrow2, _ = testerchain.interface.deploy_contract('MinersEscrowForPolicyMock', 1)
|
||||
address1 = escrow1.address
|
||||
address2 = escrow2.address
|
||||
contract_library_v1, _ = chain.interface.deploy_contract('PolicyManager', address1)
|
||||
dispatcher, _ = chain.interface.deploy_contract('Dispatcher', contract_library_v1.address)
|
||||
contract_library_v1, _ = testerchain.interface.deploy_contract('PolicyManager', address1)
|
||||
dispatcher, _ = testerchain.interface.deploy_contract('Dispatcher', contract_library_v1.address)
|
||||
|
||||
# Deploy second version of the contract
|
||||
contract_library_v2, _ = chain.interface.deploy_contract('PolicyManagerV2Mock', address2)
|
||||
contract = web3.eth.contract(
|
||||
contract_library_v2, _ = testerchain.interface.deploy_contract('PolicyManagerV2Mock', address2)
|
||||
contract = testerchain.interface.w3.eth.contract(
|
||||
abi=contract_library_v2.abi,
|
||||
address=dispatcher.address,
|
||||
ContractFactoryClass=Contract)
|
||||
|
@ -765,32 +771,32 @@ def test_verifying_state(web3, chain):
|
|||
# Upgrade to the second version
|
||||
assert address1 == contract.functions.escrow().call()
|
||||
tx = dispatcher.functions.upgrade(contract_library_v2.address).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert contract_library_v2.address == dispatcher.functions.target().call()
|
||||
assert address2 == contract.functions.escrow().call()
|
||||
tx = contract.functions.setValueToCheck(3).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 3 == contract.functions.valueToCheck().call()
|
||||
|
||||
# Can't upgrade to the previous version or to the bad version
|
||||
contract_library_bad, _ = chain.interface.deploy_contract('PolicyManagerBad', address2)
|
||||
contract_library_bad, _ = testerchain.interface.deploy_contract('PolicyManagerBad', address2)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = dispatcher.functions.upgrade(contract_library_v1.address).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = dispatcher.functions.upgrade(contract_library_bad.address).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# But can rollback
|
||||
tx = dispatcher.functions.rollback().transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert contract_library_v1.address == dispatcher.functions.target().call()
|
||||
assert address1 == contract.functions.escrow().call()
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = contract.functions.setValueToCheck(2).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Try to upgrade to the bad version
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = dispatcher.functions.upgrade(contract_library_bad.address).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
|
|
@ -2,19 +2,19 @@ import pytest
|
|||
from eth_tester.exceptions import TransactionFailed
|
||||
|
||||
|
||||
def test_create_token(web3, chain):
|
||||
def test_create_token(testerchain):
|
||||
"""
|
||||
These are tests for standard tokens taken from Consensys github:
|
||||
https://github.com/ConsenSys/Tokens/
|
||||
but some of the tests are converted from javascript to python
|
||||
"""
|
||||
|
||||
creator = web3.eth.accounts[0]
|
||||
account1 = web3.eth.accounts[1]
|
||||
account2 = web3.eth.accounts[2]
|
||||
creator = testerchain.interface.w3.eth.accounts[0]
|
||||
account1 = testerchain.interface.w3.eth.accounts[1]
|
||||
account2 = testerchain.interface.w3.eth.accounts[2]
|
||||
|
||||
# Create an ERC20 token
|
||||
token, txhash = chain.interface.deploy_contract('NuCypherToken', 10 ** 9)
|
||||
token, txhash = testerchain.interface.deploy_contract('NuCypherToken', 10 ** 9)
|
||||
assert txhash is not None
|
||||
|
||||
# Account balances
|
||||
|
@ -28,41 +28,41 @@ def test_create_token(web3, chain):
|
|||
|
||||
# Cannot send ethers to the contract
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = web3.eth.sendTransaction({'from': account1, 'to': token.address, 'value': 10 ** 9})
|
||||
chain.wait_for_receipt(tx)
|
||||
tx = testerchain.interface.w3.eth.sendTransaction({'from': account1, 'to': token.address, 'value': 10 ** 9})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Can transfer tokens
|
||||
tx = token.functions.transfer(account1, 10000).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 10000 == token.functions.balanceOf(account1).call()
|
||||
assert 10 ** 9 - 10000 == token.functions.balanceOf(creator).call()
|
||||
|
||||
tx = token.functions.transfer(account2, 10).transact({'from': account1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 10000 - 10 == token.functions.balanceOf(account1).call()
|
||||
assert 10 == token.functions.balanceOf(account2).call()
|
||||
|
||||
tx = token.functions.transfer(token.address, 10).transact({'from': account1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 10 == token.functions.balanceOf(token.address).call()
|
||||
|
||||
# Can burn own tokens
|
||||
tx = token.functions.burn(1).transact({'from': account2})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 9 == token.functions.balanceOf(account2).call()
|
||||
assert 10 ** 9 - 1 == token.functions.totalSupply().call()
|
||||
|
||||
|
||||
def test_approve_and_call(web3, chain):
|
||||
creator = web3.eth.accounts[0]
|
||||
account1 = web3.eth.accounts[1]
|
||||
account2 = web3.eth.accounts[2]
|
||||
def test_approve_and_call(testerchain):
|
||||
creator = testerchain.interface.w3.eth.accounts[0]
|
||||
account1 = testerchain.interface.w3.eth.accounts[1]
|
||||
account2 = testerchain.interface.w3.eth.accounts[2]
|
||||
|
||||
token, _ = chain.interface.deploy_contract('NuCypherToken', 10 ** 9)
|
||||
mock, _ = chain.interface.deploy_contract('ReceiveApprovalMethodMock')
|
||||
token, _ = testerchain.interface.deploy_contract('NuCypherToken', 10 ** 9)
|
||||
mock, _ = testerchain.interface.deploy_contract('ReceiveApprovalMethodMock')
|
||||
|
||||
tx = token.functions.approve(account1, 100).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 100 == token.functions.allowance(creator, account1).call()
|
||||
assert 0 == token.functions.allowance(creator, account2).call()
|
||||
assert 0 == token.functions.allowance(account1, creator).call()
|
||||
|
@ -70,16 +70,16 @@ def test_approve_and_call(web3, chain):
|
|||
assert 0 == token.functions.allowance(account2, account1).call()
|
||||
|
||||
tx = token.functions.transferFrom(creator, account2, 50).transact({'from': account1})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 50 == token.functions.balanceOf(account2).call()
|
||||
assert 50 == token.functions.allowance(creator, account1).call()
|
||||
|
||||
tx = token.functions.approveAndCall(mock.address, 25, web3.toBytes(111)).transact({'from': account1})
|
||||
chain.wait_for_receipt(tx)
|
||||
tx = token.functions.approveAndCall(mock.address, 25, testerchain.interface.w3.toBytes(111)).transact({'from': account1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 50 == token.functions.balanceOf(account2).call()
|
||||
assert 50 == token.functions.allowance(creator, account1).call()
|
||||
assert 25 == token.functions.allowance(account1, mock.address).call()
|
||||
assert account1 == mock.functions.sender().call()
|
||||
assert 25 == mock.functions.value().call()
|
||||
assert token.address == mock.functions.tokenContract().call()
|
||||
assert 111 == web3.toInt(mock.functions.extraData().call())
|
||||
assert 111 == testerchain.interface.w3.toInt(mock.functions.extraData().call())
|
||||
|
|
|
@ -3,63 +3,63 @@ from eth_tester.exceptions import TransactionFailed
|
|||
|
||||
|
||||
@pytest.fixture()
|
||||
def token(chain):
|
||||
def token(testerchain):
|
||||
# Create an ERC20 token
|
||||
token, _ = chain.interface.deploy_contract('NuCypherToken', int(2e9))
|
||||
token, _ = testerchain.interface.deploy_contract('NuCypherToken', int(2e9))
|
||||
return token
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def escrow(web3, chain, token):
|
||||
creator = web3.eth.accounts[0]
|
||||
def escrow(testerchain, token):
|
||||
creator = testerchain.interface.w3.eth.accounts[0]
|
||||
# Creator deploys the escrow
|
||||
contract, _ = chain.interface.deploy_contract('MinersEscrowForUserEscrowMock', token.address)
|
||||
contract, _ = testerchain.interface.deploy_contract('MinersEscrowForUserEscrowMock', token.address)
|
||||
|
||||
# Give escrow some coins
|
||||
tx = token.functions.transfer(contract.address, 10000).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
return contract
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def policy_manager(chain):
|
||||
contract, _ = chain.interface.deploy_contract('PolicyManagerForUserEscrowMock')
|
||||
def policy_manager(testerchain):
|
||||
contract, _ = testerchain.interface.deploy_contract('PolicyManagerForUserEscrowMock')
|
||||
return contract
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def government(chain):
|
||||
contract, _ = chain.interface.deploy_contract('GovernmentForUserEscrowMock')
|
||||
def government(testerchain):
|
||||
contract, _ = testerchain.interface.deploy_contract('GovernmentForUserEscrowMock')
|
||||
return contract
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def user_escrow(web3, chain, token, escrow, policy_manager, government):
|
||||
creator = web3.eth.accounts[0]
|
||||
user = web3.eth.accounts[1]
|
||||
def user_escrow(testerchain, token, escrow, policy_manager, government):
|
||||
creator = testerchain.interface.w3.eth.accounts[0]
|
||||
user = testerchain.interface.w3.eth.accounts[1]
|
||||
|
||||
# Creator deploys the user escrow
|
||||
contract, _ = chain.interface.deploy_contract(
|
||||
contract, _ = testerchain.interface.deploy_contract(
|
||||
'UserEscrow', token.address, escrow.address, policy_manager.address, government.address)
|
||||
|
||||
# Transfer ownership
|
||||
tx = contract.functions.transferOwnership(user).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
return contract
|
||||
|
||||
|
||||
@pytest.mark.slow
|
||||
def test_escrow(web3, chain, token, user_escrow):
|
||||
creator = web3.eth.accounts[0]
|
||||
user = web3.eth.accounts[1]
|
||||
def test_escrow(testerchain, token, user_escrow):
|
||||
creator = testerchain.interface.w3.eth.accounts[0]
|
||||
user = testerchain.interface.w3.eth.accounts[1]
|
||||
deposits = user_escrow.events.Deposited.createFilter(fromBlock='latest')
|
||||
|
||||
# Deposit some tokens to the user escrow and lock them
|
||||
tx = token.functions.approve(user_escrow.address, 2000).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = user_escrow.functions.initialDeposit(1000, 1000).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 1000 == token.functions.balanceOf(user_escrow.address).call()
|
||||
assert user == user_escrow.functions.owner().call()
|
||||
assert 1000 >= user_escrow.functions.getLockedTokens().call()
|
||||
|
@ -75,16 +75,16 @@ def test_escrow(web3, chain, token, user_escrow):
|
|||
# Can't deposit tokens again
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = user_escrow.functions.initialDeposit(1000, 1000).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Can't withdraw before unlocking
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = user_escrow.functions.withdraw(100).transact({'from': user})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Can transfer more tokens
|
||||
tx = token.functions.transfer(user_escrow.address, 1000).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 2000 == token.functions.balanceOf(user_escrow.address).call()
|
||||
|
||||
withdraws = user_escrow.events.Withdrawn.createFilter(fromBlock='latest')
|
||||
|
@ -92,9 +92,9 @@ def test_escrow(web3, chain, token, user_escrow):
|
|||
# Only user can withdraw available tokens
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = user_escrow.functions.withdraw(100).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = user_escrow.functions.withdraw(1000).transact({'from': user})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 1000 == token.functions.balanceOf(user).call()
|
||||
assert 1000 == token.functions.balanceOf(user_escrow.address).call()
|
||||
|
||||
|
@ -105,20 +105,20 @@ def test_escrow(web3, chain, token, user_escrow):
|
|||
assert 1000 == event_args['value']
|
||||
|
||||
# Wait some time
|
||||
chain.time_travel(seconds=500)
|
||||
testerchain.time_travel(seconds=500)
|
||||
assert 1000 == user_escrow.functions.getLockedTokens().call()
|
||||
|
||||
# Can't withdraw before unlocking
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = user_escrow.functions.withdraw(100).transact({'from': user})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 1000 == token.functions.balanceOf(user).call()
|
||||
|
||||
# Wait more time and withdraw all
|
||||
chain.time_travel(seconds=500)
|
||||
testerchain.time_travel(seconds=500)
|
||||
assert 0 == user_escrow.functions.getLockedTokens().call()
|
||||
tx = user_escrow.functions.withdraw(1000).transact({'from': user})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 0 == token.functions.balanceOf(user_escrow.address).call()
|
||||
assert 2000 == token.functions.balanceOf(user).call()
|
||||
|
||||
|
@ -130,19 +130,19 @@ def test_escrow(web3, chain, token, user_escrow):
|
|||
|
||||
|
||||
@pytest.mark.slow
|
||||
def test_miner(web3, chain, token, escrow, user_escrow):
|
||||
creator = web3.eth.accounts[0]
|
||||
user = web3.eth.accounts[1]
|
||||
def test_miner(testerchain, token, escrow, user_escrow):
|
||||
creator = testerchain.interface.w3.eth.accounts[0]
|
||||
user = testerchain.interface.w3.eth.accounts[1]
|
||||
|
||||
deposits = user_escrow.events.Deposited.createFilter(fromBlock='latest')
|
||||
|
||||
# Deposit some tokens to the user escrow and lock them
|
||||
tx = token.functions.approve(user_escrow.address, 1000).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = user_escrow.functions.initialDeposit(1000, 1000).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = token.functions.transfer(user_escrow.address, 1000).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 2000 == token.functions.balanceOf(user_escrow.address).call()
|
||||
|
||||
events = deposits.get_all_entries()
|
||||
|
@ -151,17 +151,17 @@ def test_miner(web3, chain, token, escrow, user_escrow):
|
|||
# Only user can deposit tokens to the miner escrow
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = user_escrow.functions.minerDeposit(1000, 5).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
# Can't deposit more than amount in the user escrow
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = user_escrow.functions.minerDeposit(10000, 5).transact({'from': user})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
miner_deposits = user_escrow.events.DepositedAsMiner.createFilter(fromBlock='latest')
|
||||
|
||||
# Deposit some tokens to the miners escrow
|
||||
tx = user_escrow.functions.minerDeposit(1500, 5).transact({'from': user})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert user_escrow.address == escrow.functions.node().call()
|
||||
assert 1500 == escrow.functions.value().call()
|
||||
assert 1500 == escrow.functions.lockedValue().call()
|
||||
|
@ -180,27 +180,27 @@ def test_miner(web3, chain, token, escrow, user_escrow):
|
|||
# Can't withdraw because of locking
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = user_escrow.functions.withdraw(100).transact({'from': user})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Can't use the miners escrow directly
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.lock(100, 1).transact({'from': user})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.divideStake(1500, 5, 100, 1).transact({'from': user})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.confirmActivity().transact({'from': user})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.mint().transact({'from': user})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.withdraw(100).transact({'from': user})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.withdrawAll().transact({'from': user})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
locks = user_escrow.events.Locked.createFilter(fromBlock='latest')
|
||||
divides = user_escrow.events.Divided.createFilter(fromBlock='latest')
|
||||
|
@ -211,28 +211,28 @@ def test_miner(web3, chain, token, escrow, user_escrow):
|
|||
|
||||
# Use methods through the user escrow
|
||||
tx = user_escrow.functions.lock(100, 1).transact({'from': user})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 1500 == escrow.functions.value().call()
|
||||
assert 1600 == escrow.functions.lockedValue().call()
|
||||
assert 6 == escrow.functions.periods().call()
|
||||
tx = user_escrow.functions.divideStake(1600, 6, 100, 1).transact({'from': user})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 1500 == escrow.functions.value().call()
|
||||
assert 1700 == escrow.functions.lockedValue().call()
|
||||
assert 7 == escrow.functions.periods().call()
|
||||
tx = user_escrow.functions.confirmActivity().transact({'from': user})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 1 == escrow.functions.confirmedPeriod().call()
|
||||
tx = user_escrow.functions.mint().transact({'from': user})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 2500 == escrow.functions.value().call()
|
||||
tx = user_escrow.functions.minerWithdraw(1500).transact({'from': user})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 1000 == escrow.functions.value().call()
|
||||
assert 10000 == token.functions.balanceOf(escrow.address).call()
|
||||
assert 2000 == token.functions.balanceOf(user_escrow.address).call()
|
||||
tx = user_escrow.functions.minerWithdraw(1000).transact({'from': user})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 0 == escrow.functions.value().call()
|
||||
assert 9000 == token.functions.balanceOf(escrow.address).call()
|
||||
assert 3000 == token.functions.balanceOf(user_escrow.address).call()
|
||||
|
@ -275,9 +275,9 @@ def test_miner(web3, chain, token, escrow, user_escrow):
|
|||
# User can withdraw reward for mining but no more than locked
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = user_escrow.functions.withdraw(2500).transact({'from': user})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = user_escrow.functions.withdraw(1000).transact({'from': user})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 2000 == token.functions.balanceOf(user_escrow.address).call()
|
||||
assert 1000 == token.functions.balanceOf(user).call()
|
||||
|
||||
|
@ -289,45 +289,45 @@ def test_miner(web3, chain, token, escrow, user_escrow):
|
|||
|
||||
|
||||
@pytest.mark.slow
|
||||
def test_policy(web3, chain, policy_manager, user_escrow):
|
||||
creator = web3.eth.accounts[0]
|
||||
user = web3.eth.accounts[1]
|
||||
user_balance = web3.eth.getBalance(user)
|
||||
def test_policy(testerchain, policy_manager, user_escrow):
|
||||
creator = testerchain.interface.w3.eth.accounts[0]
|
||||
user = testerchain.interface.w3.eth.accounts[1]
|
||||
user_balance = testerchain.interface.w3.eth.getBalance(user)
|
||||
|
||||
# Only user can withdraw reward
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = user_escrow.functions.policyRewardWithdraw().transact({'from': creator, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = user_escrow.functions.rewardWithdraw().transact({'from': creator, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Nothing to reward
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = user_escrow.functions.policyRewardWithdraw().transact({'from': user, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = user_escrow.functions.rewardWithdraw().transact({'from': user, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert user_balance == web3.eth.getBalance(user)
|
||||
assert 0 == web3.eth.getBalance(user_escrow.address)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert user_balance == testerchain.interface.w3.eth.getBalance(user)
|
||||
assert 0 == testerchain.interface.w3.eth.getBalance(user_escrow.address)
|
||||
|
||||
# Send ETH to the policy manager as a reward for the user
|
||||
tx = web3.eth.sendTransaction({'from': web3.eth.coinbase, 'to': policy_manager.address, 'value': 10000})
|
||||
chain.wait_for_receipt(tx)
|
||||
tx = testerchain.interface.w3.eth.sendTransaction({'from': testerchain.interface.w3.eth.coinbase, 'to': policy_manager.address, 'value': 10000})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
miner_collections = user_escrow.events.RewardWithdrawnAsMiner.createFilter(fromBlock='latest')
|
||||
rewards = user_escrow.events.RewardWithdrawn.createFilter(fromBlock='latest')
|
||||
|
||||
# Withdraw reward reward
|
||||
tx = user_escrow.functions.policyRewardWithdraw().transact({'from': user, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert user_balance == web3.eth.getBalance(user)
|
||||
assert 10000 == web3.eth.getBalance(user_escrow.address)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert user_balance == testerchain.interface.w3.eth.getBalance(user)
|
||||
assert 10000 == testerchain.interface.w3.eth.getBalance(user_escrow.address)
|
||||
tx = user_escrow.functions.rewardWithdraw().transact({'from': user, 'gas_price': 0})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert user_balance + 10000 == web3.eth.getBalance(user)
|
||||
assert 0 == web3.eth.getBalance(user_escrow.address)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert user_balance + 10000 == testerchain.interface.w3.eth.getBalance(user)
|
||||
assert 0 == testerchain.interface.w3.eth.getBalance(user_escrow.address)
|
||||
|
||||
events = miner_collections.get_all_entries()
|
||||
|
||||
|
@ -346,9 +346,9 @@ def test_policy(web3, chain, policy_manager, user_escrow):
|
|||
min_reward_sets = user_escrow.events.MinRewardRateSet.createFilter(fromBlock='latest')
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = user_escrow.functions.setMinRewardRate(333).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = user_escrow.functions.setMinRewardRate(222).transact({'from': user})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 222 == policy_manager.functions.minRewardRate().call()
|
||||
|
||||
events = min_reward_sets.get_all_entries()
|
||||
|
@ -359,24 +359,24 @@ def test_policy(web3, chain, policy_manager, user_escrow):
|
|||
|
||||
|
||||
@pytest.mark.slow
|
||||
def test_government(web3, chain, government, user_escrow):
|
||||
creator = web3.eth.accounts[0]
|
||||
user = web3.eth.accounts[1]
|
||||
def test_government(testerchain, government, user_escrow):
|
||||
creator = testerchain.interface.w3.eth.accounts[0]
|
||||
user = testerchain.interface.w3.eth.accounts[1]
|
||||
votes = user_escrow.events.Voted.createFilter(fromBlock='latest')
|
||||
|
||||
# Only user can vote
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = user_escrow.functions.vote(True).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = user_escrow.functions.vote(False).transact({'from': creator})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
tx = user_escrow.functions.vote(True).transact({'from': user})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert government.functions.voteFor().call()
|
||||
tx = user_escrow.functions.vote(False).transact({'from': user})
|
||||
chain.wait_for_receipt(tx)
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert not government.functions.voteFor().call()
|
||||
|
||||
events = votes.get_all_entries()
|
||||
|
|
|
@ -15,9 +15,9 @@ from web3.middleware import geth_poa_middleware
|
|||
|
||||
from nucypher.blockchain.eth.agents import NucypherTokenAgent, MinerAgent
|
||||
from nucypher.blockchain.eth.deployers import PolicyManagerDeployer, NucypherTokenDeployer, MinerEscrowDeployer
|
||||
from nucypher.blockchain.eth.interfaces import Registrar
|
||||
from nucypher.blockchain.eth.interfaces import EthereumContractRegistrar
|
||||
from nucypher.blockchain.eth.sol.compile import SolidityCompiler
|
||||
from nucypher.config.configs import BlockchainConfig
|
||||
from nucypher.config.configs import BlockchainConfiguration
|
||||
from tests.blockchain.eth import contracts, utilities
|
||||
from tests.blockchain.eth.utilities import MockMinerEscrowDeployer, TesterPyEVMBackend, MockNucypherTokenDeployer
|
||||
|
||||
|
@ -129,15 +129,15 @@ def solidity_compiler():
|
|||
@pytest.fixture(scope='module')
|
||||
def registrar():
|
||||
_, filepath = tempfile.mkstemp()
|
||||
test_registrar = Registrar(chain_name='tester', registrar_filepath=filepath)
|
||||
test_registrar = EthereumContractRegistrar(chain_name='tester', registrar_filepath=filepath)
|
||||
yield test_registrar
|
||||
os.remove(filepath)
|
||||
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
def blockchain_config(pyevm_provider, solidity_compiler, registrar):
|
||||
BlockchainConfig.add_provider(pyevm_provider)
|
||||
config = BlockchainConfig(compiler=solidity_compiler, registrar=registrar, deploy=True, tester=True) # TODO: pass in address
|
||||
BlockchainConfiguration.add_provider(pyevm_provider)
|
||||
config = BlockchainConfiguration(compiler=solidity_compiler, registrar=registrar, deploy=True, tester=True) # TODO: pass in address
|
||||
yield config
|
||||
config.chain.sever()
|
||||
del config
|
||||
|
|
|
@ -10,22 +10,23 @@ from sqlalchemy.engine import create_engine
|
|||
from nucypher.blockchain.eth.chains import Blockchain
|
||||
from nucypher.characters import Alice, Bob
|
||||
|
||||
from nucypher.config.configs import NucypherConfig
|
||||
from nucypher.config.configs import NucypherConfiguration
|
||||
|
||||
from nucypher.data_sources import DataSource
|
||||
from nucypher.keystore import keystore
|
||||
from nucypher.keystore.db import Base
|
||||
from nucypher.keystore.keypairs import SigningKeypair
|
||||
from tests.utilities import NUMBER_OF_URSULAS_IN_NETWORK, MockNetworkMiddleware, make_ursulas, URSULA_PORT, EVENT_LOOP
|
||||
from tests.utilities import MockNetworkMiddleware, make_ursulas, EVENT_LOOP
|
||||
from constant_sorrow import constants
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def nucypher_test_config(blockchain_config):
|
||||
|
||||
config = NucypherConfig(keyring="this is a faked keyring object",
|
||||
config = NucypherConfiguration(keyring="this is a faked keyring object",
|
||||
blockchain_config=blockchain_config)
|
||||
yield config
|
||||
NucypherConfig.reset()
|
||||
NucypherConfiguration.reset()
|
||||
Blockchain.sever()
|
||||
del config
|
||||
|
||||
|
@ -36,7 +37,7 @@ def idle_policy(alice, bob):
|
|||
Creates a Policy, in a manner typical of how Alice might do it, with a unique uri (soon to be "label" - see #183)
|
||||
"""
|
||||
alice.__resource_id += b"/unique-again" # A unique name each time, like a path.
|
||||
n = NUMBER_OF_URSULAS_IN_NETWORK
|
||||
n = constants.NUMBER_OF_URSULAS_IN_NETWORK
|
||||
|
||||
policy = alice.create_policy(
|
||||
bob,
|
||||
|
|
|
@ -4,7 +4,7 @@ from typing import List
|
|||
from apistar.test import TestClient
|
||||
|
||||
from nucypher.characters import Ursula
|
||||
from nucypher.config.configs import NucypherConfig
|
||||
from nucypher.config.configs import NucypherConfiguration
|
||||
from nucypher.network.middleware import NetworkMiddleware
|
||||
from nucypher.policy.models import ArrangementResponse
|
||||
from constant_sorrow import constants
|
||||
|
@ -21,7 +21,7 @@ constants.URSULA_PORT(7468)
|
|||
constants.NUMBER_OF_URSULAS_IN_NETWORK(6)
|
||||
|
||||
|
||||
def make_ursulas(ether_addresses: list, ursula_starting_port: int, config: NucypherConfig) -> List[Ursula]:
|
||||
def make_ursulas(ether_addresses: list, ursula_starting_port: int, config: NucypherConfiguration) -> List[Ursula]:
|
||||
"""
|
||||
:param how_many_ursulas: How many Ursulas to create.
|
||||
:param ursula_starting_port: The port of the first created Ursula; subsequent Ursulas will increment the port number by 1.
|
||||
|
|
Loading…
Reference in New Issue