From 05d7dc62433fe383466002f77d3c5d98ca544c89 Mon Sep 17 00:00:00 2001 From: ledanghuy1811 Date: Fri, 3 Jan 2025 09:55:38 +0700 Subject: [PATCH 1/5] feat: init setup ibc orai-osmosis --- Makefile | 4 + tests/interchaintest/orai_osmo_test.go | 101 +++++++++++++++++++++++++ tests/interchaintest/setup.go | 5 +- 3 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 tests/interchaintest/orai_osmo_test.go diff --git a/Makefile b/Makefile index 4777dbc61..3a44fdd4b 100644 --- a/Makefile +++ b/Makefile @@ -175,6 +175,10 @@ ictest-tf-set-metadata: ictest-ibchooks: cd tests/interchaintest && go test -race -v -run TestIbcHooks . +# Executes ibc orai osmosis tests via interchaintest +ictest-orai-osmo: + cd tests/interchaintest && go test -race -v -run TestOraiOsmoIbc . + # Executes wasm gas less tests via interchaintest ictest-wasm-gasless: cd tests/interchaintest && go test -race -v -run TestWasmGasLessContract . diff --git a/tests/interchaintest/orai_osmo_test.go b/tests/interchaintest/orai_osmo_test.go new file mode 100644 index 000000000..99abc0b93 --- /dev/null +++ b/tests/interchaintest/orai_osmo_test.go @@ -0,0 +1,101 @@ +package interchaintest + +import ( + "context" + "fmt" + "testing" + + "github.com/strangelove-ventures/interchaintest/v8" + "github.com/strangelove-ventures/interchaintest/v8/chain/cosmos" + "github.com/strangelove-ventures/interchaintest/v8/ibc" + "github.com/strangelove-ventures/interchaintest/v8/relayer" + "github.com/strangelove-ventures/interchaintest/v8/testreporter" + "github.com/stretchr/testify/require" + "go.uber.org/zap/zaptest" +) + +// TestStartOrai is a basic test to assert that spinning up a Orai network with 1 validator works properly. +func TestOraiOsmoIbc(t *testing.T) { + if testing.Short() { + t.Skip() + } + + t.Parallel() + + ctx := context.Background() + + numVals := 1 + numFullNodes := 1 + + cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*interchaintest.ChainSpec{ + { + Name: "orai", + ChainConfig: oraiConfig, + NumValidators: &numVals, + NumFullNodes: &numFullNodes, + }, + { + Name: "osmosis", + Version: OsmosisImageVersion, + ChainConfig: ibc.ChainConfig{ + GasPrices: "1uosmo", + }, + NumValidators: &numVals, + NumFullNodes: &numFullNodes, + }, + }) + + // Get chains from the chain factory + chains, err := cf.Chains(t.Name()) + require.NoError(t, err) + + orai, osmo := chains[0].(*cosmos.CosmosChain), chains[1].(*cosmos.CosmosChain) + + // Create relayer factory to utilize the go-relayer + client, network := interchaintest.DockerSetup(t) + r := interchaintest.NewBuiltinRelayerFactory( + ibc.CosmosRly, + zaptest.NewLogger(t), + relayer.CustomDockerImage(IBCRelayerImage, IBCRelayerVersion, "100:1000"), + ).Build(t, client, network) + + ic := interchaintest.NewInterchain(). + AddChain(orai). + AddChain(osmo). + AddRelayer(r, "rly"). + AddLink(interchaintest.InterchainLink{ + Chain1: orai, + Chain2: osmo, + Relayer: r, + Path: pathOraiOsmo, + }) + + rep := testreporter.NewNopReporter() + eRep := rep.RelayerExecReporter(t) + + err = ic.Build(ctx, eRep, interchaintest.InterchainBuildOptions{ + TestName: t.Name(), + Client: client, + NetworkID: network, + SkipPathCreation: false, + + // This can be used to write to the block database which will index all block data e.g. txs, msgs, events, etc. + // BlockDatabaseFile: interchaintest.DefaultBlockDatabaseFilepath(), + }) + require.NoError(t, err) + + t.Cleanup(func() { + _ = ic.Close() + }) + + // Start the relayer + require.NoError(t, r.StartRelayer(ctx, eRep, pathOraiOsmo)) + t.Cleanup( + func() { + err := r.StopRelayer(ctx, eRep) + if err != nil { + panic(fmt.Errorf("an error occurred while stopping the relayer: %s", err)) + } + }, + ) +} diff --git a/tests/interchaintest/setup.go b/tests/interchaintest/setup.go index 5cbde51c9..874ee82b7 100644 --- a/tests/interchaintest/setup.go +++ b/tests/interchaintest/setup.go @@ -29,7 +29,7 @@ const ( IBCRelayerImage = "ghcr.io/cosmos/relayer" IBCRelayerVersion = "latest" GaiaImageVersion = "v21.0.0" - OsmosisImageVersion = "v22.0.1" + OsmosisImageVersion = "v28.0.0" ) var ( @@ -61,7 +61,8 @@ var ( genesisWalletAmount = math.NewInt(100_000_000_000) amountToSend = math.NewInt(1_000_000_000) - pathOraiGaia = "IbcPath" + pathOraiGaia = "IbcPathOraiGaia" + pathOraiOsmo = "IbcPathOraiOsmo" ) // oraiEncoding registers the Orai specific module codecs so that the associated types and msgs From 6052eec7f3f329ec85d277b80b82f4ae8612ebd1 Mon Sep 17 00:00:00 2001 From: ledanghuy1811 Date: Fri, 3 Jan 2025 11:36:15 +0700 Subject: [PATCH 2/5] feat: refactor createChains func --- tests/interchaintest/orai_osmo_test.go | 75 +++-------------------- tests/interchaintest/setup.go | 67 ++++++++++++-------- tests/interchaintest/tokenfactory_test.go | 4 +- 3 files changed, 54 insertions(+), 92 deletions(-) diff --git a/tests/interchaintest/orai_osmo_test.go b/tests/interchaintest/orai_osmo_test.go index 99abc0b93..05214fbf5 100644 --- a/tests/interchaintest/orai_osmo_test.go +++ b/tests/interchaintest/orai_osmo_test.go @@ -5,13 +5,13 @@ import ( "fmt" "testing" - "github.com/strangelove-ventures/interchaintest/v8" - "github.com/strangelove-ventures/interchaintest/v8/chain/cosmos" - "github.com/strangelove-ventures/interchaintest/v8/ibc" - "github.com/strangelove-ventures/interchaintest/v8/relayer" - "github.com/strangelove-ventures/interchaintest/v8/testreporter" + // "github.com/strangelove-ventures/interchaintest/v8" + // "github.com/strangelove-ventures/interchaintest/v8/chain/cosmos" + // "github.com/strangelove-ventures/interchaintest/v8/ibc" + // "github.com/strangelove-ventures/interchaintest/v8/relayer" + // "github.com/strangelove-ventures/interchaintest/v8/testreporter" "github.com/stretchr/testify/require" - "go.uber.org/zap/zaptest" + // "go.uber.org/zap/zaptest" ) // TestStartOrai is a basic test to assert that spinning up a Orai network with 1 validator works properly. @@ -24,69 +24,12 @@ func TestOraiOsmoIbc(t *testing.T) { ctx := context.Background() - numVals := 1 - numFullNodes := 1 + chains := CreateChains(t, 1, 1, []string{"orai", "osmosis"}) - cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*interchaintest.ChainSpec{ - { - Name: "orai", - ChainConfig: oraiConfig, - NumValidators: &numVals, - NumFullNodes: &numFullNodes, - }, - { - Name: "osmosis", - Version: OsmosisImageVersion, - ChainConfig: ibc.ChainConfig{ - GasPrices: "1uosmo", - }, - NumValidators: &numVals, - NumFullNodes: &numFullNodes, - }, - }) - - // Get chains from the chain factory - chains, err := cf.Chains(t.Name()) - require.NoError(t, err) - - orai, osmo := chains[0].(*cosmos.CosmosChain), chains[1].(*cosmos.CosmosChain) + // orai, osmo := chains[0].(*cosmos.CosmosChain), chains[1].(*cosmos.CosmosChain) // Create relayer factory to utilize the go-relayer - client, network := interchaintest.DockerSetup(t) - r := interchaintest.NewBuiltinRelayerFactory( - ibc.CosmosRly, - zaptest.NewLogger(t), - relayer.CustomDockerImage(IBCRelayerImage, IBCRelayerVersion, "100:1000"), - ).Build(t, client, network) - - ic := interchaintest.NewInterchain(). - AddChain(orai). - AddChain(osmo). - AddRelayer(r, "rly"). - AddLink(interchaintest.InterchainLink{ - Chain1: orai, - Chain2: osmo, - Relayer: r, - Path: pathOraiOsmo, - }) - - rep := testreporter.NewNopReporter() - eRep := rep.RelayerExecReporter(t) - - err = ic.Build(ctx, eRep, interchaintest.InterchainBuildOptions{ - TestName: t.Name(), - Client: client, - NetworkID: network, - SkipPathCreation: false, - - // This can be used to write to the block database which will index all block data e.g. txs, msgs, events, etc. - // BlockDatabaseFile: interchaintest.DefaultBlockDatabaseFilepath(), - }) - require.NoError(t, err) - - t.Cleanup(func() { - _ = ic.Close() - }) + _, r, ctx, _, eRep, _ := BuildInitialChain(t, chains) // Start the relayer require.NoError(t, r.StartRelayer(ctx, eRep, pathOraiOsmo)) diff --git a/tests/interchaintest/setup.go b/tests/interchaintest/setup.go index 874ee82b7..7e601bd78 100644 --- a/tests/interchaintest/setup.go +++ b/tests/interchaintest/setup.go @@ -61,10 +61,34 @@ var ( genesisWalletAmount = math.NewInt(100_000_000_000) amountToSend = math.NewInt(1_000_000_000) + ibcPath = "IbcPath" pathOraiGaia = "IbcPathOraiGaia" pathOraiOsmo = "IbcPathOraiOsmo" ) +var ( + chainSpecs = map[string]*interchaintest.ChainSpec{ + "orai": { + Name: "orai", + ChainConfig: oraiConfig, + }, + "gaia": { + Name: "gaia", + Version: GaiaImageVersion, + ChainConfig: ibc.ChainConfig{ + GasPrices: "1uatom", + }, + }, + "osmosis": { + Name: "osmosis", + Version: OsmosisImageVersion, + ChainConfig: ibc.ChainConfig{ + GasPrices: "1uosmo", + }, + }, + } +) + // oraiEncoding registers the Orai specific module codecs so that the associated types and msgs // will be supported when writing to the blocksdb sqlite database. func oraiEncoding() *moduletestutil.TestEncodingConfig { @@ -120,24 +144,20 @@ func modifyGenesisShortProposals( } // CreateChains create testing chain. Currently we instantiate 2 chain, first is Orai, seconds is gaia -func CreateChains(t *testing.T, numVals, numFullNodes int, opts ...func(*ibc.ChainConfig)) []ibc.Chain { +func CreateChains(t *testing.T, numVals, numFullNodes int, chainIds []string, opts ...func(*ibc.ChainConfig)) []ibc.Chain { for _, opt := range opts { opt(&oraiConfig) } - cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*interchaintest.ChainSpec{ - { - Name: "orai", - ChainConfig: oraiConfig, - NumValidators: &numVals, - NumFullNodes: &numFullNodes, - }, - { - Name: "gaia", - Version: GaiaImageVersion, - NumValidators: &numVals, - NumFullNodes: &numFullNodes, - }, - }) + + var specs []*interchaintest.ChainSpec + for _, chainId := range chainIds { + chainSpecs[chainId].NumValidators = &numVals + chainSpecs[chainId].NumFullNodes = &numFullNodes + + specs = append(specs, chainSpecs[chainId]) + } + + cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), specs) // Get chains from the chain factory chains, err := cf.Chains(t.Name()) @@ -150,13 +170,12 @@ func CreateChain(t *testing.T, numVals, numFullNodes int, opts ...func(*ibc.Chai for _, opt := range opts { opt(&oraiConfig) } + + chainSpecs["orai"].NumFullNodes = &numFullNodes + chainSpecs["orai"].NumValidators = &numVals + cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*interchaintest.ChainSpec{ - { - Name: "orai", - ChainConfig: oraiConfig, - NumValidators: &numVals, - NumFullNodes: &numFullNodes, - }, + chainSpecs["orai"], }) // Get chains from the chain factory @@ -186,7 +205,7 @@ func BuildInitialChainNoIbc(t *testing.T, chain ibc.Chain) (*interchaintest.Inte return ic, ctx } -func BuildInitialChain(t *testing.T, chains []ibc.Chain) (*interchaintest.Interchain, ibc.Relayer, context.Context, *client.Client, string) { +func BuildInitialChain(t *testing.T, chains []ibc.Chain) (*interchaintest.Interchain, ibc.Relayer, context.Context, *client.Client, *testreporter.RelayerExecReporter, string) { // Create a new Interchain object which describes the chains, relayers, and IBC connections we want to use require.Equal(t, len(chains), 2) // we only initial 2 chain for now ic := interchaintest.NewInterchain() @@ -212,7 +231,7 @@ func BuildInitialChain(t *testing.T, chains []ibc.Chain) (*interchaintest.Interc Chain1: chains[0], Chain2: chains[1], Relayer: r, - Path: pathOraiGaia, + Path: ibcPath + chains[0].Config().ChainID + chains[1].Config().ChainID, }) err := ic.Build(ctx, eRep, interchaintest.InterchainBuildOptions{ @@ -225,5 +244,5 @@ func BuildInitialChain(t *testing.T, chains []ibc.Chain) (*interchaintest.Interc }) require.NoError(t, err) - return ic, r, ctx, client, network + return ic, r, ctx, client, eRep, network } diff --git a/tests/interchaintest/tokenfactory_test.go b/tests/interchaintest/tokenfactory_test.go index caf9c3d5d..bdd84f7c4 100644 --- a/tests/interchaintest/tokenfactory_test.go +++ b/tests/interchaintest/tokenfactory_test.go @@ -22,9 +22,9 @@ func TestTokenfactoryParamChange(t *testing.T) { } t.Parallel() - chains := CreateChains(t, 1, 1) + chains := CreateChains(t, 1, 1, []string{"orai", "gaia"}) orai := chains[0].(*cosmos.CosmosChain) - ic, _, ctx, _, _ := BuildInitialChain(t, chains) + ic, _, ctx, _, _, _ := BuildInitialChain(t, chains) t.Cleanup(func() { _ = ic.Close() }) From 32296527d40b1f48a623c150714fee5ce4196d18 Mon Sep 17 00:00:00 2001 From: ledanghuy1811 Date: Fri, 3 Jan 2025 11:38:18 +0700 Subject: [PATCH 3/5] fix: not created chain if not supported --- tests/interchaintest/setup.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/interchaintest/setup.go b/tests/interchaintest/setup.go index 7e601bd78..d377170fc 100644 --- a/tests/interchaintest/setup.go +++ b/tests/interchaintest/setup.go @@ -151,6 +151,11 @@ func CreateChains(t *testing.T, numVals, numFullNodes int, chainIds []string, op var specs []*interchaintest.ChainSpec for _, chainId := range chainIds { + if chainSpecs[chainId] == nil { + fmt.Println("not supported this chain: ", chainId) + continue + } + chainSpecs[chainId].NumValidators = &numVals chainSpecs[chainId].NumFullNodes = &numFullNodes From 9ef0a371b9badc6b4eb4975dc7c497dafa4781e6 Mon Sep 17 00:00:00 2001 From: ledanghuy1811 Date: Fri, 3 Jan 2025 16:17:18 +0700 Subject: [PATCH 4/5] feat: add test to force trasnfer token factory after transfer ibc --- tests/interchaintest/helpers/tokenfactory.go | 48 +++++++++ tests/interchaintest/orai_osmo_test.go | 102 +++++++++++++++++-- tests/interchaintest/setup.go | 5 +- tests/interchaintest/tokenfactory_test.go | 2 +- tests/interchaintest/utils.go | 2 +- 5 files changed, 145 insertions(+), 14 deletions(-) diff --git a/tests/interchaintest/helpers/tokenfactory.go b/tests/interchaintest/helpers/tokenfactory.go index 9bd678c37..4867ca159 100644 --- a/tests/interchaintest/helpers/tokenfactory.go +++ b/tests/interchaintest/helpers/tokenfactory.go @@ -33,6 +33,38 @@ func TxTokenFactoryCreateDenom( return denom, txHash } +func TxTokenFactoryMintToken( + t *testing.T, + ctx context.Context, + chain *cosmos.CosmosChain, + user ibc.Wallet, + denom string, + amount uint64, +) string { + tn := chain.GetNode() + txHash, err := tn.TokenFactoryMintDenom(ctx, user.KeyName(), denom, amount) + require.NoError(t, err) + + return txHash +} + +func TxTokenFactoryForceTransfer( + t *testing.T, + ctx context.Context, + chain *cosmos.CosmosChain, + user ibc.Wallet, + denom string, + amount uint64, + fromAddr string, + toAddr string, +) string { + tn := chain.GetNode() + txHash, err := tn.TokenFactoryForceTransferDenom(ctx, user.KeyName(), denom, amount, fromAddr, toAddr) + require.NoError(t, err) + + return txHash +} + func TxTokenFactoryModifyMetadata( t *testing.T, ctx context.Context, @@ -161,3 +193,19 @@ func QueryDenomAuthorityMetadata(t *testing.T, return res.AuthorityMetadata.Admin, nil } + +func QueryBalance( + t *testing.T, + ctx context.Context, + chain *cosmos.CosmosChain, + denom string, + userAddress string, +) (uint64, error) { + tn := chain.GetNode() + balance, err := tn.Chain.GetBalance(ctx, userAddress, denom) + if err != nil { + return 0, err + } + + return balance.Uint64(), nil +} diff --git a/tests/interchaintest/orai_osmo_test.go b/tests/interchaintest/orai_osmo_test.go index 05214fbf5..d7891313c 100644 --- a/tests/interchaintest/orai_osmo_test.go +++ b/tests/interchaintest/orai_osmo_test.go @@ -5,13 +5,15 @@ import ( "fmt" "testing" - // "github.com/strangelove-ventures/interchaintest/v8" - // "github.com/strangelove-ventures/interchaintest/v8/chain/cosmos" - // "github.com/strangelove-ventures/interchaintest/v8/ibc" - // "github.com/strangelove-ventures/interchaintest/v8/relayer" - // "github.com/strangelove-ventures/interchaintest/v8/testreporter" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" + transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" + "github.com/oraichain/wasmd/tests/interchaintest/helpers" + "github.com/strangelove-ventures/interchaintest/v8/chain/cosmos" + "github.com/strangelove-ventures/interchaintest/v8/ibc" + "github.com/strangelove-ventures/interchaintest/v8/testutil" + "github.com/stretchr/testify/require" - // "go.uber.org/zap/zaptest" ) // TestStartOrai is a basic test to assert that spinning up a Orai network with 1 validator works properly. @@ -25,11 +27,13 @@ func TestOraiOsmoIbc(t *testing.T) { ctx := context.Background() chains := CreateChains(t, 1, 1, []string{"orai", "osmosis"}) - - // orai, osmo := chains[0].(*cosmos.CosmosChain), chains[1].(*cosmos.CosmosChain) + orai, osmo := chains[0].(*cosmos.CosmosChain), chains[1].(*cosmos.CosmosChain) // Create relayer factory to utilize the go-relayer - _, r, ctx, _, eRep, _ := BuildInitialChain(t, chains) + ic, r, ctx, _, eRep, _ := BuildInitialChain(t, chains, pathOraiOsmo) + t.Cleanup(func() { + _ = ic.Close() + }) // Start the relayer require.NoError(t, r.StartRelayer(ctx, eRep, pathOraiOsmo)) @@ -41,4 +45,84 @@ func TestOraiOsmoIbc(t *testing.T) { } }, ) + + channel, err := ibc.GetTransferChannel(ctx, r, eRep, orai.Config().ChainID, osmo.Config().ChainID) + require.NoError(t, err) + + users := CreateTestingUser(t, ctx, t.Name(), genesisWalletAmount, chains...) + // Get our Bech32 encoded user addresses + oraiUser, osmoUser := users[0], users[1] + + oraiUserAddress := sdk.MustBech32ifyAddressBytes(orai.Config().Bech32Prefix, oraiUser.Address()) + osmoUserAddr := sdk.MustBech32ifyAddressBytes(osmo.Config().Bech32Prefix, osmoUser.Address()) + + _ = oraiUserAddress + _ = osmoUserAddr + gas := uint64(100_000_000) + + // create new token factory denom + expectedDenom, _ := helpers.TxTokenFactoryCreateDenom(t, ctx, orai, oraiUser, "orai-usd", gas) + denomCreated, err := helpers.QueryDenomsFromCreator(t, ctx, orai, oraiUserAddress) + require.NoError(t, err) + require.Contains(t, denomCreated, expectedDenom) + + // mint token + tokenToMint := uint64(100_000_000_000) + _ = helpers.TxTokenFactoryMintToken(t, ctx, orai, oraiUser, expectedDenom, tokenToMint) + oraiUserBalance, err := helpers.QueryBalance(t, ctx, orai, expectedDenom, oraiUserAddress) + require.NoError(t, err) + require.Equal(t, tokenToMint, oraiUserBalance) + + // get escrowed address + addr := types.GetEscrowAddress(channel.PortID, channel.ChannelID) + escrowedAddress := sdk.MustBech32ifyAddressBytes(orai.Config().Bech32Prefix, addr.Bytes()) + + // balance before transfer ibc must be 0 + escrowedBalance, err := helpers.QueryBalance(t, ctx, orai, expectedDenom, escrowedAddress) + require.NoError(t, err) + require.Equal(t, escrowedBalance, uint64(0)) + + // ibc denom when transfer orai to osmosis + // transfer/channel-0/factory/orai14zqwen0pqj7s6drrkwaqwded7ajrq5czyw7fhq/orai-usd + oraiDenom := transfertypes.GetPrefixedDenom(channel.Counterparty.PortID, channel.Counterparty.ChannelID, expectedDenom) + // ibc/F859A4CC5A5EA6533657F6A83F7C11A479A13DBDC53F68135CDA95B0F12E5892 + oraiIBCDenom := transfertypes.ParseDenomTrace(oraiDenom).IBCDenom() + + // osmosis user balance before transfer ibc must be 0 + userOsmosisBalance, err := helpers.QueryBalance(t, ctx, osmo, oraiIBCDenom, osmoUserAddr) + require.NoError(t, err) + require.Equal(t, userOsmosisBalance, uint64(0)) + + // try to transfer token factory to osmosis + transfer := ibc.WalletAmount{ + Address: osmoUserAddr, + Denom: expectedDenom, + Amount: amountToSend, + } + transferTx, err := orai.SendIBCTransfer(ctx, channel.Counterparty.ChannelID, oraiUserAddress, transfer, ibc.TransferOptions{}) + require.NoError(t, err) + + // waiting for ACK -> transfer successfully + oraiHeight, err := orai.Height(ctx) + require.NoError(t, err) + _, err = testutil.PollForAck(ctx, orai, oraiHeight-5, oraiHeight+25, transferTx.Packet) + require.NoError(t, err) + + // balance after transfer ibc must be equalt amount to send + escrowedBalance, err = helpers.QueryBalance(t, ctx, orai, expectedDenom, escrowedAddress) + fmt.Println("escrowed balance: ", escrowedBalance) + require.NoError(t, err) + require.Equal(t, escrowedBalance, uint64(amountToSend.Int64())) + + // osmosis user balance after transfer ibc must be equal amount to send + userOsmosisBalance, err = helpers.QueryBalance(t, ctx, osmo, oraiIBCDenom, osmoUserAddr) + require.NoError(t, err) + require.Equal(t, userOsmosisBalance, uint64(amountToSend.Int64())) + + // try to force transfer tokenfactory from escrowed address + _ = helpers.TxTokenFactoryForceTransfer(t, ctx, orai, oraiUser, expectedDenom, uint64(amountToSend.Int64()), escrowedAddress, oraiUserAddress) + escrowedBalance, err = helpers.QueryBalance(t, ctx, orai, expectedDenom, escrowedAddress) + fmt.Println("escrowed balance: ", escrowedBalance) + require.NoError(t, err) + require.Equal(t, escrowedBalance, uint64(amountToSend.Int64())) } diff --git a/tests/interchaintest/setup.go b/tests/interchaintest/setup.go index d377170fc..5133e7a3c 100644 --- a/tests/interchaintest/setup.go +++ b/tests/interchaintest/setup.go @@ -61,7 +61,6 @@ var ( genesisWalletAmount = math.NewInt(100_000_000_000) amountToSend = math.NewInt(1_000_000_000) - ibcPath = "IbcPath" pathOraiGaia = "IbcPathOraiGaia" pathOraiOsmo = "IbcPathOraiOsmo" ) @@ -210,7 +209,7 @@ func BuildInitialChainNoIbc(t *testing.T, chain ibc.Chain) (*interchaintest.Inte return ic, ctx } -func BuildInitialChain(t *testing.T, chains []ibc.Chain) (*interchaintest.Interchain, ibc.Relayer, context.Context, *client.Client, *testreporter.RelayerExecReporter, string) { +func BuildInitialChain(t *testing.T, chains []ibc.Chain, ibcPath string) (*interchaintest.Interchain, ibc.Relayer, context.Context, *client.Client, *testreporter.RelayerExecReporter, string) { // Create a new Interchain object which describes the chains, relayers, and IBC connections we want to use require.Equal(t, len(chains), 2) // we only initial 2 chain for now ic := interchaintest.NewInterchain() @@ -236,7 +235,7 @@ func BuildInitialChain(t *testing.T, chains []ibc.Chain) (*interchaintest.Interc Chain1: chains[0], Chain2: chains[1], Relayer: r, - Path: ibcPath + chains[0].Config().ChainID + chains[1].Config().ChainID, + Path: ibcPath, }) err := ic.Build(ctx, eRep, interchaintest.InterchainBuildOptions{ diff --git a/tests/interchaintest/tokenfactory_test.go b/tests/interchaintest/tokenfactory_test.go index bdd84f7c4..d11c5b1b6 100644 --- a/tests/interchaintest/tokenfactory_test.go +++ b/tests/interchaintest/tokenfactory_test.go @@ -24,7 +24,7 @@ func TestTokenfactoryParamChange(t *testing.T) { t.Parallel() chains := CreateChains(t, 1, 1, []string{"orai", "gaia"}) orai := chains[0].(*cosmos.CosmosChain) - ic, _, ctx, _, _, _ := BuildInitialChain(t, chains) + ic, _, ctx, _, _, _ := BuildInitialChain(t, chains, pathOraiGaia) t.Cleanup(func() { _ = ic.Close() }) diff --git a/tests/interchaintest/utils.go b/tests/interchaintest/utils.go index 7323632ce..654a7b0e7 100644 --- a/tests/interchaintest/utils.go +++ b/tests/interchaintest/utils.go @@ -22,7 +22,7 @@ func CreateTestingUser( chains ...ibc.Chain, ) []ibc.Wallet { // Create some user accounts on both chains - users := interchaintest.GetAndFundTestUsers(t, ctx, t.Name(), genesisWalletAmount, chains...) + users := interchaintest.GetAndFundTestUsers(t, ctx, t.Name(), amount, chains...) // Wait a few blocks for user accounts to be created err := testutil.WaitForBlocks(ctx, 5, chains[0]) require.NoError(t, err) From 8f36bc480430f96454e44cde7f20b1d6c8d1119e Mon Sep 17 00:00:00 2001 From: ledanghuy1811 Date: Mon, 6 Jan 2025 17:21:24 +0700 Subject: [PATCH 5/5] feat: remove force transfer capability and add test --- app/app.go | 2 +- .../test-tokenfactory-force-transfer.sh | 67 +++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100755 scripts/tests-0.50.4/test-tokenfactory-force-transfer.sh diff --git a/app/app.go b/app/app.go index 19c89fb2b..4e55737b6 100644 --- a/app/app.go +++ b/app/app.go @@ -195,7 +195,7 @@ var ( EnabledCapabilities = []string{ tokenfactorytypes.EnableBurnFrom, - tokenfactorytypes.EnableForceTransfer, + // tokenfactorytypes.EnableForceTransfer, tokenfactorytypes.EnableSetMetadata, } ) diff --git a/scripts/tests-0.50.4/test-tokenfactory-force-transfer.sh b/scripts/tests-0.50.4/test-tokenfactory-force-transfer.sh new file mode 100755 index 000000000..e19e4ac18 --- /dev/null +++ b/scripts/tests-0.50.4/test-tokenfactory-force-transfer.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +set -ux + +CHAIN_ID=${CHAIN_ID:-testing} +USER=${USER:-"validator1"} +NODE_HOME=${NODE_HOME:-"$PWD/.oraid"} +ARGS="--from $USER --chain-id $CHAIN_ID -y --keyring-backend test --gas auto --gas-adjustment 1.5 -b sync --home $NODE_HOME" +HIDE_LOGS="/dev/null" + +# prepare a new contract for gasless +fee_params=$(oraid query tokenfactory params --output json | jq '.params.denom_creation_fee[0].denom') +if ! [[ $fee_params =~ "orai" ]]; then + echo "Tokenfactory force transfer tests failed. The tokenfactory fee params is not orai" + exit 1 +fi + +# try creating a new denom +denom_name="usd" +oraid tx tokenfactory create-denom $denom_name $ARGS >$HIDE_LOGS + +# try querying list denoms afterwards +# need to sleep 1s +sleep 1 +user_address=$(oraid keys show $USER --home $NODE_HOME --keyring-backend test -a) +first_denom=$(oraid query tokenfactory denoms-from-creator $user_address --output json | jq '.denoms[0]' | tr -d '"') +echo "first denom: $first_denom" + +if ! [[ $first_denom =~ "factory/$user_address/$denom_name" ]]; then + echo "Tokenfactory force transfer tests failed. The tokenfactory denom does not match the created denom" + exit 1 +fi + +admin=$(oraid query tokenfactory denom-authority-metadata $first_denom --output json | jq '.authority_metadata.admin') +echo "admin: $admin" + +if ! [[ $admin =~ $user_address ]]; then + echo "Tokenfactory force transfer tests failed. The tokenfactory admin does not match the creator" + exit 1 +fi + +sleep 2 +# try to mint token +oraid tx tokenfactory mint 10000$first_denom $ARGS >$HIDE_LOGS + +# query balance after mint +# need sleep 1s +sleep 2 +tokenfactory_balance=$(oraid query bank balance $user_address $first_denom --output json | jq '.balance.amount | tonumber') +if [[ $tokenfactory_balance -ne 10000 ]]; then + echo "Tokenfactory force transfer failed. The tokenfactory balance does not increase after mint" + exit 1 +fi + +# try to force transfer token to another address +oraid tx tokenfactory force-transfer 10$first_denom $user_address orai1cknd27x0244595pp7a5c9sdekl3ywl52x62ssn $ARGS &>$HIDE_LOGS + +# query balance after force trasnfer +# need sleep 2s +sleep 2 +tokenfactory_balance=$(oraid query bank balance $user_address $first_denom --output json | jq '.balance.amount | tonumber') +if ! [[ $tokenfactory_balance =~ 10000 ]]; then + echo "Tokenfactory force transfer failed. The tokenfactory balance decreases after force transfer" + exit 1 +fi + +echo "Tokenfactory force transfer tests passed!"