Skip to content

Commit

Permalink
refactor test
Browse files Browse the repository at this point in the history
  • Loading branch information
tuantran1702 committed May 14, 2024
1 parent f844e25 commit 5cb267f
Show file tree
Hide file tree
Showing 11 changed files with 218 additions and 132 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,6 @@ replace (
// latest grpc doesn't work with our modified proto compiler, so we need to enforce
// the following version across all dependencies.
google.golang.org/grpc => google.golang.org/grpc v1.54.0


)
19 changes: 19 additions & 0 deletions tests/interchaintest/feeabs/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package feeabs
import (
"context"
"encoding/json"
"fmt"
"time"

"github.com/strangelove-ventures/interchaintest/v7/chain/cosmos"

Expand Down Expand Up @@ -73,3 +75,20 @@ func QueryOsmosisArithmeticTwap(c *cosmos.CosmosChain, ctx context.Context, ibcD
}
return &response, nil
}

func QueryOsmosisArithmeticTwapOsmosis(c *cosmos.CosmosChain, ctx context.Context, poolID, ibcDenom string) (*feeabstypes.QueryOsmosisArithmeticTwapResponse, error) {
node := getFullNode(c)
currentEpoch := time.Now().Unix()

cmd := []string{"twap", "arithmetic", poolID, ibcDenom, fmt.Sprintf("%d", currentEpoch-20), fmt.Sprintf("%d", currentEpoch-10)}
stdout, _, err := node.ExecQuery(ctx, cmd...)
if err != nil {
return &feeabstypes.QueryOsmosisArithmeticTwapResponse{}, err
}

var response feeabstypes.QueryOsmosisArithmeticTwapResponse
if err = json.Unmarshal(stdout, &response); err != nil {
return &feeabstypes.QueryOsmosisArithmeticTwapResponse{}, err
}
return &response, nil
}
2 changes: 1 addition & 1 deletion tests/interchaintest/feeabs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/strangelove-ventures/interchaintest/v7/testutil"
"github.com/stretchr/testify/require"

feeabsCli "github.com/osmosis-labs/fee-abstraction/tests/interchaintest/feeabs"
feeabsCli "github.com/osmosis-labs/fee-abstraction/v7/tests/interchaintest/feeabs"
)

func TestFeeAbs(t *testing.T) {
Expand Down
31 changes: 16 additions & 15 deletions tests/interchaintest/go.mod
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
module github.com/osmosis-labs/fee-abstraction/tests/interchaintest
module github.com/osmosis-labs/fee-abstraction/v7/tests/interchaintest

go 1.21

require (
cosmossdk.io/errors v1.0.1
cosmossdk.io/math v1.2.0
github.com/CosmWasm/wasmvm v1.3.0
github.com/avast/retry-go/v4 v4.5.0
github.com/cometbft/cometbft v0.37.4
github.com/cometbft/cometbft-db v0.9.1
github.com/cosmos/cosmos-proto v1.0.0-beta.3
github.com/cosmos/cosmos-sdk v0.47.8
github.com/cosmos/gogoproto v1.4.10
github.com/cosmos/iavl v0.20.1
github.com/cosmos/ibc-go/v7 v7.3.1
github.com/icza/dyno v0.0.0-20220812133438-f0b6f8a18845
github.com/osmosis-labs/fee-abstraction/v7 v7.0.0-20240308160138-d1eb119cae30
github.com/spf13/cast v1.5.1
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
github.com/strangelove-ventures/interchaintest/v7 v7.0.0
github.com/stretchr/testify v1.8.4
go.uber.org/zap v1.26.0
golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb
google.golang.org/grpc v1.60.1
google.golang.org/protobuf v1.32.0
gopkg.in/yaml.v2 v2.4.0
)

require (
Expand All @@ -23,7 +37,6 @@ require (
cosmossdk.io/api v0.3.1 // indirect
cosmossdk.io/core v0.6.1 // indirect
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
cosmossdk.io/errors v1.0.1 // indirect
cosmossdk.io/log v1.3.0 // indirect
cosmossdk.io/tools/rosetta v0.2.1 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
Expand All @@ -34,7 +47,6 @@ require (
github.com/ChainSafe/go-schnorrkel/1 v0.0.0-00010101000000-000000000000 // indirect
github.com/ComposableFi/go-subkey/v2 v2.0.0-tm03420 // indirect
github.com/CosmWasm/wasmd v0.41.0 // indirect
github.com/CosmWasm/wasmvm v1.3.0 // indirect
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
github.com/Microsoft/go-winio v0.6.0 // indirect
Expand All @@ -53,15 +65,10 @@ require (
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/coinbase/rosetta-sdk-go/types v1.0.0 // indirect
github.com/cometbft/cometbft v0.37.4 // indirect
github.com/cometbft/cometbft-db v0.9.1 // indirect
github.com/confio/ics23/go v0.9.0 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.3 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/gogoproto v1.4.10 // indirect
github.com/cosmos/iavl v0.20.1 // indirect
github.com/cosmos/ibc-go/modules/capability v1.0.0-rc1 // indirect
github.com/cosmos/ics23/go v0.10.0 // indirect
github.com/cosmos/interchain-security/v3 v3.1.1-0.20231102122221-81650a84f989 // indirect
Expand Down Expand Up @@ -183,10 +190,7 @@ require (
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.16.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
Expand All @@ -204,7 +208,6 @@ require (
go.opentelemetry.io/otel/trace v1.19.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.16.0 // indirect
golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/oauth2 v0.13.0 // indirect
Expand All @@ -218,11 +221,8 @@ require (
google.golang.org/genproto v0.0.0-20240102182953-50ed04b92917 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231212172506-995d672761c0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240108191215-35c7eff3a6b1 // indirect
google.golang.org/grpc v1.60.1 // indirect
google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/blake3 v1.1.7 // indirect
lukechampine.com/uint128 v1.2.0 // indirect
Expand All @@ -247,5 +247,6 @@ replace (
github.com/cometbft/cometbft => github.com/cometbft/cometbft v0.37.2
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/osmosis-labs/fee-abstraction/v7 => ../../
github.com/osmosis-labs/fee-abstraction/v7/tests/interchaintest/osmosis => ./osmosis
github.com/vedhavyas/go-subkey => github.com/strangelove-ventures/go-subkey v1.0.7
)
2 changes: 1 addition & 1 deletion tests/interchaintest/host_zone_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/strangelove-ventures/interchaintest/v7/chain/cosmos"
"github.com/stretchr/testify/require"

feeabsCli "github.com/osmosis-labs/fee-abstraction/tests/interchaintest/feeabs"
feeabsCli "github.com/osmosis-labs/fee-abstraction/v7/tests/interchaintest/feeabs"
)

func TestHostZoneProposal(t *testing.T) {
Expand Down
36 changes: 19 additions & 17 deletions tests/interchaintest/ibc_transfer_customfee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
paramsutils "github.com/cosmos/cosmos-sdk/x/params/client/utils"
transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
feeabsCli "github.com/osmosis-labs/fee-abstraction/tests/interchaintest/feeabs"
feeabsCli "github.com/osmosis-labs/fee-abstraction/v7/tests/interchaintest/feeabs"
"github.com/strangelove-ventures/interchaintest/v7/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v7/ibc"
"github.com/strangelove-ventures/interchaintest/v7/testutil"
Expand Down Expand Up @@ -84,8 +84,8 @@ func TestFeeabsGaiaIBCTransferWithIBCFee(t *testing.T) {
require.Equal(t, amountToSend, osmosisUserBalance)

poolID, err := feeabsCli.CreatePool(osmosis, ctx, osmosisUser.KeyName(), cosmos.OsmosisPoolParams{
Weights: fmt.Sprintf("5%s,5%s", stakeOnOsmosis, uatomOnOsmosis),
InitialDeposit: fmt.Sprintf("95000000%s,950000000%s", stakeOnOsmosis, uatomOnOsmosis),
Weights: fmt.Sprintf("5%s,5%s", osmosis.Config().Denom, stakeOnOsmosis),
InitialDeposit: fmt.Sprintf("95000000%s,950000000%s", osmosis.Config().Denom, stakeOnOsmosis),
SwapFee: "0.01",
ExitFee: "0",
FutureGovernor: "",
Expand Down Expand Up @@ -122,7 +122,7 @@ func TestFeeabsGaiaIBCTransferWithIBCFee(t *testing.T) {
require.NoError(t, err)

denomTrace = transfertypes.ParseDenomTrace(transfertypes.GetPrefixedDenom(channFeeabsGaia.PortID, channFeeabsGaia.ChannelID, gaia.Config().Denom))
uatomOnFeeabs := denomTrace.IBCDenom()
// uatomOnFeeabs := denomTrace.IBCDenom()

current_directory, _ := os.Getwd()
param_change_path := path.Join(current_directory, "proposal", "proposal.json")
Expand Down Expand Up @@ -157,8 +157,8 @@ func TestFeeabsGaiaIBCTransferWithIBCFee(t *testing.T) {
_, err = feeabsCli.QueryAllHostZoneConfig(feeabs, ctx)
require.NoError(t, err)

twap, err := feeabsCli.QueryOsmosisArithmeticTwap(feeabs, ctx, uatomOnFeeabs)
fmt.Println(err)
twap, err := feeabsCli.QueryOsmosisArithmeticTwap(feeabs, ctx, uatomOnOsmosis)
require.NoError(t, err)
fmt.Println(twap)

// Wait a few blocks for relayer to start and for user accounts to be created
Expand All @@ -171,14 +171,6 @@ func TestFeeabsGaiaIBCTransferWithIBCFee(t *testing.T) {
feeabsUserAddr := sdktypes.MustBech32ifyAddressBytes(feeabs.Config().Bech32Prefix, feeabsUser.Address())
gaiaUserAddr := sdktypes.MustBech32ifyAddressBytes(gaia.Config().Bech32Prefix, gaiaUser.Address())

// Compose an IBC transfer and send from feeabs -> Gaia
transferAmount := math.NewInt(1_000)
transfer := ibc.WalletAmount{
Address: gaiaUserAddr,
Denom: gaia.Config().Denom,
Amount: transferAmount,
}

// transferTx, err := feeabs.SendIBCTransfer(ctx, channel.ChannelID, feeabsUserAddr, transfer, ibc.TransferOptions{})
// require.NoError(t, err)

Expand All @@ -203,11 +195,21 @@ func TestFeeabsGaiaIBCTransferWithIBCFee(t *testing.T) {
// require.Equal(t, transferAmount, gaiaUpdateBal)

// Compose an IBC transfer and send from Gaia -> Feeabs

gaiaTokenDenom := transfertypes.GetPrefixedDenom(channFeeabsGaia.ChannelID, channFeeabsGaia.PortID, gaia.Config().Denom)
gaiaIBCDenom := transfertypes.ParseDenomTrace(gaiaTokenDenom).IBCDenom()

transferAmount := math.NewInt(1_000)
transfer := ibc.WalletAmount{
Address: gaiaUserAddr,
Denom: gaia.Config().Denom,
Amount: transferAmount,
}

gaiaInitialBal, err := gaia.GetBalance(ctx, gaiaUserAddr, gaia.Config().Denom)
require.NoError(t, err)
transferTx, err := gaia.SendIBCTransfer(ctx, channFeeabsGaia.ChannelID, gaiaUserAddr, transfer, ibc.TransferOptions{})

transferTx, err := gaia.SendIBCTransfer(ctx, channFeeabsGaia.ChannelID, gaiaUser.KeyName(), transfer, ibc.TransferOptions{})
require.NoError(t, err)

gaiaHeight, err := gaia.Height(ctx)
Expand All @@ -217,14 +219,14 @@ func TestFeeabsGaiaIBCTransferWithIBCFee(t *testing.T) {
_, err = testutil.PollForAck(ctx, gaia, gaiaHeight, gaiaHeight+10, transferTx.Packet)
require.NoError(t, err)

// Assert that the funds are now back on feeabs and not on Gaia
// Assert that the ATOM funds are no longer present in user acc on Gaia and are in the user acc on Feeabs
feeabsUpdateBal, err := feeabs.GetBalance(ctx, feeabsUserAddr, gaiaIBCDenom)
require.NoError(t, err)
require.Equal(t, transferAmount, feeabsUpdateBal)

gaiaUpdateBal, err := gaia.GetBalance(ctx, gaiaUserAddr, gaia.Config().Denom)
require.NoError(t, err)
require.Equal(t, gaiaInitialBal.Sub(transferAmount), gaiaUpdateBal)
require.LessOrEqual(t, gaiaInitialBal.Sub(transferAmount), gaiaUpdateBal)

// Compose an IBC transfer and send from Feeabs -> Gaia
transferAmount = math.NewInt(1_000)
Expand Down
2 changes: 1 addition & 1 deletion tests/interchaintest/packet_foward_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/strangelove-ventures/interchaintest/v7/testutil"
"github.com/stretchr/testify/require"

feeabsCli "github.com/osmosis-labs/fee-abstraction/tests/interchaintest/feeabs"
feeabsCli "github.com/osmosis-labs/fee-abstraction/v7/tests/interchaintest/feeabs"
)

func TestPacketForwardMiddleware(t *testing.T) {
Expand Down
23 changes: 11 additions & 12 deletions tests/interchaintest/proposal/add_host_zone.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"title": "Add Fee Abbtraction Host Zone Proposal",
"description": "Add Fee Abbtraction Host Zone",
"host_chain_fee_abs_config":
{
"ibc_denom": "ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9",
"osmosis_pool_token_denom_in": "ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9",
"pool_id": "1",
"status": 0,
"min_swap_amount": "0"
},
"deposit": "100000000stake"
}
"title": "Add Fee Abbtraction Host Zone Proposal",
"description": "Add Fee Abbtraction Host Zone",
"host_chain_fee_abs_config": {
"ibc_denom": "ibc/3C3D7B3BE4ECC85A0E5B52A3AEC3B7DFC2AA9CA47C37821E57020D6807043BE9",
"osmosis_pool_token_denom_in": "uosmo",
"pool_id": "1",
"status": 0,
"min_swap_amount": "0"
},
"deposit": "100000000stake"
}
62 changes: 31 additions & 31 deletions tests/interchaintest/proposal/proposal.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
{
"title": "Enable Fee Abtraction",
"description": "Change params for enable fee abstraction",
"changes": [
{
"subspace": "feeabs",
"key": "NativeIbcedInOsmosis",
"value": "ibc/C053D637CCA2A2BA030E2C5EE1B28A16F71CCB0E45E8BE52766DC1B241B77878"
},
{
"subspace": "feeabs",
"key": "ChainName",
"value": "feeabs"
},
{
"subspace": "feeabs",
"key": "IbcTransferChannel",
"value": "channel-0"
},
{
"subspace": "feeabs",
"key": "IbcQueryIcqChannel",
"value": "channel-1"
},
{
"subspace": "feeabs",
"key": "OsmosisCrosschainSwapAddress",
"value": "osmo17p9rzwnnfxcjp32un9ug7yhhzgtkhvl9jfksztgw5uh69wac2pgs5yczr8"
}
],
"deposit": "5000000000stake"
}
"title": "Enable Fee Abtraction",
"description": "Change params for enable fee abstraction",
"changes": [
{
"subspace": "feeabs",
"key": "NativeIbcedInOsmosis",
"value": "ibc/C053D637CCA2A2BA030E2C5EE1B28A16F71CCB0E45E8BE52766DC1B241B77878"
},
{
"subspace": "feeabs",
"key": "ChainName",
"value": "feeabs"
},
{
"subspace": "feeabs",
"key": "IbcTransferChannel",
"value": "channel-0"
},
{
"subspace": "feeabs",
"key": "IbcQueryIcqChannel",
"value": "channel-1"
},
{
"subspace": "feeabs",
"key": "OsmosisCrosschainSwapAddress",
"value": "osmo17p9rzwnnfxcjp32un9ug7yhhzgtkhvl9jfksztgw5uh69wac2pgs5yczr8"
}
],
"deposit": "5000000000stake"
}
Loading

0 comments on commit 5cb267f

Please sign in to comment.