diff --git a/interchaintest/go.mod b/interchaintest/go.mod index 3fe641520..a302e8f5b 100644 --- a/interchaintest/go.mod +++ b/interchaintest/go.mod @@ -16,6 +16,7 @@ require ( cosmossdk.io/math v1.3.0 github.com/CosmWasm/wasmd v0.45.0 github.com/CosmosContracts/juno/v23 v23.0.0-00010101000000-000000000000 + github.com/cenkalti/backoff v2.2.1+incompatible github.com/cosmos/cosmos-sdk v0.47.12 github.com/cosmos/gogoproto v1.4.10 github.com/cosmos/ibc-go/v7 v7.6.0 @@ -78,7 +79,7 @@ require ( github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect github.com/bufbuild/protocompile v0.5.1 // indirect - github.com/cenkalti/backoff/v4 v4.2.1 // indirect + github.com/cenkalti/backoff/v4 v4.2.1 github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/chzyer/readline v1.5.1 // indirect github.com/cockroachdb/errors v1.11.1 // indirect diff --git a/interchaintest/helpers/cosmwasm.go b/interchaintest/helpers/cosmwasm.go index 54d363375..9e1997b6c 100644 --- a/interchaintest/helpers/cosmwasm.go +++ b/interchaintest/helpers/cosmwasm.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "testing" + "time" "github.com/strangelove-ventures/interchaintest/v7/chain/cosmos" "github.com/strangelove-ventures/interchaintest/v7/ibc" @@ -12,9 +13,17 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cenkalti/backoff/v4" "github.com/cosmos/cosmos-sdk/crypto/keyring" ) +var backoffPolicy = &backoff.ExponentialBackOff{ + MaxElapsedTime: time.Minute, + InitialInterval: 500 * time.Millisecond, + Multiplier: 1.5, + MaxInterval: 10 * time.Second, +} + func SmartQueryString(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, contractAddr, queryMsg string, res interface{}) error { var jsonMap map[string]interface{} if err := json.Unmarshal([]byte(queryMsg), &jsonMap); err != nil { @@ -24,10 +33,16 @@ func SmartQueryString(t *testing.T, ctx context.Context, chain *cosmos.CosmosCha return err } -func StoreContract(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, keyname string, fileLoc string) (codeId string) { - codeId, err := chain.StoreContract(ctx, keyname, fileLoc) +func StoreContract(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, keyname, fileLoc string) string { + var codeId string + err := backoff.Retry(func() error { + var err error + codeId, err = chain.StoreContract(ctx, keyname, fileLoc) + return err + }, backoffPolicy) + if err != nil { - t.Fatal(err) + t.Fatalf("Failed to store contract: %v", err) } return codeId } diff --git a/interchaintest/setup.go b/interchaintest/setup.go index 4cf2eb428..904d7816f 100644 --- a/interchaintest/setup.go +++ b/interchaintest/setup.go @@ -4,9 +4,11 @@ import ( "context" "fmt" "testing" + "time" sdkmath "cosmossdk.io/math" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + "github.com/cenkalti/backoff" "github.com/docker/docker/client" interchaintest "github.com/strangelove-ventures/interchaintest/v7" "github.com/strangelove-ventures/interchaintest/v7/chain/cosmos" @@ -26,6 +28,13 @@ import ( tokenfactorytypes "github.com/CosmosContracts/juno/v23/x/tokenfactory/types" ) +var backoffPolicy = &backoff.ExponentialBackOff{ + MaxElapsedTime: 5 * time.Minute, + InitialInterval: 1 * time.Second, + Multiplier: 2, + MaxInterval: 30 * time.Second, +} + var ( VotingPeriod = "15s" MaxDepositPeriod = "10s" @@ -123,22 +132,26 @@ func CreateThisBranchChain(t *testing.T, numVals, numFull int) []ibc.Chain { } func CreateChainWithCustomConfig(t *testing.T, numVals, numFull int, config ibc.ChainConfig) []ibc.Chain { - cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*interchaintest.ChainSpec{ - { - Name: "juno", - ChainName: "juno", - Version: config.Images[0].Version, - ChainConfig: config, - NumValidators: &numVals, - NumFullNodes: &numFull, - }, - }) - - // Get chains from the chain factory - chains, err := cf.Chains(t.Name()) - require.NoError(t, err) - - // chain := chains[0].(*cosmos.CosmosChain) + var chains []ibc.Chain + + err := backoff.Retry(func() error { + cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*interchaintest.ChainSpec{ + { + Name: "juno", + ChainName: "juno", + Version: config.Images[0].Version, + ChainConfig: config, + NumValidators: &numVals, + NumFullNodes: &numFull, + }, + }) + + var err error + chains, err = cf.Chains(t.Name()) + return err + }, backoffPolicy) + + require.NoError(t, err, "Failed to create chain after multiple attempts") return chains }