Use strings instead of bignumbers, and add JSON.stringify call
This commit is contained in:
@@ -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')}`,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user