Skip to content

Commit

Permalink
Quiet down TestBodyRLPBackwardsCompatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Feb 11, 2025
1 parent 2bdeb71 commit 5cc4a70
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions core/types/rlp_backwards_compat.libevm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,25 +149,24 @@ func TestBodyRLPBackwardsCompatibility(t *testing.T) {

for _, body := range bodies {
t.Run("", func(t *testing.T) {
t.Logf("\n%s", pretty.Sprint(body))

// The original [Body] doesn't implement [rlp.Encoder] nor
// [rlp.Decoder] so we can use a methodless equivalent as the gold
// standard.
type withoutMethods Body
wantRLP, err := rlp.EncodeToBytes((*withoutMethods)(body))
require.NoErrorf(t, err, "rlp.EncodeToBytes([%T with methods stripped])", body)
require.NoErrorf(t, err, "rlp.EncodeToBytes([%T with methods stripped]) - body %s", body, pretty.Sprint(body))

t.Run("Encode", func(t *testing.T) {
got, err := rlp.EncodeToBytes(body)
require.NoErrorf(t, err, "rlp.EncodeToBytes(%#v)", body)
assert.Equalf(t, wantRLP, got, "rlp.EncodeToBytes(%#v)", body)
require.NoErrorf(t, err, "rlp.EncodeToBytes(%s)", pretty.Sprint(body))
assert.Equalf(t, wantRLP, got, "rlp.EncodeToBytes(%s)", pretty.Sprint(body))
})

t.Run("Decode", func(t *testing.T) {
got := new(Body)
err := rlp.DecodeBytes(wantRLP, got)
require.NoErrorf(t, err, "rlp.DecodeBytes(%v, %T)", wantRLP, got)
require.NoErrorf(t, err, "rlp.DecodeBytes(rlp.EncodeToBytes(%s), %T) resulted in %s",
pretty.Sprint(body), got, pretty.Sprint(got))

// Note we do not specify field names to enforce all fields are set.
gotWithoutExtra := testBodyWithoutExtra{
Expand All @@ -194,7 +193,7 @@ func TestBodyRLPBackwardsCompatibility(t *testing.T) {
cmpeth.CompareTransactionsByBinary(t),
}
if diff := cmp.Diff(want, gotWithoutExtra, opts); diff != "" {
t.Errorf("rlp.DecodeBytes(rlp.EncodeToBytes(%#v)) diff (-want +got):\n%s", want, diff)
t.Errorf("rlp.DecodeBytes(rlp.EncodeToBytes(%s)) diff (-want +got):\n%s", pretty.Sprint(want), diff)
}
})
})
Expand Down

0 comments on commit 5cc4a70

Please sign in to comment.