From a274a2bb2e0a8a5620c11365024c226dbb7b5b8d Mon Sep 17 00:00:00 2001 From: Coburn Berry <32463466+coburncoburn@users.noreply.github.com> Date: Fri, 13 Dec 2019 13:23:41 -0800 Subject: [PATCH] Coburn/fix integration test (#32) * get integration test working * fix test * clean up console.logs, change repository on npm package --- docker-compose.yml | 8 ++++---- package.json | 2 +- poster/Dockerfile | 13 +++++++++++-- poster/package.json | 1 + poster/src/index.ts | 20 ++++---------------- poster/src/poster.ts | 6 +++--- poster/tests/poster_test.ts | 2 +- poster/yarn.lock | 37 ++++++++++++++++++++++--------------- saddle.config.js | 6 ++++-- sdk/javascript/Dockerfile | 4 ++-- sdk/javascript/package.json | 4 ++-- tests/DelFiPriceTest.js | 8 -------- tests/IntegrationTest.js | 24 ++++++++++++------------ yarn.lock | 2 +- 14 files changed, 68 insertions(+), 69 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 15344531..2844a84c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: '3' services: ganache: - image: trufflesuite/ganache-cli + image: trufflesuite/ganache-cli:v6.6.0 command: ganache -d ports: - "9999:8545" @@ -38,10 +38,10 @@ services: command: npm run start -- --poster_key 0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d --sources http://reporter-1:3000/prices.json,http://reporter-2:3000/prices.json - --view_address 0xCfEB869F69431e42cdB54A4F4f105C19C080A601 + --view_address 0x5b1869d9a4c187f2eaa108f3062412ecf0526b24 --web3_provider http://ganache:8545 depends_on: - - ganache + - deployer - reporter-1 - reporter-2 - restart: always + restart: "always" diff --git a/package.json b/package.json index 763df477..61c555ab 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ }, "devDependencies": { "docker-compose": "^0.23.1", - "ganache-core": "^2.8.0", + "ganache-core": "^2.5.6", "jest": "^24.9.0", "jest-cli": "^24.9.0", "jest-junit": "^10.0.0" diff --git a/poster/Dockerfile b/poster/Dockerfile index 1bcce3d8..2d8ebbcd 100644 --- a/poster/Dockerfile +++ b/poster/Dockerfile @@ -1,10 +1,19 @@ FROM node:current-alpine +RUN apk update && apk add --no-cache --virtual .gyp \ + python \ + make \ + g++ \ + yarn \ + nodejs \ + git + WORKDIR /open-oracle-poster +RUN yarn global add node-gyp npx ADD package.json /open-oracle-poster/package.json -RUN npm install +RUN yarn install ADD . /open-oracle-poster RUN npx tsc -CMD npm run start +CMD yarn start diff --git a/poster/package.json b/poster/package.json index 96807088..abb30c93 100644 --- a/poster/package.json +++ b/poster/package.json @@ -22,6 +22,7 @@ "typescript": "^3.7.3" }, "dependencies": { + "@types/web3": "^1.2.2", "node-fetch": "^2.6.0", "web3": "1.2.4", "yargs": "^15.0.2" diff --git a/poster/src/index.ts b/poster/src/index.ts index fb354dfc..d6a121f1 100644 --- a/poster/src/index.ts +++ b/poster/src/index.ts @@ -22,31 +22,19 @@ async function run() { const web3 = await new Web3(argv.web3_provider); web3.eth.transactionPollingTimeout = argv.timeout; - web3.eth.transactionConfirmationBlocks = 10; if (argv.web3_provider.match(/.*:8545$/)) { // confirm immediately in dev web3.eth.transactionConfirmationBlocks = 1 - - // monkey patch web3 since ganache does not implement eth_chainId - // https://github.com/trufflesuite/ganache-core/issues/339 - // https://github.com/tcichowicz/ganache-core/commit/15d740cc5bdca86c87c3c9fd79bbce5f785b105e - if (web3.eth.currentProvider && typeof(web3.eth.currentProvider) !== "string" && !!web3.eth.currentProvider.send) { - const originalSend = web3.eth.currentProvider.send; - web3.eth.currentProvider!.send = async function (method, parameters) { - if (method.method === "eth_chainId") { - return "0x" + Number(1337).toString(16) - } else { - return originalSend.call(web3.eth.currentProvider, method, parameters); - } - } - } + } else { + web3.eth.transactionConfirmationBlocks = 10; } try { await main(argv.sources, argv.poster_key, argv.view_address, argv.view_function, argv.gas_limit, web3); + console.log("main completed") } catch (e) { console.error(`Poster failed to run`, e); } } -run() +run().then(console.log); diff --git a/poster/src/poster.ts b/poster/src/poster.ts index 3b5ebc0c..2827cd99 100644 --- a/poster/src/poster.ts +++ b/poster/src/poster.ts @@ -59,11 +59,11 @@ function buildTrxData(payloads : DelFiReporterPayload[], functionSig : string) : let signatures = payloads.reduce((a: string[], x) => a.concat(x.signatures), []); let priceKeys = payloads.map(x => Object.keys(x.prices)); let symbols = new Set(priceKeys.reduce((acc, val) => acc.concat(val))); + let upperCaseDeDuped = [...symbols].map((x) => x.toUpperCase()) // see https://github.com/ethereum/web3.js/blob/2.x/packages/web3-eth-abi/src/AbiCoder.js#L112 - return AbiCoder.encodeFunctionSignature(functionSig) + - AbiCoder - .encodeParameters(types, [messages, signatures, [...symbols]]) + return AbiCoder.encodeFunctionSignature(functionSig) + AbiCoder + .encodeParameters(types, [messages, signatures, [...upperCaseDeDuped]]) .replace('0x', ''); } diff --git a/poster/tests/poster_test.ts b/poster/tests/poster_test.ts index 053b9ea0..42c36942 100644 --- a/poster/tests/poster_test.ts +++ b/poster/tests/poster_test.ts @@ -118,7 +118,7 @@ describe('building a function call', () => { }; // @ts-ignore-start - let officialWeb3Encoding = new Web3().eth.abi.encodeFunctionCall(assumedAbi, [messages, signatures, ['eth', 'zrx']]); + let officialWeb3Encoding = new Web3().eth.abi.encodeFunctionCall(assumedAbi, [messages, signatures, ['ETH', 'ZRX']]); // @ts-ignore-end expect(data).toEqual(officialWeb3Encoding); diff --git a/poster/yarn.lock b/poster/yarn.lock index 448604b5..dd81f726 100644 --- a/poster/yarn.lock +++ b/poster/yarn.lock @@ -392,6 +392,13 @@ resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-1.0.1.tgz#0a851d3bd96498fa25c33ab7278ed3bd65f06c3e" integrity sha512-l42BggppR6zLmpfU6fq9HEa2oGPEI8yrSPL3GITjfRInppYFahObbIQOQK3UGxEnyQpltZLaPe75046NOZQikw== +"@types/web3@^1.2.2": + version "1.2.2" + resolved "https://registry.yarnpkg.com/@types/web3/-/web3-1.2.2.tgz#d95a101547ce625c5ebd0470baa5dbd4b9f3c015" + integrity sha512-eFiYJKggNrOl0nsD+9cMh2MLk4zVBfXfGnVeRFbpiZzBE20eet4KLA3fXcjSuHaBn0RnQzwLAGdgzgzdet4C0A== + dependencies: + web3 "*" + "@types/yargs-parser@*": version "13.1.0" resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-13.1.0.tgz#c563aa192f39350a1d18da36c5a8da382bbd8228" @@ -3488,7 +3495,7 @@ functional-red-black-tree@^1.0.1, functional-red-black-tree@~1.0.1: resolved "https://registry.yarnpkg.com/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz#1b0ab3bd553b2a0d6399d29c0e3ea0b252078327" integrity sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc= -ganache-core@^2.8.0: +ganache-core@^2.6.0: version "2.8.0" resolved "https://registry.yarnpkg.com/ganache-core/-/ganache-core-2.8.0.tgz#eeadc7f7fc3a0c20d99f8f62021fb80b5a05490c" integrity sha512-hfXqZGJx700jJqwDHNXrU2BnPYuETn1ekm36oRHuXY3oOuJLFs5C+cFdUFaBlgUxcau1dOgZUUwKqTAy0gTA9Q== @@ -8544,20 +8551,7 @@ web3-utils@1.2.4: underscore "1.9.1" utf8 "3.0.0" -web3@1.2.1: - version "1.2.1" - resolved "https://registry.yarnpkg.com/web3/-/web3-1.2.1.tgz#5d8158bcca47838ab8c2b784a2dee4c3ceb4179b" - integrity sha512-nNMzeCK0agb5i/oTWNdQ1aGtwYfXzHottFP2Dz0oGIzavPMGSKyVlr8ibVb1yK5sJBjrWVnTdGaOC2zKDFuFRw== - dependencies: - web3-bzz "1.2.1" - web3-core "1.2.1" - web3-eth "1.2.1" - web3-eth-personal "1.2.1" - web3-net "1.2.1" - web3-shh "1.2.1" - web3-utils "1.2.1" - -web3@1.2.4: +web3@*, web3@1.2.4: version "1.2.4" resolved "https://registry.yarnpkg.com/web3/-/web3-1.2.4.tgz#6e7ab799eefc9b4648c2dab63003f704a1d5e7d9" integrity sha512-xPXGe+w0x0t88Wj+s/dmAdASr3O9wmA9mpZRtixGZxmBexAF0MjfqYM+MS4tVl5s11hMTN3AZb8cDD4VLfC57A== @@ -8571,6 +8565,19 @@ web3@1.2.4: web3-shh "1.2.4" web3-utils "1.2.4" +web3@1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/web3/-/web3-1.2.1.tgz#5d8158bcca47838ab8c2b784a2dee4c3ceb4179b" + integrity sha512-nNMzeCK0agb5i/oTWNdQ1aGtwYfXzHottFP2Dz0oGIzavPMGSKyVlr8ibVb1yK5sJBjrWVnTdGaOC2zKDFuFRw== + dependencies: + web3-bzz "1.2.1" + web3-core "1.2.1" + web3-eth "1.2.1" + web3-eth-personal "1.2.1" + web3-net "1.2.1" + web3-shh "1.2.1" + web3-utils "1.2.1" + webidl-conversions@^4.0.2: version "4.0.2" resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-4.0.2.tgz#a855980b1f0b6b359ba1d5d9fb39ae941faa63ad" diff --git a/saddle.config.js b/saddle.config.js index d7457cb5..fa6269f5 100644 --- a/saddle.config.js +++ b/saddle.config.js @@ -33,12 +33,14 @@ module.exports = { test: { providers: [ {env: "PROVIDER"}, - {ganache: {}}, // In test mode, connect to a new ganache provider. Any options will be passed to ganache + {ganache: { + gasLimit: 10000000 + }}, // In test mode, connect to a new ganache provider. Any options will be passed to ganache ], web3: { gas: [ {env: "GAS"}, - {default: "4600000"} + {default: "8000000"} ], gas_price: [ {env: "GAS_PRICE"}, diff --git a/sdk/javascript/Dockerfile b/sdk/javascript/Dockerfile index 6a5542db..c68788c3 100644 --- a/sdk/javascript/Dockerfile +++ b/sdk/javascript/Dockerfile @@ -2,9 +2,9 @@ FROM node:current-alpine WORKDIR /open-oracle-reporter ADD package.json /open-oracle-reporter/package.json -RUN npm install +RUN yarn install ADD . /open-oracle-reporter RUN npx tsc -CMD npm run start +CMD yarn start diff --git a/sdk/javascript/package.json b/sdk/javascript/package.json index c63a2c86..9e5d68f6 100644 --- a/sdk/javascript/package.json +++ b/sdk/javascript/package.json @@ -1,10 +1,10 @@ { "name": "open-oracle-reporter", - "version": "1.0.1", + "version": "1.0.2", "description": "The Open Oracle Reporter", "main": ".tsbuilt/index.js", "types": ".tsbuilt/index.js", - "repository": "https://github.com/compound-finance/delfi", + "repository": "https://github.com/compound-finance/open-oracle", "author": "Compound Labs, Inc.", "license": "MIT", "scripts": { diff --git a/tests/DelFiPriceTest.js b/tests/DelFiPriceTest.js index fd708372..642cbe1f 100644 --- a/tests/DelFiPriceTest.js +++ b/tests/DelFiPriceTest.js @@ -65,7 +65,6 @@ describe('DelFiPrice', () => { const post0 = await postPrices(now, [], []) expect(post0.gasUsed).toBeLessThan(25000); - console.log('0', post0.gasUsed); expect(await getPrice('ETH')).numEquals(0); @@ -77,7 +76,6 @@ describe('DelFiPrice', () => { expect(post1.gasUsed).toBeLessThan(106000); expect(post1.events.Price.returnValues.symbol).toBe('ETH'); expect(post1.events.Price.returnValues.price).numEquals(0); - console.log('1', post1.gasUsed); expect(await getPrice('ETH')).numEquals(0); @@ -94,7 +92,6 @@ describe('DelFiPrice', () => { ] ], ['BTC', 'ETH']); expect(post2.gasUsed).toBeLessThan(265000); - console.log('2', post2.gasUsed); expect(await getPrice('BTC')).numEquals(0); // not added to list of symbols to update expect(await getPrice('ETH')).numEquals(0); @@ -120,7 +117,6 @@ describe('DelFiPrice', () => { expect(post3a.events.Price[0].returnValues.price).numEquals(8000e6); expect(post3a.events.Price[1].returnValues.symbol).toBe('ETH'); expect(post3a.events.Price[1].returnValues.price).numEquals(255e6); - console.log('3a', post3a.gasUsed); expect(await getPrice('BTC')).numEquals(8000e6); expect(await getPrice('ETH')).numEquals(255e6); @@ -142,7 +138,6 @@ describe('DelFiPrice', () => { ] ], ['BTC', 'ETH']); expect(post3b.gasUsed).toBeLessThan(281000); - console.log('3b', post3b.gasUsed); expect(await getPrice('BTC')).numEquals(8000e6); expect(await getPrice('ETH')).numEquals(255e6); @@ -316,8 +311,5 @@ describe('DelFiPrice', () => { const postC = await postPrices(now + 1, big, big[0].map(([k]) => k)); expect(postC.gasUsed).toBeLessThan(2.8e6); - console.log('A', postA.gasUsed); - console.log('B', postB.gasUsed); - console.log('C', postC.gasUsed); }, 120000); }); diff --git a/tests/IntegrationTest.js b/tests/IntegrationTest.js index 87f6117d..ed4fc1ab 100644 --- a/tests/IntegrationTest.js +++ b/tests/IntegrationTest.js @@ -7,19 +7,19 @@ const root = path.join(__dirname, '..'); describe('Integration', () => { it('deploys the contracts, starts reporters and posts the right prices', async () => { - await compose.upAll({cwd: root, log: true}); - try { - await new Promise(ok => setTimeout(ok, 3000)); + try { + await compose.upOne(["poster"], {cwd: root, log: true}); + await new Promise(ok => setTimeout(ok, 10000)); - const web3 = new Web3('http://localhost:9999'); - const accounts = await web3.eth.getAccounts(); - const delfi = await contract.getContractAt(web3, 'DelFiPrice', false, '0xCfEB869F69431e42cdB54A4F4f105C19C080A601'); + const web3 = new Web3('http://localhost:9999'); + const accounts = await web3.eth.getAccounts(); + const delfi = await contract.getContractAt(web3, 'DelFiPrice', false, '0x5b1869D9A4C187F2EAa108f3062412ecf0526b24'); - expect(await delfi.methods.prices('BTC').call({from: accounts[0]})).numEquals(0); - // expect(await delfi.methods.prices('ETH').call({from: accounts[0]})).numEquals('260000000'); - // expect(await delfi.methods.prices('ZRX').call({from: accounts[0]})).numEquals('580000'); - } finally { - await compose.down({cwd: root}); - } + expect(await delfi.methods.prices('BTC').call({from: accounts[0]})).numEquals(0); + expect(await delfi.methods.prices('ETH').call({from: accounts[0]})).numEquals('260000000'); + expect(await delfi.methods.prices('ZRX').call({from: accounts[0]})).numEquals('580000'); + } finally { + await compose.down({cwd: root}); + } }, 60000); }); diff --git a/yarn.lock b/yarn.lock index 22c70c40..f735df2b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4183,7 +4183,7 @@ functional-red-black-tree@^1.0.1, functional-red-black-tree@~1.0.1: resolved "https://registry.yarnpkg.com/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz#1b0ab3bd553b2a0d6399d29c0e3ea0b252078327" integrity sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc= -ganache-core@^2.6.0, ganache-core@^2.8.0: +ganache-core@^2.5.6, ganache-core@^2.6.0: version "2.8.0" resolved "https://registry.yarnpkg.com/ganache-core/-/ganache-core-2.8.0.tgz#eeadc7f7fc3a0c20d99f8f62021fb80b5a05490c" integrity sha512-hfXqZGJx700jJqwDHNXrU2BnPYuETn1ekm36oRHuXY3oOuJLFs5C+cFdUFaBlgUxcau1dOgZUUwKqTAy0gTA9Q==