Skip to content

Commit

Permalink
fix uidgid
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed May 25, 2024
1 parent 36510eb commit ecee546
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 49 deletions.
21 changes: 14 additions & 7 deletions chain/cosmos/ics.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,21 @@ func (c *CosmosChain) transformCCVState(ctx context.Context, ccvState []byte, co
(semver.Compare(providerVersion, icsVer330) < 0 && semver.Compare(consumerVersion, icsVer330) < 0) {
return ccvState, nil
}

var imageVersion, toVersion string

if icsCfg.ProviderVerOverride != "" {
imageVersion = icsCfg.ProviderVerOverride
}

if icsCfg.ConsumerVerOverride != "" {
toVersion = icsCfg.ConsumerVerOverride
}

if imageVersion == toVersion && imageVersion != "" {
return ccvState, nil
}

// The trick here is that when we convert the state to a consumer < 3.3.0, we need a converter that knows about that version; those are >= 4.0.0, and need a --to flag.
// Other than that, this is a question of using whichever version is newer. If it's the provider's, we need a --to flag to tell it the consumer version.
// If it's the consumer's, we don't need a --to flag cause it'll assume the consumer version.
Expand All @@ -382,13 +396,6 @@ func (c *CosmosChain) transformCCVState(ctx context.Context, ccvState []byte, co
imageVersion = consumerVersion
}

if icsCfg.ProviderVerOverride != "" {
imageVersion = icsCfg.ProviderVerOverride
}
if icsCfg.ConsumerVerOverride != "" {
toVersion = icsCfg.ConsumerVerOverride
}

c.log.Info("Transforming CCV state", zap.String("provider", providerVersion), zap.String("consumer", consumerVersion), zap.String("imageVersion", imageVersion), zap.String("toVersion", toVersion))

err := c.GetNode().WriteFile(ctx, ccvState, "ccvconsumer.json")
Expand Down
4 changes: 2 additions & 2 deletions cmd/interchaintest/example_matrix_custom.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{
"Repository": "ghcr.io/strangelove-ventures/heighliner/gaia",
"Version": "latest",
"UidGid": "1025:1025"
"uid_gid": "1025:1025"
}
],
"Bin": "gaiad",
Expand All @@ -35,7 +35,7 @@
{
"Repository": "ghcr.io/strangelove-ventures/heighliner/osmosis",
"Version": "latest",
"UidGid": "1025:1025"
"uid_gid": "1025:1025"
}
],
"Bin": "osmosisd",
Expand Down
6 changes: 3 additions & 3 deletions ibc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ type SidecarConfig struct {
type DockerImage struct {
Repository string `json:"repository" yaml:"repository"`
Version string `json:"version" yaml:"version"`
UidGid string `json:"uid_gid" yaml:"uid-gid"`
UidGid string `json:"uid-gid" yaml:"uid-gid"`
}

type CometMockConfig struct {
Expand Down Expand Up @@ -410,6 +410,6 @@ type PathUpdateOptions struct {
}

type ICSConfig struct {
ProviderVerOverride string
ConsumerVerOverride string
ProviderVerOverride string `json:"provider,omitempty" yaml:"provider,omitempty"`
ConsumerVerOverride string `json:"consumer,omitempty" yaml:"consumer,omitempty"`
}
3 changes: 2 additions & 1 deletion local-interchain/chains/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"bech32_prefix": "juno",
"docker_image": {
"repository": "ghcr.io/cosmoscontracts/juno",
"version": "v17.0.0"
"version": "v17.0.0",
"uid-gid": "1000:1000"
},
"gas_prices": "0%DENOM%",
"chain_type": "cosmos",
Expand Down
28 changes: 28 additions & 0 deletions local-interchain/chains/osmosis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"chains": [
{
"name": "osmosis",
"chain_id": "localosmo-1",
"denom": "uosmo",
"binary": "osmosisd",
"bech32_prefix": "osmo",
"docker_image": {
"version": "v25.0.0"
},
"ibc_paths": ["osmo-ibc-1"]
},
{
"name": "osmosis",
"chain_id": "localosmo-2",
"denom": "uosmo",
"binary": "osmosisd",
"bech32_prefix": "osmo",
"docker_image": {
"version": "v25.0.0"
},
"ibc_paths": ["osmo-ibc-1"]
}
]
}


2 changes: 2 additions & 0 deletions local-interchain/interchain/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ func CreateChainConfigs(cfg types.Chain) (ibc.ChainConfig, *interchaintest.Chain
ModifyGenesis: cosmos.ModifyGenesis(cfg.Genesis.Modify),
ConfigFileOverrides: ConfigurationOverrides(cfg),
EncodingConfig: nil,

InterchainSecurityConfig: cfg.ICSVersionOverride,
}

if cfg.DockerImage.Version == "" {
Expand Down
23 changes: 23 additions & 0 deletions local-interchain/interchain/types/chain_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,29 @@ func (c *Chain) SetGenesis(genesis Genesis) *Chain {
return c
}

func (c *Chain) SetDefaultSDKv47Genesis(numRandAcc int) *Chain {
c.Genesis = Genesis{
Modify: []cosmos.GenesisKV{
cosmos.NewGenesisKV("app_state.gov.params.voting_period", "3s"),
cosmos.NewGenesisKV("app_state.gov.params.max_deposit_period", "10s"),
cosmos.NewGenesisKV("app_state.gov.params.min_deposit.0.denom", c.Denom),
cosmos.NewGenesisKV("app_state.gov.params.min_deposit.0.amount", "1"),
},
Accounts: append(
[]GenesisAccount{
NewGenesisAccount("acc0", c.Bech32Prefix, "25000000000%DENOM%", c.CoinType,
"decorate bright ozone fork gallery riot bus exhaust worth way bone indoor calm squirrel merry zero scheme cotton until shop any excess stage laundry",
),
NewGenesisAccount("acc1", c.Bech32Prefix, "24000000000%DENOM%", c.CoinType,
"wealth flavor believe regret funny network recall kiss grape useless pepper cram hint member few certain unveil rather brick bargain curious require crowd raise",
),
},
GenerateRandomAccounts(numRandAcc, c.Bech32Prefix, c.CoinType)...,
),
}
return c
}

func (c *Chain) SetStartupCommands(cmds ...string) *Chain {
c.Genesis.StartupCommands = cmds
return c
Expand Down
26 changes: 4 additions & 22 deletions local-interchain/interchain/types/chains.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package types

import (
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
"github.com/strangelove-ventures/interchaintest/v8/testutil"
)
Expand All @@ -13,7 +12,7 @@ func ChainCosmosHub(chainID string) *Chain {
chain.SetDockerImage(ibc.DockerImage{
Version: "v16.0.0",
})
chain.SetGenesis(defaultSDKv47Genesis(chain))
chain.SetDefaultSDKv47Genesis(5)
return chain
}

Expand Down Expand Up @@ -49,7 +48,7 @@ func ChainJuno(chainID string) *Chain {
chain.SetDockerImage(ibc.DockerImage{
Version: "v21.0.0",
})
chain.SetGenesis(defaultSDKv47Genesis(chain))
chain.SetDefaultSDKv47Genesis(5)
chain.SetStartupCommands("%BIN% keys add example-key-after --keyring-backend test --home %HOME%")
return chain
}
Expand All @@ -60,7 +59,7 @@ func ChainStargaze() *Chain {
chain.SetDockerImage(ibc.DockerImage{
Version: "v13.0.0",
})
chain.SetGenesis(defaultSDKv47Genesis(chain))
chain.SetDefaultSDKv47Genesis(5)
return chain
}

Expand All @@ -70,23 +69,6 @@ func ChainOsmosis() *Chain {
chain.SetDockerImage(ibc.DockerImage{
Version: "v25.0.0",
})
chain.SetGenesis(defaultSDKv47Genesis(chain))
chain.SetDefaultSDKv47Genesis(5)
return chain
}

func defaultSDKv47Genesis(chain *Chain) Genesis {
return Genesis{
Modify: []cosmos.GenesisKV{
cosmos.NewGenesisKV("app_state.gov.params.voting_period", "15s"),
cosmos.NewGenesisKV("app_state.gov.params.max_deposit_period", "15s"),
cosmos.NewGenesisKV("app_state.gov.params.min_deposit.0.denom", chain.Denom),
},
Accounts: append(
[]GenesisAccount{NewGenesisAccount(
"acc0", chain.Bech32Prefix, "25000000000%DENOM%", chain.CoinType,
"decorate bright ozone fork gallery riot bus exhaust worth way bone indoor calm squirrel merry zero scheme cotton until shop any excess stage laundry",
)},
GenerateRandomAccounts(5, chain.Bech32Prefix, chain.CoinType)...,
),
}
}
24 changes: 10 additions & 14 deletions local-interchain/interchain/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ package types
import (
"fmt"

addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
sdk "github.com/cosmos/cosmos-sdk/types"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/codec"
"github.com/cosmos/go-bip39"
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
)
Expand Down Expand Up @@ -48,17 +47,19 @@ func NewGenesisAccount(name, bech32, coins string, coinType int, mnemonic string
}
}

func GenerateRandomAccounts(num int, bech32 string, coinType int) []GenesisAccount {
func GenerateRandomAccounts(num int, prefix string, coinType int) []GenesisAccount {
accounts := []GenesisAccount{}

for i := 0; i < num; i++ {
entropy, _ := bip39.NewEntropy(256)
mnemonic, _ := bip39.NewMnemonic(entropy)

addr := MnemonicToAddress(mnemonic, prefix, uint32(coinType))

accounts = append(accounts, GenesisAccount{
Name: fmt.Sprintf("user%d", i),
Amount: "100000%DENOM%",
Address: MnemonicToAddress(mnemonic, bech32, uint32(coinType)),
Address: addr,
Mnemonic: mnemonic,
})

Expand All @@ -67,18 +68,13 @@ func GenerateRandomAccounts(num int, bech32 string, coinType int) []GenesisAccou
return accounts
}

func MnemonicToAddress(mnemonic, bech32 string, coinType uint32) string {
e := moduletestutil.MakeTestEncodingConfig(
auth.AppModuleBasic{},
)
func MnemonicToAddress(mnemonic, prefix string, coinType uint32) string {
e := moduletestutil.MakeTestEncodingConfig()

kr := keyring.NewInMemory(e.Codec)

cfg := sdk.NewConfig()
cfg.SetCoinType(coinType)
cfg.SetBech32PrefixForAccount(bech32, bech32+sdk.PrefixPublic)

r, err := kr.NewAccount("tempkey", mnemonic, "", cfg.GetFullBIP44Path(), hd.Secp256k1)
bip44Path := fmt.Sprintf("m/%d'/%d'/0'/0/0", sdk.Purpose, coinType)
r, err := kr.NewAccount("tempkey", mnemonic, "", bip44Path, hd.Secp256k1)
if err != nil {
panic(err)
}
Expand All @@ -88,7 +84,7 @@ func MnemonicToAddress(mnemonic, bech32 string, coinType uint32) string {
panic(err)
}

bech32Addr, err := codec.NewBech32Codec(bech32).BytesToString(bz)
bech32Addr, err := addresscodec.NewBech32Codec(prefix).BytesToString(bz)
if err != nil {
panic(err)
}
Expand Down
1 change: 1 addition & 0 deletions local-interchain/interchain/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type Chain struct {
BlockTime string `json:"block_time,omitempty" yaml:"block_time,omitempty"`
HostPortOverride map[string]string `json:"host_port_override,omitempty" yaml:"host_port_override,omitempty"`
ICSConsumerLink string `json:"ics_consumer_link,omitempty" yaml:"ics_consumer_link,omitempty"`
ICSVersionOverride ibc.ICSConfig `json:"ics_version_override,omitempty" yaml:"ics_version_override,omitempty"`
}

func (chain *Chain) Validate() error {
Expand Down

0 comments on commit ecee546

Please sign in to comment.