Skip to content

Commit

Permalink
feat: change the data type to DeliverTx
Browse files Browse the repository at this point in the history
  • Loading branch information
jinoosss committed Nov 28, 2024
1 parent 9e45d2c commit 9efdbe7
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 30 deletions.
18 changes: 11 additions & 7 deletions src/provider/jsonrpc/jsonrpc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import {
ABCIAccount,
ABCIErrorKey,
ABCIResponse,
ABCIResponseSimulateTx,
BlockInfo,
BlockResult,
BroadcastTxSyncResult,
ConsensusParams,
DeliverTx,
NetworkInfo,
RPCRequest,
Status,
Expand All @@ -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<ABCIResponse>();
Expand Down
2 changes: 1 addition & 1 deletion src/provider/jsonrpc/jsonrpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class JSONRPCProvider implements Provider {
const simulateResult = extractSimulateFromResponse(
abciResponse.response.Value
);
return simulateResult.GasUsed;
return parseInt(simulateResult.GasUsed);
}

async getBalance(
Expand Down
8 changes: 0 additions & 8 deletions src/provider/types/abci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
12 changes: 6 additions & 6 deletions src/provider/utility/provider.utility.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -99,15 +99,15 @@ 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');
}

try {
// Parse the account
return parseABCI<ABCIResponseSimulateTx>(abciData);
return parseABCI<DeliverTx>(abciData);
} catch (e) {
throw new Error('account is not initialized');
}
Expand Down
18 changes: 11 additions & 7 deletions src/provider/websocket/ws.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import {
ABCIErrorKey,
ABCIResponse,
ABCIResponseBase,
ABCIResponseSimulateTx,
BeginBlock,
BlockInfo,
BlockResult,
BroadcastTxSyncResult,
ConsensusParams,
DeliverTx,
EndBlock,
NetworkInfo,
Status,
Expand Down Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion src/provider/websocket/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export class WSProvider implements Provider {
const simulateResult = extractSimulateFromResponse(
abciResponse.response.Value
);
return simulateResult.GasUsed;
return parseInt(simulateResult.GasUsed);
}

async getBalance(
Expand Down

0 comments on commit 9efdbe7

Please sign in to comment.