Skip to content

Commit

Permalink
update chains, SetAppendedIBCPathLink, 4 IBC gen
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed May 24, 2024
1 parent 2038f0c commit ceb278d
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 79 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ vendor
examples/hyperspace/exported_state.json

go.work.sum

# testing generation
local-interchain/interchain/types/chains
local-interchain/interchain/types/configs
1 change: 0 additions & 1 deletion local-interchain/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ Here is a base chain template with every feature the configuration accepts. Acco
"ibc_paths": ["juno-ibc-1"],
"debugging": true,
"block_time": "500ms",
"encoding-options": ["juno"],
"host_port_override": {
"26656": "26656",
"26657": "26657",
Expand Down
1 change: 0 additions & 1 deletion local-interchain/chains/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"number_node": 0,
"debugging": true,
"block_time": "5000ms",
"encoding-options": ["juno"],
"host_port_override": {
"26657": "26657",
"1317": "1317",
Expand Down
2 changes: 0 additions & 2 deletions local-interchain/chains/base_ibc.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"version": "v17.0.0"
},
"block_time": "2s",
"encoding-options": ["juno"],
"gas_prices": "0%DENOM%",
"gas_adjustment": 2.0,
"ibc_paths": ["atom-juno", "juno-terra"]
Expand All @@ -50,7 +49,6 @@
"version": "v2.3.4"
},
"block_time": "2s",
"encoding-options": ["wasm"],
"gas_prices": "0%DENOM%",
"gas_adjustment": 2.0,
"ibc_paths": ["atom-terra", "juno-terra"]
Expand Down
2 changes: 0 additions & 2 deletions local-interchain/chains/juno_ibc.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"block_time": "500ms",
"ibc_paths": ["juno-ibc-1"],
"debugging": true,
"encoding-options": ["juno"],
"genesis": {
"modify": [
{
Expand Down Expand Up @@ -79,7 +78,6 @@
]
},
"block_time": "500ms",
"encoding-options": ["juno"],
"gas_prices": "0%DENOM%",
"gas_adjustment": 2.0,
"ibc_paths": ["juno-ibc-1"]
Expand Down
9 changes: 4 additions & 5 deletions local-interchain/chains/stargaze.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"binary": "starsd",
"bech32_prefix": "stars",
"docker_image": {
"version": "v10.0.1"
"version": "v13.0.0"
},
"gas_prices": "0%DENOM%",
"chain_type": "cosmos",
Expand All @@ -18,19 +18,18 @@
"number_node": 0,
"debugging": true,
"block_time": "500ms",
"encoding-options": ["wasm"],
"genesis": {
"modify": [
{
"key": "app_state.gov.voting_params.voting_period",
"key": "app_state.gov.params.voting_period",
"value": "15s"
},
{
"key": "app_state.gov.deposit_params.max_deposit_period",
"key": "app_state.gov.params.max_deposit_period",
"value": "15s"
},
{
"key": "app_state.gov.deposit_params.min_deposit.0.denom",
"key": "app_state.gov.params.min_deposit.0.denom",
"value": "ustars"
}
],
Expand Down
13 changes: 11 additions & 2 deletions local-interchain/interchain/types/chain_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,20 @@ func (c *Chain) SetICSConsumerLink(icsConsumerLink string) *Chain {
return c
}

// SetIBCPaths hardcodes the set IBC paths array for the chain.
func (c *Chain) SetIBCPaths(ibcPaths []string) *Chain {
c.IBCPaths = ibcPaths
return c
}

// SetChainsIBCLink appends the new IBC path to both chains
func (c *Chain) SetAppendedIBCPathLink(counterParty *Chain) *Chain {
ibcPath := fmt.Sprintf("%s_%s", c.ChainID, counterParty.ChainID)
c.IBCPaths = append(c.IBCPaths, ibcPath)
counterParty.IBCPaths = append(counterParty.IBCPaths, ibcPath)
return c
}

func (c *Chain) SetGenesis(genesis Genesis) *Chain {
c.Genesis = genesis
return c
Expand All @@ -114,13 +123,13 @@ func (c *Chain) SetConfigFileOverrides(configFileOverrides []ConfigFileOverrides

func (c *Chain) SetBech32Prefix(bech32Prefix string) *Chain {
c.Bech32Prefix = bech32Prefix
c.SetRandomAccounts(10)
c.SetRandomAccounts(5)
return c
}

func (c *Chain) SetCoinType(num int) *Chain {
c.CoinType = num
c.SetRandomAccounts(10)
c.SetRandomAccounts(5)
return c
}

Expand Down
79 changes: 23 additions & 56 deletions local-interchain/interchain/types/chains.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
package types

import (
"fmt"

"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v8/testutil"
)

func ChainCosmosHub() *Chain {
cosmosHub := NewChainBuilder("gaia", "localcosmos-1", "gaiad", "uatom", "cosmos").SetDebugging(true)
cosmosHub.SetBech32Prefix("cosmos")
cosmosHub.SetBlockTime("500ms")
cosmosHub.SetDockerImage(DockerImage{
func ChainCosmosHub(chainID string) *Chain {
chain := NewChainBuilder("gaia", chainID, "gaiad", "uatom", "cosmos").SetDebugging(true)
chain.SetBech32Prefix("cosmos")
chain.SetBlockTime("500ms")
chain.SetDockerImage(DockerImage{
Version: "v16.0.0",
})
cosmosHub.SetGenesis(defaultSDKv47Genesis(cosmosHub))

return cosmosHub
chain.SetGenesis(defaultSDKv47Genesis(chain))
return chain
}

func ChainEthereum() *Chain {
Expand All @@ -42,67 +39,37 @@ func ChainEthereum() *Chain {
},
},
})

return eth
}

func ChainJuno(chainID string) *Chain {
juno := NewChainBuilder("juno", chainID, "junod", "ujuno", "juno").SetDebugging(true)
juno.SetBlockTime("500ms")
juno.SetDockerImage(DockerImage{
chain := NewChainBuilder("juno", chainID, "junod", "ujuno", "juno").SetDebugging(true)
chain.SetBlockTime("500ms")
chain.SetDockerImage(DockerImage{
Version: "v21.0.0",
})
juno.SetGenesis(defaultSDKv47Genesis(juno))
return juno
chain.SetGenesis(defaultSDKv47Genesis(chain))
return chain
}

func ChainStargaze() *Chain {
stars := NewChainBuilder("stargaze", "localstars-1", "starsd", "ustars", "stars").SetDebugging(true)
stars.SetBlockTime("500ms")
stars.SetDockerImage(DockerImage{
chain := NewChainBuilder("stargaze", "localstars-1", "starsd", "ustars", "stars").SetDebugging(true)
chain.SetBlockTime("500ms")
chain.SetDockerImage(DockerImage{
Version: "v13.0.0",
})
stars.SetGenesis(defaultSDKv47Genesis(stars))
return stars
chain.SetGenesis(defaultSDKv47Genesis(chain))
return chain
}

func ChainOsmosis() *Chain {
stars := NewChainBuilder("stargaze", "localstars-1", "starsd", "ustars", "stars").SetDebugging(true)
stars.SetBlockTime("500ms")
stars.SetDockerImage(DockerImage{
Version: "v13.0.0",
chain := NewChainBuilder("osmosis", "localosmo-1", "osmosisd", "uosmo", "osmo").SetDebugging(true)
chain.SetBlockTime("500ms")
chain.SetDockerImage(DockerImage{
Version: "v25.0.0",
})
stars.SetGenesis(defaultSDKv47Genesis(stars))
return stars
}

func ChainsIBC(chainA, chainB *Chain) (ChainsConfig, error) {
if chainA.ChainID == chainB.ChainID {
return ChainsConfig{}, fmt.Errorf("chainA and chainB cannot have the same ChainID for ChainsIBC")
}

matchingPath := false
for _, pathA := range chainA.IBCPaths {
for _, pathB := range chainB.IBCPaths {
if pathA == pathB {
matchingPath = true
break
}
}
}

if !matchingPath {
ibcPath := fmt.Sprintf("%s_%s", chainA.ChainID, chainB.ChainID)
chainA.IBCPaths = []string{ibcPath}
chainB.IBCPaths = []string{ibcPath}
}

return ChainsConfig{
Chains: []Chain{
*chainA,
*chainB,
},
}, nil
chain.SetGenesis(defaultSDKv47Genesis(chain))
return chain
}

func defaultSDKv47Genesis(chain *Chain) Genesis {
Expand Down
37 changes: 28 additions & 9 deletions local-interchain/interchain/types/chains_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,32 @@ import (
)

func TestChainsGeneration(t *testing.T) {
require.NoError(t, ChainCosmosHub().SaveJSON("chains/gen-cosmoshub.json"))
require.NoError(t, ChainEthereum().SaveJSON("chains/gen-ethereum.json"))
require.NoError(t, ChainJuno("localjuno-1").SaveJSON("chains/gen-juno.json"))
require.NoError(t, ChainStargaze().SaveJSON("chains/gen-stargaze.json"))

// Creates 2 IBC connected chains
cc, err := ChainsIBC(ChainJuno("localjuno-1"), ChainJuno("localjuno-2"))
require.NoError(t, err)
require.NoError(t, cc.SaveJSON("chains/gen-juno-ibc.json"))
t.Run("single chain runs", func(t *testing.T) {
require.NoError(t, ChainEthereum().SaveJSON("chains/gen-ethereum.json"))
require.NoError(t, ChainStargaze().SaveJSON("chains/gen-stargaze.json"))
require.NoError(t, ChainCosmosHub("localcosmos-1").SaveJSON("chains/gen-cosmoshub.json"))
require.NoError(t, ChainOsmosis().SaveJSON("chains/gen-osmosis.json"))
require.NoError(t, ChainJuno("localjuno-1").SaveYAML("chains/gen-juno.yml"))
})

t.Run("2 IBC connected chains", func(t *testing.T) {
j1, j2 := ChainJuno("localjuno-1"), ChainJuno("localjuno-2")
j1.SetAppendedIBCPathLink(j2)

require.NoError(t, NewChainsConfig(j1, j2).SaveJSON("chains/gen-juno-ibc.json"))
})

t.Run("4 way IBC setup", func(t *testing.T) {
hub := ChainCosmosHub("localhub-1")
hub2 := ChainCosmosHub("localhub-2")
juno1 := ChainJuno("localjuno-1")
osmo1 := ChainOsmosis()

hub.SetAppendedIBCPathLink(hub2).SetAppendedIBCPathLink(juno1)
hub2.SetAppendedIBCPathLink(juno1)
osmo1.SetAppendedIBCPathLink(hub).SetAppendedIBCPathLink(juno1)

require.NoError(t, NewChainsConfig(hub, hub2, juno1, osmo1).SaveJSON("chains/gen-4-ibc.json"))
})

}
16 changes: 16 additions & 0 deletions local-interchain/interchain/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"os"
"path/filepath"

"github.com/go-playground/validator"
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
Expand Down Expand Up @@ -140,8 +141,23 @@ type ChainsConfig struct {
Chains []Chain `json:"chains" yaml:"chains"`
}

func NewChainsConfig(chains ...*Chain) ChainsConfig {
updatedChains := make([]Chain, len(chains))
for i, chain := range chains {
updatedChains[i] = *chain
}

return ChainsConfig{
Chains: updatedChains,
}
}

// SaveJSON saves the chains config to a file.
func (cfg ChainsConfig) SaveJSON(file string) error {
if err := os.MkdirAll(filepath.Dir(file), 0777); err != nil {
return fmt.Errorf("failed to create directory: %w", err)
}

bz, err := json.MarshalIndent(cfg, "", " ")
if err != nil {
return fmt.Errorf("failed to marshal chains config: %w", err)
Expand Down
1 change: 0 additions & 1 deletion local-interchain/rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ echo '{
"number_node": 0,
"debugging": true,
"block_time": "500ms",
"encoding-options": ["juno"],
"genesis": {
"modify": [
{
Expand Down

0 comments on commit ceb278d

Please sign in to comment.