From ea21e114f25cf5aa50123559ffb269f1ae8d9293 Mon Sep 17 00:00:00 2001 From: Ryan Schneider Date: Wed, 22 Feb 2023 09:52:39 -0800 Subject: [PATCH] eth: Update zz_deepcopy_generated.go (#79) * eth: Update zz_deepcopy_generated.go * Add a testcase to detect eth.Block.DeepCopy mismatch --- eth/Makefile | 4 ++-- eth/block_test.go | 18 ++++++++++++++++++ eth/zz_deepcopy_generated.go | 37 ++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/eth/Makefile b/eth/Makefile index 3fda484..2b11089 100644 --- a/eth/Makefile +++ b/eth/Makefile @@ -4,9 +4,9 @@ SRC_FILES = $(filter-out zz_deepcopy_generated.go, $(wildcard *.go)) # corresponding *.go changed. # # To install deepcopy-gen simply run: -# GO111MODULE=off go install k8s.io/gengo/examples/deepcopy-gen +# GO111MODULE=off go install k8s.io/code-generator/cmd/deepcopy-gen@latest zz_deepcopy_generated.go: ${SRC_FILES} pushd .. && \ - deepcopy-gen -o . -O zz_deepcopy_generated -i ./eth --go-header-file /dev/null ; \ + deepcopy-gen -O zz_deepcopy_generated -i ./eth --go-header-file /dev/null --trim-path-prefix "github.com/INFURA/go-ethlibs" ; \ popd diff --git a/eth/block_test.go b/eth/block_test.go index 6c182f0..bd5dc1a 100644 --- a/eth/block_test.go +++ b/eth/block_test.go @@ -602,4 +602,22 @@ func TestBlock_ZhejiangBlockMarshalling(t *testing.T) { require.Equal(t, "0xbd0f", block.Withdrawals[15].ValidatorIndex.String()) require.Equal(t, "0xf97e180c050e5Ab072211Ad2C213Eb5AEE4DF134", block.Withdrawals[15].Address.String()) require.Equal(t, "0x2546b", block.Withdrawals[15].Amount.String()) + + t.Run("DeepCopying", func(t *testing.T) { + other := block.DeepCopy() + original, err := json.Marshal(&block) + require.NoError(t, err) + + copied, err := json.Marshal(&other) + require.NoError(t, err) + + require.Len(t, other.Withdrawals, 16) + + require.JSONEq(t, string(original), string(copied)) + + // ensure that block.Withdrawal and other.Withdrawal actually point to two different slices + // mutate other and make sure block isn't changed to ensure not aliases of same slice + other.Withdrawals[0].Index = eth.QuantityFromInt64(0xdeadbeef) + require.NotEqual(t, block.Withdrawals[0].Index.Int64(), other.Withdrawals[0].Index.Int64()) + }) } diff --git a/eth/zz_deepcopy_generated.go b/eth/zz_deepcopy_generated.go index 0e17c60..6618f51 100644 --- a/eth/zz_deepcopy_generated.go +++ b/eth/zz_deepcopy_generated.go @@ -1,3 +1,4 @@ +//go:build !ignore_autogenerated // +build !ignore_autogenerated // Code generated by deepcopy-gen. DO NOT EDIT. @@ -81,6 +82,18 @@ func (in *Block) DeepCopyInto(out *Block) { in, out := &in.BaseFeePerGas, &out.BaseFeePerGas *out = (*in).DeepCopy() } + if in.WithdrawalsRoot != nil { + in, out := &in.WithdrawalsRoot, &out.WithdrawalsRoot + *out = new(Data32) + **out = **in + } + if in.Withdrawals != nil { + in, out := &in.Withdrawals, &out.Withdrawals + *out = make([]Withdrawal, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } if in.Nonce != nil { in, out := &in.Nonce, &out.Nonce *out = new(Data8) @@ -322,6 +335,11 @@ func (in *NewHeadsResult) DeepCopyInto(out *NewHeadsResult) { in, out := &in.BaseFeePerGas, &out.BaseFeePerGas *out = (*in).DeepCopy() } + if in.WithdrawalsRoot != nil { + in, out := &in.WithdrawalsRoot, &out.WithdrawalsRoot + *out = new(Data32) + **out = **in + } if in.Nonce != nil { in, out := &in.Nonce, &out.Nonce *out = new(Data8) @@ -674,3 +692,22 @@ func (in *Uncle) DeepCopy() *Uncle { in.DeepCopyInto(out) return out } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Withdrawal) DeepCopyInto(out *Withdrawal) { + *out = *in + in.Index.DeepCopyInto(&out.Index) + in.ValidatorIndex.DeepCopyInto(&out.ValidatorIndex) + in.Amount.DeepCopyInto(&out.Amount) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Withdrawal. +func (in *Withdrawal) DeepCopy() *Withdrawal { + if in == nil { + return nil + } + out := new(Withdrawal) + in.DeepCopyInto(out) + return out +}