From 6db399a3404c1d42776666153d9b1a8d47dc1961 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Mon, 31 Jan 2022 09:58:49 +0100 Subject: [PATCH 1/4] Add gasWanted/gasUsed values to all result types of SigningCosmWasmClient --- .../src/signingcosmwasmclient.ts | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts b/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts index 05a0e543..37cbfdc6 100644 --- a/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts +++ b/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts @@ -71,6 +71,8 @@ export interface UploadResult { readonly logs: readonly logs.Log[]; /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ readonly transactionHash: string; + readonly gasWanted: number; + readonly gasUsed: number; } /** @@ -100,6 +102,8 @@ export interface InstantiateResult { readonly logs: readonly logs.Log[]; /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ readonly transactionHash: string; + readonly gasWanted: number; + readonly gasUsed: number; } /** @@ -109,18 +113,24 @@ export interface ChangeAdminResult { readonly logs: readonly logs.Log[]; /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ readonly transactionHash: string; + readonly gasWanted: number; + readonly gasUsed: number; } export interface MigrateResult { readonly logs: readonly logs.Log[]; /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ readonly transactionHash: string; + readonly gasWanted: number; + readonly gasUsed: number; } export interface ExecuteResult { readonly logs: readonly logs.Log[]; /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ readonly transactionHash: string; + readonly gasWanted: number; + readonly gasUsed: number; } function createDeliverTxResponseErrorMessage(result: DeliverTxResponse): string { @@ -250,6 +260,8 @@ export class SigningCosmWasmClient extends CosmWasmClient { codeId: Number.parseInt(codeIdAttr.value, 10), logs: parsedLogs, transactionHash: result.transactionHash, + gasWanted: result.gasWanted, + gasUsed: result.gasUsed, }; } @@ -282,6 +294,8 @@ export class SigningCosmWasmClient extends CosmWasmClient { contractAddress: contractAddressAttr.value, logs: parsedLogs, transactionHash: result.transactionHash, + gasWanted: result.gasWanted, + gasUsed: result.gasUsed, }; } @@ -307,6 +321,8 @@ export class SigningCosmWasmClient extends CosmWasmClient { return { logs: logs.parseRawLog(result.rawLog), transactionHash: result.transactionHash, + gasWanted: result.gasWanted, + gasUsed: result.gasUsed, }; } @@ -330,6 +346,8 @@ export class SigningCosmWasmClient extends CosmWasmClient { return { logs: logs.parseRawLog(result.rawLog), transactionHash: result.transactionHash, + gasWanted: result.gasWanted, + gasUsed: result.gasUsed, }; } @@ -357,6 +375,8 @@ export class SigningCosmWasmClient extends CosmWasmClient { return { logs: logs.parseRawLog(result.rawLog), transactionHash: result.transactionHash, + gasWanted: result.gasWanted, + gasUsed: result.gasUsed, }; } @@ -384,6 +404,8 @@ export class SigningCosmWasmClient extends CosmWasmClient { return { logs: logs.parseRawLog(result.rawLog), transactionHash: result.transactionHash, + gasWanted: result.gasWanted, + gasUsed: result.gasUsed, }; } From 77645e8f64957308adcb75a5567ccaf6d443249c Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Mon, 31 Jan 2022 13:43:32 +0100 Subject: [PATCH 2/4] Add block heights to CosmWasm client results --- .../src/signingcosmwasmclient.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts b/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts index 37cbfdc6..4ea3c3f8 100644 --- a/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts +++ b/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts @@ -69,6 +69,8 @@ export interface UploadResult { /** The ID of the code asigned by the chain */ readonly codeId: number; readonly logs: readonly logs.Log[]; + /** Block height in which the transaction is included */ + readonly height: number; /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ readonly transactionHash: string; readonly gasWanted: number; @@ -100,6 +102,8 @@ export interface InstantiateResult { /** The address of the newly instantiated contract */ readonly contractAddress: string; readonly logs: readonly logs.Log[]; + /** Block height in which the transaction is included */ + readonly height: number; /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ readonly transactionHash: string; readonly gasWanted: number; @@ -111,6 +115,8 @@ export interface InstantiateResult { */ export interface ChangeAdminResult { readonly logs: readonly logs.Log[]; + /** Block height in which the transaction is included */ + readonly height: number; /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ readonly transactionHash: string; readonly gasWanted: number; @@ -119,6 +125,8 @@ export interface ChangeAdminResult { export interface MigrateResult { readonly logs: readonly logs.Log[]; + /** Block height in which the transaction is included */ + readonly height: number; /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ readonly transactionHash: string; readonly gasWanted: number; @@ -127,6 +135,8 @@ export interface MigrateResult { export interface ExecuteResult { readonly logs: readonly logs.Log[]; + /** Block height in which the transaction is included */ + readonly height: number; /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ readonly transactionHash: string; readonly gasWanted: number; @@ -259,6 +269,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { compressedChecksum: toHex(sha256(compressed)), codeId: Number.parseInt(codeIdAttr.value, 10), logs: parsedLogs, + height: result.height, transactionHash: result.transactionHash, gasWanted: result.gasWanted, gasUsed: result.gasUsed, @@ -293,6 +304,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { return { contractAddress: contractAddressAttr.value, logs: parsedLogs, + height: result.height, transactionHash: result.transactionHash, gasWanted: result.gasWanted, gasUsed: result.gasUsed, @@ -320,6 +332,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { } return { logs: logs.parseRawLog(result.rawLog), + height: result.height, transactionHash: result.transactionHash, gasWanted: result.gasWanted, gasUsed: result.gasUsed, @@ -345,6 +358,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { } return { logs: logs.parseRawLog(result.rawLog), + height: result.height, transactionHash: result.transactionHash, gasWanted: result.gasWanted, gasUsed: result.gasUsed, @@ -374,6 +388,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { } return { logs: logs.parseRawLog(result.rawLog), + height: result.height, transactionHash: result.transactionHash, gasWanted: result.gasWanted, gasUsed: result.gasUsed, @@ -403,6 +418,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { } return { logs: logs.parseRawLog(result.rawLog), + height: result.height, transactionHash: result.transactionHash, gasWanted: result.gasWanted, gasUsed: result.gasUsed, From 0c7ff05b4df2474aaf31a8e31d78998862b130eb Mon Sep 17 00:00:00 2001 From: Milan Steiner Date: Fri, 4 Feb 2022 09:42:48 +0100 Subject: [PATCH 3/4] Adding tests --- .../src/signingcosmwasmclient.spec.ts | 51 +++++++++++++++---- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts b/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts index 295399aa..9d9ad47f 100644 --- a/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts +++ b/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts @@ -123,7 +123,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 { contractAddress } = await client.instantiate( + const { contractAddress, height, gasWanted, gasUsed } = await client.instantiate( alice.address0, codeId, { @@ -139,9 +139,12 @@ describe("SigningCosmWasmClient", () => { ); const wasmClient = await makeWasmClient(wasmd.endpoint); const ucosmBalance = await wasmClient.bank.balance(contractAddress, "ucosm"); - expect(ucosmBalance).toEqual(funds[0]); const ustakeBalance = await wasmClient.bank.balance(contractAddress, "ustake"); + expect(ucosmBalance).toEqual(funds[0]); expect(ustakeBalance).toEqual(funds[1]); + expect(height).toBeGreaterThan(0); + expect(gasWanted).toBeGreaterThan(0); + expect(gasUsed).toBeGreaterThan(0); client.disconnect(); }); @@ -152,7 +155,7 @@ describe("SigningCosmWasmClient", () => { const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, options); const { codeId } = await client.upload(alice.address0, getHackatom().data, defaultUploadFee); const beneficiaryAddress = makeRandomAddress(); - const { contractAddress } = await client.instantiate( + const { contractAddress, height, gasWanted, gasUsed } = await client.instantiate( alice.address0, codeId, { @@ -166,6 +169,9 @@ describe("SigningCosmWasmClient", () => { const wasmClient = await makeWasmClient(wasmd.endpoint); const { contractInfo } = await wasmClient.wasm.getContractInfo(contractAddress); assert(contractInfo); + expect(height).toBeGreaterThan(0); + expect(gasWanted).toBeGreaterThan(0); + expect(gasUsed).toBeGreaterThan(0); expect(contractInfo.admin).toEqual(unused.address); client.disconnect(); }); @@ -176,7 +182,12 @@ describe("SigningCosmWasmClient", () => { const options = { ...defaultSigningClientOptions, prefix: wasmd.prefix }; const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, options); const { codeId } = await client.upload(alice.address0, getHackatom().data, defaultUploadFee); - const { contractAddress: address1 } = await client.instantiate( + const { + contractAddress: address1, + height, + gasWanted, + gasUsed, + } = await client.instantiate( alice.address0, codeId, { @@ -196,6 +207,9 @@ describe("SigningCosmWasmClient", () => { "contract 2", defaultInstantiateFee, ); + expect(height).toBeGreaterThan(0); + expect(gasWanted).toBeGreaterThan(0); + expect(gasUsed).toBeGreaterThan(0); expect(address1).not.toEqual(address2); client.disconnect(); }); @@ -262,11 +276,18 @@ describe("SigningCosmWasmClient", () => { assert(contractInfo1); expect(contractInfo1.admin).toEqual(alice.address0); - await client.updateAdmin(alice.address0, contractAddress, unused.address, defaultUpdateAdminFee); + const { height, gasUsed, gasWanted } = await client.updateAdmin( + alice.address0, + contractAddress, + unused.address, + defaultUpdateAdminFee, + ); const { contractInfo: contractInfo2 } = await wasmClient.wasm.getContractInfo(contractAddress); assert(contractInfo2); expect(contractInfo2.admin).toEqual(unused.address); - + expect(height).toBeGreaterThan(0); + expect(gasWanted).toBeGreaterThan(0); + expect(gasUsed).toBeGreaterThan(0); client.disconnect(); }); }); @@ -297,11 +318,17 @@ describe("SigningCosmWasmClient", () => { assert(contractInfo1); expect(contractInfo1.admin).toEqual(alice.address0); - await client.clearAdmin(alice.address0, contractAddress, defaultClearAdminFee); + const { height, gasUsed, gasWanted } = await client.clearAdmin( + alice.address0, + contractAddress, + defaultClearAdminFee, + ); const { contractInfo: contractInfo2 } = await wasmClient.wasm.getContractInfo(contractAddress); assert(contractInfo2); expect(contractInfo2.admin).toEqual(""); - + expect(height).toBeGreaterThan(0); + expect(gasWanted).toBeGreaterThan(0); + expect(gasUsed).toBeGreaterThan(0); client.disconnect(); }); }); @@ -334,13 +361,16 @@ describe("SigningCosmWasmClient", () => { expect(contractInfo1.admin).toEqual(alice.address0); const newVerifier = makeRandomAddress(); - await client.migrate( + const { height, gasUsed, gasWanted } = await client.migrate( alice.address0, contractAddress, codeId2, { verifier: newVerifier }, defaultMigrateFee, ); + expect(height).toBeGreaterThan(0); + expect(gasWanted).toBeGreaterThan(0); + expect(gasUsed).toBeGreaterThan(0); const { contractInfo: contractInfo2 } = await wasmClient.wasm.getContractInfo(contractAddress); assert(contractInfo2); expect({ ...contractInfo2 }).toEqual({ @@ -424,6 +454,9 @@ describe("SigningCosmWasmClient", () => { { release: {} }, defaultExecuteFee, ); + 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"); assert(wasmEvent, "Event of type wasm expected"); expect(wasmEvent.attributes).toContain({ key: "action", value: "release" }); From baa257e61993b48e56eb451cf0c5b0510718a9cd Mon Sep 17 00:00:00 2001 From: Milan Steiner Date: Fri, 4 Feb 2022 09:46:36 +0100 Subject: [PATCH 4/4] Adding changes to CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46a3ff87..b0c72527 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ and this project adheres to `AminoTypesOptions`. This is an object with a required `prefix` field. Before the prefix defaulted to "cosmos" but this is almost never the right choice for CosmJS users that need to add Amino types manually. ([#989]) +- @cosmjs/cosmwasm-stargate: `height`, `gasWanted` and `gasUsed` have been added + to all result types of `SigningCosmWasmClient` [#989]: https://github.com/cosmos/cosmjs/issues/989