diff --git a/stack b/stack index ef0afabc..94b9d86f 100755 --- a/stack +++ b/stack @@ -3,32 +3,30 @@ set -euo pipefail IFS=$'\n\t' DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DATA_DIRECTORY=${DATA_DIRECTORY:="/data/chain"} -NETWORK=${NETWORK:="geth"} ############################################################################ -############################################################################ -# geth -############################################################################ +# chain ############################################################################ -# run a local geth node in dev mode mounted against a local data directory -function geth() { - docker network ls | grep lilypad || docker network create lilypad - docker run -d --restart always \ - --name geth \ - --network lilypad \ +function chain() { + DATA_DIR=${@:-/data/chain} + + docker run \ + --rm \ + --name chain \ -p 8545:8545 \ -p 8546:8546 \ - -v ${DATA_DIRECTORY}:/data/geth \ + -v ${DATA_DIR}:/data/chain \ + --network lilypad \ + --add-host localhost:host-gateway \ ethereum/client-go:v1.13.5 \ - --datadir /data/geth \ + --datadir /data/chain \ --dev \ --ws \ --ws.api web3,eth,net \ --ws.addr 0.0.0.0 \ --ws.port 8546 \ - --ws.origins '*' \ + --ws.origins '*' --http \ --http.api web3,eth,net \ --http.addr 0.0.0.0 \ @@ -37,17 +35,72 @@ function geth() { --http.vhosts '*' } -function geth-command() { - docker exec -i geth geth --exec "$@" attach /data/geth/geth.ipc +function chain-docker-build() { + docker build \ + -t chain \ + -f ./docker/chain/Dockerfile \ + --build-arg arch=arm64 \ + --build-arg admin_address=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \ + . +} + +function chain-docker-run() { + DATA_DIR=${@:-/data/chain} + + docker run \ + --rm \ + --name chain \ + --network lilypad \ + --add-host localhost:host-gateway \ + -p 8545:8545 \ + -p 8546:8546 \ + -v ${DATA_DIR}:/data/chain \ + chain +} + +function chain-boot() { + echo "- Funding services with ether" + fund-services-ether + echo "- Funding services with ether" + deploy +} + +function deploy() { + clean-deploy + echo "- Compiling contracts" + compile-contracts + echo "- Deploying contracts" + deploy-contracts + echo "- Funding services with tokens" + fund-services-tokens + echo "- Printing balances" + balances +} + + +function chain-fund-admin() { + docker exec -i chain geth --exec "eth.sendTransaction({from: eth.coinbase, to: \"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266\", value: new web3.BigNumber(eth.getBalance(eth.coinbase)).minus(web3.toWei(1, \"ether\")) })" attach /data/chain/geth.ipc +} + +function clean() { + DATA_DIR=${@:-/data/chain} + + docker rm -f $(docker ps -aq) || true + rm -rf ${DATA_DIR}/* + clean-deploy +} + +function clean-deploy() { + rm -rf $(pwd)/hardhat/artifacts + rm -rf $(pwd)/hardhat/cache + rm -rf $(pwd)/hardhat/deployments/geth } -############################################################################ ############################################################################ # faucet ############################################################################ -############################################################################ -# fun the faucet container +# TODO function faucet() { source .env eval $(./stack print-contract-env) @@ -68,90 +121,44 @@ function faucet() { ############################################################################ -############################################################################ -# bacalhau -############################################################################ +# hardhat ############################################################################ -function bacalhau-serve() { - bacalhau serve \ - --node-type compute,requester \ - --peer none \ - --private-internal-ipfs=false \ - --job-selection-accept-networked +function compile-contracts() { + ( + set -euo pipefail + cd hardhat + npx hardhat compile + ) + go-bindings } -# move ALL the money apart from 1 eth to the given admin account -# this expects the .env file to already have been created -function fund-admin() { - if [[ -z "$ADMIN_ADDRESS" ]]; then - echo >&2 "ADMIN_ADDRESS must be set (source ${DIR}/.env)" - exit 1 +function go-bindings() { + # check if the lilypad-solc image exists + # and only build it if it doesn't + if [[ -z $(docker images -q lilypad-solc) ]]; then + docker build -t lilypad-solc hardhat/solc fi - geth-command "eth.sendTransaction({from: eth.coinbase, to: \"${ADMIN_ADDRESS}\", value: new web3.BigNumber(eth.getBalance(eth.coinbase)).minus(web3.toWei(1, \"ether\")) })" -} - -function geth-stop() { - docker rm -f geth 2> /dev/null || true -} - -function clean-deploy() { - rm -rf ${DIR}/hardhat/artifacts - rm -rf ${DIR}/hardhat/cache - rm -rf ${DIR}/hardhat/deployments/geth -} - -function clean() { - docker rm -f $(docker ps -aq) || true - rm -rf ${DATA_DIRECTORY}/* - clean-deploy -} - -function boot-message() { - echo "" - echo "############################################################################" - echo "# $@" - echo "############################################################################" - echo "" -} - -function deploy() { - clean-deploy - boot-message "Compiling contracts" - compile-contracts - boot-message "Deploying contracts" - deploy-contracts - boot-message "Funding services with tokens" - fund-services-tokens - boot-message "Printing balances" - balances -} + rm -rf pkg/web3/bindings + mkdir -p pkg/web3/bindings + go-binding LilypadToken token + go-binding LilypadPayments payments + go-binding LilypadStorage storage + go-binding LilypadUsers users + go-binding LilypadMediationRandom mediation + go-binding LilypadOnChainJobCreator jobcreator + go-binding LilypadController controller -function boot() { - clean - boot-message "Starting geth" - geth - sleep 5 - boot-message "Funding admin account" - fund-admin - boot-message "Funding services with ether" - fund-services-ether - deploy + echo "- Generated all go bindings pkg/contract/bindings/" } -############################################################################ -############################################################################ -# hardhat -############################################################################ -############################################################################ - function go-binding() { local name="$1" local pkg="$2" # compile the sol files into bytecode and ABI docker run --rm \ - -v $DIR/hardhat:/src \ + -v $(pwd)/hardhat:/src \ -w /src \ --entrypoint solc \ lilypad-solc \ @@ -167,7 +174,7 @@ function go-binding() { # generate the go bindings docker run --rm \ - -v $DIR/hardhat:/src \ + -v $(pwd)/hardhat:/src \ -w /src \ --entrypoint abigen \ lilypad-solc \ @@ -179,45 +186,21 @@ function go-binding() { chmod 0644 hardhat/artifacts/bindings/$pkg/$pkg.go cp -r hardhat/artifacts/bindings/$pkg pkg/web3/bindings/$pkg - echo "Generated go binding hardhat/artifacts/bindings/$pkg/$pkg.go" -} - -function go-bindings() { - # check if the lilypad-solc image exists - # and only build it if it doesn't - if [[ -z $(docker images -q lilypad-solc) ]]; then - docker build -t lilypad-solc hardhat/solc - fi - rm -rf pkg/web3/bindings - mkdir -p pkg/web3/bindings - go-binding LilypadToken token - go-binding LilypadPayments payments - go-binding LilypadStorage storage - go-binding LilypadUsers users - go-binding LilypadMediationRandom mediation - go-binding LilypadOnChainJobCreator jobcreator - go-binding LilypadController controller - - echo "Generated all go bindings pkg/contract/bindings/" -} - -function compile-contracts() { - ( - set -euo pipefail - cd hardhat - npx hardhat compile - ) - go-bindings + echo "- Generated go binding hardhat/artifacts/bindings/$pkg/$pkg.go" } function deploy-contracts() { ( set -euo pipefail cd hardhat - npx hardhat deploy --network "$NETWORK" + npx hardhat deploy --network geth ) } +############################################################################ +# helpers +############################################################################ + function hardhat-script() { ( set -euo pipefail @@ -226,7 +209,6 @@ function hardhat-script() { ) } -# print the env settings for the various accounts and private keys function print-env() { hardhat-script scripts/print-env.ts | grep export } @@ -256,78 +238,11 @@ function run-cowsay-onchain() { } ############################################################################ +# solver ############################################################################ -# services -############################################################################ -############################################################################ - -function chain() { - DATA_DIR=${@:-/data/chain} - - docker run \ - --rm \ - --name chain \ - -p 8545:8545 \ - -p 8546:8546 \ - -v ${DATA_DIR}:/data/chain \ - --network lilypad \ - --add-host localhost:host-gateway \ - ethereum/client-go:v1.13.5 \ - --datadir /data/chain \ - --dev \ - --ws \ - --ws.api web3,eth,net \ - --ws.addr 0.0.0.0 \ - --ws.port 8546 \ - --ws.origins '*' - --http \ - --http.api web3,eth,net \ - --http.addr 0.0.0.0 \ - --http.corsdomain '*' \ - --http.port 8545 \ - --http.vhosts '*' -} - -function chain-docker-build() { - docker build \ - -t chain \ - -f ./docker/chain/Dockerfile \ - . -} - -function chain-docker-run() { - DATA_DIR=${@:-/data/chain} - - docker run \ - --rm \ - --name chain \ - --network lilypad \ - --add-host localhost:host-gateway \ - -p 8545:8545 \ - -p 8546:8546 \ - -v ${DATA_DIR}:/data/chain \ - chain -} - -function chain-boot() { - boot-message "Funding admin account" - chain-fund-admin - boot-message "Funding services with ether" - fund-services-ether - boot-message "Funding services with ether" - deploy -} - -function chain-fund-admin() { - chain-command "eth.sendTransaction({from: eth.coinbase, to: \"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266\", value: new web3.BigNumber(eth.getBalance(eth.coinbase)).minus(web3.toWei(1, \"ether\")) })" -} - -function chain-command() { - docker exec -i chain geth --exec "$@" attach /data/chain/geth.ipc -} function solver() { - echo "Reminder to do doppler setup to project->solver and config->dev" + echo "- Reminder to do doppler setup to project->solver and config->dev" doppler run -p solver -c dev -- go run . solver } @@ -335,7 +250,6 @@ function solver-docker-build() { docker build \ -t solver \ -f ./docker/solver/Dockerfile \ - --build-arg doppler_config=dev \ . } @@ -350,8 +264,12 @@ function solver-docker-run() { solver } +############################################################################ +# job creator +############################################################################ + function job-creator() { - echo "Reminder to do doppler setup to project->job-creator and config->dev" + echo "- Reminder to do doppler setup to project->job-creator and config->dev" doppler run -p job-creator -c dev -- go run . jobcreator } @@ -359,7 +277,6 @@ function job-creator-docker-build() { docker build \ -t job-creator \ -f ./docker/job-creator/Dockerfile \ - --build-arg doppler_config=dev \ . } @@ -373,8 +290,12 @@ function job-creator-docker-run() { job-creator } +############################################################################ +# resource provider +############################################################################ + function resource-provider() { - echo "Reminder to do doppler setup to project->resource-provider and config->dev" + echo "- Reminder to do doppler setup to project->resource-provider and config->dev" doppler run -p resource-provider -c dev -- go run . resource-provider } @@ -383,7 +304,6 @@ function resource-provider-docker-build() { -t resource-provider \ -f ./docker/resource-provider/Dockerfile \ --build-arg doppler_config=dev \ - --build-arg DOPPLER_TOKEN_BACALHAU="$(doppler configs tokens create -p bacalhau -c dev bacalhau_docker --plain)" \ --build-arg DOPPLER_TOKEN_RESOURCE_PROVIDER="$(doppler configs tokens create -p resource-provider -c dev resource_provider_docker --plain)" \ . } @@ -394,20 +314,22 @@ function resource-provider-docker-run() { --name resource-provider \ --network lilypad \ --add-host localhost:host-gateway \ - -e DOPPLER_TOKEN_BACALHAU="$(doppler configs tokens create -p bacalhau -c dev bacalhau_docker --max-age 1m --plain)" \ -e DOPPLER_TOKEN_RESOURCE_PROVIDER="$(doppler configs tokens create -p resource-provider -c dev resource_provider_docker --max-age 1m --plain)" \ resource-provider } -function bacalhau(){ - export BACALHAU_SERVE_IPFS_PATH=/tmp/lilypad/data/ipfs \ - && export LOG_LEVEL=debug \ - && bacalhau serve --node-type compute,requester --peer none --private-internal-ipfs=false --job-selection-accept-networked +############################################################################ +# bacalhau node +############################################################################ + +function bacalhau-node(){ + export BACALHAU_SERVE_IPFS_PATH=/tmp/lilypad/data/ipfs + export LOG_LEVEL=debug \ + bacalhau serve --node-type compute,requester --peer none --private-internal-ipfs=false --job-selection-accept-networked } function bacalhau-docker-build() { docker build \ - --no-cache \ -t bacalhau \ -f ./docker/bacalhau/Dockerfile \ . @@ -425,31 +347,29 @@ function bacalhau-docker-run() { bacalhau } +############################################################################ +# mediator +############################################################################ + function mediator() { go run . mediator "$@" } -############################################################################ ############################################################################ # tests ############################################################################ -############################################################################ function unit-tests() { - ( - set -euo pipefail - cd hardhat - npx hardhat test --network hardhat - ) + cd hardhat + npx hardhat test --network hardhat } -# this assumes boot having been run already +# this assumes chain is running +# and chain-fund-admin +# and chain-boot function integration-tests() { - ( - set -euo pipefail - cd test - go test -v -count 1 . - ) + cd test + doppler run -p integration-tests -c dev -- go test -v -count 1 . } eval "$@"