Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
tuantran1702 committed May 30, 2024
1 parent 6b5479a commit 1d9b481
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 130 deletions.
5 changes: 5 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ import (

const appName = "FeeApp"

var (
_ runtime.AppI = (*FeeApp)(nil)
_ servertypes.Application = (*FeeApp)(nil)
)

// We pull these out so we can set them with LDFLAGS in the Makefile
var (
NodeDir = ".feeapp"
Expand Down
53 changes: 6 additions & 47 deletions tests/interchaintest/chain_start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ 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/testreporter"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest"
)

// TestStartFeeabs is a basic test to assert that spinning up a Feeabs network with 1 validator works properly.
Expand All @@ -17,50 +15,11 @@ func TestStartFeeabs(t *testing.T) {
t.Skip()
}

t.Parallel()

// Set up chains, users and channels
ctx := context.Background()

// Create chain factory with Feeabs
numVals := 1
numFullNodes := 1

cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*interchaintest.ChainSpec{
{
Name: "feeabs",
ChainConfig: feeabsConfig,
NumValidators: &numVals,
NumFullNodes: &numFullNodes,
},
})

// Get chains from the chain factory
chains, err := cf.Chains(t.Name())
require.NoError(t, err)

feeabs := chains[0].(*cosmos.CosmosChain)

// Relayer Factory
client, network := interchaintest.DockerSetup(t)

// Create a new Interchain object which describes the chains, relayers, and IBC connections we want to use
ic := interchaintest.NewInterchain().AddChain(feeabs)

rep := testreporter.NewNopReporter()
eRep := rep.RelayerExecReporter(t)

err = ic.Build(ctx, eRep, interchaintest.InterchainBuildOptions{
TestName: t.Name(),
Client: client,
NetworkID: network,
SkipPathCreation: true,

// 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(),
})
chains, _, _ := SetupChain(t, ctx)
feeabs, _, _ := chains[0].(*cosmos.CosmosChain), chains[1].(*cosmos.CosmosChain), chains[2].(*cosmos.CosmosChain)
a, err := feeabs.AuthQueryModuleAccounts(ctx)
require.NoError(t, err)

