Skip to content

Commit

Permalink
refactor!: move genesis to gnoland genesis (gnolang#1954)
Browse files Browse the repository at this point in the history
## Description

Closes gnolang#1953 

This PR moves the `genesis` command suite to be a subcommand of
`gnoland`, making it callable with `gnoland genesis`.

<details><summary>Contributors' checklist...</summary>

- [x] Added new tests, or not needed, or not feasible
- [x] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [x] Updated the official documentation or not needed
- [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [x] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>
  • Loading branch information
zivkovicmilos authored Apr 19, 2024
1 parent 7ecc692 commit c628334
Show file tree
Hide file tree
Showing 27 changed files with 68 additions and 23 deletions.
6 changes: 2 additions & 4 deletions gno.land/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,21 @@ start.gnoland:; go run ./cmd/gnoland start
start.gnoweb:; go run ./cmd/gnoweb

.PHONY: build
build: build.gnoland build.gnokey build.gnoweb build.genesis
build: build.gnoland build.gnokey build.gnoweb

build.gnoland:; go build -o build/gnoland ./cmd/gnoland
build.gnoweb:; go build -o build/gnoweb ./cmd/gnoweb
build.gnokey:; go build -o build/gnokey ./cmd/gnokey
build.genesis:; go build -o build/genesis ./cmd/genesis

run.gnoland:; go run ./cmd/gnoland start
run.gnoweb:; go run ./cmd/gnoweb

.PHONY: install
install: install.gnoland install.gnoweb install.gnokey install.genesis
install: install.gnoland install.gnoweb install.gnokey

install.gnoland:; go install ./cmd/gnoland
install.gnoweb:; go install ./cmd/gnoweb
install.gnokey:; go install ./cmd/gnokey
install.genesis:; go install ./cmd/genesis

.PHONY: fclean
fclean: clean
Expand Down
17 changes: 5 additions & 12 deletions gno.land/cmd/genesis/main.go → gno.land/cmd/gnoland/genesis.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
package main

import (
"context"
"flag"
"os"

"github.com/gnolang/gno/tm2/pkg/commands"
)

func main() {
io := commands.NewDefaultIO()
cmd := newRootCmd(io)

cmd.Execute(context.Background(), os.Args[1:])
}

func newRootCmd(io commands.IO) *commands.Command {
func newGenesisCmd(io commands.IO) *commands.Command {
cmd := commands.NewCommand(
commands.Metadata{
ShortUsage: "<subcommand> [flags] [<arg>...]",
LongHelp: "Gno Genesis manipulation suite",
Name: "genesis",
ShortUsage: "genesis <subcommand> [flags] [<arg>...]",
ShortHelp: "gno genesis manipulation suite",
LongHelp: "Gno genesis.json manipulation suite, for managing genesis parameters",
},
commands.NewEmptyConfig(),
commands.HelpExec,
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func TestGenesis_Balances_Add(t *testing.T) {
// Create the command
cmd := newRootCmd(commands.NewTestIO())
args := []string{
"genesis",
"balances",
"add",
"--genesis-path",
Expand All @@ -50,6 +51,7 @@ func TestGenesis_Balances_Add(t *testing.T) {
// Create the command
cmd := newRootCmd(commands.NewTestIO())
args := []string{
"genesis",
"balances",
"add",
"--genesis-path",
Expand All @@ -67,6 +69,7 @@ func TestGenesis_Balances_Add(t *testing.T) {
// Create the command
cmd := newRootCmd(commands.NewTestIO())
args := []string{
"genesis",
"balances",
"add",
"--genesis-path",
Expand All @@ -92,6 +95,7 @@ func TestGenesis_Balances_Add(t *testing.T) {
// Create the command
cmd := newRootCmd(commands.NewTestIO())
args := []string{
"genesis",
"balances",
"add",
"--genesis-path",
Expand Down Expand Up @@ -181,6 +185,7 @@ func TestGenesis_Balances_Add(t *testing.T) {
// Create the command
cmd := newRootCmd(commands.NewTestIO())
args := []string{
"genesis",
"balances",
"add",
"--genesis-path",
Expand Down Expand Up @@ -280,6 +285,7 @@ func TestGenesis_Balances_Add(t *testing.T) {
// Create the command
cmd := newRootCmd(commands.NewTestIO())
args := []string{
"genesis",
"balances",
"add",
"--genesis-path",
Expand Down Expand Up @@ -353,6 +359,7 @@ func TestGenesis_Balances_Add(t *testing.T) {
// Create the command
cmd := newRootCmd(commands.NewTestIO())
args := []string{
"genesis",
"balances",
"add",
"--genesis-path",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func TestGenesis_Balances_Export(t *testing.T) {
// Create the command
cmd := newRootCmd(commands.NewTestIO())
args := []string{
"genesis",
"balances",
"export",
"--genesis-path",
Expand All @@ -65,6 +66,7 @@ func TestGenesis_Balances_Export(t *testing.T) {
// Create the command
cmd := newRootCmd(commands.NewTestIO())
args := []string{
"genesis",
"balances",
"export",
"--genesis-path",
Expand All @@ -91,6 +93,7 @@ func TestGenesis_Balances_Export(t *testing.T) {
// Create the command
cmd := newRootCmd(commands.NewTestIO())
args := []string{
"genesis",
"balances",
"export",
"--genesis-path",
Expand Down Expand Up @@ -124,6 +127,7 @@ func TestGenesis_Balances_Export(t *testing.T) {
// Create the command
cmd := newRootCmd(commands.NewTestIO())
args := []string{
"genesis",
"balances",
"export",
"--genesis-path",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func TestGenesis_Balances_Remove(t *testing.T) {
// Create the command
cmd := newRootCmd(commands.NewTestIO())
args := []string{
"genesis",
"balances",
"remove",
"--genesis-path",
Expand All @@ -46,6 +47,7 @@ func TestGenesis_Balances_Remove(t *testing.T) {
// Create the command
cmd := newRootCmd(commands.NewTestIO())
args := []string{
"genesis",
"balances",
"remove",
"--genesis-path",
Expand Down Expand Up @@ -83,6 +85,7 @@ func TestGenesis_Balances_Remove(t *testing.T) {
// Create the command
cmd := newRootCmd(commands.NewTestIO())
args := []string{
"genesis",
"balances",
"remove",
"--genesis-path",
Expand Down Expand Up @@ -125,6 +128,7 @@ func TestGenesis_Balances_Remove(t *testing.T) {
// Create the command
cmd := newRootCmd(commands.NewTestIO())
args := []string{
"genesis",
"balances",
"remove",
"--genesis-path",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func TestGenesis_Generate(t *testing.T) {
// Create the command
cmd := newRootCmd(commands.NewTestIO())
args := []string{
"genesis",
"generate",
"--output-path",
genesisPath,
Expand Down Expand Up @@ -60,6 +61,7 @@ func TestGenesis_Generate(t *testing.T) {
// Create the command
cmd := newRootCmd(commands.NewTestIO())
args := []string{
"genesis",
"generate",
"--chain-id",
chainID,
Expand Down Expand Up @@ -91,6 +93,7 @@ func TestGenesis_Generate(t *testing.T) {
// Create the command
cmd := newRootCmd(commands.NewTestIO())
args := []string{
"genesis",
"generate",
"--block-max-tx-bytes",
fmt.Sprintf("%d", blockMaxTxBytes),
Expand Down Expand Up @@ -126,6 +129,7 @@ func TestGenesis_Generate(t *testing.T) {
// Create the command
cmd := newRootCmd(commands.NewTestIO())
args := []string{
"genesis",
"generate",
"--block-max-data-bytes",
fmt.Sprintf("%d", blockMaxDataBytes),
Expand Down Expand Up @@ -161,6 +165,7 @@ func TestGenesis_Generate(t *testing.T) {
// Create the command
cmd := newRootCmd(commands.NewTestIO())
args := []string{
"genesis",
"generate",
"--block-max-gas",
fmt.Sprintf("%d", blockMaxGas),
Expand Down Expand Up @@ -196,6 +201,7 @@ func TestGenesis_Generate(t *testing.T) {
// Create the command
cmd := newRootCmd(commands.NewTestIO())
args := []string{
"genesis",
"generate",
"--block-time-iota",
fmt.Sprintf("%d", blockTimeIota),
Expand Down Expand Up @@ -231,6 +237,7 @@ func TestGenesis_Generate(t *testing.T) {
// Create the command
cmd := newRootCmd(commands.NewTestIO())
args := []string{
"genesis",
"generate",
"--chain-id",
invalidChainID,
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func TestGenesis_Txs_Add(t *testing.T) {
// Create the command
cmd := newRootCmd(commands.NewTestIO())
args := []string{
"genesis",
"txs",
"add",
"--genesis-path",
Expand All @@ -94,6 +95,7 @@ func TestGenesis_Txs_Add(t *testing.T) {
// Create the command
cmd := newRootCmd(commands.NewTestIO())
args := []string{
"genesis",
"txs",
"add",
"--genesis-path",
Expand All @@ -118,6 +120,7 @@ func TestGenesis_Txs_Add(t *testing.T) {
// Create the command
cmd := newRootCmd(commands.NewTestIO())
args := []string{
"genesis",
"txs",
"add",
"--genesis-path",
Expand All @@ -141,6 +144,7 @@ func TestGenesis_Txs_Add(t *testing.T) {
// Create the command
cmd := newRootCmd(commands.NewTestIO())
args := []string{
"genesis",
"txs",
"add",
"--genesis-path",
Expand Down Expand Up @@ -180,6 +184,7 @@ func TestGenesis_Txs_Add(t *testing.T) {
// Create the command
cmd := newRootCmd(commands.NewTestIO())
args := []string{
"genesis",
"txs",
"add",
"--genesis-path",
Expand Down Expand Up @@ -238,6 +243,7 @@ func TestGenesis_Txs_Add(t *testing.T) {
// Create the command
cmd := newRootCmd(commands.NewTestIO())
args := []string{
"genesis",
"txs",
"add",
"--genesis-path",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func TestGenesis_Txs_Export(t *testing.T) {
// Create the command
cmd := newRootCmd(commands.NewTestIO())
args := []string{
"genesis",
"txs",
"export",
"--genesis-path",
Expand All @@ -47,6 +48,7 @@ func TestGenesis_Txs_Export(t *testing.T) {
// Create the command
cmd := newRootCmd(commands.NewTestIO())
args := []string{
"genesis",
"txs",
"export",
"--genesis-path",
Expand All @@ -73,6 +75,7 @@ func TestGenesis_Txs_Export(t *testing.T) {
// Create the command
cmd := newRootCmd(commands.NewTestIO())
args := []string{
"genesis",
"txs",
"export",
"--genesis-path",
Expand Down Expand Up @@ -106,6 +109,7 @@ func TestGenesis_Txs_Export(t *testing.T) {
// Create the command
cmd := newRootCmd(commands.NewTestIO())
args := []string{
"genesis",
"txs",
"export",
"--genesis-path",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func TestGenesis_Txs_Remove(t *testing.T) {
// Create the command
cmd := newRootCmd(commands.NewTestIO())
args := []string{
"genesis",
"txs",
"remove",
"--genesis-path",
Expand All @@ -45,6 +46,7 @@ func TestGenesis_Txs_Remove(t *testing.T) {
// Create the command
cmd := newRootCmd(commands.NewTestIO())
args := []string{
"genesis",
"txs",
"remove",
"--genesis-path",
Expand Down Expand Up @@ -73,6 +75,7 @@ func TestGenesis_Txs_Remove(t *testing.T) {
// Create the command
cmd := newRootCmd(commands.NewTestIO())
args := []string{
"genesis",
"txs",
"remove",
"--genesis-path",
Expand Down Expand Up @@ -105,6 +108,7 @@ func TestGenesis_Txs_Remove(t *testing.T) {
// Create the command
cmd := newRootCmd(commands.NewTestIO())
args := []string{
"genesis",
"txs",
"remove",
"--genesis-path",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import (
)

var (
errInvalidPower = errors.New("invalid validator power")
errInvalidName = errors.New("invalid validator name")
errPublicKeyMismatch = errors.New("provided public key and address do not match")
errAddressPresent = errors.New("validator with same address already present in genesis.json")
errInvalidPower = errors.New("invalid validator power")
errInvalidName = errors.New("invalid validator name")
errPublicKeyAddressMismatch = errors.New("provided public key and address do not match")
errAddressPresent = errors.New("validator with same address already present in genesis.json")
)

type validatorAddCfg struct {
Expand Down Expand Up @@ -89,7 +89,7 @@ func execValidatorAdd(cfg *validatorAddCfg, io commands.IO) error {

// Check the name
if cfg.name == "" {
return errors.New("invalid validator name")
return errInvalidName
}

// Check the public key
Expand All @@ -100,7 +100,7 @@ func execValidatorAdd(cfg *validatorAddCfg, io commands.IO) error {

// Check the public key matches the address
if pubKey.Address() != address {
return errors.New("provided public key and address do not match")
return errPublicKeyAddressMismatch
}

validator := types.GenesisValidator{
Expand Down
Loading

0 comments on commit c628334

Please sign in to comment.