-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathMakefile
393 lines (311 loc) · 16.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
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
.SILENT:
POCKETD_HOME := ./localnet/pocketd
POCKET_NODE = tcp://127.0.0.1:36657 # The pocket rollup node (full node and sequencer in the localnet context)
POCKET_ADDR_PREFIX = pokt
####################
### Dependencies ###
####################
# TODO: Add other dependencies (ignite, docker, k8s, etc) here
.PHONY: install_ci_deps
install_ci_deps: ## Installs `mockgen`
go install "github.com/golang/mock/[email protected]" && mockgen --version
########################
### Makefile Helpers ###
########################
.PHONY: prompt_user
# Internal helper target - prompt the user before continuing
prompt_user:
@echo "Are you sure? [y/N] " && read ans && [ $${ans:-N} = y ]
.PHONY: list
list: ## List all make targets
@${MAKE} -pRrn : -f $(MAKEFILE_LIST) 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | sort
.PHONY: help
.DEFAULT_GOAL := help
help: ## Prints all the targets in all the Makefiles
@grep -h -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
##############
### Checks ###
##############
.PHONY: go_version_check
# Internal helper target - check go version
go_version_check:
@# Extract the version number from the `go version` command.
@GO_VERSION=$$(go version | cut -d " " -f 3 | cut -c 3-) && \
MAJOR_VERSION=$$(echo $$GO_VERSION | cut -d "." -f 1) && \
MINOR_VERSION=$$(echo $$GO_VERSION | cut -d "." -f 2) && \
\
if [ "$$MAJOR_VERSION" -ne 1 ] || [ "$$MINOR_VERSION" -ge 21 ] || [ "$$MINOR_VERSION" -le 18 ] ; then \
echo "Invalid Go version. Expected 1.19.x or 1.20.x but found $$GO_VERSION"; \
exit 1; \
fi
.PHONY: docker_check
# Internal helper target - check if docker is installed
docker_check:
{ \
if ( ! ( command -v docker >/dev/null && (docker compose version >/dev/null || command -v docker-compose >/dev/null) )); then \
echo "Seems like you don't have Docker or docker-compose installed. Make sure you review build/localnet/README.md and docs/development/README.md before continuing"; \
exit 1; \
fi; \
}
.PHONY: warn_destructive
warn_destructive: ## Print WARNING to the user
@echo "This is a destructive action that will affect docker resources outside the scope of this repo!"
#######################
### Proto Helpers ####
#######################
.PHONY: proto_regen
proto_regen: ## Delete existing protobuf artifacts and regenerate them
find . \( -name "*.pb.go" -o -name "*.pb.gw.go" \) | xargs --no-run-if-empty rm
ignite generate proto-go --yes
#######################
### Docker Helpers ###
#######################
.PHONY: docker_wipe
docker_wipe: docker_check warn_destructive prompt_user ## [WARNING] Remove all the docker containers, images and volumes.
docker ps -a -q | xargs -r -I {} docker stop {}
docker ps -a -q | xargs -r -I {} docker rm {}
docker images -q | xargs -r -I {} docker rmi {}
docker volume ls -q | xargs -r -I {} docker volume rm {}
########################
### Localnet Helpers ###
########################
.PHONY: localnet_up
localnet_up: ## Starts localnet
make localnet_regenesis
tilt up
.PHONY: localnet_down
localnet_down: ## Delete resources created by localnet
tilt down
kubectl delete secret celestia-secret || exit 1
.PHONY: localnet_regenesis
localnet_regenesis: ## Regenerate the localnet genesis file
# NOTE: intentionally not using --home <dir> flag to avoid overwriting the test keyring
ignite chain init
cp -r ${HOME}/.pocket/keyring-test $(POCKETD_HOME)
cp ${HOME}/.pocket/config/*_key.json $(POCKETD_HOME)/config/
cp ${HOME}/.pocket/config/genesis.json $(POCKETD_HOME)/config/
#############
### Tests ###
#############
.PHONY: test_e2e
test_e2e: ## Run all E2E tests
export POCKET_NODE=$(POCKET_NODE) POCKETD_HOME=../../$(POCKETD_HOME) && go test -v ./e2e/tests/... -tags=e2e
.PHONY: go_test
go_test: go_version_check ## Run all go tests
go test -v -race -tags test ./...
.PHONY: go_test_integration
go_test_integration: go_version_check ## Run all go tests, including integration
go test -v -race -tags test,integration ./...
.PHONY: itest
itest: go_version_check ## Run tests iteratively (see usage for more)
./tools/scripts/itest.sh $(filter-out $@,$(MAKECMDGOALS))
# catch-all target for itest
%:
# no-op
@:
.PHONY: go_mockgen
go_mockgen: ## Use `mockgen` to generate mocks used for testing purposes of all the modules.
find . -name "*_mock.go" | xargs --no-run-if-empty rm
go generate ./x/application/types/
go generate ./x/gateway/types/
go generate ./x/supplier/types/
go generate ./x/session/types/
go generate ./pkg/...
.PHONY: go_develop
go_develop: proto_regen go_mockgen ## Generate protos and mocks
.PHONY: go_develop_and_test
go_develop_and_test: go_develop go_test ## Generate protos, mocks and run all tests
#############
### TODOS ###
#############
# How do I use TODOs?
# 1. <KEYWORD>: <Description of follow up work>;
# e.g. TODO_HACK: This is a hack, we need to fix it later
# 2. If there's a specific issue, or specific person, add that in paranthesiss
# e.g. TODO(@Olshansk): Automatically link to the Github user https://github.com/olshansk
# e.g. TODO_INVESTIGATE(#420): Automatically link this to github issue https://github.com/pokt-network/pocket/issues/420
# e.g. TODO_DISCUSS(@Olshansk, #420): Specific individual should tend to the action item in the specific ticket
# e.g. TODO_CLEANUP(core): This is not tied to an issue, or a person, but should only be done by the core team.
# e.g. TODO_CLEANUP: This is not tied to an issue, or a person, and can be done by the core team or external contributors.
# 3. Feel free to add additional keywords to the list above.
# Inspired by @goldinguy_ in this post: https://goldin.io/blog/stop-using-todo ###
# TODO - General Purpose catch-all.
# TODO_DECIDE - A TODO indicating we need to make a decision and document it using an ADR in the future; https://github.com/pokt-network/pocket-network-protocol/tree/main/ADRs
# TODO_TECHDEBT - Not a great implementation, but we need to fix it later.
# TODO_BLOCKER - Similar to TECHDEBT, but of higher priority, urgency & risk prior to the next release
# TODO_IMPROVE - A nice to have, but not a priority. It's okay if we never get to this.
# TODO_OPTIMIZE - An opportunity for performance improvement if/when it's necessary
# TODO_DISCUSS - Probably requires a lengthy offline discussion to understand next steps.
# TODO_INCOMPLETE - A change which was out of scope of a specific PR but needed to be documented.
# TODO_INVESTIGATE - TBD what was going on, but needed to continue moving and not get distracted.
# TODO_CLEANUP - Like TECHDEBT, but not as bad. It's okay if we never get to this.
# TODO_HACK - Like TECHDEBT, but much worse. This needs to be prioritized
# TODO_REFACTOR - Similar to TECHDEBT, but will require a substantial rewrite and change across the codebase
# TODO_CONSIDERATION - A comment that involves extra work but was thoughts / considered as part of some implementation
# TODO_CONSOLIDATE - We likely have similar implementations/types of the same thing, and we should consolidate them.
# TODO_ADDTEST - Add more tests for a specific code section
# TODO_DEPRECATE - Code that should be removed in the future
# TODO_RESEARCH - A non-trivial action item that requires deep research and investigation being next steps can be taken
# TODO_DOCUMENT - A comment that involves the creation of a README or other documentation
# TODO_BUG - There is a known existing bug in this code
# TODO_NB - An important note to reference later
# TODO_DISCUSS_IN_THIS_COMMIT - SHOULD NEVER BE COMMITTED TO MASTER. It is a way for the reviewer of a PR to start / reply to a discussion.
# TODO_IN_THIS_COMMIT - SHOULD NEVER BE COMMITTED TO MASTER. It is a way to start the review process while non-critical changes are still in progress
TODO_KEYWORDS = -e "TODO" -e "TODO_DECIDE" -e "TODO_TECHDEBT" -e "TODO_IMPROVE" -e "TODO_OPTIMIZE" -e "TODO_DISCUSS" -e "TODO_INCOMPLETE" -e "TODO_INVESTIGATE" -e "TODO_CLEANUP" -e "TODO_HACK" -e "TODO_REFACTOR" -e "TODO_CONSIDERATION" -e "TODO_IN_THIS_COMMIT" -e "TODO_DISCUSS_IN_THIS_COMMIT" -e "TODO_CONSOLIDATE" -e "TODO_DEPRECATE" -e "TODO_ADDTEST" -e "TODO_RESEARCH" -e "TODO_BUG" -e "TODO_NB" -e "TODO_DISCUSS_IN_THIS_COMMIT" -e "TODO_IN_THIS_COMMIT"
.PHONY: todo_list
todo_list: ## List all the TODOs in the project (excludes vendor and prototype directories)
grep --exclude-dir={.git,vendor,prototype} -r ${TODO_KEYWORDS} .
TODO_SEARCH ?= $(shell pwd)
.PHONY: todo_search
todo_search: ## List all the TODOs in a specific directory specific by `TODO_SEARCH`
grep --exclude-dir={.git,vendor,prototype} -r ${TODO_KEYWORDS} ${TODO_SEARCH}
.PHONY: todo_count
todo_count: ## Print a count of all the TODOs in the project
grep --exclude-dir={.git,vendor,prototype} -r ${TODO_KEYWORDS} . | wc -l
.PHONY: todo_this_commit
todo_this_commit: ## List all the TODOs needed to be done in this commit
grep --exclude-dir={.git,vendor,prototype,.vscode} --exclude=Makefile -r -e "TODO_IN_THIS_COMMIT" -e "DISCUSS_IN_THIS_COMMIT"
####################
### Gateways ###
####################
.PHONY: gateway_list
gateway_list: ## List all the staked gateways
pocketd --home=$(POCKETD_HOME) q gateway list-gateway --node $(POCKET_NODE)
.PHONY: gateway_stake
gateway_stake: ## Stake tokens for the gateway specified (must specify the gateway env var)
pocketd --home=$(POCKETD_HOME) tx gateway stake-gateway 1000upokt --keyring-backend test --from $(GATEWAY) --node $(POCKET_NODE)
.PHONY: gateway1_stake
gateway1_stake: ## Stake gateway1
GATEWAY=gateway1 make gateway_stake
.PHONY: gateway2_stake
gateway2_stake: ## Stake gateway2
GATEWAY=gateway2 make gateway_stake
.PHONY: gateway3_stake
gateway3_stake: ## Stake gateway3
GATEWAY=gateway3 make gateway_stake
.PHONY: gateway_unstake
gateway_unstake: ## Unstake an gateway (must specify the GATEWAY env var)
pocketd --home=$(POCKETD_HOME) tx gateway unstake-gateway --keyring-backend test --from $(GATEWAY) --node $(POCKET_NODE)
.PHONY: gateway1_unstake
gateway1_unstake: ## Unstake gateway1
GATEWAY=gateway1 make gateway_unstake
.PHONY: gateway2_unstake
gateway2_unstake: ## Unstake gateway2
GATEWAY=gateway2 make gateway_unstake
.PHONY: gateway3_unstake
gateway3_unstake: ## Unstake gateway3
GATEWAY=gateway3 make gateway_unstake
####################
### Applications ###
####################
.PHONY: app_list
app_list: ## List all the staked applications
pocketd --home=$(POCKETD_HOME) q application list-application --node $(POCKET_NODE)
.PHONY: app_stake
app_stake: ## Stake tokens for the application specified (must specify the APP and SERVICES env vars)
pocketd --home=$(POCKETD_HOME) tx application stake-application 1000upokt $(SERVICES) --keyring-backend test --from $(APP) --node $(POCKET_NODE)
.PHONY: app1_stake
app1_stake: ## Stake app1
APP=app1 SERVICES=anvil,svc1,svc2 make app_stake
.PHONY: app2_stake
app2_stake: ## Stake app2
APP=app2 SERVICES=anvil,svc2,svc3 make app_stake
.PHONY: app3_stake
app3_stake: ## Stake app3
APP=app3 SERVICES=anvil,svc3,svc4 make app_stake
.PHONY: app_unstake
app_unstake: ## Unstake an application (must specify the APP env var)
pocketd --home=$(POCKETD_HOME) tx application unstake-application --keyring-backend test --from $(APP) --node $(POCKET_NODE)
.PHONY: app1_unstake
app1_unstake: ## Unstake app1
APP=app1 make app_unstake
.PHONY: app2_unstake
app2_unstake: ## Unstake app2
APP=app2 make app_unstake
.PHONY: app3_unstake
app3_unstake: ## Unstake app3
APP=app3 make app_unstake
.PHONY: app_delegate
app_delegate: ## Delegate trust to a gateway (must specify the APP and GATEWAY_ADDR env vars). Requires the app to be staked
pocketd --home=$(POCKETD_HOME) tx application delegate-to-gateway $(GATEWAY_ADDR) --keyring-backend test --from $(APP) --node $(POCKET_NODE)
.PHONY: app1_delegate_gateway1
app1_delegate_gateway1: ## Delegate trust to gateway1
APP=app1 GATEWAY_ADDR=pokt15vzxjqklzjtlz7lahe8z2dfe9nm5vxwwmscne4 make app_delegate
.PHONY: app2_delegate_gateway2
app2_delegate_gateway2: ## Delegate trust to gateway2
APP=app2 GATEWAY_ADDR=pokt15w3fhfyc0lttv7r585e2ncpf6t2kl9uh8rsnyz make app_delegate
.PHONY: app3_delegate_gateway3
app3_delegate_gateway3: ## Delegate trust to gateway3
APP=app3 GATEWAY_ADDR=pokt1zhmkkd0rh788mc9prfq0m2h88t9ge0j83gnxya make app_delegate
.PHONY: app_undelegate
app_undelegate: ## Undelegate trust to a gateway (must specify the APP and GATEWAY_ADDR env vars). Requires the app to be staked
pocketd --home=$(POCKETD_HOME) tx application undelegate-from-gateway $(GATEWAY_ADDR) --keyring-backend test --from $(APP) --node $(POCKET_NODE)
.PHONY: app1_undelegate_gateway1
app1_undelegate_gateway1: ## Undelegate trust to gateway1
APP=app1 GATEWAY_ADDR=pokt15vzxjqklzjtlz7lahe8z2dfe9nm5vxwwmscne4 make app_undelegate
.PHONY: app2_undelegate_gateway2
app2_undelegate_gateway2: ## Undelegate trust to gateway2
APP=app2 GATEWAY_ADDR=pokt15w3fhfyc0lttv7r585e2ncpf6t2kl9uh8rsnyz make app_undelegate
.PHONY: app3_undelegate_gateway3
app3_undelegate_gateway3: ## Undelegate trust to gateway3
APP=app3 GATEWAY_ADDR=pokt1zhmkkd0rh788mc9prfq0m2h88t9ge0j83gnxya make app_undelegate
#################
### Suppliers ###
#################
.PHONY: supplier_list
supplier_list: ## List all the staked supplier
pocketd --home=$(POCKETD_HOME) q supplier list-supplier --node $(POCKET_NODE)
# TODO(@Olshansk, @okdas): Add more services (in addition to anvil) for apps and suppliers to stake for.
# TODO_TECHDEBT: svc1, svc2 and svc3 below are only in place to make GetSession testable
.PHONY: supplier_stake
supplier_stake: ## Stake tokens for the supplier specified (must specify the APP env var)
pocketd --home=$(POCKETD_HOME) tx supplier stake-supplier 1000upokt "$(SERVICES)" --keyring-backend test --from $(SUPPLIER) --node $(POCKET_NODE)
.PHONY: supplier1_stake
supplier1_stake: ## Stake supplier1
SUPPLIER=supplier1 SERVICES="anvil;http://anvil:8547,svc1;http://localhost:8081" make supplier_stake
.PHONY: supplier2_stake
supplier2_stake: ## Stake supplier2
SUPPLIER=supplier2 SERVICES="anvil;http://anvil:8547,svc2;http://localhost:8082" make supplier_stake
.PHONY: supplier3_stake
supplier3_stake: ## Stake supplier3
SUPPLIER=supplier3 SERVICES="anvil;http://anvil:8547,svc3;http://localhost:8083" make supplier_stake
.PHONY: supplier_unstake
supplier_unstake: ## Unstake an supplier (must specify the SUPPLIER env var)
pocketd --home=$(POCKETD_HOME) tx supplier unstake-supplier --keyring-backend test --from $(SUPPLIER) --node $(POCKET_NODE)
.PHONY: supplier1_unstake
supplier1_unstake: ## Unstake supplier1
SUPPLIER=supplier1 make supplier_unstake
.PHONY: supplier2_unstake
supplier2_unstake: ## Unstake supplier2
SUPPLIER=supplier2 make supplier_unstake
.PHONY: supplier3_unstake
supplier3_unstake: ## Unstake supplier3
SUPPLIER=supplier3 make supplier_unstake
################
### Accounts ###
################
.PHONY: acc_balance_query
acc_balance_query: ## Query the balance of the account specified (make acc_balance_query ACC=pokt...)
@echo "~~~ Balances ~~~"
pocketd --home=$(POCKETD_HOME) q bank balances $(ACC) --node $(POCKET_NODE)
@echo "~~~ Spendable Balances ~~~"
@echo "Querying spendable balance for $(ACC)"
pocketd --home=$(POCKETD_HOME) q bank spendable-balances $(ACC) --node $(POCKET_NODE)
.PHONY: acc_balance_query_module_app
acc_balance_query_module_app: ## Query the balance of the network level "application" module
make acc_balance_query ACC=pokt1rl3gjgzexmplmds3tq3r3yk84zlwdl6djzgsvm
.PHONY: acc_balance_query_module_supplier
acc_balance_query_module_supplier: ## Query the balance of the network level "supplier" module
make acc_balance_query ACC=pokt1j40dzzmn6cn9kxku7a5tjnud6hv37vesr5ccaa
.PHONY: acc_balance_query_app1
acc_balance_query_app1: ## Query the balance of app1
make acc_balance_query ACC=pokt1mrqt5f7qh8uxs27cjm9t7v9e74a9vvdnq5jva4
.PHONY: acc_balance_total_supply
acc_balance_total_supply: ## Query the total supply of the network
pocketd --home=$(POCKETD_HOME) q bank total --node $(POCKET_NODE)
######################
### Ignite Helpers ###
######################
.PHONY: ignite_acc_list
ignite_acc_list: ## List all the accounts in LocalNet
ignite account list --keyring-dir=$(POCKETD_HOME) --keyring-backend test --address-prefix $(POCKET_ADDR_PREFIX)