t.Cleanup(func() {
_ = ic.Close()
})
fmt.Println("module accounts", a)
}
4 changes: 2 additions & 2 deletions tests/interchaintest/feeabs/osmosis.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func CreatePool(c *cosmos.CosmosChain, ctx context.Context, keyName string, params cosmos.OsmosisPoolParams) (string, error) {
tn := getFullNode(c)
tn := c.GetNode()
poolbz, err := json.Marshal(params)
if err != nil {
return "", err
Expand Down Expand Up @@ -50,7 +50,7 @@ func CreatePool(c *cosmos.CosmosChain, ctx context.Context, keyName string, para
func SetupProposePFM(c *cosmos.CosmosChain, ctx context.Context, keyName string, contractAddress string, message string, ibcdenom string) (txHash string, err error) {
oneCoin := strconv.FormatInt(1, 10)
amount := oneCoin + ibcdenom
tn := getFullNode(c)
tn := c.GetNode()
return tn.ExecTx(ctx, keyName,
"wasm", "execute", contractAddress, message, "--amount", amount, "--gas", "1000000",
)
Expand Down
13 changes: 7 additions & 6 deletions tests/interchaintest/feeabs/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func getTransaction(ctx client.Context, txHash string) (*types.TxResponse, error
}

func CrossChainSwap(c *cosmos.CosmosChain, ctx context.Context, keyName string, ibcDenom string) (tx ibc.Tx, _ error) {
tn := getFullNode(c)
tn := c.GetNode()

txHash, err := tn.ExecTx(ctx, keyName,
"feeabs", "swap", ibcDenom,
Expand Down Expand Up @@ -103,7 +103,7 @@ func CrossChainSwap(c *cosmos.CosmosChain, ctx context.Context, keyName string,
}

func AddHostZoneProposal(c *cosmos.CosmosChain, ctx context.Context, keyName string, fileLocation string) (string, error) {
tn := getFullNode(c)
tn := c.GetNode()
dat, err := os.ReadFile(fileLocation)
if err != nil {
return "", fmt.Errorf("failed to read file: %w", err)
Expand All @@ -127,7 +127,7 @@ func AddHostZoneProposal(c *cosmos.CosmosChain, ctx context.Context, keyName str
}

func DeleteHostZoneProposal(c *cosmos.CosmosChain, ctx context.Context, keyName string, fileLocation string) (string, error) {
tn := getFullNode(c)
tn := c.GetNode()
dat, err := os.ReadFile(fileLocation)
if err != nil {
return "", fmt.Errorf("failed to read file: %w", err)
Expand All @@ -151,7 +151,7 @@ func DeleteHostZoneProposal(c *cosmos.CosmosChain, ctx context.Context, keyName
}

func SetHostZoneProposal(c *cosmos.CosmosChain, ctx context.Context, keyName string, fileLocation string) (string, error) {
tn := getFullNode(c)
tn := c.GetNode()
dat, err := os.ReadFile(fileLocation)
if err != nil {
return "", fmt.Errorf("failed to read file: %w", err)
Expand All @@ -175,7 +175,7 @@ func SetHostZoneProposal(c *cosmos.CosmosChain, ctx context.Context, keyName str
}

func ParamChangeProposal(c *cosmos.CosmosChain, ctx context.Context, keyName string, prop *paramsutils.ParamChangeProposalJSON) (tx cosmos.TxProposal, _ error) {
tn := getFullNode(c)
tn := c.GetNode()
content, err := json.Marshal(prop)
if err != nil {
return tx, err
Expand Down Expand Up @@ -206,7 +206,8 @@ func ParamChangeProposal(c *cosmos.CosmosChain, ctx context.Context, keyName str
}

func txProposal(c *cosmos.CosmosChain, txHash string) (tx cosmos.TxProposal, _ error) {
fn := getFullNode(c)
fn := c.GetNode()

txResp, err := getTransaction(fn.CliContext(), txHash)
if err != nil {
return tx, fmt.Errorf("failed to get transaction %s: %w", txHash, err)
Expand Down
10 changes: 5 additions & 5 deletions tests/interchaintest/feeabs/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func QueryHostZoneConfigWithDenom(c *cosmos.CosmosChain, ctx context.Context, denom string) (*HostChainFeeAbsConfigResponse, error) {
tn := getFullNode(c)
tn := c.GetNode()
cmd := []string{"feeabs", "host-chain-config", denom}
stdout, _, err := tn.ExecQuery(ctx, cmd...)
if err != nil {
Expand All @@ -29,7 +29,7 @@ func QueryHostZoneConfigWithDenom(c *cosmos.CosmosChain, ctx context.Context, de
}

func QueryAllHostZoneConfig(c *cosmos.CosmosChain, ctx context.Context) (*AllQueryHostChainConfigResponse, error) {
tn := getFullNode(c)
tn := c.GetNode()
cmd := []string{"feeabs", "all-host-chain-config"}
stdout, _, err := tn.ExecQuery(ctx, cmd...)
if err != nil {
Expand All @@ -46,7 +46,7 @@ func QueryAllHostZoneConfig(c *cosmos.CosmosChain, ctx context.Context) (*AllQue
}

func QueryModuleAccountBalances(c *cosmos.CosmosChain, ctx context.Context) (*feeabstypes.QueryFeeabsModuleBalacesResponse, error) {
tn := getFullNode(c)
tn := c.GetNode()
cmd := []string{"feeabs", "module-balances"}
stdout, _, err := tn.ExecQuery(ctx, cmd...)
if err != nil {
Expand All @@ -63,7 +63,7 @@ func QueryModuleAccountBalances(c *cosmos.CosmosChain, ctx context.Context) (*fe

// QueryOsmosisArithmeticTwap queries the arithmetic twap of ibc denom stored in fee abstraction module
func QueryOsmosisArithmeticTwap(c *cosmos.CosmosChain, ctx context.Context, ibcDenom string) (*feeabstypes.QueryOsmosisArithmeticTwapResponse, error) {
node := getFullNode(c)
node := c.GetNode()
cmd := []string{"feeabs", "osmo-arithmetic-twap", ibcDenom}
stdout, _, err := node.ExecQuery(ctx, cmd...)
if err != nil {
Expand All @@ -79,7 +79,7 @@ func QueryOsmosisArithmeticTwap(c *cosmos.CosmosChain, ctx context.Context, ibcD

// QueryOsmosisArithmeticTwapOsmosis queries the arithmetic twap of a pool on osmosis chain
func QueryOsmosisArithmeticTwapOsmosis(c *cosmos.CosmosChain, ctx context.Context, poolID, ibcDenom string) (*feeabstypes.QueryOsmosisArithmeticTwapResponse, error) {
node := getFullNode(c)
node := c.GetNode()
currentEpoch := time.Now().Unix()

cmd := []string{"twap", "arithmetic", poolID, ibcDenom, fmt.Sprintf("%d", currentEpoch-20), fmt.Sprintf("%d", currentEpoch-10)}
Expand Down
24 changes: 12 additions & 12 deletions tests/interchaintest/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ go 1.22.3
require (
cosmossdk.io/math v1.3.0
github.com/avast/retry-go/v4 v4.5.1
github.com/cometbft/cometbft v0.38.7
github.com/cosmos/cosmos-sdk v0.50.6
github.com/cosmos/ibc-go/v8 v8.2.1
github.com/icza/dyno v0.0.0-20220812133438-f0b6f8a18845
github.com/osmosis-labs/fee-abstraction/v8 v8.0.0-20240320155239-bb99fef4f806
github.com/osmosis-labs/osmosis/v25 v25.0.0-20240528204424-d2c4a9666dc0
github.com/strangelove-ventures/interchaintest/v8 v8.2.0
github.com/strangelove-ventures/interchaintest/v8 v8.3.0
github.com/stretchr/testify v1.9.0
go.uber.org/zap v1.27.0
)
Expand All @@ -28,6 +29,7 @@ require (
cosmossdk.io/errors v1.0.1 // indirect
cosmossdk.io/log v1.3.1 // indirect
cosmossdk.io/store v1.1.0 // indirect
cosmossdk.io/x/evidence v0.1.1 // indirect
cosmossdk.io/x/feegrant v0.1.0 // indirect
cosmossdk.io/x/tx v0.13.3 // indirect
cosmossdk.io/x/upgrade v0.1.2 // indirect
Expand Down Expand Up @@ -60,7 +62,6 @@ require (
github.com/cockroachdb/pebble v1.1.0 // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/cometbft/cometbft v0.38.7 // indirect
github.com/cometbft/cometbft-db v0.12.0 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/cosmos-db v1.0.2 // indirect
Expand All @@ -71,6 +72,7 @@ require (
github.com/cosmos/iavl v1.1.3 // indirect
github.com/cosmos/ibc-go/modules/capability v1.0.0 // indirect
github.com/cosmos/ics23/go v0.10.0 // indirect
github.com/cosmos/interchain-security/v5 v5.0.0-alpha1.0.20240424193412-7cd900ad2a74 // indirect
github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect
github.com/danieljoos/wincred v1.2.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
Expand All @@ -90,7 +92,7 @@ require (
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/dvsekhvalnov/jose2go v1.6.0 // indirect
github.com/emicklei/dot v1.6.1 // indirect
github.com/ethereum/go-ethereum v1.13.14 // indirect
github.com/ethereum/go-ethereum v1.13.15 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
Expand Down Expand Up @@ -133,6 +135,7 @@ require (
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/hdevalence/ed25519consensus v0.1.0 // indirect
Expand All @@ -144,7 +147,6 @@ require (
github.com/ipfs/go-cid v0.4.1 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/klauspost/compress v1.17.7 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/kr/pretty v0.3.1 // indirect
Expand Down Expand Up @@ -173,6 +175,7 @@ require (
github.com/multiformats/go-multicodec v0.9.0 // indirect
github.com/multiformats/go-multihash v0.2.3 // indirect
github.com/multiformats/go-varint v0.0.7 // indirect
github.com/ncruces/go-strftime v0.1.9 // indirect
github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
Expand Down Expand Up @@ -246,16 +249,13 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.5.1 // indirect
lukechampine.com/blake3 v1.2.1 // indirect
lukechampine.com/uint128 v1.2.0 // indirect
modernc.org/cc/v3 v3.40.0 // indirect
modernc.org/ccgo/v3 v3.16.13 // indirect
modernc.org/libc v1.29.0 // indirect
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 // indirect
modernc.org/libc v1.41.0 // indirect
modernc.org/mathutil v1.6.0 // indirect
modernc.org/memory v1.7.2 // indirect
modernc.org/opt v0.1.3 // indirect
modernc.org/sqlite v1.28.0 // indirect
modernc.org/strutil v1.1.3 // indirect
modernc.org/token v1.0.1 // indirect
modernc.org/sqlite v1.29.5 // indirect
modernc.org/strutil v1.2.0 // indirect
modernc.org/token v1.1.0 // indirect
nhooyr.io/websocket v1.8.10 // indirect
pgregory.net/rapid v1.1.0 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
Expand Down
Loading

0 comments on commit 1d9b481

Please sign in to comment.