Skip to content

Commit

Permalink
Update Interchaintest (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
boojamya committed Jul 6, 2023
1 parent 692ab92 commit 1e56ae7
Show file tree
Hide file tree
Showing 10 changed files with 473 additions and 600 deletions.
128 changes: 66 additions & 62 deletions interchaintest/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import (
"context"
"fmt"

"github.com/cosmos/cosmos-sdk/crypto/keyring"
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
"github.com/cosmos/cosmos-sdk/types"
"github.com/icza/dyno"
"github.com/strangelove-ventures/interchaintest/v3"
"github.com/strangelove-ventures/interchaintest/v3/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v3/ibc"
"github.com/strangelove-ventures/interchaintest/v3/relayer"
Expand Down Expand Up @@ -186,16 +184,21 @@ type NobleRoles struct {
// It then recovers the key on the specified validator.
func createTokenfactoryRoles(ctx context.Context, nobleRoles *NobleRoles, denomMetadata DenomMetadata, val *cosmos.ChainNode, minSetup bool) error {
chainCfg := val.Chain.Config()
nobleVal := val.Chain

kr := keyring.NewInMemory()
var err error

nobleRoles.Owner = interchaintest.BuildWallet(kr, "owner-"+denomMetadata.Base, chainCfg)
err := val.RecoverKey(ctx, nobleRoles.Owner.KeyName, nobleRoles.Owner.Mnemonic)
nobleRoles.Owner, err = nobleVal.BuildRelayerWallet(ctx, "owner-"+denomMetadata.Base)
if err != nil {
return err
return fmt.Errorf("failed to create wallet: %w", err)
}

if err := val.RecoverKey(ctx, nobleRoles.Owner.KeyName(), nobleRoles.Owner.Mnemonic()); err != nil {
return fmt.Errorf("failed to restore %s wallet: %w", nobleRoles.Owner.KeyName(), err)
}

genesisWallet := ibc.WalletAmount{
Address: nobleRoles.Owner.Address,
Address: nobleRoles.Owner.FormattedAddress(),
Denom: chainCfg.Denom,
Amount: 0,
}
Expand All @@ -207,76 +210,76 @@ func createTokenfactoryRoles(ctx context.Context, nobleRoles *NobleRoles, denomM
return nil
}

nobleRoles.Owner2 = interchaintest.BuildWallet(kr, "owner2-"+denomMetadata.Base, chainCfg)
nobleRoles.MasterMinter = interchaintest.BuildWallet(kr, "masterminter-"+denomMetadata.Base, chainCfg)
nobleRoles.MinterController = interchaintest.BuildWallet(kr, "mintercontroller-"+denomMetadata.Base, chainCfg)
nobleRoles.MinterController2 = interchaintest.BuildWallet(kr, "mintercontroller2-"+denomMetadata.Base, chainCfg)
nobleRoles.Minter = interchaintest.BuildWallet(kr, "minter-"+denomMetadata.Base, chainCfg)
nobleRoles.Blacklister = interchaintest.BuildWallet(kr, "blacklister-"+denomMetadata.Base, chainCfg)
nobleRoles.Pauser = interchaintest.BuildWallet(kr, "pauser-"+denomMetadata.Base, chainCfg)

err = val.RecoverKey(ctx, nobleRoles.Owner2.KeyName, nobleRoles.Owner2.Mnemonic)
nobleRoles.Owner2, err = nobleVal.BuildRelayerWallet(ctx, "owner2-"+denomMetadata.Base)
if err != nil {
return err
return fmt.Errorf("failed to create %s wallet: %w", "owner2", err)
}
err = val.RecoverKey(ctx, nobleRoles.MasterMinter.KeyName, nobleRoles.MasterMinter.Mnemonic)
nobleRoles.MasterMinter, err = nobleVal.BuildRelayerWallet(ctx, "masterminter-"+denomMetadata.Base)
if err != nil {
return err
return fmt.Errorf("failed to create %s wallet: %w", "masterminter", err)
}
err = val.RecoverKey(ctx, nobleRoles.MinterController.KeyName, nobleRoles.MinterController.Mnemonic)
nobleRoles.MinterController, err = nobleVal.BuildRelayerWallet(ctx, "mintercontroller-"+denomMetadata.Base)
if err != nil {
return err
return fmt.Errorf("failed to create %s wallet: %w", "mintercontroller", err)
}
err = val.RecoverKey(ctx, nobleRoles.MinterController2.KeyName, nobleRoles.MinterController2.Mnemonic)
nobleRoles.MinterController2, err = nobleVal.BuildRelayerWallet(ctx, "mintercontroller2-"+denomMetadata.Base)
if err != nil {
return err
return fmt.Errorf("failed to create %s wallet: %w", "mintercontroller2", err)
}
err = val.RecoverKey(ctx, nobleRoles.Minter.KeyName, nobleRoles.Minter.Mnemonic)
nobleRoles.Minter, err = nobleVal.BuildRelayerWallet(ctx, "minter-"+denomMetadata.Base)
if err != nil {
return err
return fmt.Errorf("failed to create %s wallet: %w", "minter", err)
}
err = val.RecoverKey(ctx, nobleRoles.Blacklister.KeyName, nobleRoles.Blacklister.Mnemonic)
nobleRoles.Blacklister, err = nobleVal.BuildRelayerWallet(ctx, "blacklister-"+denomMetadata.Base)
if err != nil {
return err
return fmt.Errorf("failed to create %s wallet: %w", "blacklister", err)
}
err = val.RecoverKey(ctx, nobleRoles.Pauser.KeyName, nobleRoles.Pauser.Mnemonic)
nobleRoles.Pauser, err = nobleVal.BuildRelayerWallet(ctx, "pauser-"+denomMetadata.Base)
if err != nil {
return err
return fmt.Errorf("failed to create %s wallet: %w", "pauser", err)
}

walletsToRestore := []ibc.Wallet{nobleRoles.Owner2, nobleRoles.MasterMinter, nobleRoles.MinterController, nobleRoles.MinterController2, nobleRoles.Minter, nobleRoles.Blacklister, nobleRoles.Pauser}
for _, wallet := range walletsToRestore {
if err = val.RecoverKey(ctx, wallet.KeyName(), wallet.Mnemonic()); err != nil {
return fmt.Errorf("failed to restore %s wallet: %w", wallet.KeyName(), err)

}
}

genesisWallets := []ibc.WalletAmount{
{
Address: nobleRoles.Owner2.Address,
Address: nobleRoles.Owner2.FormattedAddress(),
Denom: chainCfg.Denom,
Amount: 0,
},
{
Address: nobleRoles.MasterMinter.Address,
Address: nobleRoles.MasterMinter.FormattedAddress(),
Denom: chainCfg.Denom,
Amount: 0,
},
{
Address: nobleRoles.MinterController.Address,
Address: nobleRoles.MinterController.FormattedAddress(),
Denom: chainCfg.Denom,
Amount: 0,
},
{
Address: nobleRoles.MinterController2.Address,
Address: nobleRoles.MinterController2.FormattedAddress(),
Denom: chainCfg.Denom,
Amount: 0,
},
{
Address: nobleRoles.Minter.Address,
Address: nobleRoles.Minter.FormattedAddress(),
Denom: chainCfg.Denom,
Amount: 0,
},
{
Address: nobleRoles.Blacklister.Address,
Address: nobleRoles.Blacklister.FormattedAddress(),
Denom: chainCfg.Denom,
Amount: 0,
},
{
Address: nobleRoles.Pauser.Address,
Address: nobleRoles.Pauser.FormattedAddress(),
Denom: chainCfg.Denom,
Amount: 0,
},
Expand All @@ -296,24 +299,20 @@ func createTokenfactoryRoles(ctx context.Context, nobleRoles *NobleRoles, denomM
func createParamAuthAtGenesis(ctx context.Context, val *cosmos.ChainNode) (ibc.Wallet, error) {
chainCfg := val.Chain.Config()

kr := keyring.NewInMemory()

wallet := interchaintest.BuildWallet(kr, "authority", chainCfg)

err := val.RecoverKey(ctx, wallet.KeyName, wallet.Mnemonic)
wallet, err := val.Chain.BuildWallet(ctx, "authority", "")
if err != nil {
return ibc.Wallet{}, err
return nil, fmt.Errorf("failed to create wallet: %w", err)
}

genesisWallet := ibc.WalletAmount{
Address: wallet.Address,
Address: wallet.FormattedAddress(),
Denom: chainCfg.Denom,
Amount: 0,
}

err = val.AddGenesisAccount(ctx, genesisWallet.Address, []types.Coin{types.NewCoin(genesisWallet.Denom, types.NewIntFromUint64(uint64(genesisWallet.Amount)))})
if err != nil {
return ibc.Wallet{}, err
return nil, err
}
return wallet, nil
}
Expand All @@ -322,41 +321,46 @@ func createParamAuthAtGenesis(ctx context.Context, val *cosmos.ChainNode) (ibc.W
// It then recovers the key on the specified validator.
func createExtraWalletsAtGenesis(ctx context.Context, val *cosmos.ChainNode) (ExtraWallets, error) {
chainCfg := val.Chain.Config()
nobleVal := val.Chain

kr := keyring.NewInMemory()
var err error

extraWallets := &ExtraWallets{}

extraWallets.User = interchaintest.BuildWallet(kr, "user", chainCfg)
extraWallets.User2 = interchaintest.BuildWallet(kr, "user2", chainCfg)
extraWallets.Alice = interchaintest.BuildWallet(kr, "alice", chainCfg)

err := val.RecoverKey(ctx, extraWallets.User.KeyName, extraWallets.User.Mnemonic)
extraWallets.User, err = nobleVal.BuildRelayerWallet(ctx, "user")
if err != nil {
return ExtraWallets{}, err
return ExtraWallets{}, fmt.Errorf("failed to create wallet: %w", err)
}
err = val.RecoverKey(ctx, extraWallets.User2.KeyName, extraWallets.User2.Mnemonic)
extraWallets.User2, err = nobleVal.BuildRelayerWallet(ctx, "user2")
if err != nil {
return ExtraWallets{}, err
return ExtraWallets{}, fmt.Errorf("failed to create wallet: %w", err)
}
err = val.RecoverKey(ctx, extraWallets.Alice.KeyName, extraWallets.Alice.Mnemonic)
extraWallets.Alice, err = nobleVal.BuildRelayerWallet(ctx, "alice")
if err != nil {
return ExtraWallets{}, err
return ExtraWallets{}, fmt.Errorf("failed to create wallet: %w", err)
}

walletsToRestore := []ibc.Wallet{extraWallets.User, extraWallets.User2, extraWallets.Alice}
for _, wallet := range walletsToRestore {
if err = val.RecoverKey(ctx, wallet.KeyName(), wallet.Mnemonic()); err != nil {
return ExtraWallets{}, fmt.Errorf("failed to restore %s wallet: %w", wallet.KeyName(), err)

}
}

genesisWallets := []ibc.WalletAmount{
{
Address: extraWallets.User.Address,
Address: extraWallets.User.FormattedAddress(),
Denom: chainCfg.Denom,
Amount: 0,
},
{
Address: extraWallets.User2.Address,
Address: extraWallets.User2.FormattedAddress(),
Denom: chainCfg.Denom,
Amount: 10_000,
},
{
Address: extraWallets.Alice.Address,
Address: extraWallets.Alice.FormattedAddress(),
Denom: chainCfg.Denom,
Amount: 0,
},
Expand All @@ -375,7 +379,7 @@ func createExtraWalletsAtGenesis(ctx context.Context, val *cosmos.ChainNode) (Ex
// If minSetup = true, only the owner address, paused state, and denom is setup in genesis.
// These are minimum requirements to start the chain. Otherwise all tokenfactory accounts are created.
func modifyGenesisTokenfactory(g map[string]interface{}, tokenfactoryModName string, denomMetadata DenomMetadata, roles *NobleRoles, minSetup bool) error {
if err := dyno.Set(g, TokenFactoryAddress{roles.Owner.Address}, "app_state", tokenfactoryModName, "owner"); err != nil {
if err := dyno.Set(g, TokenFactoryAddress{roles.Owner.FormattedAddress()}, "app_state", tokenfactoryModName, "owner"); err != nil {
return fmt.Errorf("failed to set owner address in genesis json: %w", err)
}
if err := dyno.Set(g, TokenFactoryPaused{false}, "app_state", tokenfactoryModName, "paused"); err != nil {
Expand All @@ -390,13 +394,13 @@ func modifyGenesisTokenfactory(g map[string]interface{}, tokenfactoryModName str
if minSetup {
return nil
}
if err := dyno.Set(g, TokenFactoryAddress{roles.MasterMinter.Address}, "app_state", tokenfactoryModName, "masterMinter"); err != nil {
if err := dyno.Set(g, TokenFactoryAddress{roles.MasterMinter.FormattedAddress()}, "app_state", tokenfactoryModName, "masterMinter"); err != nil {
return fmt.Errorf("failed to set owner address in genesis json: %w", err)
}
if err := dyno.Set(g, TokenFactoryAddress{roles.Blacklister.Address}, "app_state", tokenfactoryModName, "blacklister"); err != nil {
if err := dyno.Set(g, TokenFactoryAddress{roles.Blacklister.FormattedAddress()}, "app_state", tokenfactoryModName, "blacklister"); err != nil {
return fmt.Errorf("failed to set owner address in genesis json: %w", err)
}
if err := dyno.Set(g, TokenFactoryAddress{roles.Pauser.Address}, "app_state", tokenfactoryModName, "pauser"); err != nil {
if err := dyno.Set(g, TokenFactoryAddress{roles.Pauser.FormattedAddress()}, "app_state", tokenfactoryModName, "pauser"); err != nil {
return fmt.Errorf("failed to set owner address in genesis json: %w", err)
}
return nil
Expand Down
37 changes: 18 additions & 19 deletions interchaintest/globalfee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/params/types/proposal"
"github.com/strangelove-ventures/interchaintest/v3"
"github.com/strangelove-ventures/interchaintest/v3/chain/cosmos"
Expand Down Expand Up @@ -83,10 +82,10 @@ func TestGlobalFee(t *testing.T) {
if err := modifyGenesisTokenfactory(g, "fiat-tokenfactory", denomMetadataDrachma, &roles2, true); err != nil {
return nil, err
}
if err := modifyGenesisParamAuthority(g, paramauthorityWallet.Address); err != nil {
if err := modifyGenesisParamAuthority(g, paramauthorityWallet.FormattedAddress()); err != nil {
return nil, err
}
if err := modifyGenesisTariffDefaults(g, paramauthorityWallet.Address); err != nil {
if err := modifyGenesisTariffDefaults(g, paramauthorityWallet.FormattedAddress()); err != nil {
return nil, err
}
out, err := json.Marshal(&g)
Expand Down Expand Up @@ -138,7 +137,7 @@ func TestGlobalFee(t *testing.T) {
zeroGasPrice := "0.0" + chainCfg.Denom

// send tx with zero fees with the default MinimumGasPricesParam of 0 (null) - tx should succeed
_, err = nobleValidator.ExecTx(ctx, extraWallets.User2.KeyName, "bank", "send", extraWallets.User2.KeyName, extraWallets.Alice.Address, sendAmount100, "--gas-prices", zeroGasPrice)
_, err = nobleValidator.ExecTx(ctx, extraWallets.User2.KeyName(), "bank", "send", extraWallets.User2.KeyName(), extraWallets.Alice.FormattedAddress(), sendAmount100, "--gas-prices", zeroGasPrice)
require.NoError(t, err, "failed sending transaction")

msgUpdateParams := proposaltypes.MsgUpdateParams{
Expand All @@ -152,18 +151,18 @@ func TestGlobalFee(t *testing.T) {
Value: fmt.Sprintf(`[{"denom":"%s", "amount":"%s"}]`, chainCfg.Denom, minGasPriceAmount),
},
}),
Authority: paramauthorityWallet.Address,
Authority: paramauthorityWallet.FormattedAddress(),
}

broadcaster := cosmos.NewBroadcaster(t, noble)

decoded := sdk.MustAccAddressFromBech32(paramauthorityWallet.Address)
wallet := &ibc.Wallet{
Address: string(decoded),
Mnemonic: paramauthorityWallet.Mnemonic,
KeyName: paramauthorityWallet.KeyName,
CoinType: paramauthorityWallet.CoinType,
}
wallet := cosmos.NewWallet(
paramauthorityWallet.KeyName(),
paramauthorityWallet.Address(),
paramauthorityWallet.Mnemonic(),
chainCfg,
)

tx, err := cosmos.BroadcastTx(
ctx,
broadcaster,
Expand All @@ -174,33 +173,33 @@ func TestGlobalFee(t *testing.T) {
require.Equal(t, uint32(0), tx.Code, "tx proposal failed")

// send tx with zero fees while the default MinimumGasPricesParam requires fees - tx should fail
_, err = nobleValidator.ExecTx(ctx, extraWallets.User2.KeyName,
_, err = nobleValidator.ExecTx(ctx, extraWallets.User2.KeyName(),
"bank", "send",
extraWallets.User2.Address, extraWallets.Alice.Address, sendAmount100,
extraWallets.User2.FormattedAddress(), extraWallets.Alice.FormattedAddress(), sendAmount100,
"--gas-prices", zeroGasPrice,
"-b", "block",
)
require.Error(t, err, "tx should not have succeeded with zero fees")

// send tx with the gas price set by MinimumGasPricesParam - tx should succeed
_, err = nobleValidator.ExecTx(ctx, extraWallets.User2.KeyName,
_, err = nobleValidator.ExecTx(ctx, extraWallets.User2.KeyName(),
"bank", "send",
extraWallets.User2.Address, extraWallets.Alice.Address, sendAmount100,
extraWallets.User2.FormattedAddress(), extraWallets.Alice.FormattedAddress(), sendAmount100,
"--gas-prices", minGasPrice,
"-b", "block",
)
require.NoError(t, err, "tx should have succeeded")

// send tx with zero fees while the default MinimumGasPricesParam requires fees, but update owner msg is in the bypass min fee msgs list - tx should succeed
_, err = nobleValidator.ExecTx(ctx, roles.Owner.KeyName,
"tokenfactory", "update-owner", roles.Owner2.Address,
_, err = nobleValidator.ExecTx(ctx, roles.Owner.KeyName(),
"tokenfactory", "update-owner", roles.Owner2.FormattedAddress(),
"--gas-prices", zeroGasPrice,
"-b", "block",
)
require.NoError(t, err, "failed to execute update owner tx with zero fees")

// send tx with zero fees while the default MinimumGasPricesParam requires fees, but accept owner msg is in the bypass min fee msgs list - tx should succeed
_, err = nobleValidator.ExecTx(ctx, roles.Owner2.KeyName,
_, err = nobleValidator.ExecTx(ctx, roles.Owner2.KeyName(),
"tokenfactory", "accept-owner",
"--gas-prices", zeroGasPrice,
"-b", "block",
Expand Down
Loading

0 comments on commit 1e56ae7

Please sign in to comment.