Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ci/ethereum_test to check echo_server/RunLog #276

Merged
merged 5 commits into from
May 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions examples/echo_server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ a job anytime a log event occurs. It can optionally be filtered by an `address`.
Uses a `runlog` initiator to echo Chainlink log events with the matching job id.

1. Complete the [Run Chainlink Development Environment](../README.md#run-chainlink-development-environment) steps.
2. `./create_runlog_job` to create CL job. Keep track of the returned job id.
3. `yarn install`
4. `node echo.js`
5. Add job id to `contracts/RunLog.sol` where it says `MY_JOB_ID`
5. `./node_modules/.bin/truffle migrate --reset` in another window
6. `node send_runlog_transaction.js`
7. Wait for log to show up in echo server
2. `yarn install`
3. `node echo.js`
4. `./node_modules/.bin/truffle migrate` in another window
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why in another window ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

node echo.js locks up the current window.

5. `node send_runlog_transaction.js`
6. Wait for log to show up in echo server
7. Investigate migrations/5_run_log.js for insight


## Further Reading
Expand Down
16 changes: 16 additions & 0 deletions examples/echo_server/chainlink_deployer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const fs = require("fs");
const request = require("request-promise");
const util = require('util');
const url = "http://chainlink:twochains@localhost:6688/v2/specs";

module.exports = {
// Deploys chainlink jobs.
job: async function(filename) {
let readFile = util.promisify(fs.readFile);
return await readFile(filename, 'utf8').then((file) => {
let data = JSON.parse(file);
console.log(`Posting to ${url}:\n`, data);
return request.post(url, {json: data});
});
}
};
6 changes: 4 additions & 2 deletions examples/echo_server/contracts/RunLog.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import "../../../solidity/contracts/Chainlinked.sol";

contract RunLog is Chainlinked {
bytes32 private externalId;
bytes32 private jobId;

constructor(address _link, address _oracle) public {
constructor(address _link, address _oracle, bytes32 _jobId) public {
setLinkToken(_link);
setOracle(_oracle);
jobId = _jobId;
}

function request() public {
ChainlinkLib.Run memory run = newRun("MY_JOB_ID", this, "fulfill(bytes32,bytes32)");
ChainlinkLib.Run memory run = newRun(jobId, this, "fulfill(bytes32,bytes32)");
run.add("msg", "hello_chainlink");
externalId = chainlinkRequest(run, 1 szabo);
}
Expand Down
4 changes: 0 additions & 4 deletions examples/echo_server/create_runlog_job

This file was deleted.

10 changes: 8 additions & 2 deletions examples/echo_server/migrations/5_run_log.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
let chainlinkDeployer = require("../chainlink_deployer.js");
let LinkToken = artifacts.require("../node_modules/smartcontractkit/chainlink/solidity/contracts/LinkToken.sol");
let Oracle = artifacts.require("../node_modules/smartcontractkit/chainlink/solidity/contracts/Oracle.sol");
let RunLog = artifacts.require("./RunLog.sol");

module.exports = function(deployer) {
deployer.deploy(RunLog, LinkToken.address, Oracle.address);
module.exports = function(truffleDeployer) {
truffleDeployer.then(async () => {
await chainlinkDeployer.job("only_jobid_logs_job.json").then(async function(body) {
console.log(`Deploying Consumer Contract with JobID ${body.id}`);
await truffleDeployer.deploy(RunLog, LinkToken.address, Oracle.address, body.id);
}).catch(console.log);
});
};
6 changes: 3 additions & 3 deletions examples/echo_server/migrations/6_transfer_link.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ let LinkToken = artifacts.require("../node_modules/smartcontractkit/chainlink/so
let RunLog = artifacts.require("./RunLog.sol");
let devnetAddress = "0x9CA9d2D5E04012C9Ed24C0e513C9bfAa4A2dD77f";

module.exports = async function(deployer) {
await LinkToken.deployed().then(async function(linkInstance) {
module.exports = function(deployer) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently truffle migrations don't support async at the top export level, but they do inside then(async....:
trufflesuite/truffle#501

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe still return result of LinkToken.deployed? Not sure about Truffle's internals, but in tests it waits for returned promises to finish.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that to no avail and felt this was the most confident solution.

LinkToken.deployed().then(async function(linkInstance) {
await RunLog.deployed().then(async function(runLogInstance) {
await linkInstance.transfer(runLogInstance.address, web3.toWei(1000));
await linkInstance.transfer(devnetAddress, web3.toWei(1000));
});
}).catch(console.log);
});
};
5 changes: 3 additions & 2 deletions examples/echo_server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
"dependencies": {
"express": "^4.16.2",
"linkToken": "github:smartcontractkit/linktoken",
"openzeppelin-solidity": "^1.6.0",
"request-promise": "^4.2.2",
"solidity-cborutils": "github:smartcontractkit/solidity-cborutils",
"truffle": "^4.1.6",
"truffle-contract": "^3.0.3",
"openzeppelin-solidity": "^1.6.0"
"truffle-contract": "^3.0.3"
}
}
2 changes: 1 addition & 1 deletion examples/echo_server/test/RunLog_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ contract('RunLog', () => {
beforeEach(async () => {
link = await LinkToken.new();
oc = await Oracle.new(link.address);
logger = await RunLog.new(link.address, oc.address);
logger = await RunLog.new(link.address, oc.address, "SOME_JOB_ID");
await link.transfer(logger.address, web3.toWei(1));
});

Expand Down
21 changes: 20 additions & 1 deletion examples/echo_server/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5132,6 +5132,21 @@ replace-ext@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/replace-ext/-/replace-ext-1.0.0.tgz#de63128373fcbf7c3ccfa4de5a480c45a67958eb"

[email protected]:
version "1.1.1"
resolved "https://registry.yarnpkg.com/request-promise-core/-/request-promise-core-1.1.1.tgz#3eee00b2c5aa83239cfb04c5700da36f81cd08b6"
dependencies:
lodash "^4.13.1"

request-promise@^4.2.2:
version "4.2.2"
resolved "https://registry.yarnpkg.com/request-promise/-/request-promise-4.2.2.tgz#d1ea46d654a6ee4f8ee6a4fea1018c22911904b4"
dependencies:
bluebird "^3.5.0"
request-promise-core "1.1.1"
stealthy-require "^1.1.0"
tough-cookie ">=2.3.3"

request@2, request@^2.74.0:
version "2.85.0"
resolved "https://registry.yarnpkg.com/request/-/request-2.85.0.tgz#5a03615a47c61420b3eb99b7dba204f83603e1fa"
Expand Down Expand Up @@ -5676,6 +5691,10 @@ statuses@~1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.3.1.tgz#faf51b9eb74aaef3b3acf4ad5f61abf24cb7b93e"

stealthy-require@^1.1.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/stealthy-require/-/stealthy-require-1.1.1.tgz#35b09875b4ff49f26a777e509b3090a3226bf24b"

stream-browserify@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/stream-browserify/-/stream-browserify-2.0.1.tgz#66266ee5f9bdb9940a4e4514cafb43bb71e5c9db"
Expand Down Expand Up @@ -5940,7 +5959,7 @@ to-regex@^3.0.1, to-regex@^3.0.2:
regex-not "^1.0.2"
safe-regex "^1.1.0"

tough-cookie@~2.3.0, tough-cookie@~2.3.3:
tough-cookie@>=2.3.3, tough-cookie@~2.3.0, tough-cookie@~2.3.3:
version "2.3.4"
resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.3.4.tgz#ec60cee38ac675063ffc97a5c18970578ee83655"
dependencies:
Expand Down
1 change: 1 addition & 0 deletions internal/bin/cldev
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export ROOT=./internal/clroot
export ETH_URL=ws://localhost:18546
export ETH_CHAIN_ID=17
export TX_MIN_CONFIRMATIONS=2
export MINIMUM_CONTRACT_PAYMENT=1000000000000

LDFLAGS="-X github.com/smartcontractkit/chainlink/store.Sha=`git rev-parse HEAD`"

Expand Down
58 changes: 37 additions & 21 deletions internal/ci/ethereum_test
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ trap "kill -- -$$ || true" SIGINT SIGTERM EXIT

PATH=./internal/bin:./node_modules/.bin:$PATH

# Utilities
assert ()
{
echo "$1: expected $2, actual $3."
if [ "$2" -ne "$3" ]; then
exit 1
fi
}

# Run gethnet
time go get -d github.com/ethereum/go-ethereum
time go install github.com/ethereum/go-ethereum/cmd/geth
Expand All @@ -27,45 +36,52 @@ cd examples/echo_server
yarn install
truffle migrate
node echo.js &
sleep 1

########################
## runlog
########################

./send_runlog_transaction.js
sleep 2

# Check echo count
count=`curl -sS localhost:6690/count`
assert "Echo count" 1 $count

# Check CL counts
cd ../../

## Check job counts using jq to parse json: https://stedolan.github.io/jq/
jobs=`cldev -j j | jq length`
assert "Jobs count" 1 $jobs

# Check job runs
jid=`cldev -j j | jq 'first | .id' | tr -d '"'`
runs=`cldev -j s $jid | jq '.runs | length'`
assert "RunLog Runs count" 1 $runs

########################
## ethlog
########################

cd examples/echo_server
ethjob=`./create_ethlog_job`
./send_ethlog_transaction.js
sleep 2

# Check echo count
count=`curl -sS localhost:6690/count`
if [ "$count" -ne "1" ]; then
echo "Echo count is $count, not 1."
exit 1
else
echo "Echo count is correctly $count"
fi
assert "Echo count" 2 $count

# Check CL counts
cd ../../

## Check job counts
jobs=`cldev -j j | jq length`
echo Retrieved $jobs jobs
if [ "$jobs" -ne "1" ]; then
echo "Jobs count is $jobs, not 1."
exit 1
else
echo "Jobs count is correctly $jobs."
fi
assert "Jobs count" 2 $jobs

## Check job runs
jid=`echo $ethjob | jq .id | tr -d '"'`
echo Retrieved job id $jid
runs=`cldev -j s $jid | jq '.runs | length'`
echo Retrieved $runs runs
if [ "$runs" -ne "1" ]; then
echo "Runs count is $runs, not 1."
exit 1
else
echo "Runs count is correctly $runs."
fi
assert "EthLog Runs count" 1 $runs
2 changes: 1 addition & 1 deletion services/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (app *ChainlinkApplication) Start() error {
go func() {
<-sigs
app.Stop()
app.Exiter(1)
app.Exiter(0)
}()

app.attachmentID = app.HeadTracker.Attach(app.EthereumListener)
Expand Down
32 changes: 5 additions & 27 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1736,7 +1736,7 @@ [email protected], debug@^3.1.0:
dependencies:
ms "2.0.0"

debuglog@*, debuglog@^1.0.1:
debuglog@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/debuglog/-/debuglog-1.0.1.tgz#aa24ffb9ac3df9a2351837cfb2d279360cd78492"

Expand Down Expand Up @@ -3042,7 +3042,7 @@ import-local@^1.0.0:
pkg-dir "^2.0.0"
resolve-cwd "^2.0.0"

imurmurhash@*, imurmurhash@^0.1.4:
imurmurhash@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea"

Expand Down Expand Up @@ -3790,36 +3790,18 @@ lodash._basecreate@^3.0.0:
version "3.0.3"
resolved "https://registry.yarnpkg.com/lodash._basecreate/-/lodash._basecreate-3.0.3.tgz#1bc661614daa7fc311b7d03bf16806a0213cf821"

lodash._baseindexof@*:
version "3.1.0"
resolved "https://registry.yarnpkg.com/lodash._baseindexof/-/lodash._baseindexof-3.1.0.tgz#fe52b53a1c6761e42618d654e4a25789ed61822c"

lodash._baseuniq@~4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash._baseuniq/-/lodash._baseuniq-4.6.0.tgz#0ebb44e456814af7905c6212fa2c9b2d51b841e8"
dependencies:
lodash._createset "~4.0.0"
lodash._root "~3.0.0"

lodash._bindcallback@*:
version "3.0.1"
resolved "https://registry.yarnpkg.com/lodash._bindcallback/-/lodash._bindcallback-3.0.1.tgz#e531c27644cf8b57a99e17ed95b35c748789392e"

lodash._cacheindexof@*:
version "3.0.2"
resolved "https://registry.yarnpkg.com/lodash._cacheindexof/-/lodash._cacheindexof-3.0.2.tgz#3dc69ac82498d2ee5e3ce56091bafd2adc7bde92"

lodash._createcache@*:
version "3.1.2"
resolved "https://registry.yarnpkg.com/lodash._createcache/-/lodash._createcache-3.1.2.tgz#56d6a064017625e79ebca6b8018e17440bdcf093"
dependencies:
lodash._getnative "^3.0.0"

lodash._createset@~4.0.0:
version "4.0.3"
resolved "https://registry.yarnpkg.com/lodash._createset/-/lodash._createset-4.0.3.tgz#0f4659fbb09d75194fa9e2b88a6644d363c9fe26"

lodash._getnative@*, lodash._getnative@^3.0.0:
lodash._getnative@^3.0.0:
version "3.9.1"
resolved "https://registry.yarnpkg.com/lodash._getnative/-/lodash._getnative-3.9.1.tgz#570bc7dede46d61cdcde687d65d3eecbaa3aaff5"

Expand Down Expand Up @@ -3863,10 +3845,6 @@ lodash.keys@^3.0.0:
lodash.isarguments "^3.0.0"
lodash.isarray "^3.0.0"

lodash.restparam@*:
version "3.6.1"
resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805"

lodash.union@~4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash.union/-/lodash.union-4.6.0.tgz#48bb5088409f16f1821666641c44dd1aaae3cd88"
Expand Down Expand Up @@ -5351,7 +5329,7 @@ readable-stream@~1.1.10:
isarray "0.0.1"
string_decoder "~0.10.x"

readdir-scoped-modules@*, readdir-scoped-modules@^1.0.0:
readdir-scoped-modules@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/readdir-scoped-modules/-/readdir-scoped-modules-1.0.2.tgz#9fafa37d286be5d92cbaebdee030dc9b5f406747"
dependencies:
Expand Down Expand Up @@ -6664,7 +6642,7 @@ v8-compile-cache@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-1.1.2.tgz#8d32e4f16974654657e676e0e467a348e89b0dc4"

validate-npm-package-license@*, validate-npm-package-license@^3.0.1:
validate-npm-package-license@^3.0.1:
version "3.0.3"
resolved "https://registry.yarnpkg.com/validate-npm-package-license/-/validate-npm-package-license-3.0.3.tgz#81643bcbef1bdfecd4623793dc4648948ba98338"
dependencies:
Expand Down