Skip to content

Commit

Permalink
Switch to... docker provider!!
Browse files Browse the repository at this point in the history
  • Loading branch information
hayesgm committed Jan 23, 2020
1 parent 2b016d2 commit e1cdc9e
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 3 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.build
.circleci
.dockerbuild
.dockerbuild_cp
.github
node_modules
sdk/javascript/node_modules
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.dockerbuild
.dockerbuild_cp
*node_modules*
*.tsbuilt*
*.DS_Store*
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"yargs": "^15.0.2"
},
"devDependencies": {
"docker-cli-js": "^2.6.0",
"docker-compose": "^0.23.1",
"ganache-core": "^2.5.6",
"jest": "^24.9.0",
Expand Down
37 changes: 37 additions & 0 deletions tests/DockerProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
let { errors } = require('web3-core-helpers');

/**
* DockerProvider should be used to send rpc calls via a Docker node
*/
class DockerProvider {
constructor(endpoint, docker, service) {
this.endpoint = endpoint;
this.docker = docker;
this.service = service;
}

async send(payload, callback) {
const opts = JSON.stringify({
method: 'post',
body: payload,
json: true,
url: this.endpoint
});
const cmd = `node -e 'require("request")(${opts}, (err, res, body) => { if (err) { throw err; }; console.log(JSON.stringify(body)) } )'`;
try {
const data = await this.docker.command(`exec ${this.service} ${cmd}`);

try {
return callback(null, JSON.parse(data.raw));
} catch(e) {
return callback(errors.InvalidResponse(data.raw));
}
} catch (e) {
callback(e);
}
}

disconnect() {}
};

module.exports = DockerProvider;
32 changes: 29 additions & 3 deletions tests/IntegrationTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,44 @@ const path = require('path');
const Web3 = require('web3');
const compose = require('docker-compose');
const contract = require('eth-saddle/dist/contract');
const { Docker, Options } = require('docker-cli-js');
const DockerProvider = require('./DockerProvider');

const root = path.join(__dirname, '..');

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}

async function waitForLogs(serviceLogPairs) {
let [service, log] = Object.entries(serviceLogPairs)[0];
const serviceLogs = await compose.logs([service]);

if (!serviceLogs.out.includes(log)) {
console.log(`Waiting for logs ${JSON.stringify(serviceLogPairs)}`);
console.log(serviceLogs.out);
await sleep(5000);
await waitForLogs(serviceLogPairs);
}
}

