forked from autonity/autonity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
311 lines (261 loc) · 13.3 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# This Makefile is meant to be used by people that do not usually work
# with Go source code. If you know what GOPATH is then you probably
# don't need to bother with make.
.PHONY: autonity contracts android ios autonity-cross evm all test clean lint mock-gen test-fast test-contracts test-contracts-truffle-fast test-contracts-truffle start-autonity start-ganache test-contracts-pre test-contracts-fast generate
BINDIR = ./build/bin
GO ?= latest
LATEST_COMMIT ?= $(shell git log -n 1 develop --pretty=format:"%H")
ifeq ($(LATEST_COMMIT),)
LATEST_COMMIT := $(shell git log -n 1 HEAD~1 --pretty=format:"%H")
endif
SOLC_VERSION = 0.8.21
SOLC_BINARY = $(BINDIR)/solc_static_linux_v$(SOLC_VERSION)
GOBINDATA_VERSION = 3.23.0
GOBINDATA_BINARY = $(BINDIR)/go-bindata
ABIGEN_BINARY = $(BINDIR)/abigen
CONTRACTS_BASE_DIR = ./autonity/solidity
CONTRACTS_DIR = $(CONTRACTS_BASE_DIR)/contracts
CONTRACTS_TEST_DIR = $(CONTRACTS_BASE_DIR)/test
GENERATED_CONTRACT_DIR = ./params/generated
# DOCKER_SUDO is set to either the empty string or "sudo" and is used to
# control whether docker is executed with sudo or not. If the user is root or
# the user is in the docker group then this will be set to the empty string,
# otherwise it will be set to "sudo".
#
# We make use of posix's short-circuit evaluation of "or" expressions
# (https://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_09_03)
# where the second part of the expression is only executed if the first part
# evaluates to false. We first check to see if the user id is 0 since this
# indicates that the user is root. If not we then use 'id -nG $USER' to list
# all groups that the user is part of and then grep for the word docker in the
# output, if grep matches the word it returns the successful error code. If not
# we then echo "sudo".
DOCKER_SUDO = $(shell [ `id -u` -eq 0 ] || id -nG $(USER) | grep "\<docker\>" > /dev/null || echo sudo )
# Builds the docker image and checks that we can run the autonity binary inside
# it.
build-docker-image:
@$(DOCKER_SUDO) docker build -t autonity .
@$(DOCKER_SUDO) docker run --rm autonity -h > /dev/null
autonity:
mkdir -p $(BINDIR)
go build -o $(BINDIR)/autonity ./cmd/autonity
@echo "Done building."
@echo "Run \"$(BINDIR)/autonity\" to launch autonity."
bindings:
@echo Generating protocol contracts bindings
$(ABIGEN_BINARY) --pkg autonity --solc $(SOLC_BINARY) --sol "$(CONTRACTS_DIR)/bindings.sol" --out ./autonity/bindings.go
@echo Generating internal testing bindings
$(ABIGEN_BINARY) --test --pkg tests --solc $(SOLC_BINARY) --sol $(CONTRACTS_DIR)/bindings.sol --out ./autonity/tests/bindings.go
# Builds Autonity without contract compilation, useful with alpine containers not supporting
# glibc for solc.
autonity-docker:
mkdir -p $(BINDIR)
go build -o $(BINDIR)/autonity ./cmd/autonity
@echo "Done building."
@echo "Run \"$(BINDIR)/autonity\" to launch autonity."
define gen-contract
$(SOLC_BINARY) --overwrite --optimize --optimize-runs 10000 --evm-version london --abi --bin -o $(GENERATED_CONTRACT_DIR) $(CONTRACTS_DIR)/$(1)$(2).sol
@echo Generating bytecode for $(2)
@echo 'package generated' > $(GENERATED_CONTRACT_DIR)/$(2).go
@echo 'import "strings"' >> $(GENERATED_CONTRACT_DIR)/$(2).go
@echo 'import "github.com/autonity/autonity/accounts/abi"' >> $(GENERATED_CONTRACT_DIR)/$(2).go
@echo 'import "github.com/autonity/autonity/common"' >> $(GENERATED_CONTRACT_DIR)/$(2).go
@echo -n 'var $(2)Bytecode = common.Hex2Bytes("' >> $(GENERATED_CONTRACT_DIR)/$(2).go
@cat $(GENERATED_CONTRACT_DIR)/$(2).bin >> $(GENERATED_CONTRACT_DIR)/$(2).go
@echo '")\n' >> $(GENERATED_CONTRACT_DIR)/$(2).go
@echo Generating Abi for $(2)
@echo -n 'var $(2)Abi,_ = abi.JSON(strings.NewReader(`' >> $(GENERATED_CONTRACT_DIR)/$(2).go
@cat $(GENERATED_CONTRACT_DIR)/$(2).abi | json_pp >> $(GENERATED_CONTRACT_DIR)/$(2).go
@echo '`))' >> $(GENERATED_CONTRACT_DIR)/$(2).go
@gofmt -s -w $(GENERATED_CONTRACT_DIR)/$(2).go
endef
contracts: $(SOLC_BINARY) $(GOBINDATA_BINARY) $(CONTRACTS_DIR)/*.sol $(ABIGEN_BINARY)
@$(call gen-contract,,Autonity)
@$(call gen-contract,,Oracle)
@$(call gen-contract,,AutonityUpgradeTest)
@$(call gen-contract,,Accountability)
@$(call gen-contract,,AutonityTest)
@$(call gen-contract,,AccountabilityTest)
@$(call gen-contract,,UpgradeManager)
@$(call gen-contract,,InflationController)
@$(call gen-contract,asm/,ACU)
@$(call gen-contract,asm/,SupplyControl)
@$(call gen-contract,asm/,Stabilization)
@$(call gen-contract,vesting/,NonStakableVesting)
@$(call gen-contract,vesting/,StakableVesting)
# update 4byte selector for clef
./build/generate_4bytedb.sh $(SOLC_BINARY)
cd signer/fourbyte && go generate
# Generate go bindings
@echo Generating protocol contracts bindings
$(ABIGEN_BINARY) --pkg autonity --solc $(SOLC_BINARY) --sol $(CONTRACTS_DIR)/bindings.sol --out ./autonity/bindings.go
@echo Generating internal testing bindings
$(ABIGEN_BINARY) --test --pkg tests --solc $(SOLC_BINARY) --sol $(CONTRACTS_DIR)/bindings.sol --out ./autonity/tests/bindings.go
$(SOLC_BINARY):
mkdir -p $(BINDIR)
wget -O $(SOLC_BINARY) https://github.com/ethereum/solidity/releases/download/v$(SOLC_VERSION)/solc-static-linux
chmod +x $(SOLC_BINARY)
$(GOBINDATA_BINARY):
mkdir -p $(BINDIR)
wget -O $(GOBINDATA_BINARY) https://github.com/kevinburke/go-bindata/releases/download/v$(GOBINDATA_VERSION)/go-bindata-linux-amd64
chmod +x $(GOBINDATA_BINARY)
$(ABIGEN_BINARY):
go build -o $(ABIGEN_BINARY) ./cmd/abigen
all: $(ABIGEN_BINARY) contracts
go run build/ci.go install
android:
go run build/ci.go aar --local
@echo "Done building."
@echo "Import \"$(GOBIN)/geth.aar\" to use the library."
@echo "Import \"$(GOBIN)/geth-sources.jar\" to add javadocs"
@echo "For more info see https://stackoverflow.com/questions/20994336/android-studio-how-to-attach-javadoc"
ios:
go run build/ci.go xcode --local
@echo "Done building."
@echo "Import \"$(BINDIR)/autonity.framework\" to use the library."
test: all
go run build/ci.go test -coverage
test-fast:
go run build/ci.go test
test-race-all: all
go run build/ci.go test -race
make test-race
test-race:
go test -race -v ./consensus/tendermint/... -parallel 1
test-contracts: test-contracts-asm test-contracts-truffle
test-contracts-fast: test-contracts-asm test-contracts-truffle-fast
# prerequisites for testing contracts
test-contracts-pre:
@# npm list returns 0 only if the package is not installed and the shell only
@# executes the second part of an or statement if the first fails.
@# Nov, 2022, the latest release of Truffle, v5.6.6 does not works for the tests.
@echo "check and install truffle.js"
@npm list truffle > /dev/null || npm install truffle
@echo "check and install web3.js"
@npm list web3 > /dev/null || npm install web3
@echo "check and install keccak256"
@npm list keccak256 > /dev/null || npm install keccak256
@echo "check and install truffle-assertions.js"
@npm list truffle-assertions > /dev/null || npm install truffle-assertions
@echo "check and install ganache"
@npm list ganache > /dev/null || npm install ganache
@npx truffle version
APE_VERSION := 0.6.26
HARDHAT_VERSION := 2.19.1
test-contracts-asm: test-contracts-asm-pre
@echo "run tests for the asm contracts"
@cd $(CONTRACTS_BASE_DIR) && ape --verbosity DEBUG test --network ::hardhat ./test/asm/acu
@cd $(CONTRACTS_BASE_DIR) && ape --verbosity DEBUG test --network ::hardhat ./test/asm/stabilization
@cd $(CONTRACTS_BASE_DIR) && ape --verbosity DEBUG test --network ::hardhat ./test/asm/supply_control
.PHONY: test-contracts-asm-pre
test-contracts-asm-pre:
@echo "check and install ape framework"
@ape > /dev/null || pipx install eth-ape==$(APE_VERSION) || { pipx uninstall eth-ape; exit 1; }
@echo "check ape framework version"
@test $$(ape --version) = "$(APE_VERSION)" || { \
echo -n "error: unsupported ape version $$(ape --version) "; \
echo "(need $(APE_VERSION))..."; \
echo "please uninstall eth-ape and then re-run the make target"; \
exit 1;\
}
@echo "check and install hardhat"
@cd $(CONTRACTS_BASE_DIR) && npm list hardhat@$(HARDHAT_VERSION) > /dev/null || npm install hardhat@$(HARDHAT_VERSION)
@echo "install ape framework plugins"
@cd $(CONTRACTS_BASE_DIR) && ape plugins install -y --verbosity ERROR .
@echo "dependencies installed"
# start an autonity network for contract tests
start-autonity:
@echo "starting autonity test network"
@cd $(CONTRACTS_TEST_DIR)/autonity/ && nohup ./autonity-start.sh >/dev/null 2>&1 &
@# give some time for autonity to start
@sleep 10
@# check that autonity started correctly and is listening on the correct port
@pgrep autonity
@lsof -i :8545 | grep autonity
# start a ganache network for fast contract tests
start-ganache:
@echo "starting ganache"
@nohup npx ganache --chain.allowUnlimitedContractSize --chain.allowUnlimitedInitCodeSize --gasLimit 0x1fffffffffffff >/dev/null 2>&1 &
@sleep 2
@pgrep -f ganache
@lsof -i :8545 | grep node
# This runs the contract tests using truffle against an Autonity node instance.
test-contracts-truffle: autonity contracts test-contracts-pre start-autonity
@cd $(CONTRACTS_TEST_DIR) && npx truffle test autonity.js && cd -
@cd $(CONTRACTS_TEST_DIR) && npx truffle test oracle.js && cd -
@cd $(CONTRACTS_TEST_DIR) && npx truffle test liquid.js && cd -
@cd $(CONTRACTS_TEST_DIR) && npx truffle test accountability.js && cd -
@cd $(CONTRACTS_TEST_DIR) && npx truffle test protocol.js && cd -
@#refund.js is ran only against Autonity, since ganache does not implement the oracle vote refund logic
@cd $(CONTRACTS_TEST_DIR) && npx truffle test refund.js && cd -
@#validator_management.js is ran only against Autonity, since ganache does not implement the POP logic
@cd $(CONTRACTS_TEST_DIR) && npx truffle test validator_management.js && cd -
@echo "killing test autonity network and cleaning chaindata"
@-pkill autonity
@cd $(CONTRACTS_TEST_DIR)/autonity/ && rm -Rdf ./data
# This runs the contract tests using truffle against a Ganache instance
test-contracts-truffle-fast: contracts test-contracts-pre start-ganache
@cd $(CONTRACTS_TEST_DIR) && npx truffle test autonity.js && cd -
@cd $(CONTRACTS_TEST_DIR) && npx truffle test oracle.js && cd -
@cd $(CONTRACTS_TEST_DIR) && npx truffle test liquid.js && cd -
@cd $(CONTRACTS_TEST_DIR) && npx truffle test accountability.js && cd -
@cd $(CONTRACTS_TEST_DIR) && npx truffle test protocol.js && cd -
@echo "killing ganache"
@-pkill -f "ganache"
docker-e2e-test: contracts
build/env.sh go run build/ci.go install
cd docker_e2e_test && sudo python3 test_via_docker.py ..
mock-gen:
mockgen -source=consensus/tendermint/core/interfaces/core_backend.go -package=interfaces -destination=consensus/tendermint/core/interfaces/core_backend_mock.go
mockgen -source=consensus/tendermint/accountability/fault_detector.go -package=accountability -destination=consensus/tendermint/accountability/fault_detector_mock.go
mockgen -source=consensus/consensus.go -package=consensus -destination=consensus/consensus_mock.go
mockgen -source=accounts/abi/bind/backend.go -package=bind -destination=accounts/abi/bind/backend_mock.go
mockgen -source=consensus/tendermint/core/interfaces/gossiper.go -package=interfaces -destination=consensus/tendermint/core/interfaces/gossiper_mock.go
mockgen -source=consensus/tendermint/core/interfaces/broadcaster.go -package=interfaces -destination=consensus/tendermint/core/interfaces/broadcaster_mock.go
generate:
cd core/types/ && go generate
lint-dead:
@./.github/tools/golangci-lint run \
--config ./.golangci/step_dead.yml
lint:
@echo "--> Running linter for code diff versus commit $(LATEST_COMMIT)"
@./.github/tools/golangci-lint run \
--new-from-rev=$(LATEST_COMMIT) \
--config ./.golangci/step1.yml \
--exclude "which can be annoying to use"
@./.github/tools/golangci-lint run \
--new-from-rev=$(LATEST_COMMIT) \
--config ./.golangci/step2.yml
@./.github/tools/golangci-lint run \
--new-from-rev=$(LATEST_COMMIT) \
--config ./.golangci/step3.yml
@./.github/tools/golangci-lint run \
--new-from-rev=$(LATEST_COMMIT) \
--config ./.golangci/step4.yml
lint-ci: lint
test-deps:
go get golang.org/x/tools/cmd/cover
go get github.com/mattn/goveralls
cd tests/testdata && git checkout b5eb9900ee2147b40d3e681fe86efa4fd693959a
lint-deps:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./build/bin v1.55.2
clean:
go clean -cache
rm -fr build/_workspace/pkg/ $(BINDIR)/*
rm -rf $(GENERATED_CONTRACT_DIR)/*.abi $(GENERATED_CONTRACT_DIR)/*.bin
# The devtools target installs tools required for 'go generate'.
# You need to put $BINDIR (or $GOPATH/bin) in your PATH to use 'go generate'.
devtools:
go get -u go.uber.org/mock/mockgen
env BINDIR= go get -u golang.org/x/tools/cmd/stringer
env BINDIR= go install github.com/kevinburke/go-bindata/v4/...@latest
env BINDIR= go install github.com/fjl/gencodec@latest
env BINDIR= go get -u github.com/golang/protobuf/protoc-gen-go
go build -o $BINDIR/abigen ./cmd/abigen
@type "npm" 2> /dev/null || echo 'Please install node.js and npm'
@type "solc" 2> /dev/null || echo 'Please install solc'
@type "protoc" 2> /dev/null || echo 'Please install protoc'
release: autonity contracts
mkdir -p ./build/release/$(VERSION)
cd ./build/bin && tar -czvf ../release/$(VERSION)/autonity-linux-amd64-$(VERSION).tar.gz autonity
cd ./params/generated && tar -czvf ../../build/release/$(VERSION)/protocol-contracts-abi-$(VERSION).tar.gz *.abi