mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 21:56:43 +00:00
add test
This commit is contained in:
parent
b4f1640675
commit
7ae580462b
1 changed files with 42 additions and 0 deletions
|
|
@ -3740,3 +3740,45 @@ func TestCreateAccessListWithStateOverrides(t *testing.T) {
|
|||
}}
|
||||
require.Equal(t, expected, result.Accesslist)
|
||||
}
|
||||
|
||||
func TestEstimateGasWithMovePrecompile(t *testing.T) {
|
||||
t.Parallel()
|
||||
// Initialize test accounts
|
||||
var (
|
||||
accounts = newAccounts(2)
|
||||
genesis = &core.Genesis{
|
||||
Config: params.MergedTestChainConfig,
|
||||
Alloc: types.GenesisAlloc{
|
||||
accounts[0].addr: {Balance: big.NewInt(params.Ether)},
|
||||
},
|
||||
}
|
||||
)
|
||||
backend := newTestBackend(t, 1, genesis, beacon.New(ethash.NewFaker()), func(i int, b *core.BlockGen) {
|
||||
b.SetPoS()
|
||||
})
|
||||
api := NewBlockChainAPI(backend)
|
||||
// Move SHA256 precompile (0x2) to a new address (0x100)
|
||||
// and estimate gas for calling the moved precompile.
|
||||
var (
|
||||
sha256Addr = common.BytesToAddress([]byte{0x2})
|
||||
newSha256Addr = common.BytesToAddress([]byte{0x10, 0})
|
||||
sha256Input = hexutil.Bytes([]byte("hello"))
|
||||
args = TransactionArgs{
|
||||
From: &accounts[0].addr,
|
||||
To: &newSha256Addr,
|
||||
Data: &sha256Input,
|
||||
}
|
||||
overrides = &override.StateOverride{
|
||||
sha256Addr: override.OverrideAccount{
|
||||
MovePrecompileTo: &newSha256Addr,
|
||||
},
|
||||
}
|
||||
)
|
||||
gas, err := api.EstimateGas(context.Background(), args, nil, overrides, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("EstimateGas failed: %v", err)
|
||||
}
|
||||
if gas != 21366 {
|
||||
t.Fatalf("mismatched gas: %d, want 21366", gas)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue