Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: ICS v5 (IBC v8) #1088

Merged
merged 17 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright 2024 Strangelove Crypto, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
61 changes: 61 additions & 0 deletions chain/cosmos/chain_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"math/rand"
"os"
"path"
"path/filepath"
"strconv"
"strings"
"sync"
Expand All @@ -35,11 +36,13 @@ import (
dockerclient "github.com/docker/docker/client"
"github.com/docker/go-connections/nat"
"go.uber.org/zap"
"golang.org/x/mod/semver"
"golang.org/x/sync/errgroup"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types"
ccvclient "github.com/cosmos/interchain-security/v5/x/ccv/provider/client"
"github.com/strangelove-ventures/interchaintest/v8/blockdb"
"github.com/strangelove-ventures/interchaintest/v8/dockerutil"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
Expand Down Expand Up @@ -249,6 +252,25 @@ func (tn *ChainNode) OverwriteGenesisFile(ctx context.Context, content []byte) e
return nil
}

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")
if err != nil {
return nil, fmt.Errorf("getting priv_validator_key.json content: %w", err)
}

return gen, nil
}

func (tn *ChainNode) OverwritePrivValFile(ctx context.Context, content []byte) error {
fw := dockerutil.NewFileWriter(tn.logger(), tn.DockerClient, tn.TestName)
if err := fw.WriteFile(ctx, tn.VolumeName, "config/priv_validator_key.json", content); err != nil {
return fmt.Errorf("overwriting priv_validator_key.json: %w", err)
}

return nil
}

func (tn *ChainNode) copyGentx(ctx context.Context, destVal *ChainNode) error {
nid, err := tn.NodeID(ctx)
if err != nil {
Expand Down Expand Up @@ -713,6 +735,24 @@ func (tn *ChainNode) IsAboveSDK47(ctx context.Context) bool {
return tn.HasCommand(ctx, "genesis")
}

// ICSVersion returns the version of interchain-security the binary was built with.
// If it doesn't depend on interchain-security, it returns an empty string.
func (tn *ChainNode) ICSVersion(ctx context.Context) string {
if strings.HasPrefix(tn.Chain.Config().Bin, "interchain-security") {
// This isn't super pretty, but it's the best we can do for an interchain-security binary.
// It doesn't depend on itself, and the version command doesn't actually output a version.
// Ideally if you have a binary called something like "v3.3.0-my-fix" you can use it as a version, since the v3.3.0 part is in it.
return semver.Canonical(tn.Image.Version)
}
info := tn.GetBuildInformation(ctx)
for _, dep := range info.BuildDeps {
if strings.HasPrefix(dep.Parent, "github.com/cosmos/interchain-security") {
return semver.Canonical(dep.Version)
}
}
return ""
}

// AddGenesisAccount adds a genesis account for each key
func (tn *ChainNode) AddGenesisAccount(ctx context.Context, address string, genesisAmount []sdk.Coin) error {
amount := ""
Expand Down Expand Up @@ -815,6 +855,27 @@ func (tn *ChainNode) SendIBCTransfer(
return tn.ExecTx(ctx, keyName, command...)
}

func (tn *ChainNode) ConsumerAdditionProposal(ctx context.Context, keyName string, prop ccvclient.ConsumerAdditionProposalJSON) (string, error) {
propBz, err := json.Marshal(prop)
if err != nil {
return "", err
}

fileName := "proposal_" + dockerutil.RandLowerCaseLetterString(4) + ".json"

fw := dockerutil.NewFileWriter(tn.logger(), tn.DockerClient, tn.TestName)
if err := fw.WriteFile(ctx, tn.VolumeName, fileName, propBz); err != nil {
return "", fmt.Errorf("failure writing proposal json: %w", err)
}

filePath := filepath.Join(tn.HomeDir(), fileName)

return tn.ExecTx(ctx, keyName,
"gov", "submit-legacy-proposal", "consumer-addition", filePath,
"--gas", "auto",
)
}

func (tn *ChainNode) GetTransaction(clientCtx client.Context, txHash string) (*sdk.TxResponse, error) {
// Retry because sometimes the tx is not committed to state yet.
var txResp *sdk.TxResponse
Expand Down
2 changes: 2 additions & 0 deletions chain/cosmos/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
transfer "github.com/cosmos/ibc-go/v8/modules/apps/transfer"
ibccore "github.com/cosmos/ibc-go/v8/modules/core"
ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"
ccvprovider "github.com/cosmos/interchain-security/v5/x/ccv/provider"
ibcwasm "github.com/strangelove-ventures/interchaintest/v8/chain/cosmos/08-wasm-types"
)

Expand All @@ -50,6 +51,7 @@ func DefaultEncoding() testutil.TestEncodingConfig {
ibccore.AppModuleBasic{},
ibctm.AppModuleBasic{},
ibcwasm.AppModuleBasic{},
ccvprovider.AppModuleBasic{},
)
}

Expand Down
Loading
Loading