describe('Integration', () => {
it('deploys the contracts, starts reporters and posts the right prices', async () => {
try {
await compose.upOne(["poster"], {cwd: root, log: true});
await new Promise(ok => setTimeout(ok, 10000));
await waitForLogs({deployer: "Deployed DelFiPrice"});

// TODO: Better way to get these?
repo = path.basename(process.cwd());
const deployer = `${repo}_deployer_1`;
const reporter = `${repo}_reporter-1_1`;

const docker = new Docker(new Options());
await docker.command(`cp ${deployer}:/build .dockerbuild_cp`);

const web3 = new Web3('http://localhost:9999');
const web3 = new Web3(new DockerProvider('http://ganache:8545', docker, reporter));
const accounts = await web3.eth.getAccounts();
const delfi = await contract.getContractAt(web3, 'DelFiPrice', '.dockerbuild', false, '0x5b1869D9A4C187F2EAa108f3062412ecf0526b24');
const delfi = await contract.getContractAt(web3, 'DelFiPrice', '.dockerbuild_cp', 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');
Expand Down
52 changes: 52 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,14 @@
dependencies:
bignumber.js "*"

"@types/blue-tape@^0.1.30":
version "0.1.33"
resolved "https://registry.yarnpkg.com/@types/blue-tape/-/blue-tape-0.1.33.tgz#61796d4f0455a00a61be59e52288cb3428209804"
integrity sha512-l5cQcLM3aPh55bBQ4geWQ8hZ4Ew+s4RvyhMaBpgW3aJ2HUfRgwd8ENKrk/utC4Hz1dJAiehyIa4vN6emxBMaog==
dependencies:
"@types/node" "*"
"@types/tape" "*"

"@types/bn.js@^4.11.0", "@types/bn.js@^4.11.3", "@types/bn.js@^4.11.4":
version "4.11.5"
resolved "https://registry.yarnpkg.com/@types/bn.js/-/bn.js-4.11.5.tgz#40e36197433f78f807524ec623afcf0169ac81dc"
Expand Down Expand Up @@ -866,6 +874,11 @@
dependencies:
jest-diff "^24.3.0"

"@types/[email protected]":
version "4.14.119"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.119.tgz#be847e5f4bc3e35e46d041c394ead8b603ad8b39"
integrity sha512-Z3TNyBL8Vd/M9D9Ms2S3LmFq2sSMzahodD6rCS9V2N44HUMINb75jNkSuwAx7eo2ufqTdfOdtGQpNbieUjPQmw==

"@types/minimatch@^3.0.3":
version "3.0.3"
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"
Expand Down Expand Up @@ -904,6 +917,13 @@
resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-1.0.1.tgz#0a851d3bd96498fa25c33ab7278ed3bd65f06c3e"
integrity sha512-l42BggppR6zLmpfU6fq9HEa2oGPEI8yrSPL3GITjfRInppYFahObbIQOQK3UGxEnyQpltZLaPe75046NOZQikw==

"@types/tape@*":
version "4.2.33"
resolved "https://registry.yarnpkg.com/@types/tape/-/tape-4.2.33.tgz#3583953eaff5f8a77e65ad6ff197741457aaaab9"
integrity sha512-ltfyuY5BIkYlGuQfwqzTDT8f0q8Z5DGppvUnWGs39oqDmMd6/UWhNpX3ZMh/VYvfxs3rFGHMrLC/eGRdLiDGuw==
dependencies:
"@types/node" "*"

"@types/web3-provider-engine@^14.0.0":
version "14.0.0"
resolved "https://registry.yarnpkg.com/@types/web3-provider-engine/-/web3-provider-engine-14.0.0.tgz#43adc3b39dc9812b82aef8cd2d66577665ad59b0"
Expand Down Expand Up @@ -2496,6 +2516,15 @@ class-utils@^0.3.5:
isobject "^3.0.0"
static-extend "^0.1.1"

[email protected]:
version "1.0.13"
resolved "https://registry.yarnpkg.com/cli-table-2-json/-/cli-table-2-json-1.0.13.tgz#33d5be36851477854b004356197a6409c7370aea"
integrity sha512-CpUj9dubfuIZSEezwUPycAJqM2dlATyyRUyBkfGeK2KNfrqK3XrdaBohMt0XlkEvsZyDfUEmPWCNvUO+a/7Wsw==
dependencies:
"@types/blue-tape" "^0.1.30"
"@types/lodash" "4.14.119"
lodash "^4.17.15"

cliui@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/cliui/-/cliui-3.2.0.tgz#120601537a916d29940f934da3b48d585a39213d"
Expand Down Expand Up @@ -3128,11 +3157,29 @@ dirty-chai@^2.0.1:
resolved "https://registry.yarnpkg.com/dirty-chai/-/dirty-chai-2.0.1.tgz#6b2162ef17f7943589da840abc96e75bda01aff3"
integrity sha512-ys79pWKvDMowIDEPC6Fig8d5THiC0DJ2gmTeGzVAoEH18J8OzLud0Jh7I9IWg3NSk8x2UocznUuFmfHCXYZx9w==

docker-cli-js@^2.6.0:
version "2.6.0"
resolved "https://registry.yarnpkg.com/docker-cli-js/-/docker-cli-js-2.6.0.tgz#91d6e860333b8ced90bfa373f47fec0569078fe2"
integrity sha512-tep7VU3SGuydGRI2VMXyeDNRBaKmFx80YQZOTFoeyYvLlhE0nmYgqr4sP7D4M8+zGb0d8OqR0VwkhIEpR0bXsw==
dependencies:
cli-table-2-json "1.0.13"
dockermachine-cli-js "3.0.5"
lodash "^4.17.15"
nodeify-ts "1.0.6"

docker-compose@^0.23.1:
version "0.23.1"
resolved "https://registry.yarnpkg.com/docker-compose/-/docker-compose-0.23.1.tgz#d71b1e244b989527585cbd43f6b20dea4881d34c"
integrity sha512-9e4moDWxAoEU/WEVJXUnoxXEWDQCX8tQIfuRntApl1atbvz1qV5uoC6YfgYbqUqcIgSD99iZWye7ePrN+ud8AA==

[email protected]:
version "3.0.5"
resolved "https://registry.yarnpkg.com/dockermachine-cli-js/-/dockermachine-cli-js-3.0.5.tgz#7e7aa37adba885572e6b59ed9050fe347e558227"
integrity sha512-oV9RRKGvWrvsGl8JW9TWKpjBJVGxn/1qMvhqwPJiOPfRES0+lrq/Q8Wzixb6qinuXPVBhlWqhXb/Oxrh6Vuf/g==
dependencies:
cli-table-2-json "1.0.13"
nodeify-ts "1.0.6"

dom-walk@^0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/dom-walk/-/dom-walk-0.1.1.tgz#672226dc74c8f799ad35307df936aba11acd6018"
Expand Down Expand Up @@ -6926,6 +6973,11 @@ node-pre-gyp@^0.12.0:
semver "^5.3.0"
tar "^4"

[email protected]:
version "1.0.6"
resolved "https://registry.yarnpkg.com/nodeify-ts/-/nodeify-ts-1.0.6.tgz#ceef172c4fad1a45a1ae60a31c7e295150b5e221"
integrity sha512-jq+8sqVG1aLqy5maMTceL8NUJ1CvarWztlxvrYh3G0aao9BsVeoVmVedUnrUSBLetP7oLIAJrPrw4+iIo7v3GA==

noop-logger@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/noop-logger/-/noop-logger-0.1.1.tgz#94a2b1633c4f1317553007d8966fd0e841b6a4c2"
Expand Down

0 comments on commit e1cdc9e

Please sign in to comment.