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

Commit 00e7aa1

Browse files
committed
TestHeaderExtraJSON
1 parent 3ed695a commit 00e7aa1

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

core/types/header_ext_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,41 @@ func TestHeaderExtraRLP(t *testing.T) {
6969
assert.Equal(t, wantExtra, decodedExtra)
7070
}
7171

72+
func TestHeaderExtraJSON(t *testing.T) {
73+
t.Parallel()
74+
75+
eth := &ethtypes.Header{
76+
ParentHash: common.Hash{1},
77+
// Required json fields
78+
Difficulty: big.NewInt(2),
79+
Number: big.NewInt(3),
80+
}
81+
extra := &HeaderExtra{
82+
ExtDataHash: common.Hash{2},
83+
}
84+
85+
encoded, err := extra.EncodeJSON(eth)
86+
require.NoError(t, err)
87+
88+
decodedExtra := new(HeaderExtra)
89+
decodedEth := new(ethtypes.Header)
90+
err = decodedExtra.DecodeJSON(decodedEth, encoded)
91+
require.NoError(t, err)
92+
93+
wantEth := &ethtypes.Header{
94+
ParentHash: common.Hash{1},
95+
Difficulty: big.NewInt(2),
96+
Number: big.NewInt(3),
97+
Extra: []byte{},
98+
}
99+
assert.Equal(t, wantEth, decodedEth)
100+
101+
wantExtra := &HeaderExtra{
102+
ExtDataHash: common.Hash{2},
103+
}
104+
assert.Equal(t, wantExtra, decodedExtra)
105+
}
106+
72107
func TestHeaderSerializable_updates(t *testing.T) {
73108
t.Parallel()
74109

0 commit comments

Comments
 (0)