本文整理匯總了Python中ethereum.tester.state方法的典型用法代碼示例。如果您正苦於以下問題:Python tester.state方法的具體用法?Python tester.state怎麽用?Python tester.state使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ethereum.tester
的用法示例。
在下文中一共展示了tester.state方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_transaction_receipt
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import state [as 別名]
def get_transaction_receipt(self, transaction_hash):
block, transaction, transaction_index = _get_transaction_by_hash(
self.evm,
transaction_hash,
)
is_pending = block.number == self.evm.block.number
return serialize_transaction_receipt(
block,
transaction,
block.get_receipt(transaction_index),
transaction_index,
is_pending,
)
#
# Account state
#
示例2: create_and_distribute_token
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import state [as 別名]
def create_and_distribute_token(state,
receivers,
name=None,
amount_per_receiver=1000000):
proxy = state.abi_contract(
None,
path=get_contract_path(TARGETS['token']),
language='solidity',
listen=False,
sender=DEFAULT_KEY,
constructor_parameters=(
len(receivers) * amount_per_receiver,
name,
2,
name[:4].upper()
)
)
for receiver in receivers:
proxy.transfer(receiver, amount_per_receiver)
state.mine(number_of_blocks=1)
return (name, hexlify(proxy.address))
示例3: test_data_feeds
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import state [as 別名]
def test_data_feeds():
s = tester.state()
c = s.abi_contract(data_feed_code, sender=tester.k0)
o2 = c.get(500)
assert o2 == 0
o3 = c.set(500, 19)
assert o3 == 1
o4 = c.get(500)
assert o4 == 19
o5 = c.set(500, 726, sender=tester.k1)
assert o5 == 0
o6 = c.set(500, 726)
assert o6 == 1
return s, c
# Test an example hedging contract, using the data feed. This tests
# contracts calling other contracts
示例4: test_storage_objects
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import state [as 別名]
def test_storage_objects():
s = tester.state()
c = s.abi_contract(storage_object_test_code)
c.ping()
assert 1 == c.query_chessboard(0, 0)
assert 2 == c.query_chessboard(0, 1)
assert 3 == c.query_chessboard(3, 0)
assert [100, 0, 0] == c.query_stats(0)
assert [0, 15, 12] == c.query_stats(1)
assert 0 == c.query_items(1, 3)
assert 0 == c.query_items(0, 2)
assert 9 == c.query_items(1, 2)
assert [555, 556, 656, 559, 1659,
557, 0, 0, 0, 558,
657, 0, 0, 0, 658] == c.query_person()
assert [361, 441] == c.testping(19, 21)
示例5: test_ecrecover
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import state [as 別名]
def test_ecrecover():
s = tester.state()
c = s.abi_contract(ecrecover_code)
priv = utils.sha3('some big long brainwallet password')
pub = bitcoin.privtopub(priv)
msghash = utils.sha3('the quick brown fox jumps over the lazy dog')
pk = PrivateKey(priv, raw=True)
signature = pk.ecdsa_recoverable_serialize(
pk.ecdsa_sign_recoverable(msghash, raw=True)
)
signature = signature[0] + utils.bytearray_to_bytestr([signature[1]])
V = utils.safe_ord(signature[64]) + 27
R = big_endian_to_int(signature[0:32])
S = big_endian_to_int(signature[32:64])
assert bitcoin.ecdsa_raw_verify(msghash, (V, R, S), pub)
addr = utils.big_endian_to_int(utils.sha3(bitcoin.encode_pubkey(pub, 'bin')[1:])[12:])
assert utils.big_endian_to_int(utils.privtoaddr(priv)) == addr
result = c.test_ecrecover(utils.big_endian_to_int(msghash), V, R, S)
assert result == addr
示例6: test_prevhashes
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import state [as 別名]
def test_prevhashes():
s = tester.state()
c = s.abi_contract(prevhashes_code)
s.mine(7)
# Hashes of last 14 blocks including existing one
o1 = [x % 2 ** 256 for x in c.get_prevhashes(14)]
# hash of self = 0, hash of blocks back to genesis block as is, hash of
# blocks before genesis block = 0
t1 = [0] + [utils.big_endian_to_int(b.hash) for b in s.blocks[-2::-1]] \
+ [0] * 6
assert o1 == t1
s.mine(256)
# Test 256 limit: only 1 <= g <= 256 generation ancestors get hashes shown
o2 = [x % 2 ** 256 for x in c.get_prevhashes(270)]
t2 = [0] + [utils.big_endian_to_int(b.hash) for b in s.blocks[-2:-258:-1]] \
+ [0] * 13
assert o2 == t2
示例7: test_abi_logging
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import state [as 別名]
def test_abi_logging():
s = tester.state()
c = s.abi_contract(abi_logging_code)
o = []
s.block.log_listeners.append(lambda x: o.append(c.translator.listen(x)))
c.test_rabbit(3)
assert o == [{"_event_type": b"rabbit", "x": 3}]
o.pop()
c.test_frog(5)
assert o == [{"_event_type": b"frog", "y": 5}]
o.pop()
c.test_moose(7, "nine", 11, [13, 15, 17])
assert o == [{"_event_type": b"moose", "a": 7, "b": b"nine",
"c": 11, "d": [13, 15, 17]}]
o.pop()
c.test_chicken(tester.a0)
assert o == [{"_event_type": b"chicken",
"m": utils.encode_hex(tester.a0)}]
o.pop()
示例8: test_abicontract_interface
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import state [as 別名]
def test_abicontract_interface():
""" Test for issue #370. """
tester_state = state()
contract_path = path.join(CONTRACTS_DIR, 'simple_contract.sol')
simple_compiled = compile_file(contract_path)
simple_address = tester_state.evm(simple_compiled['Simple']['bin'])
# ABIContract class must accept json_abi
abi_json = json.dumps(simple_compiled['Simple']['abi']).encode('utf-8')
abi = ABIContract(
_state=tester_state,
_abi=abi_json,
address=simple_address,
listen=False,
log_listener=None,
default_key=None,
)
assert abi.test() == 1 # pylint: disable=no-member
示例9: test_library_from_file
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import state [as 別名]
def test_library_from_file():
state = tester.state()
state.env.config['HOMESTEAD_FORK_BLKNUM'] = 0 # enable CALLCODE opcode
library = state.abi_contract(
None,
path=path.join(CONTRACTS_DIR, 'seven_library.sol'),
language='solidity',
)
libraries = {
'SevenLibrary': encode_hex(library.address),
}
contract = state.abi_contract(
None,
path=path.join(CONTRACTS_DIR, 'seven_contract.sol'),
libraries=libraries,
language='solidity',
)
# pylint: disable=no-member
assert library.seven() == 7
assert contract.test() == 7
示例10: test_deploy
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import state [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)])
示例11: test_finalize
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import state [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
示例12: setUp
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import state [as 別名]
def setUp(self):
state_file_path = STATE_FILE_NAME
if os.path.isfile(state_file_path):
state_holder = StateHolder.restore(state_file_path)
else:
self.state = tester.state()
c, a, keys, addrs = deploy_contract_and_accounts(self.state, N_PARTICIPANTS,
deploy_contract=False)
state_holder = StateHolder(self.state, c, a, keys, addrs)
state_holder.persist(state_file_path)
self._populate_state_from_holder(state_holder)
self.state.block.gas_limit = calc_block_gas_limit()
print "Gas limit:", self.state.block.gas_limit
示例13: test_deploy
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import state [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)])
示例14: deploy_gnt
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import state [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
示例15: test_gas_for_transfer
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import state [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