mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-10 21:49:15 +00:00
Update event handling in tests
This commit is contained in:
parent
65d80c29aa
commit
0d83ef8c69
@ -16,7 +16,7 @@ import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
|
|||||||
import { ReadonlyDate } from "readonly-date";
|
import { ReadonlyDate } from "readonly-date";
|
||||||
|
|
||||||
import { Code, CosmWasmClient, PrivateCosmWasmClient } from "./cosmwasmclient";
|
import { Code, CosmWasmClient, PrivateCosmWasmClient } from "./cosmwasmclient";
|
||||||
import { findAttribute, SigningCosmWasmClient } from "./signingcosmwasmclient";
|
import { SigningCosmWasmClient } from "./signingcosmwasmclient";
|
||||||
import {
|
import {
|
||||||
alice,
|
alice,
|
||||||
defaultInstantiateFee,
|
defaultInstantiateFee,
|
||||||
@ -188,7 +188,6 @@ describe("CosmWasmClient", () => {
|
|||||||
amount: coins(5000, "ucosm"),
|
amount: coins(5000, "ucosm"),
|
||||||
gas: "890000",
|
gas: "890000",
|
||||||
};
|
};
|
||||||
|
|
||||||
const chainId = await client.getChainId();
|
const chainId = await client.getChainId();
|
||||||
const sequenceResponse = await client.getSequence(alice.address0);
|
const sequenceResponse = await client.getSequence(alice.address0);
|
||||||
assert(sequenceResponse);
|
assert(sequenceResponse);
|
||||||
@ -222,8 +221,11 @@ describe("CosmWasmClient", () => {
|
|||||||
const signedTx = Uint8Array.from(TxRaw.encode(txRaw).finish());
|
const signedTx = Uint8Array.from(TxRaw.encode(txRaw).finish());
|
||||||
const result = await client.broadcastTx(signedTx);
|
const result = await client.broadcastTx(signedTx);
|
||||||
assertIsDeliverTxSuccess(result);
|
assertIsDeliverTxSuccess(result);
|
||||||
const amountAttr = findAttribute(result.events, "transfer", "amount");
|
const amountAttrs = result.events
|
||||||
expect(amountAttr.value).toEqual("1234567ucosm");
|
.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}$/);
|
expect(result.transactionHash).toMatch(/^[0-9A-F]{64}$/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -607,7 +607,7 @@ describe("SigningCosmWasmClient", () => {
|
|||||||
expect(result.height).toBeGreaterThan(0);
|
expect(result.height).toBeGreaterThan(0);
|
||||||
expect(result.gasWanted).toBeGreaterThan(0);
|
expect(result.gasWanted).toBeGreaterThan(0);
|
||||||
expect(result.gasUsed).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");
|
assert(wasmEvent, "Event of type wasm expected");
|
||||||
expect(wasmEvent.attributes).toContain({ key: "action", value: "release" });
|
expect(wasmEvent.attributes).toContain({ key: "action", value: "release" });
|
||||||
expect(wasmEvent.attributes).toContain({
|
expect(wasmEvent.attributes).toContain({
|
||||||
@ -660,7 +660,7 @@ describe("SigningCosmWasmClient", () => {
|
|||||||
{ release: {} },
|
{ release: {} },
|
||||||
defaultExecuteFee,
|
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");
|
assert(wasmEvent, "Event of type wasm expected");
|
||||||
expect(wasmEvent.attributes).toContain({ key: "action", value: "release" });
|
expect(wasmEvent.attributes).toContain({ key: "action", value: "release" });
|
||||||
expect(wasmEvent.attributes).toContain({
|
expect(wasmEvent.attributes).toContain({
|
||||||
@ -727,16 +727,16 @@ describe("SigningCosmWasmClient", () => {
|
|||||||
],
|
],
|
||||||
"auto",
|
"auto",
|
||||||
);
|
);
|
||||||
expect(result.logs.length).toEqual(2);
|
const { events } = result;
|
||||||
const wasmEvent1 = result.logs[0].events.find((e) => e.type === "wasm");
|
expect(events.length).toEqual(2);
|
||||||
assert(wasmEvent1, "Event of type wasm expected");
|
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: "action", value: "release" });
|
||||||
expect(wasmEvent1.attributes).toContain({
|
expect(wasmEvent1.attributes).toContain({
|
||||||
key: "destination",
|
key: "destination",
|
||||||
value: beneficiaryAddress1,
|
value: beneficiaryAddress1,
|
||||||
});
|
});
|
||||||
const wasmEvent2 = result.logs[1].events.find((e) => e.type === "wasm");
|
expect(wasmEvent2.type).toEqual("wasm");
|
||||||
assert(wasmEvent2, "Event of type wasm expected");
|
|
||||||
expect(wasmEvent2.attributes).toContain({ key: "action", value: "release" });
|
expect(wasmEvent2.attributes).toContain({ key: "action", value: "release" });
|
||||||
expect(wasmEvent2.attributes).toContain({
|
expect(wasmEvent2.attributes).toContain({
|
||||||
key: "destination",
|
key: "destination",
|
||||||
@ -777,7 +777,8 @@ describe("SigningCosmWasmClient", () => {
|
|||||||
memo,
|
memo,
|
||||||
);
|
);
|
||||||
assertIsDeliverTxSuccess(result);
|
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
|
// got tokens
|
||||||
const after = await client.getBalance(beneficiaryAddress, "ucosm");
|
const after = await client.getBalance(beneficiaryAddress, "ucosm");
|
||||||
@ -816,7 +817,8 @@ describe("SigningCosmWasmClient", () => {
|
|||||||
memo,
|
memo,
|
||||||
);
|
);
|
||||||
assertIsDeliverTxSuccess(result);
|
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
|
// got tokens
|
||||||
const after = await client.getBalance(beneficiaryAddress, "ucosm");
|
const after = await client.getBalance(beneficiaryAddress, "ucosm");
|
||||||
|
@ -126,6 +126,7 @@ describe("SigningStargateClient", () => {
|
|||||||
} else {
|
} else {
|
||||||
expect(result.rawLog).toBeTruthy();
|
expect(result.rawLog).toBeTruthy();
|
||||||
}
|
}
|
||||||
|
expect(result.events.length).toBeGreaterThanOrEqual(1);
|
||||||
|
|
||||||
// got tokens
|
// got tokens
|
||||||
const after = await client.getBalance(beneficiaryAddress, "ucosm");
|
const after = await client.getBalance(beneficiaryAddress, "ucosm");
|
||||||
@ -167,6 +168,7 @@ describe("SigningStargateClient", () => {
|
|||||||
} else {
|
} else {
|
||||||
expect(result.rawLog).toBeTruthy();
|
expect(result.rawLog).toBeTruthy();
|
||||||
}
|
}
|
||||||
|
expect(result.events.length).toBeGreaterThanOrEqual(1);
|
||||||
|
|
||||||
// got tokens
|
// got tokens
|
||||||
const after = await client.getBalance(beneficiaryAddress, "ucosm");
|
const after = await client.getBalance(beneficiaryAddress, "ucosm");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user