Skip to content

Commit

Permalink
Merge branch 'main' into justin/docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jtieri authored Sep 16, 2024
2 parents a5046b0 + 3ca97c4 commit 7bb48e9
Show file tree
Hide file tree
Showing 8 changed files with 449 additions and 288 deletions.
54 changes: 54 additions & 0 deletions dockerutil/container_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ package dockerutil
import (
"context"
"fmt"
"io"
"net"
"regexp"
"strings"
"time"

dockertypes "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
Expand All @@ -18,6 +21,9 @@ import (
"github.com/strangelove-ventures/interchaintest/v8/ibc"
)

// Example Go/Cosmos-SDK panic format is `panic: bad Duration: time: invalid duration "bad"\n`
var panicRe = regexp.MustCompile(`panic:.*\n`)

type ContainerLifecycle struct {
log *zap.Logger
client *dockerclient.Client
Expand Down Expand Up @@ -124,7 +130,55 @@ func (c *ContainerLifecycle) StartContainer(ctx context.Context) error {
return err
}

if err := c.CheckForFailedStart(ctx, time.Second*1); err != nil {
return err
}

c.log.Info("Container started", zap.String("container", c.containerName))
return nil
}

// CheckForFailedStart checks the logs of the container for a
// panic message after a wait period to allow the container to start.
func (c *ContainerLifecycle) CheckForFailedStart(ctx context.Context, wait time.Duration) error {
time.Sleep(wait)
containerLogs, err := c.client.ContainerLogs(ctx, c.id, dockertypes.ContainerLogsOptions{
ShowStdout: true,
ShowStderr: true,
})
if err != nil {
return fmt.Errorf("failed to read logs from container %s: %w", c.containerName, err)
}
defer containerLogs.Close()

logs := new(strings.Builder)
_, err = io.Copy(logs, containerLogs)
if err != nil {
return fmt.Errorf("failed to read logs from container %s: %w", c.containerName, err)
}

if err := ParseSDKPanicFromText(logs.String()); err != nil {
// Must use Println and not the logger as there are ascii escape codes in the logs.
fmt.Printf("\nContainer name: %s.\nerror: %s.\nlogs\n%s\n", c.containerName, err.Error(), logs.String())
return fmt.Errorf("container %s failed to start: %w", c.containerName, err)
}

return nil
}

// ParsePanicFromText returns a panic line if it exists in the logs so
// that it can be returned to the user in a proper error message instead of
// hanging.
func ParseSDKPanicFromText(text string) error {
if !strings.Contains(text, "panic: ") {
return nil
}

match := panicRe.FindString(text)
if match != "" {
panicMessage := strings.TrimSpace(match)
return fmt.Errorf("%s", panicMessage)
}

return nil
}
Expand Down
64 changes: 64 additions & 0 deletions examples/cosmos/bad_genesis_params_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package cosmos_test

import (
"context"
"testing"

"github.com/strangelove-ventures/interchaintest/v8"
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest"
)

var (
badGenesis = []cosmos.GenesisKV{
cosmos.NewGenesisKV("app_state.gov.params.voting_period", "bad"),
}
)

func TestBadInputParams(t *testing.T) {
cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*interchaintest.ChainSpec{
{
Name: "juno",
ChainName: "juno",
Version: "v19.0.0-alpha.3",
ChainConfig: ibc.ChainConfig{
Denom: "ujuno",
Bech32Prefix: "juno",
CoinType: "118",
ModifyGenesis: cosmos.ModifyGenesis(badGenesis),
GasPrices: "0ujuno",
},
NumValidators: &numValsOne,
NumFullNodes: &numFullNodesZero,
},
})

chains, err := cf.Chains(t.Name())
require.NoError(t, err)

chain := chains[0].(*cosmos.CosmosChain)

ic := interchaintest.NewInterchain().
AddChain(chain)

ctx := context.Background()
client, network := interchaintest.DockerSetup(t)

err = ic.Build(ctx, nil, interchaintest.InterchainBuildOptions{
TestName: t.Name(),
Client: client,
NetworkID: network,
SkipPathCreation: true,
})

// failed to start chains: failed to start chain juno: PANIC: container juno-1-val-0-TestBadInputParams failed to start: panic: bad Duration: time: invalid duration "bad"
require.Error(t, err)
require.ErrorContains(t, err, "bad Duration")
t.Log("err", err)

t.Cleanup(func() {
_ = ic.Close()
})
}
74 changes: 39 additions & 35 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
module github.com/strangelove-ventures/interchaintest/v8

