forked from PeggyJV/sommelier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
399 lines (306 loc) · 15 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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
#!/usr/bin/make -f
PACKAGES_SIMTEST=$(shell go list ./... | grep '/simulation')
VERSION := $(shell git describe --abbrev=6 --dirty --always --tags)
COMMIT := $(shell git log -1 --format='%H')
LEDGER_ENABLED ?= true
SDK_PACK := $(shell go list -m github.com/cosmos/cosmos-sdk | sed 's/ /\@/g')
BUILDDIR ?= $(CURDIR)/build
TEST_DOCKER_REPO=jackzampolin/sommtest
HTTPS_GIT := https://github.com/peggyjv/sommelier.git
DOCKER := $(shell which docker)
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf:1.29.0
export GO111MODULE = on
# process build tags
build_tags = netgo
ifeq ($(LEDGER_ENABLED),true)
ifeq ($(OS),Windows_NT)
GCCEXE = $(shell where gcc.exe 2> NUL)
ifeq ($(GCCEXE),)
$(error gcc.exe not installed for ledger support, please install or set LEDGER_ENABLED=false)
else
build_tags += ledger
endif
else
UNAME_S = $(shell uname -s)
ifeq ($(UNAME_S),OpenBSD)
$(warning OpenBSD detected, disabling ledger support (https://github.com/cosmos/cosmos-sdk/issues/1988))
else
GCC = $(shell command -v gcc 2> /dev/null)
ifeq ($(GCC),)
$(error gcc not installed for ledger support, please install or set LEDGER_ENABLED=false)
else
build_tags += ledger
endif
endif
endif
endif
ifeq (cleveldb,$(findstring cleveldb,$(SOM_BUILD_OPTIONS)))
build_tags += gcc
endif
build_tags += $(BUILD_TAGS)
build_tags := $(strip $(build_tags))
whitespace :=
whitespace += $(whitespace)
comma := ,
build_tags_comma_sep := $(subst $(whitespace),$(comma),$(build_tags))
# process linker flags
ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=sommelier \
-X github.com/cosmos/cosmos-sdk/version.AppName=sommelier \
-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \
-X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)"
ifeq (cleveldb,$(findstring cleveldb,$(SOM_BUILD_OPTIONS)))
ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=cleveldb
endif
ifeq (,$(findstring nostrip,$(SOM_BUILD_OPTIONS)))
ldflags += -w -s
endif
ldflags += $(LDFLAGS)
ldflags := $(strip $(ldflags))
BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)'
# check for nostrip option
ifeq (,$(findstring nostrip,$(SOM_BUILD_OPTIONS)))
BUILD_FLAGS += -trimpath
endif
# The below include contains the tools target.
include contrib/devtools/Makefile
###############################################################################
### Documentation ###
###############################################################################
all: install lint test
build: go.sum
mkdir -p $(BUILDDIR)
go build -mod=readonly $(BUILD_FLAGS) -o $(BUILDDIR)/ ./cmd/sommelier
build-linux: go.sum
LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE) build
build-contract-tests-hooks:
mkdir -p $(BUILDDIR)
go build -mod=readonly $(BUILD_FLAGS) -o $(BUILDDIR)/ ./cmd/contract_tests
install: go.sum
go install -mod=readonly $(BUILD_FLAGS) ./cmd/sommelier
go-mod-cache: go.sum
@echo "--> Download go modules to local cache"
@go mod download
go.sum: go.mod
@echo "--> Ensure dependencies have not been modified"
@go mod verify
draw-deps:
@# requires brew install graphviz or apt-get install graphviz
go get github.com/RobotsAndPencils/goviz
@goviz -i ./cmd/sommelier -d 2 | dot -Tpng -o dependency-graph.png
clean:
rm -rf snapcraft-local.yaml build/
distclean: clean
rm -rf vendor/
###############################################################################
### Devdoc ###
###############################################################################
build-docs:
@cd docs && \
while read p; do \
(git checkout $${p} && npm install && VUEPRESS_BASE="/$${p}/" npm run build) ; \
mkdir -p ~/output/$${p} ; \
cp -r .vuepress/dist/* ~/output/$${p}/ ; \
cp ~/output/$${p}/index.html ~/output ; \
done < versions ;
sync-docs:
cd ~/output && \
echo "role_arn = ${DEPLOYMENT_ROLE_ARN}" >> /root/.aws/config ; \
echo "CI job = ${CIRCLE_BUILD_URL}" >> version.html ; \
aws s3 sync . s3://${WEBSITE_BUCKET} --profile terraform --delete ; \
aws cloudfront create-invalidation --distribution-id ${CF_DISTRIBUTION_ID} --profile terraform --path "/*" ;
.PHONY: sync-docs
###############################################################################
### Tests & Simulation ###
###############################################################################
test: test-unit test-build
test-all: check test-race test-cover
test-unit:
@VERSION=$(VERSION) go test -mod=readonly -tags='ledger test_ledger_mock' $(shell go list ./... | grep -v '/integration_tests')
test-race:
@VERSION=$(VERSION) go test -mod=readonly -race -tags='ledger test_ledger_mock' ./...
test-cover:
@go test -mod=readonly -timeout 30m -race -coverprofile=coverage.txt -covermode=atomic -tags='ledger test_ledger_mock' ./...
test-build: build
@go test -mod=readonly -p 4 `go list ./cli_test/...` -tags=cli_test -v
benchmark:
@go test -mod=readonly -bench=. ./...
###############################################################################
### Linting ###
###############################################################################
lint:
golangci-lint run
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" | xargs gofmt -d -s
format:
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs gofmt -w -s
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs misspell -w
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs goimports -w -local github.com/cosmos/cosmos-sdk
###############################################################################
### Localnet ###
###############################################################################
build-docker-sommnode:
$(MAKE) -C networks/local
# Run a 4-node testnet locally
localnet-start: build-linux localnet-stop
@if ! [ -f build/node0/somm/config/genesis.json ]; then docker run --rm -v $(CURDIR)/build:/somm:Z tendermint/sommnode testnet --v 4 -o . --starting-ip-address 192.168.10.2 --keyring-backend=test ; fi
docker-compose up -d
# Stop testnet
localnet-stop:
docker-compose down
test-docker:
@docker build -f contrib/Dockerfile.test -t ${TEST_DOCKER_REPO}:$(shell git rev-parse --short HEAD) .
@docker tag ${TEST_DOCKER_REPO}:$(shell git rev-parse --short HEAD) ${TEST_DOCKER_REPO}:$(shell git rev-parse --abbrev-ref HEAD | sed 's#/#_#g')
@docker tag ${TEST_DOCKER_REPO}:$(shell git rev-parse --short HEAD) ${TEST_DOCKER_REPO}:latest
test-docker-push: test-docker
@docker push ${TEST_DOCKER_REPO}:$(shell git rev-parse --short HEAD)
@docker push ${TEST_DOCKER_REPO}:$(shell git rev-parse --abbrev-ref HEAD | sed 's#/#_#g')
@docker push ${TEST_DOCKER_REPO}:latest
.PHONY: all build-linux install format lint \
go-mod-cache draw-deps clean build \
setup-transactions setup-contract-tests-data start-somm run-lcd-contract-tests contract-tests \
test test-all test-build test-cover test-unit test-race \
benchmark \
build-docker-sommnode localnet-start localnet-stop \
docker-single-node
###############################################################################
### Protobuf ###
###############################################################################
PROTO_BUILD_IMAGE=ghcr.io/cosmos/proto-builder:0.8
proto-all: proto-format proto-lint proto-gen
proto-gen:
@echo "Generating Protobuf files"
$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(PROTO_BUILD_IMAGE) sh ./scripts/protocgen.sh
proto-format:
@echo "Formatting Protobuf files"
$(DOCKER) run --rm -v $(CURDIR):/workspace \
--workdir /workspace $PROTO_BUILD_IMAGE \
find ./ -not -path "./third_party/*" -name *.proto -exec .clang-format -i {} \;
proto-swagger-gen:
@./scripts/protoc-swagger-gen.sh
proto-lint:
@$(DOCKER_BUF) lint --error-format=json
proto-check-breaking:
@$(DOCKER_BUF) check breaking --against-input $(HTTPS_GIT)#branch=main
TM_URL = https://raw.githubusercontent.com/tendermint/tendermint/v0.34.0/proto/tendermint
GOGO_PROTO_URL = https://raw.githubusercontent.com/regen-network/protobuf/cosmos
COSMOS_PROTO_URL = https://raw.githubusercontent.com/regen-network/cosmos-proto/master
COSMOS_SDK_PROTO_URL = https://raw.githubusercontent.com/cosmos/cosmos-sdk/master/proto/cosmos/base
GOOGLE_PROTO_URL = https://raw.githubusercontent.com/googleapis/googleapis/master/google/api
PROTOBUF_GOOGLE_URL = https://raw.githubusercontent.com/protocolbuffers/protobuf/master/src/google/protobuf
TM_CRYPTO_TYPES = third_party/proto/tendermint/crypto
TM_ABCI_TYPES = third_party/proto/tendermint/abci
TM_TYPES = third_party/proto/tendermint/types
TM_VERSION = third_party/proto/tendermint/version
TM_LIBS = third_party/proto/tendermint/libs/bits
GOGO_PROTO_TYPES = third_party/proto/gogoproto
COSMOS_PROTO_TYPES = third_party/proto/cosmos_proto
GOOGLE_PROTO_TYPES = third_party/proto/google/api
PROTOBUF_GOOGLE_TYPES = third_party/proto/google/protobuf
SDK_ABCI_TYPES = third_party/proto/cosmos/base/abci/v1beta1
SDK_QUERY_TYPES = third_party/proto/cosmos/base/query/v1beta1
SDK_COIN_TYPES = third_party/proto/cosmos/base/v1beta1
proto-update-deps:
mkdir -p $(GOGO_PROTO_TYPES)
curl -sSL $(GOGO_PROTO_URL)/gogoproto/gogo.proto > $(GOGO_PROTO_TYPES)/gogo.proto
mkdir -p $(COSMOS_PROTO_TYPES)
curl -sSL $(COSMOS_PROTO_URL)/cosmos.proto > $(COSMOS_PROTO_TYPES)/cosmos.proto
mkdir -p $(TM_ABCI_TYPES)
curl -sSL $(TM_URL)/abci/types.proto > $(TM_ABCI_TYPES)/types.proto
mkdir -p $(TM_VERSION)
curl -sSL $(TM_URL)/version/types.proto > $(TM_VERSION)/types.proto
mkdir -p $(TM_TYPES)
curl -sSL $(TM_URL)/types/types.proto > $(TM_TYPES)/types.proto
curl -sSL $(TM_URL)/types/evidence.proto > $(TM_TYPES)/evidence.proto
curl -sSL $(TM_URL)/types/params.proto > $(TM_TYPES)/params.proto
curl -sSL $(TM_URL)/types/validator.proto > $(TM_TYPES)/validator.proto
mkdir -p $(TM_CRYPTO_TYPES)
curl -sSL $(TM_URL)/crypto/proof.proto > $(TM_CRYPTO_TYPES)/proof.proto
curl -sSL $(TM_URL)/crypto/keys.proto > $(TM_CRYPTO_TYPES)/keys.proto
mkdir -p $(TM_LIBS)
curl -sSL $(TM_URL)/libs/bits/types.proto > $(TM_LIBS)/types.proto
mkdir -p $(SDK_ABCI_TYPES)
curl -sSL $(COSMOS_SDK_PROTO_URL)/abci/v1beta1/abci.proto > $(SDK_ABCI_TYPES)/abci.proto
mkdir -p $(SDK_QUERY_TYPES)
curl -sSL $(COSMOS_SDK_PROTO_URL)/query/v1beta1/pagination.proto > $(SDK_QUERY_TYPES)/pagination.proto
mkdir -p $(SDK_COIN_TYPES)
curl -sSL $(COSMOS_SDK_PROTO_URL)/v1beta1/coin.proto > $(SDK_COIN_TYPES)/coin.proto
mkdir -p $(GOOGLE_PROTO_TYPES)
curl -sSL $(GOOGLE_PROTO_URL)/annotations.proto > $(GOOGLE_PROTO_TYPES)/annotations.proto
curl -sSL $(GOOGLE_PROTO_URL)/http.proto > $(GOOGLE_PROTO_TYPES)/http.proto
curl -sSL $(GOOGLE_PROTO_URL)/httpbody.proto > $(GOOGLE_PROTO_TYPES)/httpbody.proto
mkdir -p $(PROTOBUF_GOOGLE_TYPES)
curl -sSL $(PROTOBUF_GOOGLE_URL)/any.proto > $(PROTOBUF_GOOGLE_TYPES)/any.proto
PREFIX ?= /usr/local
BIN ?= $(PREFIX)/bin
UNAME_S ?= $(shell uname -s)
UNAME_M ?= $(shell uname -m)
BUF_VERSION ?= 0.11.0
PROTOC_VERSION ?= 3.11.2
ifeq ($(UNAME_S),Linux)
PROTOC_ZIP ?= protoc-${PROTOC_VERSION}-linux-x86_64.zip
endif
ifeq ($(UNAME_S),Darwin)
PROTOC_ZIP ?= protoc-${PROTOC_VERSION}-osx-x86_64.zip
endif
proto-tools: proto-tools-stamp buf
proto-tools-stamp:
echo "Installing protoc compiler..."
(cd /tmp; \
curl -OL "https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/${PROTOC_ZIP}"; \
unzip -o ${PROTOC_ZIP} -d $(PREFIX) bin/protoc; \
unzip -o ${PROTOC_ZIP} -d $(PREFIX) 'include/*'; \
rm -f ${PROTOC_ZIP})
echo "Installing protoc-gen-gocosmos..."
go install github.com/regen-network/cosmos-proto/protoc-gen-gocosmos
# Create dummy file to satisfy dependency and avoid
# rebuilding when this Makefile target is hit twice
# in a row
touch $@
buf: buf-stamp
buf-stamp:
echo "Installing buf..."
curl -sSL \
"https://github.com/bufbuild/buf/releases/download/v${BUF_VERSION}/buf-${UNAME_S}-${UNAME_M}" \
-o "${BIN}/buf" && \
chmod +x "${BIN}/buf"
touch $@
tools-clean:
rm -f proto-tools-stamp buf-stampmodule
.PHONY: proto-all proto-gen proto-swagger-gen proto-format proto-lint proto-check-breaking proto-update-deps
#####################
# Integration tests #
#####################
ORCHESTRATOR_IMAGE := "ghcr.io/peggyjv/gravity-bridge-orchestrator:main"
e2e_build_images: e2e_clean_slate
@docker pull $(ORCHESTRATOR_IMAGE)
@docker tag $(ORCHESTRATOR_IMAGE) orchestrator:prebuilt
@docker build -t sommelier:prebuilt -f Dockerfile .
@docker build -t ethereum:prebuilt -f integration_tests/ethereum/Dockerfile integration_tests/ethereum/
e2e_clean_slate:
@./clean_slate.sh
e2e_basic: e2e_clean_slate
@integration_tests/integration_tests.test -test.run TestBasicChain -test.failfast -test.v || make -s fail
e2e_scheduled_cork_test: e2e_clean_slate
@E2E_SKIP_CLEANUP=true integration_tests/integration_tests.test -test.failfast -test.v -test.run IntegrationTestSuite -testify.m TestScheduledCork || make -s fail
e2e_axelarcork_test: e2e_clean_slate
@E2E_SKIP_CLEANUP=true integration_tests/integration_tests.test -test.failfast -test.v -test.run IntegrationTestSuite -testify.m TestAxelarCork || make -s fail
e2e_auction_test: e2e_clean_slate
@E2E_SKIP_CLEANUP=true integration_tests/integration_tests.test -test.failfast -test.v -test.run IntegrationTestSuite -testify.m TestAuction || make -s fail
e2e_cellarfees_test: e2e_clean_slate
@E2E_SKIP_CLEANUP=true integration_tests/integration_tests.test -test.failfast -test.v -test.run IntegrationTestSuite -testify.m TestCellarFees || make -s fail
e2e_incentives_test: e2e_clean_slate
@E2E_SKIP_CLEANUP=true integration_tests/integration_tests.test -test.failfast -test.v -test.run IntegrationTestSuite -testify.m TestIncentives || make -s fail
e2e_pubsub_test: e2e_clean_slate
@E2E_SKIP_CLEANUP=true integration_tests/integration_tests.test -test.failfast -test.v -test.run IntegrationTestSuite -testify.m TestPubsub || make -s fail
fail:
@echo 'test failed; dumping container logs into ./testlogs for review'
@docker logs ethereum > testlogs/ethereum.log 2>&1 || true
@docker logs sommelier0 > testlogs/sommelier0.log 2>&1 || true
@docker logs sommelier1 > testlogs/sommelier1.log 2>&1 || true
@docker logs sommelier2 > testlogs/sommelier2.log 2>&1 || true
@docker logs sommelier3 > testlogs/sommelier3.log 2>&1 || true
@docker logs orchestrator0 > testlogs/orchestrator0.log 2>&1 || true
@docker logs orchestrator1 > testlogs/orchestrator1.log 2>&1 || true
@docker logs orchestrator2 > testlogs/orchestrator2.log 2>&1 || true
@docker logs orchestrator3 > testlogs/orchestrator3.log 2>&1 || true
@false