From f931227de04c362e2ae52c54400a69d299bf6d8d Mon Sep 17 00:00:00 2001 From: Duong Minh Ngoc Date: Wed, 17 Jan 2024 12:02:56 +0700 Subject: [PATCH] test: add host zone proposal interchain test --- tests/interchaintest/feeabs/proposal.go | 61 ++ tests/interchaintest/feeabs/query.go | 34 ++ .../interchaintest/host_zone_proposal_test.go | 538 ++++++++++++++++++ tests/interchaintest/packet_foward_test.go | 2 +- .../{host_zone.json => add_host_zone.json} | 0 .../proposal/delete_host_zone.json | 6 + .../proposal/set_host_zone.json | 12 + 7 files changed, 652 insertions(+), 1 deletion(-) create mode 100644 tests/interchaintest/feeabs/proposal.go create mode 100644 tests/interchaintest/feeabs/query.go create mode 100644 tests/interchaintest/host_zone_proposal_test.go rename tests/interchaintest/proposal/{host_zone.json => add_host_zone.json} (100%) create mode 100644 tests/interchaintest/proposal/delete_host_zone.json create mode 100644 tests/interchaintest/proposal/set_host_zone.json diff --git a/tests/interchaintest/feeabs/proposal.go b/tests/interchaintest/feeabs/proposal.go new file mode 100644 index 00000000..e4de1379 --- /dev/null +++ b/tests/interchaintest/feeabs/proposal.go @@ -0,0 +1,61 @@ +package feeabs + +import ( + "context" + "fmt" + "github.com/strangelove-ventures/interchaintest/v7/chain/cosmos" + "os" + "path/filepath" +) + +func DeleteHostZoneProposal(c *cosmos.CosmosChain, ctx context.Context, keyName string, fileLocation string) (string, error) { + tn := c.Validators[0] + if len(c.FullNodes) > 0 { + tn = c.FullNodes[0] + } + dat, err := os.ReadFile(fileLocation) + if err != nil { + return "", fmt.Errorf("failed to read file: %w", err) + } + + fileName := "delete-hostzone.json" + + err = tn.WriteFile(ctx, dat, fileName) + if err != nil { + return "", fmt.Errorf("writing delete host zone proposal: %w", err) + } + + filePath := filepath.Join(tn.HomeDir(), fileName) + + command := []string{ + "gov", "submit-legacy-proposal", + "delete-hostzone-config", filePath, + } + return tn.ExecTx(ctx, keyName, command...) +} + +func SetHostZoneProposal(c *cosmos.CosmosChain, ctx context.Context, keyName string, fileLocation string) (string, error) { + tn := c.Validators[0] + if len(c.FullNodes) > 0 { + tn = c.FullNodes[0] + } + dat, err := os.ReadFile(fileLocation) + if err != nil { + return "", fmt.Errorf("failed to read file: %w", err) + } + + fileName := "set-hostzone.json" + + err = tn.WriteFile(ctx, dat, fileName) + if err != nil { + return "", fmt.Errorf("writing set host zone proposal: %w", err) + } + + filePath := filepath.Join(tn.HomeDir(), fileName) + + command := []string{ + "gov", "submit-legacy-proposal", + "set-hostzone-config", filePath, + } + return tn.ExecTx(ctx, keyName, command...) +} diff --git a/tests/interchaintest/feeabs/query.go b/tests/interchaintest/feeabs/query.go new file mode 100644 index 00000000..6f9e89ea --- /dev/null +++ b/tests/interchaintest/feeabs/query.go @@ -0,0 +1,34 @@ +package feeabs + +import ( + "context" + "encoding/json" + "github.com/strangelove-ventures/interchaintest/v7/chain/cosmos" +) + +type HostChainFeeAbsConfigResponse struct { + HostChainConfig HostChainFeeAbsConfig `json:"host_chain_config"` +} + +type HostChainFeeAbsConfig struct { + IbcDenom string `json:"ibc_denom"` + OsmosisPoolTokenDenomIn string `json:"osmosis_pool_token_denom_in"` + PoolId string `json:"pool_id"` + Frozen bool `json:"frozen"` +} + +func QueryFeeabsHostZoneConfigWithDenom(c *cosmos.CosmosChain, ctx context.Context, denom string) (*HostChainFeeAbsConfigResponse, error) { + cmd := []string{"feeabs", "host-chain-config", denom} + stdout, _, err := c.ExecQuery(ctx, cmd) + if err != nil { + return &HostChainFeeAbsConfigResponse{}, err + } + + var hostZoneConfig HostChainFeeAbsConfigResponse + err = json.Unmarshal(stdout, &hostZoneConfig) + if err != nil { + return &HostChainFeeAbsConfigResponse{}, err + } + + return &hostZoneConfig, nil +} diff --git a/tests/interchaintest/host_zone_proposal_test.go b/tests/interchaintest/host_zone_proposal_test.go new file mode 100644 index 00000000..e01ec0c7 --- /dev/null +++ b/tests/interchaintest/host_zone_proposal_test.go @@ -0,0 +1,538 @@ +package interchaintest + +import ( + "context" + "cosmossdk.io/math" + "fmt" + sdktypes "github.com/cosmos/cosmos-sdk/types" + feeabsCli "github.com/notional-labs/fee-abstraction/tests/interchaintest/feeabs" + "testing" + + transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" + "github.com/strangelove-ventures/interchaintest/v7" + "github.com/strangelove-ventures/interchaintest/v7/chain/cosmos" + "github.com/strangelove-ventures/interchaintest/v7/ibc" + "github.com/strangelove-ventures/interchaintest/v7/testreporter" + "github.com/strangelove-ventures/interchaintest/v7/testutil" + "github.com/stretchr/testify/require" + "go.uber.org/zap/zaptest" +) + +func TestHostZoneProposal(t *testing.T) { + if testing.Short() { + t.Skip("skipping in short mode") + } + + client, network := interchaintest.DockerSetup(t) + + rep := testreporter.NewNopReporter() + eRep := rep.RelayerExecReporter(t) + + ctx := context.Background() + + // Create chain factory with Feeabs and Gaia + numVals := 1 + numFullNodes := 1 + gasAdjustment := 2.0 + + cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*interchaintest.ChainSpec{ + { + Name: "feeabs", + ChainConfig: feeabsConfig, + NumValidators: &numVals, + NumFullNodes: &numFullNodes, + }, + { + Name: "gaia", + Version: "v12.0.0-rc0", + ChainConfig: ibc.ChainConfig{ + GasPrices: "0.0uatom", + }, + NumValidators: &numVals, + NumFullNodes: &numFullNodes, + }, + { + Name: "osmosis", + Version: "v17.0.0", + ChainConfig: ibc.ChainConfig{ + GasPrices: "0.005uosmo", + EncodingConfig: osmosisEncoding(), + }, + GasAdjustment: &gasAdjustment, + NumValidators: &numVals, + NumFullNodes: &numFullNodes, + }, + }) + + chains, err := cf.Chains(t.Name()) + require.NoError(t, err) + + feeabs, gaia, osmosis := chains[0].(*cosmos.CosmosChain), chains[1].(*cosmos.CosmosChain), chains[2].(*cosmos.CosmosChain) + + r := interchaintest.NewBuiltinRelayerFactory( + ibc.CosmosRly, + zaptest.NewLogger(t), + ).Build(t, client, network) + + ic := interchaintest.NewInterchain(). + AddChain(feeabs). + AddChain(gaia). + AddChain(osmosis). + AddRelayer(r, "relayer"). + AddLink(interchaintest.InterchainLink{ + Chain1: feeabs, + Chain2: gaia, + Relayer: r, + Path: pathFeeabsGaia, + }). + AddLink(interchaintest.InterchainLink{ + Chain1: feeabs, + Chain2: osmosis, + Relayer: r, + Path: pathFeeabsOsmosis, + }). + AddLink(interchaintest.InterchainLink{ + Chain1: osmosis, + Chain2: gaia, + Relayer: r, + Path: pathOsmosisGaia, + }) + + require.NoError(t, ic.Build(ctx, eRep, interchaintest.InterchainBuildOptions{ + TestName: t.Name(), + Client: client, + NetworkID: network, + BlockDatabaseFile: interchaintest.DefaultBlockDatabaseFilepath(), + + SkipPathCreation: true, + })) + t.Cleanup(func() { + _ = ic.Close() + }) + + const userFunds = int64(10_000_000_000) + users := interchaintest.GetAndFundTestUsers(t, ctx, t.Name(), userFunds, feeabs, gaia, osmosis) + + // rly feeabs-osmo + // Generate new path + err = r.GeneratePath(ctx, eRep, feeabs.Config().ChainID, osmosis.Config().ChainID, pathFeeabsOsmosis) + require.NoError(t, err) + // Create client + err = r.CreateClients(ctx, eRep, pathFeeabsOsmosis, ibc.DefaultClientOpts()) + require.NoError(t, err) + + err = testutil.WaitForBlocks(ctx, 5, feeabs, osmosis) + require.NoError(t, err) + + // Create connection + err = r.CreateConnections(ctx, eRep, pathFeeabsOsmosis) + require.NoError(t, err) + + err = testutil.WaitForBlocks(ctx, 5, feeabs, osmosis) + require.NoError(t, err) + // Create channel + err = r.CreateChannel(ctx, eRep, pathFeeabsOsmosis, ibc.CreateChannelOptions{ + SourcePortName: "transfer", + DestPortName: "transfer", + Order: ibc.Unordered, + Version: "ics20-1", + }) + require.NoError(t, err) + + err = testutil.WaitForBlocks(ctx, 5, feeabs, osmosis) + require.NoError(t, err) + + channsFeeabs, err := r.GetChannels(ctx, eRep, feeabs.Config().ChainID) + require.NoError(t, err) + + channsOsmosis, err := r.GetChannels(ctx, eRep, osmosis.Config().ChainID) + require.NoError(t, err) + + require.Len(t, channsFeeabs, 1) + require.Len(t, channsOsmosis, 1) + + channFeeabsOsmosis := channsFeeabs[0] + require.NotEmpty(t, channFeeabsOsmosis.ChannelID) + channOsmosisFeeabs := channsOsmosis[0] + require.NotEmpty(t, channOsmosisFeeabs.ChannelID) + // rly feeabs-gaia + // Generate new path + err = r.GeneratePath(ctx, eRep, feeabs.Config().ChainID, gaia.Config().ChainID, pathFeeabsGaia) + require.NoError(t, err) + // Create clients + err = r.CreateClients(ctx, eRep, pathFeeabsGaia, ibc.DefaultClientOpts()) + require.NoError(t, err) + + err = testutil.WaitForBlocks(ctx, 5, feeabs, gaia) + require.NoError(t, err) + + // Create connection + err = r.CreateConnections(ctx, eRep, pathFeeabsGaia) + require.NoError(t, err) + + err = testutil.WaitForBlocks(ctx, 5, feeabs, gaia) + require.NoError(t, err) + + // Create channel + err = r.CreateChannel(ctx, eRep, pathFeeabsGaia, ibc.CreateChannelOptions{ + SourcePortName: "transfer", + DestPortName: "transfer", + Order: ibc.Unordered, + Version: "ics20-1", + }) + require.NoError(t, err) + + err = testutil.WaitForBlocks(ctx, 5, feeabs, gaia) + require.NoError(t, err) + + channsFeeabs, err = r.GetChannels(ctx, eRep, feeabs.Config().ChainID) + require.NoError(t, err) + + channsGaia, err := r.GetChannels(ctx, eRep, gaia.Config().ChainID) + require.NoError(t, err) + + require.Len(t, channsFeeabs, 2) + require.Len(t, channsGaia, 1) + + var channFeeabsGaia ibc.ChannelOutput + for _, chann := range channsFeeabs { + if chann.ChannelID != channFeeabsOsmosis.ChannelID { + channFeeabsGaia = chann + } + } + require.NotEmpty(t, channFeeabsGaia.ChannelID) + + channGaiaFeeabs := channsGaia[0] + require.NotEmpty(t, channGaiaFeeabs.ChannelID) + // rly osmo-gaia + // Generate new path + err = r.GeneratePath(ctx, eRep, osmosis.Config().ChainID, gaia.Config().ChainID, pathOsmosisGaia) + require.NoError(t, err) + // Create clients + err = r.CreateClients(ctx, eRep, pathOsmosisGaia, ibc.DefaultClientOpts()) + require.NoError(t, err) + + err = testutil.WaitForBlocks(ctx, 5, osmosis, gaia) + require.NoError(t, err) + // Create connection + err = r.CreateConnections(ctx, eRep, pathOsmosisGaia) + require.NoError(t, err) + + err = testutil.WaitForBlocks(ctx, 5, osmosis, gaia) + require.NoError(t, err) + // Create channel + err = r.CreateChannel(ctx, eRep, pathOsmosisGaia, ibc.CreateChannelOptions{ + SourcePortName: "transfer", + DestPortName: "transfer", + Order: ibc.Unordered, + Version: "ics20-1", + }) + require.NoError(t, err) + + err = testutil.WaitForBlocks(ctx, 5, osmosis, gaia) + require.NoError(t, err) + + channsOsmosis, err = r.GetChannels(ctx, eRep, osmosis.Config().ChainID) + require.NoError(t, err) + + channsGaia, err = r.GetChannels(ctx, eRep, gaia.Config().ChainID) + require.NoError(t, err) + + require.Len(t, channsOsmosis, 2) + require.Len(t, channsGaia, 2) + + var channOsmosisGaia ibc.ChannelOutput + var channGaiaOsmosis ibc.ChannelOutput + + for _, chann := range channsOsmosis { + if chann.ChannelID != channOsmosisFeeabs.ChannelID { + channOsmosisGaia = chann + } + } + require.NotEmpty(t, channOsmosisGaia) + + for _, chann := range channsGaia { + if chann.ChannelID != channGaiaFeeabs.ChannelID { + channGaiaOsmosis = chann + } + } + require.NotEmpty(t, channGaiaOsmosis) + + fmt.Println("-----------------------------------") + fmt.Printf("channFeeabsOsmosis: %s - %s\n", channFeeabsOsmosis.ChannelID, channFeeabsOsmosis.Counterparty.ChannelID) + fmt.Printf("channOsmosisFeeabs: %s - %s\n", channOsmosisFeeabs.ChannelID, channOsmosisFeeabs.Counterparty.ChannelID) + fmt.Printf("channFeeabsGaia: %s - %s\n", channFeeabsGaia.ChannelID, channFeeabsGaia.Counterparty.ChannelID) + fmt.Printf("channGaiaFeeabs: %s - %s\n", channGaiaFeeabs.ChannelID, channGaiaFeeabs.Counterparty.ChannelID) + fmt.Printf("channOsmosisGaia: %s - %s\n", channOsmosisGaia.ChannelID, channOsmosisGaia.Counterparty.ChannelID) + fmt.Printf("channGaiaOsmosis: %s - %s\n", channGaiaOsmosis.ChannelID, channGaiaOsmosis.Counterparty.ChannelID) + fmt.Println("-----------------------------------") + + // Start the relayer on both paths + err = r.StartRelayer(ctx, eRep, pathFeeabsGaia, pathFeeabsOsmosis, pathOsmosisGaia) + require.NoError(t, err) + + t.Cleanup( + func() { + err := r.StopRelayer(ctx, eRep) + if err != nil { + t.Logf("an error occurred while stopping the relayer: %s", err) + } + }, + ) + + // Get original account balances + feeabsUser, gaiaUser, osmosisUser := users[0], users[1], users[2] + _ = feeabsUser + _ = gaiaUser + _ = osmosisUser + + amountToSend := math.NewInt(1_000_000_000) + + // Send Gaia uatom to Osmosis + gaiaHeight, err := gaia.Height(ctx) + require.NoError(t, err) + dstAddress := sdktypes.MustBech32ifyAddressBytes(osmosis.Config().Bech32Prefix, osmosisUser.Address()) + transfer := ibc.WalletAmount{ + Address: dstAddress, + Denom: gaia.Config().Denom, + Amount: amountToSend, + } + + tx, err := gaia.SendIBCTransfer(ctx, channGaiaOsmosis.ChannelID, gaiaUser.KeyName(), transfer, ibc.TransferOptions{}) + require.NoError(t, err) + require.NoError(t, tx.Validate()) + + _, err = testutil.PollForAck(ctx, gaia, gaiaHeight, gaiaHeight+30, tx.Packet) + require.NoError(t, err) + err = testutil.WaitForBlocks(ctx, 1, feeabs, gaia, osmosis) + require.NoError(t, err) + + // Send Feeabs stake to Osmosis + feeabsHeight, err := feeabs.Height(ctx) + require.NoError(t, err) + dstAddress = sdktypes.MustBech32ifyAddressBytes(osmosis.Config().Bech32Prefix, osmosisUser.Address()) + transfer = ibc.WalletAmount{ + Address: dstAddress, + Denom: feeabs.Config().Denom, + Amount: amountToSend, + } + + tx, err = feeabs.SendIBCTransfer(ctx, channFeeabsOsmosis.ChannelID, feeabsUser.KeyName(), transfer, ibc.TransferOptions{}) + require.NoError(t, err) + require.NoError(t, tx.Validate()) + + _, err = testutil.PollForAck(ctx, feeabs, feeabsHeight, feeabsHeight+30, tx.Packet) + require.NoError(t, err) + err = testutil.WaitForBlocks(ctx, 1, feeabs, gaia, osmosis) + require.NoError(t, err) + + // Send Gaia uatom to Feeabs + gaiaHeight, err = gaia.Height(ctx) + require.NoError(t, err) + dstAddress = sdktypes.MustBech32ifyAddressBytes(feeabs.Config().Bech32Prefix, feeabsUser.Address()) + transfer = ibc.WalletAmount{ + Address: dstAddress, + Denom: gaia.Config().Denom, + Amount: amountToSend, + } + + tx, err = gaia.SendIBCTransfer(ctx, channGaiaFeeabs.ChannelID, gaiaUser.KeyName(), transfer, ibc.TransferOptions{}) + require.NoError(t, err) + require.NoError(t, tx.Validate()) + + _, err = testutil.PollForAck(ctx, gaia, gaiaHeight, gaiaHeight+30, tx.Packet) + require.NoError(t, err) + err = testutil.WaitForBlocks(ctx, 1, feeabs, gaia, osmosis) + require.NoError(t, err) + // Setup contract on Osmosis + // Store code crosschain Registry + crossChainRegistryContractID, err := osmosis.StoreContract(ctx, osmosisUser.KeyName(), "./bytecode/crosschain_registry.wasm") + require.NoError(t, err) + _ = crossChainRegistryContractID + // // Instatiate + owner := sdktypes.MustBech32ifyAddressBytes(osmosis.Config().Bech32Prefix, osmosisUser.Address()) + initMsg := fmt.Sprintf("{\"owner\":\"%s\"}", owner) + registryContractAddress, err := osmosis.InstantiateContract(ctx, osmosisUser.KeyName(), crossChainRegistryContractID, initMsg, true) + require.NoError(t, err) + // Execute + msg := fmt.Sprintf("{\"modify_chain_channel_links\": {\"operations\": [{\"operation\": \"set\",\"source_chain\": \"feeabs\",\"destination_chain\": \"osmosis\",\"channel_id\": \"%s\"},{\"operation\": \"set\",\"source_chain\": \"osmosis\",\"destination_chain\": \"feeabs\",\"channel_id\": \"%s\"},{\"operation\": \"set\",\"source_chain\": \"feeabs\",\"destination_chain\": \"gaia\",\"channel_id\": \"%s\"},{\"operation\": \"set\",\"source_chain\": \"gaia\",\"destination_chain\": \"feeabs\",\"channel_id\": \"%s\"},{\"operation\": \"set\",\"source_chain\": \"osmosis\",\"destination_chain\": \"gaia\",\"channel_id\": \"%s\"},{\"operation\": \"set\",\"source_chain\": \"gaia\",\"destination_chain\": \"osmosis\",\"channel_id\": \"%s\"}]}}", + channFeeabsOsmosis.ChannelID, + channOsmosisFeeabs.ChannelID, + channFeeabsGaia.ChannelID, + channGaiaFeeabs.ChannelID, + channOsmosisGaia.ChannelID, + channGaiaOsmosis.ChannelID) + _, err = osmosis.ExecuteContract(ctx, osmosisUser.KeyName(), registryContractAddress, msg) + require.NoError(t, err) + // Execute + msg = `{ + "modify_bech32_prefixes": + { + "operations": + [ + {"operation": "set", "chain_name": "feeabs", "prefix": "feeabs"}, + {"operation": "set", "chain_name": "osmosis", "prefix": "osmo"}, + {"operation": "set", "chain_name": "gaia", "prefix": "cosmos"} + ] + } + }` + _, err = osmosis.ExecuteContract(ctx, osmosisUser.KeyName(), registryContractAddress, msg) + require.NoError(t, err) + + // Create pool Osmosis(uatom)/Osmosis(stake) on Osmosis + denomTrace := transfertypes.ParseDenomTrace(transfertypes.GetPrefixedDenom(channOsmosisGaia.PortID, channOsmosisGaia.ChannelID, gaia.Config().Denom)) + uatomOnOsmosis := denomTrace.IBCDenom() + osmosisUserBalance, err := osmosis.GetBalance(ctx, sdktypes.MustBech32ifyAddressBytes(osmosis.Config().Bech32Prefix, osmosisUser.Address()), uatomOnOsmosis) + require.NoError(t, err) + require.Equal(t, amountToSend, osmosisUserBalance) + + denomTrace = transfertypes.ParseDenomTrace(transfertypes.GetPrefixedDenom(channOsmosisFeeabs.PortID, channOsmosisFeeabs.ChannelID, feeabs.Config().Denom)) + stakeOnOsmosis := denomTrace.IBCDenom() + osmosisUserBalance, err = osmosis.GetBalance(ctx, sdktypes.MustBech32ifyAddressBytes(osmosis.Config().Bech32Prefix, osmosisUser.Address()), stakeOnOsmosis) + require.NoError(t, err) + require.Equal(t, amountToSend, osmosisUserBalance) + + poolID, err := cosmos.OsmosisCreatePool(osmosis, ctx, osmosisUser.KeyName(), cosmos.OsmosisPoolParams{ + Weights: fmt.Sprintf("5%s,5%s", stakeOnOsmosis, uatomOnOsmosis), + InitialDeposit: fmt.Sprintf("95000000%s,950000000%s", stakeOnOsmosis, uatomOnOsmosis), + SwapFee: "0.01", + ExitFee: "0", + FutureGovernor: "", + }) + require.NoError(t, err) + require.Equal(t, poolID, "1") + + // Setup propose_pfm + // propose_pfm for feeabs + _, err = cosmos.OsmosisSetupProposePFM(osmosis, ctx, osmosisUser.KeyName(), registryContractAddress, `{"propose_pfm":{"chain": "feeabs"}}`, stakeOnOsmosis) + require.NoError(t, err) + err = testutil.WaitForBlocks(ctx, 15, feeabs, gaia, osmosis) + require.NoError(t, err) + queryMsg := QuerySmartMsg{ + Packet: HasPacketForwarding{ + ChainID: "feeabs", + }, + } + res := QuerySmartMsgResponse{} + osmosis.QueryContract(ctx, registryContractAddress, queryMsg, res) + // propose_pfm for gaia + _, err = cosmos.OsmosisSetupProposePFM(osmosis, ctx, osmosisUser.KeyName(), registryContractAddress, `{"propose_pfm":{"chain": "gaia"}}`, uatomOnOsmosis) + require.NoError(t, err) + err = testutil.WaitForBlocks(ctx, 15, feeabs, gaia, osmosis) + require.NoError(t, err) + queryMsg = QuerySmartMsg{ + Packet: HasPacketForwarding{ + ChainID: "gaia", + }, + } + res = QuerySmartMsgResponse{} + osmosis.QueryContract(ctx, registryContractAddress, queryMsg, res) + // store swaprouter + swapRouterContractID, err := osmosis.StoreContract(ctx, osmosisUser.KeyName(), "./bytecode/swaprouter.wasm") + require.NoError(t, err) + // instantiate + swapRouterContractAddress, err := osmosis.InstantiateContract(ctx, osmosisUser.KeyName(), swapRouterContractID, initMsg, true) + require.NoError(t, err) + + // execute + msg = fmt.Sprintf("{\"set_route\":{\"input_denom\":\"%s\",\"output_denom\":\"%s\",\"pool_route\":[{\"pool_id\":\"%s\",\"token_out_denom\":\"%s\"}]}}", + uatomOnOsmosis, + stakeOnOsmosis, + poolID, + stakeOnOsmosis, + ) + _, err = osmosis.ExecuteContract(ctx, osmosisUser.KeyName(), swapRouterContractAddress, msg) + require.NoError(t, err) + + // store xcs + xcsContractID, err := osmosis.StoreContract(ctx, osmosisUser.KeyName(), "./bytecode/crosschain_swaps.wasm") + require.NoError(t, err) + // instantiate + initMsg = fmt.Sprintf("{\"swap_contract\":\"%s\",\"governor\": \"%s\"}", swapRouterContractAddress, owner) + xcsContractAddress, err := osmosis.InstantiateContract(ctx, osmosisUser.KeyName(), xcsContractID, initMsg, true) + _ = xcsContractAddress + require.NoError(t, err) + // Swap Feeabs(uatom) to Osmosis + // send ibc token to feeabs module account + gaiaHeight, err = gaia.Height(ctx) + require.NoError(t, err) + feeabsModule, err := QueryFeeabsModuleAccountBalances(feeabs, ctx) + require.NoError(t, err) + dstAddress = feeabsModule.Address + transfer = ibc.WalletAmount{ + Address: dstAddress, + Denom: gaia.Config().Denom, + Amount: math.NewInt(1_000_000), + } + + tx, err = gaia.SendIBCTransfer(ctx, channGaiaFeeabs.ChannelID, gaiaUser.KeyName(), transfer, ibc.TransferOptions{}) + require.NoError(t, err) + require.NoError(t, tx.Validate()) + + _, err = testutil.PollForAck(ctx, gaia, gaiaHeight, gaiaHeight+30, tx.Packet) + require.NoError(t, err) + err = testutil.WaitForBlocks(ctx, 1, feeabs, gaia, osmosis) + require.NoError(t, err) + + denomTrace = transfertypes.ParseDenomTrace(transfertypes.GetPrefixedDenom(channFeeabsGaia.PortID, channFeeabsGaia.ChannelID, gaia.Config().Denom)) + + // Start testing for add host zone proposal + _, err = cosmos.FeeabsAddHostZoneProposal(feeabs, ctx, feeabsUser.KeyName(), "./proposal/add_host_zone.json") + require.NoError(t, err) + + err = feeabs.VoteOnProposalAllValidators(ctx, "1", cosmos.ProposalVoteYes) + require.NoError(t, err, "failed to submit votes") + + height, _ := feeabs.Height(ctx) + _, err = cosmos.PollForProposalStatus(ctx, feeabs, height, height+10, "1", cosmos.ProposalStatusPassed) + require.NoError(t, err, "proposal status did not change to passed in expected number of blocks") + + config, err := feeabsCli.QueryFeeabsHostZoneConfigWithDenom(feeabs, ctx, "ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9") + require.NoError(t, err) + require.Equal(t, config, &feeabsCli.HostChainFeeAbsConfigResponse{HostChainConfig: feeabsCli.HostChainFeeAbsConfig{ + IbcDenom: "ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9", + OsmosisPoolTokenDenomIn: "ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9", + PoolId: "1", + Frozen: false, + }}) + + // Start testing for set host zone proposal + _, err = feeabsCli.SetHostZoneProposal(feeabs, ctx, feeabsUser.KeyName(), "./proposal/set_host_zone.json") + require.NoError(t, err) + + err = feeabs.VoteOnProposalAllValidators(ctx, "2", cosmos.ProposalVoteYes) + require.NoError(t, err, "failed to submit votes") + + height, _ = feeabs.Height(ctx) + _, err = cosmos.PollForProposalStatus(ctx, feeabs, height, height+10, "2", cosmos.ProposalStatusPassed) + require.NoError(t, err, "proposal status did not change to passed in expected number of blocks") + + config, err = feeabsCli.QueryFeeabsHostZoneConfigWithDenom(feeabs, ctx, "ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9") + require.NoError(t, err) + require.Equal(t, config, &feeabsCli.HostChainFeeAbsConfigResponse{HostChainConfig: feeabsCli.HostChainFeeAbsConfig{ + IbcDenom: "ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9", + OsmosisPoolTokenDenomIn: "ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9", + PoolId: "1", + Frozen: true, + }}) + + // Start testing for delete host zone proposal + _, err = feeabsCli.DeleteHostZoneProposal(feeabs, ctx, feeabsUser.KeyName(), "./proposal/delete_host_zone.json") + require.NoError(t, err) + + err = feeabs.VoteOnProposalAllValidators(ctx, "3", cosmos.ProposalVoteYes) + require.NoError(t, err, "failed to submit votes") + + height, _ = feeabs.Height(ctx) + response, err := cosmos.PollForProposalStatus(ctx, feeabs, height, height+10, "3", cosmos.ProposalStatusPassed) + require.NoError(t, err, "proposal status did not change to passed in expected number of blocks") + fmt.Printf("response: %s\n", response) + + config, err = feeabsCli.QueryFeeabsHostZoneConfigWithDenom(feeabs, ctx, "ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9") + require.Equal(t, config, &feeabsCli.HostChainFeeAbsConfigResponse{HostChainConfig: feeabsCli.HostChainFeeAbsConfig{ + IbcDenom: "", + OsmosisPoolTokenDenomIn: "", + PoolId: "", + Frozen: false, + }}) +} diff --git a/tests/interchaintest/packet_foward_test.go b/tests/interchaintest/packet_foward_test.go index 6dfaf2ec..c1a2f729 100644 --- a/tests/interchaintest/packet_foward_test.go +++ b/tests/interchaintest/packet_foward_test.go @@ -513,7 +513,7 @@ func TestPacketForwardMiddleware(t *testing.T) { _, err = cosmos.PollForProposalStatus(ctx, feeabs, height, height+10, paramTx.ProposalID, cosmos.ProposalStatusPassed) require.NoError(t, err, "proposal status did not change to passed in expected number of blocks") - _, err = cosmos.FeeabsAddHostZoneProposal(feeabs, ctx, feeabsUser.KeyName(), "./proposal/host_zone.json") + _, err = cosmos.FeeabsAddHostZoneProposal(feeabs, ctx, feeabsUser.KeyName(), "./proposal/add_host_zone.json") require.NoError(t, err) err = feeabs.VoteOnProposalAllValidators(ctx, "2", cosmos.ProposalVoteYes) diff --git a/tests/interchaintest/proposal/host_zone.json b/tests/interchaintest/proposal/add_host_zone.json similarity index 100% rename from tests/interchaintest/proposal/host_zone.json rename to tests/interchaintest/proposal/add_host_zone.json diff --git a/tests/interchaintest/proposal/delete_host_zone.json b/tests/interchaintest/proposal/delete_host_zone.json new file mode 100644 index 00000000..0d2f3a7c --- /dev/null +++ b/tests/interchaintest/proposal/delete_host_zone.json @@ -0,0 +1,6 @@ +{ + "title": "Delete Fee Abbtraction Host Zone Proposal", + "description": "Delete Fee Abbtraction Host Zone", + "ibc_denom": "ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9", + "deposit": "100000000stake" +} \ No newline at end of file diff --git a/tests/interchaintest/proposal/set_host_zone.json b/tests/interchaintest/proposal/set_host_zone.json new file mode 100644 index 00000000..eef2c6fb --- /dev/null +++ b/tests/interchaintest/proposal/set_host_zone.json @@ -0,0 +1,12 @@ +{ + "title": "Set Fee Abbtraction Host Zone Proposal", + "description": "Set Fee Abbtraction Host Zone", + "host_chain_fee_abs_config": + { + "ibc_denom": "ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9", + "osmosis_pool_token_denom_in": "ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9", + "pool_id": "1", + "frozen": true + }, + "deposit": "100000000stake" +} \ No newline at end of file