Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tooling, Code Health] refactor: split Makefile into multiple files #816

Merged
merged 18 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
766 changes: 16 additions & 750 deletions Makefile

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions e2e/tests/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
prooftypes "github.com/pokt-network/poktroll/x/proof/types"
servicetypes "github.com/pokt-network/poktroll/x/service/types"
sessiontypes "github.com/pokt-network/poktroll/x/session/types"
shared "github.com/pokt-network/poktroll/x/shared"
"github.com/pokt-network/poktroll/x/shared"
sharedtypes "github.com/pokt-network/poktroll/x/shared/types"
suppliertypes "github.com/pokt-network/poktroll/x/supplier/types"
)
Expand Down Expand Up @@ -740,8 +740,8 @@ func (s *suite) getSupplierUnbondingHeight(accName string) int64 {
var resp sharedtypes.QueryParamsResponse
responseBz := []byte(strings.TrimSpace(res.Stdout))
s.cdc.MustUnmarshalJSON(responseBz, &resp)
unbondingHeight := shared.GetSupplierUnbondingHeight(&resp.Params, supplier)
return unbondingHeight

return shared.GetSupplierUnbondingHeight(&resp.Params, supplier)
}

// getApplicationInfo returns the application information for a given application address.
Expand Down
35 changes: 34 additions & 1 deletion e2e/tests/stake_supplier.feature
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Feature: Stake Supplier Namespace

Scenario: User can stake and unstake a Supplier waiting for it to unbound
Scenario: User can stake a Supplier
Given the user has the pocketd binary installed
And the user verifies the "supplier" for account "supplier2" is not staked
And the account "supplier2" has a balance greater than "1000070" uPOKT
Expand All @@ -14,6 +14,21 @@ Feature: Stake Supplier Namespace

Scenario: User can unstake a Supplier
Given the user has the pocketd binary installed
# Reduce the application unbonding period to avoid timeouts and speed up scenarios.
And an authz grant from the "gov" "module" account to the "pnf" "user" account for each module MsgUpdateParam message exists
# NB: If new parameters are added to the shared module, they
# MUST be included here; otherwise, this step will fail.
And the "pnf" account sends an authz exec message to update all "shared" module params
| name | value | type |
| num_blocks_per_session | 2 | int64 |
| grace_period_end_offset_blocks | 0 | int64 |
| claim_window_open_offset_blocks | 0 | int64 |
| claim_window_close_offset_blocks | 1 | int64 |
| proof_window_open_offset_blocks | 0 | int64 |
| proof_window_close_offset_blocks | 1 | int64 |
| supplier_unbonding_period_sessions | 1 | int64 |
| application_unbonding_period_sessions | 1 | int64 |
And all "shared" module params should be updated
And the "supplier" for account "supplier2" is staked with "1000070" uPOKT
And an account exists for "supplier2"
When the user unstakes a "supplier" from the account "supplier2"
Expand All @@ -27,10 +42,28 @@ Feature: Stake Supplier Namespace

Scenario: User can restake a Supplier waiting for it to become active again
Given the user has the pocketd binary installed
# Reduce the application unbonding period to avoid timeouts and speed up scenarios.
And an authz grant from the "gov" "module" account to the "pnf" "user" account for each module MsgUpdateParam message exists
# NB: If new parameters are added to the shared module, they
# MUST be included here; otherwise, this step will fail.
And the "pnf" account sends an authz exec message to update all "shared" module params
| name | value | type |
| num_blocks_per_session | 2 | int64 |
| grace_period_end_offset_blocks | 0 | int64 |
| claim_window_open_offset_blocks | 0 | int64 |
| claim_window_close_offset_blocks | 1 | int64 |
| proof_window_open_offset_blocks | 0 | int64 |
| proof_window_close_offset_blocks | 1 | int64 |
| supplier_unbonding_period_sessions | 1 | int64 |
| application_unbonding_period_sessions | 1 | int64 |
And all "shared" module params should be updated
And the user verifies the "supplier" for account "supplier2" is not staked
Then the user stakes a "supplier" with "1000070" uPOKT for "anvil" service from the account "supplier2"
And the user should wait for the "supplier" module "StakeSupplier" message to be submitted
Then the user should see that the supplier for account "supplier2" is staked
But the session for application "app1" and service "anvil" does not contain "supplier2"
When the user waits for supplier "supplier2" to become active for service "anvil"
Then the session for application "app1" and service "anvil" contains the supplier "supplier2"
# Cleanup to make this feature idempotent.
And the user unstakes a "supplier" from the account "supplier2"
And the user waits for the supplier for account "supplier2" unbonding period to finish
77 changes: 77 additions & 0 deletions makefiles/applications.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
####################
### Applications ###
####################

