Skip to content

Commit

Permalink
Update event handling in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
webmaster128 committed Mar 8, 2024
1 parent 65d80c2 commit 0d83ef8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
10 changes: 6 additions & 4 deletions packages/cosmwasm-stargate/src/cosmwasmclient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
import { ReadonlyDate } from "readonly-date";

import { Code, CosmWasmClient, PrivateCosmWasmClient } from "./cosmwasmclient";
import { findAttribute, SigningCosmWasmClient } from "./signingcosmwasmclient";
import { SigningCosmWasmClient } from "./signingcosmwasmclient";
import {
alice,
defaultInstantiateFee,
Expand Down Expand Up @@ -188,7 +188,6 @@ describe("CosmWasmClient", () => {
amount: coins(5000, "ucosm"),
gas: "890000",
};

const chainId = await client.getChainId();
const sequenceResponse = await client.getSequence(alice.address0);
assert(sequenceResponse);
Expand Down Expand Up @@ -222,8 +221,11 @@ describe("CosmWasmClient", () => {
const signedTx = Uint8Array.from(TxRaw.encode(txRaw).finish());
const result = await client.broadcastTx(signedTx);
assertIsDeliverTxSuccess(result);
const amountAttr = findAttribute(result.events, "transfer", "amount");
expect(amountAttr.value).toEqual("1234567ucosm");
const amountAttrs = result.events
.filter((e) => e.type == "transfer")
.flatMap((e) => e.attributes.filter((a) => a.key == "amount"));
expect(amountAttrs[0].value).toEqual("5000ucosm"); // fee
expect(amountAttrs[1].value).toEqual("1234567ucosm"); // MsgSend amount
expect(result.transactionHash).toMatch(/^[0-9A-F]{64}$/);
});
});
Expand Down
20 changes: 11 additions & 9 deletions packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ describe("SigningCosmWasmClient", () => {
expect(result.height).toBeGreaterThan(0);
expect(result.gasWanted).toBeGreaterThan(0);
expect(result.gasUsed).toBeGreaterThan(0);
const wasmEvent = result.logs[0].events.find((e) => e.type === "wasm");
const wasmEvent = result.events.find((e) => e.type === "wasm");
assert(wasmEvent, "Event of type wasm expected");
expect(wasmEvent.attributes).toContain({ key: "action", value: "release" });
expect(wasmEvent.attributes).toContain({
Expand Down Expand Up @@ -660,7 +660,7 @@ describe("SigningCosmWasmClient", () => {
{ release: {} },
defaultExecuteFee,
);
const wasmEvent = result.logs[0].events.find((e) => e.type === "wasm");
const wasmEvent = result.events.find((e) => e.type === "wasm");
assert(wasmEvent, "Event of type wasm expected");
expect(wasmEvent.attributes).toContain({ key: "action", value: "release" });
expect(wasmEvent.attributes).toContain({
Expand Down Expand Up @@ -727,16 +727,16 @@ describe("SigningCosmWasmClient", () => {
],
"auto",
);
expect(result.logs.length).toEqual(2);
const wasmEvent1 = result.logs[0].events.find((e) => e.type === "wasm");
assert(wasmEvent1, "Event of type wasm expected");
const { events } = result;
expect(events.length).toEqual(2);
const [wasmEvent1, wasmEvent2] = events.filter((e) => e.type == "wasm");
expect(wasmEvent1.type).toEqual("wasm");
expect(wasmEvent1.attributes).toContain({ key: "action", value: "release" });
expect(wasmEvent1.attributes).toContain({
key: "destination",
value: beneficiaryAddress1,
});
const wasmEvent2 = result.logs[1].events.find((e) => e.type === "wasm");
assert(wasmEvent2, "Event of type wasm expected");
expect(wasmEvent2.type).toEqual("wasm");
expect(wasmEvent2.attributes).toContain({ key: "action", value: "release" });
expect(wasmEvent2.attributes).toContain({
key: "destination",
Expand Down Expand Up @@ -777,7 +777,8 @@ describe("SigningCosmWasmClient", () => {
memo,
);
assertIsDeliverTxSuccess(result);
expect(result.rawLog).toBeTruthy();
expect(result.rawLog).toEqual(""); // empty for wasmd >= 0.50.0 (https://github.com/cosmos/cosmos-sdk/pull/15845)
expect(result.events.length).toBeGreaterThanOrEqual(1);

// got tokens
const after = await client.getBalance(beneficiaryAddress, "ucosm");
Expand Down Expand Up @@ -816,7 +817,8 @@ describe("SigningCosmWasmClient", () => {
memo,
);
assertIsDeliverTxSuccess(result);
expect(result.rawLog).toBeTruthy();
expect(result.rawLog).toEqual(""); // empty for wasmd >= 0.50.0 (https://github.com/cosmos/cosmos-sdk/pull/15845)
expect(result.events.length).toBeGreaterThanOrEqual(1);

// got tokens
const after = await client.getBalance(beneficiaryAddress, "ucosm");
Expand Down
2 changes: 2 additions & 0 deletions packages/stargate/src/signingstargateclient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ describe("SigningStargateClient", () => {
} else {
expect(result.rawLog).toBeTruthy();
}
expect(result.events.length).toBeGreaterThanOrEqual(1);

// got tokens
const after = await client.getBalance(beneficiaryAddress, "ucosm");
Expand Down Expand Up @@ -167,6 +168,7 @@ describe("SigningStargateClient", () => {
} else {
expect(result.rawLog).toBeTruthy();
}
expect(result.events.length).toBeGreaterThanOrEqual(1);

// got tokens
const after = await client.getBalance(beneficiaryAddress, "ucosm");
Expand Down

0 comments on commit 0d83ef8

Please sign in to comment.