Skip to content

Commit

Permalink
feat(utxo): Add support for utxo chains (#1220)
Browse files Browse the repository at this point in the history
* Add support for utxo chains

* remove copy paste comment

* remove unnecessary config items

* Check for keyname entry in keystore map
  • Loading branch information
misko9 authored Aug 15, 2024
1 parent c48b82d commit be814e8
Show file tree
Hide file tree
Showing 25 changed files with 1,527 additions and 19 deletions.
2 changes: 1 addition & 1 deletion chain/cosmos/chain_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,7 @@ func (tn *ChainNode) CreateNodeContainer(ctx context.Context) error {
fmt.Printf("Port Overrides: %v. Using: %v\n", chainCfg.HostPortOverride, usingPorts)
}

return tn.containerLifecycle.CreateContainer(ctx, tn.TestName, tn.NetworkID, tn.Image, usingPorts, tn.Bind(), nil, tn.HostName(), cmd, chainCfg.Env)
return tn.containerLifecycle.CreateContainer(ctx, tn.TestName, tn.NetworkID, tn.Image, usingPorts, tn.Bind(), nil, tn.HostName(), cmd, chainCfg.Env, []string{})
}

func (tn *ChainNode) StartContainer(ctx context.Context) error {
Expand Down
5 changes: 5 additions & 0 deletions chain/cosmos/cosmos_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,11 @@ func (c *CosmosChain) SendFunds(ctx context.Context, keyName string, amount ibc.
return c.getFullNode().BankSend(ctx, keyName, amount)
}

// Implements Chain interface
func (c *CosmosChain) SendFundsWithNote(ctx context.Context, keyName string, amount ibc.WalletAmount, note string) (string, error) {
return c.getFullNode().BankSendWithNote(ctx, keyName, amount, note)
}

// Implements Chain interface
func (c *CosmosChain) SendIBCTransfer(
ctx context.Context,
Expand Down
6 changes: 6 additions & 0 deletions chain/cosmos/module_bank.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ func (tn *ChainNode) BankSend(ctx context.Context, keyName string, amount ibc.Wa
return err
}

// BankSend sends tokens from one account to another.
func (tn *ChainNode) BankSendWithNote(ctx context.Context, keyName string, amount ibc.WalletAmount, note string) (string, error) {
return tn.ExecTx(ctx, keyName, "bank", "send", keyName, amount.Address,
fmt.Sprintf("%s%s", amount.Amount.String(), amount.Denom), "--note", note)
}

// Deprecated: use BankSend instead
func (tn *ChainNode) SendFunds(ctx context.Context, keyName string, amount ibc.WalletAmount) error {
return tn.BankSend(ctx, keyName, amount)
Expand Down
2 changes: 1 addition & 1 deletion chain/cosmos/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (s *SidecarProcess) logger() *zap.Logger {
}

func (s *SidecarProcess) CreateContainer(ctx context.Context) error {
return s.containerLifecycle.CreateContainer(ctx, s.TestName, s.NetworkID, s.Image, s.ports, s.Bind(), nil, s.HostName(), s.startCmd, s.env)
return s.containerLifecycle.CreateContainer(ctx, s.TestName, s.NetworkID, s.Image, s.ports, s.Bind(), nil, s.HostName(), s.startCmd, s.env, []string{})
}

func (s *SidecarProcess) StartContainer(ctx context.Context) error {
Expand Down
56 changes: 53 additions & 3 deletions chain/ethereum/ethererum_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/docker/docker/api/types/volume"
dockerclient "github.com/docker/docker/client"
"github.com/docker/go-connections/nat"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/strangelove-ventures/interchaintest/v8/dockerutil"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
"github.com/strangelove-ventures/interchaintest/v8/testutil"
Expand Down Expand Up @@ -222,7 +223,7 @@ func (c *EthereumChain) Start(testName string, ctx context.Context, additionalGe
fmt.Printf("Port Overrides: %v. Using: %v\n", c.cfg.HostPortOverride, usingPorts)
}

err := c.containerLifecycle.CreateContainer(ctx, c.testName, c.NetworkID, c.cfg.Images[0], usingPorts, c.Bind(), mounts, c.HostName(), cmd, nil)
err := c.containerLifecycle.CreateContainer(ctx, c.testName, c.NetworkID, c.cfg.Images[0], usingPorts, c.Bind(), mounts, c.HostName(), cmd, nil, []string{})
if err != nil {
return err
}
Expand Down Expand Up @@ -298,6 +299,11 @@ func (c *EthereumChain) CreateKey(ctx context.Context, keyName string) error {
return err
}

_, ok := c.keystoreMap[keyName]
if ok {
return fmt.Errorf("Keyname (%s) already used", keyName)
}

cmd := []string{"cast", "wallet", "new", c.KeystoreDir(), "--unsafe-password", "", "--json"}
stdout, _, err := c.Exec(ctx, cmd, nil)
if err != nil {
Expand All @@ -317,8 +323,12 @@ func (c *EthereumChain) CreateKey(ctx context.Context, keyName string) error {

// Get address of account, cast to a string to use
func (c *EthereumChain) GetAddress(ctx context.Context, keyName string) ([]byte, error) {
keystore, ok := c.keystoreMap[keyName]
if !ok {
return nil, fmt.Errorf("Keyname (%s) not found", keyName)
}

cmd := []string{"cast", "wallet", "address", "--keystore", c.keystoreMap[keyName], "--password", ""}
cmd := []string{"cast", "wallet", "address", "--keystore", keystore, "--password", ""}
stdout, _, err := c.Exec(ctx, cmd, nil)
if err != nil {
return nil, err
Expand All @@ -335,8 +345,12 @@ func (c *EthereumChain) SendFunds(ctx context.Context, keyName string, amount ib
)

} else {
keystore, ok := c.keystoreMap[keyName]
if !ok {
return fmt.Errorf("keyname (%s) not found", keyName)
}
cmd = append(cmd,
"--keystore", c.keystoreMap[keyName],
"--keystore", keystore,
"--password", "",
"--rpc-url", c.GetRPCAddress(),
)
Expand All @@ -345,6 +359,42 @@ func (c *EthereumChain) SendFunds(ctx context.Context, keyName string, amount ib
return err
}

type TransactionReceipt struct {
TxHash string `json:"transactionHash"`
}

func (c *EthereumChain) SendFundsWithNote(ctx context.Context, keyName string, amount ibc.WalletAmount, note string) (string, error) {
cmd := []string{"cast", "send", amount.Address, hexutil.Encode([]byte(note)), "--value", amount.Amount.String(), "--json"}
if keyName == "faucet" {
cmd = append(cmd,
"--private-key", "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
"--rpc-url", c.GetRPCAddress(),
)

} else {
keystore, ok := c.keystoreMap[keyName]
if !ok {
return "", fmt.Errorf("Keyname (%s) not found", keyName)
}
cmd = append(cmd,
"--keystore", keystore,
"--password", "",
"--rpc-url", c.GetRPCAddress(),
)
}
stdout, _, err := c.Exec(ctx, cmd, nil)
if err != nil {
return "", err
}

var txReceipt TransactionReceipt
if err = json.Unmarshal(stdout, &txReceipt); err != nil {
return "", err
}

return txReceipt.TxHash, nil
}

func (c *EthereumChain) Height(ctx context.Context) (int64, error) {
cmd := []string{"cast", "block-number", "--rpc-url", c.GetRPCAddress()}
stdout, _, err := c.Exec(ctx, cmd, nil)
Expand Down
2 changes: 1 addition & 1 deletion chain/internal/tendermint/tendermint_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func (tn *TendermintNode) CreateNodeContainer(ctx context.Context, additionalFla
cmd := []string{chainCfg.Bin, "start", "--home", tn.HomeDir()}
cmd = append(cmd, additionalFlags...)

return tn.containerLifecycle.CreateContainer(ctx, tn.TestName, tn.NetworkID, tn.Image, sentryPorts, tn.Bind(), nil, tn.HostName(), cmd, nil)
return tn.containerLifecycle.CreateContainer(ctx, tn.TestName, tn.NetworkID, tn.Image, sentryPorts, tn.Bind(), nil, tn.HostName(), cmd, nil, []string{})
}

func (tn *TendermintNode) StopContainer(ctx context.Context) error {
Expand Down
2 changes: 1 addition & 1 deletion chain/penumbra/penumbra_app_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func (p *PenumbraAppNode) CreateNodeContainer(ctx context.Context, tendermintAdd
"--home", p.HomeDir(),
}

return p.containerLifecycle.CreateContainer(ctx, p.TestName, p.NetworkID, p.Image, exposedPorts, p.Bind(), nil, p.HostName(), cmd, p.Chain.Config().Env)
return p.containerLifecycle.CreateContainer(ctx, p.TestName, p.NetworkID, p.Image, exposedPorts, p.Bind(), nil, p.HostName(), cmd, p.Chain.Config().Env, []string{})
}

// StopContainer stops the running container for the PenumbraAppNode.
Expand Down
7 changes: 7 additions & 0 deletions chain/penumbra/penumbra_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,13 @@ func (c *PenumbraChain) SendFunds(ctx context.Context, keyName string, amount ib
return fn.PenumbraClientNodes[keyName].SendFunds(ctx, amount)
}


// SendFundsWithNote will initiate a local transfer from the account associated with the specified keyName,
// amount, token denom, and recipient are specified in the amount and attach a note/memo
func (c *PenumbraChain) SendFundsWithNote(ctx context.Context, keyName string, amount ibc.WalletAmount, note string) (string, error) {
panic("Penumbrachain: SendFundsWithNote unimplemented")
}

// SendIBCTransfer attempts to send a fungible token transfer via IBC from the specified account on the source chain
// to the specified account on the counterparty chain.
func (c *PenumbraChain) SendIBCTransfer(
Expand Down
2 changes: 1 addition & 1 deletion chain/penumbra/penumbra_client_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ func (p *PenumbraClientNode) CreateNodeContainer(ctx context.Context) error {
"start",
}

return p.containerLifecycle.CreateContainer(ctx, p.TestName, p.NetworkID, p.Image, pclientdPorts, p.Bind(), nil, p.HostName(), cmd, p.Chain.Config().Env)
return p.containerLifecycle.CreateContainer(ctx, p.TestName, p.NetworkID, p.Image, pclientdPorts, p.Bind(), nil, p.HostName(), cmd, p.Chain.Config().Env, []string{})
}

// StopContainer stops the container associated with the PenumbraClientNode.
Expand Down
2 changes: 1 addition & 1 deletion chain/polkadot/parachain_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func (pn *ParachainNode) CreateNodeContainer(ctx context.Context) error {
cmd = append(cmd, "--", fmt.Sprintf("--chain=%s", pn.RawRelayChainSpecFilePathFull()))
cmd = append(cmd, pn.RelayChainFlags...)

return pn.containerLifecycle.CreateContainer(ctx, pn.TestName, pn.NetworkID, pn.Image, exposedPorts, pn.Bind(), nil, pn.HostName(), cmd, nil)
return pn.containerLifecycle.CreateContainer(ctx, pn.TestName, pn.NetworkID, pn.Image, exposedPorts, pn.Bind(), nil, pn.HostName(), cmd, nil, []string{})
}

// StopContainer stops the relay chain node container, waiting at most 30 seconds.
Expand Down
6 changes: 6 additions & 0 deletions chain/polkadot/polkadot_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,12 @@ func (c *PolkadotChain) SendFunds(ctx context.Context, keyName string, amount ib
return c.ParachainNodes[0][0].SendFunds(ctx, keyName, amount)
}

// SendFundsWithNote sends funds to a wallet from a user account with a note/memo.
// Implements Chain interface.
func (c *PolkadotChain) SendFundsWithNote(ctx context.Context, keyName string, amount ibc.WalletAmount, note string) (string, error) {
panic("PolkadotChain: SendFundsWithNote unimplemented")
}

// SendIBCTransfer sends an IBC transfer returning a transaction or an error if the transfer failed.
// Implements Chain interface.
func (c *PolkadotChain) SendIBCTransfer(
Expand Down
2 changes: 1 addition & 1 deletion chain/polkadot/relay_chain_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func (p *RelayChainNode) CreateNodeContainer(ctx context.Context) error {
fmt.Sprintf("--public-addr=%s", multiAddress),
"--base-path", p.NodeHome(),
}
return p.containerLifecycle.CreateContainer(ctx, p.TestName, p.NetworkID, p.Image, exposedPorts, p.Bind(), nil, p.HostName(), cmd, nil)
return p.containerLifecycle.CreateContainer(ctx, p.TestName, p.NetworkID, p.Image, exposedPorts, p.Bind(), nil, p.HostName(), cmd, nil, []string{})
}

// StopContainer stops the relay chain node container, waiting at most 30 seconds.
Expand Down
Loading

0 comments on commit be814e8

Please sign in to comment.