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.
- Installing pre-requisites
- Linux
- Mac
- Build
- Install
- Running Tests
- Running tests continuously while developing
- Run a Geth node locally or Rinkeby environments
- Run Centrifuge Chain locally in dev mode
- Run Integration Tests against Local/Rinkeby Environments
- Configure local dev node run integration/functional tests
- Configure node to point to integration run integration/functional tests
- Configure node to point to rinkeby run integration/functional tests
- Configure node to point to infura-rinkeby run integration/functional tests
- Ethereum Contract Bindings
- Protobufs bindings
# Install Go
sudo apt-get update
sudo apt-get -y upgrade
#download go using this command
wget https://dl.google.com/go/go1.11.4.linux-amd64.tar.gz
#extract the archive and move it to /usr/local folder
sudo tar -xvf go1.11.4.linux-amd64.tar.gz
sudo mv go /usr/local
#cd to ~/.profile and add the following lines to the end.
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
# execute this command to use go in the current shell.
source ~/.profile
# 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
# 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
# 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
Make sure you have docker-compose installed, usually comes bundled with Mac OS Docker. Otherwise: https://docs.docker.com/compose/install/
Build & install the Centrifuge OS Node
mkdir -p $GOPATH/src/github.com/centrifuge/go-centrifuge/
cd $GOPATH/src/github.com/centrifuge/
git clone git@github.com:centrifuge/go-centrifuge.git $GOPATH/src/github.com/centrifuge/go-centrifuge
cd go-centrifuge
make install
Check whether everything is fine by running tests
go test --tags="unit" ./...
go test --tags="integration" ./...
Install packages and dependencies
dep ensure
Run only unit tests
go test --tags="unit" ./...
Run only integration tests:
go test --tags="integration" ./...
For Testworld tests, please refer to the Testworld README
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
)
- Run contract migration (fetched by ENV_VAR CENT_ETHEREUM_CONTRACTS_DIR under
- 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
Please note that this testing script is intended for CI testing. Please use the go test
commands for unit and integration testing.
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
For development, we use Docker Compose locally to run the Centrifuge Chain. It comes with a set of preconfigured accounts to be used.
./build/scripts/docker/run.sh ccdev
For more info: https://github.com/centrifuge/centrifuge-chain
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
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
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
- Remove running container if any:
- docker rm -f geth-node
- 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)
- In centrifuge-ethereum-contracts project:
- Run tests:
- To run only integration tests:
- ./build/scripts/tests/run_integration_tests.sh
- To run only integration tests:
- Remove running container if any:
- docker rm -f geth-node
- 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 http://localhost:9545 --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 http://localhost:9545 --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
- To run only integration tests:
- 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
- To run only integration tests:
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"
)
Create any new .proto
files in its own package under protobufs
folder.
Generating go bindings and swagger with the following command
make proto-all