Skip to content
This repository was archived by the owner on Nov 25, 2025. It is now read-only.

Commit 17de2bf

Browse files
committed
TestHeaderExtraRLP
1 parent aa49251 commit 17de2bf

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

core/types/header_ext_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
package types
55

66
import (
7+
"bytes"
78
"math/big"
89
"testing"
910

1011
"github.com/ava-labs/libevm/common"
1112
ethtypes "github.com/ava-labs/libevm/core/types"
13+
"github.com/ava-labs/libevm/rlp"
1214
"github.com/stretchr/testify/assert"
1315
"github.com/stretchr/testify/require"
1416
)
@@ -33,6 +35,40 @@ func TestHeaderExtraGetWith(t *testing.T) {
3335
}, extra)
3436
}
3537

38+
func TestHeaderExtraRLP(t *testing.T) {
39+
t.Parallel()
40+
41+
eth := &ethtypes.Header{
42+
ParentHash: common.Hash{1},
43+
}
44+
extra := &HeaderExtra{
45+
ExtDataHash: common.Hash{2},
46+
}
47+
48+
writer := bytes.NewBuffer(nil)
49+
err := extra.EncodeRLP(eth, writer)
50+
require.NoError(t, err)
51+
52+
stream := rlp.NewStream(bytes.NewReader(writer.Bytes()), 0)
53+
decodedExtra := new(HeaderExtra)
54+
decodedEth := new(ethtypes.Header)
55+
err = decodedExtra.DecodeRLP(decodedEth, stream)
56+
require.NoError(t, err)
57+
58+
wantEth := &ethtypes.Header{
59+
ParentHash: common.Hash{1},
60+
Difficulty: new(big.Int),
61+
Number: new(big.Int),
62+
Extra: []byte{},
63+
}
64+
assert.Equal(t, wantEth, decodedEth)
65+
66+
wantExtra := &HeaderExtra{
67+
ExtDataHash: common.Hash{2},
68+
}
69+
assert.Equal(t, wantExtra, decodedExtra)
70+
}
71+
3672
func TestHeaderSerializable_updates(t *testing.T) {
3773
t.Parallel()
3874

0 commit comments

Comments
 (0)