diff --git a/Makefile b/Makefile index a4f805d5c..a17c4fc84 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,9 @@ .SILENT: -POKTROLLD_HOME := ./localnet/poktrolld -POCKET_NODE = tcp://127.0.0.1:36657 # The pocket rollup node (full node and sequencer in the localnet context) -APPGATE_SERVER = http://localhost:42069 +SHELL = /bin/sh +POKTROLLD_HOME ?= ./localnet/poktrolld +POCKET_NODE ?= tcp://127.0.0.1:36657 # The pocket rollup node (full node and sequencer in the localnet context) +APPGATE_SERVER ?= http://localhost:42069 POCKET_ADDR_PREFIX = pokt #################### @@ -166,7 +167,7 @@ localnet_down: ## Delete resources created by localnet tilt down .PHONY: localnet_regenesis -localnet_regenesis: ## Regenerate the localnet genesis file +localnet_regenesis: acc_initialize_pubkeys_warn_message ## Regenerate the localnet genesis file # NOTE: intentionally not using --home flag to avoid overwriting the test keyring # NB: Currently the stake => power calculation is constant; however, cosmos-sdk # intends to make this parameterizable in the future. @@ -207,7 +208,7 @@ go_imports: check_go_version ## Run goimports on all go files ############# .PHONY: test_e2e -test_e2e: ## Run all E2E tests +test_e2e: acc_initialize_pubkeys_warn_message ## Run all E2E tests export POCKET_NODE=$(POCKET_NODE) && \ export APPGATE_SERVER=$(APPGATE_SERVER) && \ POKTROLLD_HOME=../../$(POKTROLLD_HOME) && \ @@ -369,7 +370,6 @@ app_list: ## List all the staked applications app_stake: ## Stake tokens for the application specified (must specify the APP and SERVICES env vars) poktrolld --home=$(POKTROLLD_HOME) tx application stake-application --config $(POKTROLLD_HOME)/config/$(SERVICES) --keyring-backend test --from $(APP) --node $(POCKET_NODE) -# TODO_IMPROVE(#180): Make sure genesis-staked actors are available via AccountKeeper .PHONY: app1_stake app1_stake: ## Stake app1 (also staked in genesis) APP=app1 SERVICES=application1_stake_config.yaml make app_stake @@ -529,6 +529,32 @@ acc_balance_query_app1: ## Query the balance of app1 acc_balance_total_supply: ## Query the total supply of the network poktrolld --home=$(POKTROLLD_HOME) q bank total --node $(POCKET_NODE) +# NB: Ignite does not populate `pub_key` in `accounts` within `genesis.json` leading +# to queries like this to fail: `poktrolld query account pokt1 --node $(POCKET_NODE). +# We attempted using a `tx multi-send` from the `faucet` to all accounts, but +# that also did not solve this problem because the account itself must sign the +# transaction for its public key to be populated in the account keeper. As such, +# the solution is to send funds from every account in genesis to some address +# (PNF was selected ambigously) to make sure their public keys are populated. + +.PHONY: acc_initialize_pubkeys +acc_initialize_pubkeys: ## Make sure the account keeper has public keys for all available accounts + $(eval ADDRESSES=$(shell make -s ignite_acc_list | grep pokt | awk '{printf "%s ", $$2}' | sed 's/.$$//')) + $(eval PNF_ADDR=pokt1eeeksh2tvkh7wzmfrljnhw4wrhs55lcuvmekkw) + # @printf "Addresses: ${ADDRESSES}" + $(foreach addr, $(ADDRESSES),\ + echo $(addr);\ + poktrolld tx bank send \ + $(addr) $(PNF_ADDR) 1000upokt \ + --yes \ + --home=$(POKTROLLD_HOME) \ + --node $(POCKET_NODE);) + +.PHONY: acc_initialize_pubkeys_warn_message +acc_initialize_pubkeys_warn_message: ## Print a warning message about the need to run `make acc_initialize_pubkeys` + @printf "!!! YOU MUST RUN THE FOLLOWING COMMAND ONCE FOR E2E TESTS TO WORK AFTER THE NETWORK HAS STARTED!!!\n"\ + "\t\tmake acc_initialize_pubkeys\n" + ############## ### Claims ### ############## @@ -656,4 +682,4 @@ act_list: check_act ## List all github actions that can be executed locally with act_reviewdog: check_act check_gh ## Run the reviewdog workflow locally like so: `GITHUB_TOKEN=$(gh auth token) make act_reviewdog` $(eval CONTAINER_ARCH := $(shell make -s detect_arch)) @echo "Detected architecture: $(CONTAINER_ARCH)" - act -v -s GITHUB_TOKEN=$(GITHUB_TOKEN) -W .github/workflows/reviewdog.yml --container-architecture $(CONTAINER_ARCH) + act -v -s GITHUB_TOKEN=$(GITHUB_TOKEN) -W .github/workflows/reviewdog.yml --container-architecture $(CONTAINER_ARCH) \ No newline at end of file diff --git a/api/poktroll/gateway/gateway.pulsar.go b/api/poktroll/gateway/gateway.pulsar.go index edcafe393..76b5d7dff 100644 --- a/api/poktroll/gateway/gateway.pulsar.go +++ b/api/poktroll/gateway/gateway.pulsar.go @@ -532,8 +532,8 @@ type Gateway struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` - Stake *v1beta1.Coin `protobuf:"bytes,2,opt,name=stake,proto3" json:"stake,omitempty"` + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` // The Bech32 address of the gateway + Stake *v1beta1.Coin `protobuf:"bytes,2,opt,name=stake,proto3" json:"stake,omitempty"` // The total amount of uPOKT the gateway has staked } func (x *Gateway) Reset() { diff --git a/api/poktroll/gateway/query.pulsar.go b/api/poktroll/gateway/query.pulsar.go index dce0a107e..f7318f7e2 100644 --- a/api/poktroll/gateway/query.pulsar.go +++ b/api/poktroll/gateway/query.pulsar.go @@ -2924,72 +2924,71 @@ var file_poktroll_gateway_query_proto_rawDesc = []byte{ 0x72, 0x61, 0x6d, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x42, 0x09, 0xc8, 0xde, 0x1f, 0x00, 0xa8, 0xe7, 0xb0, 0x2a, 0x01, 0x52, - 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x22, 0x4c, 0x0a, 0x16, 0x51, 0x75, 0x65, 0x72, 0x79, + 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x22, 0x32, 0x0a, 0x16, 0x51, 0x75, 0x65, 0x72, 0x79, 0x47, 0x65, 0x74, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x12, 0x32, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x42, 0x18, 0xd2, 0xb4, 0x2d, 0x14, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x41, - 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x52, 0x07, 0x61, 0x64, - 0x64, 0x72, 0x65, 0x73, 0x73, 0x22, 0x54, 0x0a, 0x17, 0x51, 0x75, 0x65, 0x72, 0x79, 0x47, 0x65, - 0x74, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x12, 0x39, 0x0a, 0x07, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x0b, 0x32, 0x19, 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x67, 0x61, 0x74, - 0x65, 0x77, 0x61, 0x79, 0x2e, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x42, 0x04, 0xc8, 0xde, - 0x1f, 0x00, 0x52, 0x07, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x22, 0x60, 0x0a, 0x16, 0x51, - 0x75, 0x65, 0x72, 0x79, 0x41, 0x6c, 0x6c, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x46, 0x0a, 0x0a, 0x70, 0x61, 0x67, 0x69, 0x6e, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x26, 0x2e, 0x63, 0x6f, 0x73, 0x6d, - 0x6f, 0x73, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x71, 0x75, 0x65, 0x72, 0x79, 0x2e, 0x76, 0x31, - 0x62, 0x65, 0x74, 0x61, 0x31, 0x2e, 0x50, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x52, 0x0a, 0x70, 0x61, 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x9d, 0x01, - 0x0a, 0x17, 0x51, 0x75, 0x65, 0x72, 0x79, 0x41, 0x6c, 0x6c, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, - 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x39, 0x0a, 0x07, 0x67, 0x61, 0x74, - 0x65, 0x77, 0x61, 0x79, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x70, 0x6f, 0x6b, - 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x47, 0x61, - 0x74, 0x65, 0x77, 0x61, 0x79, 0x42, 0x04, 0xc8, 0xde, 0x1f, 0x00, 0x52, 0x07, 0x67, 0x61, 0x74, - 0x65, 0x77, 0x61, 0x79, 0x12, 0x47, 0x0a, 0x0a, 0x70, 0x61, 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, - 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x27, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, - 0x73, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x71, 0x75, 0x65, 0x72, 0x79, 0x2e, 0x76, 0x31, 0x62, - 0x65, 0x74, 0x61, 0x31, 0x2e, 0x50, 0x61, 0x67, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x52, 0x0a, 0x70, 0x61, 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x32, 0xbd, 0x03, - 0x0a, 0x05, 0x51, 0x75, 0x65, 0x72, 0x79, 0x12, 0x84, 0x01, 0x0a, 0x06, 0x50, 0x61, 0x72, 0x61, - 0x6d, 0x73, 0x12, 0x24, 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x67, 0x61, - 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x50, 0x61, 0x72, 0x61, 0x6d, - 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x25, 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, + 0x74, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x22, 0x54, 0x0a, 0x17, 0x51, + 0x75, 0x65, 0x72, 0x79, 0x47, 0x65, 0x74, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x39, 0x0a, 0x07, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, + 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, + 0x6c, 0x6c, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x47, 0x61, 0x74, 0x65, 0x77, + 0x61, 0x79, 0x42, 0x04, 0xc8, 0xde, 0x1f, 0x00, 0x52, 0x07, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, + 0x79, 0x22, 0x60, 0x0a, 0x16, 0x51, 0x75, 0x65, 0x72, 0x79, 0x41, 0x6c, 0x6c, 0x47, 0x61, 0x74, + 0x65, 0x77, 0x61, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x46, 0x0a, 0x0a, 0x70, + 0x61, 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x26, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x71, 0x75, + 0x65, 0x72, 0x79, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2e, 0x50, 0x61, 0x67, 0x65, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x52, 0x0a, 0x70, 0x61, 0x67, 0x69, 0x6e, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x22, 0x9d, 0x01, 0x0a, 0x17, 0x51, 0x75, 0x65, 0x72, 0x79, 0x41, 0x6c, 0x6c, + 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, + 0x39, 0x0a, 0x07, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, + 0x32, 0x19, 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x67, 0x61, 0x74, 0x65, + 0x77, 0x61, 0x79, 0x2e, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x42, 0x04, 0xc8, 0xde, 0x1f, + 0x00, 0x52, 0x07, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x12, 0x47, 0x0a, 0x0a, 0x70, 0x61, + 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x27, + 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x71, 0x75, 0x65, + 0x72, 0x79, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2e, 0x50, 0x61, 0x67, 0x65, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x52, 0x0a, 0x70, 0x61, 0x67, 0x69, 0x6e, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x32, 0xbd, 0x03, 0x0a, 0x05, 0x51, 0x75, 0x65, 0x72, 0x79, 0x12, 0x84, 0x01, + 0x0a, 0x06, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x24, 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x51, 0x75, 0x65, 0x72, - 0x79, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, - 0x2d, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x27, 0x12, 0x25, 0x2f, 0x70, 0x6f, 0x6b, 0x74, 0x2d, 0x6e, - 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2f, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, - 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x98, - 0x01, 0x0a, 0x07, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x12, 0x28, 0x2e, 0x70, 0x6f, 0x6b, + 0x79, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x25, + 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, + 0x79, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x2d, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x27, 0x12, 0x25, 0x2f, + 0x70, 0x6f, 0x6b, 0x74, 0x2d, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2f, 0x70, 0x6f, 0x6b, + 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2f, 0x70, 0x61, + 0x72, 0x61, 0x6d, 0x73, 0x12, 0x98, 0x01, 0x0a, 0x07, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, + 0x12, 0x28, 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x67, 0x61, 0x74, 0x65, + 0x77, 0x61, 0x79, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x47, 0x65, 0x74, 0x47, 0x61, 0x74, 0x65, + 0x77, 0x61, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x29, 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x51, 0x75, - 0x65, 0x72, 0x79, 0x47, 0x65, 0x74, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x29, 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, - 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x47, 0x65, 0x74, - 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, - 0x38, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x32, 0x12, 0x30, 0x2f, 0x70, 0x6f, 0x6b, 0x74, 0x2d, 0x6e, - 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2f, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, - 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2f, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2f, - 0x7b, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x7d, 0x12, 0x91, 0x01, 0x0a, 0x0a, 0x47, 0x61, - 0x74, 0x65, 0x77, 0x61, 0x79, 0x41, 0x6c, 0x6c, 0x12, 0x28, 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, + 0x65, 0x72, 0x79, 0x47, 0x65, 0x74, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x38, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x32, 0x12, 0x30, 0x2f, + 0x70, 0x6f, 0x6b, 0x74, 0x2d, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2f, 0x70, 0x6f, 0x6b, + 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2f, 0x67, 0x61, + 0x74, 0x65, 0x77, 0x61, 0x79, 0x2f, 0x7b, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x7d, 0x12, + 0x91, 0x01, 0x0a, 0x0a, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x41, 0x6c, 0x6c, 0x12, 0x28, + 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, + 0x79, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x41, 0x6c, 0x6c, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, + 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x29, 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x51, 0x75, 0x65, 0x72, - 0x79, 0x41, 0x6c, 0x6c, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x1a, 0x29, 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x67, 0x61, - 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x41, 0x6c, 0x6c, 0x47, 0x61, - 0x74, 0x65, 0x77, 0x61, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x2e, 0x82, - 0xd3, 0xe4, 0x93, 0x02, 0x28, 0x12, 0x26, 0x2f, 0x70, 0x6f, 0x6b, 0x74, 0x2d, 0x6e, 0x65, 0x74, - 0x77, 0x6f, 0x72, 0x6b, 0x2f, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x67, 0x61, - 0x74, 0x65, 0x77, 0x61, 0x79, 0x2f, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x42, 0xa6, 0x01, - 0x0a, 0x14, 0x63, 0x6f, 0x6d, 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x67, - 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x42, 0x0a, 0x51, 0x75, 0x65, 0x72, 0x79, 0x50, 0x72, 0x6f, - 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x21, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, - 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, - 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0xa2, 0x02, 0x03, 0x50, 0x47, 0x58, 0xaa, 0x02, 0x10, - 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, - 0xca, 0x02, 0x10, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x5c, 0x47, 0x61, 0x74, 0x65, - 0x77, 0x61, 0x79, 0xe2, 0x02, 0x1c, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x5c, 0x47, - 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, - 0x74, 0x61, 0xea, 0x02, 0x11, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x3a, 0x3a, 0x47, - 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x79, 0x41, 0x6c, 0x6c, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x22, 0x2e, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x28, 0x12, 0x26, 0x2f, 0x70, 0x6f, + 0x6b, 0x74, 0x2d, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2f, 0x70, 0x6f, 0x6b, 0x74, 0x72, + 0x6f, 0x6c, 0x6c, 0x2f, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2f, 0x67, 0x61, 0x74, 0x65, + 0x77, 0x61, 0x79, 0x42, 0xa6, 0x01, 0x0a, 0x14, 0x63, 0x6f, 0x6d, 0x2e, 0x70, 0x6f, 0x6b, 0x74, + 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x42, 0x0a, 0x51, 0x75, + 0x65, 0x72, 0x79, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x21, 0x63, 0x6f, 0x73, 0x6d, + 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x70, 0x6f, 0x6b, + 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0xa2, 0x02, 0x03, + 0x50, 0x47, 0x58, 0xaa, 0x02, 0x10, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x47, + 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0xca, 0x02, 0x10, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, + 0x6c, 0x5c, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0xe2, 0x02, 0x1c, 0x50, 0x6f, 0x6b, 0x74, + 0x72, 0x6f, 0x6c, 0x6c, 0x5c, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x5c, 0x47, 0x50, 0x42, + 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x11, 0x50, 0x6f, 0x6b, 0x74, 0x72, + 0x6f, 0x6c, 0x6c, 0x3a, 0x3a, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x62, 0x06, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/go.mod b/go.mod index 6b79eacf7..b545e2745 100644 --- a/go.mod +++ b/go.mod @@ -327,9 +327,7 @@ require ( google.golang.org/api v0.153.0 // indirect google.golang.org/appengine v1.6.8 // indirect google.golang.org/genproto v0.0.0-20240102182953-50ed04b92917 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20240116215550-a9fa1716bcac // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240116215550-a9fa1716bcac // indirect - google.golang.org/grpc v1.60.1 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect gotest.tools/v3 v3.5.1 // indirect diff --git a/proto/poktroll/gateway/gateway.proto b/proto/poktroll/gateway/gateway.proto index 030ae58b9..ff6798ba7 100644 --- a/proto/poktroll/gateway/gateway.proto +++ b/proto/poktroll/gateway/gateway.proto @@ -7,7 +7,7 @@ import "gogoproto/gogo.proto"; import "cosmos/base/v1beta1/coin.proto"; message Gateway { - string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; - cosmos.base.v1beta1.Coin stake = 2; + string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the gateway + cosmos.base.v1beta1.Coin stake = 2; // The total amount of uPOKT the gateway has staked } diff --git a/proto/poktroll/gateway/params.proto b/proto/poktroll/gateway/params.proto index 9a4c44b81..bb7a65110 100644 --- a/proto/poktroll/gateway/params.proto +++ b/proto/poktroll/gateway/params.proto @@ -11,5 +11,4 @@ message Params { option (amino.name) = "poktroll/x/gateway/Params"; option (gogoproto.equal) = true; - } \ No newline at end of file diff --git a/proto/poktroll/gateway/query.proto b/proto/poktroll/gateway/query.proto index 0cf6d43a2..6e000cf4f 100644 --- a/proto/poktroll/gateway/query.proto +++ b/proto/poktroll/gateway/query.proto @@ -43,7 +43,7 @@ message QueryParamsResponse { } message QueryGetGatewayRequest { - string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + string address = 1; } message QueryGetGatewayResponse { diff --git a/x/gateway/keeper/msg_server_stake_gateway.go b/x/gateway/keeper/msg_server_stake_gateway.go index daf956530..1a08d0049 100644 --- a/x/gateway/keeper/msg_server_stake_gateway.go +++ b/x/gateway/keeper/msg_server_stake_gateway.go @@ -4,12 +4,16 @@ import ( "context" "fmt" + sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/pokt-network/poktroll/x/gateway/types" ) -func (k msgServer) StakeGateway(goCtx context.Context, msg *types.MsgStakeGateway) (*types.MsgStakeGatewayResponse, error) { +func (k msgServer) StakeGateway( + goCtx context.Context, + msg *types.MsgStakeGateway, +) (*types.MsgStakeGatewayResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) logger := k.Logger().With("method", "StakeGateway") @@ -74,13 +78,13 @@ func (k msgServer) updateGateway( ) error { // Checks if the the msg address is the same as the current owner if msg.Address != gateway.Address { - return types.ErrGatewayUnauthorized.Wrapf("msg Address (%s) != gateway address (%s)", msg.Address, gateway.Address) + return sdkerrors.Wrapf(types.ErrGatewayUnauthorized, "msg Address (%s) != gateway address (%s)", msg.Address, gateway.Address) } - if msg.Stake.IsZero() { - return types.ErrGatewayInvalidStake.Wrap("stake amount cannot be 0") + if msg.Stake == nil { + return sdkerrors.Wrapf(types.ErrGatewayInvalidStake, "stake amount cannot be nil") } if msg.Stake.IsLTE(*gateway.Stake) { - return types.ErrGatewayInvalidStake.Wrapf("stake amount %v must be higher than previous stake amount %v", msg.Stake, gateway.Stake) + return sdkerrors.Wrapf(types.ErrGatewayInvalidStake, "stake amount %v must be higher than previous stake amount %v", msg.Stake, gateway.Stake) } gateway.Stake = msg.Stake return nil diff --git a/x/gateway/keeper/msg_server_stake_gateway_test.go b/x/gateway/keeper/msg_server_stake_gateway_test.go index 9645c1a0a..113304ee9 100644 --- a/x/gateway/keeper/msg_server_stake_gateway_test.go +++ b/x/gateway/keeper/msg_server_stake_gateway_test.go @@ -3,7 +3,7 @@ package keeper_test import ( "testing" - "cosmossdk.io/math" + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" @@ -25,7 +25,7 @@ func TestMsgServer_StakeGateway_SuccessfulCreateAndUpdate(t *testing.T) { require.False(t, isGatewayFound) // Prepare the gateway - initialStake := sdk.NewCoin("upokt", math.NewInt(100)) + initialStake := sdk.NewCoin("upokt", sdkmath.NewInt(100)) stakeMsg := &types.MsgStakeGateway{ Address: addr, Stake: &initialStake, @@ -42,7 +42,7 @@ func TestMsgServer_StakeGateway_SuccessfulCreateAndUpdate(t *testing.T) { require.Equal(t, initialStake.Amount, foundGateway.Stake.Amount) // Prepare an updated gateway with a higher stake - updatedStake := sdk.NewCoin("upokt", math.NewInt(200)) + updatedStake := sdk.NewCoin("upokt", sdkmath.NewInt(200)) updateMsg := &types.MsgStakeGateway{ Address: addr, Stake: &updatedStake, @@ -62,7 +62,7 @@ func TestMsgServer_StakeGateway_FailLoweringStake(t *testing.T) { // Prepare the gateway addr := sample.AccAddress() - initialStake := sdk.NewCoin("upokt", math.NewInt(100)) + initialStake := sdk.NewCoin("upokt", sdkmath.NewInt(100)) stakeMsg := &types.MsgStakeGateway{ Address: addr, Stake: &initialStake, @@ -75,7 +75,7 @@ func TestMsgServer_StakeGateway_FailLoweringStake(t *testing.T) { require.True(t, isGatewayFound) // Prepare an updated gateway with a lower stake - updatedStake := sdk.NewCoin("upokt", math.NewInt(50)) + updatedStake := sdk.NewCoin("upokt", sdkmath.NewInt(50)) updateMsg := &types.MsgStakeGateway{ Address: addr, Stake: &updatedStake, diff --git a/x/gateway/keeper/msg_server_unstake_gateway.go b/x/gateway/keeper/msg_server_unstake_gateway.go index ebf919477..302c388f2 100644 --- a/x/gateway/keeper/msg_server_unstake_gateway.go +++ b/x/gateway/keeper/msg_server_unstake_gateway.go @@ -5,10 +5,16 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/pokt-network/poktroll/x/gateway/types" ) -func (k msgServer) UnstakeGateway(goCtx context.Context, msg *types.MsgUnstakeGateway) (*types.MsgUnstakeGatewayResponse, error) { +// TODO_TECHDEBT(#49): Add un-delegation from delegated apps +// TODO(#73): Determine if a gateway needs an unbonding period after unstaking. +func (k msgServer) UnstakeGateway( + goCtx context.Context, + msg *types.MsgUnstakeGateway, +) (*types.MsgUnstakeGatewayResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) logger := k.Logger().With("method", "UnstakeGateway") @@ -44,6 +50,5 @@ func (k msgServer) UnstakeGateway(goCtx context.Context, msg *types.MsgUnstakeGa // Update the Gateway in the store k.RemoveGateway(ctx, gatewayAddress.String()) logger.Info(fmt.Sprintf("Successfully removed the gateway: %+v", gateway)) - return &types.MsgUnstakeGatewayResponse{}, nil } diff --git a/x/gateway/keeper/msg_server_unstake_gateway_test.go b/x/gateway/keeper/msg_server_unstake_gateway_test.go index 4c977ef3c..8f1dcf351 100644 --- a/x/gateway/keeper/msg_server_unstake_gateway_test.go +++ b/x/gateway/keeper/msg_server_unstake_gateway_test.go @@ -3,7 +3,7 @@ package keeper_test import ( "testing" - "cosmossdk.io/math" + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" @@ -25,7 +25,7 @@ func TestMsgServer_UnstakeGateway_Success(t *testing.T) { require.False(t, isGatewayFound) // Prepare the gateway - initialStake := sdk.NewCoin("upokt", math.NewInt(100)) + initialStake := sdk.NewCoin("upokt", sdkmath.NewInt(100)) stakeMsg := &types.MsgStakeGateway{ Address: addr, Stake: &initialStake, diff --git a/x/gateway/keeper/params_test.go b/x/gateway/keeper/params_test.go index 7d4c17132..27bf9d53d 100644 --- a/x/gateway/keeper/params_test.go +++ b/x/gateway/keeper/params_test.go @@ -5,12 +5,12 @@ import ( "github.com/stretchr/testify/require" - keepertest "github.com/pokt-network/poktroll/testutil/keeper" + testkeeper "github.com/pokt-network/poktroll/testutil/keeper" "github.com/pokt-network/poktroll/x/gateway/types" ) func TestGetParams(t *testing.T) { - k, ctx := keepertest.GatewayKeeper(t) + k, ctx := testkeeper.GatewayKeeper(t) params := types.DefaultParams() require.NoError(t, k.SetParams(ctx, params)) diff --git a/x/gateway/keeper/query_gateway.go b/x/gateway/keeper/query_gateway.go index 284fbe0fe..06712114c 100644 --- a/x/gateway/keeper/query_gateway.go +++ b/x/gateway/keeper/query_gateway.go @@ -7,9 +7,10 @@ import ( "cosmossdk.io/store/prefix" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/types/query" - "github.com/pokt-network/poktroll/x/gateway/types" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + + "github.com/pokt-network/poktroll/x/gateway/types" ) func (k Keeper) GatewayAll(ctx context.Context, req *types.QueryAllGatewayRequest) (*types.QueryAllGatewayResponse, error) { @@ -50,8 +51,6 @@ func (k Keeper) Gateway(ctx context.Context, req *types.QueryGetGatewayRequest) ) if !found { return nil, status.Error(codes.NotFound, fmt.Sprintf("gateway not found: address %s", req.Address)) - } - return &types.QueryGetGatewayResponse{Gateway: val}, nil } diff --git a/x/gateway/keeper/query_params_test.go b/x/gateway/keeper/query_params_test.go index c24ed298a..cca74a59b 100644 --- a/x/gateway/keeper/query_params_test.go +++ b/x/gateway/keeper/query_params_test.go @@ -5,12 +5,12 @@ import ( "github.com/stretchr/testify/require" - keepertest "github.com/pokt-network/poktroll/testutil/keeper" + testkeeper "github.com/pokt-network/poktroll/testutil/keeper" "github.com/pokt-network/poktroll/x/gateway/types" ) func TestParamsQuery(t *testing.T) { - keeper, ctx := keepertest.GatewayKeeper(t) + keeper, ctx := testkeeper.GatewayKeeper(t) params := types.DefaultParams() require.NoError(t, keeper.SetParams(ctx, params)) diff --git a/x/gateway/simulation/stake_gateway.go b/x/gateway/simulation/stake_gateway.go index ebffa84a5..ea7474891 100644 --- a/x/gateway/simulation/stake_gateway.go +++ b/x/gateway/simulation/stake_gateway.go @@ -18,12 +18,12 @@ func SimulateMsgStakeGateway( return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { simAccount, _ := simtypes.RandomAcc(r, accs) - msg := &types.MsgStakeGateway{ + stakeMsg := &types.MsgStakeGateway{ Address: simAccount.Address.String(), } // TODO: Handling the StakeGateway simulation - return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "StakeGateway simulation not implemented"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(stakeMsg), "StakeGateway simulation not implemented"), nil, nil } } diff --git a/x/gateway/types/genesis.go b/x/gateway/types/genesis.go index e06a6c5cb..5cb161252 100644 --- a/x/gateway/types/genesis.go +++ b/x/gateway/types/genesis.go @@ -1,7 +1,8 @@ package types import ( - "fmt" + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" ) // DefaultIndex is the default global index @@ -19,15 +20,32 @@ func DefaultGenesis() *GenesisState { // Validate performs basic genesis state validation returning an error upon any // failure. func (gs GenesisState) Validate() error { - // Check for duplicated index in gateway gatewayIndexMap := make(map[string]struct{}) - for _, elem := range gs.GatewayList { - index := string(GatewayKey(elem.Address)) + for _, gateway := range gs.GatewayList { + // Check for duplicated index in gateway + index := string(GatewayKey(gateway.Address)) if _, ok := gatewayIndexMap[index]; ok { - return fmt.Errorf("duplicated index for gateway") + return sdkerrors.Wrap(ErrGatewayInvalidAddress, "duplicated index for gateway") } gatewayIndexMap[index] = struct{}{} + // Validate the stake of each gateway + if gateway.Stake == nil { + return sdkerrors.Wrap(ErrGatewayInvalidStake, "nil stake amount for gateway") + } + stake, err := sdk.ParseCoinNormalized(gateway.Stake.String()) + if !stake.IsValid() { + return sdkerrors.Wrapf(ErrGatewayInvalidStake, "invalid stake amount for gateway %v; (%v)", gateway.Stake, stake.Validate()) + } + if err != nil { + return sdkerrors.Wrapf(ErrGatewayInvalidStake, "cannot parse stake amount for gateway %v; (%v)", gateway.Stake, err) + } + if stake.IsZero() || stake.IsNegative() { + return sdkerrors.Wrapf(ErrGatewayInvalidStake, "invalid stake amount for gateway: %v <= 0", gateway.Stake) + } + if stake.Denom != "upokt" { + return sdkerrors.Wrapf(ErrGatewayInvalidStake, "invalid stake amount denom for gateway %v", gateway.Stake) + } } // this line is used by starport scaffolding # genesis/types/validate diff --git a/x/gateway/types/genesis_test.go b/x/gateway/types/genesis_test.go index 446f2db3b..a6aa2816c 100644 --- a/x/gateway/types/genesis_test.go +++ b/x/gateway/types/genesis_test.go @@ -3,11 +3,21 @@ package types_test import ( "testing" - "github.com/pokt-network/poktroll/x/gateway/types" + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" + + "github.com/pokt-network/poktroll/testutil/sample" + "github.com/pokt-network/poktroll/x/gateway/types" ) func TestGenesisState_Validate(t *testing.T) { + addr1 := sample.AccAddress() + stake1 := sdk.NewCoin("upokt", sdkmath.NewInt(100)) + + addr2 := sample.AccAddress() + stake2 := sdk.NewCoin("upokt", sdkmath.NewInt(100)) + tests := []struct { desc string genState *types.GenesisState @@ -21,13 +31,14 @@ func TestGenesisState_Validate(t *testing.T) { { desc: "valid genesis state", genState: &types.GenesisState{ - GatewayList: []types.Gateway{ { - Address: "0", + Address: addr1, + Stake: &stake1, }, { - Address: "1", + Address: addr2, + Stake: &stake2, }, }, // this line is used by starport scaffolding # types/genesis/validField @@ -35,14 +46,112 @@ func TestGenesisState_Validate(t *testing.T) { valid: true, }, { - desc: "duplicated gateway", + desc: "invalid - duplicated gateway address", + genState: &types.GenesisState{ + GatewayList: []types.Gateway{ + { + Address: addr1, + Stake: &stake1, + }, + { + Address: addr1, + Stake: &stake2, + }, + }, + }, + valid: false, + }, + { + desc: "invalid - nil gateway stake", + genState: &types.GenesisState{ + GatewayList: []types.Gateway{ + { + Address: addr1, + Stake: &stake1, + }, + { + Address: addr2, + Stake: nil, + }, + }, + }, + valid: false, + }, + { + desc: "invalid - missing gateway stake", + genState: &types.GenesisState{ + GatewayList: []types.Gateway{ + { + Address: addr1, + Stake: &stake1, + }, + { + Address: addr2, + // Stake: stake2, + }, + }, + }, + valid: false, + }, + { + desc: "invalid - zero gateway stake", + genState: &types.GenesisState{ + GatewayList: []types.Gateway{ + { + Address: addr1, + Stake: &stake1, + }, + { + Address: addr2, + Stake: &sdk.Coin{Denom: "upokt", Amount: sdkmath.NewInt(0)}, + }, + }, + }, + valid: false, + }, + { + desc: "invalid - negative gateway stake", + genState: &types.GenesisState{ + GatewayList: []types.Gateway{ + { + Address: addr1, + Stake: &stake1, + }, + { + Address: addr2, + Stake: &sdk.Coin{Denom: "upokt", Amount: sdkmath.NewInt(-100)}, + }, + }, + }, + valid: false, + }, + { + desc: "invalid - wrong stake denom", + genState: &types.GenesisState{ + GatewayList: []types.Gateway{ + { + Address: addr1, + Stake: &stake1, + }, + { + Address: addr2, + Stake: &sdk.Coin{Denom: "invalid", Amount: sdkmath.NewInt(100)}, + }, + }, + }, + valid: false, + }, + { + desc: "invalid - missing denom", genState: &types.GenesisState{ GatewayList: []types.Gateway{ { - Address: "0", + Address: addr1, + Stake: &stake1, }, { - Address: "0", + Address: addr2, + Stake: &sdk.Coin{Denom: "", Amount: sdkmath.NewInt(100)}, }, }, }, diff --git a/x/gateway/types/key_gateway.go b/x/gateway/types/key_gateway.go index aaf7397a5..8fe1e65f7 100644 --- a/x/gateway/types/key_gateway.go +++ b/x/gateway/types/key_gateway.go @@ -5,7 +5,7 @@ import "encoding/binary" var _ binary.ByteOrder const ( - // GatewayKeyPrefix is the prefix to retrieve all Gateway + // GatewayKeyPrefix is the prefix to retrieve all Gateways GatewayKeyPrefix = "Gateway/value/" ) diff --git a/x/gateway/types/message_stake_gateway.go b/x/gateway/types/message_stake_gateway.go index b3f19883c..9f349cf16 100644 --- a/x/gateway/types/message_stake_gateway.go +++ b/x/gateway/types/message_stake_gateway.go @@ -1,6 +1,7 @@ package types import ( + sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -16,25 +17,25 @@ func NewMsgStakeGateway(address string, stake sdk.Coin) *MsgStakeGateway { func (msg *MsgStakeGateway) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Address) if err != nil { - return ErrGatewayInvalidAddress.Wrapf("invalid gateway address %s; (%v)", msg.Address, err) + return sdkerrors.Wrapf(ErrGatewayInvalidAddress, "invalid gateway address %s; (%v)", msg.Address, err) } // Validate the stake amount if msg.Stake == nil { - return ErrGatewayInvalidStake.Wrapf("nil gateway stake; (%v)", err) + return sdkerrors.Wrapf(ErrGatewayInvalidStake, "nil gateway stake; (%v)", err) } stake, err := sdk.ParseCoinNormalized(msg.Stake.String()) if !stake.IsValid() { - return ErrGatewayInvalidStake.Wrapf("invalid gateway stake %v; (%v)", msg.Stake, stake.Validate()) + return sdkerrors.Wrapf(ErrGatewayInvalidStake, "invalid gateway stake %v; (%v)", msg.Stake, stake.Validate()) } if err != nil { - return ErrGatewayInvalidStake.Wrapf("cannot parse gateway stake %v; (%v)", msg.Stake, err) + return sdkerrors.Wrapf(ErrGatewayInvalidStake, "cannot parse gateway stake %v; (%v)", msg.Stake, err) } if stake.IsZero() || stake.IsNegative() { - return ErrGatewayInvalidStake.Wrapf("invalid stake amount for gateway: %v <= 0", msg.Stake) + return sdkerrors.Wrapf(ErrGatewayInvalidStake, "invalid stake amount for gateway: %v <= 0", msg.Stake) } if stake.Denom != "upokt" { - return ErrGatewayInvalidStake.Wrapf("invalid stake amount denom for gateway %v", msg.Stake) + return sdkerrors.Wrapf(ErrGatewayInvalidStake, "invalid stake amount denom for gateway %v", msg.Stake) } return nil } diff --git a/x/gateway/types/message_stake_gateway_test.go b/x/gateway/types/message_stake_gateway_test.go index f6b40a403..d1cb20902 100644 --- a/x/gateway/types/message_stake_gateway_test.go +++ b/x/gateway/types/message_stake_gateway_test.go @@ -3,7 +3,7 @@ package types import ( "testing" - "cosmossdk.io/math" + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" @@ -11,7 +11,7 @@ import ( ) func TestMsgStakeGateway_ValidateBasic(t *testing.T) { - coins := sdk.NewCoin("upokt", math.NewInt(100)) + coins := sdk.NewCoin("upokt", sdkmath.NewInt(100)) tests := []struct { name string msg MsgStakeGateway @@ -35,28 +35,28 @@ func TestMsgStakeGateway_ValidateBasic(t *testing.T) { name: "valid address - zero stake", msg: MsgStakeGateway{ Address: sample.AccAddress(), - Stake: &sdk.Coin{Denom: "upokt", Amount: math.NewInt(0)}, + Stake: &sdk.Coin{Denom: "upokt", Amount: sdkmath.NewInt(0)}, }, err: ErrGatewayInvalidStake, }, { name: "valid address - negative stake", msg: MsgStakeGateway{ Address: sample.AccAddress(), - Stake: &sdk.Coin{Denom: "upokt", Amount: math.NewInt(-100)}, + Stake: &sdk.Coin{Denom: "upokt", Amount: sdkmath.NewInt(-100)}, }, err: ErrGatewayInvalidStake, }, { name: "valid address - invalid stake denom", msg: MsgStakeGateway{ Address: sample.AccAddress(), - Stake: &sdk.Coin{Denom: "invalid", Amount: math.NewInt(100)}, + Stake: &sdk.Coin{Denom: "invalid", Amount: sdkmath.NewInt(100)}, }, err: ErrGatewayInvalidStake, }, { name: "valid address - invalid stake missing denom", msg: MsgStakeGateway{ Address: sample.AccAddress(), - Stake: &sdk.Coin{Denom: "", Amount: math.NewInt(100)}, + Stake: &sdk.Coin{Denom: "", Amount: sdkmath.NewInt(100)}, }, err: ErrGatewayInvalidStake, }, { diff --git a/x/gateway/types/message_unstake_gateway.go b/x/gateway/types/message_unstake_gateway.go index 41bdfca92..fc163d022 100644 --- a/x/gateway/types/message_unstake_gateway.go +++ b/x/gateway/types/message_unstake_gateway.go @@ -1,6 +1,7 @@ package types import ( + sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -15,7 +16,7 @@ func NewMsgUnstakeGateway(address string) *MsgUnstakeGateway { func (msg *MsgUnstakeGateway) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Address) if err != nil { - return ErrGatewayInvalidAddress.Wrapf("invalid gateway address (%s); (%v)", msg.Address, err) + return sdkerrors.Wrapf(ErrGatewayInvalidAddress, "invalid gateway address %s; (%v)", msg.Address, err) } return nil } diff --git a/x/gateway/types/message_unstake_gateway_test.go b/x/gateway/types/message_unstake_gateway_test.go index 6212bee1c..301ad05ef 100644 --- a/x/gateway/types/message_unstake_gateway_test.go +++ b/x/gateway/types/message_unstake_gateway_test.go @@ -19,11 +19,14 @@ func TestMsgUnstakeGateway_ValidateBasic(t *testing.T) { Address: "invalid_address", }, err: ErrGatewayInvalidAddress, - }, { + }, + { name: "missing address", msg: MsgUnstakeGateway{}, err: ErrGatewayInvalidAddress, - }, {name: "valid address", + }, + { + name: "valid address", msg: MsgUnstakeGateway{ Address: sample.AccAddress(), },