add blob test case for estimate gas

This commit is contained in:
Sina Mahmoodi 2024-01-10 17:04:24 +03:30
parent 0b04471b7f
commit 18ba214b02

View file

@ -627,7 +627,7 @@ func TestEstimateGas(t *testing.T) {
var ( var (
accounts = newAccounts(2) accounts = newAccounts(2)
genesis = &core.Genesis{ genesis = &core.Genesis{
Config: params.TestChainConfig, Config: params.MergedTestChainConfig,
Alloc: core.GenesisAlloc{ Alloc: core.GenesisAlloc{
accounts[0].addr: {Balance: big.NewInt(params.Ether)}, accounts[0].addr: {Balance: big.NewInt(params.Ether)},
accounts[1].addr: {Balance: big.NewInt(params.Ether)}, accounts[1].addr: {Balance: big.NewInt(params.Ether)},
@ -637,12 +637,13 @@ func TestEstimateGas(t *testing.T) {
signer = types.HomesteadSigner{} signer = types.HomesteadSigner{}
randomAccounts = newAccounts(2) randomAccounts = newAccounts(2)
) )
api := NewBlockChainAPI(newTestBackend(t, genBlocks, genesis, ethash.NewFaker(), func(i int, b *core.BlockGen) { api := NewBlockChainAPI(newTestBackend(t, genBlocks, genesis, beacon.New(ethash.NewFaker()), func(i int, b *core.BlockGen) {
// Transfer from account[0] to account[1] // Transfer from account[0] to account[1]
// value: 1000 wei // value: 1000 wei
// fee: 0 wei // fee: 0 wei
tx, _ := types.SignTx(types.NewTx(&types.LegacyTx{Nonce: uint64(i), To: &accounts[1].addr, Value: big.NewInt(1000), Gas: params.TxGas, GasPrice: b.BaseFee(), Data: nil}), signer, accounts[0].key) tx, _ := types.SignTx(types.NewTx(&types.LegacyTx{Nonce: uint64(i), To: &accounts[1].addr, Value: big.NewInt(1000), Gas: params.TxGas, GasPrice: b.BaseFee(), Data: nil}), signer, accounts[0].key)
b.AddTx(tx) b.AddTx(tx)
b.SetPoS()
})) }))
var testSuite = []struct { var testSuite = []struct {
blockNumber rpc.BlockNumber blockNumber rpc.BlockNumber
@ -742,6 +743,18 @@ func TestEstimateGas(t *testing.T) {
expectErr: nil, expectErr: nil,
want: 67595, want: 67595,
}, },
// Blobs should have no effect on gas estimate
{
blockNumber: rpc.LatestBlockNumber,
call: TransactionArgs{
From: &accounts[0].addr,
To: &accounts[1].addr,
Value: (*hexutil.Big)(big.NewInt(1)),
BlobVersionedHashes: []common.Hash{common.Hash{0x01, 0x22}},
MaxFeePerBlobGas: (*hexutil.Big)(big.NewInt(1)),
},
want: 21000,
},
} }
for i, tc := range testSuite { for i, tc := range testSuite {
result, err := api.EstimateGas(context.Background(), tc.call, &rpc.BlockNumberOrHash{BlockNumber: &tc.blockNumber}, &tc.overrides) result, err := api.EstimateGas(context.Background(), tc.call, &rpc.BlockNumberOrHash{BlockNumber: &tc.blockNumber}, &tc.overrides)