-
Notifications
You must be signed in to change notification settings - Fork 135
/
structs_marshal_rlp_test.go
50 lines (45 loc) · 1.13 KB
/
structs_marshal_rlp_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package ethgo
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/umbracle/fastrlp"
)
func TestEncodingRLP_Transaction_Fuzz(t *testing.T) {
testTransaction := func(t *testing.T, typ TransactionType) {
obj := &Transaction{}
err := fastrlp.Fuzz(100, obj,
fastrlp.WithDefaults(func(obj fastrlp.FuzzObject) {
obj.(*Transaction).Type = typ
}),
fastrlp.WithPostHook(func(obj fastrlp.FuzzObject) error {
// Test that the hash from unmarshal is the same as the one computed
txn := obj.(*Transaction)
cHash, err := txn.GetHash()
if err != nil {
return err
}
if cHash != txn.Hash {
return fmt.Errorf("hash not equal")
}
return nil
}),
)
assert.NoError(t, err)
}
t.Run("legacy", func(t *testing.T) {
testTransaction(t, TransactionLegacy)
})
t.Run("accesslist", func(t *testing.T) {
testTransaction(t, TransactionAccessList)
})
t.Run("dynamicfee", func(t *testing.T) {
testTransaction(t, TransactionDynamicFee)
})
}
func TestEncodingRLP_AccessList_Fuzz(t *testing.T) {
obj := &AccessList{}
if err := fastrlp.Fuzz(100, obj); err != nil {
t.Fatal(err)
}
}