2018-03-19 00:46:48 +00:00
|
|
|
#!/usr/bin/env python3
|
2018-12-03 01:06:40 +00:00
|
|
|
|
|
|
|
|
2018-11-04 19:23:11 +00:00
|
|
|
"""
|
|
|
|
This file is part of nucypher.
|
|
|
|
|
|
|
|
nucypher is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
nucypher is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with nucypher. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
"""
|
2018-03-19 00:46:48 +00:00
|
|
|
|
2018-12-08 20:23:26 +00:00
|
|
|
|
2018-12-13 22:56:16 +00:00
|
|
|
import json
|
2018-03-23 05:05:03 +00:00
|
|
|
import os
|
2018-12-13 22:56:16 +00:00
|
|
|
from typing import List, Tuple
|
|
|
|
|
|
|
|
import time
|
2018-12-08 20:23:26 +00:00
|
|
|
from os.path import abspath, dirname
|
|
|
|
|
|
|
|
import io
|
|
|
|
import re
|
|
|
|
from twisted.logger import globalLogPublisher, Logger, jsonFileLogObserver, ILogObserver
|
|
|
|
from zope.interface import provider
|
2018-06-15 05:51:28 +00:00
|
|
|
|
2018-12-03 01:06:40 +00:00
|
|
|
from nucypher.blockchain.eth.actors import Deployer
|
|
|
|
from nucypher.blockchain.eth.agents import NucypherTokenAgent, MinerAgent, PolicyAgent
|
|
|
|
from nucypher.blockchain.eth.constants import (
|
|
|
|
DISPATCHER_SECRET_LENGTH,
|
|
|
|
MIN_ALLOWED_LOCKED,
|
|
|
|
MIN_LOCKED_PERIODS,
|
|
|
|
POLICY_ID_LENGTH
|
|
|
|
)
|
2018-08-20 02:44:50 +00:00
|
|
|
from nucypher.blockchain.eth.interfaces import BlockchainDeployerInterface
|
2018-12-03 01:06:40 +00:00
|
|
|
from nucypher.blockchain.eth.registry import InMemoryEthereumContractRegistry
|
2018-06-15 05:51:28 +00:00
|
|
|
from nucypher.blockchain.eth.sol.compile import SolidityCompiler
|
2018-12-13 22:56:16 +00:00
|
|
|
from nucypher.config.constants import CONTRACT_ROOT
|
2018-12-03 01:06:40 +00:00
|
|
|
from nucypher.utilities.sandbox.blockchain import TesterBlockchain
|
2018-03-07 19:22:59 +00:00
|
|
|
|
2018-12-08 20:23:26 +00:00
|
|
|
|
2018-12-13 22:56:16 +00:00
|
|
|
class AnalyzeGas:
|
2018-12-08 20:23:26 +00:00
|
|
|
|
2018-12-13 22:56:16 +00:00
|
|
|
# Tweaks
|
|
|
|
LOG_NAME = 'estimate-gas'
|
|
|
|
LOG_FILENAME = '{}.log.json'.format(LOG_NAME)
|
|
|
|
OUTPUT_DIR = os.path.join(abspath(dirname(__file__)), 'results')
|
|
|
|
CONTRACT_DIR = CONTRACT_ROOT
|
|
|
|
PROVIDER_URI = "tester://pyevm"
|
|
|
|
TEST_ACCOUNTS = 10
|
|
|
|
JSON_OUTPUT_FILENAME ='{}.json'.format(LOG_NAME)
|
2018-12-08 20:23:26 +00:00
|
|
|
|
2018-12-13 22:56:16 +00:00
|
|
|
def __init__(self) -> None:
|
|
|
|
self.gas_estimations = dict()
|
2018-12-08 20:23:26 +00:00
|
|
|
|
2018-12-13 22:56:16 +00:00
|
|
|
if not os.path.isdir(self.OUTPUT_DIR):
|
|
|
|
os.mkdir(self.OUTPUT_DIR)
|
2018-12-08 20:23:26 +00:00
|
|
|
|
|
|
|
@provider(ILogObserver)
|
2018-12-13 22:56:16 +00:00
|
|
|
def __call__(self, event, *args, **kwargs) -> None:
|
|
|
|
if event.get('log_namespace') == self.LOG_NAME:
|
2018-12-08 20:23:26 +00:00
|
|
|
message = event.get("log_format")
|
2018-12-14 16:06:32 +00:00
|
|
|
if not re.match(r'\w+\s=\s\d+$', message):
|
2018-12-08 20:23:26 +00:00
|
|
|
return
|
|
|
|
label, gas = (s.strip() for s in message.split('='))
|
2018-12-13 22:56:16 +00:00
|
|
|
self.paint_line(label, gas)
|
2018-12-08 20:23:26 +00:00
|
|
|
self.gas_estimations[label] = int(gas)
|
|
|
|
|
2018-12-13 22:56:16 +00:00
|
|
|
@staticmethod
|
|
|
|
def paint_line(label: str, gas: str) -> None:
|
|
|
|
print('{label} {dots} {gas:,}'.format(label=label, dots='.' * (65 - len(label)), gas=int(gas)))
|
2018-01-27 13:05:19 +00:00
|
|
|
|
2018-12-13 22:56:16 +00:00
|
|
|
def to_json_file(self) -> None:
|
|
|
|
print('Saving JSON Output...')
|
2018-06-15 05:51:28 +00:00
|
|
|
|
2018-12-13 22:56:16 +00:00
|
|
|
epoch_time = str(int(time.time()))
|
|
|
|
timestamped_filename = '{}-{}'.format(epoch_time, self.JSON_OUTPUT_FILENAME)
|
|
|
|
filepath = os.path.join(self.OUTPUT_DIR, timestamped_filename)
|
|
|
|
with open(filepath, 'w') as file:
|
|
|
|
file.write(json.dumps(self.gas_estimations, indent=4))
|
2018-06-15 05:51:28 +00:00
|
|
|
|
2018-12-13 22:56:16 +00:00
|
|
|
def start_collection(self) -> None:
|
|
|
|
print("Starting Data Collection...")
|
2018-12-08 20:23:26 +00:00
|
|
|
|
2018-12-13 22:56:16 +00:00
|
|
|
json_filepath = os.path.join(self.OUTPUT_DIR, AnalyzeGas.LOG_FILENAME)
|
|
|
|
json_io = io.open(json_filepath, "w")
|
|
|
|
json_observer = jsonFileLogObserver(json_io)
|
|
|
|
globalLogPublisher.addObserver(json_observer)
|
|
|
|
globalLogPublisher.addObserver(self)
|
2018-06-15 05:51:28 +00:00
|
|
|
|
2018-12-13 22:56:16 +00:00
|
|
|
def connect_to_blockchain(self) -> TesterBlockchain:
|
|
|
|
print("Deploying Blockchain...")
|
|
|
|
|
|
|
|
solidity_compiler = SolidityCompiler(test_contract_dir=self.CONTRACT_DIR)
|
|
|
|
memory_registry = InMemoryEthereumContractRegistry()
|
|
|
|
interface = BlockchainDeployerInterface(provider_uri=self.PROVIDER_URI, compiler=solidity_compiler,
|
|
|
|
registry=memory_registry)
|
|
|
|
|
|
|
|
testerchain = TesterBlockchain(interface=interface, test_accounts=self.TEST_ACCOUNTS, airdrop=False)
|
|
|
|
return testerchain
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def deploy_contracts(testerchain: TesterBlockchain) -> None:
|
|
|
|
print("Deploying Contracts...")
|
|
|
|
|
|
|
|
origin = testerchain.interface.w3.eth.accounts[0]
|
|
|
|
deployer = Deployer(blockchain=testerchain, deployer_address=origin, bare=True)
|
|
|
|
_txhashes, _agents = deployer.deploy_network_contracts(miner_secret=os.urandom(DISPATCHER_SECRET_LENGTH),
|
|
|
|
policy_secret=os.urandom(DISPATCHER_SECRET_LENGTH))
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def connect_to_contracts(testerchain: TesterBlockchain) -> Tuple[NucypherTokenAgent, MinerAgent, PolicyAgent]:
|
|
|
|
print("Connecting...")
|
|
|
|
|
|
|
|
token_agent = NucypherTokenAgent(blockchain=testerchain)
|
|
|
|
miner_agent = MinerAgent(blockchain=testerchain)
|
|
|
|
policy_agent = PolicyAgent(blockchain=testerchain)
|
2018-06-15 05:51:28 +00:00
|
|
|
|
2018-12-13 22:56:16 +00:00
|
|
|
return token_agent, miner_agent, policy_agent
|
2018-12-08 20:23:26 +00:00
|
|
|
|
2018-12-13 22:56:16 +00:00
|
|
|
def bootstrap_network(self) -> Tuple[TesterBlockchain, List[str]]:
|
|
|
|
print("Bootstrapping testing network...")
|
2018-10-26 14:33:52 +00:00
|
|
|
|
2018-12-13 22:56:16 +00:00
|
|
|
testerchain = self.connect_to_blockchain()
|
|
|
|
self.deploy_contracts(testerchain=testerchain)
|
|
|
|
return testerchain, testerchain.interface.w3.eth.accounts
|
2018-12-08 20:23:26 +00:00
|
|
|
|
2018-12-13 22:56:16 +00:00
|
|
|
|
|
|
|
def estimate_gas(analyzer: AnalyzeGas) -> AnalyzeGas:
|
|
|
|
|
|
|
|
#
|
|
|
|
# Setup
|
|
|
|
#
|
|
|
|
log = Logger(AnalyzeGas.LOG_NAME)
|
|
|
|
|
|
|
|
testerchain, accounts = analyzer.bootstrap_network()
|
2018-12-03 01:06:40 +00:00
|
|
|
web3 = testerchain.interface.w3
|
2018-12-13 22:56:16 +00:00
|
|
|
|
|
|
|
token_agent, miner_agent, policy_agent = analyzer.connect_to_contracts(testerchain=testerchain)
|
|
|
|
log.info("Running with provider URI: {}".format(testerchain.interface.provider_uri))
|
|
|
|
|
|
|
|
analyzer.start_collection()
|
2018-10-26 14:33:52 +00:00
|
|
|
|
2018-12-03 01:06:40 +00:00
|
|
|
#
|
|
|
|
# Scenario
|
|
|
|
#
|
2018-12-08 20:23:26 +00:00
|
|
|
|
2018-12-13 22:56:16 +00:00
|
|
|
origin, ursula1, ursula2, ursula3, alice1, *everyone_else = testerchain.interface.w3.eth.accounts
|
2018-06-15 05:51:28 +00:00
|
|
|
|
2018-12-13 22:56:16 +00:00
|
|
|
print("********* Estimating Gas *********")
|
2018-06-15 05:51:28 +00:00
|
|
|
|
2018-03-02 17:10:49 +00:00
|
|
|
# Pre deposit tokens
|
2018-12-03 01:06:40 +00:00
|
|
|
tx = token_agent.contract.functions.approve(miner_agent.contract_address, MIN_ALLOWED_LOCKED * 5).transact({'from': origin})
|
2018-06-15 05:51:28 +00:00
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Pre-deposit tokens for 5 owners = " +
|
2018-06-15 05:51:28 +00:00
|
|
|
str(miner_agent.contract.functions
|
|
|
|
.preDeposit(everyone_else[0:5],
|
2018-12-13 22:56:16 +00:00
|
|
|
[MIN_ALLOWED_LOCKED] * 5,
|
|
|
|
[MIN_LOCKED_PERIODS] * 5)
|
2018-06-15 05:51:28 +00:00
|
|
|
.estimateGas({'from': origin})))
|
2018-02-08 09:29:32 +00:00
|
|
|
|
|
|
|
# Give Ursula and Alice some coins
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Transfer tokens = " +
|
2018-12-03 01:06:40 +00:00
|
|
|
str(token_agent.contract.functions.transfer(ursula1, MIN_ALLOWED_LOCKED * 10)
|
2018-06-15 05:51:28 +00:00
|
|
|
.estimateGas({'from': origin})))
|
2018-12-03 01:06:40 +00:00
|
|
|
tx = token_agent.contract.functions.transfer(ursula1, MIN_ALLOWED_LOCKED * 10).transact({'from': origin})
|
2018-06-15 05:51:28 +00:00
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-03 01:06:40 +00:00
|
|
|
tx = token_agent.contract.functions.transfer(ursula2, MIN_ALLOWED_LOCKED * 10).transact({'from': origin})
|
2018-06-15 05:51:28 +00:00
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-03 01:06:40 +00:00
|
|
|
tx = token_agent.contract.functions.transfer(ursula3, MIN_ALLOWED_LOCKED * 10).transact({'from': origin})
|
2018-06-15 05:51:28 +00:00
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-02-08 09:29:32 +00:00
|
|
|
|
|
|
|
# Ursula and Alice give Escrow rights to transfer
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Approving transfer = " +
|
2018-12-03 01:06:40 +00:00
|
|
|
str(token_agent.contract.functions.approve(miner_agent.contract_address, MIN_ALLOWED_LOCKED * 6)
|
2018-06-15 05:51:28 +00:00
|
|
|
.estimateGas({'from': ursula1})))
|
2018-12-03 01:06:40 +00:00
|
|
|
tx = token_agent.contract.functions.approve(miner_agent.contract_address, MIN_ALLOWED_LOCKED * 6)\
|
2018-06-15 05:51:28 +00:00
|
|
|
.transact({'from': ursula1})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-03 01:06:40 +00:00
|
|
|
tx = token_agent.contract.functions.approve(miner_agent.contract_address, MIN_ALLOWED_LOCKED * 6)\
|
2018-06-15 05:51:28 +00:00
|
|
|
.transact({'from': ursula2})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-03 01:06:40 +00:00
|
|
|
tx = token_agent.contract.functions.approve(miner_agent.contract_address, MIN_ALLOWED_LOCKED * 6)\
|
2018-06-15 05:51:28 +00:00
|
|
|
.transact({'from': ursula3})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-02-08 09:29:32 +00:00
|
|
|
|
|
|
|
# Ursula and Alice transfer some tokens to the escrow and lock them
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("First initial deposit tokens = " +
|
2018-12-13 22:56:16 +00:00
|
|
|
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})
|
2018-06-15 05:51:28 +00:00
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Second initial deposit tokens = " +
|
2018-12-13 22:56:16 +00:00
|
|
|
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})
|
2018-06-15 05:51:28 +00:00
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Third initial deposit tokens = " +
|
2018-12-13 22:56:16 +00:00
|
|
|
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})
|
2018-06-15 05:51:28 +00:00
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-02-08 09:29:32 +00:00
|
|
|
|
|
|
|
# Wait 1 period and confirm activity
|
2018-06-15 05:51:28 +00:00
|
|
|
testerchain.time_travel(periods=1)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("First confirm activity = " +
|
2018-06-15 05:51:28 +00:00
|
|
|
str(miner_agent.contract.functions.confirmActivity().estimateGas({'from': ursula1})))
|
|
|
|
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula1})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Second confirm activity = " +
|
2018-06-15 05:51:28 +00:00
|
|
|
str(miner_agent.contract.functions.confirmActivity().estimateGas({'from': ursula2})))
|
|
|
|
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula2})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Third confirm activity = " +
|
2018-06-15 05:51:28 +00:00
|
|
|
str(miner_agent.contract.functions.confirmActivity().estimateGas({'from': ursula3})))
|
|
|
|
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula3})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-02-08 09:29:32 +00:00
|
|
|
|
|
|
|
# Wait 1 period and mint tokens
|
2018-06-15 05:51:28 +00:00
|
|
|
testerchain.time_travel(periods=1)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("First mining (1 stake) = " + str(miner_agent.contract.functions.mint().estimateGas({'from': ursula1})))
|
2018-06-15 05:51:28 +00:00
|
|
|
tx = miner_agent.contract.functions.mint().transact({'from': ursula1})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Second mining (1 stake) = " + str(miner_agent.contract.functions.mint().estimateGas({'from': ursula2})))
|
2018-06-15 05:51:28 +00:00
|
|
|
tx = miner_agent.contract.functions.mint().transact({'from': ursula2})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Third/last mining (1 stake) = " + str(miner_agent.contract.functions.mint().estimateGas({'from': ursula3})))
|
2018-06-15 05:51:28 +00:00
|
|
|
tx = miner_agent.contract.functions.mint().transact({'from': ursula3})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
|
|
|
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("First confirm activity again = " +
|
2018-06-15 05:51:28 +00:00
|
|
|
str(miner_agent.contract.functions.confirmActivity().estimateGas({'from': ursula1})))
|
|
|
|
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula1})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Second confirm activity again = " +
|
2018-06-15 05:51:28 +00:00
|
|
|
str(miner_agent.contract.functions.confirmActivity().estimateGas({'from': ursula2})))
|
|
|
|
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula2})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Third confirm activity again = " +
|
2018-06-15 05:51:28 +00:00
|
|
|
str(miner_agent.contract.functions.confirmActivity().estimateGas({'from': ursula3})))
|
|
|
|
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula3})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-02-08 09:29:32 +00:00
|
|
|
|
|
|
|
# Confirm again
|
2018-06-15 05:51:28 +00:00
|
|
|
testerchain.time_travel(periods=1)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("First confirm activity + mint = " +
|
2018-06-15 05:51:28 +00:00
|
|
|
str(miner_agent.contract.functions.confirmActivity().estimateGas({'from': ursula1})))
|
|
|
|
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula1})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Second confirm activity + mint = " +
|
2018-06-15 05:51:28 +00:00
|
|
|
str(miner_agent.contract.functions.confirmActivity().estimateGas({'from': ursula2})))
|
|
|
|
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula2})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Third confirm activity + mint = " +
|
2018-06-15 05:51:28 +00:00
|
|
|
str(miner_agent.contract.functions.confirmActivity().estimateGas({'from': ursula3})))
|
|
|
|
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula3})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-02-08 09:29:32 +00:00
|
|
|
|
|
|
|
# Get locked tokens
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Getting locked tokens = " + str(miner_agent.contract.functions.getLockedTokens(ursula1).estimateGas()))
|
2018-02-08 09:29:32 +00:00
|
|
|
|
|
|
|
# Wait 1 period and withdraw tokens
|
2018-06-15 05:51:28 +00:00
|
|
|
testerchain.time_travel(periods=1)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("First withdraw = " + str(miner_agent.contract.functions.withdraw(1).estimateGas({'from': ursula1})))
|
2018-06-15 05:51:28 +00:00
|
|
|
tx = miner_agent.contract.functions.withdraw(1).transact({'from': ursula1})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Second withdraw = " + str(miner_agent.contract.functions.withdraw(1).estimateGas({'from': ursula2})))
|
2018-06-15 05:51:28 +00:00
|
|
|
tx = miner_agent.contract.functions.withdraw(1).transact({'from': ursula2})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Third withdraw = " + str(miner_agent.contract.functions.withdraw(1).estimateGas({'from': ursula3})))
|
2018-06-15 05:51:28 +00:00
|
|
|
tx = miner_agent.contract.functions.withdraw(1).transact({'from': ursula3})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-02-08 09:29:32 +00:00
|
|
|
|
|
|
|
# Wait 1 period and confirm activity
|
2018-06-15 05:51:28 +00:00
|
|
|
testerchain.time_travel(periods=1)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("First confirm activity after downtime = " +
|
2018-06-15 05:51:28 +00:00
|
|
|
str(miner_agent.contract.functions.confirmActivity().estimateGas({'from': ursula1})))
|
|
|
|
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula1})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Second confirm activity after downtime = " +
|
2018-06-15 05:51:28 +00:00
|
|
|
str(miner_agent.contract.functions.confirmActivity().estimateGas({'from': ursula2})))
|
|
|
|
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula2})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Third confirm activity after downtime = " +
|
2018-06-15 05:51:28 +00:00
|
|
|
str(miner_agent.contract.functions.confirmActivity().estimateGas({'from': ursula3})))
|
|
|
|
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula3})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-02-08 09:29:32 +00:00
|
|
|
|
|
|
|
# Ursula and Alice deposit some tokens to the escrow again
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("First deposit tokens again = " +
|
2018-12-13 22:56:16 +00:00
|
|
|
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})
|
2018-06-15 05:51:28 +00:00
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Second deposit tokens again = " +
|
2018-12-13 22:56:16 +00:00
|
|
|
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})
|
2018-06-15 05:51:28 +00:00
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Third deposit tokens again = " +
|
2018-12-13 22:56:16 +00:00
|
|
|
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})
|
2018-06-15 05:51:28 +00:00
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-02-08 09:29:32 +00:00
|
|
|
|
|
|
|
# Wait 1 period and mint tokens
|
2018-06-15 05:51:28 +00:00
|
|
|
testerchain.time_travel(periods=1)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("First mining again = " + str(miner_agent.contract.functions.mint().estimateGas({'from': ursula1})))
|
2018-06-15 05:51:28 +00:00
|
|
|
tx = miner_agent.contract.functions.mint().transact({'from': ursula1})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Second mining again = " + str(miner_agent.contract.functions.mint().estimateGas({'from': ursula2})))
|
2018-06-15 05:51:28 +00:00
|
|
|
tx = miner_agent.contract.functions.mint().transact({'from': ursula2})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Third/last mining again = " + str(miner_agent.contract.functions.mint().estimateGas({'from': ursula3})))
|
2018-06-15 05:51:28 +00:00
|
|
|
tx = miner_agent.contract.functions.mint().transact({'from': ursula3})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-02-08 09:29:32 +00:00
|
|
|
|
2018-03-10 13:04:11 +00:00
|
|
|
# Create policy
|
2018-12-03 01:06:40 +00:00
|
|
|
policy_id_1 = os.urandom(int(POLICY_ID_LENGTH))
|
|
|
|
policy_id_2 = os.urandom(int(POLICY_ID_LENGTH))
|
2018-03-10 13:04:11 +00:00
|
|
|
number_of_periods = 10
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("First creating policy (1 node, 10 periods) = " +
|
2018-06-15 05:51:28 +00:00
|
|
|
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})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Second creating policy (1 node, 10 periods) = " +
|
2018-06-15 05:51:28 +00:00
|
|
|
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})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-03-10 13:04:11 +00:00
|
|
|
|
|
|
|
# Revoke policy
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Revoking policy = " +
|
2018-06-15 05:51:28 +00:00
|
|
|
str(policy_agent.contract.functions.revokePolicy(policy_id_1).estimateGas({'from': alice1})))
|
|
|
|
tx = policy_agent.contract.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})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-03-10 13:04:11 +00:00
|
|
|
|
|
|
|
# Create policy with more periods
|
2018-12-03 01:06:40 +00:00
|
|
|
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))
|
2018-03-10 13:04:11 +00:00
|
|
|
number_of_periods = 100
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("First creating policy (1 node, " + str(number_of_periods) + " periods, first reward) = " +
|
2018-06-15 05:51:28 +00:00
|
|
|
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})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
|
|
|
testerchain.time_travel(periods=1)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Second creating policy (1 node, " + str(number_of_periods) + " periods, first reward) = " +
|
2018-06-15 05:51:28 +00:00
|
|
|
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})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Third creating policy (1 node, " + str(number_of_periods) + " periods, first reward) = " +
|
2018-06-15 05:51:28 +00:00
|
|
|
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})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-03-10 13:04:11 +00:00
|
|
|
|
|
|
|
# Mine and revoke policy
|
2018-06-15 05:51:28 +00:00
|
|
|
testerchain.time_travel(periods=10)
|
|
|
|
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula2})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
|
|
|
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula1})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
|
|
|
|
|
|
|
testerchain.time_travel(periods=1)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("First mining after downtime = " + str(miner_agent.contract.functions.mint().estimateGas({'from': ursula1})))
|
2018-06-15 05:51:28 +00:00
|
|
|
tx = miner_agent.contract.functions.mint().transact({'from': ursula1})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Second mining after downtime = " + str(miner_agent.contract.functions.mint().estimateGas({'from': ursula2})))
|
2018-06-15 05:51:28 +00:00
|
|
|
tx = miner_agent.contract.functions.mint().transact({'from': ursula2})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
|
|
|
|
|
|
|
testerchain.time_travel(periods=10)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("First revoking policy after downtime = " +
|
2018-06-15 05:51:28 +00:00
|
|
|
str(policy_agent.contract.functions.revokePolicy(policy_id_1).estimateGas({'from': alice1})))
|
|
|
|
tx = policy_agent.contract.functions.revokePolicy(policy_id_1).transact({'from': alice1})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Second revoking policy after downtime = " +
|
2018-06-15 05:51:28 +00:00
|
|
|
str(policy_agent.contract.functions.revokePolicy(policy_id_2).estimateGas({'from': alice1})))
|
|
|
|
tx = policy_agent.contract.functions.revokePolicy(policy_id_2).transact({'from': alice1})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Second revoking policy after downtime = " +
|
2018-06-15 05:51:28 +00:00
|
|
|
str(policy_agent.contract.functions.revokePolicy(policy_id_3).estimateGas({'from': alice1})))
|
|
|
|
tx = policy_agent.contract.functions.revokePolicy(policy_id_3).transact({'from': alice1})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-03-16 18:44:20 +00:00
|
|
|
|
|
|
|
# Create policy with multiple nodes
|
2018-12-03 01:06:40 +00:00
|
|
|
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))
|
2018-03-16 18:44:20 +00:00
|
|
|
number_of_periods = 100
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("First creating policy (3 nodes, 100 periods, first reward) = " +
|
2018-06-15 05:51:28 +00:00
|
|
|
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})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Second creating policy (3 nodes, 100 periods, first reward) = " +
|
2018-06-15 05:51:28 +00:00
|
|
|
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})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Third creating policy (2 nodes, 100 periods, first reward) = " +
|
2018-06-15 05:51:28 +00:00
|
|
|
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})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
|
|
|
|
|
|
|
for index in range(5):
|
|
|
|
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula1})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
|
|
|
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula2})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
|
|
|
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula3})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
|
|
|
testerchain.time_travel(periods=1)
|
|
|
|
|
|
|
|
tx = miner_agent.contract.functions.mint().transact({'from': ursula1})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
|
|
|
tx = miner_agent.contract.functions.mint().transact({'from': ursula2})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
|
|
|
tx = miner_agent.contract.functions.mint().transact({'from': ursula3})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
|
|
|
|
|
|
|
# Check regular deposit
|
2018-12-13 22:56:16 +00:00
|
|
|
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})
|
2018-06-15 05:51:28 +00:00
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-13 22:56:16 +00:00
|
|
|
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})
|
2018-06-15 05:51:28 +00:00
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-13 22:56:16 +00:00
|
|
|
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})
|
2018-06-15 05:51:28 +00:00
|
|
|
testerchain.wait_for_receipt(tx)
|
|
|
|
|
|
|
|
# ApproveAndCall
|
|
|
|
testerchain.time_travel(periods=1)
|
|
|
|
|
|
|
|
tx = miner_agent.contract.functions.mint().transact({'from': ursula1})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
|
|
|
tx = miner_agent.contract.functions.mint().transact({'from': ursula2})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
|
|
|
tx = miner_agent.contract.functions.mint().transact({'from': ursula3})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
|
|
|
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("First approveAndCall = " +
|
2018-06-15 05:51:28 +00:00
|
|
|
str(token_agent.contract.functions.approveAndCall(miner_agent.contract_address,
|
2018-12-13 22:56:16 +00:00
|
|
|
MIN_ALLOWED_LOCKED * 2,
|
|
|
|
web3.toBytes(MIN_LOCKED_PERIODS))
|
2018-06-15 05:51:28 +00:00
|
|
|
.estimateGas({'from': ursula1})))
|
|
|
|
tx = token_agent.contract.functions.approveAndCall(miner_agent.contract_address,
|
2018-12-13 22:56:16 +00:00
|
|
|
MIN_ALLOWED_LOCKED * 2,
|
|
|
|
web3.toBytes(MIN_LOCKED_PERIODS)).transact({'from': ursula1})
|
2018-06-15 05:51:28 +00:00
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Second approveAndCall = " +
|
2018-06-15 05:51:28 +00:00
|
|
|
str(token_agent.contract.functions.approveAndCall(miner_agent.contract_address,
|
2018-12-13 22:56:16 +00:00
|
|
|
MIN_ALLOWED_LOCKED * 2,
|
|
|
|
web3.toBytes(MIN_LOCKED_PERIODS)).estimateGas({'from': ursula2})))
|
2018-06-15 05:51:28 +00:00
|
|
|
tx = token_agent.contract.functions.approveAndCall(miner_agent.contract_address,
|
2018-12-13 22:56:16 +00:00
|
|
|
MIN_ALLOWED_LOCKED * 2,
|
|
|
|
web3.toBytes(MIN_LOCKED_PERIODS)).transact({'from': ursula2})
|
2018-06-15 05:51:28 +00:00
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Third approveAndCall = " +
|
2018-06-15 05:51:28 +00:00
|
|
|
str(token_agent.contract.functions.approveAndCall(miner_agent.contract_address,
|
2018-12-13 22:56:16 +00:00
|
|
|
MIN_ALLOWED_LOCKED * 2,
|
|
|
|
web3.toBytes(MIN_LOCKED_PERIODS))
|
2018-06-15 05:51:28 +00:00
|
|
|
.estimateGas({'from': ursula3})))
|
|
|
|
tx = token_agent.contract.functions.approveAndCall(miner_agent.contract_address,
|
2018-12-13 22:56:16 +00:00
|
|
|
MIN_ALLOWED_LOCKED * 2,
|
|
|
|
web3.toBytes(MIN_LOCKED_PERIODS)).transact({'from': ursula3})
|
2018-06-15 05:51:28 +00:00
|
|
|
testerchain.wait_for_receipt(tx)
|
|
|
|
|
|
|
|
# Locking tokens
|
|
|
|
testerchain.time_travel(periods=1)
|
|
|
|
|
|
|
|
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula1})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
|
|
|
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula2})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
|
|
|
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula3})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
|
|
|
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("First locking tokens = " +
|
2018-12-13 22:56:16 +00:00
|
|
|
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})
|
2018-06-15 05:51:28 +00:00
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Second locking tokens = " +
|
2018-12-13 22:56:16 +00:00
|
|
|
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})
|
2018-06-15 05:51:28 +00:00
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Third locking tokens = " +
|
2018-12-13 22:56:16 +00:00
|
|
|
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})
|
2018-06-15 05:51:28 +00:00
|
|
|
testerchain.wait_for_receipt(tx)
|
|
|
|
|
|
|
|
# Divide stake
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("First divide stake = " +
|
2018-12-13 22:56:16 +00:00
|
|
|
str(miner_agent.contract.functions.divideStake(1, MIN_ALLOWED_LOCKED, 2)
|
2018-06-15 05:51:28 +00:00
|
|
|
.estimateGas({'from': ursula1})))
|
2018-12-13 22:56:16 +00:00
|
|
|
tx = miner_agent.contract.functions.divideStake(1, MIN_ALLOWED_LOCKED, 2).transact({'from': ursula1})
|
2018-06-15 05:51:28 +00:00
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Second divide stake = " +
|
2018-12-13 22:56:16 +00:00
|
|
|
str(miner_agent.contract.functions.divideStake(3, MIN_ALLOWED_LOCKED, 2)
|
2018-06-15 05:51:28 +00:00
|
|
|
.estimateGas({'from': ursula1})))
|
2018-12-13 22:56:16 +00:00
|
|
|
tx = miner_agent.contract.functions.divideStake(3, MIN_ALLOWED_LOCKED, 2).transact({'from': ursula1})
|
2018-06-15 05:51:28 +00:00
|
|
|
testerchain.wait_for_receipt(tx)
|
|
|
|
|
|
|
|
# Divide almost finished stake
|
|
|
|
testerchain.time_travel(periods=1)
|
|
|
|
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula1})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
|
|
|
testerchain.time_travel(periods=1)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Divide stake (next period is not confirmed) = " +
|
2018-12-13 22:56:16 +00:00
|
|
|
str(miner_agent.contract.functions.divideStake(0, MIN_ALLOWED_LOCKED, 2)
|
2018-06-15 05:51:28 +00:00
|
|
|
.estimateGas({'from': ursula1})))
|
|
|
|
tx = miner_agent.contract.functions.confirmActivity().transact({'from': ursula1})
|
|
|
|
testerchain.wait_for_receipt(tx)
|
2018-12-08 20:23:26 +00:00
|
|
|
log.info("Divide stake (next period is confirmed) = " +
|
2018-12-13 22:56:16 +00:00
|
|
|
str(miner_agent.contract.functions.divideStake(0, MIN_ALLOWED_LOCKED, 2)
|
2018-06-15 05:51:28 +00:00
|
|
|
.estimateGas({'from': ursula1})))
|
2018-12-08 20:23:26 +00:00
|
|
|
print("********* All Done! *********")
|
2018-12-13 22:56:16 +00:00
|
|
|
return analyzer
|
2018-01-27 13:05:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2018-12-08 20:23:26 +00:00
|
|
|
print("Starting Up...")
|
2018-12-13 22:56:16 +00:00
|
|
|
analyzer = AnalyzeGas()
|
|
|
|
analyzer = estimate_gas(analyzer=analyzer)
|
|
|
|
analyzer.to_json_file()
|