-
Notifications
You must be signed in to change notification settings - Fork 19
/
Makefile
121 lines (94 loc) · 4.92 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
################################################################################
### Project Settings ###
################################################################################
PROJECT_NAME := kava-bridge
PROJECT_DIR := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
GO ?= go
PKGS ?= ./...
################################################################################
### Help ###
################################################################################
help: ## Display this help message
@grep -hE '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
################################################################################
### Targets ###
################################################################################
.PHONY: install
install: ## Install kava-bridge
$(GO) install -mod=readonly ./cmd/kava-bridged
$(GO) install -mod=readonly ./cmd/kava-relayer
.PHONY: start
start: install ## Start kava-bridge chain locally
./contrib/devnet/init-new-chain.sh
kava-bridged start
.PHONY: start-geth
start-geth: ## Start private geth chain locally with the Bridge contract
./contrib/devnet/start-geth.sh
.PHONY: export-geth
export-geth: ## Exports the current geth state to reuse e.g. for kvtool
geth --datadir ./contrib/devnet/geth/data export exported_state
.PHONY: lint
lint: ## Run golint
golint -set_exit_status $(PKGS)
.PHONY: golangci-lint
golangci-lint: ## Run golangci-lint
golangci-lint run
.PHONY: vet
vet: ## Run go vet
$(GO) vet $(PKGS)
.PHONY: build
build: ## Run go build
$(GO) build $(PKGS)
.PHONY: test
test: ## Run go test
$(GO) test $(PKGS)
.PHONY: test-integration
test-integration: ## Run go integration tests
$(GO) test -tags integration ./testing
.PHONY: cover
cover: ## Run tests with coverage and save to coverage.html
$(GO) test -coverprofile=c.out $(PKGS)
$(GO) tool cover -html=c.out -o coverage.html
.PHONY: watch
watch: ## Run tests on file changes
while sleep 0.5; do find . -type f -name '*.go' | entr -d $(GO) test $(PKGS); done
.PHONY: watch-integration
watch-integration: ## Run integration tests on file changes
while sleep 0.5; do find . -type f -name '*.go' | entr -d $(GO) test -tags integration ./testing; done
.PHONY: clean
clean: ## Clean up build and temporary files
rm c.out coverage.html
GETH_VERSION := v1.10.17
.PHONY: install-devtools
install-devtools: ## Install solc and abigen used by compile-contracts
cd contract && npm install
$(GO) install github.com/ethereum/go-ethereum/cmd/abigen@$(GETH_VERSION)
$(GO) install github.com/ethereum/go-ethereum/cmd/geth@$(GETH_VERSION)
JQ ?= jq
NPM ?= npm
SOLC ?= npx solc
ABIGEN ?= abigen
.PHONY: compile-contracts
compile-contracts: contract/ethermint_json/ERC20MintableBurnable.json relayer/bridge.go relayer/erc20.go ## Compiles contracts and creates ethermint compatible json
contract/artifacts/contracts/ERC20MintableBurnable.sol/ERC20MintableBurnable.json: contract/contracts/ERC20MintableBurnable.sol
cd contract && $(NPM) run compile
# Ethermint has their own json format for a compiled contract. The following
# converts the abi field to a stringified array, renames bytecode field name to
# bin with the leading `0x` trimmed.
contract/ethermint_json/ERC20MintableBurnable.json: contract/artifacts/contracts/ERC20MintableBurnable.sol/ERC20MintableBurnable.json
mkdir -p contract/ethermint_json
$(JQ) '.abi = (.abi | tostring) | {abi, bin: .bytecode[2:] }' < $< > $@
contract/artifacts/contracts_Bridge_sol_Bridge.abi: contract/contracts/Bridge.sol
cd contract && $(SOLC) --abi contracts/Bridge.sol --base-path . --include-path node_modules/ -o artifacts
contract/artifacts/contracts_Bridge_sol_Bridge.bin: contract/contracts/Bridge.sol
cd contract && $(SOLC) --optimize --bin contracts/Bridge.sol --base-path . --include-path node_modules/ -o artifacts
contract/artifacts/node_modules_@openzeppelin_contracts_token_ERC20_ERC20_sol_ERC20.abi: contract/node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol
cd contract && $(SOLC) --abi node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol --base-path . --include-path node_modules/ -o artifacts
relayer/bridge.go: contract/artifacts/contracts_Bridge_sol_Bridge.bin contract/artifacts/contracts_Bridge_sol_Bridge.abi
$(ABIGEN) --bin $< --abi $(word 2,$^) --pkg relayer --type Bridge --out $@
relayer/erc20.go: contract/artifacts/node_modules_@openzeppelin_contracts_token_ERC20_ERC20_sol_ERC20.abi
$(ABIGEN) --abi $< --pkg relayer --type ERC20 --out $@
################################################################################
### Includes ###
################################################################################
include protobuf.mk