@@ -83,8 +83,8 @@ func TestEncodeValid(t *testing.T) {
8383 randomInt , err := rand .Int (rand .Reader , upperLimit )
8484 require .NoError (t , err , "cryptographic random int init fail" )
8585
86- expected := make ([] byte , intSize / 8 )
87- randomInt . FillBytes ( expected )
86+ expected , err := bigIntToBytes ( randomInt , uint ( intSize / 8 ) )
87+ require . NoError ( t , err , "big int to byte conversion error" )
8888
8989 uintEncode , err := uintType .Encode (randomInt )
9090 require .NoError (t , err , "encoding from uint type fail" )
@@ -122,8 +122,9 @@ func TestEncodeValid(t *testing.T) {
122122 encodedUfixed , err := typeUfixed .Encode (randomInt )
123123 require .NoError (t , err , "ufixed encode fail" )
124124
125- expected := make ([]byte , size / 8 )
126- randomInt .FillBytes (expected )
125+ expected , err := bigIntToBytes (randomInt , uint (size / 8 ))
126+ require .NoError (t , err , "big int to byte conversion error" )
127+
127128 require .Equal (t , expected , encodedUfixed , "encode ufixed not match with expected" )
128129 }
129130 // (2^[bitSize] - 1) / (10^[precision]) test
@@ -141,8 +142,8 @@ func TestEncodeValid(t *testing.T) {
141142 randomAddrInt , err := rand .Int (rand .Reader , upperLimit )
142143 require .NoError (t , err , "cryptographic random int init fail" )
143144
144- addrBytesExpected := make ([] byte , addressByteSize )
145- randomAddrInt . FillBytes ( addrBytesExpected )
145+ addrBytesExpected , err := bigIntToBytes ( randomAddrInt , uint ( addressByteSize ) )
146+ require . NoError ( t , err , "big int to byte conversion error" )
146147
147148 addrBytesActual , err := addressType .Encode (addrBytesExpected )
148149 require .NoError (t , err , "address encode fail" )
@@ -421,8 +422,8 @@ func TestDecodeValid(t *testing.T) {
421422 randomAddrInt , err := rand .Int (rand .Reader , upperLimit )
422423 require .NoError (t , err , "cryptographic random int init fail" )
423424
424- expected := make ([] byte , addressByteSize )
425- randomAddrInt . FillBytes ( expected )
425+ expected , err := bigIntToBytes ( randomAddrInt , uint ( addressByteSize ) )
426+ require . NoError ( t , err , "big int to byte conversion error" )
426427
427428 actual , err := addressType .Decode (expected )
428429 require .NoError (t , err , "decoding address should not return error" )
@@ -951,8 +952,10 @@ func addPrimitiveRandomValues(t *testing.T, pool *map[BaseType][]testUnit) {
951952 for i := 0 ; i < addressTestCaseCount ; i ++ {
952953 randAddrVal , err := rand .Int (rand .Reader , maxAddress )
953954 require .NoError (t , err , "generate random value for address, should be no error" )
954- addrBytes := make ([]byte , addressByteSize )
955- randAddrVal .FillBytes (addrBytes )
955+
956+ addrBytes , err := bigIntToBytes (randAddrVal , uint (addressByteSize ))
957+ require .NoError (t , err , "big int to byte conversion error" )
958+
956959 (* pool )[Address ][i ] = testUnit {serializedType : addressType .String (), value : addrBytes }
957960 }
958961 categorySelfRoundTripTest (t , (* pool )[Address ])
@@ -1162,7 +1165,7 @@ func TestParseArgJSONtoByteSlice(t *testing.T) {
11621165
11631166 for i , test := range tests {
11641167 t .Run (fmt .Sprintf ("index=%d" , i ), func (t * testing.T ) {
1165- applicationArgs := [][]byte {}
1168+ applicationArgs := make ( [][]byte , 0 )
11661169 err := ParseArgJSONtoByteSlice (test .argTypes , test .jsonArgs , & applicationArgs )
11671170 require .NoError (t , err )
11681171 require .Equal (t , test .expectedAppArgs , applicationArgs )
0 commit comments