.PHONY: app_list
app_list: ## List all the staked applications
poktrolld --home=$(POKTROLLD_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)
poktrolld --home=$(POKTROLLD_HOME) tx application stake-application -y --config $(POKTROLLD_HOME)/config/$(SERVICES) --keyring-backend test --from $(APP) --node $(POCKET_NODE)

.PHONY: app1_stake
app1_stake: ## Stake app1 (also staked in genesis)
APP=app1 SERVICES=application1_stake_config.yaml make app_stake

.PHONY: app2_stake
app2_stake: ## Stake app2
APP=app2 SERVICES=application2_stake_config.yaml make app_stake

.PHONY: app3_stake
app3_stake: ## Stake app3
APP=app3 SERVICES=application3_stake_config.yaml make app_stake

.PHONY: app_unstake
app_unstake: ## Unstake an application (must specify the APP env var)
poktrolld --home=$(POKTROLLD_HOME) tx application unstake-application -y --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
poktrolld --home=$(POKTROLLD_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
GATEWAY1=$$(make poktrolld_addr ACC_NAME=gateway1) && \
APP=app1 GATEWAY_ADDR=$$GATEWAY1 make app_delegate

.PHONY: app2_delegate_gateway2
app2_delegate_gateway2: ## Delegate trust to gateway2
GATEWAY2=$$(make poktrolld_addr ACC_NAME=gateway2) && \
APP=app2 GATEWAY_ADDR=$$GATEWAY2 make app_delegate

.PHONY: app3_delegate_gateway3
app3_delegate_gateway3: ## Delegate trust to gateway3
GATEWAY3=$$(make poktrolld_addr ACC_NAME=gateway3) && \
APP=app3 GATEWAY_ADDR=$$GATEWAY3 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
poktrolld --home=$(POKTROLLD_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
GATEWAY1=$$(make poktrolld_addr ACC_NAME=gateway1) && \
APP=app1 GATEWAY_ADDR=$$GATEWAY1 make app_undelegate

.PHONY: app2_undelegate_gateway2
app2_undelegate_gateway2: ## Undelegate trust to gateway2
GATEWAY2=$$(make poktrolld_addr ACC_NAME=gateway2) && \
APP=app2 GATEWAY_ADDR=$$GATEWAY2 make app_undelegate

.PHONY: app3_undelegate_gateway3
app3_undelegate_gateway3: ## Undelegate trust to gateway3
GATEWAY3=$$(make poktrolld_addr ACC_NAME=gateway3) && \
APP=app3 GATEWAY_ADDR=$$GATEWAY3 make app_undelegate
160 changes: 160 additions & 0 deletions makefiles/checks.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
##############
### Checks ###
##############

# TODO_DOCUMENT: All of the `check_` helpers can be installed differently depending
# on the user's OS and environment.
# NB: For mac users, you may need to install with the proper linkers: https://github.com/golang/go/issues/65940

.PHONY: check_go_version
# Internal helper target - check go version
check_go_version:
@# 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" -le 20 ] ; then \
echo "Invalid Go version. Expected 1.21.x or newer but found $$GO_VERSION"; \
exit 1; \
fi

.PHONY: check_ignite_version
# Internal helper target - check ignite version
check_ignite_version:
@version=$$(ignite version 2>/dev/null | grep 'Ignite CLI version:' | awk '{print $$4}') ; \
if [ "$$(printf "v28\n$$version" | sort -V | head -n1)" != "v28" ]; then \
echo "Error: Version $$version is less than v28. Exiting with error." ; \
exit 1 ; \
fi

.PHONY: check_mockgen
# Internal helper target- Check if mockgen is installed
check_mockgen:
{ \
if ( ! ( command -v mockgen >/dev/null )); then \
echo "Seems like you don't have `mockgen` installed. Please visit https://github.com/golang/mock#installation and follow the instructions to install `mockgen` before continuing"; \
exit 1; \
fi; \
}


.PHONY: check_act
# Internal helper target - check if `act` is installed
check_act:
{ \
if ( ! ( command -v act >/dev/null )); then \
echo "Seems like you don't have `act` installed. Please visit https://github.com/nektos/act before continuing"; \
exit 1; \
fi; \
}

.PHONY: check_gh
# Internal helper target - check if `gh` is installed
check_gh:
{ \
if ( ! ( command -v gh >/dev/null )); then \
echo "Seems like you don't have `gh` installed. Please visit https://cli.github.com/ before continuing"; \
exit 1; \
fi; \
}

.PHONY: check_docker
# Internal helper target - check if docker is installed
check_docker:
{ \
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: check_kind
# Internal helper target - check if kind is installed
check_kind:
@if ! command -v kind >/dev/null 2>&1; then \
echo "kind is not installed. Make sure you review build/localnet/README.md and docs/development/README.md before continuing"; \
exit 1; \
fi

.PHONY: check_docker_ps
## Internal helper target - checks if Docker is running
check_docker_ps: check_docker
@echo "Checking if Docker is running..."
@docker ps > /dev/null 2>&1 || (echo "Docker is not running. Please start Docker and try again."; exit 1)

.PHONY: check_kind_context
## Internal helper target - checks if the kind-kind context exists and is set
check_kind_context: check_kind
@if ! kubectl config get-contexts | grep -q 'kind-kind'; then \
echo "kind-kind context does not exist. Please create it or switch to it."; \
exit 1; \
fi
@if ! kubectl config current-context | grep -q 'kind-kind'; then \
echo "kind-kind context is not currently set. Use 'kubectl config use-context kind-kind' to set it."; \
exit 1; \
fi


.PHONY: check_godoc
# Internal helper target - check if godoc is installed
check_godoc:
{ \
if ( ! ( command -v godoc >/dev/null )); then \
echo "Seems like you don't have godoc installed. Make sure you install it via 'go install golang.org/x/tools/cmd/godoc@latest' before continuing"; \
exit 1; \
fi; \
}

.PHONY: check_npm
# Internal helper target - check if npm is installed
check_npm:
{ \
if ( ! ( command -v npm >/dev/null )); then \
echo "Seems like you don't have npm installed. Make sure you install it before continuing"; \
exit 1; \
fi; \
}

.PHONY: check_jq
# Internal helper target - check if jq is installed
check_jq:
{ \
if ( ! ( command -v jq >/dev/null )); then \
echo "Seems like you don't have jq installed. Make sure you install it before continuing"; \
exit 1; \
fi; \
}

.PHONY: check_yq
# Internal helper target - check if `yq` is installed
check_yq:
{ \
if ( ! ( command -v yq >/dev/null )); then \
echo "Seems like you don't have `yq` installed. Make sure you install it before continuing"; \
exit 1; \
fi; \
}

.PHONY: check_node
# Internal helper target - check if node is installed
check_node:
{ \
if ( ! ( command -v node >/dev/null )); then \
echo "Seems like you don't have node installed. Make sure you install it before continuing"; \
exit 1; \
fi; \
}

.PHONY: check_proto_unstable_marshalers
check_proto_unstable_marshalers: ## Check that all protobuf files have the `stable_marshalers_all` option set to true.
go run ./tools/scripts/protocheck/cmd unstable

.PHONY: fix_proto_unstable_marshalers
fix_proto_unstable_marshalers: ## Ensure the `stable_marshaler_all` option is present on all protobuf files.
go run ./tools/scripts/protocheck/cmd unstable --fix
${MAKE} proto_regen


.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!"
bryanchriswhite marked this conversation as resolved.
Show resolved Hide resolved
38 changes: 38 additions & 0 deletions makefiles/claims.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
##############
### Claims ###
##############

# These encoded values were generated using the `encodeSessionHeader` helpers in `query_claim_test.go` as dummy values.
ENCODED_SESSION_HEADER = "eyJhcHBsaWNhdGlvbl9hZGRyZXNzIjoicG9rdDFleXJuNDUwa3JoZnpycmVyemd0djd2c3J4bDA5NDN0dXN4azRhayIsInNlcnZpY2UiOnsiaWQiOiJhbnZpbCIsIm5hbWUiOiIifSwic2Vzc2lvbl9zdGFydF9ibG9ja19oZWlnaHQiOiI1Iiwic2Vzc2lvbl9pZCI6InNlc3Npb25faWQxIiwic2Vzc2lvbl9lbmRfYmxvY2tfaGVpZ2h0IjoiOSJ9"
ENCODED_ROOT_HASH = "cm9vdF9oYXNo"
.PHONY: claim_create_dummy
claim_create_dummy: ## Create a dummy claim by supplier1
poktrolld --home=$(POKTROLLD_HOME) tx supplier create-claim \
$(ENCODED_SESSION_HEADER) \
$(ENCODED_ROOT_HASH) \
--from supplier1 --node $(POCKET_NODE)

.PHONY: claims_list
claim_list: ## List all the claims
poktrolld --home=$(POKTROLLD_HOME) q supplier list-claims --node $(POCKET_NODE)

.PHONY: claims_list_address
claim_list_address: ## List all the claims for a specific address (specified via ADDR variable)
poktrolld --home=$(POKTROLLD_HOME) q supplier list-claims --supplier-operator-address $(ADDR) --node $(POCKET_NODE)

.PHONY: claims_list_address_supplier1
claim_list_address_supplier1: ## List all the claims for supplier1
SUPPLIER1=$$(make poktrolld_addr ACC_NAME=supplier1) && \
ADDR=$$SUPPLIER1 make claim_list_address

.PHONY: claim_list_height
claim_list_height: ## List all the claims ending at a specific height (specified via HEIGHT variable)
poktrolld --home=$(POKTROLLD_HOME) q supplier list-claims --session-end-height $(HEIGHT) --node $(POCKET_NODE)

.PHONY: claim_list_height_5
claim_list_height_5: ## List all the claims at height 5
HEIGHT=5 make claim_list_height

.PHONY: claim_list_session
claim_list_session: ## List all the claims ending at a specific session (specified via SESSION variable)
poktrolld --home=$(POKTROLLD_HOME) q supplier list-claims --session-id $(SESSION) --node $(POCKET_NODE)
39 changes: 39 additions & 0 deletions makefiles/gateways.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
####################
### Gateways ###
####################

.PHONY: gateway_list
gateway_list: ## List all the staked gateways
poktrolld --home=$(POKTROLLD_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)
poktrolld --home=$(POKTROLLD_HOME) tx gateway stake-gateway -y --config $(POKTROLLD_HOME)/config/$(STAKE) --keyring-backend test --from $(GATEWAY) --node $(POCKET_NODE)

.PHONY: gateway1_stake
gateway1_stake: ## Stake gateway1
GATEWAY=gateway1 STAKE=gateway1_stake_config.yaml make gateway_stake

.PHONY: gateway2_stake
gateway2_stake: ## Stake gateway2
GATEWAY=gateway2 STAKE=gateway2_stake_config.yaml make gateway_stake

.PHONY: gateway3_stake
gateway3_stake: ## Stake gateway3
GATEWAY=gateway3 STAKE=gateway3_stake_config.yaml make gateway_stake

.PHONY: gateway_unstake
gateway_unstake: ## Unstake an gateway (must specify the GATEWAY env var)
poktrolld --home=$(POKTROLLD_HOME) tx gateway unstake-gateway -y --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
Loading
Loading