@@ -3,6 +3,8 @@ package eos
33import (
44 "encoding/hex"
55 "encoding/json"
6+ "errors"
7+ "fmt"
68 "testing"
79
810 "github.com/stretchr/testify/assert"
@@ -34,3 +36,33 @@ func TestTransactionID(t *testing.T) {
3436 assert .Equal (t , test .expectID , trxID )
3537 }
3638}
39+
40+ func TestTransaction_UnmarshalPacked_Compression (t * testing.T ) {
41+ tests := []struct {
42+ name string
43+ in string
44+ expected CompressionType
45+ expectedErr error
46+ }{
47+ {"string/none" , `{"compression": "none"}` , CompressionNone , nil },
48+ {"string/zlib" , `{"compression": "zlib"}` , CompressionZlib , nil },
49+ {"string/unknown" , `{"compression": "random"}` , 0 , errors .New ("unknown compression type random" )},
50+
51+ {"int/none" , `{"compression": 0}` , CompressionNone , nil },
52+ {"int/zlib" , `{"compression": 1}` , CompressionZlib , nil },
53+ {"int/unknown" , `{"compression": 3}` , 0 , errors .New ("unknown compression type 3" )},
54+ }
55+
56+ for i , test := range tests {
57+ t .Run (fmt .Sprintf ("%d" , i ), func (t * testing.T ) {
58+ var tx * PackedTransaction
59+ err := json .Unmarshal ([]byte (test .in ), & tx )
60+ if test .expectedErr == nil {
61+ require .NoError (t , err )
62+ assert .Equal (t , test .expected , tx .Compression )
63+ } else {
64+ assert .Equal (t , test .expectedErr , err )
65+ }
66+ })
67+ }
68+ }
0 commit comments