Skip to content

Commit

Permalink
Fix unmarshalling issue with multisig keys
Browse files Browse the repository at this point in the history
  • Loading branch information
haasted committed Sep 1, 2021
1 parent ed5d165 commit a3c8dea
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crypto/keys/multisig/amino.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ func (m *LegacyAminoPubKey) UnmarshalAminoJSON(tmPk tmMultisig) error {
// Instead of just doing `*m = *protoPk`, we prefer to modify in-place the
// existing Anys inside `m` (instead of allocating new Anys), as so not to
// break the `.compat` fields in the existing Anys.

m.PubKeys = make ([]*types.Any, len(protoPk.PubKeys))
for i := range m.PubKeys {
m.PubKeys[i] = &types.Any{}
m.PubKeys[i].TypeUrl = protoPk.PubKeys[i].TypeUrl
m.PubKeys[i].Value = protoPk.PubKeys[i].Value
}
Expand Down
2 changes: 2 additions & 0 deletions crypto/keys/multisig/multisig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func TestEquals(t *testing.T) {
multisigKey := kmultisig.NewLegacyAminoPubKey(1, []cryptotypes.PubKey{pubKey1, pubKey2})
otherMultisigKey := kmultisig.NewLegacyAminoPubKey(1, []cryptotypes.PubKey{pubKey1, multisigKey})


testCases := []struct {
msg string
other cryptotypes.PubKey
Expand Down Expand Up @@ -380,4 +381,5 @@ func TestAminoUnmarshalJSON(t *testing.T) {
err := cdc.UnmarshalJSON([]byte(pkJSON), &pk)
require.NoError(t, err)
require.Equal(t, uint32(3), pk.(*kmultisig.LegacyAminoPubKey).Threshold)
require.Equal(t, 5, len(pk.(*kmultisig.LegacyAminoPubKey).PubKeys))
}

0 comments on commit a3c8dea

Please sign in to comment.