Skip to content

Commit

Permalink
add test case demonstrating rlp order dependence
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanschalm committed Dec 9, 2024
1 parent b484203 commit a61e30e
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions model/encoding/rlp/rlp_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package rlp_test

import (
"testing"

"github.com/onflow/go-ethereum/rlp"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

// TestRLPStructFieldOrder tests the field ordering property of RLP encoding.
// It provides evidence that RLP encoding depends on struct field ordering.
func TestRLPStructFieldOrder(t *testing.T) {
a := struct {
A uint32 // A first
B uint32
}{A: 2, B: 3}

b := struct {
B uint32 // B first
A uint32
}{A: 2, B: 3}

abin, err := rlp.EncodeToBytes(a)
require.NoError(t, err)
bbin, err := rlp.EncodeToBytes(b)
require.NoError(t, err)
assert.NotEqual(t, abin, bbin)
}

0 comments on commit a61e30e

Please sign in to comment.