@@ -22,102 +22,48 @@ import (
2222 . "github.com/centrifuge/go-substrate-rpc-client/v4/types"
2323 . "github.com/centrifuge/go-substrate-rpc-client/v4/types/codec"
2424 . "github.com/centrifuge/go-substrate-rpc-client/v4/types/test_utils"
25- fuzz "github.com/google/gofuzz"
26- "github.com/stretchr/testify/assert"
2725)
2826
2927var (
30- optionWeightFuzzOpts = []FuzzOpt {
31- WithFuzzFuncs (func (o * OptionWeight , c fuzz.Continue ) {
32- if c .RandBool () {
33- * o = NewOptionWeightEmpty ()
34- return
35- }
36-
37- var weight Weight
38-
39- c .Fuzz (& weight )
40-
41- * o = NewOptionWeight (weight )
42- }),
43- }
28+ testWeight = NewWeight (NewUCompactFromUInt (11 ), NewUCompactFromUInt (634 ))
4429)
4530
46- func TestOptionWeight_EncodeDecode (t * testing.T ) {
47- AssertRoundTripFuzz [OptionWeight ](t , 100 , optionWeightFuzzOpts ... )
48- AssertEncodeEmptyObj [OptionWeight ](t , 1 )
49- }
50-
51- func TestOptionWeight_Encode (t * testing.T ) {
52- AssertEncode (t , []EncodingAssert {
53- {NewOptionWeight (NewWeight (0 )), MustHexDecodeString ("0x010000000000000000" )},
54- {NewOptionWeight (NewWeight (1 )), MustHexDecodeString ("0x010100000000000000" )},
55- {NewOptionWeight (NewWeight (2 )), MustHexDecodeString ("0x010200000000000000" )},
56- {NewOptionWeightEmpty (), MustHexDecodeString ("0x00" )},
57- })
58- }
59-
60- func TestOptionWeight_Decode (t * testing.T ) {
61- AssertDecode (t , []DecodingAssert {
62- {MustHexDecodeString ("0x010000000000000000" ), NewOptionWeight (NewWeight (0 ))},
63- {MustHexDecodeString ("0x010100000000000000" ), NewOptionWeight (NewWeight (1 ))},
64- {MustHexDecodeString ("0x010200000000000000" ), NewOptionWeight (NewWeight (2 ))},
65- {MustHexDecodeString ("0x00" ), NewOptionWeightEmpty ()},
66- })
67- }
68-
69- func TestOptionWeight_OptionMethods (t * testing.T ) {
70- o := NewOptionWeightEmpty ()
71- o .SetSome (Weight (11 ))
72-
73- ok , v := o .Unwrap ()
74- assert .True (t , ok )
75- assert .NotNil (t , v )
76-
77- o .SetNone ()
78-
79- ok , v = o .Unwrap ()
80- assert .False (t , ok )
81- assert .Equal (t , Weight (0 ), v )
82- }
83-
8431func TestWeight_EncodeDecode (t * testing.T ) {
8532 AssertRoundTripFuzz [Weight ](t , 100 )
86- AssertDecodeNilData [Weight ](t )
87- AssertEncodeEmptyObj [Weight ](t , 8 )
33+ AssertEncodeEmptyObj [Weight ](t , 2 )
8834}
8935
9036func TestWeight_EncodedLength (t * testing.T ) {
91- AssertEncodedLength (t , []EncodedLengthAssert {{NewWeight ( 13 ), 8 }})
37+ AssertEncodedLength (t , []EncodedLengthAssert {{testWeight , 3 }})
9238}
9339
9440func TestWeight_Encode (t * testing.T ) {
9541 AssertEncode (t , []EncodingAssert {
96- {NewWeight (29 ), MustHexDecodeString ("0x1d00000000000000" )},
42+ {testWeight , MustHexDecodeString ("0x2ce909" )},
43+ })
44+ }
45+
46+ func TestWeight_Decode (t * testing.T ) {
47+ AssertDecode (t , []DecodingAssert {
48+ {MustHexDecodeString ("0x2ce909" ), testWeight },
9749 })
9850}
9951
10052func TestWeight_Hash (t * testing.T ) {
10153 AssertHash (t , []HashAssert {
102- {NewWeight ( 29 ) , MustHexDecodeString ("0x83e168a13a013e6d47b0778f046aaa05d6c01d6857d044d9e9b658a6d85eb865 " )},
54+ {testWeight , MustHexDecodeString ("0x7daf57922bb9694b4e29da7634e1b0a6af1477a8d13b0544208cda78331ea135 " )},
10355 })
10456}
10557
10658func TestWeight_Hex (t * testing.T ) {
10759 AssertEncodeToHex (t , []EncodeToHexAssert {
108- {NewWeight (29 ), "0x1d00000000000000" },
109- })
110- }
111-
112- func TestWeight_String (t * testing.T ) {
113- AssertString (t , []StringAssert {
114- {NewWeight (29 ), "29" },
60+ {testWeight , "0x2ce909" },
11561 })
11662}
11763
11864func TestWeight_Eq (t * testing.T ) {
11965 AssertEq (t , []EqAssert {
120- {NewWeight (23 ), NewWeight ( 23 ), true },
121- {NewWeight ( 23 ) , NewBool (false ), false },
66+ {testWeight , NewWeight (NewUCompactFromUInt ( 11 ), NewUCompactFromUInt ( 634 ) ), true },
67+ {testWeight , NewBool (false ), false },
12268 })
12369}
0 commit comments