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

feat: ibc e2e tests for fiattokenfactory #374

Merged
merged 8 commits into from
Oct 29, 2024
Merged
Changes from 2 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
274 changes: 274 additions & 0 deletions e2e/fiat_tf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import (
fiattokenfactorytypes "github.com/circlefin/noble-fiattokenfactory/x/fiattokenfactory/types"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
sdk "github.com/cosmos/cosmos-sdk/types"
transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
"github.com/noble-assets/noble/e2e"
"github.com/strangelove-ventures/interchaintest/v8"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
"github.com/strangelove-ventures/interchaintest/v8/testutil"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -1846,3 +1848,275 @@ func TestFiatTFBankSend(t *testing.T) {
require.NoError(t, err, "error getting balance")
require.Equal(t, amountToSend.Amount, bobBal)
}

func TestFiatTFIBCOut(t *testing.T) {
if testing.Short() {
t.Skip()
}
boojamya marked this conversation as resolved.
Show resolved Hide resolved
t.Parallel()

ctx := context.Background()

nw, gaia, _, r, ibcPathName, _, eRep, _, _ := e2e.NobleSpinUpIBC(t, ctx, true)
boojamya marked this conversation as resolved.
Show resolved Hide resolved
noble := nw.Chain
val := noble.Validators[0]

johnletey marked this conversation as resolved.
Show resolved Hide resolved
w := interchaintest.GetAndFundTestUsers(t, ctx, "default", math.OneInt(), noble, gaia)
nobleWallet := w[0]
gaiaWallet := w[1]

mintAmount := int64(100)
_, err := val.ExecTx(ctx, nw.FiatTfRoles.Minter.KeyName(), "fiat-tokenfactory", "mint", nobleWallet.FormattedAddress(), fmt.Sprintf("%duusdc", mintAmount))
require.NoError(t, err, "error minting")

// noble -> gaia channel info
nobleToGaiaChannelInfo, err := r.GetChannels(ctx, eRep, noble.Config().ChainID)
require.NoError(t, err)
nobleToGaiaChannelID := nobleToGaiaChannelInfo[0].ChannelID
// gaia -> noble channel info
gaiaToNobleChannelInfo, err := r.GetChannels(ctx, eRep, gaia.Config().ChainID)
require.NoError(t, err)
gaiaToNobleChannelID := gaiaToNobleChannelInfo[0].ChannelID

johnletey marked this conversation as resolved.
Show resolved Hide resolved
// uusdc IBC denom on gaia
srcDenomTrace := transfertypes.ParseDenomTrace(transfertypes.GetPrefixedDenom("transfer", gaiaToNobleChannelID, e2e.DenomMetadataUsdc.Base))
dstIbcDenom := srcDenomTrace.IBCDenom()

amountToSend := math.NewInt(5)
transfer := ibc.WalletAmount{
Address: gaiaWallet.FormattedAddress(),
Denom: e2e.DenomMetadataUsdc.Base,
Amount: amountToSend,
}

// ACTION: IBC send out a TF token while TF is paused
// EXPECTED: Request fails;

e2e.PauseFiatTF(t, ctx, val, nw.FiatTfRoles.Pauser)

// ibc transfer noble -> gaia
_, err = noble.SendIBCTransfer(ctx, nobleToGaiaChannelID, nobleWallet.KeyName(), transfer, ibc.TransferOptions{})
require.ErrorContains(t, err, "the chain is paused")

// relay MsgRecvPacket & MsgAcknowledgement
require.NoError(t, r.Flush(ctx, eRep, ibcPathName, nobleToGaiaChannelID))

gaiaWalletBal, err := gaia.GetBalance(ctx, gaiaWallet.FormattedAddress(), dstIbcDenom)
require.NoError(t, err)
require.True(t, gaiaWalletBal.IsZero())

e2e.UnpauseFiatTF(t, ctx, val, nw.FiatTfRoles.Pauser)

// ACTION: IBC send TF token from a blacklisted user
// EXPECTED: Request fails;

e2e.BlacklistAccount(t, ctx, val, nw.FiatTfRoles.Blacklister, nobleWallet)

_, err = noble.SendIBCTransfer(ctx, nobleToGaiaChannelID, nobleWallet.KeyName(), transfer, ibc.TransferOptions{})
require.ErrorContains(t, err, fmt.Sprintf("an address (%s) is blacklisted and can not send tokens", nobleWallet.FormattedAddress()))

require.NoError(t, r.Flush(ctx, eRep, ibcPathName, nobleToGaiaChannelID))

gaiaWalletBal, err = gaia.GetBalance(ctx, gaiaWallet.FormattedAddress(), dstIbcDenom)
require.NoError(t, err)
require.True(t, gaiaWalletBal.IsZero())

e2e.UnblacklistAccount(t, ctx, val, nw.FiatTfRoles.Blacklister, nobleWallet)

// ACTION: IBC send out a TF token to a blacklisted user
// EXPECTED: Request fails;

e2e.BlacklistAccount(t, ctx, val, nw.FiatTfRoles.Blacklister, gaiaWallet)

_, err = noble.SendIBCTransfer(ctx, nobleToGaiaChannelID, nobleWallet.KeyName(), transfer, ibc.TransferOptions{})
require.ErrorContains(t, err, fmt.Sprintf("an address (%s) is blacklisted and can not receive tokens", gaiaWallet.FormattedAddress()))

require.NoError(t, r.Flush(ctx, eRep, ibcPathName, nobleToGaiaChannelID))

gaiaWalletBal, err = gaia.GetBalance(ctx, gaiaWallet.FormattedAddress(), dstIbcDenom)
require.NoError(t, err)
require.True(t, gaiaWalletBal.IsZero())

e2e.UnblacklistAccount(t, ctx, val, nw.FiatTfRoles.Blacklister, gaiaWallet)

// ACTION: IBC send out a TF token to malformed address
// EXPECTED: Request fails;

transfer.Address = "malformed-address1234"

_, err = noble.SendIBCTransfer(ctx, nobleToGaiaChannelID, nobleWallet.KeyName(), transfer, ibc.TransferOptions{})
require.ErrorContains(t, err, "error decoding address")

// ACTION: Successfully IBC send out a TF token to an address on another chain
// EXPECTED: Success;

transfer.Address = gaiaWallet.FormattedAddress()

_, err = noble.SendIBCTransfer(ctx, nobleToGaiaChannelID, nobleWallet.KeyName(), transfer, ibc.TransferOptions{})
require.NoError(t, err)

require.NoError(t, r.Flush(ctx, eRep, ibcPathName, nobleToGaiaChannelID))

gaiaWalletBal, err = gaia.GetBalance(ctx, gaiaWallet.FormattedAddress(), dstIbcDenom)
require.NoError(t, err)
require.Equal(t, transfer.Amount, gaiaWalletBal)
}
johnletey marked this conversation as resolved.
Show resolved Hide resolved
boojamya marked this conversation as resolved.
Show resolved Hide resolved

func TestFiatTFIBCIn(t *testing.T) {
if testing.Short() {
t.Skip()
}
t.Parallel()

ctx := context.Background()

nw, gaia, _, r, ibcPathName, _, eRep, _, _ := e2e.NobleSpinUpIBC(t, ctx, true)
noble := nw.Chain
val := noble.Validators[0]

w := interchaintest.GetAndFundTestUsers(t, ctx, "default", math.NewInt(1_000_000), noble, gaia)
nobleWallet := w[0] // 1_000_000ustake
gaiaWallet := w[1] // 1_000_000uatom

mintAmount := int64(100)
_, err := val.ExecTx(ctx, nw.FiatTfRoles.Minter.KeyName(), "fiat-tokenfactory", "mint", nobleWallet.FormattedAddress(), fmt.Sprintf("%duusdc", mintAmount))
require.NoError(t, err, "error minting")

// noble -> gaia channel info
nobleToGaiaChannelInfo, err := r.GetChannels(ctx, eRep, noble.Config().ChainID)
require.NoError(t, err)
nobleToGaiaChannelID := nobleToGaiaChannelInfo[0].ChannelID
// gaia -> noble channel info
gaiaToNobleChannelInfo, err := r.GetChannels(ctx, eRep, gaia.Config().ChainID)
require.NoError(t, err)
gaiaToNobleChannelID := gaiaToNobleChannelInfo[0].ChannelID

amountToSend := math.NewInt(mintAmount)
transfer := ibc.WalletAmount{
Address: gaiaWallet.FormattedAddress(),
Denom: e2e.DenomMetadataUsdc.Base,
Amount: amountToSend,
}

// ibc transfer noble -> gaia
_, err = noble.SendIBCTransfer(ctx, nobleToGaiaChannelID, nobleWallet.KeyName(), transfer, ibc.TransferOptions{})
require.NoError(t, err)

// relay MsgRecvPacket & MsgAcknowledgement
require.NoError(t, r.Flush(ctx, eRep, ibcPathName, nobleToGaiaChannelID))

// uusdc IBC denom on gaia
srcDenomTrace := transfertypes.ParseDenomTrace(transfertypes.GetPrefixedDenom("transfer", gaiaToNobleChannelID, e2e.DenomMetadataUsdc.Base))
dstIbcDenom := srcDenomTrace.IBCDenom()

gaiaWalletBal, err := gaia.GetBalance(ctx, gaiaWallet.FormattedAddress(), dstIbcDenom)
require.NoError(t, err)
require.Equal(t, transfer.Amount, gaiaWalletBal)

// ACTION: IBC send in a TF token while TF is paused
// EXPECTED: Request fails;

e2e.PauseFiatTF(t, ctx, val, nw.FiatTfRoles.Pauser)

amountToSend = math.OneInt()
transfer = ibc.WalletAmount{
Address: nobleWallet.FormattedAddress(),
Denom: dstIbcDenom,
Amount: amountToSend,
}

height, err := noble.Height(ctx)
require.NoError(t, err)

tx, err := gaia.SendIBCTransfer(ctx, gaiaToNobleChannelID, gaiaWallet.KeyName(), transfer, ibc.TransferOptions{})
require.NoError(t, err, "error broadcasting IBC send")

require.NoError(t, r.Flush(ctx, eRep, ibcPathName, gaiaToNobleChannelID))

heightAfterFlush, err := noble.Height(ctx)
require.NoError(t, err)

ack, err := testutil.PollForAck(ctx, gaia, height, heightAfterFlush+5, tx.Packet)
require.NoError(t, err, "error polling for ack")
johnletey marked this conversation as resolved.
Show resolved Hide resolved
require.Contains(t, string(ack.Acknowledgement), "error handling packet")

nobleWalletBal, err := noble.GetBalance(ctx, nobleWallet.FormattedAddress(), e2e.DenomMetadataUsdc.Base)
require.NoError(t, err)
require.True(t, nobleWalletBal.IsZero())

e2e.UnpauseFiatTF(t, ctx, val, nw.FiatTfRoles.Pauser)

// ACTION: IBC send in a TF token FROM an address that is blacklisted
// EXPECTED: Request fails;

e2e.BlacklistAccount(t, ctx, val, nw.FiatTfRoles.Blacklister, gaiaWallet)

height, err = noble.Height(ctx)
require.NoError(t, err)

tx, err = gaia.SendIBCTransfer(ctx, gaiaToNobleChannelID, gaiaWallet.KeyName(), transfer, ibc.TransferOptions{})
require.NoError(t, err, "error broadcasting IBC send")

require.NoError(t, r.Flush(ctx, eRep, ibcPathName, gaiaToNobleChannelID))

heightAfterFlush, err = noble.Height(ctx)
require.NoError(t, err)

ack, err = testutil.PollForAck(ctx, gaia, height, heightAfterFlush+5, tx.Packet)
require.NoError(t, err, "error polling for ack")
require.Contains(t, string(ack.Acknowledgement), "error handling packet")

nobleWalletBal, err = noble.GetBalance(ctx, nobleWallet.FormattedAddress(), e2e.DenomMetadataUsdc.Base)
require.NoError(t, err)
require.True(t, nobleWalletBal.IsZero())

e2e.UnblacklistAccount(t, ctx, val, nw.FiatTfRoles.Blacklister, gaiaWallet)

// ACTION: IBC send in a TF token TO an address that is blacklisted
// EXPECTED: Request fails;

e2e.BlacklistAccount(t, ctx, val, nw.FiatTfRoles.Blacklister, nobleWallet)

height, err = noble.Height(ctx)
require.NoError(t, err)

tx, err = gaia.SendIBCTransfer(ctx, gaiaToNobleChannelID, gaiaWallet.KeyName(), transfer, ibc.TransferOptions{})
require.NoError(t, err, "error broadcasting IBC send")

require.NoError(t, r.Flush(ctx, eRep, ibcPathName, gaiaToNobleChannelID))

heightAfterFlush, err = noble.Height(ctx)
require.NoError(t, err)

ack, err = testutil.PollForAck(ctx, gaia, height, heightAfterFlush+5, tx.Packet)
require.NoError(t, err, "error polling for ack")
require.Contains(t, string(ack.Acknowledgement), "error handling packet")

nobleWalletBal, err = noble.GetBalance(ctx, nobleWallet.FormattedAddress(), e2e.DenomMetadataUsdc.Base)
require.NoError(t, err)
require.True(t, nobleWalletBal.IsZero())

e2e.UnblacklistAccount(t, ctx, val, nw.FiatTfRoles.Blacklister, nobleWallet)

// ACTION: Successfully IBC send in a TF token to an address on noble
// EXPECTED: Success;

height, err = noble.Height(ctx)
require.NoError(t, err)

tx, err = gaia.SendIBCTransfer(ctx, gaiaToNobleChannelID, gaiaWallet.KeyName(), transfer, ibc.TransferOptions{})
require.NoError(t, err, "error broadcasting IBC send")

require.NoError(t, r.Flush(ctx, eRep, ibcPathName, gaiaToNobleChannelID))

heightAfterFlush, err = noble.Height(ctx)
require.NoError(t, err)

ack, err = testutil.PollForAck(ctx, gaia, height, heightAfterFlush+5, tx.Packet)
require.NoError(t, err, "error polling for ack")
require.NotContains(t, string(ack.Acknowledgement), "error handling packet")

nobleWalletBal, err = noble.GetBalance(ctx, nobleWallet.FormattedAddress(), e2e.DenomMetadataUsdc.Base)
require.NoError(t, err)
require.Equal(t, transfer.Amount, nobleWalletBal)
}
johnletey marked this conversation as resolved.
Show resolved Hide resolved
Loading