Change gasWanted/gasUsed to bigint

This commit is contained in:
Simon Warta
2023-10-26 16:16:19 +02:00
parent 9f33cd31de
commit 585338a3fa
11 changed files with 39 additions and 36 deletions
@@ -78,8 +78,8 @@ export interface UploadResult {
/** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */
readonly transactionHash: string;
readonly events: readonly Event[];
readonly gasWanted: number;
readonly gasUsed: number;
readonly gasWanted: bigint;
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 */
readonly transactionHash: string;
readonly events: readonly Event[];
readonly gasWanted: number;
readonly gasUsed: number;
readonly gasWanted: bigint;
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 */
readonly transactionHash: string;
readonly events: readonly Event[];
readonly gasWanted: number;
readonly gasUsed: number;
readonly gasWanted: bigint;
readonly gasUsed: bigint;
}
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 */
readonly transactionHash: string;
readonly events: readonly Event[];
readonly gasWanted: number;
readonly gasUsed: number;
readonly gasWanted: bigint;
readonly gasUsed: bigint;
}
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 */
readonly transactionHash: string;
readonly events: readonly Event[];
readonly gasWanted: number;
readonly gasUsed: number;
readonly gasWanted: bigint;
readonly gasUsed: bigint;
}
function createDeliverTxResponseErrorMessage(result: DeliverTxResponse): string {
@@ -366,9 +366,9 @@ describe("SigningStargateClient", () => {
const result = await client.signAndBroadcast(faucet.address0, [msgAny], fee, memo);
assertIsDeliverTxSuccess(result);
expect(result.code).toEqual(0);
expect(result.gasWanted).toEqual(222_000);
expect(result.gasUsed).toBeLessThanOrEqual(222_000);
expect(result.gasUsed).toBeGreaterThan(100_000);
expect(result.gasWanted).toEqual(222_000n);
expect(Number(result.gasUsed)).toBeLessThanOrEqual(222_000);
expect(Number(result.gasUsed)).toBeGreaterThan(100_000);
});
it("returns DeliverTxFailure on DeliverTx failure", async () => {
@@ -396,9 +396,9 @@ describe("SigningStargateClient", () => {
const result = await client.signAndBroadcast(faucet.address0, [msgAny], fee);
assertIsDeliverTxFailure(result);
expect(result.code).toBeGreaterThan(0);
expect(result.gasWanted).toEqual(99_000);
expect(result.gasUsed).toBeLessThanOrEqual(99_000);
expect(result.gasUsed).toBeGreaterThan(40_000);
expect(result.gasWanted).toEqual(99_000n);
expect(Number(result.gasUsed)).toBeLessThanOrEqual(99_000);
expect(Number(result.gasUsed)).toBeGreaterThan(40_000);
});
it("works with auto gas", async () => {
+4 -4
View File
@@ -46,8 +46,8 @@ const resultFailure: DeliverTxResponse = {
transactionHash: "FDC4FB701AABD465935F7D04AE490D1EF5F2BD4B227601C4E98B57EB077D9B7D",
events: [],
msgResponses: [],
gasUsed: 54396,
gasWanted: 200000,
gasUsed: 54396n,
gasWanted: 200000n,
};
const resultSuccess: DeliverTxResponse = {
code: 0,
@@ -58,8 +58,8 @@ const resultSuccess: DeliverTxResponse = {
transactionHash: "C0B416CA868C55C2B8C1BBB8F3CFA233854F13A5CB15D3E9599F50CAF7B3D161",
events: [],
msgResponses: [],
gasUsed: 61556,
gasWanted: 200000,
gasUsed: 61556n,
gasWanted: 200000n,
};
describe("isDeliverTxFailure", () => {
+4 -4
View File
@@ -91,8 +91,8 @@ export interface IndexedTx {
* This field is an empty list for chains running Cosmos SDK < 0.46.
*/
readonly msgResponses: Array<{ readonly typeUrl: string; readonly value: Uint8Array }>;
readonly gasUsed: number;
readonly gasWanted: number;
readonly gasUsed: bigint;
readonly gasWanted: bigint;
}
export interface SequenceResponse {
@@ -128,8 +128,8 @@ export interface DeliverTxResponse {
* This field is an empty list for chains running Cosmos SDK < 0.46.
*/
readonly msgResponses: Array<{ readonly typeUrl: string; readonly value: Uint8Array }>;
readonly gasUsed: number;
readonly gasWanted: number;
readonly gasUsed: bigint;
readonly gasWanted: bigint;
}
export function isDeliverTxFailure(result: DeliverTxResponse): boolean {
@@ -159,8 +159,8 @@ function decodeTxData(data: RpcTxData): responses.TxData {
log: data.log,
data: may(fromBase64, data.data),
events: data.events ? decodeEvents(data.events) : [],
gasWanted: apiToSmallInt(data.gas_wanted ?? "0"),
gasUsed: apiToSmallInt(data.gas_used ?? "0"),
gasWanted: apiToBigInt(data.gas_wanted ?? "0"),
gasUsed: apiToBigInt(data.gas_used ?? "0"),
};
}
@@ -203,8 +203,8 @@ export interface TxData {
readonly log?: string;
readonly data?: Uint8Array;
readonly events: readonly Event[];
readonly gasWanted: number;
readonly gasUsed: number;
readonly gasWanted: bigint;
readonly gasUsed: bigint;
}
export interface TxProof {
@@ -158,8 +158,8 @@ function decodeTxData(data: RpcTxData): responses.TxData {
log: data.log,
data: may(fromBase64, data.data),
events: data.events ? decodeEvents(data.events) : [],
gasWanted: apiToSmallInt(data.gas_wanted ?? "0"),
gasUsed: apiToSmallInt(data.gas_used ?? "0"),
gasWanted: apiToBigInt(data.gas_wanted ?? "0"),
gasUsed: apiToBigInt(data.gas_used ?? "0"),
};
}
@@ -196,8 +196,8 @@ export interface TxData {
readonly log?: string;
readonly data?: Uint8Array;
readonly events: readonly Event[];
readonly gasWanted: number;
readonly gasUsed: number;
readonly gasWanted: bigint;
readonly gasUsed: bigint;
}
export interface TxProof {
@@ -159,8 +159,8 @@ function decodeTxData(data: RpcTxData): responses.TxData {
log: data.log,
data: may(fromBase64, data.data),
events: data.events ? decodeEvents(data.events) : [],
gasWanted: apiToSmallInt(data.gas_wanted ?? "0"),
gasUsed: apiToSmallInt(data.gas_used ?? "0"),
gasWanted: apiToBigInt(data.gas_wanted ?? "0"),
gasUsed: apiToBigInt(data.gas_used ?? "0"),
};
}
@@ -201,8 +201,8 @@ export interface TxData {
readonly log?: string;
readonly data?: Uint8Array;
readonly events: readonly Event[];
readonly gasWanted: number;
readonly gasUsed: number;
readonly gasWanted: bigint;
readonly gasUsed: bigint;
}
export interface TxProof {