Skip to content

Commit

Permalink
eth: Update zz_deepcopy_generated.go (#79)
Browse files Browse the repository at this point in the history
* eth: Update zz_deepcopy_generated.go
* Add a testcase to detect eth.Block.DeepCopy mismatch
  • Loading branch information
ryanschneider authored Feb 22, 2023
1 parent 96eff6c commit ea21e11
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
4 changes: 2 additions & 2 deletions eth/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

18 changes: 18 additions & 0 deletions eth/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
}
37 changes: 37 additions & 0 deletions eth/zz_deepcopy_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ea21e11

Please sign in to comment.