Skip to content

Commit

Permalink
Adapt testing code for 0.50 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
webmaster128 committed Nov 22, 2023
1 parent d0e4c37 commit f01ae2a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 13 deletions.
8 changes: 4 additions & 4 deletions packages/stargate/src/modules/gov/messages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ describe("gov messages", () => {
"Test proposal for simd",
);
assertIsDeliverTxSuccess(proposalResult);
const logs = JSON.parse(proposalResult.rawLog || "");
proposalId = logs[0].events
.find(({ type }: any) => type === "submit_proposal")
.attributes.find(({ key }: any) => key === "proposal_id").value;

proposalId = proposalResult.events
.find(({ type }) => type === "submit_proposal")
?.attributes.find(({ key }: any) => key === "proposal_id")?.value;
assert(proposalId, "Proposal ID not found in events");
assert(proposalId.match(nonNegativeIntegerMatcher));

Expand Down
8 changes: 4 additions & 4 deletions packages/stargate/src/modules/gov/queries.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ describe("GovExtension", () => {
"Test proposal for simd",
);
assertIsDeliverTxSuccess(proposalResult);
const logs = JSON.parse(proposalResult.rawLog || "");
proposalId = logs[0].events
.find(({ type }: any) => type === "submit_proposal")
.attributes.find(({ key }: any) => key === "proposal_id").value;

proposalId = proposalResult.events
.find(({ type }) => type === "submit_proposal")
?.attributes.find(({ key }: any) => key === "proposal_id")?.value;
assert(proposalId, "Proposal ID not found in events");
assert(proposalId.match(nonNegativeIntegerMatcher));

Expand Down
15 changes: 13 additions & 2 deletions packages/stargate/src/signingstargateclient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
ModifyingSecp256k1HdWallet,
pendingWithoutSimapp,
simapp,
simapp50Enabled,
validator,
} from "./testutils.spec";

Expand Down Expand Up @@ -119,7 +120,12 @@ describe("SigningStargateClient", () => {
memo,
);
assertIsDeliverTxSuccess(result);
expect(result.rawLog).toBeTruthy();

if (simapp50Enabled()) {
expect(result.rawLog).toEqual(""); // empty now (https://github.com/cosmos/cosmos-sdk/pull/15845)
} else {
expect(result.rawLog).toBeTruthy();
}

// got tokens
const after = await client.getBalance(beneficiaryAddress, "ucosm");
Expand Down Expand Up @@ -155,7 +161,12 @@ describe("SigningStargateClient", () => {
memo,
);
assertIsDeliverTxSuccess(result);
expect(result.rawLog).toBeTruthy();

if (simapp50Enabled()) {
expect(result.rawLog).toEqual(""); // empty now (https://github.com/cosmos/cosmos-sdk/pull/15845)
} else {
expect(result.rawLog).toBeTruthy();
}

// got tokens
const after = await client.getBalance(beneficiaryAddress, "ucosm");
Expand Down
23 changes: 20 additions & 3 deletions packages/stargate/src/stargateclient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ import {
pendingWithoutSlowSimapp,
simapp,
simapp44Enabled,
simapp46Enabled,
simapp47Enabled,
simapp50Enabled,
slowSimapp,
tendermintIdMatcher,
unused,
Expand Down Expand Up @@ -395,7 +398,11 @@ describe("StargateClient", () => {

const { gasUsed, rawLog, transactionHash } = txResult;
expect(gasUsed).toBeGreaterThan(0);
expect(rawLog).toMatch(/{"key":"amount","value":"1234567ucosm"}/);
if (simapp50Enabled()) {
expect(rawLog).toEqual(""); // empty now (https://github.com/cosmos/cosmos-sdk/pull/15845)
} else {
expect(rawLog).toMatch(/{"key":"amount","value":"1234567ucosm"}/);
}
expect(transactionHash).toMatch(/^[0-9A-F]{64}$/);

client.disconnect();
Expand Down Expand Up @@ -462,10 +469,20 @@ describe("StargateClient", () => {
assert(false, "Expected broadcastTx to throw");
} catch (error: any) {
expect(error).toMatch(
simapp44Enabled() ? /invalid recipient address/i : /Broadcasting transaction failed with code 7/i,
simapp44Enabled()
? /invalid recipient address/i
: simapp46Enabled() || simapp47Enabled()
? /Broadcasting transaction failed with code 7/i
: // New error code for SDK 0.50+
/Broadcasting transaction failed with code 4/i,
);
assert(error instanceof BroadcastTxError);
expect(error.code).toEqual(7);
if (simapp50Enabled()) {
// New error code for SDK 0.50+
expect(error.code).toEqual(4);
} else {
expect(error.code).toEqual(7);
}
expect(error.codespace).toEqual("sdk");
}

Expand Down

0 comments on commit f01ae2a

Please sign in to comment.