Skip to content

Commit

Permalink
Jonahkaye/feat/unit testing (#42)
Browse files Browse the repository at this point in the history
* helpers written

* proper indexing must occur into the logs

* data size conversion issue resolved

* all committed

* Cargo.toml

* make test

* checking in our changes from the call

* cleaning up validate.rs some

* simplifying, current bug

* TODOs finished and a lot cleaner

* cleaning at present

* integrating banyan shared

* proof test failing

* basic tests passing single thread

* deal and proof tests passing, next multi window and errors

* PR Ready

* simplifying API and aligning with example format

* README and testing working

* more docs

* rm unused job

* cleanup

* trying to pass codecov

* commenting out tests

* formaatting

* patching security vulnerability

Co-authored-by: Claudia Richoux <c@laudiacay.cool>
  • Loading branch information
jonahkaye and laudiacay authored Oct 20, 2022
1 parent 62572bb commit 85d3e4e
Show file tree
Hide file tree
Showing 41 changed files with 1,014 additions and 20,565 deletions.
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# .env
PRIVATE_KEY =
API_KEY =
ACCOUNT_ADDRESS =
CONTRACT_ADDRESS=
17 changes: 6 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,11 @@ edition = "2021"
rocket = { version = "0.5.0-rc.2", features = ["json"] }
serde = "*"
serde_json = "*"
serde_derive = "*"
ethers = { git = "https://github.com/gakonst/ethers-rs" }
eyre = "0.6.8"
tokio = "1.20.1"
bytes = "1.2.1"
anyhow = {version = "1.0", features = ["std", "backtrace"] }
bao = "0.12.0"
blake3 = "1.3.1"
cid = "0.8.6"
sled = "0.34"
ctor = "0.1.23"
banyan-shared = { git = "https://github.com/banyancomputer/banyan-shared-rs" }
banyan-shared ={git = "https://github.com/banyancomputer/banyan-shared-rs"}
dotenv = "0.15.0"
reqwest = "0.11.11"
log = "0.4.17"
tokio = "1.21.2"
rand = "0.8.5"
ethers = { git = "https://github.com/gakonst/ethers-rs" }
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# initial setup
install deps
```bash
$ npm i
```

move .env.example to .env
```bash
$ mv .env.example .env
```
then add your private key and infura API key to .env

# chainlink Node Setup

Follow the instructions to set up a chainlink EA Node on https://docs.chain.link/docs/running-a-chainlink-node/

Once you have set everything up, each time you start up your chainlink node again requires:

Connect postgreSQl to workbench: sh sqlworkbench.sh
Pull desired docker image if not already present in docker: docker pull smartcontract/chainlink:1.7.0-root
Run: docker run -p 6688:6688 -v ~/.chainlink-goerli:/chainlink -it --env-file=.env smartcontract/chainlink:1.7.0-nonroot local n
Make sure your ip is permitted in inbound security group settings for AWS PostgreSql backend. Add your ip, which you can find with the command: dig -4 TXT +short o-o.myaddr.l.google.com @ns1.google.com

To launch the API on the localhost: Cargo run

Create a chainlink job by copying the example_job.toml into the chainlink node operator UI. Create a bridge in the UI, specifying the name of the bridge in the job (.i.e. rust_proof_verifier), and make sure to specify that the url is a docker internal address: http://host.docker.internal:8000/compute

You must deploy the operator.sol contract using the deploy_operator function and call the set_authorized_senders fu

# contract deployment
Deploy contract using
npx hardhat run scripts/deploy.js --network goerli
Proofs.sol is a test contract. You can see our real contracts at https://github.com/banyancomputer/contracts. Proofs.sol is deployed at 0x8185599b47373dF84CB504cbfA124295FF4F346e.

Trigger chainlink API contract function for basic testing using
npx hardhat run scripts/test_ea.js --network goerli

Make sure your contract is funded with some testnet link

# testing

To test your Chainlink EA without constantly making calls to chain, use the unit testing functions in main. Uncomment them out, and make sure you have your infura API_KEY in your env file. Note to use a single thread, since concurrency may give you problems with the nonce in your Eth Client. A better longterm solution would be to develop a nonce manager (Pull requests welcome!)

cargo test -- --test-threads=1

# Things to know

Our implementation of the EA for our specific use case looks almost identical to the example EA, which can be found https://github.com/banyancomputer/chainlink-external-adapter-rs/tree/testing-setup.

Our implementation uses an EthClient as our provider for maing calls to chain. We imnplemented this as a wrapper that makes interfacing with the contract ABI making calls that require gas and modify state much easier. You can check out that implementation in https://github.com/banyancomputer/banyan-shared-rs/blob/master/src/eth.rs, THe ABI for the contract is inputted there, which can be found in hardhat_test/artifacts/contracts/Proofs.sol/Proofs.json after deploying the contract.

Loading

0 comments on commit 85d3e4e

Please sign in to comment.