From f01ae2a3a47e3f3be2f247b07449bed2a6af9501 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 22 Nov 2023 11:19:48 +0100 Subject: [PATCH] Adapt testing code for 0.50 compatibility --- .../stargate/src/modules/gov/messages.spec.ts | 8 +++---- .../stargate/src/modules/gov/queries.spec.ts | 8 +++---- .../src/signingstargateclient.spec.ts | 15 ++++++++++-- packages/stargate/src/stargateclient.spec.ts | 23 ++++++++++++++++--- 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/packages/stargate/src/modules/gov/messages.spec.ts b/packages/stargate/src/modules/gov/messages.spec.ts index 378147ea03..2ee24b6d29 100644 --- a/packages/stargate/src/modules/gov/messages.spec.ts +++ b/packages/stargate/src/modules/gov/messages.spec.ts @@ -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)); diff --git a/packages/stargate/src/modules/gov/queries.spec.ts b/packages/stargate/src/modules/gov/queries.spec.ts index 9cfb7e10e7..722cb89592 100644 --- a/packages/stargate/src/modules/gov/queries.spec.ts +++ b/packages/stargate/src/modules/gov/queries.spec.ts @@ -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)); diff --git a/packages/stargate/src/signingstargateclient.spec.ts b/packages/stargate/src/signingstargateclient.spec.ts index 643aa651df..c8d57cf308 100644 --- a/packages/stargate/src/signingstargateclient.spec.ts +++ b/packages/stargate/src/signingstargateclient.spec.ts @@ -44,6 +44,7 @@ import { ModifyingSecp256k1HdWallet, pendingWithoutSimapp, simapp, + simapp50Enabled, validator, } from "./testutils.spec"; @@ -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"); @@ -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"); diff --git a/packages/stargate/src/stargateclient.spec.ts b/packages/stargate/src/stargateclient.spec.ts index f4de57adde..8761c9a968 100644 --- a/packages/stargate/src/stargateclient.spec.ts +++ b/packages/stargate/src/stargateclient.spec.ts @@ -31,6 +31,9 @@ import { pendingWithoutSlowSimapp, simapp, simapp44Enabled, + simapp46Enabled, + simapp47Enabled, + simapp50Enabled, slowSimapp, tendermintIdMatcher, unused, @@ -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(); @@ -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"); }