From e0c90b0b996bcea788868accdd04aca070b0a8bd Mon Sep 17 00:00:00 2001 From: Reece Williams <31943163+Reecepbcups@users.noreply.github.com> Date: Fri, 5 Jul 2024 17:49:00 -0500 Subject: [PATCH] refactor: use prettier `ReadFile` instead of `NewFileRetriever.SingleFileContent` (#1161) --- chain/cosmos/chain_node.go | 3 +-- chain/internal/tendermint/tendermint_node.go | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/chain/cosmos/chain_node.go b/chain/cosmos/chain_node.go index 00e46ac39..92a006da4 100644 --- a/chain/cosmos/chain_node.go +++ b/chain/cosmos/chain_node.go @@ -260,8 +260,7 @@ func (tn *ChainNode) OverwriteGenesisFile(ctx context.Context, content []byte) e } func (tn *ChainNode) PrivValFileContent(ctx context.Context) ([]byte, error) { - fr := dockerutil.NewFileRetriever(tn.logger(), tn.DockerClient, tn.TestName) - gen, err := fr.SingleFileContent(ctx, tn.VolumeName, "config/priv_validator_key.json") + gen, err := tn.ReadFile(ctx, "config/priv_validator_key.json") if err != nil { return nil, fmt.Errorf("getting priv_validator_key.json content: %w", err) } diff --git a/chain/internal/tendermint/tendermint_node.go b/chain/internal/tendermint/tendermint_node.go index d334a7f8a..27f2226a4 100644 --- a/chain/internal/tendermint/tendermint_node.go +++ b/chain/internal/tendermint/tendermint_node.go @@ -132,8 +132,7 @@ func (tn *TendermintNode) HostName() string { } func (tn *TendermintNode) GenesisFileContent(ctx context.Context) ([]byte, error) { - fr := dockerutil.NewFileRetriever(tn.logger(), tn.DockerClient, tn.TestName) - gen, err := fr.SingleFileContent(ctx, tn.VolumeName, "config/genesis.json") + gen, err := tn.ReadFile(ctx, "config/genesis.json") if err != nil { return nil, fmt.Errorf("getting genesis.json content: %w", err) } @@ -141,6 +140,17 @@ func (tn *TendermintNode) GenesisFileContent(ctx context.Context) ([]byte, error return gen, nil } +// ReadFile reads the contents of a single file at the specified path in the docker filesystem. +// relPath describes the location of the file in the docker volume relative to the home directory. +func (tn *TendermintNode) ReadFile(ctx context.Context, relPath string) ([]byte, error) { + fr := dockerutil.NewFileRetriever(tn.logger(), tn.DockerClient, tn.TestName) + gen, err := fr.SingleFileContent(ctx, tn.VolumeName, relPath) + if err != nil { + return nil, fmt.Errorf("failed to read file at %s: %w", relPath, err) + } + return gen, nil +} + func (tn *TendermintNode) OverwriteGenesisFile(ctx context.Context, content []byte) error { fw := dockerutil.NewFileWriter(tn.logger(), tn.DockerClient, tn.TestName) if err := fw.WriteFile(ctx, tn.VolumeName, "config/genesis.json", content); err != nil { @@ -315,10 +325,9 @@ func (tn *TendermintNode) NodeID(ctx context.Context) (string, error) { // This used to call p2p.LoadNodeKey against the file on the host, // but because we are transitioning to operating on Docker volumes, // we only have to tmjson.Unmarshal the raw content. - fr := dockerutil.NewFileRetriever(tn.logger(), tn.DockerClient, tn.TestName) - j, err := fr.SingleFileContent(ctx, tn.VolumeName, "config/node_key.json") + j, err := tn.ReadFile(ctx, "config/node_key.json") if err != nil { - return "", fmt.Errorf("getting node_key.json content: %w", err) + return "", fmt.Errorf("getting genesis.json content: %w", err) } var nk p2p.NodeKey