From d4858380ef5afbe9b48adf8ad77549ba6082d673 Mon Sep 17 00:00:00 2001 From: Trajan0x Date: Fri, 18 Aug 2023 20:04:07 +0100 Subject: [PATCH 1/3] fix nightly builds --- ethergo/backends/anvil/anvil.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ethergo/backends/anvil/anvil.go b/ethergo/backends/anvil/anvil.go index cedc9fe3d3..277d47abd2 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(), }, From a4155f73408af0b885f483b06f91844fd160f049 Mon Sep 17 00:00:00 2001 From: Trajan0x Date: Fri, 18 Aug 2023 20:46:15 +0100 Subject: [PATCH 2/3] test anvil txes --- ethergo/backends/anvil/client.go | 51 +++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 11 deletions(-) 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) } From bec60e826465cd450dff6e07720a6e5c1aed627b Mon Sep 17 00:00:00 2001 From: Trajan0x Date: Fri, 18 Aug 2023 20:50:51 +0100 Subject: [PATCH 3/3] document the need for another test [goreleaser] --- ethergo/backends/anvil/anvil.go | 1 + 1 file changed, 1 insertion(+) diff --git a/ethergo/backends/anvil/anvil.go b/ethergo/backends/anvil/anvil.go index 277d47abd2..3727621b69 100644 --- a/ethergo/backends/anvil/anvil.go +++ b/ethergo/backends/anvil/anvil.go @@ -345,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())