Centrifuge OS node
go-centrifuge
is the go implementation of the Centrifuge OS interacting with the peer to peer network and our Ethereum smart contracts.
Getting help: Head over to our developer documentation at developer.centrifuge.io to learn how to setup a node and interact with it. If you have any questions, feel free to join our slack channel
DISCLAIMER: The code released here presents a very early alpha version that should not be used in production and has not been audited. Use this at your own risk.
Table of Contents
Installing pre-requisites
Linux
# install jq
sudo apt-get install jq
# install truffle framework
npm install -g truffle@4.0.4
# install Dep
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
Install Docker Compose
# Run this command to download the latest version of Docker Compose
sudo curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
# Apply executable permissions to the binary
sudo chmod +x /usr/local/bin/docker-compose
Mac
# install jq
brew install jq
# install truffle framework
npm install -g truffle@4.0.4
# install Dep
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
Install Docker Compose
Make sure you have docker-compose installed, usually comes bundled with Mac OS Docker. Otherwise: https://docs.docker.com/compose/install/
Build
Build & install the Centrifuge OS Node
cd $GOPATH/src/github.com/centrifuge/go-centrifuge
make install
Install
mkdir -p $GOPATH/src/github.com/centrifuge/go-centrifuge/
git clone git@github.com:centrifuge/go-centrifuge.git $GOPATH/src/github.com/centrifuge/go-centrifuge
# run your local geth node for the first time
./build/scripts/docker/run.sh dev
# You can, however, already run unit/integration tests
./build/scripts/tests/run_unit_tests.sh
./build/scripts/tests/run_integration_tests.sh
Running Tests
Install packages and dependencies
dep ensure
Run only unit tests
./build/scripts/tests/run_unit_tests.sh
Run only integration Tests:
./build/scripts/tests/run_integration_tests.sh
To run integration/functional tests a few other components need to be set up.
- Geth node needs to be up and running
- Contracts need to be deployed
- Run contract migration (fetched by ENV_VAR CENT_ETHEREUM_CONTRACTS_DIR under
build/scripts/test-dependencies/test-ethereum/env_vars.sh
)
- Local account keys need to be set and able to call the right contracts on Ethereum
To do this setup + run all the tests (unit, integration, functional) use the test_wrapper.sh
script.
Run the whole test-suite with
./build/scripts/test_wrapper.sh
Running tests continuously while developing
If you want to run tests continuously when a file changes, you can use reflex:
go get github.com/cespare/reflex
Then run (only for unit tests). It is a good idea to exclude the vendor
and ``.idea` folders from scanning by reflex as it hogs a lot of resources for no good reason.
reflex -R '(^|/)vendor/|(^|/)\\.idea/' -- go test ./centrifuge/... -tags=unit
Or run for specific tests only:
reflex -R '(^|/)vendor/|(^|/)\\.idea/' -- go test ./centrifuge/invoice/... -tags=unit
Run a Geth node locally or Rinkeby environments
For development, we make use of Docker Compose locally as it is easy and clear to bundle volume and environment configurations:
Docker Compose files live in ./build/scripts/docker
Run as local node in dev mode
Then run the local node via ./build/scripts/docker/run.sh dev
By default it uses:
- ETH_DATADIR=${HOME}/Library/Ethereum
- RPC_PORT=9545
- WS_PORT=9546
Run local peer connected to Rinkeby
Let's run the rinkeby local node:
./build/scripts/docker/run.sh rinkeby
By default it uses:
- ETH_DATADIR=${HOME}/Library/Ethereum
- RPC_PORT=9545
Override those when needed
Let it catch up for a while until is fully synced with the remote peer
Run Integration Tests against Local/Rinkeby Environments
- Remove running container if any:
- Clear up ~/Library/Ethereum/8383 folder (keep in mind this will clear up all previous data you had before)
- rm -Rf ~/Library/Ethereum/8383
- In go-centrifuge project run:
- ./build/scripts/docker/run.sh dev
- Run contract migration to generate local contract address artifact:
- In centrifuge-ethereum-contracts project:
- ./build/scripts/migrate.sh localgeth
- Verify that ./deployments/local.json has been generated (note that local.json is excluded in .gitignore)
- Run tests:
- To run only integration tests:
- ./build/scripts/tests/run_integration_tests.sh
- Remove running container if any:
- In go-centrifuge project run:
- ./build/scripts/docker/run.sh rinkeby
- Wait until node is in sync with remote peer (1-2 hours):
- geth attach ws://localhost:9546 --exec "net.peerCount" > 0 (rinkeby takes additional time to sync as it needs a peer to pull from, and has shortage of full node peers)
- geth attach ws://localhost:9546 --exec "eth.syncing" -> false
- Run tests:
- To run only integration tests:
- CENT_CENTRIFUGENETWORK='russianhill' TEST_TARGET_ENVIRONMENT='rinkeby' CENT_ETHEREUM_ACCOUNTS_MAIN_KEY='$JSON_KEY' CENT_ETHEREUM_ACCOUNTS_MAIN_PASSWORD="$PASS" CENT_ETHEREUM_ACCOUNTS_MAIN_ADDRESS="$ADDR" ./build/scripts/tests/run_integration_tests.sh
- Run tests:
- To run only integration tests:
- CENT_ETHEREUM_TXPOOLACCESSENABLED=false CENT_ETHEREUM_NODEURL='wss://rinkeby.infura.io/ws/MtCWERMbJtnqPKI8co84' CENT_CENTRIFUGENETWORK='russianhill' TEST_TARGET_ENVIRONMENT='rinkeby' CENT_ETHEREUM_ACCOUNTS_MAIN_KEY='$JSON_KEY' CENT_ETHEREUM_ACCOUNTS_MAIN_PASSWORD="$PASS" CENT_ETHEREUM_ACCOUNTS_MAIN_ADDRESS="$ADDR" ./build/scripts/tests/run_integration_tests.sh
Ethereum Contract Bindings
To create the go bindings for the deployed truffle contract, use the following command:
abigen --abi abi/AnchorRepository.abi --pkg anchor --type EthereumAnchorRepositoryContract --out ${GOPATH}/src/github.com/centrifuge/go-centrifuge/anchor/ethereum_anchor_repository_contract.go
and then copy the ethereum_anchor_registry_contract.go
file to anchors/
. You will also need to modify the file to add the following imports:
import(
ethereum "github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/event"
)
Protobufs bindings
Create any new .proto
files in its own package under protobufs
folder.
Generating go bindings and swagger with the following command
make proto-all