本文整理汇总了Python中ethereum.tester.gas_limit方法的典型用法代码示例。如果您正苦于以下问题:Python tester.gas_limit方法的具体用法?Python tester.gas_limit怎么用?Python tester.gas_limit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ethereum.tester
的用法示例。
在下文中一共展示了tester.gas_limit方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_suicider
# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import gas_limit [as 别名]
def test_suicider():
s = tester.state()
c = s.abi_contract(suicider_code)
prev_gas_limit = tester.gas_limit
tester.gas_limit = 200000
# Run normally: suicide processes, so the attempt to ping the
# contract fails
c.entry(5)
o2 = c.ping_ten()
assert o2 is None
c = s.abi_contract(suicider_code)
# Run the suicider in such a way that it suicides in a sub-call,
# then runs out of gas, leading to a revert of the suicide and the
# storage mutation
c.entry(8000)
# Check that the suicide got reverted
o2 = c.ping_ten()
assert o2 == 10
# Check that the storage op got reverted
o3 = c.ping_storage15()
assert o3 == 20
tester.gas_limit = prev_gas_limit
# Test reverts
示例2: setUp
# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import gas_limit [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
示例3: _send_evm_transaction
# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import gas_limit [as 别名]
def _send_evm_transaction(tester_module, evm, transaction):
from ethereum import tester
try:
# record the current gas price so that it can be reset after sending
# the transaction.
pre_transaction_gas_price = tester.gas_price
pre_transaction_gas_limit = tester.gas_limit
# set the evm gas price to the one specified by the transaction.
tester.gas_price = transaction.get('gas_price', tester.gas_price)
tester.gas_limit = transaction['gas']
# get the private key of the sender.
try:
sender = tester.keys[tester.accounts.index(transaction['from'])]
except ValueError:
sender = evm.extra_accounts[transaction['from']]
output = evm.send(
sender=sender,
to=transaction.get('to', b''),
value=transaction.get('value', 0),
evmdata=transaction.get('data', b''),
)
finally:
# revert the tester gas price back to the original value.
tester.gas_price = pre_transaction_gas_price
tester.gas_limit = pre_transaction_gas_limit
return output
示例4: register_endpoint
# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import gas_limit [as 别名]
def register_endpoint(self, node_address, endpoint):
if node_address != privatekey_to_address(self.private_key):
raise ValueError('node_address doesnt match this node address')
prev_gas_limit = tester.gas_limit
tester.gas_limit = DISCOVERY_REGISTRATION_GAS
self.proxy.registerEndpoint(endpoint)
tester.gas_limit = prev_gas_limit
self.tester_state.mine(number_of_blocks=1)
示例5: test_mul
# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import gas_limit [as 别名]
def test_mul():
set_level(None, 'info')
s = t.state()
c = s.abi_contract(serpent_code)
assert c.mul([1, 0, 0, 1], [2, 3, 4, 5]) == [2, 3, 4, 5]
assert c.exp([0, 1, -1, 0], 24) == [1, 0, 0, 1]
assert c.exp([0, -1, 1, 0], 39) == [0, 1, -1, 0]
t.gas_limit = 100000000
x = time.time()
c.exp([i for i in range(81)], 31415)
print('Exponentiation done in: %f' % (time.time() - x))
示例6: __init__
# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import gas_limit [as 别名]
def __init__(self, *args, **kwargs):
super(AbstractTestContract, self).__init__(*args, **kwargs)
self.pp = PreProcessor()
self.s = t.state()
self.s.block.number = HOMESTEAD_BLOCK
# t.gas_limit = 4712388
t.gas_limit = 2000000
示例7: _send
# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import gas_limit [as 别名]
def _send(self, idx, address, value):
# Retries sending if block gas limit has been reached
try:
self.state.send(self.keys[idx], address, value)
except BlockGasLimitReached:
self.state.mine(1)
print ":: block", self.state.block.number
print "Gas limit:", self.state.block.gas_limit
self._send(idx, address, value)
示例8: __init__
# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import gas_limit [as 别名]
def __init__(self, *args, **kwargs):
super(AbstractTestContracts, self).__init__(*args, **kwargs)
self.s = t.state()
self.s.block.number = self.HOMESTEAD_BLOCK
t.gas_limit = 4712388
示例9: test
# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import gas_limit [as 别名]
def test(self):
t.gas_limit = 4712388*4 # Creation gas cost is above gas limit!!!
# Create futarchy oracle
ipfs_hash = b'QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG'
oracle = self.contract_at(self.centralized_oracle_factory.createCentralizedOracle(ipfs_hash), self.oracle_abi)
fee = 50000 # 5%
lower = -100
upper = 100
deadline = self.s.block.timestamp + 60*60 # in 1h
creator = 0
profiling = self.futarchy_factory.createFutarchyOracle(self.ether_token.address, oracle.address, 2, lower, upper,
self.market_factory.address, self.lmsr.address, fee,
deadline, sender=keys[creator], profiling=True)
self.assertLess(profiling['gas'], 20000000)
futarchy = self.contract_at(profiling['output'], self.futarchy_abi)
categorical_event = self.contract_at(futarchy.categoricalEvent(), self.event_abi)
# Fund markets
collateral_token_count = 10**18
self.ether_token.deposit(value=collateral_token_count, sender=keys[creator])
self.assertEqual(self.ether_token.balanceOf(accounts[creator]), collateral_token_count)
self.ether_token.approve(futarchy.address, collateral_token_count, sender=keys[creator])
futarchy.fund(collateral_token_count, sender=keys[creator])
# Buy into market for outcome token 1
market = self.contract_at(futarchy.markets(1), self.market_abi)
buyer = 1
outcome = 1
token_count = 10 ** 15
outcome_token_cost = self.lmsr.calcCost(market.address, outcome, token_count)
fee = market.calcMarketFee(outcome_token_cost)
cost = outcome_token_cost + fee
# Buy all outcomes
self.ether_token.deposit(value=cost, sender=keys[buyer])
self.ether_token.approve(categorical_event.address, cost, sender=keys[buyer])
categorical_event.buyAllOutcomes(cost, sender=keys[buyer])
collateral_token = self.contract_at(categorical_event.outcomeTokens(1), self.token_abi)
collateral_token.approve(market.address, cost, sender=keys[buyer])
self.assertEqual(market.buy(outcome, token_count, cost, sender=keys[buyer]), cost)
# Set outcome of futarchy oracle
self.assertRaises(TransactionFailed, futarchy.setOutcome)
self.s.block.timestamp = deadline
futarchy.setOutcome()
self.assertTrue(futarchy.isOutcomeSet())
self.assertEqual(futarchy.getOutcome(), 1)
categorical_event.setOutcome()
# Set winning outcome for scalar events
self.assertRaises(TransactionFailed, futarchy.close)
oracle.setOutcome(-50)
scalar_event = self.contract_at(market.eventContract(), self.event_abi)
scalar_event.setOutcome()
# Close winning market and transfer collateral tokens to creator
futarchy.close(sender=keys[creator])
self.assertGreater(self.ether_token.balanceOf(accounts[creator]), collateral_token_count)
示例10: test
# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import gas_limit [as 别名]
def test(self):
t.gas_limit = 4712388*4 # Creation gas cost is above gas limit!!!
# Create futarchy oracle
ipfs_hash = b'QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG'
oracle = self.contract_at(self.arbiter_factory.createArbiter(ipfs_hash), self.oracle_abi)
fee = 50000 # 5%
lower = -100
upper = 100
deadline = self.s.block.timestamp + 60*60 # in 1h
creator = 0
profiling = self.futarchy_factory.createFutarchyOracle(self.ether_token.address, oracle.address, 2, lower, upper,
self.market_factory.address, self.lmsr.address, fee,
deadline, sender=keys[creator], profiling=True)
self.assertLess(profiling['gas'], 20000000)
futarchy = self.contract_at(profiling['output'], self.futarchy_abi)
categorical_event = self.contract_at(futarchy.categoricalEvent(), self.event_abi)
# Fund markets
collateral_token_count = 10**18
self.ether_token.deposit(value=collateral_token_count, sender=keys[creator])
self.assertEqual(self.ether_token.balanceOf(accounts[creator]), collateral_token_count)
self.ether_token.approve(futarchy.address, collateral_token_count, sender=keys[creator])
futarchy.fund(collateral_token_count, sender=keys[creator])
# Buy into market for outcome token 1
market = self.contract_at(futarchy.markets(1), self.market_abi)
buyer = 1
outcome = 1
token_count = 10 ** 15
outcome_token_cost = self.lmsr.calcCost(market.address, outcome, token_count)
fee = market.calcMarketFee(outcome_token_cost)
cost = outcome_token_cost + fee
# Buy all outcomes
self.ether_token.deposit(value=cost, sender=keys[buyer])
self.ether_token.approve(categorical_event.address, cost, sender=keys[buyer])
categorical_event.buyAllOutcomes(cost, sender=keys[buyer])
collateral_token = self.contract_at(categorical_event.outcomeTokens(1), self.token_abi)
collateral_token.approve(market.address, cost, sender=keys[buyer])
self.assertEqual(market.buy(outcome, token_count, cost, sender=keys[buyer]), cost)
# Set outcome of futarchy oracle
self.assertRaises(TransactionFailed, futarchy.setOutcome)
self.s.block.timestamp = deadline
futarchy.setOutcome()
self.assertTrue(futarchy.isOutcomeSet())
self.assertEqual(futarchy.getOutcome(), 1)
categorical_event.setOutcome()
# Set winning outcome for scalar events
self.assertRaises(TransactionFailed, futarchy.close)
oracle.setOutcome(-50)
scalar_event = self.contract_at(market.eventContract(), self.event_abi)
scalar_event.setOutcome()
# Close winning market and transfer collateral tokens to creator
futarchy.close(sender=keys[creator])
self.assertGreater(self.ether_token.balanceOf(accounts[creator]), collateral_token_count)