Skip to content

Commit

Permalink
Merge pull request #886 from cosmos/multisig-decoding-testing
Browse files Browse the repository at this point in the history
Testing and CHANGELOG for multisig support in decodeBech32Pubkey
  • Loading branch information
webmaster128 authored Sep 30, 2021
2 parents c2f1f4c + 705d1e8 commit ad63636
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@ and this project adheres to

## [Unreleased]

### Added

- @cosmjs/amino: `decodeBech32Pubkey` and `decodeAminoPubkey` now support
decoding multisig public keys ([#882]).

### Fixed

- @cosmjs/stargate: Add missing pagination key arguments to query types in
`GovExtension`.

[#882]: https://github.com/cosmos/cosmjs/issues/882

## [0.26.0] - 2021-08-24

### Added
Expand Down
54 changes: 51 additions & 3 deletions packages/amino/src/encoding.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Bech32, fromBase64 } from "@cosmjs/encoding";
import { Bech32, fromBase64, fromHex } from "@cosmjs/encoding";

import {
decodeAminoPubkey,
Expand Down Expand Up @@ -63,6 +63,53 @@ describe("encoding", () => {
it("works for sr25519", () => {
pending("No test data available");
});

it("works for multisig", () => {
const pubkeyData = Bech32.decode(
"cosmospub1addwnpepqd8sgxq7aw348ydctp3n5ajufgxp395hksxjzc6565yfp56scupfqhlgyg5",
).data;
const pubkey = {
type: "tendermint/PubKeySecp256k1",
value: "A08EGB7ro1ORuFhjOnZcSgwYlpe0DSFjVNUIkNNQxwKQ",
};

const data1 = fromHex("22C1F7E20805");
expect(decodeAminoPubkey(data1)).toEqual({
type: "tendermint/PubKeyMultisigThreshold",
value: {
threshold: "5",
pubkeys: [],
},
});

const data2 = Uint8Array.from([...fromHex("22C1F7E2081a"), 0x12, pubkeyData.length, ...pubkeyData]);
expect(decodeAminoPubkey(data2)).toEqual({
type: "tendermint/PubKeyMultisigThreshold",
value: {
threshold: "26",
pubkeys: [pubkey],
},
});

const data3 = Uint8Array.from([
...fromHex("22C1F7E2081a"),
0x12,
pubkeyData.length,
...pubkeyData,
0x12,
pubkeyData.length,
...pubkeyData,
]);
expect(decodeAminoPubkey(data3)).toEqual({
type: "tendermint/PubKeyMultisigThreshold",
value: {
threshold: "26",
pubkeys: [pubkey, pubkey],
},
});

expect(() => decodeAminoPubkey(fromHex("22C1F7E20705"))).toThrowError(/expecting 0x08 prefix/i);
});
});

describe("decodeBech32Pubkey", () => {
Expand Down Expand Up @@ -97,8 +144,9 @@ describe("encoding", () => {
});

it("works for multisig", () => {
const decoded = decodeBech32Pubkey(testgroup1PubkeyBech32);
expect(decoded).toEqual(testgroup1);
expect(decodeBech32Pubkey(testgroup1PubkeyBech32)).toEqual(testgroup1);
expect(decodeBech32Pubkey(testgroup2PubkeyBech32)).toEqual(testgroup2);
expect(decodeBech32Pubkey(testgroup3PubkeyBech32)).toEqual(testgroup3);
});
});

Expand Down

0 comments on commit ad63636

Please sign in to comment.