diff --git a/integration-tests/contracts/modules/simple-state.go b/integration-tests/contracts/modules/simple-state.go index fa1fddc44..96d08c33c 100644 --- a/integration-tests/contracts/modules/simple-state.go +++ b/integration-tests/contracts/modules/simple-state.go @@ -7,8 +7,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" - integrationtests "github.com/CoreumFoundation/coreum/v3/integration-tests" "github.com/CoreumFoundation/coreum/v3/pkg/client" + integrationtests "github.com/CoreumFoundation/coreum/v3/testutil/integration" ) // SimpleState is a structure used to initizlize the simple state contract diff --git a/integration-tests/go.mod b/integration-tests/go.mod index e8f57e156..58259315f 100644 --- a/integration-tests/go.mod +++ b/integration-tests/go.mod @@ -30,7 +30,7 @@ require ( github.com/cosmos/ics23/go v0.10.0 // indirect github.com/cosmos/relayer/v2 v2.4.1 github.com/dvsekhvalnov/jose2go v1.5.0 // indirect - github.com/google/uuid v1.3.0 + github.com/google/uuid v1.3.0 // indirect github.com/gorilla/mux v1.8.0 // indirect github.com/pkg/errors v0.9.1 github.com/rakyll/statik v0.1.7 // indirect @@ -38,10 +38,10 @@ require ( github.com/stretchr/testify v1.8.4 go.uber.org/zap v1.24.0 google.golang.org/genproto v0.0.0-20230706204954-ccb25ca9f130 // indirect - google.golang.org/grpc v1.57.0 + google.golang.org/grpc v1.57.0 // indirect ) -require cosmossdk.io/errors v1.0.0 +require cosmossdk.io/errors v1.0.0 // indirect require ( cloud.google.com/go v0.110.4 // indirect diff --git a/integration-tests/ibc/asset_ft_test.go b/integration-tests/ibc/asset_ft_test.go index a5e8f72d3..be3e66835 100644 --- a/integration-tests/ibc/asset_ft_test.go +++ b/integration-tests/ibc/asset_ft_test.go @@ -23,6 +23,7 @@ import ( "github.com/CoreumFoundation/coreum-tools/pkg/retry" integrationtests "github.com/CoreumFoundation/coreum/v3/integration-tests" "github.com/CoreumFoundation/coreum/v3/pkg/client" + "github.com/CoreumFoundation/coreum/v3/testutil/integration" assetfttypes "github.com/CoreumFoundation/coreum/v3/x/asset/ft/types" ) @@ -36,7 +37,7 @@ func TestIBCFailsIfNotEnabled(t *testing.T) { coreumIssuer := coreumChain.GenAccount() issueFee := coreumChain.QueryAssetFTParams(ctx, t).IssueFee.Amount - coreumChain.FundAccountWithOptions(ctx, t, coreumIssuer, integrationtests.BalancesOptions{ + coreumChain.FundAccountWithOptions(ctx, t, coreumIssuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgIssue{}, &ibctransfertypes.MsgTransfer{}, @@ -95,25 +96,25 @@ func TestIBCAssetFTSendCommissionAndBurnRate(t *testing.T) { osmosisRecipient1 := osmosisChain.GenAccount() osmosisRecipient2 := osmosisChain.GenAccount() - gaiaChain.Faucet.FundAccounts(ctx, t, integrationtests.FundedAccount{ + gaiaChain.Faucet.FundAccounts(ctx, t, integration.FundedAccount{ Address: gaiaRecipient1, Amount: gaiaChain.NewCoin(sdkmath.NewInt(1000000)), // coin for the fees - }, integrationtests.FundedAccount{ + }, integration.FundedAccount{ Address: gaiaRecipient2, Amount: gaiaChain.NewCoin(sdkmath.NewInt(1000000)), // coin for the fees }) - osmosisChain.Faucet.FundAccounts(ctx, t, integrationtests.FundedAccount{ + osmosisChain.Faucet.FundAccounts(ctx, t, integration.FundedAccount{ Address: osmosisRecipient1, Amount: gaiaChain.NewCoin(sdkmath.NewInt(1000000)), // coin for the fees - }, integrationtests.FundedAccount{ + }, integration.FundedAccount{ Address: osmosisRecipient2, Amount: gaiaChain.NewCoin(sdkmath.NewInt(1000000)), // coin for the fees }) coreumIssuer := coreumChain.GenAccount() issueFee := coreumChain.QueryAssetFTParams(ctx, t).IssueFee.Amount - coreumChain.FundAccountWithOptions(ctx, t, coreumIssuer, integrationtests.BalancesOptions{ + coreumChain.FundAccountWithOptions(ctx, t, coreumIssuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &banktypes.MsgSend{}, &assetfttypes.MsgIssue{}, @@ -123,7 +124,7 @@ func TestIBCAssetFTSendCommissionAndBurnRate(t *testing.T) { Amount: issueFee, }) - coreumChain.FundAccountWithOptions(ctx, t, coreumSender, integrationtests.BalancesOptions{ + coreumChain.FundAccountWithOptions(ctx, t, coreumSender, integration.BalancesOptions{ Messages: []sdk.Msg{ &ibctransfertypes.MsgTransfer{}, &ibctransfertypes.MsgTransfer{}, @@ -351,13 +352,13 @@ func TestIBCAssetFTWhitelisting(t *testing.T) { coreumRecipientWhitelisted := coreumChain.GenAccount() gaiaRecipient := gaiaChain.GenAccount() - gaiaChain.Faucet.FundAccounts(ctx, t, integrationtests.FundedAccount{ + gaiaChain.Faucet.FundAccounts(ctx, t, integration.FundedAccount{ Address: gaiaRecipient, Amount: gaiaChain.NewCoin(sdkmath.NewInt(1000000)), // coin for the fees }) issueFee := coreumChain.QueryAssetFTParams(ctx, t).IssueFee.Amount - coreumChain.FundAccountWithOptions(ctx, t, coreumIssuer, integrationtests.BalancesOptions{ + coreumChain.FundAccountWithOptions(ctx, t, coreumIssuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgIssue{}, &assetfttypes.MsgSetWhitelistedLimit{}, @@ -446,13 +447,13 @@ func TestIBCAssetFTFreezing(t *testing.T) { coreumSender := coreumChain.GenAccount() gaiaRecipient := gaiaChain.GenAccount() - gaiaChain.Faucet.FundAccounts(ctx, t, integrationtests.FundedAccount{ + gaiaChain.Faucet.FundAccounts(ctx, t, integration.FundedAccount{ Address: gaiaRecipient, Amount: gaiaChain.NewCoin(sdkmath.NewInt(1000000)), // coin for the fees }) issueFee := coreumChain.QueryAssetFTParams(ctx, t).IssueFee.Amount - coreumChain.FundAccountWithOptions(ctx, t, coreumIssuer, integrationtests.BalancesOptions{ + coreumChain.FundAccountWithOptions(ctx, t, coreumIssuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgIssue{}, &banktypes.MsgSend{}, @@ -460,7 +461,7 @@ func TestIBCAssetFTFreezing(t *testing.T) { }, Amount: issueFee, }) - coreumChain.FundAccountWithOptions(ctx, t, coreumSender, integrationtests.BalancesOptions{ + coreumChain.FundAccountWithOptions(ctx, t, coreumSender, integration.BalancesOptions{ Messages: []sdk.Msg{ &ibctransfertypes.MsgTransfer{}, &ibctransfertypes.MsgTransfer{}, @@ -546,13 +547,13 @@ func TestEscrowAddressIsResistantToFreezingAndWhitelisting(t *testing.T) { coreumIssuer := coreumChain.GenAccount() gaiaRecipient := gaiaChain.GenAccount() - gaiaChain.Faucet.FundAccounts(ctx, t, integrationtests.FundedAccount{ + gaiaChain.Faucet.FundAccounts(ctx, t, integration.FundedAccount{ Address: gaiaRecipient, Amount: gaiaChain.NewCoin(sdkmath.NewInt(1000000)), // coin for the fees }) issueFee := coreumChain.QueryAssetFTParams(ctx, t).IssueFee.Amount - coreumChain.FundAccountWithOptions(ctx, t, coreumIssuer, integrationtests.BalancesOptions{ + coreumChain.FundAccountWithOptions(ctx, t, coreumIssuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgIssue{}, &assetfttypes.MsgFreeze{}, @@ -630,13 +631,13 @@ func TestIBCGlobalFreeze(t *testing.T) { coreumRecipient := coreumChain.GenAccount() gaiaRecipient := gaiaChain.GenAccount() - gaiaChain.Faucet.FundAccounts(ctx, t, integrationtests.FundedAccount{ + gaiaChain.Faucet.FundAccounts(ctx, t, integration.FundedAccount{ Address: gaiaRecipient, Amount: gaiaChain.NewCoin(sdkmath.NewInt(1000000)), // coin for the fees }) issueFee := coreumChain.QueryAssetFTParams(ctx, t).IssueFee.Amount - coreumChain.FundAccountWithOptions(ctx, t, coreumIssuer, integrationtests.BalancesOptions{ + coreumChain.FundAccountWithOptions(ctx, t, coreumIssuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgIssue{}, &assetfttypes.MsgGloballyFreeze{}, @@ -646,7 +647,7 @@ func TestIBCGlobalFreeze(t *testing.T) { }, Amount: issueFee, }) - coreumChain.FundAccountWithOptions(ctx, t, coreumSender, integrationtests.BalancesOptions{ + coreumChain.FundAccountWithOptions(ctx, t, coreumSender, integration.BalancesOptions{ Messages: []sdk.Msg{ &ibctransfertypes.MsgTransfer{}, }, @@ -784,7 +785,7 @@ func TestIBCAssetFTTimedOutTransfer(t *testing.T) { coreumSender := coreumChain.GenAccount() gaiaRecipient := gaiaChain.GenAccount() - coreumChain.FundAccountWithOptions(ctx, t, coreumSender, integrationtests.BalancesOptions{ + coreumChain.FundAccountWithOptions(ctx, t, coreumSender, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgIssue{}, &ibctransfertypes.MsgTransfer{}, @@ -892,7 +893,7 @@ func TestIBCAssetFTRejectedTransfer(t *testing.T) { coreumSender := coreumChain.GenAccount() gaiaRecipient := gaiaChain.GenAccount() - coreumChain.FundAccountWithOptions(ctx, t, coreumSender, integrationtests.BalancesOptions{ + coreumChain.FundAccountWithOptions(ctx, t, coreumSender, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgIssue{}, &ibctransfertypes.MsgTransfer{}, @@ -900,7 +901,7 @@ func TestIBCAssetFTRejectedTransfer(t *testing.T) { }, Amount: coreumChain.QueryAssetFTParams(ctx, t).IssueFee.Amount, }) - gaiaChain.Faucet.FundAccounts(ctx, t, integrationtests.FundedAccount{ + gaiaChain.Faucet.FundAccounts(ctx, t, integration.FundedAccount{ Address: gaiaRecipient, Amount: gaiaChain.NewCoin(sdk.NewIntFromUint64(100000)), }) @@ -944,7 +945,7 @@ func TestIBCAssetFTRejectedTransfer(t *testing.T) { // test that the reverse transfer from gaia to coreum is blocked too - coreumChain.FundAccountWithOptions(ctx, t, coreumSender, integrationtests.BalancesOptions{ + coreumChain.FundAccountWithOptions(ctx, t, coreumSender, integration.BalancesOptions{ Messages: []sdk.Msg{&ibctransfertypes.MsgTransfer{}}, }) @@ -985,7 +986,7 @@ func TestIBCRejectedTransferWithWhitelistingAndFreezing(t *testing.T) { moduleAddress := authtypes.NewModuleAddress(ibctransfertypes.ModuleName) issueFee := coreumChain.QueryAssetFTParams(ctx, t).IssueFee.Amount - coreumChain.FundAccountWithOptions(ctx, t, coreumIssuer, integrationtests.BalancesOptions{ + coreumChain.FundAccountWithOptions(ctx, t, coreumIssuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgIssue{}, &assetfttypes.MsgFreeze{}, @@ -995,7 +996,7 @@ func TestIBCRejectedTransferWithWhitelistingAndFreezing(t *testing.T) { }, Amount: issueFee, }) - coreumChain.FundAccountWithOptions(ctx, t, coreumSender, integrationtests.BalancesOptions{ + coreumChain.FundAccountWithOptions(ctx, t, coreumSender, integration.BalancesOptions{ Messages: []sdk.Msg{ &ibctransfertypes.MsgTransfer{}, }, @@ -1116,7 +1117,7 @@ func TestIBCTimedOutTransferWithWhitelistingAndFreezing(t *testing.T) { coreumSender := coreumChain.GenAccount() gaiaRecipient := gaiaChain.GenAccount() - coreumChain.FundAccountWithOptions(ctx, t, coreumIssuer, integrationtests.BalancesOptions{ + coreumChain.FundAccountWithOptions(ctx, t, coreumIssuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgIssue{}, &assetfttypes.MsgFreeze{}, @@ -1126,7 +1127,7 @@ func TestIBCTimedOutTransferWithWhitelistingAndFreezing(t *testing.T) { }, Amount: issueFee, }) - coreumChain.FundAccountWithOptions(ctx, t, coreumSender, integrationtests.BalancesOptions{ + coreumChain.FundAccountWithOptions(ctx, t, coreumSender, integration.BalancesOptions{ Messages: []sdk.Msg{ &ibctransfertypes.MsgTransfer{}, }, @@ -1283,14 +1284,14 @@ func TestIBCRejectedTransferWithBurnRateAndSendCommission(t *testing.T) { moduleAddress := authtypes.NewModuleAddress(ibctransfertypes.ModuleName) issueFee := coreumChain.QueryAssetFTParams(ctx, t).IssueFee.Amount - coreumChain.FundAccountWithOptions(ctx, t, coreumIssuer, integrationtests.BalancesOptions{ + coreumChain.FundAccountWithOptions(ctx, t, coreumIssuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgIssue{}, &banktypes.MsgSend{}, }, Amount: issueFee, }) - coreumChain.FundAccountWithOptions(ctx, t, coreumSender, integrationtests.BalancesOptions{ + coreumChain.FundAccountWithOptions(ctx, t, coreumSender, integration.BalancesOptions{ Messages: []sdk.Msg{ &ibctransfertypes.MsgTransfer{}, }, @@ -1378,14 +1379,14 @@ func TestIBCTimedOutTransferWithBurnRateAndSendCommission(t *testing.T) { coreumSender := coreumChain.GenAccount() gaiaRecipient := gaiaChain.GenAccount() - coreumChain.FundAccountWithOptions(ctx, t, coreumIssuer, integrationtests.BalancesOptions{ + coreumChain.FundAccountWithOptions(ctx, t, coreumIssuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgIssue{}, &banktypes.MsgSend{}, }, Amount: issueFee, }) - coreumChain.FundAccountWithOptions(ctx, t, coreumSender, integrationtests.BalancesOptions{ + coreumChain.FundAccountWithOptions(ctx, t, coreumSender, integration.BalancesOptions{ Messages: []sdk.Msg{ &ibctransfertypes.MsgTransfer{}, }, @@ -1499,10 +1500,10 @@ func TestIBCTimedOutTransferWithBurnRateAndSendCommission(t *testing.T) { func ibcTransferAndAssertBalanceChanges( ctx context.Context, t *testing.T, - srcChainCtx integrationtests.ChainContext, + srcChainCtx integration.ChainContext, srcSender sdk.AccAddress, sendCoin sdk.Coin, - dstChainCtx integrationtests.ChainContext, + dstChainCtx integration.ChainContext, dstChainRecipient sdk.AccAddress, receiveCoin sdk.Coin, srcExpectedBalanceChanges map[string]sdkmath.Int, @@ -1537,7 +1538,7 @@ func ibcTransferAndAssertBalanceChanges( func fetchBalanceForMultipleAddresses( ctx context.Context, t *testing.T, - chainCtx integrationtests.ChainContext, + chainCtx integration.ChainContext, denom string, addresses []string, ) map[string]sdkmath.Int { diff --git a/integration-tests/ibc/ibc.go b/integration-tests/ibc/ibc.go index 58ab9b7bf..ec6c27fe3 100644 --- a/integration-tests/ibc/ibc.go +++ b/integration-tests/ibc/ibc.go @@ -3,7 +3,23 @@ package ibc import ( + "context" + "fmt" + "testing" + "time" + + sdkmath "cosmossdk.io/math" + "github.com/cosmos/cosmos-sdk/crypto/hd" + "github.com/cosmos/cosmos-sdk/types/bech32" ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" + ibcchanneltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + cosmosrelayer "github.com/cosmos/relayer/v2/relayer" + cosmosrelayercosmoschain "github.com/cosmos/relayer/v2/relayer/chains/cosmos" + "github.com/stretchr/testify/require" + "go.uber.org/zap" + "go.uber.org/zap/zaptest" + + "github.com/CoreumFoundation/coreum/v3/testutil/integration" ) // ConvertToIBCDenom returns the IBC denom based on the channelID and denom. @@ -12,3 +28,101 @@ func ConvertToIBCDenom(channelID, denom string) string { ibctransfertypes.GetPrefixedDenom(ibctransfertypes.PortID, channelID, denom), ).IBCDenom() } + +// CreateIBCChannelsAndConnect creates two new channels for the provided ports on provided chains and connects them. +func CreateIBCChannelsAndConnect( + ctx context.Context, + t *testing.T, + srcChain integration.Chain, + srcChainPort string, + dstChain integration.Chain, + dstChainPort string, + channelVersion string, + channelOrder ibcchanneltypes.Order, +) func() { + t.Helper() + + log := zaptest.NewLogger(t) + + const relayerKeyName = "relayer-key" + + srcClientID, srcConnectionID := srcChain.AwaitForIBCClientAndConnectionIDs(ctx, t, dstChain.ChainSettings.ChainID) + relayerSrcChain := setupRelayerChain(ctx, t, log, srcChain, relayerKeyName, srcClientID, srcConnectionID) + + dstClientID, dstConnectionID := dstChain.AwaitForIBCClientAndConnectionIDs(ctx, t, srcChain.ChainSettings.ChainID) + relayerDstChain := setupRelayerChain(ctx, t, log, dstChain, relayerKeyName, dstClientID, dstConnectionID) + + var channelOrderString string + switch channelOrder { + case ibcchanneltypes.UNORDERED: + channelOrderString = "UNORDERED" + case ibcchanneltypes.ORDERED: + channelOrderString = "ORDERED" + default: + t.Fatalf("Unsupported chennel order type:%d", channelOrder) + } + + pathName := fmt.Sprintf("%s-%s", srcChain.ChainSettings.ChainID, dstChain.ChainSettings.ChainID) + require.NoError(t, relayerSrcChain.CreateOpenChannels( + ctx, + relayerDstChain, + 3, + 5*time.Second, + srcChainPort, dstChainPort, + channelOrderString, channelVersion, + false, + "", + pathName, + )) + closerFunc := func() { + require.NoError(t, relayerSrcChain.CloseChannel(ctx, relayerDstChain, 5, 5*time.Second, srcChain.ChainSettings.ChainID, srcChainPort, "", pathName)) + } + return closerFunc +} + +func setupRelayerChain( + ctx context.Context, + t *testing.T, + log *zap.Logger, + chain integration.Chain, + relayerKeyName string, + clientID, connectionID string, +) *cosmosrelayer.Chain { + t.Helper() + + relayerSrcChainConfig := cosmosrelayercosmoschain.CosmosProviderConfig{ + Key: relayerKeyName, + ChainName: chain.ChainSettings.ChainID, + ChainID: chain.ChainSettings.ChainID, + RPCAddr: chain.ChainSettings.RPCAddress, + AccountPrefix: chain.ChainSettings.AddressPrefix, + KeyringBackend: "test", + GasAdjustment: 1.2, + GasPrices: fmt.Sprintf("%s%s", chain.ChainSettings.GasPrice, chain.ChainSettings.Denom), + Debug: false, + Timeout: "20s", + OutputFormat: "indent", + SignModeStr: "direct", + } + + relayerSrcChainProvider, err := relayerSrcChainConfig.NewProvider(log, t.TempDir(), false, chain.ChainSettings.ChainID) + require.NoError(t, err) + require.NoError(t, relayerSrcChainProvider.Init(ctx)) + relayerSrcChainKeyInfo, err := relayerSrcChainProvider.AddKey(relayerKeyName, chain.ChainSettings.CoinType, string(hd.Secp256k1Type)) + require.NoError(t, err) + _, relayerKeyBytes, err := bech32.DecodeAndConvert(relayerSrcChainKeyInfo.Address) + require.NoError(t, err) + + chain.Faucet.FundAccounts(ctx, t, integration.FundedAccount{ + Address: relayerKeyBytes, + Amount: chain.NewCoin(sdkmath.NewInt(2000000)), + }) + + relayerChain := cosmosrelayer.NewChain(log, relayerSrcChainProvider, false) + relayerChain.PathEnd = &cosmosrelayer.PathEnd{ + ChainID: relayerChain.ChainID(), + ClientID: clientID, + ConnectionID: connectionID, + } + return relayerChain +} diff --git a/integration-tests/ibc/transfer_test.go b/integration-tests/ibc/transfer_test.go index eb98c8a4e..6fc2a4248 100644 --- a/integration-tests/ibc/transfer_test.go +++ b/integration-tests/ibc/transfer_test.go @@ -21,6 +21,7 @@ import ( "github.com/CoreumFoundation/coreum-tools/pkg/retry" integrationtests "github.com/CoreumFoundation/coreum/v3/integration-tests" "github.com/CoreumFoundation/coreum/v3/pkg/client" + "github.com/CoreumFoundation/coreum/v3/testutil/integration" ) func TestIBCTransferFromCoreumToGaiaAndBack(t *testing.T) { @@ -37,12 +38,12 @@ func TestIBCTransferFromCoreumToGaiaAndBack(t *testing.T) { gaiaRecipient := gaiaChain.GenAccount() sendToGaiaCoin := coreumChain.NewCoin(sdkmath.NewInt(1000)) - coreumChain.FundAccountWithOptions(ctx, t, coreumSender, integrationtests.BalancesOptions{ + coreumChain.FundAccountWithOptions(ctx, t, coreumSender, integration.BalancesOptions{ Messages: []sdk.Msg{&ibctransfertypes.MsgTransfer{}}, Amount: sendToGaiaCoin.Amount, }) - gaiaChain.Faucet.FundAccounts(ctx, t, integrationtests.FundedAccount{ + gaiaChain.Faucet.FundAccounts(ctx, t, integration.FundedAccount{ Address: gaiaRecipient, Amount: gaiaChain.NewCoin(sdkmath.NewInt(1000000)), // coin for the fees }) @@ -80,14 +81,14 @@ func TestIBCTransferFromGaiaToCoreumAndBack(t *testing.T) { coreumToGaiaSender := coreumChain.GenAccount() // Fund accounts - coreumChain.FundAccountWithOptions(ctx, t, coreumToCoreumSender, integrationtests.BalancesOptions{ + coreumChain.FundAccountWithOptions(ctx, t, coreumToCoreumSender, integration.BalancesOptions{ Messages: []sdk.Msg{&banktypes.MsgSend{}}, }) - coreumChain.FundAccountWithOptions(ctx, t, coreumToGaiaSender, integrationtests.BalancesOptions{ + coreumChain.FundAccountWithOptions(ctx, t, coreumToGaiaSender, integration.BalancesOptions{ Messages: []sdk.Msg{&ibctransfertypes.MsgTransfer{}}, }) - gaiaChain.Faucet.FundAccounts(ctx, t, integrationtests.FundedAccount{ + gaiaChain.Faucet.FundAccounts(ctx, t, integration.FundedAccount{ Address: gaiaAccount1, Amount: sendToCoreumCoin.Add(gaiaChain.NewCoin(sdkmath.NewInt(1000000))), // coin to send + coin for the fee }) @@ -151,7 +152,7 @@ func TestTimedOutTransfer(t *testing.T) { osmosisRecipient := osmosisChain.GenAccount() sendToOsmosisCoin := coreumChain.NewCoin(sdkmath.NewInt(1000)) - coreumChain.FundAccountWithOptions(ctx, t, coreumSender, integrationtests.BalancesOptions{ + coreumChain.FundAccountWithOptions(ctx, t, coreumSender, integration.BalancesOptions{ Messages: []sdk.Msg{&ibctransfertypes.MsgTransfer{}}, Amount: sendToOsmosisCoin.Amount, }) @@ -237,11 +238,11 @@ func TestRejectedTransfer(t *testing.T) { gaiaRecipient := gaiaChain.GenAccount() sendToGaiaCoin := coreumChain.NewCoin(sdkmath.NewInt(1000)) - coreumChain.FundAccountWithOptions(ctx, t, coreumSender, integrationtests.BalancesOptions{ + coreumChain.FundAccountWithOptions(ctx, t, coreumSender, integration.BalancesOptions{ Messages: []sdk.Msg{&ibctransfertypes.MsgTransfer{}}, Amount: sendToGaiaCoin.Amount, }) - gaiaChain.Faucet.FundAccounts(ctx, t, integrationtests.FundedAccount{ + gaiaChain.Faucet.FundAccounts(ctx, t, integration.FundedAccount{ Address: gaiaRecipient, Amount: gaiaChain.NewCoin(sdk.NewIntFromUint64(100000)), }) @@ -264,7 +265,7 @@ func TestRejectedTransfer(t *testing.T) { // test that the reverse transfer from gaia to coreum is blocked too - coreumChain.FundAccountWithOptions(ctx, t, coreumSender, integrationtests.BalancesOptions{ + coreumChain.FundAccountWithOptions(ctx, t, coreumSender, integration.BalancesOptions{ Messages: []sdk.Msg{&ibctransfertypes.MsgTransfer{}}, }) diff --git a/integration-tests/ibc/wasm_test.go b/integration-tests/ibc/wasm_test.go index 711793d25..62558c34f 100644 --- a/integration-tests/ibc/wasm_test.go +++ b/integration-tests/ibc/wasm_test.go @@ -23,6 +23,7 @@ import ( "github.com/CoreumFoundation/coreum-tools/pkg/retry" integrationtests "github.com/CoreumFoundation/coreum/v3/integration-tests" ibcwasm "github.com/CoreumFoundation/coreum/v3/integration-tests/contracts/ibc" + "github.com/CoreumFoundation/coreum/v3/testutil/integration" ) type ibcTimeoutBlock struct { @@ -78,7 +79,7 @@ func TestIBCTransferFromSmartContract(t *testing.T) { coreumAdmin := coreumChain.GenAccount() osmosisRecipient := osmosisChain.GenAccount() - coreumChain.Faucet.FundAccounts(ctx, t, integrationtests.FundedAccount{ + coreumChain.Faucet.FundAccounts(ctx, t, integration.FundedAccount{ Address: coreumAdmin, Amount: coreumChain.NewCoin(sdkmath.NewInt(2000000)), }) @@ -94,7 +95,7 @@ func TestIBCTransferFromSmartContract(t *testing.T) { coreumChain.TxFactory().WithSimulateAndExecute(true), coreumAdmin, ibcwasm.IBCTransferWASM, - integrationtests.InstantiateConfig{ + integration.InstantiateConfig{ AccessType: wasmtypes.AccessTypeUnspecified, Payload: initialPayload, Amount: sendToOsmosisCoin, @@ -177,12 +178,12 @@ func TestIBCCallFromSmartContract(t *testing.T) { coreumCaller := coreumChain.GenAccount() osmosisCaller := osmosisChain.GenAccount() - coreumChain.Faucet.FundAccounts(ctx, t, integrationtests.FundedAccount{ + coreumChain.Faucet.FundAccounts(ctx, t, integration.FundedAccount{ Address: coreumCaller, Amount: coreumChain.NewCoin(sdkmath.NewInt(2000000)), }) - osmosisChain.Faucet.FundAccounts(ctx, t, integrationtests.FundedAccount{ + osmosisChain.Faucet.FundAccounts(ctx, t, integration.FundedAccount{ Address: osmosisCaller, Amount: osmosisChain.NewCoin(sdkmath.NewInt(2000000)), }) @@ -195,7 +196,7 @@ func TestIBCCallFromSmartContract(t *testing.T) { coreumChain.TxFactory().WithSimulateAndExecute(true), coreumCaller, ibcwasm.IBCCallWASM, - integrationtests.InstantiateConfig{ + integration.InstantiateConfig{ Admin: coreumCaller, AccessType: wasmtypes.AccessTypeUnspecified, Payload: initialPayload, @@ -209,7 +210,7 @@ func TestIBCCallFromSmartContract(t *testing.T) { osmosisChain.TxFactory().WithSimulateAndExecute(true), osmosisCaller, ibcwasm.IBCCallWASM, - integrationtests.InstantiateConfig{ + integration.InstantiateConfig{ Admin: osmosisCaller, AccessType: wasmtypes.AccessTypeUnspecified, Payload: initialPayload, @@ -234,7 +235,7 @@ func TestIBCCallFromSmartContract(t *testing.T) { requireT.NotEmpty(osmosisIBCPort) t.Logf("Osmisis contrac IBC port:%s", osmosisIBCPort) - closerFunc := integrationtests.CreateIBCChannelsAndConnect( + closerFunc := CreateIBCChannelsAndConnect( ctx, t, coreumChain.Chain, @@ -278,7 +279,7 @@ func TestIBCCallFromSmartContract(t *testing.T) { func executeWasmIncrement( ctx context.Context, requireT *require.Assertions, - chain integrationtests.Chain, + chain integration.Chain, caller sdk.AccAddress, channelID, contractAddr string, ) { @@ -304,7 +305,7 @@ func executeWasmIncrement( func awaitWasmCounterValue( ctx context.Context, t *testing.T, - chain integrationtests.Chain, + chain integration.Chain, channelID, contractAddress string, expectedCount uint32, ) { diff --git a/integration-tests/init.go b/integration-tests/init.go index 3b170d45f..ba8b8504d 100644 --- a/integration-tests/init.go +++ b/integration-tests/init.go @@ -9,21 +9,14 @@ import ( "time" sdkclient "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/grpc/tmservice" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/bech32" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/cosmos/gogoproto/proto" "github.com/pkg/errors" - "google.golang.org/grpc" - "google.golang.org/grpc/credentials/insecure" "github.com/CoreumFoundation/coreum/v3/app" "github.com/CoreumFoundation/coreum/v3/pkg/client" "github.com/CoreumFoundation/coreum/v3/pkg/config" "github.com/CoreumFoundation/coreum/v3/pkg/config/constant" + "github.com/CoreumFoundation/coreum/v3/testutil/integration" feemodeltypes "github.com/CoreumFoundation/coreum/v3/x/feemodel/types" ) @@ -44,9 +37,9 @@ func (m *stringsFlag) Set(val string) error { // Chains defines the all chains used for the tests. type Chains struct { - Coreum CoreumChain - Gaia Chain - Osmosis Chain + Coreum integration.CoreumChain + Gaia integration.Chain + Osmosis integration.Chain } var ( @@ -93,6 +86,9 @@ func init() { flag.Parse() ctx = context.Background() + if !runUnsafe { + ctx = integration.WithSkipUnsafe(ctx) + } // set the default staker mnemonic used in the dev znet by default if len(coreumStakerMnemonics) == 0 { @@ -108,8 +104,8 @@ func init() { // ********** Coreum ********** - coreumGRPCClient := dialGRPCClient(coreumGRPCAddress) - coreumSettings := queryCommonSettings(queryCtx, coreumGRPCClient) + coreumGRPCClient := integration.DialGRPCClient(coreumGRPCAddress) + coreumSettings := integration.QueryChainSettings(queryCtx, coreumGRPCClient) coreumClientCtx := client.NewContext(getTestContextConfig(), app.ModuleBasics). WithGRPCClient(coreumGRPCClient) @@ -129,7 +125,7 @@ func init() { panic(errors.WithStack(err)) } - chains.Coreum = NewCoreumChain(NewChain( + chains.Coreum = integration.NewCoreumChain(integration.NewChain( coreumGRPCClient, coreumRPCClient, coreumSettings, @@ -137,7 +133,7 @@ func init() { } // NewCoreumTestingContext returns the configured coreum chain and new context for the integration tests. -func NewCoreumTestingContext(t *testing.T) (context.Context, CoreumChain) { +func NewCoreumTestingContext(t *testing.T) (context.Context, integration.CoreumChain) { testCtx, testCtxCancel := context.WithCancel(ctx) t.Cleanup(testCtxCancel) @@ -154,8 +150,8 @@ func NewChainsTestingContext(t *testing.T) (context.Context, Chains) { defer queryCtxCancel() // ********** Gaia ********** - gaiaGRPClient := dialGRPCClient(gaiaGRPCAddress) - gaiaSettings := queryCommonSettings(queryCtx, gaiaGRPClient) + gaiaGRPClient := integration.DialGRPCClient(gaiaGRPCAddress) + gaiaSettings := integration.QueryChainSettings(queryCtx, gaiaGRPClient) gaiaSettings.GasPrice = sdk.MustNewDecFromStr("0.01") gaiaSettings.GasAdjustment = 1.5 gaiaSettings.CoinType = sdk.CoinType // gaia coin type @@ -166,7 +162,7 @@ func NewChainsTestingContext(t *testing.T) (context.Context, Chains) { panic(errors.WithStack(err)) } - chains.Gaia = NewChain( + chains.Gaia = integration.NewChain( gaiaGRPClient, gaiaRPClient, gaiaSettings, @@ -174,8 +170,8 @@ func NewChainsTestingContext(t *testing.T) (context.Context, Chains) { // ********** Osmosis ********** - osmosisGRPClient := dialGRPCClient(osmosisGRPCAddress) - osmosisChainSettings := queryCommonSettings(queryCtx, osmosisGRPClient) + osmosisGRPClient := integration.DialGRPCClient(osmosisGRPCAddress) + osmosisChainSettings := integration.QueryChainSettings(queryCtx, osmosisGRPClient) osmosisChainSettings.GasPrice = sdk.MustNewDecFromStr("0.01") osmosisChainSettings.GasAdjustment = 1.5 osmosisChainSettings.CoinType = sdk.CoinType // osmosis coin type @@ -186,7 +182,7 @@ func NewChainsTestingContext(t *testing.T) (context.Context, Chains) { panic(errors.WithStack(err)) } - chains.Osmosis = NewChain( + chains.Osmosis = integration.NewChain( osmosisGRPClient, osmosisRPClient, osmosisChainSettings, @@ -196,77 +192,9 @@ func NewChainsTestingContext(t *testing.T) (context.Context, Chains) { return testCtx, chains } -func queryCommonSettings(ctx context.Context, grpcClient *grpc.ClientConn) ChainSettings { - clientCtx := client.NewContext(getTestContextConfig(), app.ModuleBasics). - WithGRPCClient(grpcClient) - - infoBeforeRes, err := tmservice.NewServiceClient(clientCtx).GetNodeInfo(ctx, &tmservice.GetNodeInfoRequest{}) - if err != nil { - panic(fmt.Sprintf("can't get node info, err: %s", err)) - } - - chainID := infoBeforeRes.DefaultNodeInfo.Network - - paramsRes, err := stakingtypes.NewQueryClient(clientCtx).Params(ctx, &stakingtypes.QueryParamsRequest{}) - if err != nil { - panic(errors.Errorf("can't get staking params, err: %s", err)) - } - - denom := paramsRes.Params.BondDenom - - accountsRes, err := authtypes.NewQueryClient(clientCtx).Accounts(ctx, &authtypes.QueryAccountsRequest{}) - if err != nil { - panic(fmt.Sprintf("can't get account params, err: %s", err)) - } - - var addressPrefix string - for _, account := range accountsRes.Accounts { - if account != nil && account.TypeUrl == fmt.Sprintf("/%s", proto.MessageName(&authtypes.BaseAccount{})) { - var acc authtypes.BaseAccount - if err := proto.Unmarshal(account.Value, &acc); err != nil { - panic(fmt.Sprintf("can't unpack account, err: %s", err)) - } - - addressPrefix, _, err = bech32.DecodeAndConvert(acc.Address) - if err != nil { - panic(fmt.Sprintf("can't extract address prefix address:%s, err: %s", acc.Address, err)) - } - break - } - } - if addressPrefix == "" { - panic("address prefix is empty") - } - - return ChainSettings{ - ChainID: chainID, - Denom: denom, - AddressPrefix: addressPrefix, - } -} - func getTestContextConfig() client.ContextConfig { cfg := client.DefaultContextConfig() cfg.TimeoutConfig.TxStatusPollInterval = 100 * time.Millisecond return cfg } - -func dialGRPCClient(url string) *grpc.ClientConn { - encodingConfig := config.NewEncodingConfig(app.ModuleBasics) - pc, ok := encodingConfig.Codec.(codec.GRPCCodecProvider) - if !ok { - panic("failed to cast codec to codec.GRPCCodecProvider)") - } - - grpClient, err := grpc.Dial( - url, - grpc.WithDefaultCallOptions(grpc.ForceCodec(pc.GRPCCodec())), - grpc.WithTransportCredentials(insecure.NewCredentials()), - ) - if err != nil { - panic(errors.WithStack(err)) - } - - return grpClient -} diff --git a/integration-tests/keyring.go b/integration-tests/keyring.go deleted file mode 100644 index 5bfe62c07..000000000 --- a/integration-tests/keyring.go +++ /dev/null @@ -1,185 +0,0 @@ -package integrationtests - -import ( - "sync" - - "github.com/cosmos/cosmos-sdk/crypto/keyring" - "github.com/cosmos/cosmos-sdk/crypto/types" - sdk "github.com/cosmos/cosmos-sdk/types" -) - -var _ keyring.Keyring = concurrentSafeKeyring{} - -// concurrentSafeKeyring wraps standard Cosmos SDK keyring implementation to make it concurrent safe. -// Since we run our integration tests in parallel from time to time we get: "concurrent map read and map write" -// so concurrentSafeKeyring wraps all methods of keyring and locks mutex before calling method. -type concurrentSafeKeyring struct { - mu *sync.RWMutex - kr keyring.Keyring -} - -func newConcurrentSafeKeyring(kr keyring.Keyring) concurrentSafeKeyring { - return concurrentSafeKeyring{ - mu: &sync.RWMutex{}, - kr: kr, - } -} - -func (csk concurrentSafeKeyring) SupportedAlgorithms() (keyring.SigningAlgoList, keyring.SigningAlgoList) { - return csk.kr.SupportedAlgorithms() -} - -// Read operations: - -func (csk concurrentSafeKeyring) List() ([]*keyring.Record, error) { - csk.mu.RLock() - defer csk.mu.RUnlock() - - return csk.kr.List() -} - -func (csk concurrentSafeKeyring) Key(uid string) (*keyring.Record, error) { - csk.mu.RLock() - defer csk.mu.RUnlock() - - return csk.kr.Key(uid) -} - -func (csk concurrentSafeKeyring) KeyByAddress(address sdk.Address) (*keyring.Record, error) { - csk.mu.RLock() - defer csk.mu.RUnlock() - - return csk.kr.KeyByAddress(address) -} - -func (csk concurrentSafeKeyring) ExportPubKeyArmor(uid string) (string, error) { - csk.mu.RLock() - defer csk.mu.RUnlock() - - return csk.kr.ExportPubKeyArmor(uid) -} - -func (csk concurrentSafeKeyring) ExportPubKeyArmorByAddress(address sdk.Address) (string, error) { - csk.mu.RLock() - defer csk.mu.RUnlock() - - return csk.kr.ExportPubKeyArmorByAddress(address) -} - -func (csk concurrentSafeKeyring) ExportPrivKeyArmor(uid, encryptPassphrase string) (armor string, err error) { - csk.mu.RLock() - defer csk.mu.RUnlock() - - return csk.kr.ExportPrivKeyArmor(uid, encryptPassphrase) -} - -func (csk concurrentSafeKeyring) ExportPrivKeyArmorByAddress(address sdk.Address, encryptPassphrase string) (armor string, err error) { - csk.mu.RLock() - defer csk.mu.RUnlock() - - return csk.kr.ExportPrivKeyArmorByAddress(address, encryptPassphrase) -} - -func (csk concurrentSafeKeyring) Sign(uid string, msg []byte) ([]byte, types.PubKey, error) { - csk.mu.RLock() - defer csk.mu.RUnlock() - - return csk.kr.Sign(uid, msg) -} - -func (csk concurrentSafeKeyring) SignByAddress(address sdk.Address, msg []byte) ([]byte, types.PubKey, error) { - csk.mu.RLock() - defer csk.mu.RUnlock() - - return csk.kr.SignByAddress(address, msg) -} - -// Write operations: - -func (csk concurrentSafeKeyring) Delete(uid string) error { - csk.mu.Lock() - defer csk.mu.Unlock() - - return csk.kr.Delete(uid) -} - -func (csk concurrentSafeKeyring) DeleteByAddress(address sdk.Address) error { - csk.mu.Lock() - defer csk.mu.Unlock() - - return csk.kr.DeleteByAddress(address) -} - -func (csk concurrentSafeKeyring) NewMnemonic(uid string, language keyring.Language, hdPath, bip39Passphrase string, algo keyring.SignatureAlgo) (*keyring.Record, string, error) { - csk.mu.Lock() - defer csk.mu.Unlock() - - return csk.kr.NewMnemonic(uid, language, hdPath, bip39Passphrase, algo) -} - -func (csk concurrentSafeKeyring) NewAccount(uid, mnemonic, bip39Passphrase, hdPath string, algo keyring.SignatureAlgo) (*keyring.Record, error) { - csk.mu.Lock() - defer csk.mu.Unlock() - - return csk.kr.NewAccount(uid, mnemonic, bip39Passphrase, hdPath, algo) -} - -func (csk concurrentSafeKeyring) SaveLedgerKey(uid string, algo keyring.SignatureAlgo, hrp string, coinType, account, index uint32) (*keyring.Record, error) { - csk.mu.Lock() - defer csk.mu.Unlock() - - return csk.kr.SaveLedgerKey(uid, algo, hrp, coinType, account, index) -} - -func (csk concurrentSafeKeyring) SaveMultisig(uid string, pubkey types.PubKey) (*keyring.Record, error) { - csk.mu.Lock() - defer csk.mu.Unlock() - - return csk.kr.SaveMultisig(uid, pubkey) -} - -func (csk concurrentSafeKeyring) ImportPrivKey(uid, armor, passphrase string) error { - csk.mu.Lock() - defer csk.mu.Unlock() - - return csk.kr.ImportPrivKey(uid, armor, passphrase) -} - -func (csk concurrentSafeKeyring) ImportPrivKeyHex(uid, privKey, algoStr string) error { - csk.mu.Lock() - defer csk.mu.Unlock() - - return csk.kr.ImportPrivKeyHex(uid, privKey, algoStr) -} - -func (csk concurrentSafeKeyring) ImportPubKey(uid, armor string) error { - csk.mu.Lock() - defer csk.mu.Unlock() - - return csk.kr.ImportPubKey(uid, armor) -} - -func (csk concurrentSafeKeyring) Backend() string { - return csk.kr.Backend() -} - -func (csk concurrentSafeKeyring) Rename(from, to string) error { - csk.mu.Lock() - defer csk.mu.Unlock() - - return csk.kr.Rename(from, to) -} - -func (csk concurrentSafeKeyring) SaveOfflineKey(uid string, pubkey types.PubKey) (*keyring.Record, error) { - csk.mu.Lock() - defer csk.mu.Unlock() - - return csk.kr.SaveOfflineKey(uid, pubkey) -} - -func (csk concurrentSafeKeyring) MigrateAll() ([]*keyring.Record, error) { - csk.mu.Lock() - defer csk.mu.Unlock() - - return csk.kr.MigrateAll() -} diff --git a/integration-tests/modules/assetft_test.go b/integration-tests/modules/assetft_test.go index c53f7f312..a5c198f8a 100644 --- a/integration-tests/modules/assetft_test.go +++ b/integration-tests/modules/assetft_test.go @@ -26,6 +26,7 @@ import ( moduleswasm "github.com/CoreumFoundation/coreum/v3/integration-tests/contracts/modules" "github.com/CoreumFoundation/coreum/v3/pkg/client" "github.com/CoreumFoundation/coreum/v3/testutil/event" + "github.com/CoreumFoundation/coreum/v3/testutil/integration" assetfttypes "github.com/CoreumFoundation/coreum/v3/x/asset/ft/types" ) @@ -49,7 +50,7 @@ func TestAssetFTIssue(t *testing.T) { requireT := require.New(t) issuer := chain.GenAccount() - chain.FundAccountWithOptions(ctx, t, issuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgIssue{}, }, @@ -100,7 +101,7 @@ func TestAssetFTIssueInvalidFeatures(t *testing.T) { requireT := require.New(t) issuer := chain.GenAccount() - chain.FundAccountWithOptions(ctx, t, issuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgIssue{}, &assetfttypes.MsgIssue{}, @@ -177,7 +178,7 @@ func TestAssetFTIssueFeeProposal(t *testing.T) { ) issuer := chain.GenAccount() - chain.FundAccountWithOptions(ctx, t, issuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgIssue{}, }, @@ -228,13 +229,13 @@ func TestAssetIssueAndQueryTokens(t *testing.T) { issueFee := chain.QueryAssetFTParams(ctx, t).IssueFee.Amount issuer1 := chain.GenAccount() - chain.FundAccountWithOptions(ctx, t, issuer1, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer1, integration.BalancesOptions{ Messages: []sdk.Msg{&assetfttypes.MsgIssue{}}, Amount: issueFee, }) issuer2 := chain.GenAccount() - chain.FundAccountWithOptions(ctx, t, issuer2, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer2, integration.BalancesOptions{ Messages: []sdk.Msg{&assetfttypes.MsgIssue{}}, Amount: issueFee, }) @@ -305,7 +306,7 @@ func TestBalanceQuery(t *testing.T) { issuer := chain.GenAccount() recipient := chain.GenAccount() - chain.FundAccountWithOptions(ctx, t, issuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgIssue{}, &assetfttypes.MsgSetWhitelistedLimit{}, @@ -427,7 +428,7 @@ func TestAssetFTMint(t *testing.T) { randomAddress := chain.GenAccount() bankClient := banktypes.NewQueryClient(chain.ClientContext) - chain.FundAccountWithOptions(ctx, t, issuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgIssue{}, &assetfttypes.MsgIssue{}, @@ -437,7 +438,7 @@ func TestAssetFTMint(t *testing.T) { Amount: chain.QueryAssetFTParams(ctx, t).IssueFee.Amount.MulRaw(2), }) - chain.FundAccountWithOptions(ctx, t, randomAddress, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, randomAddress, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgMint{}, }, @@ -560,7 +561,7 @@ func TestAssetFTBurn(t *testing.T) { recipient := chain.GenAccount() bankClient := banktypes.NewQueryClient(chain.ClientContext) - chain.FundAccountWithOptions(ctx, t, issuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &banktypes.MsgSend{}, &banktypes.MsgSend{}, @@ -572,7 +573,7 @@ func TestAssetFTBurn(t *testing.T) { Amount: chain.QueryAssetFTParams(ctx, t).IssueFee.Amount.MulRaw(2), }) - chain.FundAccountWithOptions(ctx, t, recipient, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, recipient, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgBurn{}, &assetfttypes.MsgBurn{}, @@ -744,19 +745,19 @@ func TestAssetFTBurnRate(t *testing.T) { recipient1 := chain.GenAccount() recipient2 := chain.GenAccount() - chain.FundAccountWithOptions(ctx, t, issuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgIssue{}, &banktypes.MsgSend{}, }, Amount: chain.QueryAssetFTParams(ctx, t).IssueFee.Amount, }) - chain.FundAccountWithOptions(ctx, t, recipient1, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, recipient1, integration.BalancesOptions{ Messages: []sdk.Msg{ &banktypes.MsgSend{}, }, }) - chain.FundAccountWithOptions(ctx, t, recipient2, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, recipient2, integration.BalancesOptions{ Messages: []sdk.Msg{ &banktypes.MsgSend{}, }, @@ -858,7 +859,7 @@ func TestAssetFTBurnRate(t *testing.T) { }, } - chain.FundAccountWithOptions(ctx, t, recipient1, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, recipient1, integration.BalancesOptions{ Messages: []sdk.Msg{ multiSendMsg, }, @@ -891,19 +892,19 @@ func TestAssetFTSendCommissionRate(t *testing.T) { recipient1 := chain.GenAccount() recipient2 := chain.GenAccount() - chain.FundAccountWithOptions(ctx, t, issuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgIssue{}, &banktypes.MsgSend{}, }, Amount: chain.QueryAssetFTParams(ctx, t).IssueFee.Amount, }) - chain.FundAccountWithOptions(ctx, t, recipient1, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, recipient1, integration.BalancesOptions{ Messages: []sdk.Msg{ &banktypes.MsgSend{}, }, }) - chain.FundAccountWithOptions(ctx, t, recipient2, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, recipient2, integration.BalancesOptions{ Messages: []sdk.Msg{ &banktypes.MsgSend{}, }, @@ -1005,7 +1006,7 @@ func TestAssetFTSendCommissionRate(t *testing.T) { }, } - chain.FundAccountWithOptions(ctx, t, recipient1, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, recipient1, integration.BalancesOptions{ Messages: []sdk.Msg{ multiSendMsg, }, @@ -1041,7 +1042,7 @@ func TestAssetFTFreeze(t *testing.T) { issuer := chain.GenAccount() recipient := chain.GenAccount() randomAddress := chain.GenAccount() - chain.FundAccountWithOptions(ctx, t, issuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgIssue{}, &banktypes.MsgSend{}, @@ -1053,7 +1054,7 @@ func TestAssetFTFreeze(t *testing.T) { }, Amount: chain.QueryAssetFTParams(ctx, t).IssueFee.Amount, }) - chain.FundAccountWithOptions(ctx, t, recipient, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, recipient, integration.BalancesOptions{ Messages: []sdk.Msg{ &banktypes.MsgSend{}, &banktypes.MsgMultiSend{}, @@ -1063,7 +1064,7 @@ func TestAssetFTFreeze(t *testing.T) { &banktypes.MsgSend{}, }, }) - chain.FundAccountWithOptions(ctx, t, randomAddress, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, randomAddress, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgFreeze{}, }, @@ -1331,7 +1332,7 @@ func TestAssetFTFreezeUnfreezable(t *testing.T) { assertT := assert.New(t) issuer := chain.GenAccount() recipient := chain.GenAccount() - chain.FundAccountWithOptions(ctx, t, issuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgIssue{}, &assetfttypes.MsgFreeze{}, @@ -1385,7 +1386,7 @@ func TestAssetFTFreezeIssuerAccount(t *testing.T) { requireT := require.New(t) issuer := chain.GenAccount() - chain.FundAccountWithOptions(ctx, t, issuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgIssue{}, &assetfttypes.MsgFreeze{}, @@ -1439,7 +1440,7 @@ func TestAssetFTGloballyFreeze(t *testing.T) { issuer := chain.GenAccount() recipient := chain.GenAccount() - chain.FundAccountWithOptions(ctx, t, issuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgIssue{}, &assetfttypes.MsgGloballyFreeze{}, @@ -1450,7 +1451,7 @@ func TestAssetFTGloballyFreeze(t *testing.T) { }, Amount: chain.QueryAssetFTParams(ctx, t).IssueFee.Amount, }) - chain.FundAccountWithOptions(ctx, t, recipient, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, recipient, integration.BalancesOptions{ Messages: []sdk.Msg{ &banktypes.MsgSend{}, &banktypes.MsgMultiSend{}, @@ -1605,7 +1606,7 @@ func TestAssetCommissionRateExceedFreeze(t *testing.T) { issuer := chain.GenAccount() recipient := chain.GenAccount() - chain.FundAccountWithOptions(ctx, t, issuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgIssue{}, &banktypes.MsgSend{}, @@ -1613,7 +1614,7 @@ func TestAssetCommissionRateExceedFreeze(t *testing.T) { }, Amount: chain.QueryAssetFTParams(ctx, t).IssueFee.Amount, }) - chain.FundAccountWithOptions(ctx, t, recipient, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, recipient, integration.BalancesOptions{ Messages: []sdk.Msg{ &banktypes.MsgSend{}, }, @@ -1690,7 +1691,7 @@ func TestSendCoreTokenWithRestrictedToken(t *testing.T) { issuer := chain.GenAccount() recipient := chain.GenAccount() - chain.FundAccountWithOptions(ctx, t, issuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgIssue{}, &banktypes.MsgSend{}, @@ -1698,7 +1699,7 @@ func TestSendCoreTokenWithRestrictedToken(t *testing.T) { }, Amount: chain.QueryAssetFTParams(ctx, t).IssueFee.Amount, }) - chain.FundAccountWithOptions(ctx, t, recipient, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, recipient, integration.BalancesOptions{ Messages: []sdk.Msg{ &banktypes.MsgSend{}, }, @@ -1779,14 +1780,14 @@ func TestNotEnoughBalanceForBurnRate(t *testing.T) { issuer := chain.GenAccount() recipient := chain.GenAccount() - chain.FundAccountWithOptions(ctx, t, issuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgIssue{}, &banktypes.MsgSend{}, }, Amount: chain.QueryAssetFTParams(ctx, t).IssueFee.Amount, }) - chain.FundAccountWithOptions(ctx, t, recipient, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, recipient, integration.BalancesOptions{ Messages: []sdk.Msg{ &banktypes.MsgSend{}, }, @@ -1858,14 +1859,14 @@ func TestNotEnoughBalanceForCommissionRate(t *testing.T) { issuer := chain.GenAccount() recipient := chain.GenAccount() - chain.FundAccountWithOptions(ctx, t, issuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgIssue{}, &banktypes.MsgSend{}, }, Amount: chain.QueryAssetFTParams(ctx, t).IssueFee.Amount, }) - chain.FundAccountWithOptions(ctx, t, recipient, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, recipient, integration.BalancesOptions{ Messages: []sdk.Msg{ &banktypes.MsgSend{}, }, @@ -1940,7 +1941,7 @@ func TestAssetFTWhitelist(t *testing.T) { issuer := chain.GenAccount() nonIssuer := chain.GenAccount() recipient := chain.GenAccount() - chain.FundAccountWithOptions(ctx, t, issuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgIssue{}, &assetfttypes.MsgSetWhitelistedLimit{}, @@ -1957,12 +1958,12 @@ func TestAssetFTWhitelist(t *testing.T) { }, Amount: chain.QueryAssetFTParams(ctx, t).IssueFee.Amount, }) - chain.FundAccountWithOptions(ctx, t, nonIssuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, nonIssuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgSetWhitelistedLimit{}, }, }) - chain.FundAccountWithOptions(ctx, t, recipient, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, recipient, integration.BalancesOptions{ Messages: []sdk.Msg{ &banktypes.MsgSend{}, }, @@ -2223,7 +2224,7 @@ func TestAssetFTWhitelistUnwhitelistable(t *testing.T) { assertT := assert.New(t) issuer := chain.GenAccount() recipient := chain.GenAccount() - chain.FundAccountWithOptions(ctx, t, issuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgIssue{}, &assetfttypes.MsgSetWhitelistedLimit{}, @@ -2277,7 +2278,7 @@ func TestAssetFTWhitelistIssuerAccount(t *testing.T) { requireT := require.New(t) issuer := chain.GenAccount() - chain.FundAccountWithOptions(ctx, t, issuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgIssue{}, &assetfttypes.MsgSetWhitelistedLimit{}, @@ -2336,7 +2337,7 @@ func TestBareToken(t *testing.T) { assertT := assert.New(t) issuer := chain.GenAccount() recipient := chain.GenAccount() - chain.FundAccountWithOptions(ctx, t, issuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgIssue{}, &assetfttypes.MsgMint{}, @@ -2348,7 +2349,7 @@ func TestBareToken(t *testing.T) { }, Amount: chain.QueryAssetFTParams(ctx, t).IssueFee.Amount, }) - chain.FundAccountWithOptions(ctx, t, recipient, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, recipient, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgBurn{}, }, @@ -2483,7 +2484,7 @@ func TestAuthzWithAssetFT(t *testing.T) { grantee := chain.GenAccount() recipient := chain.GenAccount() - chain.FundAccountWithOptions(ctx, t, granter, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, granter, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgIssue{}, &authztypes.MsgGrant{}, @@ -2551,7 +2552,7 @@ func TestAuthzWithAssetFT(t *testing.T) { } execMsg := authztypes.NewMsgExec(grantee, []sdk.Msg{msgFreeze, msgWhitelist}) - chain.FundAccountWithOptions(ctx, t, grantee, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, grantee, integration.BalancesOptions{ Messages: []sdk.Msg{ &execMsg, }, @@ -2594,7 +2595,7 @@ func TestAuthzMintAuthorizationLimit(t *testing.T) { granter := chain.GenAccount() grantee := chain.GenAccount() - chain.FundAccountWithOptions(ctx, t, granter, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, granter, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgIssue{}, &authztypes.MsgGrant{}, @@ -2646,7 +2647,7 @@ func TestAuthzMintAuthorizationLimit(t *testing.T) { } execMsg := authztypes.NewMsgExec(grantee, []sdk.Msg{msgMint}) - chain.FundAccountWithOptions(ctx, t, grantee, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, grantee, integration.BalancesOptions{ Messages: []sdk.Msg{ &execMsg, }, @@ -2681,7 +2682,7 @@ func TestAuthzMintAuthorizationLimit(t *testing.T) { } execMsg = authztypes.NewMsgExec(grantee, []sdk.Msg{msgMint}) - chain.FundAccountWithOptions(ctx, t, grantee, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, grantee, integration.BalancesOptions{ Messages: []sdk.Msg{ &execMsg, }, @@ -2703,7 +2704,7 @@ func TestAuthzMintAuthorizationLimit(t *testing.T) { } execMsg = authztypes.NewMsgExec(grantee, []sdk.Msg{msgMint}) - chain.FundAccountWithOptions(ctx, t, grantee, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, grantee, integration.BalancesOptions{ Messages: []sdk.Msg{ &execMsg, }, @@ -2739,14 +2740,14 @@ func TestAuthzMintAuthorizationLimit_GrantFromNonIssuer(t *testing.T) { granter := chain.GenAccount() grantee := chain.GenAccount() - chain.FundAccountWithOptions(ctx, t, issuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgIssue{}, }, Amount: chain.QueryAssetFTParams(ctx, t).IssueFee.Amount, }) - chain.FundAccountWithOptions(ctx, t, granter, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, granter, integration.BalancesOptions{ Messages: []sdk.Msg{ &authztypes.MsgGrant{}, &authztypes.MsgGrant{}, @@ -2804,7 +2805,7 @@ func TestAuthzMintAuthorizationLimit_GrantFromNonIssuer(t *testing.T) { } execMsg := authztypes.NewMsgExec(grantee, []sdk.Msg{msgMint}) - chain.FundAccountWithOptions(ctx, t, grantee, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, grantee, integration.BalancesOptions{ Messages: []sdk.Msg{ &execMsg, }, @@ -2830,7 +2831,7 @@ func TestAssetFT_RatesAreNotApplied_OnMinting(t *testing.T) { bankClient := banktypes.NewQueryClient(chain.ClientContext) - chain.FundAccountWithOptions(ctx, t, issuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgIssue{}, &assetfttypes.MsgMint{}, @@ -2895,7 +2896,7 @@ func TestAssetFTBurnRate_SendCommissionRate_OnBurning(t *testing.T) { bankClient := banktypes.NewQueryClient(chain.ClientContext) - chain.FundAccountWithOptions(ctx, t, issuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &banktypes.MsgSend{}, &assetfttypes.MsgIssue{}, @@ -2903,7 +2904,7 @@ func TestAssetFTBurnRate_SendCommissionRate_OnBurning(t *testing.T) { Amount: chain.QueryAssetFTParams(ctx, t).IssueFee.Amount, }) - chain.FundAccountWithOptions(ctx, t, recipient, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, recipient, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgBurn{}, }, @@ -2993,7 +2994,7 @@ func TestAssetFTFreezeAndBurn(t *testing.T) { bankClient := banktypes.NewQueryClient(chain.ClientContext) - chain.FundAccountWithOptions(ctx, t, issuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &banktypes.MsgSend{}, &assetfttypes.MsgIssue{}, @@ -3002,7 +3003,7 @@ func TestAssetFTFreezeAndBurn(t *testing.T) { Amount: chain.QueryAssetFTParams(ctx, t).IssueFee.Amount, }) - chain.FundAccountWithOptions(ctx, t, recipient, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, recipient, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgBurn{}, &assetfttypes.MsgBurn{}, @@ -3125,7 +3126,7 @@ func TestAssetFTFreeze_WithRates(t *testing.T) { recipient1 := chain.GenAccount() recipient2 := chain.GenAccount() - chain.FundAccountWithOptions(ctx, t, issuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &banktypes.MsgSend{}, &assetfttypes.MsgIssue{}, @@ -3134,7 +3135,7 @@ func TestAssetFTFreeze_WithRates(t *testing.T) { Amount: chain.QueryAssetFTParams(ctx, t).IssueFee.Amount, }) - chain.FundAccountWithOptions(ctx, t, recipient1, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, recipient1, integration.BalancesOptions{ Messages: []sdk.Msg{ &banktypes.MsgSend{}, &banktypes.MsgSend{}, @@ -3256,7 +3257,7 @@ func TestAssetFTAminoMultisig(t *testing.T) { bankClient := banktypes.NewQueryClient(chain.ClientContext) - chain.FundAccountWithOptions(ctx, t, multisigAddress, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, multisigAddress, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgIssue{}, &assetfttypes.MsgBurn{}, @@ -3336,7 +3337,7 @@ func TestAssetFTAminoMultisigWithAuthz(t *testing.T) { ) require.NoError(t, err) - chain.FundAccountWithOptions(ctx, t, multisigGranterAddress, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, multisigGranterAddress, integration.BalancesOptions{ Messages: []sdk.Msg{ grantMsg, }, @@ -3366,7 +3367,7 @@ func TestAssetFTAminoMultisigWithAuthz(t *testing.T) { execMsg := authztypes.NewMsgExec(multisigGranteeAddress, []sdk.Msg{issueMsg}) - chain.FundAccountWithOptions(ctx, t, multisigGranteeAddress, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, multisigGranteeAddress, integration.BalancesOptions{ Messages: []sdk.Msg{ &execMsg, }, @@ -3401,8 +3402,8 @@ func TestAssetFTSendCommissionAndBurnRateWithSmartContract(t *testing.T) { requireT := require.New(t) chain.Faucet.FundAccounts(ctx, t, - integrationtests.NewFundedAccount(issuer, chain.NewCoin(sdkmath.NewInt(5000000000))), - integrationtests.NewFundedAccount(admin, chain.NewCoin(sdkmath.NewInt(5000000000))), + integration.NewFundedAccount(issuer, chain.NewCoin(sdkmath.NewInt(5000000000))), + integration.NewFundedAccount(admin, chain.NewCoin(sdkmath.NewInt(5000000000))), ) clientCtx := chain.ClientContext @@ -3455,7 +3456,7 @@ func TestAssetFTSendCommissionAndBurnRateWithSmartContract(t *testing.T) { txf, issuer, moduleswasm.BankSendWASM, - integrationtests.InstantiateConfig{ + integration.InstantiateConfig{ AccessType: wasmtypes.AccessTypeUnspecified, Payload: initialPayload, Amount: sdk.NewInt64Coin(denom, 100), @@ -3571,7 +3572,7 @@ func TestAssetFTSendCommissionAndBurnRateWithSmartContract(t *testing.T) { ctx, txf, admin, - integrationtests.InstantiateConfig{ + integration.InstantiateConfig{ CodeID: contractCodeID, AccessType: wasmtypes.AccessTypeUnspecified, Payload: initialPayload, diff --git a/integration-tests/modules/assetnft_test.go b/integration-tests/modules/assetnft_test.go index b61f71f6e..3d6b481bb 100644 --- a/integration-tests/modules/assetnft_test.go +++ b/integration-tests/modules/assetnft_test.go @@ -25,6 +25,7 @@ import ( integrationtests "github.com/CoreumFoundation/coreum/v3/integration-tests" "github.com/CoreumFoundation/coreum/v3/pkg/client" "github.com/CoreumFoundation/coreum/v3/testutil/event" + "github.com/CoreumFoundation/coreum/v3/testutil/integration" assetnfttypes "github.com/CoreumFoundation/coreum/v3/x/asset/nft/types" "github.com/CoreumFoundation/coreum/v3/x/nft" ) @@ -50,7 +51,7 @@ func TestAssetNFTIssueClass(t *testing.T) { assetNftClient := assetnfttypes.NewQueryClient(chain.ClientContext) - chain.FundAccountWithOptions(ctx, t, issuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetnfttypes.MsgIssueClass{}, }, @@ -201,7 +202,7 @@ func TestAssetNFTIssueClassInvalidFeatures(t *testing.T) { ctx, chain := integrationtests.NewCoreumTestingContext(t) issuer := chain.GenAccount() - chain.FundAccountWithOptions(ctx, t, issuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetnfttypes.MsgIssueClass{}, &assetnfttypes.MsgIssueClass{}, @@ -268,7 +269,7 @@ func TestAssetNFTMint(t *testing.T) { recipient := chain.GenAccount() nftClient := nft.NewQueryClient(chain.ClientContext) - chain.FundAccountWithOptions(ctx, t, issuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetnfttypes.MsgIssueClass{}, &assetnfttypes.MsgMint{}, @@ -463,7 +464,7 @@ func TestAssetNFTMintFeeProposal(t *testing.T) { ) issuer := chain.GenAccount() - chain.FundAccountWithOptions(ctx, t, issuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetnfttypes.MsgIssueClass{}, &assetnfttypes.MsgMint{}, @@ -539,7 +540,7 @@ func TestAssetNFTBurn(t *testing.T) { nftClient := nft.NewQueryClient(chain.ClientContext) assetnftClient := assetnfttypes.NewQueryClient(chain.ClientContext) - chain.FundAccountWithOptions(ctx, t, issuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetnfttypes.MsgIssueClass{}, &assetnfttypes.MsgMint{}, @@ -700,7 +701,7 @@ func TestAssetNFTBurnFrozen(t *testing.T) { recipient1 := chain.GenAccount() assetNFTClient := assetnfttypes.NewQueryClient(chain.ClientContext) - chain.FundAccountWithOptions(ctx, t, issuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetnfttypes.MsgIssueClass{}, &assetnfttypes.MsgMint{}, @@ -711,7 +712,7 @@ func TestAssetNFTBurnFrozen(t *testing.T) { Amount: chain.QueryAssetNFTParams(ctx, t).MintFee.Amount, }) - chain.FundAccountWithOptions(ctx, t, recipient1, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, recipient1, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetnfttypes.MsgBurn{}, &assetnfttypes.MsgBurn{}, @@ -843,7 +844,7 @@ func TestAssetNFTBurnFrozen_Issuer(t *testing.T) { assetNFTClient := assetnfttypes.NewQueryClient(chain.ClientContext) nftClient := nft.NewQueryClient(chain.ClientContext) - chain.FundAccountWithOptions(ctx, t, issuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetnfttypes.MsgIssueClass{}, &assetnfttypes.MsgMint{}, @@ -946,7 +947,7 @@ func TestAssetNFTFreeze(t *testing.T) { recipient1 := chain.GenAccount() nftClient := assetnfttypes.NewQueryClient(chain.ClientContext) - chain.FundAccountWithOptions(ctx, t, issuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetnfttypes.MsgIssueClass{}, &assetnfttypes.MsgMint{}, @@ -957,7 +958,7 @@ func TestAssetNFTFreeze(t *testing.T) { Amount: chain.QueryAssetNFTParams(ctx, t).MintFee.Amount, }) - chain.FundAccountWithOptions(ctx, t, recipient1, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, recipient1, integration.BalancesOptions{ Messages: []sdk.Msg{ &nft.MsgSend{}, &nft.MsgSend{}, @@ -1140,7 +1141,7 @@ func TestAssetNFTWhitelist(t *testing.T) { recipient := chain.GenAccount() nftClient := assetnfttypes.NewQueryClient(chain.ClientContext) - chain.FundAccountWithOptions(ctx, t, issuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetnfttypes.MsgIssueClass{}, &assetnfttypes.MsgMint{}, @@ -1248,14 +1249,14 @@ func TestAssetNFTWhitelist(t *testing.T) { requireT.NoError(err) // send from whitelisted recipient to non-whitelisted recipient2 (send must fail) - chain.FundAccountWithOptions(ctx, t, recipient, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, recipient, integration.BalancesOptions{ Messages: []sdk.Msg{ &nft.MsgSend{}, &nft.MsgSend{}, }, }) recipient2 := chain.GenAccount() - chain.FundAccountWithOptions(ctx, t, recipient2, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, recipient2, integration.BalancesOptions{ Messages: []sdk.Msg{ &nft.MsgSend{}, &nft.MsgSend{}, @@ -1394,7 +1395,7 @@ func TestAssetNFTAuthZ(t *testing.T) { grantee := chain.GenAccount() nftClient := assetnfttypes.NewQueryClient(chain.ClientContext) - chain.FundAccountWithOptions(ctx, t, granter, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, granter, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetnfttypes.MsgIssueClass{}, &assetnfttypes.MsgMint{}, @@ -1447,7 +1448,7 @@ func TestAssetNFTAuthZ(t *testing.T) { } execMsg := authztypes.NewMsgExec(grantee, []sdk.Msg{freezeMsg}) - chain.FundAccountWithOptions(ctx, t, grantee, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, grantee, integration.BalancesOptions{ Messages: []sdk.Msg{ &execMsg, }, @@ -1488,7 +1489,7 @@ func TestAssetNFTAminoMultisig(t *testing.T) { nftClient := nft.NewQueryClient(chain.ClientContext) // fund the multisig account - chain.FundAccountWithOptions(ctx, t, multisigAddress, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, multisigAddress, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetnfttypes.MsgIssueClass{}, &assetnfttypes.MsgMint{}, diff --git a/integration-tests/modules/auth_test.go b/integration-tests/modules/auth_test.go index e84ef6aaf..e39fd93d8 100644 --- a/integration-tests/modules/auth_test.go +++ b/integration-tests/modules/auth_test.go @@ -13,6 +13,7 @@ import ( integrationtests "github.com/CoreumFoundation/coreum/v3/integration-tests" "github.com/CoreumFoundation/coreum/v3/pkg/client" + "github.com/CoreumFoundation/coreum/v3/testutil/integration" assetfttypes "github.com/CoreumFoundation/coreum/v3/x/asset/ft/types" ) @@ -26,7 +27,7 @@ func TestAuthFeeLimits(t *testing.T) { feeModel := getFeemodelParams(ctx, t, chain.ClientContext) maxBlockGas := feeModel.MaxBlockGas - chain.FundAccountWithOptions(ctx, t, sender, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, sender, integration.BalancesOptions{ Messages: []sdk.Msg{ &banktypes.MsgSend{}, &assetfttypes.MsgIssue{}, @@ -136,7 +137,7 @@ func TestAuthMultisig(t *testing.T) { bankClient := banktypes.NewQueryClient(chain.ClientContext) // fund the multisig account - chain.FundAccountWithOptions(ctx, t, multisigAddress, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, multisigAddress, integration.BalancesOptions{ Messages: []sdk.Msg{&banktypes.MsgSend{}}, Amount: sdkmath.NewInt(amountToSendFromMultisigAccount), }) @@ -187,7 +188,7 @@ func TestAuthUnexpectedSequenceNumber(t *testing.T) { sender := chain.GenAccount() - chain.FundAccountWithOptions(ctx, t, sender, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, sender, integration.BalancesOptions{ Messages: []sdk.Msg{&banktypes.MsgSend{}}, Amount: sdkmath.NewInt(10), }) diff --git a/integration-tests/modules/authz_test.go b/integration-tests/modules/authz_test.go index b8c2a2653..61e79e302 100644 --- a/integration-tests/modules/authz_test.go +++ b/integration-tests/modules/authz_test.go @@ -16,6 +16,7 @@ import ( integrationtests "github.com/CoreumFoundation/coreum/v3/integration-tests" "github.com/CoreumFoundation/coreum/v3/pkg/client" + "github.com/CoreumFoundation/coreum/v3/testutil/integration" ) // TestAuthz tests the authz module Grant/Execute/Revoke messages execution and their deterministic gas. @@ -34,7 +35,7 @@ func TestAuthz(t *testing.T) { recipient := chain.GenAccount() totalAmountToSend := sdkmath.NewInt(2_000) - chain.FundAccountWithOptions(ctx, t, granter, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, granter, integration.BalancesOptions{ Messages: []sdk.Msg{ &authztypes.MsgGrant{}, &authztypes.MsgRevoke{}, @@ -50,7 +51,7 @@ func TestAuthz(t *testing.T) { Amount: sdk.NewCoins(chain.NewCoin(sdkmath.NewInt(1_000))), } execMsg := authztypes.NewMsgExec(grantee, []sdk.Msg{msgBankSend, msgBankSend}) - chain.FundAccountWithOptions(ctx, t, grantee, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, grantee, integration.BalancesOptions{ Messages: []sdk.Msg{ msgBankSend, &execMsg, @@ -167,7 +168,7 @@ func TestAuthZWithMultisigGrantee(t *testing.T) { ) require.NoError(t, err) - chain.FundAccountWithOptions(ctx, t, granter, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, granter, integration.BalancesOptions{ Messages: []sdk.Msg{grantMsg}, Amount: sdkmath.NewInt(amountToSendFromMultisigAccount), }) @@ -187,7 +188,7 @@ func TestAuthZWithMultisigGrantee(t *testing.T) { Amount: coinsToSendToRecipient, } execMsg := authztypes.NewMsgExec(multisigAddress, []sdk.Msg{msgBankSend}) - chain.FundAccountWithOptions(ctx, t, multisigAddress, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, multisigAddress, integration.BalancesOptions{ Messages: []sdk.Msg{ &execMsg, }, @@ -249,7 +250,7 @@ func TestAuthZWithMultisigGranter(t *testing.T) { ) require.NoError(t, err) - chain.FundAccountWithOptions(ctx, t, multisigAddress, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, multisigAddress, integration.BalancesOptions{ Messages: []sdk.Msg{ grantMsg, }, @@ -273,7 +274,7 @@ func TestAuthZWithMultisigGranter(t *testing.T) { } execMsg := authztypes.NewMsgExec(grantee, []sdk.Msg{msgBankSend}) - chain.FundAccountWithOptions(ctx, t, grantee, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, grantee, integration.BalancesOptions{ Messages: []sdk.Msg{ &execMsg, }, diff --git a/integration-tests/modules/bank_test.go b/integration-tests/modules/bank_test.go index 267a6b295..1be8004e9 100644 --- a/integration-tests/modules/bank_test.go +++ b/integration-tests/modules/bank_test.go @@ -21,6 +21,7 @@ import ( integrationtests "github.com/CoreumFoundation/coreum/v3/integration-tests" "github.com/CoreumFoundation/coreum/v3/pkg/client" "github.com/CoreumFoundation/coreum/v3/testutil/event" + "github.com/CoreumFoundation/coreum/v3/testutil/integration" assetfttypes "github.com/CoreumFoundation/coreum/v3/x/asset/ft/types" ) @@ -79,7 +80,7 @@ func TestBankMultiSendBatchOutputs(t *testing.T) { }) } - chain.FundAccountWithOptions(ctx, t, issuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer, integration.BalancesOptions{ Messages: append([]sdk.Msg{issueMsg}, multiSendMsgs...), NondeterministicMessagesGas: 50_000_000, // to cover extra bytes because of the message size Amount: chain.QueryAssetFTParams(ctx, t).IssueFee.Amount, @@ -155,7 +156,7 @@ func TestBankSendBatchMsgs(t *testing.T) { for i := 0; i < iterationsToFund; i++ { fundMsgs = append(fundMsgs, bankSendSendMsgs...) } - chain.FundAccountWithOptions(ctx, t, issuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer, integration.BalancesOptions{ Messages: fundMsgs, Amount: chain.QueryAssetFTParams(ctx, t).IssueFee.Amount, }) @@ -195,7 +196,7 @@ func TestBankSendDeterministicGas(t *testing.T) { recipient := chain.GenAccount() amountToSend := sdkmath.NewInt(1000) - chain.FundAccountWithOptions(ctx, t, sender, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, sender, integration.BalancesOptions{ Messages: []sdk.Msg{&banktypes.MsgSend{}}, Amount: amountToSend, }) @@ -240,7 +241,7 @@ func TestBankSendDeterministicGasTwoBankSends(t *testing.T) { Amount: sdk.NewCoins(chain.NewCoin(sdkmath.NewInt(1000))), } - chain.FundAccountWithOptions(ctx, t, sender, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, sender, integration.BalancesOptions{ Messages: []sdk.Msg{bankSend1, bankSend2}, Amount: sdkmath.NewInt(2000), }) @@ -278,7 +279,7 @@ func TestBankSendDeterministicGasManyCoins(t *testing.T) { }) } - chain.FundAccountWithOptions(ctx, t, sender, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, sender, integration.BalancesOptions{ Messages: append([]sdk.Msg{&banktypes.MsgSend{ Amount: make(sdk.Coins, numOfTokens), }}, issueMsgs...), @@ -337,7 +338,7 @@ func TestBankSendFailsIfNotEnoughGasIsProvided(t *testing.T) { sender := chain.GenAccount() amountToSend := sdkmath.NewInt(1000) - chain.FundAccountWithOptions(ctx, t, sender, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, sender, integration.BalancesOptions{ Messages: []sdk.Msg{&banktypes.MsgSend{}}, Amount: amountToSend, }) @@ -368,7 +369,7 @@ func TestBankSendGasEstimation(t *testing.T) { sender := chain.GenAccount() amountToSend := sdkmath.NewInt(1000) - chain.FundAccountWithOptions(ctx, t, sender, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, sender, integration.BalancesOptions{ Messages: []sdk.Msg{&banktypes.MsgSend{}}, Amount: amountToSend, }) @@ -416,7 +417,7 @@ func TestBankMultiSendDeterministicGasManyCoins(t *testing.T) { }) } - chain.FundAccountWithOptions(ctx, t, sender, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, sender, integration.BalancesOptions{ Messages: append([]sdk.Msg{&banktypes.MsgMultiSend{ Inputs: []banktypes.Input{ { @@ -511,7 +512,7 @@ func TestBankMultiSend(t *testing.T) { }, } - chain.FundAccountWithOptions(ctx, t, sender, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, sender, integration.BalancesOptions{ Messages: append([]sdk.Msg{&banktypes.MsgMultiSend{ Inputs: []banktypes.Input{ {Coins: make(sdk.Coins, 2)}, @@ -683,14 +684,14 @@ func TestTryBankMultiSendFromMultipleAccounts(t *testing.T) { issueFee := chain.QueryAssetFTParams(ctx, t).IssueFee.Amount // fund accounts - chain.FundAccountWithOptions(ctx, t, sender1, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, sender1, integration.BalancesOptions{ Messages: []sdk.Msg{ multiSendMsg, issue1Msg, }, Amount: issueFee.Add(nativeAmountToSend.Amount), }) - chain.FundAccountWithOptions(ctx, t, sender2, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, sender2, integration.BalancesOptions{ Messages: []sdk.Msg{issue2Msg}, Amount: issueFee, }) @@ -767,11 +768,11 @@ func TestBankCoreSend(t *testing.T) { senderInitialAmount := sdkmath.NewInt(100) recipientInitialAmount := sdkmath.NewInt(10) - chain.FundAccountWithOptions(ctx, t, sender, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, sender, integration.BalancesOptions{ Messages: []sdk.Msg{&banktypes.MsgSend{}}, Amount: senderInitialAmount, }) - chain.FundAccountWithOptions(ctx, t, recipient, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, recipient, integration.BalancesOptions{ Amount: recipientInitialAmount, }) @@ -814,7 +815,7 @@ func TestBankCoreSend(t *testing.T) { func assertBatchAccounts( ctx context.Context, - chain integrationtests.CoreumChain, + chain integration.CoreumChain, expectedCoins sdk.Coins, fundedAccounts []sdk.AccAddress, denom string, diff --git a/integration-tests/modules/crisis_test.go b/integration-tests/modules/crisis_test.go index 38f1b846f..bf0c84a64 100644 --- a/integration-tests/modules/crisis_test.go +++ b/integration-tests/modules/crisis_test.go @@ -12,6 +12,7 @@ import ( integrationtests "github.com/CoreumFoundation/coreum/v3/integration-tests" "github.com/CoreumFoundation/coreum/v3/pkg/client" + "github.com/CoreumFoundation/coreum/v3/testutil/integration" ) // TestVerifyInvariantMessageIsDenied verifies that transactions containing crisis.MsgVerifyInvariant message are rejected. @@ -27,7 +28,7 @@ func TestVerifyInvariantMessageIsDenied(t *testing.T) { sender := chain.GenAccount() - chain.FundAccountWithOptions(ctx, t, sender, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, sender, integration.BalancesOptions{ Amount: sdkmath.NewIntFromUint64(invariantFee), }) diff --git a/integration-tests/modules/distribution_test.go b/integration-tests/modules/distribution_test.go index 7ed520d0d..f6dcb19fa 100644 --- a/integration-tests/modules/distribution_test.go +++ b/integration-tests/modules/distribution_test.go @@ -18,6 +18,7 @@ import ( integrationtests "github.com/CoreumFoundation/coreum/v3/integration-tests" "github.com/CoreumFoundation/coreum/v3/pkg/client" + "github.com/CoreumFoundation/coreum/v3/testutil/integration" customparamstypes "github.com/CoreumFoundation/coreum/v3/x/customparams/types" ) @@ -41,7 +42,7 @@ func TestDistributionSpendCommunityPoolProposal(t *testing.T) { Depositor: communityPoolFunder.String(), } - chain.FundAccountWithOptions(ctx, t, communityPoolFunder, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, communityPoolFunder, integration.BalancesOptions{ Messages: []sdk.Msg{ msgFundCommunityPool, }, @@ -75,7 +76,7 @@ func TestDistributionSpendCommunityPoolProposal(t *testing.T) { communityPoolRecipient := chain.GenAccount() - chain.Faucet.FundAccounts(ctx, t, integrationtests.NewFundedAccount(proposer, proposerBalance)) + chain.Faucet.FundAccounts(ctx, t, integration.NewFundedAccount(proposer, proposerBalance)) poolCoin := getCommunityPoolCoin(ctx, requireT, distributionClient) msgPoolSpend := &distributiontypes.MsgCommunityPoolSpend{ @@ -137,7 +138,7 @@ func TestDistributionWithdrawRewardWithDeterministicGas(t *testing.T) { requireT := require.New(t) // the amount of the delegation should be big enough to get at least some reward for the few blocks amountToDelegate := sdkmath.NewInt(1_000_000_000) - chain.FundAccountWithOptions(ctx, t, delegator, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, delegator, integration.BalancesOptions{ Messages: []sdk.Msg{ &stakingtypes.MsgDelegate{}, &distributiontypes.MsgWithdrawDelegatorReward{}, @@ -220,7 +221,7 @@ func TestDistributionWithdrawRewardWithDeterministicGas(t *testing.T) { requireT.NoError(err) delegatorBalanceAfterWithdrawal := delegatorBalanceRes.Balance - feeSpentOnWithdrawReward := chain.ComputeNeededBalanceFromOptions(integrationtests.BalancesOptions{ + feeSpentOnWithdrawReward := chain.ComputeNeededBalanceFromOptions(integration.BalancesOptions{ Messages: []sdk.Msg{withdrawRewardMsg}, }) @@ -272,7 +273,7 @@ func TestDistributionWithdrawRewardWithDeterministicGas(t *testing.T) { ValidatorAddress: validatorAddress.String(), } - chain.FundAccountWithOptions(ctx, t, validatorStakerAddress, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, validatorStakerAddress, integration.BalancesOptions{ Messages: []sdk.Msg{withdrawCommissionMsg}, }) @@ -293,7 +294,7 @@ func TestDistributionWithdrawRewardWithDeterministicGas(t *testing.T) { requireT.NoError(err) validatorStakerBalanceAfterWithdrawal := validatorStakerBalanceRes.Balance - feeSpentOnWithdrawCommission := chain.ComputeNeededBalanceFromOptions(integrationtests.BalancesOptions{ + feeSpentOnWithdrawCommission := chain.ComputeNeededBalanceFromOptions(integration.BalancesOptions{ Messages: []sdk.Msg{withdrawCommissionMsg}, }) diff --git a/integration-tests/modules/feegrant_test.go b/integration-tests/modules/feegrant_test.go index d57c6434c..b6d82ec26 100644 --- a/integration-tests/modules/feegrant_test.go +++ b/integration-tests/modules/feegrant_test.go @@ -15,6 +15,7 @@ import ( integrationtests "github.com/CoreumFoundation/coreum/v3/integration-tests" "github.com/CoreumFoundation/coreum/v3/pkg/client" + "github.com/CoreumFoundation/coreum/v3/testutil/integration" ) func TestFeeGrant(t *testing.T) { @@ -26,7 +27,7 @@ func TestFeeGrant(t *testing.T) { grantee := chain.GenAccount() recipient := chain.GenAccount() - chain.FundAccountWithOptions(ctx, t, granter, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, granter, integration.BalancesOptions{ Messages: []sdk.Msg{ &banktypes.MsgSend{}, &banktypes.MsgSend{}, @@ -34,7 +35,7 @@ func TestFeeGrant(t *testing.T) { &feegrant.MsgRevokeAllowance{}, }, }) - chain.FundAccountWithOptions(ctx, t, grantee, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, grantee, integration.BalancesOptions{ Amount: sdkmath.NewInt(1), }) basicAllowance, err := codetypes.NewAnyWithValue(&feegrant.BasicAllowance{ diff --git a/integration-tests/modules/feemodel_test.go b/integration-tests/modules/feemodel_test.go index 465087c07..bbab70999 100644 --- a/integration-tests/modules/feemodel_test.go +++ b/integration-tests/modules/feemodel_test.go @@ -15,6 +15,7 @@ import ( integrationtests "github.com/CoreumFoundation/coreum/v3/integration-tests" "github.com/CoreumFoundation/coreum/v3/pkg/client" + "github.com/CoreumFoundation/coreum/v3/testutil/integration" feemodeltypes "github.com/CoreumFoundation/coreum/v3/x/feemodel/types" ) @@ -78,7 +79,7 @@ func TestFeeModelProposalParamChange(t *testing.T) { // For the test we need to create the proposal twice. proposerBalance = proposerBalance.Add(proposerBalance) requireT.NoError(err) - chain.Faucet.FundAccounts(ctx, t, integrationtests.NewFundedAccount(proposer, proposerBalance)) + chain.Faucet.FundAccounts(ctx, t, integration.NewFundedAccount(proposer, proposerBalance)) feeModelParamsRes, err := feeModelClient.Params(ctx, &feemodeltypes.QueryParamsRequest{}) requireT.NoError(err) diff --git a/integration-tests/modules/gov_test.go b/integration-tests/modules/gov_test.go index c63d6d21a..e508b5643 100644 --- a/integration-tests/modules/gov_test.go +++ b/integration-tests/modules/gov_test.go @@ -15,6 +15,7 @@ import ( integrationtests "github.com/CoreumFoundation/coreum/v3/integration-tests" "github.com/CoreumFoundation/coreum/v3/pkg/client" + "github.com/CoreumFoundation/coreum/v3/testutil/integration" ) // TestGovProposalWithDepositAndWeightedVotes - is a complex governance test which tests: @@ -36,7 +37,7 @@ func TestGovProposalWithDepositAndWeightedVotes(t *testing.T) { requireT.NoError(err) proposerBalance = proposerBalance.Sub(missingDepositAmount) chain.Faucet.FundAccounts(ctx, t, - integrationtests.FundedAccount{ + integration.FundedAccount{ Address: proposer, Amount: proposerBalance, }, @@ -44,7 +45,7 @@ func TestGovProposalWithDepositAndWeightedVotes(t *testing.T) { // Create proposer depositor. depositor := chain.GenAccount() - chain.FundAccountWithOptions(ctx, t, depositor, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, depositor, integration.BalancesOptions{ Messages: []sdk.Msg{&govtypesv1beta1.MsgDeposit{}}, Amount: missingDepositAmount.Amount, }) diff --git a/integration-tests/modules/staking_test.go b/integration-tests/modules/staking_test.go index c09b6c0ba..e18cfdec9 100644 --- a/integration-tests/modules/staking_test.go +++ b/integration-tests/modules/staking_test.go @@ -20,6 +20,7 @@ import ( integrationtests "github.com/CoreumFoundation/coreum/v3/integration-tests" "github.com/CoreumFoundation/coreum/v3/pkg/client" + "github.com/CoreumFoundation/coreum/v3/testutil/integration" customparamstypes "github.com/CoreumFoundation/coreum/v3/x/customparams/types" ) @@ -36,7 +37,7 @@ func TestStakingProposalParamChange(t *testing.T) { proposerBalance, err := chain.Governance.ComputeProposerBalance(ctx) requireT.NoError(err) - chain.Faucet.FundAccounts(ctx, t, integrationtests.NewFundedAccount(proposer, proposerBalance)) + chain.Faucet.FundAccounts(ctx, t, integration.NewFundedAccount(proposer, proposerBalance)) stakingClient := stakingtypes.NewQueryClient(chain.ClientContext) paramsBeforeUpgrade, err := stakingClient.Params(ctx, &stakingtypes.QueryParamsRequest{}) @@ -118,7 +119,7 @@ func TestStakingValidatorCRUDAndStaking(t *testing.T) { delegator := chain.GenAccount() delegateAmount := sdkmath.NewInt(100) - chain.FundAccountWithOptions(ctx, t, delegator, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, delegator, integration.BalancesOptions{ Messages: []sdk.Msg{ &stakingtypes.MsgDelegate{}, &stakingtypes.MsgUndelegate{}, @@ -140,7 +141,7 @@ func TestStakingValidatorCRUDAndStaking(t *testing.T) { ValidatorAddress: validatorAddress.String(), } - chain.FundAccountWithOptions(ctx, t, validatorAccAddress, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, validatorAccAddress, integration.BalancesOptions{ Messages: []sdk.Msg{editValidatorMsg}, }) @@ -307,7 +308,7 @@ func TestValidatorUpdateWithLowMinSelfDelegation(t *testing.T) { }, ValidatorAddress: validatorAddress.String(), } - chain.FundAccountWithOptions(ctx, t, validatorAccAddress, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, validatorAccAddress, integration.BalancesOptions{ Messages: []sdk.Msg{editValidatorMsg}, }) @@ -330,7 +331,7 @@ func TestValidatorUpdateWithLowMinSelfDelegation(t *testing.T) { func changeMinSelfDelegationCustomParam( ctx context.Context, t *testing.T, - chain integrationtests.CoreumChain, + chain integration.CoreumChain, customParamsClient customparamstypes.QueryClient, newMinSelfDelegation sdkmath.Int, ) { @@ -355,7 +356,7 @@ func changeMinSelfDelegationCustomParam( requireT.Equal(newMinSelfDelegation.String(), customStakingParams.Params.MinSelfDelegation.String()) } -func setUnbondingTimeViaGovernance(ctx context.Context, t *testing.T, chain integrationtests.CoreumChain, unbondingTime time.Duration) { +func setUnbondingTimeViaGovernance(ctx context.Context, t *testing.T, chain integration.CoreumChain, unbondingTime time.Duration) { requireT := require.New(t) // Create new proposer. @@ -363,7 +364,7 @@ func setUnbondingTimeViaGovernance(ctx context.Context, t *testing.T, chain inte proposerBalance, err := chain.Governance.ComputeProposerBalance(ctx) requireT.NoError(err) - chain.Faucet.FundAccounts(ctx, t, integrationtests.NewFundedAccount(proposer, proposerBalance)) + chain.Faucet.FundAccounts(ctx, t, integration.NewFundedAccount(proposer, proposerBalance)) stakingClient := stakingtypes.NewQueryClient(chain.ClientContext) paramsBeforeUpgrade, err := stakingClient.Params(ctx, &stakingtypes.QueryParamsRequest{}) @@ -400,7 +401,7 @@ func setUnbondingTimeViaGovernance(ctx context.Context, t *testing.T, chain inte requireT.Equal(unbondingTime, stakingParams.Params.UnbondingTime) } -func getBalance(ctx context.Context, t *testing.T, chain integrationtests.CoreumChain, addr sdk.AccAddress) sdk.Coin { +func getBalance(ctx context.Context, t *testing.T, chain integration.CoreumChain, addr sdk.AccAddress) sdk.Coin { bankClient := banktypes.NewQueryClient(chain.ClientContext) resp, err := bankClient.Balance(ctx, &banktypes.QueryBalanceRequest{ Address: addr.String(), diff --git a/integration-tests/modules/vesting_test.go b/integration-tests/modules/vesting_test.go index d576aec13..c79c8dc9e 100644 --- a/integration-tests/modules/vesting_test.go +++ b/integration-tests/modules/vesting_test.go @@ -17,6 +17,7 @@ import ( integrationtests "github.com/CoreumFoundation/coreum/v3/integration-tests" "github.com/CoreumFoundation/coreum/v3/pkg/client" + "github.com/CoreumFoundation/coreum/v3/testutil/integration" assetfttypes "github.com/CoreumFoundation/coreum/v3/x/asset/ft/types" customparamstypes "github.com/CoreumFoundation/coreum/v3/x/customparams/types" ) @@ -36,7 +37,7 @@ func TestVestingAccountCreationAndBankSend(t *testing.T) { bankClient := banktypes.NewQueryClient(chain.ClientContext) amountToVest := sdkmath.NewInt(100) - chain.FundAccountWithOptions(ctx, t, creator, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, creator, integration.BalancesOptions{ Messages: []sdk.Msg{&vestingtypes.MsgCreateVestingAccount{}}, Amount: amountToVest, }) @@ -75,7 +76,7 @@ func TestVestingAccountCreationAndBankSend(t *testing.T) { requireT.Equal(vestingCoin.String(), balanceRes.Balance.String()) // fund the vesting account to pay fees - chain.FundAccountWithOptions(ctx, t, vestingAcc, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, vestingAcc, integration.BalancesOptions{ Messages: []sdk.Msg{ &banktypes.MsgSend{}, }, @@ -104,7 +105,7 @@ func TestVestingAccountCreationAndBankSend(t *testing.T) { } // fund the vesting account to pay fees one more time - chain.FundAccountWithOptions(ctx, t, vestingAcc, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, vestingAcc, integration.BalancesOptions{ Messages: []sdk.Msg{&banktypes.MsgSend{}}, }) @@ -133,7 +134,7 @@ func TestVestingAccountStaking(t *testing.T) { customParamsClient := customparamstypes.NewQueryClient(chain.ClientContext) amountToVest := sdkmath.NewInt(100) - chain.FundAccountWithOptions(ctx, t, creator, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, creator, integration.BalancesOptions{ Messages: []sdk.Msg{&vestingtypes.MsgCreateVestingAccount{}}, Amount: amountToVest, }) @@ -181,7 +182,7 @@ func TestVestingAccountStaking(t *testing.T) { requireT.Equal(vestingCoin.String(), balanceRes.Balance.String()) // fund the vesting account to pay fees for the staking - chain.FundAccountWithOptions(ctx, t, vestingAcc, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, vestingAcc, integration.BalancesOptions{ Messages: []sdk.Msg{ &stakingtypes.MsgDelegate{}, }, @@ -216,7 +217,7 @@ func TestVestingAccountWithFTInteraction(t *testing.T) { requireT := require.New(t) bankClient := banktypes.NewQueryClient(chain.ClientContext) - chain.FundAccountWithOptions(ctx, t, issuer, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, issuer, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgSetWhitelistedLimit{}, &assetfttypes.MsgSetWhitelistedLimit{}, @@ -310,7 +311,7 @@ func TestVestingAccountWithFTInteraction(t *testing.T) { requireT.Equal(vestingCoin.String(), balanceRes.Balance.String()) // fund the vesting account to pay fees - chain.FundAccountWithOptions(ctx, t, vestingAcc, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, vestingAcc, integration.BalancesOptions{ Messages: []sdk.Msg{ &assetfttypes.MsgBurn{}, &assetfttypes.MsgBurn{}, diff --git a/integration-tests/modules/wasm_test.go b/integration-tests/modules/wasm_test.go index 1841ba995..cebbbb834 100644 --- a/integration-tests/modules/wasm_test.go +++ b/integration-tests/modules/wasm_test.go @@ -26,6 +26,7 @@ import ( integrationtests "github.com/CoreumFoundation/coreum/v3/integration-tests" moduleswasm "github.com/CoreumFoundation/coreum/v3/integration-tests/contracts/modules" "github.com/CoreumFoundation/coreum/v3/pkg/client" + "github.com/CoreumFoundation/coreum/v3/testutil/integration" assetfttypes "github.com/CoreumFoundation/coreum/v3/x/asset/ft/types" assetnfttypes "github.com/CoreumFoundation/coreum/v3/x/asset/nft/types" nfttypes "github.com/CoreumFoundation/coreum/v3/x/nft" @@ -129,7 +130,7 @@ func TestWASMBankSendContract(t *testing.T) { requireT := require.New(t) chain.Faucet.FundAccounts(ctx, t, - integrationtests.NewFundedAccount(admin, chain.NewCoin(sdkmath.NewInt(5000000000))), + integration.NewFundedAccount(admin, chain.NewCoin(sdkmath.NewInt(5000000000))), ) clientCtx := chain.ClientContext @@ -145,7 +146,7 @@ func TestWASMBankSendContract(t *testing.T) { txf, admin, moduleswasm.BankSendWASM, - integrationtests.InstantiateConfig{ + integration.InstantiateConfig{ AccessType: wasmtypes.AccessTypeUnspecified, Payload: initialPayload, Amount: chain.NewCoin(sdkmath.NewInt(10000)), @@ -245,7 +246,7 @@ func TestWASMGasBankSendAndBankSend(t *testing.T) { admin := chain.GenAccount() chain.Faucet.FundAccounts(ctx, t, - integrationtests.NewFundedAccount(admin, chain.NewCoin(sdkmath.NewInt(5000000000))), + integration.NewFundedAccount(admin, chain.NewCoin(sdkmath.NewInt(5000000000))), ) // deployWASMContract and init contract with the initial coins amount @@ -261,7 +262,7 @@ func TestWASMGasBankSendAndBankSend(t *testing.T) { txf, admin, moduleswasm.BankSendWASM, - integrationtests.InstantiateConfig{ + integration.InstantiateConfig{ AccessType: wasmtypes.AccessTypeUnspecified, Payload: initialPayload, Amount: chain.NewCoin(sdkmath.NewInt(10000)), @@ -322,8 +323,8 @@ func TestWASMPinningAndUnpinningSmartContractUsingGovernance(t *testing.T) { proposerBalance.Amount = proposerBalance.Amount.MulRaw(2) chain.Faucet.FundAccounts(ctx, t, - integrationtests.NewFundedAccount(admin, chain.NewCoin(sdkmath.NewInt(5000000000))), - integrationtests.NewFundedAccount(proposer, proposerBalance), + integration.NewFundedAccount(admin, chain.NewCoin(sdkmath.NewInt(5000000000))), + integration.NewFundedAccount(proposer, proposerBalance), ) // instantiateWASMContract the contract and set the initial counter state. @@ -340,7 +341,7 @@ func TestWASMPinningAndUnpinningSmartContractUsingGovernance(t *testing.T) { txf, admin, moduleswasm.SimpleStateWASM, - integrationtests.InstantiateConfig{ + integration.InstantiateConfig{ AccessType: wasmtypes.AccessTypeUnspecified, Payload: initialPayload, Label: "simple_state", @@ -434,8 +435,8 @@ func TestWASMContractUpgrade(t *testing.T) { wasmClient := wasmtypes.NewQueryClient(chain.ClientContext) chain.Faucet.FundAccounts(ctx, t, - integrationtests.NewFundedAccount(admin, chain.NewCoin(sdkmath.NewInt(5000000))), - integrationtests.NewFundedAccount(noneAdmin, chain.NewCoin(sdkmath.NewInt(5000000))), + integration.NewFundedAccount(admin, chain.NewCoin(sdkmath.NewInt(5000000))), + integration.NewFundedAccount(noneAdmin, chain.NewCoin(sdkmath.NewInt(5000000))), ) // instantiateWASMContract the contract and set the initial counter state. @@ -452,7 +453,7 @@ func TestWASMContractUpgrade(t *testing.T) { txf, admin, moduleswasm.SimpleStateWASM, - integrationtests.InstantiateConfig{ + integration.InstantiateConfig{ Admin: admin, AccessType: wasmtypes.AccessTypeUnspecified, Payload: initialPayload, @@ -517,9 +518,9 @@ func TestUpdateAndClearAdminOfContract(t *testing.T) { requireT := require.New(t) chain.Faucet.FundAccounts(ctx, t, - integrationtests.NewFundedAccount(admin, chain.NewCoin(sdkmath.NewInt(5000000000))), + integration.NewFundedAccount(admin, chain.NewCoin(sdkmath.NewInt(5000000000))), ) - chain.FundAccountWithOptions(ctx, t, newAdmin, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, newAdmin, integration.BalancesOptions{ Messages: []sdk.Msg{ &wasmtypes.MsgClearAdmin{}, }, @@ -535,7 +536,7 @@ func TestUpdateAndClearAdminOfContract(t *testing.T) { chain.TxFactory().WithSimulateAndExecute(true), admin, moduleswasm.BankSendWASM, - integrationtests.InstantiateConfig{ + integration.InstantiateConfig{ AccessType: wasmtypes.AccessTypeUnspecified, Admin: admin, Payload: initialPayload, @@ -615,7 +616,7 @@ func TestWASMAuthzContract(t *testing.T) { totalAmountToSend := sdkmath.NewInt(2_000) chain.Faucet.FundAccounts(ctx, t, - integrationtests.NewFundedAccount(granter, chain.NewCoin(sdkmath.NewInt(5000000000))), + integration.NewFundedAccount(granter, chain.NewCoin(sdkmath.NewInt(5000000000))), ) // deployWASMContract and init contract with the granter. @@ -629,7 +630,7 @@ func TestWASMAuthzContract(t *testing.T) { chain.TxFactory().WithSimulateAndExecute(true), granter, moduleswasm.AuthzWASM, - integrationtests.InstantiateConfig{ + integration.InstantiateConfig{ AccessType: wasmtypes.AccessTypeUnspecified, Payload: initialPayload, Label: "authz", @@ -697,7 +698,7 @@ func TestWASMFungibleTokenInContract(t *testing.T) { requireT := require.New(t) chain.Faucet.FundAccounts(ctx, t, - integrationtests.NewFundedAccount(admin, chain.NewCoin(sdkmath.NewInt(5000000000))), + integration.NewFundedAccount(admin, chain.NewCoin(sdkmath.NewInt(5000000000))), ) clientCtx := chain.ClientContext @@ -736,7 +737,7 @@ func TestWASMFungibleTokenInContract(t *testing.T) { txf, admin, moduleswasm.FTWASM, - integrationtests.InstantiateConfig{ + integration.InstantiateConfig{ // we add the initial amount to let the contract issue the token on behalf of it Amount: chain.QueryAssetFTParams(ctx, t).IssueFee, AccessType: wasmtypes.AccessTypeUnspecified, @@ -1095,7 +1096,7 @@ func TestWASMNonFungibleTokenInContract(t *testing.T) { requireT := require.New(t) chain.Faucet.FundAccounts(ctx, t, - integrationtests.NewFundedAccount(admin, chain.NewCoin(sdkmath.NewInt(5000000000))), + integration.NewFundedAccount(admin, chain.NewCoin(sdkmath.NewInt(5000000000))), ) clientCtx := chain.ClientContext @@ -1137,7 +1138,7 @@ func TestWASMNonFungibleTokenInContract(t *testing.T) { txf, admin, moduleswasm.NftWASM, - integrationtests.InstantiateConfig{ + integration.InstantiateConfig{ AccessType: wasmtypes.AccessTypeUnspecified, Payload: issuerNFTInstantiatePayload, Label: "non_fungible_token", @@ -1643,7 +1644,7 @@ func TestWASMBankSendContractWithMultipleFundsAttached(t *testing.T) { requireT := require.New(t) chain.Faucet.FundAccounts(ctx, t, - integrationtests.NewFundedAccount(admin, chain.NewCoin(sdk.NewInt(5000_000_000))), + integration.NewFundedAccount(admin, chain.NewCoin(sdk.NewInt(5000_000_000))), ) // deployWASMContract and init contract with the initial coins amount @@ -1655,7 +1656,7 @@ func TestWASMBankSendContractWithMultipleFundsAttached(t *testing.T) { WithSimulateAndExecute(true), admin, moduleswasm.BankSendWASM, - integrationtests.InstantiateConfig{ + integration.InstantiateConfig{ AccessType: wasmtypes.AccessTypeUnspecified, Payload: initialPayload, Amount: chain.NewCoin(sdk.NewInt(10000)), diff --git a/integration-tests/unsafe.go b/integration-tests/unsafe.go deleted file mode 100644 index a5e3bf324..000000000 --- a/integration-tests/unsafe.go +++ /dev/null @@ -1,10 +0,0 @@ -package integrationtests - -import "testing" - -// SkipUnsafe skips the test if run-unsafe flag is set to false. -func SkipUnsafe(t *testing.T) { - if !runUnsafe { - t.SkipNow() - } -} diff --git a/integration-tests/upgrade/gov_migration_test.go b/integration-tests/upgrade/gov_migration_test.go index ac25e300d..878551496 100644 --- a/integration-tests/upgrade/gov_migration_test.go +++ b/integration-tests/upgrade/gov_migration_test.go @@ -14,6 +14,7 @@ import ( integrationtests "github.com/CoreumFoundation/coreum/v3/integration-tests" "github.com/CoreumFoundation/coreum/v3/pkg/client" + "github.com/CoreumFoundation/coreum/v3/testutil/integration" ) var ( @@ -39,7 +40,7 @@ func (gmt *govMigrationTest) Before(t *testing.T) { } chain.FundAccountWithOptions(ctx, t, communityPoolFunder, - integrationtests.BalancesOptions{ + integration.BalancesOptions{ Messages: []sdk.Msg{ msgFundCommunityPool, }, @@ -57,7 +58,7 @@ func (gmt *govMigrationTest) Before(t *testing.T) { proposer := chain.GenAccount() proposerBalance, err := chain.LegacyGovernance.ComputeProposerBalance(ctx) requireT.NoError(err) - chain.Faucet.FundAccounts(ctx, t, integrationtests.NewFundedAccount(proposer, proposerBalance)) + chain.Faucet.FundAccounts(ctx, t, integration.NewFundedAccount(proposer, proposerBalance)) communityPoolRecipient := chain.GenAccount() proposalMsg, err := chain.LegacyGovernance.NewMsgSubmitProposalV1Beta1( @@ -100,7 +101,7 @@ func (gmt *govMigrationTest) After(t *testing.T) { depositor := chain.GenAccount() requireT.NoError(err) - chain.FundAccountWithOptions(ctx, t, depositor, integrationtests.BalancesOptions{ + chain.FundAccountWithOptions(ctx, t, depositor, integration.BalancesOptions{ Messages: []sdk.Msg{&govtypesv1.MsgDeposit{}}, Amount: missingDepositAmount, }) diff --git a/integration-tests/upgrade/ibc_test.go b/integration-tests/upgrade/ibc_test.go index fc360a5ee..fcf55fe65 100644 --- a/integration-tests/upgrade/ibc_test.go +++ b/integration-tests/upgrade/ibc_test.go @@ -12,6 +12,7 @@ import ( integrationtests "github.com/CoreumFoundation/coreum/v3/integration-tests" integrationtestsibc "github.com/CoreumFoundation/coreum/v3/integration-tests/ibc" + "github.com/CoreumFoundation/coreum/v3/testutil/integration" ) type ibcUpgradeTest struct { @@ -36,21 +37,21 @@ func (iut *ibcUpgradeTest) Before(t *testing.T) { gaiaRecipient := gaiaChain.GenAccount() // account to receive IBC transfer form Coreum to Gaia sendToGaiaCoin := coreumChain.NewCoin(sdkmath.NewInt(1000)) - coreumChain.FundAccountWithOptions(ctx, t, coreumSender, integrationtests.BalancesOptions{ + coreumChain.FundAccountWithOptions(ctx, t, coreumSender, integration.BalancesOptions{ Messages: []sdk.Msg{&ibctransfertypes.MsgTransfer{}}, Amount: sendToGaiaCoin.Amount, }) - coreumChain.FundAccountWithOptions(ctx, t, coreumRecipient, integrationtests.BalancesOptions{ + coreumChain.FundAccountWithOptions(ctx, t, coreumRecipient, integration.BalancesOptions{ Messages: []sdk.Msg{&ibctransfertypes.MsgTransfer{}}, }) sendToCoreumCoin := gaiaChain.NewCoin(sdkmath.NewInt(1500)) gaiaFeesCoin := gaiaChain.NewCoin(sdkmath.NewInt(1000000)) - gaiaChain.Faucet.FundAccounts(ctx, t, integrationtests.FundedAccount{ + gaiaChain.Faucet.FundAccounts(ctx, t, integration.FundedAccount{ Address: gaiaSender, Amount: sendToCoreumCoin.Add(gaiaFeesCoin), // amount to send + coin for the fees }) - gaiaChain.Faucet.FundAccounts(ctx, t, integrationtests.FundedAccount{ + gaiaChain.Faucet.FundAccounts(ctx, t, integration.FundedAccount{ Address: gaiaRecipient, Amount: gaiaFeesCoin, // coin for the fees }) diff --git a/integration-tests/upgrade/params_migration_test.go b/integration-tests/upgrade/params_migration_test.go index 41667fe8d..e3f701d15 100644 --- a/integration-tests/upgrade/params_migration_test.go +++ b/integration-tests/upgrade/params_migration_test.go @@ -27,6 +27,7 @@ import ( "github.com/stretchr/testify/require" integrationtests "github.com/CoreumFoundation/coreum/v3/integration-tests" + "github.com/CoreumFoundation/coreum/v3/testutil/integration" assetfttypes "github.com/CoreumFoundation/coreum/v3/x/asset/ft/types" assetnfttypes "github.com/CoreumFoundation/coreum/v3/x/asset/nft/types" customparams "github.com/CoreumFoundation/coreum/v3/x/customparams/types" @@ -226,7 +227,7 @@ func (pmt *paramsMigrationTest) After(t *testing.T) { assertT.Equal(pmt.wasmParamsBeforeMigration, wasmResp.Params) } -func querySubspaceParamsValue(ctx context.Context, t *testing.T, chain integrationtests.CoreumChain, subspace string, key string) string { +func querySubspaceParamsValue(ctx context.Context, t *testing.T, chain integration.CoreumChain, subspace, key string) string { res, err := paramstypesproposal.NewQueryClient(chain.ClientContext).Params( ctx, ¶mstypesproposal.QueryParamsRequest{Subspace: subspace, Key: key}, @@ -235,7 +236,7 @@ func querySubspaceParamsValue(ctx context.Context, t *testing.T, chain integrati return res.Param.Value } -func queryConsensusParams(ctx context.Context, t *testing.T, chain integrationtests.CoreumChain) tmtypes.ConsensusParams { +func queryConsensusParams(ctx context.Context, t *testing.T, chain integration.CoreumChain) tmtypes.ConsensusParams { requireT := require.New(t) blockParamsJSONStr := querySubspaceParamsValue(ctx, t, chain, "baseapp", "BlockParams") diff --git a/integration-tests/upgrade/upgrade_test.go b/integration-tests/upgrade/upgrade_test.go index c2ee077d1..66fa5909d 100644 --- a/integration-tests/upgrade/upgrade_test.go +++ b/integration-tests/upgrade/upgrade_test.go @@ -17,6 +17,7 @@ import ( "github.com/CoreumFoundation/coreum-tools/pkg/retry" appupgradev3 "github.com/CoreumFoundation/coreum/v3/app/upgrade/v3" integrationtests "github.com/CoreumFoundation/coreum/v3/integration-tests" + "github.com/CoreumFoundation/coreum/v3/testutil/integration" ) type upgradeTest interface { @@ -95,7 +96,7 @@ func runUpgrade( proposerBalance, err := chain.LegacyGovernance.ComputeProposerBalance(ctx) requireT.NoError(err) - chain.Faucet.FundAccounts(ctx, t, integrationtests.NewFundedAccount(proposer, proposerBalance)) + chain.Faucet.FundAccounts(ctx, t, integration.NewFundedAccount(proposer, proposerBalance)) t.Logf("Creating proposal for upgrading, upgradeName:%s, upgradeHeight:%d", upgradeName, upgradeHeight) diff --git a/integration-tests/upgrade/wasm_migration_test.go b/integration-tests/upgrade/wasm_migration_test.go index 8f2de5067..638d0393a 100644 --- a/integration-tests/upgrade/wasm_migration_test.go +++ b/integration-tests/upgrade/wasm_migration_test.go @@ -13,6 +13,7 @@ import ( integrationtests "github.com/CoreumFoundation/coreum/v3/integration-tests" moduleswasm "github.com/CoreumFoundation/coreum/v3/integration-tests/contracts/modules" + "github.com/CoreumFoundation/coreum/v3/testutil/integration" ) type wasmMigrationTest struct { @@ -28,7 +29,7 @@ func (wmt *wasmMigrationTest) Before(t *testing.T) { admin := chain.GenAccount() chain.Faucet.FundAccounts(ctx, t, - integrationtests.NewFundedAccount(admin, chain.NewCoin(sdkmath.NewInt(5000000))), + integration.NewFundedAccount(admin, chain.NewCoin(sdkmath.NewInt(5000000))), ) // instantiateWASMContract the contract and set the initial counter state. @@ -46,7 +47,7 @@ func (wmt *wasmMigrationTest) Before(t *testing.T) { txf, admin, moduleswasm.SimpleStateWASM, - integrationtests.InstantiateConfig{ + integration.InstantiateConfig{ Admin: admin, AccessType: wasmtypes.AccessTypeUnspecified, Payload: initialPayload, diff --git a/pkg/keyring/keyring.go b/pkg/keyring/keyring.go new file mode 100644 index 000000000..01b88f9b2 --- /dev/null +++ b/pkg/keyring/keyring.go @@ -0,0 +1,215 @@ +package keyring + +import ( + "sync" + + "github.com/cosmos/cosmos-sdk/crypto/keyring" + "github.com/cosmos/cosmos-sdk/crypto/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var _ keyring.Keyring = ConcurrentSafeKeyring{} + +// ConcurrentSafeKeyring wraps standard Cosmos SDK keyring implementation to make it concurrent safe. +// Since we run our integration tests in parallel from time to time we get: "concurrent map read and map write" +// so ConcurrentSafeKeyring wraps all methods of keyring and locks mutex before calling method. +type ConcurrentSafeKeyring struct { + mu *sync.RWMutex + kr keyring.Keyring +} + +// NewConcurrentSafeKeyring returns new instance of ConcurrentSafeKeyring. +func NewConcurrentSafeKeyring(kr keyring.Keyring) ConcurrentSafeKeyring { + return ConcurrentSafeKeyring{ + mu: &sync.RWMutex{}, + kr: kr, + } +} + +// Read operations: + +// SupportedAlgorithms supported signing algorithms for Keyring and Ledger respectively. +func (csk ConcurrentSafeKeyring) SupportedAlgorithms() (keyring.SigningAlgoList, keyring.SigningAlgoList) { + return csk.kr.SupportedAlgorithms() +} + +// List lists all keys. +func (csk ConcurrentSafeKeyring) List() ([]*keyring.Record, error) { + csk.mu.RLock() + defer csk.mu.RUnlock() + + return csk.kr.List() +} + +// Key returns keys by uid. +func (csk ConcurrentSafeKeyring) Key(uid string) (*keyring.Record, error) { + csk.mu.RLock() + defer csk.mu.RUnlock() + + return csk.kr.Key(uid) +} + +// KeyByAddress return keys by address. +func (csk ConcurrentSafeKeyring) KeyByAddress(address sdk.Address) (*keyring.Record, error) { + csk.mu.RLock() + defer csk.mu.RUnlock() + + return csk.kr.KeyByAddress(address) +} + +// ExportPubKeyArmor exports public key armor by uid. +func (csk ConcurrentSafeKeyring) ExportPubKeyArmor(uid string) (string, error) { + csk.mu.RLock() + defer csk.mu.RUnlock() + + return csk.kr.ExportPubKeyArmor(uid) +} + +// ExportPubKeyArmorByAddress exports public key armor by address. +func (csk ConcurrentSafeKeyring) ExportPubKeyArmorByAddress(address sdk.Address) (string, error) { + csk.mu.RLock() + defer csk.mu.RUnlock() + + return csk.kr.ExportPubKeyArmorByAddress(address) +} + +// ExportPrivKeyArmor exports priv key armor by uid. +func (csk ConcurrentSafeKeyring) ExportPrivKeyArmor(uid, encryptPassphrase string) (armor string, err error) { + csk.mu.RLock() + defer csk.mu.RUnlock() + + return csk.kr.ExportPrivKeyArmor(uid, encryptPassphrase) +} + +// ExportPrivKeyArmorByAddress exports priv key armor by address. +func (csk ConcurrentSafeKeyring) ExportPrivKeyArmorByAddress(address sdk.Address, encryptPassphrase string) (armor string, err error) { + csk.mu.RLock() + defer csk.mu.RUnlock() + + return csk.kr.ExportPrivKeyArmorByAddress(address, encryptPassphrase) +} + +// Sign signs byte messages with a user key. +func (csk ConcurrentSafeKeyring) Sign(uid string, msg []byte) ([]byte, types.PubKey, error) { + csk.mu.RLock() + defer csk.mu.RUnlock() + + return csk.kr.Sign(uid, msg) +} + +// SignByAddress sign byte messages with a user key providing the address. +func (csk ConcurrentSafeKeyring) SignByAddress(address sdk.Address, msg []byte) ([]byte, types.PubKey, error) { + csk.mu.RLock() + defer csk.mu.RUnlock() + + return csk.kr.SignByAddress(address, msg) +} + +// Write operations: + +// Delete deletes keys from the keyring by uid. +func (csk ConcurrentSafeKeyring) Delete(uid string) error { + csk.mu.Lock() + defer csk.mu.Unlock() + + return csk.kr.Delete(uid) +} + +// DeleteByAddress deletes keys from the keyring by address. +func (csk ConcurrentSafeKeyring) DeleteByAddress(address sdk.Address) error { + csk.mu.Lock() + defer csk.mu.Unlock() + + return csk.kr.DeleteByAddress(address) +} + +// NewMnemonic generates a new mnemonic, derives a hierarchical deterministic key from it, and +// persists the key to storage. Returns the generated mnemonic and the key Info. +// It returns an error if it fails to generate a key for the given algo type, or if +// another key is already stored under the same name or address. +// +// A passphrase set to the empty string will set the passphrase to the DefaultBIP39Passphrase value. +func (csk ConcurrentSafeKeyring) NewMnemonic(uid string, language keyring.Language, hdPath, bip39Passphrase string, algo keyring.SignatureAlgo) (*keyring.Record, string, error) { + csk.mu.Lock() + defer csk.mu.Unlock() + + return csk.kr.NewMnemonic(uid, language, hdPath, bip39Passphrase, algo) +} + +// NewAccount converts a mnemonic to a private key and BIP-39 HD Path and persists it. +// It fails if there is an existing key Info with the same address. +func (csk ConcurrentSafeKeyring) NewAccount(uid, mnemonic, bip39Passphrase, hdPath string, algo keyring.SignatureAlgo) (*keyring.Record, error) { + csk.mu.Lock() + defer csk.mu.Unlock() + + return csk.kr.NewAccount(uid, mnemonic, bip39Passphrase, hdPath, algo) +} + +// SaveLedgerKey retrieves a public key reference from a Ledger device and persists it. +func (csk ConcurrentSafeKeyring) SaveLedgerKey(uid string, algo keyring.SignatureAlgo, hrp string, coinType, account, index uint32) (*keyring.Record, error) { + csk.mu.Lock() + defer csk.mu.Unlock() + + return csk.kr.SaveLedgerKey(uid, algo, hrp, coinType, account, index) +} + +// SaveMultisig stores and returns a new multsig (offline) key reference. +func (csk ConcurrentSafeKeyring) SaveMultisig(uid string, pubkey types.PubKey) (*keyring.Record, error) { + csk.mu.Lock() + defer csk.mu.Unlock() + + return csk.kr.SaveMultisig(uid, pubkey) +} + +// ImportPrivKey imports ASCII armored passphrase-encrypted private keys. +func (csk ConcurrentSafeKeyring) ImportPrivKey(uid, armor, passphrase string) error { + csk.mu.Lock() + defer csk.mu.Unlock() + + return csk.kr.ImportPrivKey(uid, armor, passphrase) +} + +// ImportPrivKeyHex imports hex encoded keys. +func (csk ConcurrentSafeKeyring) ImportPrivKeyHex(uid, privKey, algoStr string) error { + csk.mu.Lock() + defer csk.mu.Unlock() + + return csk.kr.ImportPrivKeyHex(uid, privKey, algoStr) +} + +// ImportPubKey imports ASCII armored public keys. +func (csk ConcurrentSafeKeyring) ImportPubKey(uid, armor string) error { + csk.mu.Lock() + defer csk.mu.Unlock() + + return csk.kr.ImportPubKey(uid, armor) +} + +// Backend returns the backend type used in the keyring config: "file", "os", "kwallet", "pass", "test", "memory". +func (csk ConcurrentSafeKeyring) Backend() string { + return csk.kr.Backend() +} + +// Rename renames an existing key from the Keyring. +func (csk ConcurrentSafeKeyring) Rename(from, to string) error { + csk.mu.Lock() + defer csk.mu.Unlock() + + return csk.kr.Rename(from, to) +} + +// SaveOfflineKey stores a public key and returns the persisted Info structure. +func (csk ConcurrentSafeKeyring) SaveOfflineKey(uid string, pubkey types.PubKey) (*keyring.Record, error) { + csk.mu.Lock() + defer csk.mu.Unlock() + + return csk.kr.SaveOfflineKey(uid, pubkey) +} + +// MigrateAll migrates keys from amino to proto. +func (csk ConcurrentSafeKeyring) MigrateAll() ([]*keyring.Record, error) { + csk.mu.Lock() + defer csk.mu.Unlock() + + return csk.kr.MigrateAll() +} diff --git a/integration-tests/chain.go b/testutil/integration/chain.go similarity index 75% rename from integration-tests/chain.go rename to testutil/integration/chain.go index 934e1948c..d71c86ce1 100644 --- a/integration-tests/chain.go +++ b/testutil/integration/chain.go @@ -1,11 +1,14 @@ -package integrationtests +package integration import ( "context" + "fmt" sdkmath "cosmossdk.io/math" rpchttp "github.com/cometbft/cometbft/rpc/client/http" "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/grpc/tmservice" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" sdkmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" @@ -14,13 +17,18 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/bech32" sdksigning "github.com/cosmos/cosmos-sdk/types/tx/signing" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/cosmos/gogoproto/proto" "github.com/google/uuid" "github.com/pkg/errors" "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" "github.com/CoreumFoundation/coreum/v3/app" "github.com/CoreumFoundation/coreum/v3/pkg/client" "github.com/CoreumFoundation/coreum/v3/pkg/config" + coreumkeyring "github.com/CoreumFoundation/coreum/v3/pkg/keyring" ) // ChainSettings represent common settings for the chains. @@ -258,7 +266,7 @@ func NewChain(grpcClient *grpc.ClientConn, rpcClient *rpchttp.HTTP, chainSetting clientCtxConfig.GasConfig.GasAdjustment = 1 clientCtx := client.NewContext(clientCtxConfig, app.ModuleBasics). WithChainID(chainSettings.ChainID). - WithKeyring(newConcurrentSafeKeyring(keyring.NewInMemory(encodingConfig.Codec))). + WithKeyring(coreumkeyring.NewConcurrentSafeKeyring(keyring.NewInMemory(encodingConfig.Codec))). WithBroadcastMode(flags.BroadcastSync). WithGRPCClient(grpcClient). WithClient(rpcClient). @@ -278,3 +286,73 @@ func NewChain(grpcClient *grpc.ClientConn, rpcClient *rpchttp.HTTP, chainSetting Wasm: NewWasm(chainCtx), } } + +// QueryChainSettings queries the chain setting using the provided GRPC client. +func QueryChainSettings(ctx context.Context, grpcClient *grpc.ClientConn) ChainSettings { + clientCtx := client.NewContext(client.DefaultContextConfig(), app.ModuleBasics). + WithGRPCClient(grpcClient) + + infoBeforeRes, err := tmservice.NewServiceClient(clientCtx).GetNodeInfo(ctx, &tmservice.GetNodeInfoRequest{}) + if err != nil { + panic(fmt.Sprintf("failed to get node info, err: %s", err)) + } + + chainID := infoBeforeRes.DefaultNodeInfo.Network + + paramsRes, err := stakingtypes.NewQueryClient(clientCtx).Params(ctx, &stakingtypes.QueryParamsRequest{}) + if err != nil { + panic(errors.Errorf("failed to get staking params, err: %s", err)) + } + + denom := paramsRes.Params.BondDenom + + accountsRes, err := authtypes.NewQueryClient(clientCtx).Accounts(ctx, &authtypes.QueryAccountsRequest{}) + if err != nil { + panic(fmt.Sprintf("failed to get account params, err: %s", err)) + } + + var addressPrefix string + for _, account := range accountsRes.Accounts { + if account != nil && account.TypeUrl == fmt.Sprintf("/%s", proto.MessageName(&authtypes.BaseAccount{})) { + var acc authtypes.BaseAccount + if err := proto.Unmarshal(account.Value, &acc); err != nil { + panic(fmt.Sprintf("failed to unpack account, err: %s", err)) + } + + addressPrefix, _, err = bech32.DecodeAndConvert(acc.Address) + if err != nil { + panic(fmt.Sprintf("failed to extract address prefix address:%s, err: %s", acc.Address, err)) + } + break + } + } + if addressPrefix == "" { + panic("address prefix is empty") + } + + return ChainSettings{ + ChainID: chainID, + Denom: denom, + AddressPrefix: addressPrefix, + } +} + +// DialGRPCClient creates the grpc connection for the given URL. +func DialGRPCClient(url string) *grpc.ClientConn { + encodingConfig := config.NewEncodingConfig(app.ModuleBasics) + pc, ok := encodingConfig.Codec.(codec.GRPCCodecProvider) + if !ok { + panic("failed to cast codec to codec.GRPCCodecProvider)") + } + + grpClient, err := grpc.Dial( + url, + grpc.WithDefaultCallOptions(grpc.ForceCodec(pc.GRPCCodec())), + grpc.WithTransportCredentials(insecure.NewCredentials()), + ) + if err != nil { + panic(errors.WithStack(err)) + } + + return grpClient +} diff --git a/integration-tests/chain_ibc.go b/testutil/integration/chain_ibc.go similarity index 72% rename from integration-tests/chain_ibc.go rename to testutil/integration/chain_ibc.go index de27b7453..6f77eff89 100644 --- a/integration-tests/chain_ibc.go +++ b/testutil/integration/chain_ibc.go @@ -1,17 +1,13 @@ -package integrationtests +package integration import ( "context" - "fmt" "testing" "time" sdkerrors "cosmossdk.io/errors" - sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/client/grpc/tmservice" - "github.com/cosmos/cosmos-sdk/crypto/hd" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/bech32" cosmoserrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/query" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -21,12 +17,8 @@ import ( ibcchanneltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" "github.com/cosmos/ibc-go/v7/modules/core/exported" ibctmlightclienttypes "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" - cosmosrelayer "github.com/cosmos/relayer/v2/relayer" - cosmosrelayercosmoschain "github.com/cosmos/relayer/v2/relayer/chains/cosmos" "github.com/pkg/errors" "github.com/stretchr/testify/require" - "go.uber.org/zap" - "go.uber.org/zap/zaptest" "github.com/CoreumFoundation/coreum-tools/pkg/retry" ) @@ -263,104 +255,6 @@ func (c ChainContext) AwaitForIBCClientAndConnectionIDs(ctx context.Context, t * return clientID, connectionID } -// CreateIBCChannelsAndConnect creates two new channels for the provided ports on provided chains and connects them. -func CreateIBCChannelsAndConnect( - ctx context.Context, - t *testing.T, - srcChain Chain, - srcChainPort string, - dstChain Chain, - dstChainPort string, - channelVersion string, - channelOrder ibcchanneltypes.Order, -) func() { - t.Helper() - - log := zaptest.NewLogger(t) - - const relayerKeyName = "relayer-key" - - srcClientID, srcConnectionID := srcChain.AwaitForIBCClientAndConnectionIDs(ctx, t, dstChain.ChainSettings.ChainID) - relayerSrcChain := setupRelayerChain(ctx, t, log, srcChain, relayerKeyName, srcClientID, srcConnectionID) - - dstClientID, dstConnectionID := dstChain.AwaitForIBCClientAndConnectionIDs(ctx, t, srcChain.ChainSettings.ChainID) - relayerDstChain := setupRelayerChain(ctx, t, log, dstChain, relayerKeyName, dstClientID, dstConnectionID) - - var channelOrderString string - switch channelOrder { - case ibcchanneltypes.UNORDERED: - channelOrderString = "UNORDERED" - case ibcchanneltypes.ORDERED: - channelOrderString = "ORDERED" - default: - t.Fatalf("Unsupported chennel order type:%d", channelOrder) - } - - pathName := fmt.Sprintf("%s-%s", srcChain.ChainSettings.ChainID, dstChain.ChainSettings.ChainID) - require.NoError(t, relayerSrcChain.CreateOpenChannels( - ctx, - relayerDstChain, - 3, - 5*time.Second, - srcChainPort, dstChainPort, - channelOrderString, channelVersion, - false, - "", - pathName, - )) - closerFunc := func() { - require.NoError(t, relayerSrcChain.CloseChannel(ctx, relayerDstChain, 5, 5*time.Second, srcChain.ChainSettings.ChainID, srcChainPort, "", pathName)) - } - return closerFunc -} - -func setupRelayerChain( - ctx context.Context, - t *testing.T, - log *zap.Logger, - chain Chain, - relayerKeyName string, - clientID, connectionID string, -) *cosmosrelayer.Chain { - t.Helper() - - relayerSrcChainConfig := cosmosrelayercosmoschain.CosmosProviderConfig{ - Key: relayerKeyName, - ChainName: chain.ChainSettings.ChainID, - ChainID: chain.ChainSettings.ChainID, - RPCAddr: chain.ChainSettings.RPCAddress, - AccountPrefix: chain.ChainSettings.AddressPrefix, - KeyringBackend: "test", - GasAdjustment: 1.2, - GasPrices: fmt.Sprintf("%s%s", chain.ChainSettings.GasPrice, chain.ChainSettings.Denom), - Debug: false, - Timeout: "20s", - OutputFormat: "indent", - SignModeStr: "direct", - } - - relayerSrcChainProvider, err := relayerSrcChainConfig.NewProvider(log, t.TempDir(), false, chain.ChainSettings.ChainID) - require.NoError(t, err) - require.NoError(t, relayerSrcChainProvider.Init(ctx)) - relayerSrcChainKeyInfo, err := relayerSrcChainProvider.AddKey(relayerKeyName, chain.ChainSettings.CoinType, string(hd.Secp256k1Type)) - require.NoError(t, err) - _, relayerKeyBytes, err := bech32.DecodeAndConvert(relayerSrcChainKeyInfo.Address) - require.NoError(t, err) - - chain.Faucet.FundAccounts(ctx, t, FundedAccount{ - Address: relayerKeyBytes, - Amount: chain.NewCoin(sdkmath.NewInt(2000000)), - }) - - relayerChain := cosmosrelayer.NewChain(log, relayerSrcChainProvider, false) - relayerChain.PathEnd = &cosmosrelayer.PathEnd{ - ChainID: relayerChain.ChainID(), - ClientID: clientID, - ConnectionID: connectionID, - } - return relayerChain -} - func (c ChainContext) getIBCClientAndConnectionIDs(ctx context.Context, peerChainID string) (string, string, error) { ibcClientClient := ibcclienttypes.NewQueryClient(c.ClientContext) ibcChannelClient := ibcconnectiontypes.NewQueryClient(c.ClientContext) @@ -391,11 +285,11 @@ func (c ChainContext) getIBCClientAndConnectionIDs(ctx context.Context, peerChai return "", "", err } if len(channelsRes.ConnectionPaths) != 1 { - return "", "", errors.Errorf("can't find client %s connection on the chain %s", clientID, peerChainID) + return "", "", errors.Errorf("failed to find client %s connection on the chain %s", clientID, peerChainID) } return clientID, channelsRes.ConnectionPaths[0], nil } - return "", "", errors.Errorf("can't find client and connection on the %s", peerChainID) + return "", "", errors.Errorf("failed to find client and connection on the %s", peerChainID) } diff --git a/integration-tests/chain_tx.go b/testutil/integration/chain_tx.go similarity index 99% rename from integration-tests/chain_tx.go rename to testutil/integration/chain_tx.go index b501b69a4..d4d09b684 100644 --- a/integration-tests/chain_tx.go +++ b/testutil/integration/chain_tx.go @@ -1,4 +1,4 @@ -package integrationtests +package integration import ( "context" diff --git a/integration-tests/coreum.go b/testutil/integration/coreum.go similarity index 99% rename from integration-tests/coreum.go rename to testutil/integration/coreum.go index e2b674970..54ac98e5a 100644 --- a/integration-tests/coreum.go +++ b/testutil/integration/coreum.go @@ -1,4 +1,4 @@ -package integrationtests +package integration import ( "context" @@ -116,7 +116,7 @@ func (c CoreumChain) FundAccountWithOptions(ctx context.Context, t *testing.T, a // CreateValidator creates a new validator on the chain and returns the staker addresses, validator addresses and callback function to deactivate it. func (c CoreumChain) CreateValidator(ctx context.Context, t *testing.T, stakingAmount, selfDelegationAmount sdkmath.Int) (sdk.AccAddress, sdk.ValAddress, func(), error) { t.Helper() - SkipUnsafe(t) + SkipUnsafe(ctx, t) stakingClient := stakingtypes.NewQueryClient(c.ClientContext) staker := c.GenAccount() diff --git a/integration-tests/faucet.go b/testutil/integration/faucet.go similarity index 99% rename from integration-tests/faucet.go rename to testutil/integration/faucet.go index a521b387a..e2fccf551 100644 --- a/integration-tests/faucet.go +++ b/testutil/integration/faucet.go @@ -1,4 +1,4 @@ -package integrationtests +package integration import ( "context" diff --git a/integration-tests/gov.go b/testutil/integration/gov.go similarity index 99% rename from integration-tests/gov.go rename to testutil/integration/gov.go index 3e4dd545a..1e730a9b2 100644 --- a/integration-tests/gov.go +++ b/testutil/integration/gov.go @@ -1,4 +1,4 @@ -package integrationtests +package integration import ( "context" @@ -119,7 +119,7 @@ func (g Governance) ProposalFromMsgAndVote( // Propose creates a new proposal. func (g Governance) Propose(ctx context.Context, t *testing.T, msg *govtypesv1.MsgSubmitProposal) (uint64, error) { - SkipUnsafe(t) + SkipUnsafe(ctx, t) proposer, err := sdk.AccAddressFromBech32(msg.Proposer) if err != nil { return 0, err @@ -160,7 +160,6 @@ func (g Governance) NewMsgSubmitProposal( msg, err := govtypesv1.NewMsgSubmitProposal( messages, govParams.MinDeposit, proposer.String(), metadata, title, summary, ) - if err != nil { return nil, errors.WithStack(err) } diff --git a/integration-tests/gov_legacy.go b/testutil/integration/gov_legacy.go similarity index 99% rename from integration-tests/gov_legacy.go rename to testutil/integration/gov_legacy.go index 816ac31e3..c95ab9e47 100644 --- a/integration-tests/gov_legacy.go +++ b/testutil/integration/gov_legacy.go @@ -1,4 +1,4 @@ -package integrationtests +package integration import ( "context" @@ -26,6 +26,7 @@ import ( // 1. Fully migrate new params (which are stored inside each module instead of params module). // 2. Migrate to new proposal types. Mostly initialize by NewMsgSubmitProposalV1 method. // 3. Get rid of interactions with cored v2 (inside upgrade tests) which uses v1beta1 API. +// Deprecated: Don't use it since it will be removed soon. type GovernanceLegacy struct { chainCtx ChainContext faucet Faucet @@ -103,7 +104,7 @@ func (g GovernanceLegacy) ProposeAndVote(ctx context.Context, t *testing.T, prop // Propose creates a new proposal. func (g GovernanceLegacy) Propose(ctx context.Context, t *testing.T, msg *govtypesv1beta1.MsgSubmitProposal) (uint64, error) { - SkipUnsafe(t) + SkipUnsafe(ctx, t) txf := g.chainCtx.TxFactory().WithGas(submitProposalGas) result, err := client.BroadcastTx( diff --git a/testutil/integration/unsafe.go b/testutil/integration/unsafe.go new file mode 100644 index 000000000..fcebe3a33 --- /dev/null +++ b/testutil/integration/unsafe.go @@ -0,0 +1,29 @@ +package integration + +import ( + "context" + "testing" +) + +type skipUnsafeKey struct{} + +// SkipUnsafe skips the test if run-unsafe flag is set to false. +func SkipUnsafe(ctx context.Context, t *testing.T) { + if GetSkipUnsafe(ctx) { + t.SkipNow() + } +} + +// WithSkipUnsafe sets the skip unsafe to the context. +func WithSkipUnsafe(ctx context.Context) context.Context { + return context.WithValue(ctx, skipUnsafeKey{}, true) +} + +// GetSkipUnsafe returns the skip unsafe from the context. +func GetSkipUnsafe(ctx context.Context) bool { + v, ok := ctx.Value(skipUnsafeKey{}).(bool) + if !ok { + return ok + } + return v +} diff --git a/integration-tests/wasm.go b/testutil/integration/wasm.go similarity index 99% rename from integration-tests/wasm.go rename to testutil/integration/wasm.go index cc0bf64e9..5bf2f2bdf 100644 --- a/integration-tests/wasm.go +++ b/testutil/integration/wasm.go @@ -1,4 +1,4 @@ -package integrationtests +package integration import ( "context" diff --git a/x/customparams/types/errors.go b/x/customparams/types/errors.go index 2f91b36ec..ce15627a6 100644 --- a/x/customparams/types/errors.go +++ b/x/customparams/types/errors.go @@ -4,7 +4,5 @@ import ( sdkerrors "cosmossdk.io/errors" ) -var ( - // ErrInvalidState is returned when state of the module is invalid. - ErrInvalidState = sdkerrors.Register(ModuleName, 1, "invalid state") -) +// ErrInvalidState is returned when state of the module is invalid. +var ErrInvalidState = sdkerrors.Register(ModuleName, 1, "invalid state") diff --git a/x/feemodel/types/errors.go b/x/feemodel/types/errors.go index 2f91b36ec..ce15627a6 100644 --- a/x/feemodel/types/errors.go +++ b/x/feemodel/types/errors.go @@ -4,7 +4,5 @@ import ( sdkerrors "cosmossdk.io/errors" ) -var ( - // ErrInvalidState is returned when state of the module is invalid. - ErrInvalidState = sdkerrors.Register(ModuleName, 1, "invalid state") -) +// ErrInvalidState is returned when state of the module is invalid. +var ErrInvalidState = sdkerrors.Register(ModuleName, 1, "invalid state")