aboutsummaryrefslogtreecommitdiffstats
path: root/packages/subproviders
diff options
context:
space:
mode:
authorJacob Evans <jacob@dekz.net>2018-01-31 13:23:51 +0800
committerJacob Evans <jacob@dekz.net>2018-02-02 08:06:22 +0800
commit58dd90b7b7408a04a39e2e643c77bbf86859df1d (patch)
tree1c15bb44b58bc13520606bd7d67ac531ef365130 /packages/subproviders
parentead990a734e0caf0ce0e5d0297c487756894acf2 (diff)
downloaddexon-0x-contracts-58dd90b7b7408a04a39e2e643c77bbf86859df1d.tar
dexon-0x-contracts-58dd90b7b7408a04a39e2e643c77bbf86859df1d.tar.gz
dexon-0x-contracts-58dd90b7b7408a04a39e2e643c77bbf86859df1d.tar.bz2
dexon-0x-contracts-58dd90b7b7408a04a39e2e643c77bbf86859df1d.tar.lz
dexon-0x-contracts-58dd90b7b7408a04a39e2e643c77bbf86859df1d.tar.xz
dexon-0x-contracts-58dd90b7b7408a04a39e2e643c77bbf86859df1d.tar.zst
dexon-0x-contracts-58dd90b7b7408a04a39e2e643c77bbf86859df1d.zip
Prettify
Diffstat (limited to 'packages/subproviders')
-rw-r--r--packages/subproviders/src/globals.d.ts1
-rw-r--r--packages/subproviders/src/subproviders/nonce_tracker.ts11
-rw-r--r--packages/subproviders/test/unit/nonce_tracker_subprovider_test.ts121
3 files changed, 65 insertions, 68 deletions
diff --git a/packages/subproviders/src/globals.d.ts b/packages/subproviders/src/globals.d.ts
index 595bae89e..325dc27ed 100644
--- a/packages/subproviders/src/globals.d.ts
+++ b/packages/subproviders/src/globals.d.ts
@@ -1,4 +1,3 @@
-
declare module 'dirty-chai';
declare module 'es6-promisify';
diff --git a/packages/subproviders/src/subproviders/nonce_tracker.ts b/packages/subproviders/src/subproviders/nonce_tracker.ts
index 540a91771..560f2dd68 100644
--- a/packages/subproviders/src/subproviders/nonce_tracker.ts
+++ b/packages/subproviders/src/subproviders/nonce_tracker.ts
@@ -1,4 +1,3 @@
-import { promisify } from '@0xproject/utils';
import * as _ from 'lodash';
import EthereumTx = require('ethereumjs-tx');
@@ -46,21 +45,17 @@ export class NonceTrackerSubprovider extends Subprovider {
const address = NonceTrackerSubprovider._determineAddress(payload);
const cachedResult = this._nonceCache[address];
if (cachedResult) {
- end(null, cachedResult);
- return;
+ return end(null, cachedResult);
} else {
- next((requestError: Error | null, requestResult: any, cb: any) => {
+ return next((requestError: Error | null, requestResult: any, cb: any) => {
if (_.isNull(requestError)) {
this._nonceCache[address] = requestResult as string;
}
cb();
- return;
});
- return;
}
} else {
- next();
- return;
+ return next();
}
case 'eth_sendRawTransaction':
return next(async (sendTransactionError: Error | null, txResult: any, cb: any) => {
diff --git a/packages/subproviders/test/unit/nonce_tracker_subprovider_test.ts b/packages/subproviders/test/unit/nonce_tracker_subprovider_test.ts
index a99f1f9fb..9bb8268cb 100644
--- a/packages/subproviders/test/unit/nonce_tracker_subprovider_test.ts
+++ b/packages/subproviders/test/unit/nonce_tracker_subprovider_test.ts
@@ -1,6 +1,5 @@
import * as chai from 'chai';
import * as _ from 'lodash';
-import Web3 = require('web3');
import Web3ProviderEngine = require('web3-provider-engine');
import FixtureSubprovider = require('web3-provider-engine/subproviders/fixture');
@@ -8,11 +7,7 @@ import promisify = require('es6-promisify');
import EthereumTx = require('ethereumjs-tx');
import { NonceTrackerSubprovider } from '../../src';
-import { DoneCallback } from '../../src/types';
import { chaiSetup } from '../chai_setup';
-import { reportCallbackErrors } from '../utils/report_callback_errors';
-
-import { Subprovider } from '../../src/subproviders/subprovider';
const expect = chai.expect;
chaiSetup.configure();
@@ -24,17 +19,19 @@ describe('NonceTrackerSubprovider', () => {
let called = false;
const nonceTrackerSubprovider = new NonceTrackerSubprovider();
provider.addProvider(nonceTrackerSubprovider);
- provider.addProvider(new FixtureSubprovider({
- 'eth_getBlockByNumber': '0x01',
- 'eth_getTransactionCount': (data: any, next: any, end: any) => {
- if (called) {
- return end(null, '0x99');
- } else {
- called = true;
- end(null, '0x01');
- }
- },
- }));
+ provider.addProvider(
+ new FixtureSubprovider({
+ eth_getBlockByNumber: '0x01',
+ eth_getTransactionCount: (data: any, next: any, end: any) => {
+ if (called) {
+ return end(null, '0x99');
+ } else {
+ called = true;
+ end(null, '0x01');
+ }
+ },
+ }),
+ );
provider.start();
const payload = {
@@ -54,17 +51,19 @@ describe('NonceTrackerSubprovider', () => {
let called = false;
const nonceTrackerSubprovider = new NonceTrackerSubprovider();
provider.addProvider(nonceTrackerSubprovider);
- provider.addProvider(new FixtureSubprovider({
- 'eth_getBlockByNumber': '0x01',
- 'eth_getTransactionCount': (data: any, next: any, end: any) => {
- if (called) {
- return end(null, '0x99');
- } else {
- called = true;
- end(null, '0x01');
- }
- },
- }));
+ provider.addProvider(
+ new FixtureSubprovider({
+ eth_getBlockByNumber: '0x01',
+ eth_getTransactionCount: (data: any, next: any, end: any) => {
+ if (called) {
+ return end(null, '0x99');
+ } else {
+ called = true;
+ end(null, '0x01');
+ }
+ },
+ }),
+ );
provider.start();
const payload = {
@@ -84,20 +83,22 @@ describe('NonceTrackerSubprovider', () => {
let called = false;
const nonceTrackerSubprovider = new NonceTrackerSubprovider();
provider.addProvider(nonceTrackerSubprovider);
- provider.addProvider(new FixtureSubprovider({
- 'eth_getBlockByNumber': '0x01',
- 'eth_getTransactionCount': (data: any, next: any, end: any) => {
- if (called) {
- return end(null, '0x99');
- } else {
- called = true;
- end(null, '0x01');
- }
- },
- 'eth_sendRawTransaction': (data: any, next: any, end: any) => {
- end(new Error('Transaction nonce is too low'));
- },
- }));
+ provider.addProvider(
+ new FixtureSubprovider({
+ eth_getBlockByNumber: '0x01',
+ eth_getTransactionCount: (data: any, next: any, end: any) => {
+ if (called) {
+ return end(null, '0x99');
+ } else {
+ called = true;
+ end(null, '0x01');
+ }
+ },
+ eth_sendRawTransaction: (data: any, next: any, end: any) => {
+ end(new Error('Transaction nonce is too low'));
+ },
+ }),
+ );
provider.start();
const noncePayload = {
@@ -115,7 +116,7 @@ describe('NonceTrackerSubprovider', () => {
'0x7f7465737432000000000000000000000000000000000000000000000000000000600057',
'0x1c',
'0x5e1d3a76fbf824220eafc8c79ad578ad2b67d01b0c2425eb1f1347e8f50882ab',
- '0x5bd428537f05f9830e93792f90ea6a3e2d1ee84952dd96edbae9f658f831ab13'
+ '0x5bd428537f05f9830e93792f90ea6a3e2d1ee84952dd96edbae9f658f831ab13',
];
const transaction = new EthereumTx(txParams);
@@ -131,7 +132,7 @@ describe('NonceTrackerSubprovider', () => {
const secondResponse = await promisify(provider.sendAsync, provider)(noncePayload);
expect(secondResponse.result).to.be.eq('0x01');
try {
- const txResponse = await promisify(provider.sendAsync, provider)(txPayload);
+ await promisify(provider.sendAsync, provider)(txPayload);
} catch (err) {
const thirdResponse = await promisify(provider.sendAsync, provider)(noncePayload);
expect(thirdResponse.result).to.be.eq('0x99');
@@ -142,20 +143,22 @@ describe('NonceTrackerSubprovider', () => {
let called = false;
const nonceTrackerSubprovider = new NonceTrackerSubprovider();
provider.addProvider(nonceTrackerSubprovider);
- provider.addProvider(new FixtureSubprovider({
- 'eth_getBlockByNumber': '0x01',
- 'eth_getTransactionCount': (data: any, next: any, end: any) => {
- if (called) {
- return end(null, '0x99');
- } else {
- called = true;
- end(null, '0x00');
- }
- },
- 'eth_sendRawTransaction': (data: any, next: any, end: any) => {
- end(null);
- },
- }));
+ provider.addProvider(
+ new FixtureSubprovider({
+ eth_getBlockByNumber: '0x01',
+ eth_getTransactionCount: (data: any, next: any, end: any) => {
+ if (called) {
+ return end(null, '0x99');
+ } else {
+ called = true;
+ end(null, '0x00');
+ }
+ },
+ eth_sendRawTransaction: (data: any, next: any, end: any) => {
+ end(null);
+ },
+ }),
+ );
provider.start();
const noncePayload = {
@@ -173,7 +176,7 @@ describe('NonceTrackerSubprovider', () => {
'0x7f7465737432000000000000000000000000000000000000000000000000000000600057',
'0x1c',
'0x5e1d3a76fbf824220eafc8c79ad578ad2b67d01b0c2425eb1f1347e8f50882ab',
- '0x5bd428537f05f9830e93792f90ea6a3e2d1ee84952dd96edbae9f658f831ab13'
+ '0x5bd428537f05f9830e93792f90ea6a3e2d1ee84952dd96edbae9f658f831ab13',
];
const transaction = new EthereumTx(txParams);
@@ -188,7 +191,7 @@ describe('NonceTrackerSubprovider', () => {
expect(response.result).to.be.eq('0x00');
const secondResponse = await promisify(provider.sendAsync, provider)(noncePayload);
expect(secondResponse.result).to.be.eq('0x00');
- const txResponse = await promisify(provider.sendAsync, provider)(txPayload);
+ await promisify(provider.sendAsync, provider)(txPayload);
const thirdResponse = await promisify(provider.sendAsync, provider)(noncePayload);
expect(thirdResponse.result).to.be.eq('0x01');
});