From e7b05a17801211ac018b04f212ffa00a3484946a Mon Sep 17 00:00:00 2001 From: trajan0x <83933037+trajan0x@users.noreply.github.com> Date: Fri, 18 Aug 2023 16:10:21 -0400 Subject: [PATCH] update foundry tag (#1265) Comply w/ foundry-rs/foundry#5414 Co-authored-by: Trajan0x --- ethergo/backends/anvil/anvil.go | 7 ++--- ethergo/backends/anvil/client.go | 51 +++++++++++++++++++++++++------- 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/ethergo/backends/anvil/anvil.go b/ethergo/backends/anvil/anvil.go index cedc9fe3d3..3727621b69 100644 --- a/ethergo/backends/anvil/anvil.go +++ b/ethergo/backends/anvil/anvil.go @@ -76,10 +76,8 @@ func NewAnvilBackend(ctx context.Context, t *testing.T, args *OptionBuilder) *Ba runOptions := &dockertest.RunOptions{ Repository: "ghcr.io/foundry-rs/foundry", - // Note: https://github.com/foundry-rs/foundry/commit/6e041f9751efa6b75420689b862df05b0934022b introduces a breaking change with regards to - // eth_BsendTransaction. The commit changes the way tx fields are detected. This will be fixed (on the anvil or ethergo sides) in a future version. - Tag: "nightly-7398b65e831f2339d1d0a0bb05ade799e4f9d01e", - Cmd: []string{strings.Join(append([]string{"anvil"}, commandArgs...), " ")}, + Tag: "latest", + Cmd: []string{strings.Join(append([]string{"anvil"}, commandArgs...), " ")}, Labels: map[string]string{ "test-id": uuid.New().String(), }, @@ -347,6 +345,7 @@ func (f *Backend) ImpersonateAccount(ctx context.Context, address common.Address NoSend: true, }) + // TODO: test both legacy and dynamic tx types err = anvilClient.SendUnsignedTransaction(ctx, address, tx) assert.Nilf(f.T(), err, "could not send unsigned transaction for chain %d: %v from %s", f.GetChainID(), err, address.String()) diff --git a/ethergo/backends/anvil/client.go b/ethergo/backends/anvil/client.go index fed16c84b0..2273d4c764 100644 --- a/ethergo/backends/anvil/client.go +++ b/ethergo/backends/anvil/client.go @@ -198,8 +198,8 @@ func (c *Client) EnableTraces(ctx context.Context) error { return c.callAnvilContext(ctx, nil, "enableTraces") } -// anvilTransaction represents a transaction that will serialize to the correct JSON. -type anvilTransaction struct { +// anvilTransactionLegacy represents a transaction that will serialize to the correct JSON. +type anvilTransactionLegacy struct { From string `json:"from"` To string `json:"to"` GasPrice string `json:"gasPrice"` @@ -210,19 +210,48 @@ type anvilTransaction struct { TransactionType string `json:"type"` } +// anvilTransactionDynamic represents a transaction that will serialize to the correct JSON. +type anvilTransactionDynamic struct { + From string `json:"from"` + To string `json:"to"` + MaxFeePerGas string `json:"maxFeePerGas"` + MaxPriorityFeePerGas string `json:"maxPriorityFeePerGas"` + Gas string `json:"gas"` + Value string `json:"value,omitempty"` + Data string `json:"data"` + Nonce string `json:"nonce"` + TransactionType string `json:"type"` +} + // SendUnsignedTransaction sends a transaction to the anvil node. // It is the responsibility of the caller to call impersonateAccount and revertImpersonatedAccount. func (c *Client) SendUnsignedTransaction(ctx context.Context, from common.Address, tx *types.Transaction) error { - anTx := anvilTransaction{ - From: from.Hex(), - To: tx.To().Hex(), - GasPrice: bigIntToString(tx.GasPrice().Int64()), - Gas: bigIntToString(int64(tx.Gas())), - Data: hex.EncodeToString(tx.Data()), - Nonce: bigIntToString(int64(tx.Nonce())), - Value: fmt.Sprintf("%x", tx.Value()), - TransactionType: bigIntToString(int64(tx.Type())), + var anTx interface{} + if tx.Type() == types.LegacyTxType { + anTx = anvilTransactionLegacy{ + From: from.Hex(), + To: tx.To().Hex(), + GasPrice: bigIntToString(tx.GasPrice().Int64()), + Gas: bigIntToString(int64(tx.Gas())), + Data: hex.EncodeToString(tx.Data()), + Nonce: bigIntToString(int64(tx.Nonce())), + Value: fmt.Sprintf("%x", tx.Value()), + TransactionType: bigIntToString(int64(tx.Type())), + } + } else { + anTx = anvilTransactionDynamic{ + From: from.Hex(), + To: tx.To().Hex(), + MaxFeePerGas: bigIntToString(tx.GasPrice().Int64()), + MaxPriorityFeePerGas: bigIntToString(tx.GasPrice().Int64()), + Gas: bigIntToString(int64(tx.Gas())), + Data: hex.EncodeToString(tx.Data()), + Nonce: bigIntToString(int64(tx.Nonce())), + Value: fmt.Sprintf("%x", tx.Value()), + TransactionType: bigIntToString(int64(tx.Type())), + } } + // nolint: wrapcheck return c.CallContext(ctx, nil, "eth_sendTransaction", anTx) }