Change gasWanted/gasUsed to bigint

This commit is contained in:
Simon Warta 2023-10-26 15:37:35 +02:00
parent 9f33cd31de
commit 585338a3fa
11 changed files with 39 additions and 36 deletions

View File

@ -12,6 +12,8 @@ and this project adheres to
changes all 64 bit int fields from type `long` to `bigint`. As part of the changes all 64 bit int fields from type `long` to `bigint`. As part of the
upgrade, the types do not require the `long` and `protobufjs` anymore. upgrade, the types do not require the `long` and `protobufjs` anymore.
([#1484]) ([#1484])
- all: `gasWanted`/`gasUsed` fields were changed from type `number` to `bigint`
to supported cases where users put very high gas values in there ([#1465]).
- Drop support for Node.js 14 and add support for Node.js 20. ([#1421]) - Drop support for Node.js 14 and add support for Node.js 20. ([#1421])
- @cosmjs/tendermint-rpc: Remove `Adaptor` abstractions which are not needed - @cosmjs/tendermint-rpc: Remove `Adaptor` abstractions which are not needed
anymore by haing a dedicated client for each backend. anymore by haing a dedicated client for each backend.
@ -34,6 +36,7 @@ and this project adheres to
`.getCometClient`/`.forceGetCometClient`. `.getCometClient`/`.forceGetCometClient`.
[#1421]: https://github.com/cosmos/cosmjs/issues/1421 [#1421]: https://github.com/cosmos/cosmjs/issues/1421
[#1465]: https://github.com/cosmos/cosmjs/issues/1465
[#1484]: https://github.com/cosmos/cosmjs/pull/1484 [#1484]: https://github.com/cosmos/cosmjs/pull/1484
### Deprecated ### Deprecated

View File

@ -78,8 +78,8 @@ export interface UploadResult {
/** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */
readonly transactionHash: string; readonly transactionHash: string;
readonly events: readonly Event[]; readonly events: readonly Event[];
readonly gasWanted: number; readonly gasWanted: bigint;
readonly gasUsed: number; readonly gasUsed: bigint;
} }
/** /**
@ -112,8 +112,8 @@ export interface InstantiateResult {
/** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */
readonly transactionHash: string; readonly transactionHash: string;
readonly events: readonly Event[]; readonly events: readonly Event[];
readonly gasWanted: number; readonly gasWanted: bigint;
readonly gasUsed: number; readonly gasUsed: bigint;
} }
/** /**
@ -126,8 +126,8 @@ export interface ChangeAdminResult {
/** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */
readonly transactionHash: string; readonly transactionHash: string;
readonly events: readonly Event[]; readonly events: readonly Event[];
readonly gasWanted: number; readonly gasWanted: bigint;
readonly gasUsed: number; readonly gasUsed: bigint;
} }
export interface MigrateResult { export interface MigrateResult {
@ -137,8 +137,8 @@ export interface MigrateResult {
/** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */
readonly transactionHash: string; readonly transactionHash: string;
readonly events: readonly Event[]; readonly events: readonly Event[];
readonly gasWanted: number; readonly gasWanted: bigint;
readonly gasUsed: number; readonly gasUsed: bigint;
} }
export interface ExecuteInstruction { export interface ExecuteInstruction {
@ -154,8 +154,8 @@ export interface ExecuteResult {
/** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */
readonly transactionHash: string; readonly transactionHash: string;
readonly events: readonly Event[]; readonly events: readonly Event[];
readonly gasWanted: number; readonly gasWanted: bigint;
readonly gasUsed: number; readonly gasUsed: bigint;
} }
function createDeliverTxResponseErrorMessage(result: DeliverTxResponse): string { function createDeliverTxResponseErrorMessage(result: DeliverTxResponse): string {

View File

@ -366,9 +366,9 @@ describe("SigningStargateClient", () => {
const result = await client.signAndBroadcast(faucet.address0, [msgAny], fee, memo); const result = await client.signAndBroadcast(faucet.address0, [msgAny], fee, memo);
assertIsDeliverTxSuccess(result); assertIsDeliverTxSuccess(result);
expect(result.code).toEqual(0); expect(result.code).toEqual(0);
expect(result.gasWanted).toEqual(222_000); expect(result.gasWanted).toEqual(222_000n);
expect(result.gasUsed).toBeLessThanOrEqual(222_000); expect(Number(result.gasUsed)).toBeLessThanOrEqual(222_000);
expect(result.gasUsed).toBeGreaterThan(100_000); expect(Number(result.gasUsed)).toBeGreaterThan(100_000);
}); });
it("returns DeliverTxFailure on DeliverTx failure", async () => { it("returns DeliverTxFailure on DeliverTx failure", async () => {
@ -396,9 +396,9 @@ describe("SigningStargateClient", () => {
const result = await client.signAndBroadcast(faucet.address0, [msgAny], fee); const result = await client.signAndBroadcast(faucet.address0, [msgAny], fee);
assertIsDeliverTxFailure(result); assertIsDeliverTxFailure(result);
expect(result.code).toBeGreaterThan(0); expect(result.code).toBeGreaterThan(0);
expect(result.gasWanted).toEqual(99_000); expect(result.gasWanted).toEqual(99_000n);
expect(result.gasUsed).toBeLessThanOrEqual(99_000); expect(Number(result.gasUsed)).toBeLessThanOrEqual(99_000);
expect(result.gasUsed).toBeGreaterThan(40_000); expect(Number(result.gasUsed)).toBeGreaterThan(40_000);
}); });
it("works with auto gas", async () => { it("works with auto gas", async () => {

View File

@ -46,8 +46,8 @@ const resultFailure: DeliverTxResponse = {
transactionHash: "FDC4FB701AABD465935F7D04AE490D1EF5F2BD4B227601C4E98B57EB077D9B7D", transactionHash: "FDC4FB701AABD465935F7D04AE490D1EF5F2BD4B227601C4E98B57EB077D9B7D",
events: [], events: [],
msgResponses: [], msgResponses: [],
gasUsed: 54396, gasUsed: 54396n,
gasWanted: 200000, gasWanted: 200000n,
}; };
const resultSuccess: DeliverTxResponse = { const resultSuccess: DeliverTxResponse = {
code: 0, code: 0,
@ -58,8 +58,8 @@ const resultSuccess: DeliverTxResponse = {
transactionHash: "C0B416CA868C55C2B8C1BBB8F3CFA233854F13A5CB15D3E9599F50CAF7B3D161", transactionHash: "C0B416CA868C55C2B8C1BBB8F3CFA233854F13A5CB15D3E9599F50CAF7B3D161",
events: [], events: [],
msgResponses: [], msgResponses: [],
gasUsed: 61556, gasUsed: 61556n,
gasWanted: 200000, gasWanted: 200000n,
}; };
describe("isDeliverTxFailure", () => { describe("isDeliverTxFailure", () => {

View File

@ -91,8 +91,8 @@ export interface IndexedTx {
* This field is an empty list for chains running Cosmos SDK < 0.46. * This field is an empty list for chains running Cosmos SDK < 0.46.
*/ */
readonly msgResponses: Array<{ readonly typeUrl: string; readonly value: Uint8Array }>; readonly msgResponses: Array<{ readonly typeUrl: string; readonly value: Uint8Array }>;
readonly gasUsed: number; readonly gasUsed: bigint;
readonly gasWanted: number; readonly gasWanted: bigint;
} }
export interface SequenceResponse { export interface SequenceResponse {
@ -128,8 +128,8 @@ export interface DeliverTxResponse {
* This field is an empty list for chains running Cosmos SDK < 0.46. * This field is an empty list for chains running Cosmos SDK < 0.46.
*/ */
readonly msgResponses: Array<{ readonly typeUrl: string; readonly value: Uint8Array }>; readonly msgResponses: Array<{ readonly typeUrl: string; readonly value: Uint8Array }>;
readonly gasUsed: number; readonly gasUsed: bigint;
readonly gasWanted: number; readonly gasWanted: bigint;
} }
export function isDeliverTxFailure(result: DeliverTxResponse): boolean { export function isDeliverTxFailure(result: DeliverTxResponse): boolean {

View File

@ -159,8 +159,8 @@ function decodeTxData(data: RpcTxData): responses.TxData {
log: data.log, log: data.log,
data: may(fromBase64, data.data), data: may(fromBase64, data.data),
events: data.events ? decodeEvents(data.events) : [], events: data.events ? decodeEvents(data.events) : [],
gasWanted: apiToSmallInt(data.gas_wanted ?? "0"), gasWanted: apiToBigInt(data.gas_wanted ?? "0"),
gasUsed: apiToSmallInt(data.gas_used ?? "0"), gasUsed: apiToBigInt(data.gas_used ?? "0"),
}; };
} }

View File

@ -203,8 +203,8 @@ export interface TxData {
readonly log?: string; readonly log?: string;
readonly data?: Uint8Array; readonly data?: Uint8Array;
readonly events: readonly Event[]; readonly events: readonly Event[];
readonly gasWanted: number; readonly gasWanted: bigint;
readonly gasUsed: number; readonly gasUsed: bigint;
} }
export interface TxProof { export interface TxProof {

View File

@ -158,8 +158,8 @@ function decodeTxData(data: RpcTxData): responses.TxData {
log: data.log, log: data.log,
data: may(fromBase64, data.data), data: may(fromBase64, data.data),
events: data.events ? decodeEvents(data.events) : [], events: data.events ? decodeEvents(data.events) : [],
gasWanted: apiToSmallInt(data.gas_wanted ?? "0"), gasWanted: apiToBigInt(data.gas_wanted ?? "0"),
gasUsed: apiToSmallInt(data.gas_used ?? "0"), gasUsed: apiToBigInt(data.gas_used ?? "0"),
}; };
} }

View File

@ -196,8 +196,8 @@ export interface TxData {
readonly log?: string; readonly log?: string;
readonly data?: Uint8Array; readonly data?: Uint8Array;
readonly events: readonly Event[]; readonly events: readonly Event[];
readonly gasWanted: number; readonly gasWanted: bigint;
readonly gasUsed: number; readonly gasUsed: bigint;
} }
export interface TxProof { export interface TxProof {

View File

@ -159,8 +159,8 @@ function decodeTxData(data: RpcTxData): responses.TxData {
log: data.log, log: data.log,
data: may(fromBase64, data.data), data: may(fromBase64, data.data),
events: data.events ? decodeEvents(data.events) : [], events: data.events ? decodeEvents(data.events) : [],
gasWanted: apiToSmallInt(data.gas_wanted ?? "0"), gasWanted: apiToBigInt(data.gas_wanted ?? "0"),
gasUsed: apiToSmallInt(data.gas_used ?? "0"), gasUsed: apiToBigInt(data.gas_used ?? "0"),
}; };
} }

View File

@ -201,8 +201,8 @@ export interface TxData {
readonly log?: string; readonly log?: string;
readonly data?: Uint8Array; readonly data?: Uint8Array;
readonly events: readonly Event[]; readonly events: readonly Event[];
readonly gasWanted: number; readonly gasWanted: bigint;
readonly gasUsed: number; readonly gasUsed: bigint;
} }
export interface TxProof { export interface TxProof {