@@ -3725,3 +3725,45 @@ func TestCreateAccessListWithStateOverrides(t *testing.T) {
3725
3725
}}
3726
3726
require .Equal (t , expected , result .Accesslist )
3727
3727
}
3728
+
3729
+ func TestEstimateGasWithMovePrecompile (t * testing.T ) {
3730
+ t .Parallel ()
3731
+ // Initialize test accounts
3732
+ var (
3733
+ accounts = newAccounts (2 )
3734
+ genesis = & core.Genesis {
3735
+ Config : params .MergedTestChainConfig ,
3736
+ Alloc : types.GenesisAlloc {
3737
+ accounts [0 ].addr : {Balance : big .NewInt (params .Ether )},
3738
+ },
3739
+ }
3740
+ )
3741
+ backend := newTestBackend (t , 1 , genesis , beacon .New (ethash .NewFaker ()), func (i int , b * core.BlockGen ) {
3742
+ b .SetPoS ()
3743
+ })
3744
+ api := NewBlockChainAPI (backend )
3745
+ // Move SHA256 precompile (0x2) to a new address (0x100)
3746
+ // and estimate gas for calling the moved precompile.
3747
+ var (
3748
+ sha256Addr = common .BytesToAddress ([]byte {0x2 })
3749
+ newSha256Addr = common .BytesToAddress ([]byte {0x10 , 0 })
3750
+ sha256Input = hexutil .Bytes ([]byte ("hello" ))
3751
+ args = TransactionArgs {
3752
+ From : & accounts [0 ].addr ,
3753
+ To : & newSha256Addr ,
3754
+ Data : & sha256Input ,
3755
+ }
3756
+ overrides = & override.StateOverride {
3757
+ sha256Addr : override.OverrideAccount {
3758
+ MovePrecompileTo : & newSha256Addr ,
3759
+ },
3760
+ }
3761
+ )
3762
+ gas , err := api .EstimateGas (context .Background (), args , nil , overrides , nil )
3763
+ if err != nil {
3764
+ t .Fatalf ("EstimateGas failed: %v" , err )
3765
+ }
3766
+ if gas != 21366 {
3767
+ t .Fatalf ("mismatched gas: %d, want 21366" , gas )
3768
+ }
3769
+ }
0 commit comments