Skip to content

Commit

Permalink
Coburn/fix integration test (#32)
Browse files Browse the repository at this point in the history
* get integration test working

* fix test

* clean up console.logs, change repository on npm package
  • Loading branch information
coburncoburn authored Dec 13, 2019
1 parent 8ef5d1b commit a274a2b
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 69 deletions.
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 11 additions & 2 deletions poster/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions poster/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 4 additions & 16 deletions poster/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
6 changes: 3 additions & 3 deletions poster/src/poster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', '');
}

Expand Down
2 changes: 1 addition & 1 deletion poster/tests/poster_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
37 changes: 22 additions & 15 deletions poster/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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==
Expand Down Expand Up @@ -8544,20 +8551,7 @@ [email protected]:
underscore "1.9.1"
utf8 "3.0.0"

[email protected]:
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"

[email protected]:
web3@*, [email protected]:
version "1.2.4"
resolved "https://registry.yarnpkg.com/web3/-/web3-1.2.4.tgz#6e7ab799eefc9b4648c2dab63003f704a1d5e7d9"
integrity sha512-xPXGe+w0x0t88Wj+s/dmAdASr3O9wmA9mpZRtixGZxmBexAF0MjfqYM+MS4tVl5s11hMTN3AZb8cDD4VLfC57A==
Expand All @@ -8571,6 +8565,19 @@ [email protected]:
web3-shh "1.2.4"
web3-utils "1.2.4"

[email protected]:
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"
Expand Down
6 changes: 4 additions & 2 deletions saddle.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
4 changes: 2 additions & 2 deletions sdk/javascript/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions sdk/javascript/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
8 changes: 0 additions & 8 deletions tests/DelFiPriceTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);


Expand All @@ -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);


Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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);
});
24 changes: 12 additions & 12 deletions tests/IntegrationTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
Expand Down

0 comments on commit a274a2b

Please sign in to comment.