当前位置: 首页>>代码示例>>Python>>正文


Python tester.gas_limit方法代码示例

本文整理汇总了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 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:27,代码来源:test_contracts.py

示例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 
开发者ID:golemfactory,项目名称:golem-crowdfunding,代码行数:18,代码来源:test_cf_100k.py

示例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 
开发者ID:ethereum,项目名称:eth-tester,代码行数:32,代码来源:main.py

示例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) 
开发者ID:raiden-network,项目名称:raiden,代码行数:11,代码来源:tester_client.py

示例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)) 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:13,代码来源:stress_test.py

示例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 
开发者ID:ConsenSys,项目名称:singulardtv-contracts,代码行数:9,代码来源:abstract_test.py

示例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) 
开发者ID:golemfactory,项目名称:golem-crowdfunding,代码行数:11,代码来源:test_cf_100k.py

示例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 
开发者ID:gnosis,项目名称:gnosis-contracts,代码行数:7,代码来源:abstract_test.py

示例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) 
开发者ID:gnosis,项目名称:gnosis-contracts,代码行数:54,代码来源:test_futarchy_oracle.py

示例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) 
开发者ID:delphi-markets,项目名称:delphi-framework,代码行数:54,代码来源:test_futarchy_oracle.py


注:本文中的ethereum.tester.gas_limit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。