Fix more tests

This commit is contained in:
Simon Warta 2024-02-29 16:21:15 +01:00
parent 7c68060789
commit add1898de6
3 changed files with 16 additions and 8 deletions

View File

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

View File

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

View File

@ -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.`,