From 8d423be22320d113550ea3874813cccb6065c140 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Tue, 12 Nov 2019 11:30:24 -0800 Subject: [PATCH] Use strings instead of bignumbers, and add JSON.stringify call --- .../src/subproviders/debug_subprovider.ts | 20 +++++++++---------- .../test/unit/debug_subprovider_test.ts | 20 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/packages/subproviders/src/subproviders/debug_subprovider.ts b/packages/subproviders/src/subproviders/debug_subprovider.ts index a516c5f8ae..332bcd81a8 100644 --- a/packages/subproviders/src/subproviders/debug_subprovider.ts +++ b/packages/subproviders/src/subproviders/debug_subprovider.ts @@ -9,10 +9,10 @@ import { Subprovider } from './subprovider'; const HEX_BASE = 16; export interface DebugPayloadRawTransactionAttributes { - gasPrice: BigNumber; - gasLimit: BigNumber; - nonce: BigNumber; - value: BigNumber; + gasPrice: string; + gasLimit: string; + nonce: string; + value: string; to: string; } export interface DebugPayload extends JSONRPCRequestPayload { @@ -21,7 +21,7 @@ export interface DebugPayload extends JSONRPCRequestPayload { export type WithDebugPayload = (debugPayload: DebugPayload) => void; // tslint:disable-next-line:no-console -const defaultDebugCallback = (debugPayload: DebugPayload) => console.debug(debugPayload); +const defaultDebugCallback = (debugPayload: DebugPayload) => console.debug(JSON.stringify(debugPayload, null, 2)); /** * This class implements the [web3-provider-engine](https://github.com/MetaMask/provider-engine) subprovider interface. @@ -32,13 +32,13 @@ export class DebugSubprovider extends Subprovider { private readonly _debugCallback: WithDebugPayload; private static _generateRawTransactionAttributes(txn: EthereumTx): DebugPayloadRawTransactionAttributes { - const hexBufferToBN = (value: Buffer) => new BigNumber(value.toString('hex'), HEX_BASE); + const hexBufferToString = (value: Buffer): string => new BigNumber(value.toString('hex'), HEX_BASE).toString(); return { - gasLimit: hexBufferToBN(txn.gasLimit), - gasPrice: hexBufferToBN(txn.gasPrice), - nonce: hexBufferToBN(txn.nonce), - value: hexBufferToBN(txn.value), + gasLimit: hexBufferToString(txn.gasLimit), + gasPrice: hexBufferToString(txn.gasPrice), + nonce: hexBufferToString(txn.nonce), + value: hexBufferToString(txn.value), to: `0x${txn.to.toString('hex')}`, }; } diff --git a/packages/subproviders/test/unit/debug_subprovider_test.ts b/packages/subproviders/test/unit/debug_subprovider_test.ts index 67948b0484..1c2e178639 100644 --- a/packages/subproviders/test/unit/debug_subprovider_test.ts +++ b/packages/subproviders/test/unit/debug_subprovider_test.ts @@ -39,11 +39,11 @@ describe('DebugSubprovider', () => { if (!rawTxnAttrs) { fail('No rawTransactionAttributes'); } else { - expect(rawTxnAttrs.gasLimit.toString()).to.eql('37428'); - expect(rawTxnAttrs.gasPrice.toString()).to.eql('1000000000'); - expect(rawTxnAttrs.nonce.toString()).to.eql('32'); - expect(rawTxnAttrs.value.toString()).to.eql('0'); - expect(rawTxnAttrs.to.toString()).to.eql('0x2002d3812f58e35f0ea1ffbf80a75a38c32175fa'); + expect(rawTxnAttrs.gasLimit).to.eql('37428'); + expect(rawTxnAttrs.gasPrice).to.eql('1000000000'); + expect(rawTxnAttrs.nonce).to.eql('32'); + expect(rawTxnAttrs.value).to.eql('0'); + expect(rawTxnAttrs.to).to.eql('0x2002d3812f58e35f0ea1ffbf80a75a38c32175fa'); } } }); @@ -75,11 +75,11 @@ describe('DebugSubprovider', () => { if (!rawTxnAttrs) { fail('No rawTransactionAttributes'); } else { - expect(rawTxnAttrs.gasLimit.toString()).to.eql('21000'); - expect(rawTxnAttrs.gasPrice.toString()).to.eql('8000000000'); - expect(rawTxnAttrs.nonce.toString()).to.eql('38'); - expect(rawTxnAttrs.value.toString()).to.eql('410000000000000'); - expect(rawTxnAttrs.to.toString()).to.eql('0x8a333a18b924554d6e83ef9e9944de6260f61d3b'); + expect(rawTxnAttrs.gasLimit).to.eql('21000'); + expect(rawTxnAttrs.gasPrice).to.eql('8000000000'); + expect(rawTxnAttrs.nonce).to.eql('38'); + expect(rawTxnAttrs.value).to.eql('410000000000000'); + expect(rawTxnAttrs.to).to.eql('0x8a333a18b924554d6e83ef9e9944de6260f61d3b'); } } });