-
Notifications
You must be signed in to change notification settings - Fork 547
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: scaffold consumer chain (#3660)
* feat: add validation kind in config Disable gentx generation when validation is consumer. * Add consumer chain plush scaffolding * update config.yml when scaffold consumer chain * Add hard-coded interchain-security require * remove comment * fix bad merge go.sum * update ibc to v8 * fix changelog * chore: update interchain-security dependency Use the latest compatible with sdk50 * update ccvconsumertypes -> ccvtypes * templates: ibc-go/v7 -> ibc-go/v8 plus other dep updates * fix imports * fix imports paths * do not pass CapabilityKeeper in dep.Inject * Fix lint * fix: add missing ibcconsumer.AppModule (#3848) Co-authored-by: Pantani <Pantani> * remove ICS dep * wip exec plugin! * use plugin repo * restore templates/app/files w/o IsConsumerChain condition * create files-consumer alternate template folder * mark minimal and consumer flags as exclusive * fix wrong location for consumer_*.go files * fix error handling for IsInitialized * revert commit wip plugin exec * use plugin to read & write consumer module genesis * fix linter * backport NFT module #3924 in files-consumer * update app-consumer url * move app-consumer address to ignite org * update CL * use new plugin location * use merged version of consumer app * changelog * sync fixes * updates * fixes * changelog * feedback * fix linter * update ante handlers * import * updates --------- Co-authored-by: Ehsan-saradar <[email protected]> Co-authored-by: Danilo Pantani <[email protected]> Co-authored-by: Julien Robert <[email protected]>
- Loading branch information
1 parent
5127085
commit 5ed9632
Showing
30 changed files
with
1,654 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package plugininternal | ||
|
||
import ( | ||
"context" | ||
"strconv" | ||
|
||
"github.com/ignite/cli/v28/ignite/pkg/errors" | ||
"github.com/ignite/cli/v28/ignite/services/plugin" | ||
) | ||
|
||
// TODO use released version of app-consumer. | ||
const consumerPlugin = "github.com/ignite/apps/consumer" | ||
|
||
// ConsumerWriteGenesis writes validators in the consumer module genesis. | ||
// NOTE(tb): Using a plugin for this task avoids having the interchain-security | ||
// dependency in Ignite. | ||
func ConsumerWriteGenesis(ctx context.Context, c plugin.Chainer) error { | ||
_, err := Execute(ctx, consumerPlugin, []string{"writeGenesis"}, plugin.WithChain(c)) | ||
if err != nil { | ||
return errors.Errorf("execute consumer plugin 'writeGenesis': %w", err) | ||
} | ||
return nil | ||
} | ||
|
||
// ConsumerIsInitialized returns true if the consumer chain's genesis c has | ||
// a consumer module entry with an initial validator set. | ||
// NOTE(tb): Using a plugin for this task avoids having the interchain-security | ||
// dependency in Ignite. | ||
func ConsumerIsInitialized(ctx context.Context, c plugin.Chainer) (bool, error) { | ||
out, err := Execute(ctx, consumerPlugin, []string{"isInitialized"}, plugin.WithChain(c)) | ||
if err != nil { | ||
return false, errors.Errorf("execute consumer plugin 'isInitialized': %w", err) | ||
} | ||
b, err := strconv.ParseBool(out) | ||
if err != nil { | ||
return false, errors.Errorf("invalid consumer plugin 'isInitialized' output, got '%s': %w", out, err) | ||
} | ||
return b, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
package plugininternal | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/ignite/cli/v28/ignite/services/plugin" | ||
"github.com/ignite/cli/v28/ignite/services/plugin/mocks" | ||
) | ||
|
||
func TestConsumerPlugin(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
args []string | ||
setup func(*testing.T, string) | ||
expectedOutput string | ||
expectedError string | ||
}{ | ||
{ | ||
name: "fail: missing arg", | ||
expectedError: "missing argument", | ||
}, | ||
{ | ||
name: "fail: invalid arg", | ||
args: []string{"xxx"}, | ||
expectedError: "invalid argument \"xxx\"", | ||
}, | ||
{ | ||
name: "fail: writeGenesis w/o priv_validator_key.json", | ||
args: []string{"writeGenesis"}, | ||
expectedError: "open .*/config/priv_validator_key.json: no such file or directory", | ||
}, | ||
{ | ||
name: "fail: writeFenesis w/o genesis.json", | ||
args: []string{"writeGenesis"}, | ||
setup: func(t *testing.T, path string) { | ||
// Add priv_validator_key.json to path | ||
bz, err := os.ReadFile("testdata/consumer/config/priv_validator_key.json") | ||
require.NoError(t, err) | ||
err = os.WriteFile(filepath.Join(path, "config", "priv_validator_key.json"), bz, 0o777) | ||
require.NoError(t, err) | ||
}, | ||
expectedError: ".*/config/genesis.json does not exist, run `init` first", | ||
}, | ||
|
||
{ | ||
name: "ok: writeGenesis", | ||
args: []string{"writeGenesis"}, | ||
setup: func(t *testing.T, path string) { | ||
// Add priv_validator_key.json to path | ||
bz, err := os.ReadFile("testdata/consumer/config/priv_validator_key.json") | ||
require.NoError(t, err) | ||
err = os.WriteFile(filepath.Join(path, "config", "priv_validator_key.json"), bz, 0o777) | ||
require.NoError(t, err) | ||
|
||
// Add genesis.json to path | ||
bz, err = os.ReadFile("testdata/consumer/config/genesis.json") | ||
require.NoError(t, err) | ||
err = os.WriteFile(filepath.Join(path, "config", "genesis.json"), bz, 0o777) | ||
require.NoError(t, err) | ||
}, | ||
}, | ||
{ | ||
name: "ok: isInitialized returns false", | ||
args: []string{"isInitialized"}, | ||
expectedOutput: "false", | ||
}, | ||
{ | ||
name: "ok: isInitialized returns true", | ||
args: []string{"isInitialized"}, | ||
setup: func(t *testing.T, path string) { | ||
// isInitialized returns true if there's a consumer genesis with an | ||
// InitialValSet length != 0 | ||
// Add priv_validator_key.json to path | ||
bz, err := os.ReadFile("testdata/consumer/config/priv_validator_key.json") | ||
require.NoError(t, err) | ||
err = os.WriteFile(filepath.Join(path, "config", "priv_validator_key.json"), bz, 0o777) | ||
require.NoError(t, err) | ||
|
||
// Add genesis.json to path | ||
bz, err = os.ReadFile("testdata/consumer/config/genesis.json") | ||
require.NoError(t, err) | ||
err = os.WriteFile(filepath.Join(path, "config", "genesis.json"), bz, 0o777) | ||
require.NoError(t, err) | ||
|
||
// Call writeGenesis to create the genesis | ||
chainer := mocks.NewChainerInterface(t) | ||
chainer.EXPECT().ID().Return("id", nil).Maybe() | ||
chainer.EXPECT().AppPath().Return("apppath").Maybe() | ||
chainer.EXPECT().ConfigPath().Return("configpath").Maybe() | ||
chainer.EXPECT().Home().Return(path, nil).Maybe() | ||
chainer.EXPECT().RPCPublicAddress().Return("rpcPublicAddress", nil).Maybe() | ||
_, err = Execute(context.Background(), consumerPlugin, []string{"writeGenesis"}, plugin.WithChain(chainer)) | ||
require.NoError(t, err) | ||
}, | ||
expectedOutput: "true", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
homePath := t.TempDir() | ||
err := os.MkdirAll(filepath.Join(homePath, "config"), 0o777) | ||
require.NoError(t, err) | ||
chainer := mocks.NewChainerInterface(t) | ||
chainer.EXPECT().ID().Return("id", nil).Maybe() | ||
chainer.EXPECT().AppPath().Return("apppath").Maybe() | ||
chainer.EXPECT().ConfigPath().Return("configpath").Maybe() | ||
chainer.EXPECT().Home().Return(homePath, nil).Maybe() | ||
chainer.EXPECT().RPCPublicAddress().Return("rpcPublicAddress", nil).Maybe() | ||
if tt.setup != nil { | ||
tt.setup(t, homePath) | ||
} | ||
|
||
out, err := Execute( | ||
context.Background(), | ||
consumerPlugin, | ||
tt.args, | ||
plugin.WithChain(chainer), | ||
) | ||
|
||
if tt.expectedError != "" { | ||
require.Error(t, err) | ||
require.Regexp(t, tt.expectedError, err.Error()) | ||
return | ||
} | ||
require.NoError(t, err) | ||
require.Equal(t, tt.expectedOutput, out) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"app_name": "test", | ||
"app_version": "", | ||
"genesis_time": "2024-01-19T10:27:44.742750573Z", | ||
"chain_id": "test", | ||
"initial_height": 1, | ||
"app_hash": null, | ||
"app_state": {} | ||
} |
11 changes: 11 additions & 0 deletions
11
ignite/internal/plugin/testdata/consumer/config/priv_validator_key.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"address": "2D3C15095E5EAA318CAEDE1C2D02C77581584751", | ||
"pub_key": { | ||
"type": "tendermint/PubKeyEd25519", | ||
"value": "uBOT+dDuUvXjJrkfwMNrS4bRT4/O+fBnpwfYpR6n1Wk=" | ||
}, | ||
"priv_key": { | ||
"type": "tendermint/PrivKeyEd25519", | ||
"value": "HovIzTJTGMrQx5oBikjfypyMZYF9QP5MxS+S+S/3QYq4E5P50O5S9eMmuR/Aw2tLhtFPj8758GenB9ilHqfVaQ==" | ||
} | ||
} |
Oops, something went wrong.