Skip to content

Commit 4042a9b

Browse files
committed
fix
1 parent 5691d73 commit 4042a9b

File tree

2 files changed

+70
-100
lines changed

2 files changed

+70
-100
lines changed

ethclient/ethclient.go

Lines changed: 22 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"github.com/ethereum/go-ethereum/common"
2929
"github.com/ethereum/go-ethereum/common/hexutil"
3030
"github.com/ethereum/go-ethereum/core/types"
31-
"github.com/ethereum/go-ethereum/crypto/kzg4844"
31+
"github.com/ethereum/go-ethereum/ethclient/gethclient"
3232
"github.com/ethereum/go-ethereum/rpc"
3333
)
3434

@@ -831,59 +831,27 @@ type SimulateOptions struct {
831831

832832
// SimulateBlock represents a batch of calls to be simulated.
833833
type SimulateBlock struct {
834-
BlockOverrides *BlockOverrides `json:"blockOverrides,omitempty"`
835-
StateOverrides *StateOverride `json:"stateOverrides,omitempty"`
836-
Calls []CallArgs `json:"calls"`
837-
}
838-
839-
// BlockOverrides is a set of header fields to override.
840-
type BlockOverrides struct {
841-
Number *hexutil.Big `json:"number,omitempty"`
842-
Difficulty *hexutil.Big `json:"difficulty,omitempty"`
843-
Time *hexutil.Uint64 `json:"time,omitempty"`
844-
GasLimit *hexutil.Uint64 `json:"gasLimit,omitempty"`
845-
FeeRecipient *common.Address `json:"feeRecipient,omitempty"`
846-
PrevRandao *common.Hash `json:"prevRandao,omitempty"`
847-
BaseFeePerGas *hexutil.Big `json:"baseFeePerGas,omitempty"`
848-
BlobBaseFee *hexutil.Big `json:"blobBaseFee,omitempty"`
849-
BeaconRoot *common.Hash `json:"beaconRoot,omitempty"`
850-
Withdrawals *types.Withdrawals `json:"withdrawals,omitempty"`
851-
}
852-
853-
// StateOverride is the collection of overridden accounts.
854-
type StateOverride map[common.Address]OverrideAccount
855-
856-
// OverrideAccount indicates the overriding fields of account during the execution
857-
// of a message call.
858-
type OverrideAccount struct {
859-
Nonce *hexutil.Uint64 `json:"nonce,omitempty"`
860-
Code *hexutil.Bytes `json:"code,omitempty"`
861-
Balance *hexutil.Big `json:"balance,omitempty"`
862-
State map[common.Hash]common.Hash `json:"state,omitempty"`
863-
StateDiff map[common.Hash]common.Hash `json:"stateDiff,omitempty"`
864-
MovePrecompileTo *common.Address `json:"movePrecompileToAddress,omitempty"`
865-
}
866-
867-
// CallArgs represents the arguments to construct a transaction call.
868-
type CallArgs struct {
869-
From *common.Address `json:"from,omitempty"`
870-
To *common.Address `json:"to,omitempty"`
871-
Gas *hexutil.Uint64 `json:"gas,omitempty"`
872-
GasPrice *hexutil.Big `json:"gasPrice,omitempty"`
873-
MaxFeePerGas *hexutil.Big `json:"maxFeePerGas,omitempty"`
874-
MaxPriorityFeePerGas *hexutil.Big `json:"maxPriorityFeePerGas,omitempty"`
875-
Value *hexutil.Big `json:"value,omitempty"`
876-
Nonce *hexutil.Uint64 `json:"nonce,omitempty"`
877-
Data *hexutil.Bytes `json:"data,omitempty"`
878-
Input *hexutil.Bytes `json:"input,omitempty"`
879-
AccessList *types.AccessList `json:"accessList,omitempty"`
880-
ChainID *hexutil.Big `json:"chainId,omitempty"`
881-
BlobFeeCap *hexutil.Big `json:"maxFeePerBlobGas,omitempty"`
882-
BlobHashes []common.Hash `json:"blobVersionedHashes,omitempty"`
883-
Blobs []kzg4844.Blob `json:"blobs,omitempty"`
884-
Commitments []kzg4844.Commitment `json:"commitments,omitempty"`
885-
Proofs []kzg4844.Proof `json:"proofs,omitempty"`
886-
AuthorizationList []types.SetCodeAuthorization `json:"authorizationList,omitempty"`
834+
BlockOverrides *gethclient.BlockOverrides `json:"blockOverrides,omitempty"`
835+
StateOverrides *map[common.Address]gethclient.OverrideAccount `json:"stateOverrides,omitempty"`
836+
Calls []ethereum.CallMsg `json:"calls"`
837+
}
838+
839+
// MarshalJSON implements json.Marshaler for SimulateBlock.
840+
func (s SimulateBlock) MarshalJSON() ([]byte, error) {
841+
type Alias struct {
842+
BlockOverrides *gethclient.BlockOverrides `json:"blockOverrides,omitempty"`
843+
StateOverrides *map[common.Address]gethclient.OverrideAccount `json:"stateOverrides,omitempty"`
844+
Calls []interface{} `json:"calls"`
845+
}
846+
calls := make([]interface{}, len(s.Calls))
847+
for i, call := range s.Calls {
848+
calls[i] = toCallArg(call)
849+
}
850+
return json.Marshal(Alias{
851+
BlockOverrides: s.BlockOverrides,
852+
StateOverrides: s.StateOverrides,
853+
Calls: calls,
854+
})
887855
}
888856

889857
// SimulateCallResult is the result of a simulated call.

ethclient/ethclient_test.go

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"github.com/ethereum/go-ethereum"
3030
"github.com/ethereum/go-ethereum/accounts/abi"
3131
"github.com/ethereum/go-ethereum/common"
32-
"github.com/ethereum/go-ethereum/common/hexutil"
3332
"github.com/ethereum/go-ethereum/consensus/beacon"
3433
"github.com/ethereum/go-ethereum/consensus/ethash"
3534
"github.com/ethereum/go-ethereum/core"
@@ -38,6 +37,7 @@ import (
3837
"github.com/ethereum/go-ethereum/eth"
3938
"github.com/ethereum/go-ethereum/eth/ethconfig"
4039
"github.com/ethereum/go-ethereum/ethclient"
40+
"github.com/ethereum/go-ethereum/ethclient/gethclient"
4141
"github.com/ethereum/go-ethereum/node"
4242
"github.com/ethereum/go-ethereum/params"
4343
"github.com/ethereum/go-ethereum/rpc"
@@ -777,20 +777,20 @@ func TestSimulateV1(t *testing.T) {
777777
// Simple test: transfer ETH from one account to another
778778
from := testAddr
779779
to := common.HexToAddress("0x0000000000000000000000000000000000000001")
780-
value := hexutil.Big(*big.NewInt(100))
781-
gas := hexutil.Uint64(100000)
782-
maxFeePerGas := hexutil.Big(*new(big.Int).Mul(header.BaseFee, big.NewInt(2)))
780+
value := big.NewInt(100)
781+
gas := uint64(100000)
782+
maxFeePerGas := new(big.Int).Mul(header.BaseFee, big.NewInt(2))
783783

784784
opts := ethclient.SimulateOptions{
785785
BlockStateCalls: []ethclient.SimulateBlock{
786786
{
787-
Calls: []ethclient.CallArgs{
787+
Calls: []ethereum.CallMsg{
788788
{
789-
From: &from,
790-
To: &to,
791-
Value: &value,
792-
Gas: &gas,
793-
MaxFeePerGas: &maxFeePerGas,
789+
From: from,
790+
To: &to,
791+
Value: value,
792+
Gas: gas,
793+
GasFeeCap: maxFeePerGas,
794794
},
795795
},
796796
},
@@ -841,26 +841,26 @@ func TestSimulateV1WithBlockOverrides(t *testing.T) {
841841

842842
from := testAddr
843843
to := common.HexToAddress("0x0000000000000000000000000000000000000001")
844-
value := hexutil.Big(*big.NewInt(100))
845-
gas := hexutil.Uint64(100000)
846-
maxFeePerGas := hexutil.Big(*new(big.Int).Mul(header.BaseFee, big.NewInt(2)))
844+
value := big.NewInt(100)
845+
gas := uint64(100000)
846+
maxFeePerGas := new(big.Int).Mul(header.BaseFee, big.NewInt(2))
847847

848848
// Override timestamp only
849-
timestamp := hexutil.Uint64(1234567890)
849+
timestamp := uint64(1234567890)
850850

851851
opts := ethclient.SimulateOptions{
852852
BlockStateCalls: []ethclient.SimulateBlock{
853853
{
854-
BlockOverrides: &ethclient.BlockOverrides{
855-
Time: &timestamp,
854+
BlockOverrides: &gethclient.BlockOverrides{
855+
Time: timestamp,
856856
},
857-
Calls: []ethclient.CallArgs{
857+
Calls: []ethereum.CallMsg{
858858
{
859-
From: &from,
860-
To: &to,
861-
Value: &value,
862-
Gas: &gas,
863-
MaxFeePerGas: &maxFeePerGas,
859+
From: from,
860+
To: &to,
861+
Value: value,
862+
Gas: gas,
863+
GasFeeCap: maxFeePerGas,
864864
},
865865
},
866866
},
@@ -878,7 +878,7 @@ func TestSimulateV1WithBlockOverrides(t *testing.T) {
878878
}
879879

880880
// Verify the timestamp was overridden
881-
if results[0].Timestamp != timestamp {
881+
if uint64(results[0].Timestamp) != timestamp {
882882
t.Errorf("expected timestamp %d, got %d", timestamp, results[0].Timestamp)
883883
}
884884
}
@@ -903,30 +903,32 @@ func TestSimulateV1WithStateOverrides(t *testing.T) {
903903

904904
from := testAddr
905905
to := common.HexToAddress("0x0000000000000000000000000000000000000001")
906-
value := hexutil.Big(*big.NewInt(1000000000000000000)) // 1 ETH
907-
gas := hexutil.Uint64(100000)
908-
maxFeePerGas := hexutil.Big(*new(big.Int).Mul(header.BaseFee, big.NewInt(2)))
906+
value := big.NewInt(1000000000000000000) // 1 ETH
907+
gas := uint64(100000)
908+
maxFeePerGas := new(big.Int).Mul(header.BaseFee, big.NewInt(2))
909909

910910
// Override the balance of the 'from' address
911911
balanceStr := "1000000000000000000000"
912912
balance := new(big.Int)
913913
balance.SetString(balanceStr, 10)
914914

915+
stateOverrides := map[common.Address]gethclient.OverrideAccount{
916+
from: {
917+
Balance: balance,
918+
},
919+
}
920+
915921
opts := ethclient.SimulateOptions{
916922
BlockStateCalls: []ethclient.SimulateBlock{
917923
{
918-
StateOverrides: &ethclient.StateOverride{
919-
from: ethclient.OverrideAccount{
920-
Balance: (*hexutil.Big)(balance),
921-
},
922-
},
923-
Calls: []ethclient.CallArgs{
924+
StateOverrides: &stateOverrides,
925+
Calls: []ethereum.CallMsg{
924926
{
925-
From: &from,
926-
To: &to,
927-
Value: &value,
928-
Gas: &gas,
929-
MaxFeePerGas: &maxFeePerGas,
927+
From: from,
928+
To: &to,
929+
Value: value,
930+
Gas: gas,
931+
GasFeeCap: maxFeePerGas,
930932
},
931933
},
932934
},
@@ -968,20 +970,20 @@ func TestSimulateV1WithBlockNumberOrHash(t *testing.T) {
968970

969971
from := testAddr
970972
to := common.HexToAddress("0x0000000000000000000000000000000000000001")
971-
value := hexutil.Big(*big.NewInt(100))
972-
gas := hexutil.Uint64(100000)
973-
maxFeePerGas := hexutil.Big(*new(big.Int).Mul(header.BaseFee, big.NewInt(2)))
973+
value := big.NewInt(100)
974+
gas := uint64(100000)
975+
maxFeePerGas := new(big.Int).Mul(header.BaseFee, big.NewInt(2))
974976

975977
opts := ethclient.SimulateOptions{
976978
BlockStateCalls: []ethclient.SimulateBlock{
977979
{
978-
Calls: []ethclient.CallArgs{
980+
Calls: []ethereum.CallMsg{
979981
{
980-
From: &from,
981-
To: &to,
982-
Value: &value,
983-
Gas: &gas,
984-
MaxFeePerGas: &maxFeePerGas,
982+
From: from,
983+
To: &to,
984+
Value: value,
985+
Gas: gas,
986+
GasFeeCap: maxFeePerGas,
985987
},
986988
},
987989
},

0 commit comments

Comments
 (0)