mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 06:42:16 +00:00
Support json encode/decode for nil values in S structs
This commit is contained in:
parent
b6a2c5949f
commit
8c9b889ccf
@ -84,5 +84,29 @@ func TestKeyEncodings(t *testing.T) {
|
|||||||
checkJSON(t, pubKey, &pub3, tc.keyName)
|
checkJSON(t, pubKey, &pub3, tc.keyName)
|
||||||
assert.EqualValues(t, pubKey, pub3)
|
assert.EqualValues(t, pubKey, pub3)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func toFromJSON(t *testing.T, in interface{}, recvr interface{}) {
|
||||||
|
js, err := data.ToJSON(in)
|
||||||
|
require.Nil(t, err, "%+v", err)
|
||||||
|
err = data.FromJSON(js, recvr)
|
||||||
|
require.Nil(t, err, "%+v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNilEncodings(t *testing.T) {
|
||||||
|
// make sure sigs are okay with nil
|
||||||
|
a, b := SignatureS{}, SignatureS{}
|
||||||
|
toFromJSON(t, a, &b)
|
||||||
|
assert.EqualValues(t, a, b)
|
||||||
|
|
||||||
|
// make sure sigs are okay with nil
|
||||||
|
c, d := PubKeyS{}, PubKeyS{}
|
||||||
|
toFromJSON(t, c, &d)
|
||||||
|
assert.EqualValues(t, c, d)
|
||||||
|
|
||||||
|
// make sure sigs are okay with nil
|
||||||
|
e, f := PrivKeyS{}, PrivKeyS{}
|
||||||
|
toFromJSON(t, e, &f)
|
||||||
|
assert.EqualValues(t, e, f)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ func (p PrivKeyS) MarshalJSON() ([]byte, error) {
|
|||||||
|
|
||||||
func (p *PrivKeyS) UnmarshalJSON(data []byte) (err error) {
|
func (p *PrivKeyS) UnmarshalJSON(data []byte) (err error) {
|
||||||
parsed, err := privKeyMapper.FromJSON(data)
|
parsed, err := privKeyMapper.FromJSON(data)
|
||||||
if err == nil {
|
if err == nil && parsed != nil {
|
||||||
p.PrivKey = parsed.(PrivKey)
|
p.PrivKey = parsed.(PrivKey)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@ -49,7 +49,7 @@ func (p PubKeyS) MarshalJSON() ([]byte, error) {
|
|||||||
|
|
||||||
func (p *PubKeyS) UnmarshalJSON(data []byte) (err error) {
|
func (p *PubKeyS) UnmarshalJSON(data []byte) (err error) {
|
||||||
parsed, err := pubKeyMapper.FromJSON(data)
|
parsed, err := pubKeyMapper.FromJSON(data)
|
||||||
if err == nil {
|
if err == nil && parsed != nil {
|
||||||
p.PubKey = parsed.(PubKey)
|
p.PubKey = parsed.(PubKey)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@ -45,7 +45,7 @@ func (p SignatureS) MarshalJSON() ([]byte, error) {
|
|||||||
|
|
||||||
func (p *SignatureS) UnmarshalJSON(data []byte) (err error) {
|
func (p *SignatureS) UnmarshalJSON(data []byte) (err error) {
|
||||||
parsed, err := sigMapper.FromJSON(data)
|
parsed, err := sigMapper.FromJSON(data)
|
||||||
if err == nil {
|
if err == nil && parsed != nil {
|
||||||
p.Signature = parsed.(Signature)
|
p.Signature = parsed.(Signature)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user