X-Git-Url: http://git.osdn.net/view?p=bytom%2Fvapor.git;a=blobdiff_plain;f=vendor%2Fgithub.com%2Fbytom%2Fcrypto%2Fed25519%2Fchainkd%2Fserialize_test.go;fp=vendor%2Fgithub.com%2Fbytom%2Fcrypto%2Fed25519%2Fchainkd%2Fserialize_test.go;h=142549d4f736b92a63bbc5763f83230e52cc4792;hp=0000000000000000000000000000000000000000;hb=54373c1a3efe0e373ec1605840a4363e4b246c46;hpb=ee01d543fdfe1fd0a4d548965c66f7923ea7b062 diff --git a/vendor/github.com/bytom/crypto/ed25519/chainkd/serialize_test.go b/vendor/github.com/bytom/crypto/ed25519/chainkd/serialize_test.go new file mode 100644 index 00000000..142549d4 --- /dev/null +++ b/vendor/github.com/bytom/crypto/ed25519/chainkd/serialize_test.go @@ -0,0 +1,37 @@ +package chainkd + +import ( + "bytes" + "encoding/hex" + "encoding/json" + "reflect" + "testing" +) + +func TestMarshalingFuncs(t *testing.T) { + xprv, err := NewXPrv(nil) + if err != nil { + t.Fatal(err) + } + + want := make([]byte, hex.EncodedLen(len(xprv.Bytes()))) + hex.Encode(want, xprv.Bytes()) + + got, err := json.Marshal(xprv) + if err != nil { + t.Fatal(err) + } + // First and last bytes are " + if !reflect.DeepEqual(want, got[1:len(got)-1]) { + t.Errorf("marshaling error: want = %+v, got = %+v", want, got) + } + + secXprv := new(XPrv) + err = json.Unmarshal(got, &secXprv) + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(xprv[:], secXprv[:]) { + t.Errorf("unmarshaling error: want = %+v, got = %+v", xprv, secXprv) + } +}