Skip to content

Commit

Permalink
test: Implemented integration tests for roller config init (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
ItayLevyOfficial authored Jun 5, 2023
1 parent 3b4099f commit a434f3c
Show file tree
Hide file tree
Showing 27 changed files with 2,138 additions and 56 deletions.
4 changes: 2 additions & 2 deletions cmd/config/init/DALightClient.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package init
package initconfig

import (
"os/exec"
"path/filepath"
)

func initializeLightNodeConfig(initConfig InitConfig) error {
initLightNodeCmd := exec.Command(celestiaExecutablePath, "light", "init", "--p2p.network", "arabica", "--node.store", filepath.Join(initConfig.Home, configDirName.DALightNode))
initLightNodeCmd := exec.Command(celestiaExecutablePath, "light", "init", "--p2p.network", "arabica", "--node.store", filepath.Join(initConfig.Home, ConfigDirName.DALightNode))
err := initLightNodeCmd.Run()
if err != nil {
return err
Expand Down
14 changes: 6 additions & 8 deletions cmd/config/init/consts.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
package init
package initconfig

var flagNames = struct {
var FlagNames = struct {
Home string
LightNodeEndpoint string
Denom string
Decimals string
RollappBinary string
HubRPC string
}{
Home: "home",
LightNodeEndpoint: "light-node-endpoint",
Denom: "denom",
Decimals: "decimals",
RollappBinary: "rollapp-binary",
HubRPC: "hub-rpc",
}

var keyNames = struct {
var KeyNames = struct {
HubSequencer string
RollappSequencer string
RollappRelayer string
Expand All @@ -40,7 +38,7 @@ var addressPrefixes = struct {
DA: "celestia",
}

var configDirName = struct {
var ConfigDirName = struct {
Rollapp string
Relayer string
DALightNode string
Expand All @@ -55,8 +53,8 @@ const defaultRollappRPC = "http://localhost:26657"
const lightNodeEndpointFlag = "light-node-endpoint"

const evmCoinType uint32 = 60
const defaultHubId = "35-C"
const relayerKeysDirName = "keys"
const DefaultHubID = "35-C"
const KeysDirName = "keys"
const cosmosDefaultCointype uint32 = 118
const celestiaExecutablePath = "/usr/local/bin/roller/lib/celestia"
const defaultRollappBinaryPath = "/usr/local/bin/roller/lib/rollapp_evm"
Expand Down
22 changes: 13 additions & 9 deletions cmd/config/init/genesis.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package init
package initconfig

import (
"io/ioutil"
Expand All @@ -13,26 +13,30 @@ import (
func initializeRollappGenesis(initConfig InitConfig) error {
zeros := initConfig.Decimals + 9
tokenAmount := "1" + fmt.Sprintf("%0*d", zeros, 0) + initConfig.Denom
rollappConfigDirPath := filepath.Join(initConfig.Home, configDirName.Rollapp)
genesisSequencerAccountCmd := exec.Command(initConfig.RollappBinary, "add-genesis-account", keyNames.RollappSequencer, tokenAmount, "--keyring-backend", "test", "--home", rollappConfigDirPath)
rollappConfigDirPath := filepath.Join(initConfig.Home, ConfigDirName.Rollapp)
genesisSequencerAccountCmd := exec.Command(initConfig.RollappBinary, "add-genesis-account", KeyNames.RollappSequencer, tokenAmount, "--keyring-backend", "test", "--home", rollappConfigDirPath)
err := genesisSequencerAccountCmd.Run()
if err != nil {
return err
}
err = updateGenesisParams(filepath.Join(rollappConfigDirPath, "config", "genesis.json"), initConfig.Denom)
err = updateGenesisParams(GetGenesisFilePath(initConfig.Home), initConfig.Denom)
if err != nil {
return err
}
return nil
}

type pathValue struct {
func GetGenesisFilePath(root string) string {
return filepath.Join(RollappConfigDir(root), "genesis.json")
}

type PathValue struct {
Path string
Value interface{}
}

func getDefaultGenesisParams(denom string) []pathValue {
return []pathValue{
func getDefaultGenesisParams(denom string) []PathValue {
return []PathValue{
{"app_state.mint.params.mint_denom", denom},
{"app_state.staking.params.bond_denom", denom},
{"app_state.crisis.constant_fee.denom", denom},
Expand All @@ -48,7 +52,7 @@ func getDefaultGenesisParams(denom string) []pathValue {
}
}

func updateJSONParams(jsonFilePath string, params []pathValue) error {
func UpdateJSONParams(jsonFilePath string, params []PathValue) error {
jsonFileContent, err := ioutil.ReadFile(jsonFilePath)
if err != nil {
return err
Expand All @@ -69,5 +73,5 @@ func updateJSONParams(jsonFilePath string, params []pathValue) error {

func updateGenesisParams(genesisFilePath string, denom string) error {
params := getDefaultGenesisParams(denom)
return updateJSONParams(genesisFilePath, params)
return UpdateJSONParams(genesisFilePath, params)
}
32 changes: 16 additions & 16 deletions cmd/config/init/init.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package init
package initconfig

import (
"github.com/spf13/cobra"
Expand All @@ -21,7 +21,7 @@ func InitCmd() *cobra.Command {
Run: func(cmd *cobra.Command, args []string) {
rollappId := args[0]
denom := args[1]
home := cmd.Flag(flagNames.Home).Value.String()
home := cmd.Flag(FlagNames.Home).Value.String()
createLightNode := !cmd.Flags().Changed(lightNodeEndpointFlag)
rollappBinaryPath := getRollappBinaryPath(cmd)
decimals := getDecimals(cmd)
Expand All @@ -31,7 +31,7 @@ func InitCmd() *cobra.Command {
RollappBinary: rollappBinaryPath,
CreateDALightNode: createLightNode,
Denom: denom,
HubID: defaultHubId,
HubID: DefaultHubID,
Decimals: decimals,
}

Expand All @@ -52,16 +52,16 @@ func InitCmd() *cobra.Command {
Denom: denom,
AddressPrefix: addressPrefixes.Rollapp,
}, ChainConfig{
ID: defaultHubId,
RPC: cmd.Flag(flagNames.HubRPC).Value.String(),
ID: DefaultHubID,
RPC: cmd.Flag(FlagNames.HubRPC).Value.String(),
Denom: "udym",
AddressPrefix: addressPrefixes.Hub,
}, initConfig); err != nil {
panic(err)
}
celestiaAddress := addresses[keyNames.DALightNode]
rollappHubAddress := addresses[keyNames.HubSequencer]
relayerHubAddress := addresses[keyNames.HubRelayer]
celestiaAddress := addresses[KeyNames.DALightNode]
rollappHubAddress := addresses[KeyNames.HubSequencer]
relayerHubAddress := addresses[KeyNames.HubRelayer]
printInitOutput(AddressesToFund{
DA: celestiaAddress,
HubSequencer: rollappHubAddress,
Expand All @@ -76,15 +76,15 @@ func InitCmd() *cobra.Command {
}

func addFlags(cmd *cobra.Command) {
cmd.Flags().StringP(flagNames.HubRPC, "", defaultHubRPC, "Dymension Hub rpc endpoint")
cmd.Flags().StringP(flagNames.LightNodeEndpoint, "", "", "The data availability light node endpoint. Runs an Arabica Celestia light node if not provided")
cmd.Flags().StringP(flagNames.RollappBinary, "", "", "The rollapp binary. Should be passed only if you built a custom rollapp")
cmd.Flags().Uint64P(flagNames.Decimals, "", 18, "The number of decimal places a rollapp token supports")
cmd.Flags().StringP(flagNames.Home, "", getRollerRootDir(), "The directory of the roller config files")
cmd.Flags().StringP(FlagNames.HubRPC, "", defaultHubRPC, "Dymension Hub rpc endpoint")
cmd.Flags().StringP(FlagNames.LightNodeEndpoint, "", "", "The data availability light node endpoint. Runs an Arabica Celestia light node if not provided")
cmd.Flags().StringP(FlagNames.RollappBinary, "", "", "The rollapp binary. Should be passed only if you built a custom rollapp")
cmd.Flags().Uint64P(FlagNames.Decimals, "", 18, "The number of decimal places a rollapp token supports")
cmd.Flags().StringP(FlagNames.Home, "", getRollerRootDir(), "The directory of the roller config files")
}

func getDecimals(cmd *cobra.Command) uint64 {
decimals, err := cmd.Flags().GetUint64(flagNames.Decimals)
decimals, err := cmd.Flags().GetUint64(FlagNames.Decimals)
if err != nil {
panic(err)
}
Expand All @@ -99,7 +99,7 @@ func initializeKeys(initConfig InitConfig) map[string]string {
}
return addresses
} else {
addresses, err := generateKeys(initConfig, keyNames.DALightNode)
addresses, err := generateKeys(initConfig, KeyNames.DALightNode)
if err != nil {
panic(err)
}
Expand All @@ -108,7 +108,7 @@ func initializeKeys(initConfig InitConfig) map[string]string {
}

func getRollappBinaryPath(cmd *cobra.Command) string {
rollappBinaryPath := cmd.Flag(flagNames.RollappBinary).Value.String()
rollappBinaryPath := cmd.Flag(FlagNames.RollappBinary).Value.String()
if rollappBinaryPath == "" {
return defaultRollappBinaryPath
}
Expand Down
22 changes: 11 additions & 11 deletions cmd/config/init/keys.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package init
package initconfig

import (
"path"
Expand Down Expand Up @@ -69,32 +69,32 @@ func createKey(keyConfig KeyConfig, home string) (keyring.Info, error) {
func getDefaultKeysConfig(initConfig InitConfig) []KeyConfig {
return []KeyConfig{
{
dir: configDirName.Rollapp,
keyId: keyNames.HubSequencer,
dir: ConfigDirName.Rollapp,
keyId: KeyNames.HubSequencer,
coinType: cosmosDefaultCointype,
prefix: addressPrefixes.Hub,
},
{
dir: configDirName.Rollapp,
keyId: keyNames.RollappSequencer,
dir: ConfigDirName.Rollapp,
keyId: KeyNames.RollappSequencer,
coinType: evmCoinType,
prefix: addressPrefixes.Rollapp,
},
{
dir: path.Join(configDirName.Relayer, relayerKeysDirName, initConfig.RollappID),
keyId: keyNames.HubRelayer,
dir: path.Join(ConfigDirName.Relayer, KeysDirName, initConfig.HubID),
keyId: KeyNames.HubRelayer,
coinType: cosmosDefaultCointype,
prefix: addressPrefixes.Hub,
},
{
dir: path.Join(configDirName.Relayer, relayerKeysDirName, initConfig.HubID),
keyId: keyNames.RollappRelayer,
dir: path.Join(ConfigDirName.Relayer, KeysDirName, initConfig.RollappID),
keyId: KeyNames.RollappRelayer,
coinType: evmCoinType,
prefix: addressPrefixes.Rollapp,
}, {

dir: path.Join(configDirName.DALightNode, relayerKeysDirName),
keyId: keyNames.DALightNode,
dir: path.Join(ConfigDirName.DALightNode, KeysDirName),
keyId: KeyNames.DALightNode,
coinType: cosmosDefaultCointype,
prefix: addressPrefixes.DA,
},
Expand Down
4 changes: 2 additions & 2 deletions cmd/config/init/output.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package init
package initconfig

import (
"os"
Expand All @@ -14,7 +14,7 @@ type AddressesToFund struct {
}

func printInitOutput(addresses AddressesToFund, rollappId string) {
color.New(color.FgCyan, color.Bold).Printf("🚀 RollApp '%s' configuration files have been successfully generated on your local machine. Congratulations!\n\n", rollappId)
color.New(color.FgCyan, color.Bold).Printf("💈 RollApp '%s' configuration files have been successfully generated on your local machine. Congratulations!\n\n", rollappId)
color.New(color.FgGreen, color.Bold).Printf("🔑 Key Details:\n\n")

data := [][]string{
Expand Down
8 changes: 4 additions & 4 deletions cmd/config/init/relayer.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package init
package initconfig

import (
"encoding/json"
Expand Down Expand Up @@ -95,14 +95,14 @@ func addChainsConfig(rollappConfig ChainConfig, hubConfig ChainConfig, relayerHo
ChainConfig: rollappConfig,
GasPrices: "0.0" + rollappConfig.Denom,
ClientType: "01-dymint",
KeyName: keyNames.RollappRelayer,
KeyName: KeyNames.RollappRelayer,
})

relayerHubConfig := getRelayerFileChainConfig(RelayerChainConfig{
ChainConfig: hubConfig,
GasPrices: "0.25" + hubConfig.Denom,
ClientType: "07-tendermint",
KeyName: keyNames.HubRelayer,
KeyName: KeyNames.HubRelayer,
})

if err := addChainToRelayer(relayerRollappConfig, relayerHome); err != nil {
Expand All @@ -128,7 +128,7 @@ func setupPath(rollappConfig ChainConfig, hubConfig ChainConfig, relayerHome str
}

func initializeRelayerConfig(rollappConfig ChainConfig, hubConfig ChainConfig, initConfig InitConfig) error {
relayerHome := filepath.Join(initConfig.Home, configDirName.Relayer)
relayerHome := filepath.Join(initConfig.Home, ConfigDirName.Relayer)
if err := initRelayer(relayerHome); err != nil {
return err
}
Expand Down
10 changes: 7 additions & 3 deletions cmd/config/init/rollapp.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package init
package initconfig

import (
"os"
Expand All @@ -9,12 +9,12 @@ import (
)

func initializeRollappConfig(initConfig InitConfig) {
initRollappCmd := exec.Command(initConfig.RollappBinary, "init", keyNames.HubSequencer, "--chain-id", initConfig.RollappID, "--home", filepath.Join(initConfig.Home, configDirName.Rollapp))
initRollappCmd := exec.Command(initConfig.RollappBinary, "init", KeyNames.HubSequencer, "--chain-id", initConfig.RollappID, "--home", filepath.Join(initConfig.Home, ConfigDirName.Rollapp))
err := initRollappCmd.Run()
if err != nil {
panic(err)
}
setRollappAppConfig(filepath.Join(initConfig.Home, configDirName.Rollapp, "config/app.toml"), initConfig.Denom)
setRollappAppConfig(filepath.Join(initConfig.Home, ConfigDirName.Rollapp, "config/app.toml"), initConfig.Denom)
}

func setRollappAppConfig(appConfigFilePath string, denom string) {
Expand All @@ -28,3 +28,7 @@ func setRollappAppConfig(appConfigFilePath string, denom string) {
}
file.Close()
}

func RollappConfigDir(root string) string {
return filepath.Join(root, ConfigDirName.Rollapp, "config")
}
2 changes: 1 addition & 1 deletion cmd/config/init/utils.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package init
package initconfig

import (
"os"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
global:
api-listen-addr: :5183
timeout: 10s
memo: ""
light-cache-size: 20
chains:
35-C:
type: cosmos
value:
key: relayer-hub-key
chain-id: 35-C
rpc-addr: https://rpc-hub-35c.dymension.xyz:443
account-prefix: dym
keyring-backend: test
gas-adjustment: 1.2
gas-prices: 0.25udym
debug: true
timeout: 10s
output-format: json
sign-mode: direct
client-type: 07-tendermint
mars:
type: cosmos
value:
key: relayer-rollapp-key
chain-id: mars
rpc-addr: http://localhost:26657
account-prefix: rol
keyring-backend: test
gas-adjustment: 1.2
gas-prices: 0.0udym
debug: true
timeout: 10s
output-format: json
sign-mode: direct
client-type: 01-dymint
paths:
hub-rollapp:
src:
chain-id: mars
dst:
chain-id: 35-C
src-channel-filter:
rule: ""
channel-list: []
settlement: 35-C
Loading

0 comments on commit a434f3c

Please sign in to comment.