Skip to content

Commit

Permalink
fix genesis time and toml updating
Browse files Browse the repository at this point in the history
  • Loading branch information
yito88 committed Nov 11, 2024
1 parent 08dda03 commit 86c62e8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 21 deletions.
38 changes: 22 additions & 16 deletions chain/namada/namada_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (c *NamadaChain) Start(testName string, ctx context.Context, additionalGene
return err
}

if err := testutil.WaitForBlocks(ctx, 2, c.Validators[0]); err != nil {
if err := testutil.WaitForBlocks(ctx, 2, c.getNode()); err != nil {
return err
}

Expand All @@ -197,9 +197,13 @@ func (c *NamadaChain) Start(testName string, ctx context.Context, additionalGene
return nil
}

func (c *NamadaChain) getNode() *NamadaNode {
return c.Validators[0]
}

// Execute a command.
func (c *NamadaChain) Exec(ctx context.Context, cmd []string, env []string) (stdout, stderr []byte, err error) {
return c.Validators[0].Exec(ctx, cmd, env)
return c.getNode().Exec(ctx, cmd, env)
}

// Exports the chain state at the specific height.
Expand All @@ -209,23 +213,23 @@ func (c *NamadaChain) ExportState(ctx context.Context, height int64) (string, er

// Get the RPC address.
func (c *NamadaChain) GetRPCAddress() string {
return fmt.Sprintf("http://%s:26657", c.Validators[0].HostName())
return fmt.Sprintf("http://%s:26657", c.getNode().HostName())
}

// Get the gRPC address. This isn't used for Namada.
func (c *NamadaChain) GetGRPCAddress() string {
// Returns a dummy address because Namada doesn't support gRPC
return fmt.Sprintf("http://%s:9090", c.Validators[0].HostName())
return fmt.Sprintf("http://%s:9090", c.getNode().HostName())
}

// Get the host RPC address.
func (c *NamadaChain) GetHostRPCAddress() string {
return "http://" + c.Validators[0].hostRPCPort
return "http://" + c.getNode().hostRPCPort
}

// Get the host peer address.
func (c *NamadaChain) GetHostPeerAddress() string {
return c.Validators[0].hostP2PPort
return c.getNode().hostP2PPort
}

// Get the host gRPC address.
Expand All @@ -235,7 +239,7 @@ func (c *NamadaChain) GetHostGRPCAddress() string {

// Get Namada home directory.
func (c *NamadaChain) HomeDir() string {
return c.Validators[0].HomeDir()
return c.getNode().HomeDir()
}

// Create a test key.
Expand Down Expand Up @@ -488,7 +492,7 @@ func (c *NamadaChain) SendIBCTransfer(ctx context.Context, channelID, keyName st
GasSpent: gas,
}

results, err := c.Validators[0].Client.BlockResults(ctx, &height)
results, err := c.getNode().Client.BlockResults(ctx, &height)
if err != nil {
return ibc.Tx{}, fmt.Errorf("checking the events failed: %v", err)
}
Expand Down Expand Up @@ -617,7 +621,7 @@ func (c *NamadaChain) GenIbcShieldingTransfer(ctx context.Context, channelID str
return "", fmt.Errorf("failed to get the file path of the IBC shielding transfer")
}
relPath, _ := filepath.Rel(c.HomeDir(), path)
shieldingTransfer, err := c.Validators[0].ReadFile(ctx, relPath)
shieldingTransfer, err := c.getNode().ReadFile(ctx, relPath)
if err != nil {
return "", fmt.Errorf("failed to read the IBC shielding transfer file: %v", err)
}
Expand All @@ -627,7 +631,7 @@ func (c *NamadaChain) GenIbcShieldingTransfer(ctx context.Context, channelID str

// Get the current block height.
func (c *NamadaChain) Height(ctx context.Context) (int64, error) {
return c.Validators[0].Height(ctx)
return c.getNode().Height(ctx)
}

// Get the balance with the key alias, not the address.
Expand Down Expand Up @@ -667,6 +671,7 @@ func (c *NamadaChain) GetBalance(ctx context.Context, keyName string, denom stri
}
outputStr := string(output)
lines := strings.Split(outputStr, "\n")
// Parse the balance from the output like `nam: 1000.000000`
re := regexp.MustCompile(`:\s*(\d+(\.\d+)?)$`)

ret := math.NewInt(0)
Expand Down Expand Up @@ -875,7 +880,7 @@ func (c *NamadaChain) downloadTemplates(ctx context.Context) error {
if _, err := io.Copy(&buf, resp.Body); err != nil {
return fmt.Errorf("failed to read the file: %w", err)
}
err = c.Validators[0].writeFile(ctx, filepath.Join(destDir, file), buf.Bytes())
err = c.getNode().writeFile(ctx, filepath.Join(destDir, file), buf.Bytes())
if err != nil {
return fmt.Errorf("failed to write the file %s: %w", file, err)
}
Expand Down Expand Up @@ -941,7 +946,7 @@ func (c *NamadaChain) downloadWasms(ctx context.Context) error {
return fmt.Errorf("failed to read the file: %w", err)
}
fileName := filepath.Base(header.Name)
err = c.Validators[0].writeFile(ctx, filepath.Join(destDir, fileName), buf.Bytes())
err = c.getNode().writeFile(ctx, filepath.Join(destDir, fileName), buf.Bytes())
if err != nil {
return fmt.Errorf("failed to write the file: %w", err)
}
Expand Down Expand Up @@ -1217,6 +1222,7 @@ func (c *NamadaChain) initNetwork(ctx context.Context) error {
templatesDir := filepath.Join(c.HomeDir(), "templates")
wasmDir := filepath.Join(c.HomeDir(), "wasm")
checksumsPath := filepath.Join(wasmDir, "checksums.json")
genesisTime := time.Now().UTC().Format("2006-01-02T15:04:05.000000000-07:00")
cmd := []string{
"namadac",
"--base-dir",
Expand All @@ -1232,7 +1238,7 @@ func (c *NamadaChain) initNetwork(ctx context.Context) error {
"--wasm-dir",
wasmDir,
"--genesis-time",
"2023-08-30T00:00:00.000000000+00:00",
genesisTime,
"--archive-dir",
c.HomeDir(),
}
Expand All @@ -1254,7 +1260,7 @@ func (c *NamadaChain) initNetwork(ctx context.Context) error {

func (c *NamadaChain) copyGenesisFiles(ctx context.Context, n *NamadaNode) error {
archivePath := fmt.Sprintf("%s.tar.gz", c.Config().ChainID)
content, err := c.Validators[0].ReadFile(ctx, archivePath)
content, err := c.getNode().ReadFile(ctx, archivePath)
if err != nil {
return fmt.Errorf("failed to read the archive file: %w", err)
}
Expand All @@ -1265,7 +1271,7 @@ func (c *NamadaChain) copyGenesisFiles(ctx context.Context, n *NamadaNode) error
}

walletPath := filepath.Join("pre-genesis", "wallet.toml")
content, err = c.Validators[0].ReadFile(ctx, walletPath)
content, err = c.getNode().ReadFile(ctx, walletPath)
if err != nil {
return fmt.Errorf("failed to read the wallet file: %w", err)
}
Expand All @@ -1277,7 +1283,7 @@ func (c *NamadaChain) copyGenesisFiles(ctx context.Context, n *NamadaNode) error
if n.Validator {
validatorAlias := fmt.Sprintf("validator-%d", n.Index)
validatorWalletPath := filepath.Join("pre-genesis", validatorAlias, "validator-wallet.toml")
content, err = c.Validators[0].ReadFile(ctx, validatorWalletPath)
content, err = c.getNode().ReadFile(ctx, validatorWalletPath)
if err != nil {
return fmt.Errorf("failed to read the validator wallet file: %w", err)
}
Expand Down
10 changes: 8 additions & 2 deletions chain/namada/namada_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/strangelove-ventures/interchaintest/v8/dockerutil"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
"github.com/strangelove-ventures/interchaintest/v8/testutil"
)

type NamadaNode struct {
Expand Down Expand Up @@ -181,7 +182,12 @@ func (n *NamadaNode) CreateContainer(ctx context.Context) error {
joinNetworkCmd += " --genesis-validator " + fmt.Sprintf("validator-%d", n.Index)
}

updateCmd := fmt.Sprintf(`sed -i s/127.0.0.1:26657/0.0.0.0:26657/g %s/%s/config.toml`, n.HomeDir(), n.Chain.Config().ChainID)
configPath := fmt.Sprintf("%s/%s/config.toml", n.HomeDir(), n.Chain.Config().ChainID)
c := make(testutil.Toml)
p2p := make(testutil.Toml)
p2p["laddr"] = "0.0.0.0:26657"
c["ledger.cometbft.p2p"] = p2p
testutil.ModifyTomlConfigFile(ctx, n.logger(), n.DockerClient, n.TestName, n.VolumeName, configPath, c)

mvCmd := "echo 'starting a validator node'"
if !n.Validator {
Expand All @@ -193,7 +199,7 @@ func (n *NamadaNode) CreateContainer(ctx context.Context) error {
cmd := []string{
"sh",
"-c",
fmt.Sprintf(`%s && %s && %s && %s`, joinNetworkCmd, updateCmd, mvCmd, ledgerCmd),
fmt.Sprintf(`%s && %s && %s`, joinNetworkCmd, mvCmd, ledgerCmd),
}

exposedPorts := nat.PortMap{
Expand Down
14 changes: 11 additions & 3 deletions relayer/hermes/hermes_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"strconv"
"strings"

"github.com/strangelove-ventures/interchaintest/v8/ibc"
)

// NewConfig returns a hermes Config with an entry for each of the provided ChainConfigs.
Expand All @@ -22,12 +24,12 @@ func NewConfig(chainConfigs ...ChainConfig) Config {
var accountPrefix string
var trustingPeriod string
switch chainCfg.Type {
case "namada":
chainType = "Namada"
case ibc.Namada:
chainType = Namada
accountPrefix = ""
trustingPeriod = "1000s"
default:
chainType = "CosmosSdk"
chainType = Cosmos
accountPrefix = chainCfg.Bech32Prefix
trustingPeriod = "14days"
}
Expand Down Expand Up @@ -106,6 +108,12 @@ func NewConfig(chainConfigs ...ChainConfig) Config {
}
}

// Chain type for Hermes, currently only `CosmosSdk` or `Namada` is supported.
const (
Cosmos = "CosmosSdk"
Namada = "Namada"
)

type Config struct {
Global Global `toml:"global"`
Mode Mode `toml:"mode"`
Expand Down

0 comments on commit 86c62e8

Please sign in to comment.