github.com/chain5j/chain5j-pkg@v1.0.7/codec/json/json_test.go (about) 1 package json 2 3 import ( 4 "math/big" 5 "testing" 6 ) 7 8 func TestByteCodec(t *testing.T) { 9 type tmpst struct { 10 Data []byte 11 Num *big.Int 12 } 13 14 tmp := &tmpst{ 15 Data: []byte{0x1, 0x2, 0x3, 0xf}, 16 Num: big.NewInt(100), 17 } 18 19 b, err := Marshal(tmp) 20 if err != nil { 21 t.Fatal(err) 22 } 23 24 t.Logf("encode byte: %s", string(b)) 25 26 var dec tmpst 27 if err := Unmarshal(b, &dec); err != nil { 28 t.Fatal(err) 29 } 30 31 return 32 } 33 34 func TestBigIntCodec(t *testing.T) { 35 type tmpst struct { 36 Num *big.Int 37 } 38 39 tmp := &tmpst{ 40 Num: big.NewInt(100), 41 } 42 43 b, err := Marshal(tmp) 44 if err != nil { 45 t.Fatal(err) 46 } 47 48 t.Logf("encode: %s", string(b)) 49 50 var dec tmpst 51 if err := Unmarshal(b, &dec); err != nil { 52 t.Fatal(err) 53 } 54 55 tmp2 := &tmpst{} 56 57 b2, err := Marshal(tmp2) 58 if err != nil { 59 t.Fatal(err) 60 } 61 62 t.Logf("encode: %s", string(b2)) 63 64 if err := Unmarshal(b2, &dec); err != nil { 65 t.Fatal(err) 66 } 67 68 return 69 }