diff --git a/interchaintest/contracts/tokenfactory_core.wasm b/interchaintest/contracts/tokenfactory_core.wasm deleted file mode 100644 index 532d536..0000000 Binary files a/interchaintest/contracts/tokenfactory_core.wasm and /dev/null differ diff --git a/interchaintest/globalfee_test.go b/interchaintest/globalfee_test.go new file mode 100644 index 0000000..9b91609 --- /dev/null +++ b/interchaintest/globalfee_test.go @@ -0,0 +1,97 @@ +package interchaintest + +import ( + "context" + "fmt" + "testing" + + "github.com/cosmos/cosmos-sdk/crypto/keyring" + "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/testutil" + "github.com/stretchr/testify/require" + "go.uber.org/zap/zaptest" +) + +func TestGlobalFee(t *testing.T) { + cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*interchaintest.ChainSpec{ + &DefaultChainSpec, + }) + + chains, err := cf.Chains(t.Name()) + require.NoError(t, err) + + chain := chains[0].(*cosmos.CosmosChain) + + ic := interchaintest.NewInterchain(). + AddChain(chain) + + ctx := context.Background() + client, network := interchaintest.DockerSetup(t) + + require.NoError(t, ic.Build(ctx, nil, interchaintest.InterchainBuildOptions{ + TestName: t.Name(), + Client: client, + NetworkID: network, + SkipPathCreation: true, + })) + t.Cleanup(func() { + _ = ic.Close() + }) + + // faucet funds to the user + users := interchaintest.GetAndFundTestUsers(t, ctx, "default", DefaultGenesisAmt, chain, chain) + user := users[0] + toUser := users[1] + + // balance check + balance, err := chain.GetBalance(ctx, user.FormattedAddress(), Denom) + require.NoError(t, err) + require.True(t, balance.Equal(DefaultGenesisAmt), "user balance should be equal to genesis funds") + + // std := bankSendWithFees(t, ctx, juno, sender, receiver, "1"+nativeDenom, "0"+nativeDenom, 200000) + + token := fmt.Sprintf("1%s", Denom) + + // this should fail for not enough funds + // res, err := chain.GetNode().ExecTx(ctx, user.KeyName(), "bank", "send", user.KeyName(), toUser.FormattedAddress(), token, "--fees=0token") + + // none + res := bankSendWithFees(t, ctx, chain, user, toUser.FormattedAddress(), token, "0token", 200000) + require.Contains(t, res, "no fees were specified", res) + + // not enough + res = bankSendWithFees(t, ctx, chain, user, toUser.FormattedAddress(), token, "1token", 200000) + require.Contains(t, res, "insufficient fees", res) + + // wrong fee + res = bankSendWithFees(t, ctx, chain, user, toUser.FormattedAddress(), token, "1NOTTOKEN", 200000) + require.Contains(t, res, "this fee denom is not accepted", res) + + // success + res = bankSendWithFees(t, ctx, chain, user, toUser.FormattedAddress(), token, "500token", 200000) + require.Contains(t, res, "code: 0", res) +} + +// We ignore some of the safeguards interchaintest puts in place (such as gas prices and adjustment, since we are testing fees) +func bankSendWithFees(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, from ibc.Wallet, toAddr, coins, feeCoin string, gasAmt int64) string { + cmd := []string{chain.Config().Bin, "tx", "bank", "send", from.KeyName(), toAddr, coins, + "--node", chain.GetRPCAddress(), + "--home", chain.HomeDir(), + "--chain-id", chain.Config().ChainID, + "--gas", fmt.Sprintf("%d", gasAmt), + "--fees", feeCoin, + "--keyring-dir", chain.HomeDir(), + "--keyring-backend", keyring.BackendTest, + "-y", + } + stdout, _, err := chain.Exec(ctx, cmd, nil) + require.NoError(t, err) + + if err := testutil.WaitForBlocks(ctx, 2, chain); err != nil { + t.Fatal(err) + } + + return string(stdout) +} diff --git a/interchaintest/go.mod b/interchaintest/go.mod index c70b021..0c062a7 100644 --- a/interchaintest/go.mod +++ b/interchaintest/go.mod @@ -43,8 +43,6 @@ require ( github.com/ChainSafe/go-schnorrkel v1.0.0 // indirect 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.50.0 // indirect - github.com/CosmWasm/wasmvm v1.5.2 // indirect github.com/DataDog/datadog-go v3.2.0+incompatible // indirect github.com/DataDog/zstd v1.5.5 // indirect github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect @@ -91,7 +89,6 @@ require ( github.com/dgraph-io/badger/v2 v2.2007.4 // indirect github.com/dgraph-io/ristretto v0.1.1 // indirect github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect - github.com/distribution/reference v0.5.0 // indirect github.com/docker/distribution v2.8.2+incompatible // indirect github.com/docker/docker v24.0.7+incompatible // indirect github.com/docker/go-connections v0.5.0 // indirect @@ -243,7 +240,6 @@ require ( 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 gotest.tools/v3 v3.5.1 // indirect lukechampine.com/blake3 v1.2.1 // indirect diff --git a/interchaintest/go.sum b/interchaintest/go.sum index cedface..ef1e7ce 100644 --- a/interchaintest/go.sum +++ b/interchaintest/go.sum @@ -231,10 +231,6 @@ github.com/ChainSafe/go-schnorrkel v1.0.0 h1:3aDA67lAykLaG1y3AOjs88dMxC88PgUuHRr github.com/ChainSafe/go-schnorrkel v1.0.0/go.mod h1:dpzHYVxLZcp8pjlV+O+UR8K0Hp/z7vcchBSbMBEhCw4= github.com/ComposableFi/go-subkey/v2 v2.0.0-tm03420 h1:oknQF/iIhf5lVjbwjsVDzDByupRhga8nhA3NAmwyHDA= github.com/ComposableFi/go-subkey/v2 v2.0.0-tm03420/go.mod h1:KYkiMX5AbOlXXYfxkrYPrRPV6EbVUALTQh5ptUOJzu8= -github.com/CosmWasm/wasmd v0.50.0 h1:NVaGqCSTRfb9UTDHJwT6nQIWcb6VjlQl88iI+u1+qjE= -github.com/CosmWasm/wasmd v0.50.0/go.mod h1:UjmShW4l9YxaMytwJZ7IB7MWzHiynSZP3DdWrG0FRtk= -github.com/CosmWasm/wasmvm v1.5.2 h1:+pKB1Mz9GZVt1vadxB+EDdD1FOz3dMNjIKq/58/lrag= -github.com/CosmWasm/wasmvm v1.5.2/go.mod h1:Q0bSEtlktzh7W2hhEaifrFp1Erx11ckQZmjq8FLCyys= github.com/DataDog/datadog-go v3.2.0+incompatible h1:qSG2N4FghB1He/r2mFrWKCaL7dXCilEuNEeAn20fdD4= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= github.com/DataDog/zstd v1.5.5 h1:oWf5W7GtOLgp6bciQYDmhHHjdhYkALu6S/5Ni9ZgSvQ= @@ -432,8 +428,6 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 h1:fAjc9m62+UWV/WAFKLNi6ZS0675eEUC9y3AlwSbQu1Y= github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= -github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0= -github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= github.com/docker/distribution v2.8.2+incompatible h1:T3de5rq0dB1j30rp0sA2rER+m322EBzniBPB6ZIzuh8= github.com/docker/distribution v2.8.2+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= github.com/docker/docker v24.0.7+incompatible h1:Wo6l37AuwP3JaMnZa226lzVXGA3F9Ig1seQen0cKYlM= diff --git a/interchaintest/setup.go b/interchaintest/setup.go index 9f0623f..dac51d8 100644 --- a/interchaintest/setup.go +++ b/interchaintest/setup.go @@ -2,6 +2,10 @@ package interchaintest import ( sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + + globalfee "github.com/reecepbcups/globalfee/x/globalfee/types" + "github.com/strangelove-ventures/interchaintest/v8" "github.com/strangelove-ventures/interchaintest/v8/chain/cosmos" "github.com/strangelove-ventures/interchaintest/v8/ibc" @@ -17,17 +21,16 @@ var ( CosmosGovModuleAcc = "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn" - vals = 1 - fullNodes = 0 + NumberVals = 1 + NumberFullNodes = 0 + Denom = "token" + GlobalFeeGasPrices = "0.0025" DefaultGenesis = []cosmos.GenesisKV{ cosmos.NewGenesisKV("app_state.gov.params.voting_period", votingPeriod), cosmos.NewGenesisKV("app_state.gov.params.max_deposit_period", maxDepositPeriod), cosmos.NewGenesisKV("consensus.params.abci.vote_extensions_enable_height", "1"), - - // TODO: globalfee - // coin = sdk.NewDecCoinFromDec(cfg.Denom, sdk.NewDecWithPrec(25, 4)) // 0.002500000000000000 <- use must from string - // cosmos.NewGenesisKV("app_state.globalfee.params.minimum_gas_prices", sdk.DecCoins{coin}), + cosmos.NewGenesisKV("app_state.globalfee.params.minimum_gas_prices", sdk.DecCoins{sdk.NewDecCoinFromDec(Denom, sdkmath.LegacyMustNewDecFromStr(GlobalFeeGasPrices))}), } // `make local-image` @@ -44,8 +47,8 @@ var ( }, Bin: "globald", Bech32Prefix: "cosmos", - Denom: "token", - GasPrices: "0token", + Denom: Denom, + GasPrices: GlobalFeeGasPrices + Denom, GasAdjustment: 1.3, TrustingPeriod: "508h", NoHostMount: false, @@ -54,10 +57,21 @@ var ( } DefaultGenesisAmt = sdkmath.NewInt(10_000_000) + + DefaultChainSpec = interchaintest.ChainSpec{ + Name: LocalChainConfig.Name, + ChainName: LocalChainConfig.Name, + Version: LocalChainConfig.Images[0].Version, + ChainConfig: LocalChainConfig, + NumValidators: &NumberVals, + NumFullNodes: &NumberFullNodes, + } ) func AppEncoding() *sdktestutil.TestEncodingConfig { enc := cosmos.DefaultEncoding() - return enc + globalfee.RegisterInterfaces(enc.InterfaceRegistry) + + return &enc }