Adapt testing code for 0.50 compatibility

This commit is contained in:
Simon Warta 2023-11-22 11:19:48 +01:00
parent d0e4c37248
commit f01ae2a3a4
4 changed files with 41 additions and 13 deletions

View File

@ -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));

View File

@ -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));

View File

@ -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");

View File

@ -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");
}