From ebb2308df7fffd2868c06050d023723aaa849499 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Guti=C3=A9rrez?= Date: Thu, 21 Mar 2019 03:02:05 +0100 Subject: [PATCH] Fix integration tests and remove parallel execution workaround. --- integration/config/config.json | 2 +- integration/mocha.opts | 2 +- integration/ocean/ConsumeAsset.test.ts | 5 +++-- integration/ocean/ConsumeAssetBrizo.test.ts | 5 +++-- ...isterEscrowAccessSecretStoreTemplate.test.ts | 17 ++++++++--------- integration/ocean/Signature.test.ts | 10 +++++++--- library.json | 2 +- package.json | 8 +++----- scripts/unlock-spree-accounts.sh | 3 ++- 9 files changed, 29 insertions(+), 25 deletions(-) diff --git a/integration/config/config.json b/integration/config/config.json index ffc9b64..7476a6e 100644 --- a/integration/config/config.json +++ b/integration/config/config.json @@ -7,5 +7,5 @@ "threshold": 0, "password": "secret", "address": "0x068Ed00cF0441e4829D9784fCBe7b9e26D4BD8d0", - "verbose": 0 + "verbose": false } diff --git a/integration/mocha.opts b/integration/mocha.opts index ea41a5e..f4674be 100644 --- a/integration/mocha.opts +++ b/integration/mocha.opts @@ -3,4 +3,4 @@ --full-trace --exit --timeout 300000 -integration/ocean/RegisterEscrowAccessSecretStoreTemplate.test.ts integration/**/*.test.ts +integration/**/*.test.ts diff --git a/integration/ocean/ConsumeAsset.test.ts b/integration/ocean/ConsumeAsset.test.ts index 38807e8..5a6a289 100644 --- a/integration/ocean/ConsumeAsset.test.ts +++ b/integration/ocean/ConsumeAsset.test.ts @@ -26,9 +26,10 @@ describe("Consume Asset", () => { }) // Accounts - publisher = new Account("0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e") + const instanceConfig = (ocean).instanceConfig + publisher = new Account("0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e", instanceConfig) publisher.setPassword("node0") - consumer = new Account("0x068Ed00cF0441e4829D9784fCBe7b9e26D4BD8d0") + consumer = new Account("0x068Ed00cF0441e4829D9784fCBe7b9e26D4BD8d0", instanceConfig) consumer.setPassword("secret") }) diff --git a/integration/ocean/ConsumeAssetBrizo.test.ts b/integration/ocean/ConsumeAssetBrizo.test.ts index 887016e..f663864 100644 --- a/integration/ocean/ConsumeAssetBrizo.test.ts +++ b/integration/ocean/ConsumeAssetBrizo.test.ts @@ -26,9 +26,10 @@ describe("Consume Asset (Brizo)", () => { }) // Accounts - publisher = new Account("0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e") + const instanceConfig = (ocean).instanceConfig + publisher = new Account("0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e", instanceConfig) publisher.setPassword("node0") - consumer = new Account("0x068Ed00cF0441e4829D9784fCBe7b9e26D4BD8d0") + consumer = new Account("0x068Ed00cF0441e4829D9784fCBe7b9e26D4BD8d0", instanceConfig) consumer.setPassword("secret") }) diff --git a/integration/ocean/RegisterEscrowAccessSecretStoreTemplate.test.ts b/integration/ocean/RegisterEscrowAccessSecretStoreTemplate.test.ts index 812eacb..fd5f452 100644 --- a/integration/ocean/RegisterEscrowAccessSecretStoreTemplate.test.ts +++ b/integration/ocean/RegisterEscrowAccessSecretStoreTemplate.test.ts @@ -2,10 +2,9 @@ import { assert } from "chai" import { config } from "../config" -import { Ocean, templates, conditions, utils, Keeper, Account } from "../../src" // @oceanprotocol/squid +import { Ocean, templates, conditions, utils, Account, Keeper } from "../../src" // @oceanprotocol/squid const { LockRewardCondition, EscrowReward, AccessSecretStoreCondition } = conditions -const { EscrowAccessSecretStoreTemplate } = templates describe("Register Escrow Access Secret Store Template", () => { let ocean: Ocean @@ -27,9 +26,9 @@ describe("Register Escrow Access Secret Store Template", () => { before(async () => { ocean = await Ocean.getInstance(config) - keeper = await Keeper.getInstance() + keeper = ocean.keeper - template = await EscrowAccessSecretStoreTemplate.getInstance() + template = keeper.templates.escrowAccessSecretStoreTemplate // Accounts templateManagerOwner = (await ocean.accounts.list())[0] @@ -37,22 +36,22 @@ describe("Register Escrow Access Secret Store Template", () => { consumer = (await ocean.accounts.list())[2] // Conditions - accessSecretStoreCondition = await AccessSecretStoreCondition.getInstance() - lockRewardCondition = await LockRewardCondition.getInstance() - escrowReward = await EscrowReward.getInstance() + accessSecretStoreCondition = keeper.conditions.accessSecretStoreCondition + lockRewardCondition = keeper.conditions.lockRewardCondition + escrowReward = keeper.conditions.escrowReward }) describe("Propose and approve template", () => { it("should propose the template", async () => { await keeper.templateStoreManager.proposeTemplate(template.getAddress(), consumer.getId(), true) // TODO: Use a event to detect template mined - await new Promise((_) => setTimeout(_, 6 * 1000)) + await new Promise((_) => setTimeout(_, 2 * 1000)) }) it("should approve the template", async () => { await keeper.templateStoreManager.approveTemplate(template.getAddress(), templateManagerOwner.getId(), true) // TODO: Use a event to detect template mined - await new Promise((_) => setTimeout(_, 6 * 1000)) + await new Promise((_) => setTimeout(_, 2 * 1000)) }) }) diff --git a/integration/ocean/Signature.test.ts b/integration/ocean/Signature.test.ts index 6f787e3..f9afbaf 100644 --- a/integration/ocean/Signature.test.ts +++ b/integration/ocean/Signature.test.ts @@ -3,7 +3,7 @@ import * as Web3 from "web3" import { config } from "../config" -import { Ocean, Account, DDO, Keeper } from "../../src" // @oceanprotocol/squid +import { Ocean, Account, DDO } from "../../src" // @oceanprotocol/squid import ServiceAgreement from "../../src/ocean/ServiceAgreements/ServiceAgreement" @@ -11,14 +11,17 @@ import ServiceAgreement from "../../src/ocean/ServiceAgreements/ServiceAgreement // depends on the first account on spree (only accessible from integration test) describe("Signature", () => { + let ocean: Ocean + let web3: Web3 let consumer: Account before(async () => { - await Ocean.getInstance({ + ocean = await Ocean.getInstance({ ...config, web3Provider: new (Web3 as any).providers .HttpProvider("http://localhost:8545", 0, "0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e", "node0"), }) + web3 = (ocean as any).web3 // Accounts consumer = new Account("0x00bd138abd70e2f00903268f3db08f2d25677c9e") @@ -45,7 +48,7 @@ describe("Signature", () => { }) it("should generate the correct signature", async () => { - const templates = (await Keeper.getInstance()).templates + const templates = ocean.keeper.templates const did = `did:op:${"c".repeat(64)}` const templateId = `0x${"f".repeat(40)}` @@ -80,6 +83,7 @@ describe("Signature", () => { .getAgreementIdsFromDDO(agreementId, ddo, consumer.getId(), consumer.getId()) const signature = await ServiceAgreement.signServiceAgreement( + web3, ddo, serviceDefinitionId, agreementId, diff --git a/library.json b/library.json index 48a58bf..4a64e38 100644 --- a/library.json +++ b/library.json @@ -7,7 +7,7 @@ "dependencies": [ { "name": "keeper-contracts", - "version": "~0.8.5" + "version": "~0.8.6" }, { "name": "brizo", diff --git a/package.json b/package.json index 6939295..99061f4 100644 --- a/package.json +++ b/package.json @@ -9,10 +9,9 @@ "test": "mocha", "test:watch": "mocha -w --watch-extensions js,ts,json", "test:cover": "nyc --report-dir coverage/unit mocha", - "@@integration@@": "Using mocha-parallel-tests to ensure independent execution", - "integration": "mocha-parallel-tests --max-parallel 1 --opts integration/mocha.opts", + "integration": "mocha --opts integration/mocha.opts", "integration:watch": "mocha -w --watch-extensions js,ts,json --opts integration/mocha.opts", - "integration:cover": "nyc --report-dir coverage/integration mocha-parallel-tests --max-parallel 1 --opts integration/mocha.opts", + "integration:cover": "nyc --report-dir coverage/integration mocha --opts integration/mocha.opts", "examples": "./src/examples/fire_lazers.sh", "clean": "rm -rf ./dist/ ./doc/ ./coverage ./.nyc_output", "lint": "tslint -c tslint.json 'src/**/*.ts' 'test/**/*.ts' 'integration/**/*.ts'", @@ -23,7 +22,7 @@ "build:watch": "tsc -w", "doc": "typedoc --mode modules --exclude \"**/examples/**\" --out ./doc/ ./src/", "merge-coverages": "npx lcov-result-merger \"coverage/*/lcov.info\" coverage/lcov.info", - "report-coverage": "cat ./coverage/lcov.info | codacy-coverage --token 71ef0d15f6f04ac29b31d704b28f866a", + "report-coverage": "cat ./coverage/unit/lcov.info | codacy-coverage --token 71ef0d15f6f04ac29b31d704b28f866a", "run": "ts-node", "release": "./node_modules/release-it/bin/release-it.js --src.tagName='v%s' --github.release --npm.publish --non-interactive", "release-minor": "./node_modules/release-it/bin/release-it.js minor --src.tagName='v%s' --github.release --npm.publish --non-interactive", @@ -82,7 +81,6 @@ "cross-env": "^5.2.0", "lcov-result-merger": "^3.1.0", "mocha": "^5.2.0", - "mocha-parallel-tests": "^2.0.6-alpha.3", "nyc": "^13.1.0", "source-map-support": "^0.5.9", "truffle-hdwallet-provider": "^1.0.4", diff --git a/scripts/unlock-spree-accounts.sh b/scripts/unlock-spree-accounts.sh index 3b1bda6..cd52e33 100755 --- a/scripts/unlock-spree-accounts.sh +++ b/scripts/unlock-spree-accounts.sh @@ -1,9 +1,10 @@ count=0 echo "Starting..." -while sleep 0.2; +while sleep 0.1; do curl --data '{"method":"personal_unlockAccount","params":["0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e","node0",null],"id":1,"jsonrpc":"2.0"}' -H "Content-Type: application/json" -X POST localhost:8545 &> /dev/null; curl --data '{"method":"personal_unlockAccount","params":["0x068Ed00cF0441e4829D9784fCBe7b9e26D4BD8d0","secret",null],"id":1,"jsonrpc":"2.0"}' -H "Content-Type: application/json" -X POST localhost:8545 &> /dev/null; + curl --data '{"method":"personal_unlockAccount","params":["0xA99D43d86A0758d5632313b8fA3972B6088A21BB","secret",null],"id":1,"jsonrpc":"2.0"}' -H "Content-Type: application/json" -X POST localhost:8545 &> /dev/null; count=$((count+1)); echo -en "\e[1A"; echo -e "\e[0K\rRequest ${count}";