mirror of https://github.com/nucypher/nucypher.git
Respond to RFCs: Code Style and Readability Improvements
parent
9f32f76942
commit
0c7c5a92a8
|
@ -75,7 +75,7 @@ class AnalyzeGas:
|
|||
|
||||
@staticmethod
|
||||
def paint_line(label: str, gas: str) -> None:
|
||||
print('{label} {dots} {gas:,}'.format(label=label, dots='.' * (65 - len(label)), gas=int(gas)))
|
||||
print('{label} {gas:,}'.format(label=label.ljust(65, '.'), gas=int(gas)))
|
||||
|
||||
def to_json_file(self) -> None:
|
||||
print('Saving JSON Output...')
|
||||
|
@ -144,6 +144,10 @@ def estimate_gas(analyzer: AnalyzeGas) -> AnalyzeGas:
|
|||
web3 = testerchain.interface.w3
|
||||
|
||||
token_agent, miner_agent, policy_agent = analyzer.connect_to_contracts(testerchain=testerchain)
|
||||
token_functions = token_agent.contract.functions
|
||||
miner_functions = miner_agent.contract.functions
|
||||
policy_functions = policy_agent.contract.functions
|
||||
|
||||
log.info("Running with provider URI: {}".format(testerchain.interface.provider_uri))
|
||||
|
||||
analyzer.start_collection()
|
||||
|
@ -156,383 +160,393 @@ def estimate_gas(analyzer: AnalyzeGas) -> AnalyzeGas:
|
|||
|
||||
print("********* Estimating Gas *********")
|
||||
|
||||
#
|
||||
# Pre deposit tokens
|
||||
tx = token_agent.contract.functions.approve(miner_agent.contract_address, MIN_ALLOWED_LOCKED * 5).transact({'from': origin})
|
||||
#
|
||||
tx = token_functions.approve(miner_agent.contract_address, MIN_ALLOWED_LOCKED * 5).transact({'from': origin})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
log.info("Pre-deposit tokens for 5 owners = " +
|
||||
str(miner_agent.contract.functions
|
||||
.preDeposit(everyone_else[0:5],
|
||||
[MIN_ALLOWED_LOCKED] * 5,
|
||||
[MIN_LOCKED_PERIODS] * 5)
|
||||
.estimateGas({'from': origin})))
|
||||
log.info("Pre-deposit tokens for 5 owners = " + str(miner_functions.preDeposit(everyone_else[0:5],
|
||||
[MIN_ALLOWED_LOCKED] * 5,
|
||||
[MIN_LOCKED_PERIODS] * 5)
|
||||
.estimateGas({'from': origin})))
|
||||
|
||||
#
|
||||
# Give Ursula and Alice some coins
|
||||
log.info("Transfer tokens = " +
|
||||
str(token_agent.contract.functions.transfer(ursula1, MIN_ALLOWED_LOCKED * 10)
|
||||
.estimateGas({'from': origin})))
|
||||
tx = token_agent.contract.functions.transfer(ursula1, MIN_ALLOWED_LOCKED * 10).transact({'from': origin})
|
||||
#
|
||||
log.info("Transfer tokens = " + str(token_functions.transfer(ursula1, MIN_ALLOWED_LOCKED * 10).estimateGas({'from': origin})))
|
||||
tx = token_functions.transfer(ursula1, MIN_ALLOWED_LOCKED * 10).transact({'from': origin})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = token_agent.contract.functions.transfer(ursula2, MIN_ALLOWED_LOCKED * 10).transact({'from': origin})
|
||||
tx = token_functions.transfer(ursula2, MIN_ALLOWED_LOCKED * 10).transact({'from': origin})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = token_agent.contract.functions.transfer(ursula3, MIN_ALLOWED_LOCKED * 10).transact({'from': origin})
|
||||
tx = token_functions.transfer(ursula3, MIN_ALLOWED_LOCKED * 10).transact({'from': origin})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
#
|
||||
# Ursula and Alice give Escrow rights to transfer
|
||||
log.info("Approving transfer = " +
|
||||
str(token_agent.contract.functions.approve(miner_agent.contract_address, MIN_ALLOWED_LOCKED * 6)
|
||||
.estimateGas({'from': ursula1})))
|
||||
tx = token_agent.contract.functions.approve(miner_agent.contract_address, MIN_ALLOWED_LOCKED * 6)\
|
||||
.transact({'from': ursula1})
|
||||
#
|
||||
log.info("Approving transfer = "
|
||||
+ str(token_functions.approve(miner_agent.contract_address, MIN_ALLOWED_LOCKED * 6).estimateGas({'from': ursula1})))
|
||||
tx = token_functions.approve(miner_agent.contract_address, MIN_ALLOWED_LOCKED * 6).transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = token_agent.contract.functions.approve(miner_agent.contract_address, MIN_ALLOWED_LOCKED * 6)\
|
||||
.transact({'from': ursula2})
|
||||
tx = token_functions.approve(miner_agent.contract_address, MIN_ALLOWED_LOCKED * 6).transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = token_agent.contract.functions.approve(miner_agent.contract_address, MIN_ALLOWED_LOCKED * 6)\
|
||||
.transact({'from': ursula3})
|
||||
tx = token_functions.approve(miner_agent.contract_address, MIN_ALLOWED_LOCKED * 6).transact({'from': ursula3})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
#
|
||||
# Ursula and Alice transfer some tokens to the escrow and lock them
|
||||
#
|
||||
log.info("First initial deposit tokens = " +
|
||||
str(miner_agent.contract.functions.deposit(MIN_ALLOWED_LOCKED * 3, MIN_LOCKED_PERIODS).estimateGas({'from': ursula1})))
|
||||
tx = miner_agent.contract.functions.deposit(MIN_ALLOWED_LOCKED * 3, MIN_LOCKED_PERIODS).transact({'from': ursula1})
|
||||
str(miner_functions.deposit(MIN_ALLOWED_LOCKED * 3, MIN_LOCKED_PERIODS).estimateGas({'from': ursula1})))
|
||||
tx = miner_functions.deposit(MIN_ALLOWED_LOCKED * 3, MIN_LOCKED_PERIODS).transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
log.info("Second initial deposit tokens = " +
|
||||
str(miner_agent.contract.functions.deposit(MIN_ALLOWED_LOCKED * 3, MIN_LOCKED_PERIODS).estimateGas({'from': ursula2})))
|
||||
tx = miner_agent.contract.functions.deposit(MIN_ALLOWED_LOCKED * 3, MIN_LOCKED_PERIODS).transact({'from': ursula2})
|
||||
str(miner_functions.deposit(MIN_ALLOWED_LOCKED * 3, MIN_LOCKED_PERIODS).estimateGas({'from': ursula2})))
|
||||
tx = miner_functions.deposit(MIN_ALLOWED_LOCKED * 3, MIN_LOCKED_PERIODS).transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
log.info("Third initial deposit tokens = " +
|
||||
str(miner_agent.contract.functions.deposit(MIN_ALLOWED_LOCKED * 3, MIN_LOCKED_PERIODS).estimateGas({'from': ursula3})))
|
||||
tx = miner_agent.contract.functions.deposit(MIN_ALLOWED_LOCKED * 3, MIN_LOCKED_PERIODS).transact({'from': ursula3})
|
||||
str(miner_functions.deposit(MIN_ALLOWED_LOCKED * 3, MIN_LOCKED_PERIODS).estimateGas({'from': ursula3})))
|
||||
tx = miner_functions.deposit(MIN_ALLOWED_LOCKED * 3, MIN_LOCKED_PERIODS).transact({'from': ursula3})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
#
|
||||
# Wait 1 period and confirm activity
|
||||
#
|
||||
testerchain.time_travel(periods=1)
|
||||
log.info("First confirm activity = " +
|
||||
str(miner_agent.contract.functions.confirmActivity().estimateGas({'from': ursula1})))
|
||||
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula1})
|
||||
str(miner_functions.confirmActivity().estimateGas({'from': ursula1})))
|
||||
tx = miner_functions.confirmActivity().transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
log.info("Second confirm activity = " +
|
||||
str(miner_agent.contract.functions.confirmActivity().estimateGas({'from': ursula2})))
|
||||
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula2})
|
||||
str(miner_functions.confirmActivity().estimateGas({'from': ursula2})))
|
||||
tx = miner_functions.confirmActivity().transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
log.info("Third confirm activity = " +
|
||||
str(miner_agent.contract.functions.confirmActivity().estimateGas({'from': ursula3})))
|
||||
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula3})
|
||||
str(miner_functions.confirmActivity().estimateGas({'from': ursula3})))
|
||||
tx = miner_functions.confirmActivity().transact({'from': ursula3})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
#
|
||||
# Wait 1 period and mint tokens
|
||||
#
|
||||
testerchain.time_travel(periods=1)
|
||||
log.info("First mining (1 stake) = " + str(miner_agent.contract.functions.mint().estimateGas({'from': ursula1})))
|
||||
tx = miner_agent.contract.functions.mint().transact({'from': ursula1})
|
||||
log.info("First mining (1 stake) = " + str(miner_functions.mint().estimateGas({'from': ursula1})))
|
||||
tx = miner_functions.mint().transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
log.info("Second mining (1 stake) = " + str(miner_agent.contract.functions.mint().estimateGas({'from': ursula2})))
|
||||
tx = miner_agent.contract.functions.mint().transact({'from': ursula2})
|
||||
log.info("Second mining (1 stake) = " + str(miner_functions.mint().estimateGas({'from': ursula2})))
|
||||
tx = miner_functions.mint().transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
log.info("Third/last mining (1 stake) = " + str(miner_agent.contract.functions.mint().estimateGas({'from': ursula3})))
|
||||
tx = miner_agent.contract.functions.mint().transact({'from': ursula3})
|
||||
log.info("Third/last mining (1 stake) = " + str(miner_functions.mint().estimateGas({'from': ursula3})))
|
||||
tx = miner_functions.mint().transact({'from': ursula3})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
log.info("First confirm activity again = " +
|
||||
str(miner_agent.contract.functions.confirmActivity().estimateGas({'from': ursula1})))
|
||||
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula1})
|
||||
str(miner_functions.confirmActivity().estimateGas({'from': ursula1})))
|
||||
tx = miner_functions.confirmActivity().transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
log.info("Second confirm activity again = " +
|
||||
str(miner_agent.contract.functions.confirmActivity().estimateGas({'from': ursula2})))
|
||||
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula2})
|
||||
str(miner_functions.confirmActivity().estimateGas({'from': ursula2})))
|
||||
tx = miner_functions.confirmActivity().transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
log.info("Third confirm activity again = " +
|
||||
str(miner_agent.contract.functions.confirmActivity().estimateGas({'from': ursula3})))
|
||||
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula3})
|
||||
str(miner_functions.confirmActivity().estimateGas({'from': ursula3})))
|
||||
tx = miner_functions.confirmActivity().transact({'from': ursula3})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
#
|
||||
# Confirm again
|
||||
#
|
||||
testerchain.time_travel(periods=1)
|
||||
log.info("First confirm activity + mint = " +
|
||||
str(miner_agent.contract.functions.confirmActivity().estimateGas({'from': ursula1})))
|
||||
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula1})
|
||||
str(miner_functions.confirmActivity().estimateGas({'from': ursula1})))
|
||||
tx = miner_functions.confirmActivity().transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
log.info("Second confirm activity + mint = " +
|
||||
str(miner_agent.contract.functions.confirmActivity().estimateGas({'from': ursula2})))
|
||||
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula2})
|
||||
str(miner_functions.confirmActivity().estimateGas({'from': ursula2})))
|
||||
tx = miner_functions.confirmActivity().transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
log.info("Third confirm activity + mint = " +
|
||||
str(miner_agent.contract.functions.confirmActivity().estimateGas({'from': ursula3})))
|
||||
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula3})
|
||||
str(miner_functions.confirmActivity().estimateGas({'from': ursula3})))
|
||||
tx = miner_functions.confirmActivity().transact({'from': ursula3})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
#
|
||||
# Get locked tokens
|
||||
log.info("Getting locked tokens = " + str(miner_agent.contract.functions.getLockedTokens(ursula1).estimateGas()))
|
||||
#
|
||||
log.info("Getting locked tokens = " + str(miner_functions.getLockedTokens(ursula1).estimateGas()))
|
||||
|
||||
#
|
||||
# Wait 1 period and withdraw tokens
|
||||
#
|
||||
testerchain.time_travel(periods=1)
|
||||
log.info("First withdraw = " + str(miner_agent.contract.functions.withdraw(1).estimateGas({'from': ursula1})))
|
||||
tx = miner_agent.contract.functions.withdraw(1).transact({'from': ursula1})
|
||||
log.info("First withdraw = " + str(miner_functions.withdraw(1).estimateGas({'from': ursula1})))
|
||||
tx = miner_functions.withdraw(1).transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
log.info("Second withdraw = " + str(miner_agent.contract.functions.withdraw(1).estimateGas({'from': ursula2})))
|
||||
tx = miner_agent.contract.functions.withdraw(1).transact({'from': ursula2})
|
||||
log.info("Second withdraw = " + str(miner_functions.withdraw(1).estimateGas({'from': ursula2})))
|
||||
tx = miner_functions.withdraw(1).transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
log.info("Third withdraw = " + str(miner_agent.contract.functions.withdraw(1).estimateGas({'from': ursula3})))
|
||||
tx = miner_agent.contract.functions.withdraw(1).transact({'from': ursula3})
|
||||
log.info("Third withdraw = " + str(miner_functions.withdraw(1).estimateGas({'from': ursula3})))
|
||||
tx = miner_functions.withdraw(1).transact({'from': ursula3})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
#
|
||||
# Wait 1 period and confirm activity
|
||||
#
|
||||
testerchain.time_travel(periods=1)
|
||||
log.info("First confirm activity after downtime = " +
|
||||
str(miner_agent.contract.functions.confirmActivity().estimateGas({'from': ursula1})))
|
||||
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula1})
|
||||
str(miner_functions.confirmActivity().estimateGas({'from': ursula1})))
|
||||
tx = miner_functions.confirmActivity().transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
log.info("Second confirm activity after downtime = " +
|
||||
str(miner_agent.contract.functions.confirmActivity().estimateGas({'from': ursula2})))
|
||||
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula2})
|
||||
str(miner_functions.confirmActivity().estimateGas({'from': ursula2})))
|
||||
tx = miner_functions.confirmActivity().transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
log.info("Third confirm activity after downtime = " +
|
||||
str(miner_agent.contract.functions.confirmActivity().estimateGas({'from': ursula3})))
|
||||
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula3})
|
||||
str(miner_functions.confirmActivity().estimateGas({'from': ursula3})))
|
||||
tx = miner_functions.confirmActivity().transact({'from': ursula3})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
#
|
||||
# Ursula and Alice deposit some tokens to the escrow again
|
||||
#
|
||||
log.info("First deposit tokens again = " +
|
||||
str(miner_agent.contract.functions.deposit(MIN_ALLOWED_LOCKED * 2, MIN_LOCKED_PERIODS).estimateGas({'from': ursula1})))
|
||||
tx = miner_agent.contract.functions.deposit(MIN_ALLOWED_LOCKED * 2, MIN_LOCKED_PERIODS).transact({'from': ursula1})
|
||||
str(miner_functions.deposit(MIN_ALLOWED_LOCKED * 2, MIN_LOCKED_PERIODS).estimateGas({'from': ursula1})))
|
||||
tx = miner_functions.deposit(MIN_ALLOWED_LOCKED * 2, MIN_LOCKED_PERIODS).transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
log.info("Second deposit tokens again = " +
|
||||
str(miner_agent.contract.functions.deposit(MIN_ALLOWED_LOCKED * 2, MIN_LOCKED_PERIODS).estimateGas({'from': ursula2})))
|
||||
tx = miner_agent.contract.functions.deposit(MIN_ALLOWED_LOCKED * 2, MIN_LOCKED_PERIODS).transact({'from': ursula2})
|
||||
str(miner_functions.deposit(MIN_ALLOWED_LOCKED * 2, MIN_LOCKED_PERIODS).estimateGas({'from': ursula2})))
|
||||
tx = miner_functions.deposit(MIN_ALLOWED_LOCKED * 2, MIN_LOCKED_PERIODS).transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
log.info("Third deposit tokens again = " +
|
||||
str(miner_agent.contract.functions.deposit(MIN_ALLOWED_LOCKED * 2, MIN_LOCKED_PERIODS).estimateGas({'from': ursula3})))
|
||||
tx = miner_agent.contract.functions.deposit(MIN_ALLOWED_LOCKED * 2, MIN_LOCKED_PERIODS).transact({'from': ursula3})
|
||||
str(miner_functions.deposit(MIN_ALLOWED_LOCKED * 2, MIN_LOCKED_PERIODS).estimateGas({'from': ursula3})))
|
||||
tx = miner_functions.deposit(MIN_ALLOWED_LOCKED * 2, MIN_LOCKED_PERIODS).transact({'from': ursula3})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
#
|
||||
# Wait 1 period and mint tokens
|
||||
#
|
||||
testerchain.time_travel(periods=1)
|
||||
log.info("First mining again = " + str(miner_agent.contract.functions.mint().estimateGas({'from': ursula1})))
|
||||
tx = miner_agent.contract.functions.mint().transact({'from': ursula1})
|
||||
log.info("First mining again = " + str(miner_functions.mint().estimateGas({'from': ursula1})))
|
||||
tx = miner_functions.mint().transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
log.info("Second mining again = " + str(miner_agent.contract.functions.mint().estimateGas({'from': ursula2})))
|
||||
tx = miner_agent.contract.functions.mint().transact({'from': ursula2})
|
||||
log.info("Second mining again = " + str(miner_functions.mint().estimateGas({'from': ursula2})))
|
||||
tx = miner_functions.mint().transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
log.info("Third/last mining again = " + str(miner_agent.contract.functions.mint().estimateGas({'from': ursula3})))
|
||||
tx = miner_agent.contract.functions.mint().transact({'from': ursula3})
|
||||
log.info("Third/last mining again = " + str(miner_functions.mint().estimateGas({'from': ursula3})))
|
||||
tx = miner_functions.mint().transact({'from': ursula3})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
#
|
||||
# Create policy
|
||||
#
|
||||
policy_id_1 = os.urandom(int(POLICY_ID_LENGTH))
|
||||
policy_id_2 = os.urandom(int(POLICY_ID_LENGTH))
|
||||
number_of_periods = 10
|
||||
log.info("First creating policy (1 node, 10 periods) = " +
|
||||
str(policy_agent.contract.functions.createPolicy(policy_id_1, number_of_periods, 0, [ursula1])
|
||||
.estimateGas({'from': alice1, 'value': 10000})))
|
||||
tx = policy_agent.contract.functions.createPolicy(policy_id_1, number_of_periods, 0, [ursula1])\
|
||||
.transact({'from': alice1, 'value': 10000})
|
||||
str(policy_functions.createPolicy(policy_id_1, number_of_periods, 0, [ursula1]).estimateGas({'from': alice1, 'value': 10000})))
|
||||
tx = policy_functions.createPolicy(policy_id_1, number_of_periods, 0, [ursula1]).transact({'from': alice1, 'value': 10000})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
log.info("Second creating policy (1 node, 10 periods) = " +
|
||||
str(policy_agent.contract.functions.createPolicy(policy_id_2, number_of_periods, 0, [ursula1])
|
||||
.estimateGas({'from': alice1, 'value': 10000})))
|
||||
tx = policy_agent.contract.functions.createPolicy(policy_id_2, number_of_periods, 0, [ursula1])\
|
||||
.transact({'from': alice1, 'value': 10000})
|
||||
str(policy_functions.createPolicy(policy_id_2, number_of_periods, 0, [ursula1]).estimateGas({'from': alice1, 'value': 10000})))
|
||||
tx = policy_functions.createPolicy(policy_id_2, number_of_periods, 0, [ursula1]).transact({'from': alice1, 'value': 10000})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
#
|
||||
# Revoke policy
|
||||
log.info("Revoking policy = " +
|
||||
str(policy_agent.contract.functions.revokePolicy(policy_id_1).estimateGas({'from': alice1})))
|
||||
tx = policy_agent.contract.functions.revokePolicy(policy_id_1).transact({'from': alice1})
|
||||
#
|
||||
log.info("Revoking policy = " + str(policy_functions.revokePolicy(policy_id_1).estimateGas({'from': alice1})))
|
||||
tx = policy_functions.revokePolicy(policy_id_1).transact({'from': alice1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = policy_agent.contract.functions.revokePolicy(policy_id_2).transact({'from': alice1})
|
||||
tx = policy_functions.revokePolicy(policy_id_2).transact({'from': alice1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
#
|
||||
# Create policy with more periods
|
||||
#
|
||||
policy_id_1 = os.urandom(int(POLICY_ID_LENGTH))
|
||||
policy_id_2 = os.urandom(int(POLICY_ID_LENGTH))
|
||||
policy_id_3 = os.urandom(int(POLICY_ID_LENGTH))
|
||||
number_of_periods = 100
|
||||
log.info("First creating policy (1 node, " + str(number_of_periods) + " periods, first reward) = " +
|
||||
str(policy_agent.contract.functions.createPolicy(policy_id_1, number_of_periods, 50, [ursula2])
|
||||
.estimateGas({'from': alice1, 'value': 10050})))
|
||||
tx = policy_agent.contract.functions.createPolicy(policy_id_1, number_of_periods, 50, [ursula2])\
|
||||
.transact({'from': alice1, 'value': 10050})
|
||||
str(policy_functions.createPolicy(policy_id_1, number_of_periods, 50, [ursula2]).estimateGas({'from': alice1, 'value': 10050})))
|
||||
tx = policy_functions.createPolicy(policy_id_1, number_of_periods, 50, [ursula2]).transact({'from': alice1, 'value': 10050})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(periods=1)
|
||||
log.info("Second creating policy (1 node, " + str(number_of_periods) + " periods, first reward) = " +
|
||||
str(policy_agent.contract.functions.createPolicy(policy_id_2, number_of_periods, 50, [ursula2])
|
||||
.estimateGas({'from': alice1, 'value': 10050})))
|
||||
tx = policy_agent.contract.functions.createPolicy(policy_id_2, number_of_periods, 50, [ursula2])\
|
||||
.transact({'from': alice1, 'value': 10050})
|
||||
str(policy_functions.createPolicy(policy_id_2, number_of_periods, 50, [ursula2]).estimateGas({'from': alice1, 'value': 10050})))
|
||||
tx = policy_functions.createPolicy(policy_id_2, number_of_periods, 50, [ursula2]).transact({'from': alice1, 'value': 10050})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
log.info("Third creating policy (1 node, " + str(number_of_periods) + " periods, first reward) = " +
|
||||
str(policy_agent.contract.functions.createPolicy(policy_id_3, number_of_periods, 50, [ursula1])
|
||||
.estimateGas({'from': alice1, 'value': 10050})))
|
||||
tx = policy_agent.contract.functions.createPolicy(policy_id_3, number_of_periods, 50, [ursula1])\
|
||||
.transact({'from': alice1, 'value': 10050})
|
||||
str(policy_functions.createPolicy(policy_id_3, number_of_periods, 50, [ursula1]).estimateGas({'from': alice1, 'value': 10050})))
|
||||
tx = policy_functions.createPolicy(policy_id_3, number_of_periods, 50, [ursula1]).transact({'from': alice1, 'value': 10050})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
#
|
||||
# Mine and revoke policy
|
||||
#
|
||||
testerchain.time_travel(periods=10)
|
||||
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula2})
|
||||
tx = miner_functions.confirmActivity().transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula1})
|
||||
tx = miner_functions.confirmActivity().transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
testerchain.time_travel(periods=1)
|
||||
log.info("First mining after downtime = " + str(miner_agent.contract.functions.mint().estimateGas({'from': ursula1})))
|
||||
tx = miner_agent.contract.functions.mint().transact({'from': ursula1})
|
||||
log.info("First mining after downtime = " + str(miner_functions.mint().estimateGas({'from': ursula1})))
|
||||
tx = miner_functions.mint().transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
log.info("Second mining after downtime = " + str(miner_agent.contract.functions.mint().estimateGas({'from': ursula2})))
|
||||
tx = miner_agent.contract.functions.mint().transact({'from': ursula2})
|
||||
log.info("Second mining after downtime = " + str(miner_functions.mint().estimateGas({'from': ursula2})))
|
||||
tx = miner_functions.mint().transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
testerchain.time_travel(periods=10)
|
||||
log.info("First revoking policy after downtime = " +
|
||||
str(policy_agent.contract.functions.revokePolicy(policy_id_1).estimateGas({'from': alice1})))
|
||||
tx = policy_agent.contract.functions.revokePolicy(policy_id_1).transact({'from': alice1})
|
||||
str(policy_functions.revokePolicy(policy_id_1).estimateGas({'from': alice1})))
|
||||
tx = policy_functions.revokePolicy(policy_id_1).transact({'from': alice1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
log.info("Second revoking policy after downtime = " +
|
||||
str(policy_agent.contract.functions.revokePolicy(policy_id_2).estimateGas({'from': alice1})))
|
||||
tx = policy_agent.contract.functions.revokePolicy(policy_id_2).transact({'from': alice1})
|
||||
str(policy_functions.revokePolicy(policy_id_2).estimateGas({'from': alice1})))
|
||||
tx = policy_functions.revokePolicy(policy_id_2).transact({'from': alice1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
log.info("Second revoking policy after downtime = " +
|
||||
str(policy_agent.contract.functions.revokePolicy(policy_id_3).estimateGas({'from': alice1})))
|
||||
tx = policy_agent.contract.functions.revokePolicy(policy_id_3).transact({'from': alice1})
|
||||
str(policy_functions.revokePolicy(policy_id_3).estimateGas({'from': alice1})))
|
||||
tx = policy_functions.revokePolicy(policy_id_3).transact({'from': alice1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
#
|
||||
# Create policy with multiple nodes
|
||||
#
|
||||
policy_id_1 = os.urandom(int(POLICY_ID_LENGTH))
|
||||
policy_id_2 = os.urandom(int(POLICY_ID_LENGTH))
|
||||
policy_id_3 = os.urandom(int(POLICY_ID_LENGTH))
|
||||
number_of_periods = 100
|
||||
log.info("First creating policy (3 nodes, 100 periods, first reward) = " +
|
||||
str(policy_agent.contract.functions
|
||||
.createPolicy(policy_id_1, number_of_periods, 50, [ursula1, ursula2, ursula3])
|
||||
.estimateGas({'from': alice1, 'value': 30150})))
|
||||
tx = policy_agent.contract.functions.createPolicy(policy_id_1, number_of_periods, 50, [ursula1, ursula2, ursula3])\
|
||||
.transact({'from': alice1, 'value': 30150})
|
||||
str(policy_functions
|
||||
.createPolicy(policy_id_1, number_of_periods, 50, [ursula1, ursula2, ursula3])
|
||||
.estimateGas({'from': alice1, 'value': 30150})))
|
||||
tx = policy_functions.createPolicy(policy_id_1, number_of_periods, 50, [ursula1, ursula2, ursula3]).transact({'from': alice1, 'value': 30150})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
log.info("Second creating policy (3 nodes, 100 periods, first reward) = " +
|
||||
str(policy_agent.contract.functions
|
||||
.createPolicy(policy_id_2, number_of_periods, 50, [ursula1, ursula2, ursula3])
|
||||
.estimateGas({'from': alice1, 'value': 30150})))
|
||||
tx = policy_agent.contract.functions.createPolicy(policy_id_2, number_of_periods, 50, [ursula1, ursula2, ursula3])\
|
||||
.transact({'from': alice1, 'value': 30150})
|
||||
str(policy_functions
|
||||
.createPolicy(policy_id_2, number_of_periods, 50, [ursula1, ursula2, ursula3])
|
||||
.estimateGas({'from': alice1, 'value': 30150})))
|
||||
tx = policy_functions.createPolicy(policy_id_2, number_of_periods, 50, [ursula1, ursula2, ursula3]).transact({'from': alice1, 'value': 30150})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
log.info("Third creating policy (2 nodes, 100 periods, first reward) = " +
|
||||
str(policy_agent.contract.functions.createPolicy(policy_id_3, number_of_periods, 50, [ursula1, ursula2])
|
||||
.estimateGas({'from': alice1, 'value': 20100})))
|
||||
tx = policy_agent.contract.functions.createPolicy(policy_id_3, number_of_periods, 50, [ursula1, ursula2])\
|
||||
.transact({'from': alice1, 'value': 20100})
|
||||
str(policy_functions.createPolicy(policy_id_3, number_of_periods, 50, [ursula1, ursula2]).estimateGas({'from': alice1, 'value': 20100})))
|
||||
tx = policy_functions.createPolicy(policy_id_3, number_of_periods, 50, [ursula1, ursula2]).transact({'from': alice1, 'value': 20100})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
for index in range(5):
|
||||
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula1})
|
||||
tx = miner_functions.confirmActivity().transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula2})
|
||||
tx = miner_functions.confirmActivity().transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula3})
|
||||
tx = miner_functions.confirmActivity().transact({'from': ursula3})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(periods=1)
|
||||
|
||||
tx = miner_agent.contract.functions.mint().transact({'from': ursula1})
|
||||
tx = miner_functions.mint().transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = miner_agent.contract.functions.mint().transact({'from': ursula2})
|
||||
tx = miner_functions.mint().transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = miner_agent.contract.functions.mint().transact({'from': ursula3})
|
||||
tx = miner_functions.mint().transact({'from': ursula3})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
#
|
||||
# Check regular deposit
|
||||
log.info("First deposit tokens = " + str(miner_agent.contract.functions.deposit(MIN_ALLOWED_LOCKED, MIN_LOCKED_PERIODS).estimateGas({'from': ursula1})))
|
||||
tx = miner_agent.contract.functions.deposit(MIN_ALLOWED_LOCKED, MIN_LOCKED_PERIODS).transact({'from': ursula1})
|
||||
#
|
||||
log.info("First deposit tokens = " + str(miner_functions.deposit(MIN_ALLOWED_LOCKED, MIN_LOCKED_PERIODS).estimateGas({'from': ursula1})))
|
||||
tx = miner_functions.deposit(MIN_ALLOWED_LOCKED, MIN_LOCKED_PERIODS).transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
log.info("Second deposit tokens = " + str(miner_agent.contract.functions.deposit(MIN_ALLOWED_LOCKED, MIN_LOCKED_PERIODS).estimateGas({'from': ursula2})))
|
||||
tx = miner_agent.contract.functions.deposit(MIN_ALLOWED_LOCKED, MIN_LOCKED_PERIODS).transact({'from': ursula2})
|
||||
log.info("Second deposit tokens = " + str(miner_functions.deposit(MIN_ALLOWED_LOCKED, MIN_LOCKED_PERIODS).estimateGas({'from': ursula2})))
|
||||
tx = miner_functions.deposit(MIN_ALLOWED_LOCKED, MIN_LOCKED_PERIODS).transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
log.info("Third deposit tokens = " + str(miner_agent.contract.functions.deposit(MIN_ALLOWED_LOCKED, MIN_LOCKED_PERIODS).estimateGas({'from': ursula3})))
|
||||
tx = miner_agent.contract.functions.deposit(MIN_ALLOWED_LOCKED, MIN_LOCKED_PERIODS).transact({'from': ursula3})
|
||||
log.info("Third deposit tokens = " + str(miner_functions.deposit(MIN_ALLOWED_LOCKED, MIN_LOCKED_PERIODS).estimateGas({'from': ursula3})))
|
||||
tx = miner_functions.deposit(MIN_ALLOWED_LOCKED, MIN_LOCKED_PERIODS).transact({'from': ursula3})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
#
|
||||
# ApproveAndCall
|
||||
#
|
||||
testerchain.time_travel(periods=1)
|
||||
|
||||
tx = miner_agent.contract.functions.mint().transact({'from': ursula1})
|
||||
tx = miner_functions.mint().transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = miner_agent.contract.functions.mint().transact({'from': ursula2})
|
||||
tx = miner_functions.mint().transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = miner_agent.contract.functions.mint().transact({'from': ursula3})
|
||||
tx = miner_functions.mint().transact({'from': ursula3})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
log.info("First approveAndCall = " +
|
||||
str(token_agent.contract.functions.approveAndCall(miner_agent.contract_address,
|
||||
MIN_ALLOWED_LOCKED * 2,
|
||||
web3.toBytes(MIN_LOCKED_PERIODS))
|
||||
.estimateGas({'from': ursula1})))
|
||||
tx = token_agent.contract.functions.approveAndCall(miner_agent.contract_address,
|
||||
MIN_ALLOWED_LOCKED * 2,
|
||||
web3.toBytes(MIN_LOCKED_PERIODS)).transact({'from': ursula1})
|
||||
str(token_functions.approveAndCall(miner_agent.contract_address,
|
||||
MIN_ALLOWED_LOCKED * 2,
|
||||
web3.toBytes(MIN_LOCKED_PERIODS)).estimateGas({'from': ursula1})))
|
||||
tx = token_functions.approveAndCall(miner_agent.contract_address,
|
||||
MIN_ALLOWED_LOCKED * 2,
|
||||
web3.toBytes(MIN_LOCKED_PERIODS)).transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
log.info("Second approveAndCall = " +
|
||||
str(token_agent.contract.functions.approveAndCall(miner_agent.contract_address,
|
||||
MIN_ALLOWED_LOCKED * 2,
|
||||
web3.toBytes(MIN_LOCKED_PERIODS)).estimateGas({'from': ursula2})))
|
||||
tx = token_agent.contract.functions.approveAndCall(miner_agent.contract_address,
|
||||
MIN_ALLOWED_LOCKED * 2,
|
||||
web3.toBytes(MIN_LOCKED_PERIODS)).transact({'from': ursula2})
|
||||
str(token_functions.approveAndCall(miner_agent.contract_address, MIN_ALLOWED_LOCKED * 2,
|
||||
web3.toBytes(MIN_LOCKED_PERIODS)).estimateGas({'from': ursula2})))
|
||||
tx = token_functions.approveAndCall(miner_agent.contract_address,
|
||||
MIN_ALLOWED_LOCKED * 2,
|
||||
web3.toBytes(MIN_LOCKED_PERIODS)).transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
log.info("Third approveAndCall = " +
|
||||
str(token_agent.contract.functions.approveAndCall(miner_agent.contract_address,
|
||||
MIN_ALLOWED_LOCKED * 2,
|
||||
web3.toBytes(MIN_LOCKED_PERIODS))
|
||||
.estimateGas({'from': ursula3})))
|
||||
tx = token_agent.contract.functions.approveAndCall(miner_agent.contract_address,
|
||||
MIN_ALLOWED_LOCKED * 2,
|
||||
web3.toBytes(MIN_LOCKED_PERIODS)).transact({'from': ursula3})
|
||||
str(token_functions.approveAndCall(miner_agent.contract_address,
|
||||
MIN_ALLOWED_LOCKED * 2,
|
||||
web3.toBytes(MIN_LOCKED_PERIODS)).estimateGas({'from': ursula3})))
|
||||
tx = token_functions.approveAndCall(miner_agent.contract_address,
|
||||
MIN_ALLOWED_LOCKED * 2,
|
||||
web3.toBytes(MIN_LOCKED_PERIODS)).transact({'from': ursula3})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
#
|
||||
# Locking tokens
|
||||
#
|
||||
testerchain.time_travel(periods=1)
|
||||
|
||||
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula1})
|
||||
tx = miner_functions.confirmActivity().transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula2})
|
||||
tx = miner_functions.confirmActivity().transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula3})
|
||||
tx = miner_functions.confirmActivity().transact({'from': ursula3})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
log.info("First locking tokens = " +
|
||||
str(miner_agent.contract.functions.lock(MIN_ALLOWED_LOCKED, MIN_LOCKED_PERIODS).estimateGas({'from': ursula1})))
|
||||
tx = miner_agent.contract.functions.lock(MIN_ALLOWED_LOCKED, MIN_LOCKED_PERIODS).transact({'from': ursula1})
|
||||
str(miner_functions.lock(MIN_ALLOWED_LOCKED, MIN_LOCKED_PERIODS).estimateGas({'from': ursula1})))
|
||||
tx = miner_functions.lock(MIN_ALLOWED_LOCKED, MIN_LOCKED_PERIODS).transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
log.info("Second locking tokens = " +
|
||||
str(miner_agent.contract.functions.lock(MIN_ALLOWED_LOCKED, MIN_LOCKED_PERIODS).estimateGas({'from': ursula2})))
|
||||
tx = miner_agent.contract.functions.lock(MIN_ALLOWED_LOCKED,MIN_LOCKED_PERIODS).transact({'from': ursula2})
|
||||
str(miner_functions.lock(MIN_ALLOWED_LOCKED, MIN_LOCKED_PERIODS).estimateGas({'from': ursula2})))
|
||||
tx = miner_functions.lock(MIN_ALLOWED_LOCKED,MIN_LOCKED_PERIODS).transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
log.info("Third locking tokens = " +
|
||||
str(miner_agent.contract.functions.lock(MIN_ALLOWED_LOCKED, MIN_LOCKED_PERIODS).estimateGas({'from': ursula3})))
|
||||
tx = miner_agent.contract.functions.lock(MIN_ALLOWED_LOCKED, MIN_LOCKED_PERIODS).transact({'from': ursula3})
|
||||
str(miner_functions.lock(MIN_ALLOWED_LOCKED, MIN_LOCKED_PERIODS).estimateGas({'from': ursula3})))
|
||||
tx = miner_functions.lock(MIN_ALLOWED_LOCKED, MIN_LOCKED_PERIODS).transact({'from': ursula3})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
#
|
||||
# Divide stake
|
||||
log.info("First divide stake = " +
|
||||
str(miner_agent.contract.functions.divideStake(1, MIN_ALLOWED_LOCKED, 2)
|
||||
.estimateGas({'from': ursula1})))
|
||||
tx = miner_agent.contract.functions.divideStake(1, MIN_ALLOWED_LOCKED, 2).transact({'from': ursula1})
|
||||
#
|
||||
log.info("First divide stake = " + str(miner_functions.divideStake(1, MIN_ALLOWED_LOCKED, 2).estimateGas({'from': ursula1})))
|
||||
tx = miner_functions.divideStake(1, MIN_ALLOWED_LOCKED, 2).transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
log.info("Second divide stake = " +
|
||||
str(miner_agent.contract.functions.divideStake(3, MIN_ALLOWED_LOCKED, 2)
|
||||
.estimateGas({'from': ursula1})))
|
||||
tx = miner_agent.contract.functions.divideStake(3, MIN_ALLOWED_LOCKED, 2).transact({'from': ursula1})
|
||||
log.info("Second divide stake = " + str(miner_functions.divideStake(3, MIN_ALLOWED_LOCKED, 2).estimateGas({'from': ursula1})))
|
||||
tx = miner_functions.divideStake(3, MIN_ALLOWED_LOCKED, 2).transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
#
|
||||
# Divide almost finished stake
|
||||
#
|
||||
testerchain.time_travel(periods=1)
|
||||
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula1})
|
||||
tx = miner_functions.confirmActivity().transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(periods=1)
|
||||
log.info("Divide stake (next period is not confirmed) = " +
|
||||
str(miner_agent.contract.functions.divideStake(0, MIN_ALLOWED_LOCKED, 2)
|
||||
.estimateGas({'from': ursula1})))
|
||||
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula1})
|
||||
log.info("Divide stake (next period is not confirmed) = " + str(miner_functions.divideStake(0, MIN_ALLOWED_LOCKED, 2).estimateGas({'from': ursula1})))
|
||||
tx = miner_functions.confirmActivity().transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
log.info("Divide stake (next period is confirmed) = " +
|
||||
str(miner_agent.contract.functions.divideStake(0, MIN_ALLOWED_LOCKED, 2)
|
||||
.estimateGas({'from': ursula1})))
|
||||
log.info("Divide stake (next period is confirmed) = " + str(miner_functions.divideStake(0, MIN_ALLOWED_LOCKED, 2).estimateGas({'from': ursula1})))
|
||||
print("********* All Done! *********")
|
||||
return analyzer
|
||||
|
||||
|
|
Loading…
Reference in New Issue