From 47e35d192b1625fb52e609cb24b8405fbcb61c3c Mon Sep 17 00:00:00 2001 From: Nicholas Rodrigues Lordello Date: Thu, 30 Apr 2020 12:54:17 +0200 Subject: [PATCH] fix lints and improve test plna --- package.json | 1 + src/streamed/index.ts | 12 +++++------- test/models/streamed/index.spec.ts | 15 ++++++++++++--- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 979aae7de..9c1ae126e 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "test-stablex": "yarn run test-js test/stablex/*", "test-js": "truffle test", "test-ts": "mocha -r ts-node/register 'test/models/**/*spec.ts'", + "test-streamed-orderbook": "TEST_STREAMED_ORDERBOOK_E2E=1 mocha -r ts-node/register test/models/streamed/index.spec.ts", "coverage": "truffle run coverage --network coverage --file \"{build/common/,}test/*js\"", "networks-extract": "CONF_FILE=$(pwd)'/migration_conf.js' node node_modules/@gnosis.pm/util-contracts/src/extract_network_info.js", "networks-inject": "CONF_FILE=$(pwd)'/migration_conf.js' node node_modules/@gnosis.pm/util-contracts/src/inject_network_info.js", diff --git a/src/streamed/index.ts b/src/streamed/index.ts index 0635dafea..263bf48fe 100644 --- a/src/streamed/index.ts +++ b/src/streamed/index.ts @@ -13,12 +13,10 @@ * @packageDocumentation */ -import assert from 'assert' -import Web3 from 'web3' -import { TransactionReceipt } from 'web3-core' -import { EventData } from 'web3-eth-contract' -import { BatchExchange, BatchExchangeArtifact } from '../..' -import { AccountState } from './state' +import Web3 from "web3" +import { TransactionReceipt } from "web3-core" +import { BatchExchange, BatchExchangeArtifact } from "../.." +import { AccountState } from "./state" /** * Configuration options for the streamed orderbook. @@ -138,7 +136,7 @@ export class StreamedOrderbook { this.options.logger?.debug(`fetching page ${fromBlock}-${toBlock}`) const events = await this.contract.getPastEvents( - 'allEvents', + "allEvents", { fromBlock, toBlock }, ) diff --git a/test/models/streamed/index.spec.ts b/test/models/streamed/index.spec.ts index 9be3007e1..bcf785881 100644 --- a/test/models/streamed/index.spec.ts +++ b/test/models/streamed/index.spec.ts @@ -6,15 +6,24 @@ import { StreamedOrderbook } from "../../../src/streamed" describe("Streamed Orderbook", () => { describe("init", () => { it("should successfully apply all events and match on-chain orderbook", async function() { - const { ETHEREUM_NODE_URL, ORDERBOOK_END_BLOCK, TEST_STREAMED_ORDERBOOK_E2E } = process.env + const { + ETHEREUM_NODE_URL, + INFURA_PROJECT_ID, + ORDERBOOK_END_BLOCK, + TEST_STREAMED_ORDERBOOK_E2E, + } = process.env if (!TEST_STREAMED_ORDERBOOK_E2E) { this.skip() return } - assert.isDefined(ETHEREUM_NODE_URL, "ETHEREUM_NODE_URL environment variable is required"); + assert.isDefined( + ETHEREUM_NODE_URL || INFURA_PROJECT_ID, + "ETHEREUM_NODE_URL or INFURA_PROJECT_ID environment variable is required", + ) + const url = ETHEREUM_NODE_URL || `https://mainnet.infura.io/v3/${INFURA_PROJECT_ID}` + const web3 = new Web3(url) - const web3 = new Web3(ETHEREUM_NODE_URL!) await StreamedOrderbook.init(web3, { endBlock: ORDERBOOK_END_BLOCK ? parseInt(ORDERBOOK_END_BLOCK) : undefined, strict: true,