本文整理匯總了Python中ethereum.tester.keys方法的典型用法代碼示例。如果您正苦於以下問題:Python tester.keys方法的具體用法?Python tester.keys怎麽用?Python tester.keys使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ethereum.tester
的用法示例。
在下文中一共展示了tester.keys方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_owner_2of3_rem_add
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import keys [as 別名]
def test_owner_2of3_rem_add(self):
n_wallet_owners = 3
wallet, wallet_owners, wallet_owner_keys, translator = self.deploy_wallet(n_wallet_owners,
required=2)
self.state.mine(1)
old_acc = tester.accounts[0]
assert wallet.isOwner(old_acc)
rem_old = translator.encode_function_call('removeOwner', [old_acc])
wallet.submitTransaction(wallet.address, 0, rem_old,
10001, sender=tester.keys[1])
wallet.submitTransaction(wallet.address, 0, rem_old,
10001, sender=tester.keys[2])
assert not wallet.isOwner(old_acc)
self.state.mine(1)
new_acc = tester.accounts[9]
assert not wallet.isOwner(new_acc)
add_new = translator.encode_function_call('addOwner', [new_acc])
wallet.submitTransaction(wallet.address, 0, add_new,
10001, sender=tester.keys[1])
wallet.submitTransaction(wallet.address, 0, add_new,
10001, sender=tester.keys[2])
assert wallet.isOwner(new_acc)
示例2: test_deploy
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import keys [as 別名]
def test_deploy(self):
n_wallet_owners = 3
wallet, wallet_owners, wallet_owner_keys, _ = self.deploy_wallet(n_wallet_owners)
wallet_owner_balances = [self.state.block.get_balance(wallet_owners[i])
for i in xrange(n_wallet_owners)]
# Send eth to the wallet contract
to_send = 10 * denoms.ether
gas_before = self.state.block.gas_used
self.state.send(tester.keys[8], wallet.address, to_send)
gas_used = self.state.block.gas_used - gas_before
gas_bonus = gas_used * tester.gas_price
wallet_owner_balances[0] += gas_bonus
assert self.state.block.get_balance(wallet.address) == to_send
assert all([self.state.block.get_balance(wallet_owners[i]) == b
for i, b in enumerate(wallet_owner_balances)])
示例3: test_finalize
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import keys [as 別名]
def test_finalize(self):
n_wallet_owners = 3
wallet, wallet_owners, wallet_owner_keys, _ = self.deploy_wallet(n_wallet_owners, required=2)
self.state.mine(1)
contract, translator = self.deploy_contract(2, 3, founder=wallet.address)
wallet_balance_init = self.state.block.get_balance(wallet.address)
self.state.mine(2)
# Send funds to contract to achieve mincap
to_send = 200000 * denoms.ether
contract.create(sender=tester.keys[9], value=to_send)
# wait for end of funding period and finalize from multisig
self.state.mine(2)
finalize = translator.encode_function_call('finalize', [])
wallet.submitTransaction(contract.address, 0, finalize,
10001, sender=tester.keys[0])
wallet.submitTransaction(contract.address, 0, finalize,
10001, sender=tester.keys[1])
assert self.state.block.get_balance(wallet.address) == to_send - wallet_balance_init
示例4: test_deploy
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import keys [as 別名]
def test_deploy(self):
n_wallet_owners = 3
wallet, wallet_owners, wallet_owner_keys = self.deploy_wallet(n_wallet_owners)
wallet_owner_balances = [self.state.block.get_balance(wallet_owners[i])
for i in xrange(n_wallet_owners)]
# Send eth to the wallet contract
to_send = 10 * denoms.ether
gas_before = self.state.block.gas_used
self.state.send(tester.keys[8], wallet.address, to_send)
gas_used = self.state.block.gas_used - gas_before
gas_bonus = gas_used * tester.gas_price
wallet_owner_balances[0] += gas_bonus
assert self.state.block.get_balance(wallet.address) == to_send
assert all([self.state.block.get_balance(wallet_owners[i]) == b
for i, b in enumerate(wallet_owner_balances)])
示例5: deploy_gnt
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import keys [as 別名]
def deploy_gnt(state, factory, start, end, creator_idx=9, replacements=None):
alloc_helper = ContractHelper(ALLOC_CONTRACT_PATH)
# remove import
alloc_helper.sub([''], regex=IMPORT_TOKEN_REGEX)
# replace import with contract source
gnt_helper = ContractHelper(GNT_CONTRACT_PATH, regex=IMPORT_ALLOC_REGEX)
gnt_helper.sub([alloc_helper.source])
# replace values
for rep, regex in replacements:
gnt_helper.sub(rep, regex)
gas_before = state.block.gas_used
starting_block = state.block.number
contract = state.abi_contract(gnt_helper.source,
language='solidity',
sender=tester.keys[creator_idx],
constructor_parameters=(factory, factory,
starting_block + start,
starting_block + end))
return contract, contract.address, state.block.gas_used - gas_before
示例6: test_gas_for_transfer
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import keys [as 別名]
def test_gas_for_transfer(self):
addr, _ = self.deploy_contract(urandom(20), 1, 2)
self.state.mine(1)
for i, k in enumerate(tester.keys):
v = random.randrange(15000 * denoms.ether, 82000 * denoms.ether)
self.c.create(sender=k, value=v)
self.state.mine(2)
self.c.finalize()
self.state.mine()
self.state.block.coinbase = urandom(20)
costs = []
for i, k in enumerate(tester.keys):
v = random.randrange(1, 15000000 * denoms.ether)
m = self.monitor(i)
self.c.transfer(urandom(20), v, sender=k)
costs.append(m.gas())
print(costs)
assert max(costs) <= 52062
assert min(costs) >= 51342
示例7: test_gas_for_migrate_all
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import keys [as 別名]
def test_gas_for_migrate_all(self):
factory_key = urandom(32)
addr, _ = self.deploy_contract(privtoaddr(factory_key), 1, 2)
self.state.mine(1)
for i, k in enumerate(tester.keys):
v = random.randrange(15000 * denoms.ether, 82000 * denoms.ether)
self.c.create(sender=k, value=v)
self.state.mine(2)
self.c.finalize()
m_addr, _ = self.deploy_migration_contract(addr)
t_addr, _ = self.deploy_target_contract(m_addr)
self.c.setMigrationAgent(m_addr, sender=factory_key)
self.m.setTargetToken(t_addr, sender=tester.k9)
self.state.mine()
self.state.block.coinbase = urandom(20)
costs = []
for i, k in enumerate(tester.keys):
b = self.c.balanceOf(tester.accounts[i])
m = self.monitor(i)
self.c.migrate(b, sender=k)
costs.append(m.gas())
print(costs)
assert max(costs) <= 99304
assert min(costs) >= 56037
示例8: test_gas_for_migrate_half
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import keys [as 別名]
def test_gas_for_migrate_half(self):
factory_key = urandom(32)
addr, _ = self.deploy_contract(privtoaddr(factory_key), 1, 2)
self.state.mine(1)
for i, k in enumerate(tester.keys):
v = random.randrange(15000 * denoms.ether, 82000 * denoms.ether)
self.c.create(sender=k, value=v)
self.state.mine(2)
self.c.finalize()
m_addr, _ = self.deploy_migration_contract(addr)
t_addr, _ = self.deploy_target_contract(m_addr)
self.c.setMigrationAgent(m_addr, sender=factory_key)
self.m.setTargetToken(t_addr, sender=tester.k9)
self.state.mine()
self.state.block.coinbase = urandom(20)
costs = []
for i, k in enumerate(tester.keys):
b = self.c.balanceOf(tester.accounts[i])
m = self.monitor(i)
self.c.migrate(b / 2, sender=k)
costs.append(m.gas())
print(costs)
assert max(costs) <= 114304
assert min(costs) >= 71037
示例9: test_gas_for_set_migration_agent_and_master
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import keys [as 別名]
def test_gas_for_set_migration_agent_and_master(self):
factory_key = urandom(32)
addr, _ = self.deploy_contract(privtoaddr(factory_key), 1, 2)
self.state.mine(1)
for i, k in enumerate(tester.keys):
v = random.randrange(15000 * denoms.ether, 82000 * denoms.ether)
self.c.create(sender=k, value=v)
self.state.mine(2)
self.c.finalize()
m_addr, _ = self.deploy_migration_contract(addr)
self.state.mine()
lg = self.state.block.gas_used
self.c.setMigrationAgent(m_addr, sender=factory_key)
g = self.state.block.gas_used - lg
assert g == 44169
lg = self.state.block.gas_used
self.c.setMigrationMaster(m_addr, sender=factory_key)
g = self.state.block.gas_used - lg
assert g == 28570
示例10: test_gas_for_refund
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import keys [as 別名]
def test_gas_for_refund(self):
addr, _ = self.deploy_contract(urandom(20), 1, 2)
self.state.mine(1)
for i, k in enumerate(tester.keys):
v = random.randrange(1 * denoms.ether, 15000 * denoms.ether)
self.c.create(sender=k, value=v)
self.state.mine(2)
self.state.block.coinbase = urandom(20)
costs = []
for i, k in enumerate(tester.keys):
b = self.c.balanceOf(tester.accounts[i])
m = self.monitor(i, -(b // 1000))
self.c.refund(sender=k)
costs.append(m.gas())
print(costs)
assert max(costs) == 27113
assert min(costs) == 21057
示例11: test_transfer_enabled_after_end_block
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import keys [as 別名]
def test_transfer_enabled_after_end_block(self):
founder = tester.accounts[4]
addr, _ = self.deploy_contract(founder, 3, 13)
assert self.state.block.number == self.starting_block
assert self.c.funding()
for _ in range(13):
self.state.mine()
assert self.c.funding()
assert self.state.block.number == self.starting_block + 13
# ensure min funding met
v = self.c.tokenCreationMin() / self.c.tokenCreationRate()
self.c.create(sender=tester.keys[1], value=v)
self.state.mine()
self.c.finalize()
for _ in range(11):
self.state.mine()
assert not self.c.funding()
示例12: test_transfer_enabled_after_max_fund_reached
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import keys [as 別名]
def test_transfer_enabled_after_max_fund_reached(self):
founder = tester.accounts[2]
addr, _ = self.deploy_contract(founder, 3, 7)
assert self.c.funding()
for _ in range(3):
self.state.mine()
assert self.c.funding()
assert self.state.block.number == self.starting_block + 3
self.c.create(sender=tester.keys[0], value=11)
assert self.c.funding()
self.c.create(sender=tester.keys[1], value=self.c.tokenCreationCap() / self.c.tokenCreationRate() - 11)
assert self.c.funding()
for _ in range(8):
self.state.mine()
assert self.c.funding()
# Transfer is enabled after the funding is finalized.
self.c.finalize(sender=tester.k5)
assert not self.c.funding()
示例13: test_wallet_looping_in_payable
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import keys [as 別名]
def test_wallet_looping_in_payable(self):
founder = tester.accounts[9]
key = tester.keys[9]
wallet_addr, g0 = self.deploy_wallet(founder)
assert 0 == self.wallet.get_out_i(sender=key)
self.wallet.set_extra_work(1, sender=key)
extra = 10 # 601 passes, 602 fails send
value = 11000
self.wallet.set_extra_work(extra)
self.state.mine(1)
initial_b = self.state.block.get_balance(wallet_addr)
self.state.send(tester.keys[0], wallet_addr, value)
self.state.mine(1)
current_b = self.state.block.get_balance(wallet_addr)
assert extra == self.wallet.get_out_i(sender=key)
assert current_b == initial_b + value
示例14: test_good_wallet
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import keys [as 別名]
def test_good_wallet(self):
founder = tester.accounts[9]
key = tester.keys[9]
wallet_addr, g0 = self.deploy_wallet(founder)
c_addr = self.deploy_contract_on_wallet(wallet_addr, 1, 2)
value = int(self.c.tokenCreationMin() / self.c.tokenCreationRate())
self.state.mine(1)
self.c.create(sender=tester.k1, value=value)
self.state.mine(3)
extra = 0
self.wallet.set_extra_work(extra)
assert extra == self.wallet.get_extra_work()
initial_b = self.state.block.get_balance(wallet_addr)
self.wallet.finalize(c_addr, sender=key)
self.state.mine(1)
current_b = self.state.block.get_balance(wallet_addr)
assert current_b == initial_b + value
assert extra == self.wallet.get_out_i(sender=key)
示例15: create_contract
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import keys [as 別名]
def create_contract(self, path, params=None, libraries=None, sender=None):
path, extra_args = self.get_dirs(path)
if params:
params = [x.address if isinstance(x, t.ABIContract) else x for x in params]
if libraries:
for name, address in libraries.items():
if type(address) == str:
if self.is_hex(address):
libraries[name] = address
else:
libraries[name] = encode(address, 'hex')
elif isinstance(address, t.ABIContract):
libraries[name] = encode(address.address, 'hex')
else:
raise ValueError
return self.s.abi_contract(None,
path=path,
constructor_parameters=params,
libraries=libraries,
language='solidity',
extra_args=extra_args,
sender=keys[sender if sender else 0])