Skip to content

Commit

Permalink
[Application] Implement MsgStakeApplication & Add Extensive Tests (#59)
Browse files Browse the repository at this point in the history
## Summary

https://github.com/pokt-network/poktroll/assets/1892194/ffe3158d-a1b3-4672-8e0b-e673349067d2

### Human Summary

- Various small helpers (e.g. Makefile)
- Shared helpers for unit tests
- Add `stake` to the `Application` type
- Add `stake` to the `MsgStakeApplication` command
- Implement unit tests in all related parts of the codebase (CLI, genesis, keeper, etc...) with the exception of the `simulation` package

--- 

Co-authored-by: harry <[email protected]>
Co-authored-by: Bryan White <[email protected]>
  • Loading branch information
3 people authored Oct 18, 2023
1 parent 4be9ab9 commit b5cb88d
Show file tree
Hide file tree
Showing 34 changed files with 933 additions and 171 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ jobs:
with:
go-version: "1.20"

- name: Generate protobufs
run: make proto_regen

- name: Install CI dependencies
run: make install_ci_deps

- name: Generate protobufs
run: make proto_regen

- name: Generate mocks
run: make go_mockgen

Expand All @@ -42,4 +42,4 @@ jobs:
run: make go_mockgen

- name: Test
run: go test -v ./...
run: make go_test
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,8 @@ ts-client/
.tool-versions

# Proto artifacts
*/*.pb.go
*/*.pb.gw.go
**/*.pb.go
**/*.pb.gw.go

# Mock
**/*_mock.go
63 changes: 62 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
.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_NODE = tcp://127.0.0.1:36657 # The pocket rollup node (full node and sequencer in the localnet context)
POCKET_ADDR_PREFIX = pokt

####################
### Dependencies ###
Expand Down Expand Up @@ -116,8 +117,12 @@ go_test: go_version_check ## Run all go tests

.PHONY: go_mockgen
go_mockgen: ## Use `mockgen` to generate mocks used for testing purposes of all the modules.
go generate ./x/application/types/
go generate ./x/gateway/types/

.PHONY: go_develop
go_develop: proto_regen go_mockgen go_test ## Generate protos, mocks and run all tests

#############
### TODOS ###
#############
Expand Down Expand Up @@ -174,3 +179,59 @@ todo_count: ## Print a count of all the TODOs in the project
.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"

####################
### 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 env var)
pocketd --home=$(POCKETD_HOME) tx application stake-application 1000upokt --keyring-backend test --from $(APP) --node $(POCKET_NODE)

.PHONY: app1_stake
app1_stake: ## Stake app1
APP=app1 make app_stake

.PHONY: app2_stake
app2_stake: ## Stake app2
APP=app2 make app_stake

.PHONY: app3_stake
app3_stake: ## Stake app3
APP=app3 make app_stake

################
### 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_app_module
acc_balance_query_app_module: ## Query the balance of the network level "application" module
make acc_balance_query ACC=pokt1rl3gjgzexmplmds3tq3r3yk84zlwdl6djzgsvm

.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)
60 changes: 21 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,34 @@
# pocket
**pocket** is a blockchain built using Cosmos SDK and Tendermint and created with [Ignite CLI](https://ignite.com/cli).
# poktroll <!-- omit in toc -->

## Get started
**poktroll** is a rollup built using [Rollkit](https://rollkit.dev/), [Cosmos SDK](https://docs.cosmos.network) and [CometBFT](https://cometbft.com/), created with [Ignite CLI](https://ignite.com/cli) for the Shannon upgrade of the [Pocket Network](https://pokt.network) blockchain.

```
ignite chain serve
```
- [Getting Started](#getting-started)
- [Makefile](#makefile)
- [Development](#development)
- [LocalNet](#localnet)

`serve` command installs dependencies, builds, initializes, and starts your blockchain in development.
## Getting Started

### Configure
### Makefile

Your blockchain in development can be configured with `config.yml`. To learn more, see the [Ignite CLI docs](https://docs.ignite.com).
Run `make` to see all the available commands

### Web Frontend
### Development

Ignite CLI has scaffolded a Vue.js-based web app in the `vue` directory. Run the following commands to install dependencies and start the app:
```bash
# Build local files & binaries
make go_develop

```
cd vue
npm install
npm run serve
# Run all the unit tests
make go_test
```

The frontend app is built using the `@starport/vue` and `@starport/vuex` packages. For details, see the [monorepo for Ignite front-end development](https://github.com/ignite/web).
### LocalNet

## Release
To release a new version of your blockchain, create and push a new tag with `v` prefix. A new draft release with the configured targets will be created.
```bash
# Create a k8s cluster
kind create cluster

# Start a LocalNet
make localnet_up
```
git tag v0.1
git push origin v0.1
```

After a draft release is created, make your final changes from the release page and publish it.

### Install
To install the latest version of your blockchain node's binary, execute the following command on your machine:

```
curl https://get.ignite.com/username/pocket@latest! | sudo bash
```
`username/pocket` should match the `username` and `repo_name` of the Github repository to which the source code was pushed. Learn more about [the install process](https://github.com/allinbits/starport-installer).

## Learn more

- [Ignite CLI](https://ignite.com/cli)
- [Tutorials](https://docs.ignite.com/guide)
- [Ignite CLI docs](https://docs.ignite.com)
- [Cosmos SDK docs](https://docs.cosmos.network)
- [Developer Chat](https://discord.gg/ignite)
26 changes: 11 additions & 15 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"os"
"path/filepath"
// this line is used by starport scaffolding # stargate/app/moduleImport

autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
Expand Down Expand Up @@ -110,38 +111,33 @@ import (
ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
"github.com/spf13/cast"

appparams "pocket/app/params"
"pocket/docs"
applicationmodule "pocket/x/application"
applicationmodulekeeper "pocket/x/application/keeper"
applicationmoduletypes "pocket/x/application/types"
gatewaymodule "pocket/x/gateway"
gatewaymodulekeeper "pocket/x/gateway/keeper"
gatewaymoduletypes "pocket/x/gateway/types"
pocketmodule "pocket/x/pocket"
pocketmodulekeeper "pocket/x/pocket/keeper"
pocketmoduletypes "pocket/x/pocket/types"

servicemodule "pocket/x/service"
servicemodulekeeper "pocket/x/service/keeper"
servicemoduletypes "pocket/x/service/types"

sessionmodule "pocket/x/session"
sessionmodulekeeper "pocket/x/session/keeper"
sessionmoduletypes "pocket/x/session/types"

applicationmodule "pocket/x/application"
applicationmodulekeeper "pocket/x/application/keeper"
applicationmoduletypes "pocket/x/application/types"

suppliermodule "pocket/x/supplier"
suppliermodulekeeper "pocket/x/supplier/keeper"
suppliermoduletypes "pocket/x/supplier/types"

gatewaymodule "pocket/x/gateway"
gatewaymodulekeeper "pocket/x/gateway/keeper"
gatewaymoduletypes "pocket/x/gateway/types"
// this line is used by starport scaffolding # stargate/app/moduleImport

appparams "pocket/app/params"
"pocket/docs"
)

const (
AccountAddressPrefix = "pokt"
Name = "pocket"
// TODO_CLEANUP: Find a way to centralize the use of `upokt` throughout the codebase
DenomuPOKT = "upokt"
)

// this line is used by starport scaffolding # stargate/wasm/app/enabledProposals
Expand Down
6 changes: 5 additions & 1 deletion cmd/pocketd/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import (
"pocket/app"
)

func initSDKConfig() {
// InitSDKConfig initializes the SDK's config with the appropriate parameters
// and prefixes so everything is named appropriately for Pocket Network.
// TODO_DISCUSS: Exporting publically for testing purposes only.
// Consider adding a helper per the discussion here: https://github.com/pokt-network/poktroll/pull/59#discussion_r1357816798
func InitSDKConfig() {
// Set prefixes
accountPubKeyPrefix := app.AccountAddressPrefix + "pub"
validatorAddressPrefix := app.AccountAddressPrefix + "valoper"
Expand Down
5 changes: 3 additions & 2 deletions cmd/pocketd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"path/filepath"
"strings"

// this line is used by starport scaffolding # root/moduleImport

dbm "github.com/cometbft/cometbft-db"
tmcfg "github.com/cometbft/cometbft/config"
tmcli "github.com/cometbft/cometbft/libs/cli"
Expand Down Expand Up @@ -36,7 +38,6 @@ import (
"github.com/spf13/cast"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
// this line is used by starport scaffolding # root/moduleImport

"pocket/app"
appparams "pocket/app/params"
Expand Down Expand Up @@ -104,7 +105,7 @@ func initRootCmd(
encodingConfig appparams.EncodingConfig,
) {
// Set config
initSDKConfig()
InitSDKConfig()

gentxModule := app.ModuleBasics[genutiltypes.ModuleName].(genutil.AppModuleBasic)
rootCmd.AddCommand(
Expand Down
87 changes: 44 additions & 43 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ accounts:
mnemonic: "involve clean slab term real human green immune valid swing protect talk silent unique cart few ice era right thunder again drop among bounce"
coins:
- 300000000upokt
- name: servicer1
- name: supplier1
mnemonic: "cool industry busy tumble funny relax error state height like board wing goat emerge visual idle never unveil announce hill primary okay spatial frog"
coins:
- 110000000upokt
- name: servicer2
- name: supplier2
mnemonic: "peanut hen enroll meat legal have error input bulk later correct denial onion fossil wing excuse elephant object apology switch claim rare decide surface"
coins:
- 220000000upokt
- name: servicer3
- name: supplier3
mnemonic: "client city senior tenant source soda spread buffalo shaft amused bar carbon keen off feel coral easily announce metal orphan sustain maple expand loop"
coins:
- 330000000upokt
Expand Down Expand Up @@ -79,49 +79,50 @@ genesis:
- amount: "10000"
denom: upokt
application:
# TODO(olshansky): Add this back after the Application type is added to the SDK
# applicationList:
# - address: pokt1mrqt5f7qh8uxs27cjm9t7v9e74a9vvdnq5jva4
applicationList:
- address: pokt1mrqt5f7qh8uxs27cjm9t7v9e74a9vvdnq5jva4
stake:
amount: "1000"
denom: upokt
# TODO(@Olshansk): Update genesis to include services
# services:
# - id: svc1
# name: TODO
# - id: svc2
# name: TODO
# stake:
# amount: '1000'
# denom: upokt
# params: {}
servicer:
params: {}
servicersList:
- address: pokt19a3t4yunp0dlpfjrp7qwnzwlrzd5fzs2gjaaaj
services:
- endpoints:
- configs:
- key: TIMEOUT
value: 30s
metadata:
entries: {}
rpc_type: WEBSOCKET
url: ws://localhost:8546/
id:
id: svc1
name: Pocket Network Service 1
metadata:
entries: {}
- endpoints:
- configs:
- key: TIMEOUT
value: 60s
metadata:
entries: {}
rpc_type: JSON_RPC
url: http://localhost:8545
id:
id: svc2
name: Pocket Network Service 2
metadata:
entries: {}
stake:
amount: "1000000"
denom: upokt
# TODO(@Olshansk): Update genesis to include suppliers
# supplier:
# params: {}
# suppliersList:
# - address: pokt19a3t4yunp0dlpfjrp7qwnzwlrzd5fzs2gjaaaj
# services:
# - endpoints:
# - configs:
# - key: TIMEOUT
# value: 30s
# metadata:
# entries: {}
# rpc_type: WEBSOCKET
# url: ws://localhost:8546/
# id:
# id: svc1
# name: Pocket Network Service 1
# metadata:
# entries: {}
# - endpoints:
# - configs:
# - key: TIMEOUT
# value: 60s
# metadata:
# entries: {}
# rpc_type: JSON_RPC
# url: http://localhost:8545
# id:
# id: svc2
# name: Pocket Network Service 2
# metadata:
# entries: {}
# stake:
# amount: "1000000"
# denom: upokt
Loading

0 comments on commit b5cb88d

Please sign in to comment.