go 1.22.2
go 1.22.5

toolchain go1.23.0

replace (
github.com/ChainSafe/go-schnorrkel => github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d
github.com/ChainSafe/go-schnorrkel/1 => github.com/ChainSafe/go-schnorrkel v1.0.0
// cometbft API breaking change fix
github.com/btcsuite/btcd/btcec/v2 => github.com/btcsuite/btcd/btcec/v2 v2.3.3
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/vedhavyas/go-subkey => github.com/strangelove-ventures/go-subkey v1.0.7
)
Expand All @@ -13,26 +17,26 @@ require (
cosmossdk.io/math v1.3.0
cosmossdk.io/store v1.1.0
cosmossdk.io/x/feegrant v0.1.0
cosmossdk.io/x/upgrade v0.1.3
cosmossdk.io/x/upgrade v0.1.4
github.com/99designs/keyring v1.2.2
github.com/BurntSushi/toml v1.4.0
github.com/ChainSafe/go-schnorrkel/1 v0.0.0-00010101000000-000000000000
github.com/CosmWasm/wasmd v0.42.1-0.20230928145107-894076a25cb2
github.com/StirlingMarketingGroup/go-namecase v1.0.0
github.com/atotto/clipboard v0.1.4
github.com/avast/retry-go/v4 v4.5.1
github.com/cometbft/cometbft v0.38.10
github.com/cosmos/cosmos-sdk v0.50.8
github.com/cometbft/cometbft v0.38.11
github.com/cosmos/cosmos-sdk v0.50.9
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/gogoproto v1.5.0
github.com/cosmos/ibc-go/modules/capability v1.0.0
github.com/cosmos/ibc-go/v8 v8.3.2
github.com/cosmos/interchain-security/v5 v5.0.0-alpha1.0.20240424193412-7cd900ad2a74
github.com/cosmos/ibc-go/modules/capability v1.0.1
github.com/cosmos/ibc-go/v8 v8.4.0
github.com/cosmos/interchain-security/v5 v5.1.1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
github.com/decred/dcrd/dcrec/secp256k1/v2 v2.0.1
github.com/docker/docker v24.0.9+incompatible
github.com/docker/go-connections v0.5.0
github.com/ethereum/go-ethereum v1.14.5
github.com/ethereum/go-ethereum v1.14.8
github.com/gdamore/tcell/v2 v2.7.4
github.com/gogo/protobuf v1.3.3
github.com/google/go-cmp v0.6.0
Expand All @@ -45,20 +49,20 @@ require (
github.com/pelletier/go-toml v1.9.5
github.com/pelletier/go-toml/v2 v2.2.2
github.com/rivo/tview v0.0.0-20220307222120-9994674d60a8
github.com/spf13/cobra v1.8.0
github.com/spf13/cobra v1.8.1
github.com/stretchr/testify v1.9.0
github.com/tidwall/gjson v1.17.1
github.com/tyler-smith/go-bip32 v1.0.0
github.com/tyler-smith/go-bip39 v1.1.0
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.27.0
golang.org/x/crypto v0.24.0
golang.org/x/mod v0.18.0
golang.org/x/crypto v0.25.0
golang.org/x/mod v0.19.0
golang.org/x/sync v0.7.0
golang.org/x/tools v0.22.0
golang.org/x/tools v0.23.0
google.golang.org/grpc v1.65.0
gopkg.in/yaml.v3 v3.0.1
modernc.org/sqlite v1.30.1
modernc.org/sqlite v1.31.1
)

require (
Expand All @@ -68,17 +72,17 @@ require (
cloud.google.com/go/storage v1.38.0 // indirect
cosmossdk.io/api v0.7.5 // indirect
cosmossdk.io/collections v0.4.0 // indirect
cosmossdk.io/core v0.11.0 // indirect
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
cosmossdk.io/core v0.11.1 // indirect
cosmossdk.io/depinject v1.0.0 // indirect
cosmossdk.io/errors v1.0.1 // indirect
cosmossdk.io/log v1.3.1 // indirect
cosmossdk.io/x/evidence v0.1.0 // indirect
cosmossdk.io/x/tx v0.13.3 // indirect
cosmossdk.io/x/tx v0.13.4 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d // indirect
github.com/ComposableFi/go-subkey/v2 v2.0.0-tm03420 // indirect
github.com/CosmWasm/wasmvm v1.4.0 // indirect
github.com/CosmWasm/wasmvm v1.5.4 // indirect
github.com/DataDog/datadog-go v3.2.0+incompatible // indirect
github.com/DataDog/zstd v1.5.5 // indirect
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
Expand All @@ -90,18 +94,18 @@ require (
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
github.com/bits-and-blooms/bitset v1.10.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/chzyer/readline v1.5.1 // indirect
github.com/cockroachdb/datadriven v1.0.3-0.20230801171734-e384cf455877 // indirect
github.com/cockroachdb/errors v1.11.1 // indirect
github.com/cockroachdb/errors v1.11.3 // indirect
github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/pebble v1.1.0 // indirect
github.com/cockroachdb/pebble v1.1.1 // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/cometbft/cometbft-db v0.10.0 // indirect
github.com/cometbft/cometbft-db v0.14.0 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.12.1 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
Expand All @@ -119,9 +123,8 @@ require (
github.com/decred/dcrd/crypto/blake256 v1.0.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect
github.com/dgraph-io/badger/v2 v2.2007.4 // indirect
github.com/dgraph-io/badger/v4 v4.2.0 // indirect
github.com/dgraph-io/ristretto v0.1.1 // indirect
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
Expand All @@ -148,11 +151,12 @@ require (
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/flatbuffers v1.12.1 // indirect
github.com/google/orderedcode v0.0.1 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.3 // indirect
github.com/gorilla/handlers v1.5.2 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
Expand All @@ -173,7 +177,7 @@ require (
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/hdevalence/ed25519consensus v0.1.0 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/holiman/uint256 v1.3.1 // indirect
github.com/huandu/skiplist v1.2.0 // indirect
github.com/iancoleman/strcase v0.3.0 // indirect
github.com/improbable-eng/grpc-web v0.15.0 // indirect
Expand Down Expand Up @@ -238,7 +242,7 @@ require (
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.18.2 // indirect
github.com/spf13/viper v1.19.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/supranational/blst v0.3.11 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
Expand All @@ -251,32 +255,32 @@ require (
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/zondax/hid v0.9.2 // indirect
github.com/zondax/ledger-go v0.14.3 // indirect
go.etcd.io/bbolt v1.3.8 // indirect
go.etcd.io/bbolt v1.4.0-alpha.0.0.20240404170359-43604f3112c5 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/oauth2 v0.20.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/term v0.21.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/term v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/api v0.169.0 // indirect
google.golang.org/api v0.171.0 // indirect
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 // indirect
google.golang.org/protobuf v1.34.1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240709173604-40e1e62336c5 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gotest.tools/v3 v3.5.1 // indirect
lukechampine.com/blake3 v1.2.1 // indirect
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 // indirect
modernc.org/libc v1.52.1 // indirect
modernc.org/libc v1.55.3 // indirect
modernc.org/mathutil v1.6.0 // indirect
modernc.org/memory v1.8.0 // indirect
modernc.org/strutil v1.2.0 // indirect
Expand Down
Loading

0 comments on commit 7bb48e9

Please sign in to comment.