Пример #1
0
def test_estimate_gas_on_full_block(chain, funded_address_private_key, funded_address):

    def estimation_txn(chain, from_, from_key, data):
        to = decode_hex('0xa94f5374fce5edbc8e2a8697c15331677e6ebf0c')
        gas = chain.header.gas_limit
        amount = 200
        vm = chain.get_vm()
        return new_transaction(vm, from_, to, amount, from_key, gas=gas, data=data)

    from_ = funded_address
    from_key = funded_address_private_key
    garbage_data = b"""
        fill up the block much faster because this transaction contains a bunch of extra
        garbage_data, which doesn't add to execution time, just the gas costs
    """ * 30
    gas = 375000

    # fill the canonical head
    fill_block(chain, from_, from_key, gas, garbage_data)
    chain.import_block(chain.get_vm().block)

    # build a transaction to estimate gas for
    next_canonical_tx = estimation_txn(chain, from_, from_key, data=garbage_data * 2)

    assert chain.estimate_gas(next_canonical_tx) == 722760

    # fill the pending block
    fill_block(chain, from_, from_key, gas, garbage_data)

    # build a transaction to estimate gas for
    next_pending_tx = estimation_txn(chain, from_, from_key, data=garbage_data * 2)

    assert chain.estimate_gas(next_pending_tx, chain.header) == 722760
Пример #2
0
def test_estimate_gas_on_full_block(chain_without_block_validation_from_vm,
                                    vm_cls, expected,
                                    funded_address_private_key,
                                    funded_address):
    def mk_estimation_txn(chain, from_, from_key, data):
        vm = chain.get_vm()
        tx_params = dict(from_=from_,
                         to=ADDR_1010,
                         amount=200,
                         private_key=from_key,
                         gas=chain.header.gas_limit,
                         data=data)
        return new_transaction(vm, **tx_params)

    chain = chain_without_block_validation_from_vm(vm_cls)
    from_ = funded_address
    from_key = funded_address_private_key
    garbage_data = b"""
        fill up the block much faster because this transaction contains a bunch of extra
        garbage_data, which doesn't add to execution time, just the gas costs
    """ * 30
    gas = 375000

    # fill the canonical head
    fill_block(chain, from_, from_key, gas, garbage_data)
    chain.import_block(chain.get_vm().get_block())

    # build a transaction to estimate gas for
    next_canonical_tx = mk_estimation_txn(chain,
                                          from_,
                                          from_key,
                                          data=garbage_data * 2)

    assert chain.estimate_gas(next_canonical_tx) == expected

    # fill the pending block
    fill_block(chain, from_, from_key, gas, garbage_data)

    # build a transaction to estimate gas for
    next_pending_tx = mk_estimation_txn(chain,
                                        from_,
                                        from_key,
                                        data=garbage_data * 2)

    assert chain.estimate_gas(next_pending_tx, chain.header) == expected