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

refactor!: move genesis to gnoland genesis #1954

Merged
merged 5 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
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
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
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
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.
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
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
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
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
Loading