Merge pull request #610 from filecoin-project/fix/marshal-tipsetkey

Fix Marshaling of TipSetKey
This commit is contained in:
Łukasz Magiera 2019-11-14 21:42:10 +01:00 committed by GitHub
commit 8ff3df3c1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 10 deletions

View File

@ -77,7 +77,7 @@ func (k TipSetKey) Bytes() []byte {
return []byte(k.value)
}
func (k *TipSetKey) MarshalJSON() ([]byte, error) {
func (k TipSetKey) MarshalJSON() ([]byte, error) {
return json.Marshal(k.Cids())
}

View File

@ -1,6 +1,7 @@
package types
import (
"encoding/json"
"fmt"
"testing"
@ -71,12 +72,12 @@ func TestTipSetKey(t *testing.T) {
}
func verifyJson(t *testing.T, expected string, k TipSetKey) {
bytes, err := k.MarshalJSON()
bytes, err := json.Marshal(k)
require.NoError(t, err)
assert.Equal(t, expected, string(bytes))
var rehydrated TipSetKey
err = rehydrated.UnmarshalJSON(bytes)
err = json.Unmarshal(bytes, &rehydrated)
require.NoError(t, err)
assert.Equal(t, k, rehydrated)
}