Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move duplicated getIssueFee & getMintFee helpers to CoreumChain in integr-tests #581

Merged
merged 5 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions integration-tests/coreum.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/stretchr/testify/require"

"github.com/CoreumFoundation/coreum/v2/pkg/client"
assetfttypes "github.com/CoreumFoundation/coreum/v2/x/asset/ft/types"
assetnfttypes "github.com/CoreumFoundation/coreum/v2/x/asset/nft/types"
"github.com/CoreumFoundation/coreum/v2/x/deterministicgas"
)

Expand Down Expand Up @@ -178,3 +180,25 @@ func (c CoreumChain) CreateValidator(ctx context.Context, t *testing.T, stakingA
}
}, nil
}

// QueryAssetFTParams queries for asset/ft module params and returns them.
func (c CoreumChain) QueryAssetFTParams(ctx context.Context, t *testing.T) assetfttypes.Params {
t.Helper()

queryClient := assetfttypes.NewQueryClient(c.ClientContext)
resp, err := queryClient.Params(ctx, &assetfttypes.QueryParamsRequest{})
require.NoError(t, err)

return resp.Params
}

// QueryAssetNFTParams queries for asset/nft module params and returns them.
func (c CoreumChain) QueryAssetNFTParams(ctx context.Context, t *testing.T) assetnfttypes.Params {
t.Helper()

queryClient := assetnfttypes.NewQueryClient(c.ClientContext)
resp, err := queryClient.Params(ctx, &assetnfttypes.QueryParamsRequest{})
require.NoError(t, err)

return resp.Params
}
28 changes: 10 additions & 18 deletions integration-tests/ibc/asset_ft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestIBCFailsIfNotEnabled(t *testing.T) {
coreumChain := chains.Coreum
coreumIssuer := coreumChain.GenAccount()

issueFee := getIssueFee(ctx, t, coreumChain.ClientContext).Amount
issueFee := coreumChain.QueryAssetFTParams(ctx, t).IssueFee.Amount
coreumChain.FundAccountWithOptions(ctx, t, coreumIssuer, integrationtests.BalancesOptions{
Messages: []sdk.Msg{
&assetfttypes.MsgIssue{},
Expand Down Expand Up @@ -111,7 +111,7 @@ func TestIBCAssetFTSendCommissionAndBurnRate(t *testing.T) {
})

coreumIssuer := coreumChain.GenAccount()
issueFee := getIssueFee(ctx, t, coreumChain.ClientContext).Amount
issueFee := coreumChain.QueryAssetFTParams(ctx, t).IssueFee.Amount
coreumChain.FundAccountWithOptions(ctx, t, coreumIssuer, integrationtests.BalancesOptions{
Messages: []sdk.Msg{
&banktypes.MsgSend{},
Expand Down Expand Up @@ -355,7 +355,7 @@ func TestIBCAssetFTWhitelisting(t *testing.T) {
Amount: gaiaChain.NewCoin(sdk.NewInt(1000000)), // coin for the fees
})

issueFee := getIssueFee(ctx, t, coreumChain.ClientContext).Amount
issueFee := coreumChain.QueryAssetFTParams(ctx, t).IssueFee.Amount
coreumChain.FundAccountWithOptions(ctx, t, coreumIssuer, integrationtests.BalancesOptions{
Messages: []sdk.Msg{
&assetfttypes.MsgIssue{},
Expand Down Expand Up @@ -450,7 +450,7 @@ func TestIBCAssetFTFreezing(t *testing.T) {
Amount: gaiaChain.NewCoin(sdk.NewInt(1000000)), // coin for the fees
})

issueFee := getIssueFee(ctx, t, coreumChain.ClientContext).Amount
issueFee := coreumChain.QueryAssetFTParams(ctx, t).IssueFee.Amount
coreumChain.FundAccountWithOptions(ctx, t, coreumIssuer, integrationtests.BalancesOptions{
Messages: []sdk.Msg{
&assetfttypes.MsgIssue{},
Expand Down Expand Up @@ -550,7 +550,7 @@ func TestEscrowAddressIsResistantToFreezingAndWhitelisting(t *testing.T) {
Amount: gaiaChain.NewCoin(sdk.NewInt(1000000)), // coin for the fees
})

issueFee := getIssueFee(ctx, t, coreumChain.ClientContext).Amount
issueFee := coreumChain.QueryAssetFTParams(ctx, t).IssueFee.Amount
coreumChain.FundAccountWithOptions(ctx, t, coreumIssuer, integrationtests.BalancesOptions{
Messages: []sdk.Msg{
&assetfttypes.MsgIssue{},
Expand Down Expand Up @@ -634,7 +634,7 @@ func TestIBCGlobalFreeze(t *testing.T) {
Amount: gaiaChain.NewCoin(sdk.NewInt(1000000)), // coin for the fees
})

issueFee := getIssueFee(ctx, t, coreumChain.ClientContext).Amount
issueFee := coreumChain.QueryAssetFTParams(ctx, t).IssueFee.Amount
coreumChain.FundAccountWithOptions(ctx, t, coreumIssuer, integrationtests.BalancesOptions{
Messages: []sdk.Msg{
&assetfttypes.MsgIssue{},
Expand Down Expand Up @@ -778,7 +778,7 @@ func TestIBCAssetFTTimedOutTransfer(t *testing.T) {
// On every trial we send funds from one chain to the other. Then we observe accounts on both chains
// to find if IBC transfer completed successfully or timed out. If tokens were delivered to the recipient
// we must retry. Otherwise, if tokens were returned back to the sender, we might continue the test.
issueFee := getIssueFee(ctx, t, coreumChain.ClientContext).Amount
issueFee := coreumChain.QueryAssetFTParams(ctx, t).IssueFee.Amount
err := retry.Do(retryCtx, time.Millisecond, func() error {
coreumSender := coreumChain.GenAccount()
gaiaRecipient := gaiaChain.GenAccount()
Expand Down Expand Up @@ -897,7 +897,7 @@ func TestIBCAssetFTRejectedTransfer(t *testing.T) {
&ibctransfertypes.MsgTransfer{},
&ibctransfertypes.MsgTransfer{},
},
Amount: getIssueFee(ctx, t, coreumChain.ClientContext).Amount,
Amount: coreumChain.QueryAssetFTParams(ctx, t).IssueFee.Amount,
})
gaiaChain.Faucet.FundAccounts(ctx, t, integrationtests.FundedAccount{
Address: gaiaRecipient,
Expand Down Expand Up @@ -983,7 +983,7 @@ func TestIBCRejectedTransferWithWhitelistingAndFreezing(t *testing.T) {
// this type of IBC transfer is rejected by the receiving chain.
moduleAddress := authtypes.NewModuleAddress(ibctransfertypes.ModuleName)

issueFee := getIssueFee(ctx, t, coreumChain.ClientContext).Amount
issueFee := coreumChain.QueryAssetFTParams(ctx, t).IssueFee.Amount
coreumChain.FundAccountWithOptions(ctx, t, coreumIssuer, integrationtests.BalancesOptions{
Messages: []sdk.Msg{
&assetfttypes.MsgIssue{},
Expand Down Expand Up @@ -1109,7 +1109,7 @@ func TestIBCTimedOutTransferWithWhitelistingAndFreezing(t *testing.T) {
// On every trial we send funds from one chain to the other. Then we observe accounts on both chains
// to find if IBC transfer completed successfully or timed out. If tokens were delivered to the recipient
// we must retry. Otherwise, if tokens were returned back to the sender, we might continue the test.
issueFee := getIssueFee(ctx, t, coreumChain.ClientContext).Amount
issueFee := coreumChain.QueryAssetFTParams(ctx, t).IssueFee.Amount
err := retry.Do(retryCtx, time.Millisecond, func() error {
coreumIssuer := coreumChain.GenAccount()
coreumSender := coreumChain.GenAccount()
Expand Down Expand Up @@ -1336,11 +1336,3 @@ func assertBalanceChanges(t *testing.T, expectedBalanceChanges, balancesBefore,
requireT.Equal(expectedBalanceChange.String(), actualBalanceChange.String())
}
}

func getIssueFee(ctx context.Context, t *testing.T, clientCtx client.Context) sdk.Coin {
queryClient := assetfttypes.NewQueryClient(clientCtx)
resp, err := queryClient.Params(ctx, &assetfttypes.QueryParamsRequest{})
require.NoError(t, err)

return resp.Params.IssueFee
}
Loading