Fix Marshaling of TipSetKey

License: MIT
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
Jakub Sztandera 2019-11-14 21:33:56 +01:00
parent c20aaf3856
commit 9f3b5bfb6e
No known key found for this signature in database
GPG Key ID: 9A9AF56F8B3879BA
2 changed files with 11 additions and 10 deletions

View File

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

View File

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