Skip to content

Commit

Permalink
Improve Amino JSON test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
webmaster128 committed Apr 17, 2024
1 parent e20a95c commit 5db290f
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 36 deletions.
90 changes: 61 additions & 29 deletions packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ describe("SigningCosmWasmClient", () => {
client.disconnect();
});

it("works with legacy Amino signer", async () => {
it("works with Amino JSON signer", async () => {
pendingWithoutWasmd();
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix });
const client = await SigningCosmWasmClient.connectWithSigner(
Expand All @@ -147,7 +147,7 @@ describe("SigningCosmWasmClient", () => {
client.disconnect();
});

it("works with legacy Amino signer (instantiatePermission set)", async () => {
it("works with Amino JSON signer (instantiatePermission set)", async () => {
pendingWithoutWasmd();
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix });
const client = await SigningCosmWasmClient.connectWithSigner(
Expand Down Expand Up @@ -285,16 +285,17 @@ describe("SigningCosmWasmClient", () => {
client.disconnect();
});

it("works with legacy Amino signer", async () => {
it("works with Amino JSON signer", async () => {
pendingWithoutWasmd();
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix });
const client = await SigningCosmWasmClient.connectWithSigner(
wasmd.endpoint,
wallet,
defaultSigningClientOptions,
);
const funds = [coin(1234, "ucosm"), coin(321, "ustake")];

// With admin
// Without admin
await client.instantiate(
alice.address0,
deployedHackatom.codeId,
Expand All @@ -304,10 +305,13 @@ describe("SigningCosmWasmClient", () => {
},
"contract 1",
defaultInstantiateFee,
{ admin: makeRandomAddress() },
{
funds: funds,
memo: "instantiate it",
},
);

// Without admin
// With admin
await client.instantiate(
alice.address0,
deployedHackatom.codeId,
Expand All @@ -317,6 +321,10 @@ describe("SigningCosmWasmClient", () => {
},
"contract 1",
defaultInstantiateFee,
{
funds: funds,
admin: makeRandomAddress(),
},
);

client.disconnect();
Expand Down Expand Up @@ -368,41 +376,65 @@ describe("SigningCosmWasmClient", () => {
client.disconnect();
});

it("works with Amino JSON signing", async () => {
it("works with Amino JSON signer", async () => {
pendingWithoutWasmd();
const aminoJsonWallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic, {
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic, {
prefix: wasmd.prefix,
});
const client = await SigningCosmWasmClient.connectWithSigner(
wasmd.endpoint,
aminoJsonWallet,
wallet,
defaultSigningClientOptions,
);
const { codeId } = await client.upload(alice.address0, getHackatom().data, defaultUploadFee);
const funds = [coin(1234, "ucosm"), coin(321, "ustake")];
const salt = Random.getBytes(64);
const msg = {
verifier: alice.address0,
beneficiary: makeRandomAddress(),
};

const { contractAddress } = await client.instantiate2(
alice.address0,
codeId,
salt,
msg,
"My cool label--",
defaultInstantiateFee,
{
memo: "Let's see if the memo is used",
funds: funds,
},
);
// Without admin
{
const salt = Random.getBytes(64);
const { contractAddress } = await client.instantiate2(
alice.address0,
codeId,
salt,
msg,
"My cool label--",
defaultInstantiateFee,
{
memo: "Let's see if the memo is used",
funds: funds,
},
);
const ucosmBalance = await client.getBalance(contractAddress, "ucosm");
const ustakeBalance = await client.getBalance(contractAddress, "ustake");
expect(ucosmBalance).toEqual(funds[0]);
expect(ustakeBalance).toEqual(funds[1]);
}

const ucosmBalance = await client.getBalance(contractAddress, "ucosm");
const ustakeBalance = await client.getBalance(contractAddress, "ustake");
expect(ucosmBalance).toEqual(funds[0]);
expect(ustakeBalance).toEqual(funds[1]);
// With admin
{
const salt = Random.getBytes(64);
const { contractAddress } = await client.instantiate2(
alice.address0,
codeId,
salt,
msg,
"My cool label--",
defaultInstantiateFee,
{
memo: "Let's see if the memo is used",
funds: funds,
admin: makeRandomAddress(),
},
);
const ucosmBalance = await client.getBalance(contractAddress, "ucosm");
const ustakeBalance = await client.getBalance(contractAddress, "ustake");
expect(ucosmBalance).toEqual(funds[0]);
expect(ustakeBalance).toEqual(funds[1]);
}

client.disconnect();
});
Expand Down Expand Up @@ -549,7 +581,7 @@ describe("SigningCosmWasmClient", () => {
client.disconnect();
});

it("works with legacy Amino signer", async () => {
it("works with Amino JSON signer", async () => {
pendingWithoutWasmd();
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix });
const client = await SigningCosmWasmClient.connectWithSigner(
Expand Down Expand Up @@ -652,7 +684,7 @@ describe("SigningCosmWasmClient", () => {
client.disconnect();
});

it("works with legacy Amino signer", async () => {
it("works with Amino JSON signer", async () => {
pendingWithoutWasmd();
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix });
const client = await SigningCosmWasmClient.connectWithSigner(
Expand Down Expand Up @@ -813,7 +845,7 @@ describe("SigningCosmWasmClient", () => {
client.disconnect();
});

it("works with legacy Amino signer", async () => {
it("works with Amino JSON signer", async () => {
pendingWithoutWasmd();
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix });
const client = await SigningCosmWasmClient.connectWithSigner(
Expand Down
4 changes: 2 additions & 2 deletions packages/stargate/src/modules/gov/messages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ describe("gov messages", () => {
client.disconnect();
});

it("works with Amino JSON sign mode", async () => {
it("works with Amino JSON signer", async () => {
pendingWithoutSimapp();
assert(voterWalletAmino);
assert(proposalId, "Missing proposal ID");
Expand Down Expand Up @@ -206,7 +206,7 @@ describe("gov messages", () => {
client.disconnect();
});

it("works with Amino JSON sign mode", async () => {
it("works with Amino JSON signer", async () => {
pendingWithoutSimapp();
if (simapp50Enabled()) pending("Not working, see https://github.com/cosmos/cosmos-sdk/issues/18546");
assert(voterWalletAmino);
Expand Down
4 changes: 2 additions & 2 deletions packages/stargate/src/modules/staking/messages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe("staking messages", () => {
client.disconnect();
});

it("works with Amino JSON sign mode", async () => {
it("works with Amino JSON signer", async () => {
pendingWithoutSimapp();
if (simapp50Enabled()) pending("Not working, see https://github.com/cosmos/cosmos-sdk/issues/18546");

Expand Down Expand Up @@ -235,7 +235,7 @@ describe("staking messages", () => {
client.disconnect();
});

it("works with Amino JSON sign mode", async () => {
it("works with Amino JSON signer", async () => {
pendingWithoutSimapp();
if (simapp50Enabled()) pending("Not working, see https://github.com/cosmos/cosmos-sdk/issues/18546");

Expand Down
2 changes: 1 addition & 1 deletion packages/stargate/src/modules/vesting/messages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe("vesting messages", () => {
client.disconnect();
});

it("works with Amino JSON sign mode", async () => {
it("works with Amino JSON signer", async () => {
pendingWithoutSimapp46OrHigher(); // Amino JSON broken on chain before Cosmos SDK 0.46
const wallet = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic);
const client = await SigningStargateClient.connectWithSigner(
Expand Down
4 changes: 2 additions & 2 deletions packages/stargate/src/signingstargateclient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ describe("SigningStargateClient", () => {
expect(after).toEqual(amount[0]);
});

it("works with legacy Amino signer", async () => {
it("works with Amino JSON signer", async () => {
pendingWithoutSimapp();
const wallet = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic);
const client = await SigningStargateClient.connectWithSigner(
Expand Down Expand Up @@ -301,7 +301,7 @@ describe("SigningStargateClient", () => {
}
});

it("works with Amino signing", async () => {
it("works with Amino JSON signer", async () => {
pending("We cannot test this easily anymore since the IBC module was removed from simapp");
const wallet = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic);
const client = await SigningStargateClient.connectWithSigner(
Expand Down

0 comments on commit 5db290f

Please sign in to comment.