@@ -29,13 +29,16 @@ import (
29
29
. "github.com/ava-labs/libevm/core/types"
30
30
"github.com/ava-labs/libevm/crypto"
31
31
"github.com/ava-labs/libevm/libevm/ethtest"
32
+ "github.com/ava-labs/libevm/libevm/pseudo"
32
33
"github.com/ava-labs/libevm/rlp"
33
34
)
34
35
35
36
type stubHeaderHooks struct {
36
37
suffix []byte
37
38
gotRawJSONToUnmarshal , gotRawRLPToDecode []byte
38
39
setHeaderToOnUnmarshalOrDecode Header
40
+ accessor pseudo.Accessor [* Header , * stubHeaderHooks ]
41
+ toCopy * stubHeaderHooks
39
42
40
43
errMarshal , errUnmarshal , errEncode , errDecode error
41
44
}
@@ -75,6 +78,10 @@ func (hh *stubHeaderHooks) DecodeRLP(h *Header, s *rlp.Stream) error {
75
78
return hh .errDecode
76
79
}
77
80
81
+ func (hh * stubHeaderHooks ) PostCopy (dst * Header ) {
82
+ hh .accessor .Set (dst , hh .toCopy )
83
+ }
84
+
78
85
func TestHeaderHooks (t * testing.T ) {
79
86
TestOnlyClearRegisteredExtras ()
80
87
defer TestOnlyClearRegisteredExtras ()
@@ -135,6 +142,20 @@ func TestHeaderHooks(t *testing.T) {
135
142
assert .Equalf (t , & stub .setHeaderToOnUnmarshalOrDecode , hdr , "%T after RLP decoding with hook" , hdr )
136
143
})
137
144
145
+ t .Run ("PostCopy" , func (t * testing.T ) {
146
+ hdr := new (Header )
147
+ stub := & stubHeaderHooks {
148
+ accessor : extras .Header ,
149
+ toCopy : & stubHeaderHooks {
150
+ suffix : []byte ("copied" ),
151
+ },
152
+ }
153
+ extras .Header .Set (hdr , stub )
154
+
155
+ got := extras .Header .Get (CopyHeader (hdr ))
156
+ assert .Equal (t , stub .toCopy , got )
157
+ })
158
+
138
159
t .Run ("error_propagation" , func (t * testing.T ) {
139
160
errMarshal := errors .New ("whoops" )
140
161
errUnmarshal := errors .New ("is it broken?" )
0 commit comments