From 9efdbe70b3b575d681d8a1d8cd58d0473c525363 Mon Sep 17 00:00:00 2001 From: jinoosss Date: Thu, 28 Nov 2024 15:55:26 +0900 Subject: [PATCH] feat: change the data type to DeliverTx --- src/provider/jsonrpc/jsonrpc.test.ts | 18 +++++++++++------- src/provider/jsonrpc/jsonrpc.ts | 2 +- src/provider/types/abci.ts | 8 -------- src/provider/utility/provider.utility.ts | 12 ++++++------ src/provider/websocket/ws.test.ts | 18 +++++++++++------- src/provider/websocket/ws.ts | 2 +- 6 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/provider/jsonrpc/jsonrpc.test.ts b/src/provider/jsonrpc/jsonrpc.test.ts index 5235979..c5927fd 100644 --- a/src/provider/jsonrpc/jsonrpc.test.ts +++ b/src/provider/jsonrpc/jsonrpc.test.ts @@ -10,11 +10,11 @@ import { ABCIAccount, ABCIErrorKey, ABCIResponse, - ABCIResponseSimulateTx, BlockInfo, BlockResult, BroadcastTxSyncResult, ConsensusParams, + DeliverTx, NetworkInfo, RPCRequest, Status, @@ -40,12 +40,16 @@ describe('JSON-RPC Provider', () => { }); const expectedEstimation = 1000; - const mockSimulateResponse: ABCIResponseSimulateTx = { - Data: null, - Error: null, - Events: null, - GasWanted: 0, - GasUsed: expectedEstimation, + const mockSimulateResponse: DeliverTx = { + ResponseBase: { + Data: null, + Error: null, + Events: null, + Info: '', + Log: '', + }, + GasWanted: '0', + GasUsed: expectedEstimation.toString(), }; const mockABCIResponse: ABCIResponse = mock(); diff --git a/src/provider/jsonrpc/jsonrpc.ts b/src/provider/jsonrpc/jsonrpc.ts index 9292ce9..cee88bb 100644 --- a/src/provider/jsonrpc/jsonrpc.ts +++ b/src/provider/jsonrpc/jsonrpc.ts @@ -64,7 +64,7 @@ export class JSONRPCProvider implements Provider { const simulateResult = extractSimulateFromResponse( abciResponse.response.Value ); - return simulateResult.GasUsed; + return parseInt(simulateResult.GasUsed); } async getBalance( diff --git a/src/provider/types/abci.ts b/src/provider/types/abci.ts index c33c535..1ce603a 100644 --- a/src/provider/types/abci.ts +++ b/src/provider/types/abci.ts @@ -47,12 +47,4 @@ export interface ABCIAccount { }; } -export interface ABCIResponseSimulateTx { - Error: string | null; - Data: string | null; - Events: any[] | null; - GasWanted: number; - GasUsed: number; -} - export const ABCIErrorKey = '@type'; diff --git a/src/provider/utility/provider.utility.ts b/src/provider/utility/provider.utility.ts index af9c570..9701671 100644 --- a/src/provider/utility/provider.utility.ts +++ b/src/provider/utility/provider.utility.ts @@ -1,12 +1,12 @@ -import { ABCIAccount, ABCIResponseSimulateTx, BlockInfo } from '../types'; +import { sha256 } from '@cosmjs/crypto'; +import { Tx } from '../../proto'; +import { Provider } from '../provider'; +import { ABCIAccount, BlockInfo, DeliverTx } from '../types'; import { base64ToUint8Array, parseABCI, uint8ArrayToBase64, } from './requests.utility'; -import { Provider } from '../provider'; -import { Tx } from '../../proto'; -import { sha256 } from '@cosmjs/crypto'; /** * Extracts the specific balance denomination from the ABCI response @@ -99,7 +99,7 @@ export const extractAccountNumberFromResponse = ( */ export const extractSimulateFromResponse = ( abciData: string | null -): ABCIResponseSimulateTx => { +): DeliverTx => { // Make sure the response is initialized if (!abciData) { throw new Error('abci data is not initialized'); @@ -107,7 +107,7 @@ export const extractSimulateFromResponse = ( try { // Parse the account - return parseABCI(abciData); + return parseABCI(abciData); } catch (e) { throw new Error('account is not initialized'); } diff --git a/src/provider/websocket/ws.test.ts b/src/provider/websocket/ws.test.ts index cef0926..6294b78 100644 --- a/src/provider/websocket/ws.test.ts +++ b/src/provider/websocket/ws.test.ts @@ -10,12 +10,12 @@ import { ABCIErrorKey, ABCIResponse, ABCIResponseBase, - ABCIResponseSimulateTx, BeginBlock, BlockInfo, BlockResult, BroadcastTxSyncResult, ConsensusParams, + DeliverTx, EndBlock, NetworkInfo, Status, @@ -90,12 +90,16 @@ describe('WS Provider', () => { }); const expectedEstimation = 1000; - const mockSimulateResponse: ABCIResponseSimulateTx = { - Data: null, - Error: null, - Events: null, - GasWanted: 0, - GasUsed: expectedEstimation, + const mockSimulateResponse: DeliverTx = { + ResponseBase: { + Data: null, + Error: null, + Events: null, + Info: '', + Log: '', + }, + GasWanted: '0', + GasUsed: expectedEstimation.toString(), }; const mockABCIResponse: ABCIResponse = { diff --git a/src/provider/websocket/ws.ts b/src/provider/websocket/ws.ts index 7ddf288..ea8e3a6 100644 --- a/src/provider/websocket/ws.ts +++ b/src/provider/websocket/ws.ts @@ -167,7 +167,7 @@ export class WSProvider implements Provider { const simulateResult = extractSimulateFromResponse( abciResponse.response.Value ); - return simulateResult.GasUsed; + return parseInt(simulateResult.GasUsed); } async getBalance(