Detailing embedded HW Tx Prompts; Finding the balance of gas strategies in tests v. prod.

pull/1750/head
Kieran R. Prasch 2020-02-26 19:35:02 -07:00
parent 33df86b9be
commit 0184ef9161
3 changed files with 15 additions and 11 deletions

View File

@ -438,7 +438,12 @@ class BlockchainInterface:
#
if self.transacting_power.device:
emitter.message(f'Confirm transaction {transaction_name} on hardware wallet...', color='yellow')
cost_wei = unsigned_transaction['gasPrice'] * unsigned_transaction['gas']
cost = Web3.fromWei(cost_wei, 'gwei')
# TODO: Show the USD Price
# Price Oracle
# https://api.coinmarketcap.com/v1/ticker/ethereum/
emitter.message(f'Confirm transaction {transaction_name} on hardware wallet... ({cost} gwei)', color='yellow')
signed_raw_transaction = self.transacting_power.sign_transaction(unsigned_transaction)
#

View File

@ -73,7 +73,7 @@ option_registry_infile = click.option('--registry-infile', help="Input path for
option_registry_outfile = click.option('--registry-outfile', help="Output path for contract registry file", type=click.Path(file_okay=True))
option_target_address = click.option('--target-address', help="Address of the target contract", type=EIP55_CHECKSUM_ADDRESS)
option_gas = click.option('--gas', help="Operate with a specified gas per-transaction limit", type=click.IntRange(min=1))
option_gas_strategy = click.option('--gas-strategy', help="Operate with a specified gas price strategy", type=GAS_STRATEGY_CHOICES, default=None)
option_gas_strategy = click.option('--gas-strategy', help="Operate with a specified gas price strategy", type=click.STRING, default=None) # TODO: GAS_STRATEGY_CHOICES
option_network = click.option('--network', help="Name of NuCypher network", type=click.Choice(NetworksInventory.networks), default=None)
option_ignore_deployed = click.option('--ignore-deployed', help="Ignore already deployed contracts if exist.", is_flag=True)
option_ignore_solidity_version = click.option('--ignore-solidity-check', help="Ignore solidity version compatibility check", is_flag=True, default=None)

View File

@ -62,6 +62,10 @@ def token_airdrop(token_agent, amount: NU, origin: str, addresses: List[str]):
return receipts
def free_gas_price_strategy(w3, transaction_params=None):
return 0
class TesterBlockchain(BlockchainDeployerInterface):
"""
Blockchain subclass with additional test utility methods and options.
@ -69,6 +73,9 @@ class TesterBlockchain(BlockchainDeployerInterface):
_instance = None
GAS_STRATEGIES = {**BlockchainDeployerInterface.GAS_STRATEGIES,
'free': free_gas_price_strategy}
_PROVIDER_URI = 'tester://pyevm'
TEST_CONTRACTS_DIR = os.path.join(BASE_DIR, 'tests', 'blockchain', 'eth', 'contracts', 'contracts')
_compiler = SolidityCompiler(source_dirs=[(SolidityCompiler.default_contract_dir(), {TEST_CONTRACTS_DIR})])
@ -124,17 +131,9 @@ class TesterBlockchain(BlockchainDeployerInterface):
if eth_airdrop is True: # ETH for everyone!
self.ether_airdrop(amount=DEVELOPMENT_ETH_AIRDROP_AMOUNT)
@staticmethod
def free_gas_price_strategy(w3, transaction_params=None):
return 0
def attach_middleware(self):
# For use with Proof-Of-Authority test-blockchains
if self.poa is True:
self.log.debug('Injecting POA middleware at layer 0')
self.client.inject_middleware(geth_poa_middleware, layer=0)
if self.free_transactions:
self.w3.eth.setGasPriceStrategy(self.free_gas_price_strategy)
self.w3.eth.setGasPriceStrategy(free_gas_price_strategy)
def __generate_insecure_unlocked_accounts(self, quantity: int) -> List[str]: