Skip to content

Commit

Permalink
Fix more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
webmaster128 committed Mar 8, 2024
1 parent 7c68060 commit add1898
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
7 changes: 5 additions & 2 deletions packages/cosmwasm-stargate/src/modules/wasm/queries.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,11 @@ describe("WasmExtension", () => {
assertIsDeliverTxSuccess(result);
const contractAddressAttr = findAttribute(result.events, "instantiate", "_contract_address");
contractAddress = contractAddressAttr.value;
const amountAttr = findAttribute(result.events, "transfer", "amount");
expect(amountAttr.value).toEqual("1234ucosm,321ustake");
const amountAttrs = result.events
.filter((e) => e.type == "transfer")
.flatMap((e) => e.attributes.filter((a) => a.key == "amount"));
expect(amountAttrs[0].value).toEqual("5000000ucosm"); // fee
expect(amountAttrs[1].value).toEqual("1234ucosm,321ustake"); // instantiate funds
const actionAttr = findAttribute(result.events, "message", "module");
expect(actionAttr.value).toEqual("wasm");

Expand Down
7 changes: 6 additions & 1 deletion packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ describe("SigningCosmWasmClient", () => {

it("works with legacy Amino signer access type", async () => {
pendingWithoutWasmd();
pending("wasmd 0.50 does not work with Amino JSON signing");
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix });
const options = { ...defaultSigningClientOptions, prefix: wasmd.prefix };
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, options);
Expand Down Expand Up @@ -263,6 +264,7 @@ describe("SigningCosmWasmClient", () => {

it("works with legacy Amino signer", async () => {
pendingWithoutWasmd();
pending("wasmd 0.50 does not work with Amino JSON signing");
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix });
const client = await SigningCosmWasmClient.connectWithSigner(
wasmd.endpoint,
Expand Down Expand Up @@ -313,7 +315,7 @@ describe("SigningCosmWasmClient", () => {
const { codeId } = await client.upload(alice.address0, getHackatom().data, defaultUploadFee);
const funds = [coin(1234, "ucosm"), coin(321, "ustake")];
const beneficiaryAddress = makeRandomAddress();
const salt = Uint8Array.from([0x01]);
const salt = Random.getBytes(64); // different salt every time we run the test to avoid address collision erors
const wasm = getHackatom().data;
const msg = {
verifier: alice.address0,
Expand Down Expand Up @@ -346,6 +348,7 @@ describe("SigningCosmWasmClient", () => {

it("works with Amino JSON signing", async () => {
pendingWithoutWasmd();
pending("wasmd 0.50 does not work with Amino JSON signing");
const aminoJsonWallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic, {
prefix: wasmd.prefix,
});
Expand Down Expand Up @@ -527,6 +530,7 @@ describe("SigningCosmWasmClient", () => {

it("works with legacy Amino signer", async () => {
pendingWithoutWasmd();
pending("wasmd 0.50 does not work with Amino JSON signing");
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix });
const client = await SigningCosmWasmClient.connectWithSigner(
wasmd.endpoint,
Expand Down Expand Up @@ -630,6 +634,7 @@ describe("SigningCosmWasmClient", () => {

it("works with legacy Amino signer", async () => {
pendingWithoutWasmd();
pending("wasmd 0.50 does not work with Amino JSON signing");
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix });
const client = await SigningCosmWasmClient.connectWithSigner(
wasmd.endpoint,
Expand Down
10 changes: 5 additions & 5 deletions packages/cosmwasm-stargate/src/signingcosmwasmclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,15 @@ export interface ExecuteResult {
}

/**
* Searches in events for the first event of the given event type and in that event
* for the first first attribute with the given attribute key.
* Searches in events for an event of the given event type which contains an
* attribute for with the given key.
*
* Throws if the attribute was not found.
*/
export function findAttribute(events: readonly Event[], eventType: string, attrKey: string): Attribute {
const out = events
.find((event) => event.type === eventType)
?.attributes.find((attr) => attr.key === attrKey);
// all attributes from events with the right event type
const attributes = events.filter((event) => event.type === eventType).flatMap((e) => e.attributes);
const out = attributes.find((attr) => attr.key === attrKey);
if (!out) {
throw new Error(
`Could not find attribute '${attrKey}' in first event of type '${eventType}' in first log.`,
Expand Down

0 comments on commit add1898

Please sign in to comment.