Skip to content

Commit

Permalink
add feepay test base
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed Oct 9, 2023
1 parent ab03d6c commit 1477880
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ ictest-pob: rm-testcache
ictest-drip: rm-testcache
cd interchaintest && go test -race -v -run TestJunoDrip .

ictest-feepay: rm-testcache
cd interchaintest && go test -race -v -run TestJunoFeePay .

rm-testcache:
go clean -testcache

Expand Down
1 change: 1 addition & 0 deletions interchaintest/helpers/cosmwasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keyring"
)


func SetupContract(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, keyname string, fileLoc string, message string) (codeId, contract string) {
codeId, err := chain.StoreContract(ctx, keyname, fileLoc)
if err != nil {
Expand Down
80 changes: 80 additions & 0 deletions interchaintest/helpers/feepay.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package helpers

import (
"context"
"fmt"
"testing"

"github.com/strangelove-ventures/interchaintest/v7/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v7/ibc"
"github.com/strangelove-ventures/interchaintest/v7/testutil"
"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/crypto/keyring"
)

func RegisterFeePay(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet, contract string, walletLimit uint) {
cmd := []string{
"junod", "tx", "feepay", "register", contract, fmt.Sprintf("%d", walletLimit),
"--node", chain.GetRPCAddress(),
"--home", chain.HomeDir(),
"--chain-id", chain.Config().ChainID,
"--fees", "500ujuno",
"--from", user.KeyName(),
"--keyring-dir", chain.HomeDir(),
"--keyring-backend", keyring.BackendTest,
"-y",
}
stdout, _, err := chain.Exec(ctx, cmd, nil)
require.NoError(t, err)

debugOutput(t, string(stdout))

err = testutil.WaitForBlocks(ctx, 2, chain)
require.NoError(t, err)
}

func FundFeePayContract(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet, contract string, amountCoin string) {
cmd := []string{
"junod", "tx", "feepay", "fund", contract, amountCoin,
"--node", chain.GetRPCAddress(),
"--home", chain.HomeDir(),
"--chain-id", chain.Config().ChainID,
"--fees", "500ujuno",
"--from", user.KeyName(),
"--keyring-dir", chain.HomeDir(),
"--keyring-backend", keyring.BackendTest,
"-y",
}
stdout, _, err := chain.Exec(ctx, cmd, nil)
require.NoError(t, err)

debugOutput(t, string(stdout))

err = testutil.WaitForBlocks(ctx, 2, chain)
require.NoError(t, err)
}

func UpdateFeePayWalletLimit(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet, contract string, newLimit uint64) {
cmd := []string{
"junod", "tx", "feepay", "update-wallet-limit", contract, fmt.Sprintf("%d", newLimit),
"--node", chain.GetRPCAddress(),
"--home", chain.HomeDir(),
"--chain-id", chain.Config().ChainID,
"--from", user.KeyName(),
"--keyring-dir", chain.HomeDir(),
"--keyring-backend", keyring.BackendTest,
"-y",
}
stdout, _, err := chain.Exec(ctx, cmd, nil)
require.NoError(t, err)

debugOutput(t, string(stdout))

err = testutil.WaitForBlocks(ctx, 2, chain)
require.NoError(t, err)
}

// TODO:
// {"fee_pay_contract":{"contract_address":"juno14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9skjuwg8","balance":"1000000","wallet_limit":"5"}}
// feepay contract juno14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9skjuwg8
79 changes: 79 additions & 0 deletions interchaintest/module_feepay_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package interchaintest

import (
"fmt"
"testing"

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

helpers "github.com/CosmosContracts/juno/tests/interchaintest/helpers"
)

// TestJunoFeePay
func TestJunoFeePay(t *testing.T) {
t.Parallel()

cfg := junoConfig
cfg.GasPrices = "0.0025ujuno"

// Base setup
chains := CreateChainWithCustomConfig(t, 1, 0, cfg)
ic, ctx, _, _ := BuildInitialChain(t, chains)

// Chains
juno := chains[0].(*cosmos.CosmosChain)

nativeDenom := juno.Config().Denom

// Users
users := interchaintest.GetAndFundTestUsers(t, ctx, "default", int64(10_000_000), juno, juno)
admin := users[0]
user := users[1]

// Upload & init contract payment to another address
codeId, err := juno.StoreContract(ctx, admin.KeyName(), "contracts/cw_template.wasm", "--fees", "50000ujuno")
if err != nil {
t.Fatal(err)
}

contractAddr, err := juno.InstantiateContract(ctx, admin.KeyName(), codeId, `{"count":0}`, true)
if err != nil {
t.Fatal(err)
}

// Register contract for 0 fee usage (x amount of times)
helpers.RegisterFeePay(t, ctx, juno, admin, contractAddr, 5)
helpers.FundFeePayContract(t, ctx, juno, admin, contractAddr, "1000000"+nativeDenom)

// execute against it from another account with enough fees (standard Tx)
txHash, err := juno.ExecuteContract(ctx, user.KeyName(), contractAddr, `{"increment":{}}`, "--fees", "500"+nativeDenom)
if err != nil {
// TODO:
t.Log(err)
}
fmt.Println("txHash", txHash)

// execute against it from another account and have the dev pay it
txHash, err = juno.ExecuteContract(ctx, user.KeyName(), contractAddr, `{"increment":{}}`, "--fees", "0"+nativeDenom)
if err != nil {
// TODO:
t.Log(err)
}
fmt.Println("txHash", txHash)

// validate their balance did not go down, and that the contract did infact increase +=1
// if balance, err := juno.GetBalance(ctx, feeRcvAddr, nativeDenom); err != nil {
// t.Fatal(err)
// } else if balance != 0 {
// t.Fatal("balance not 0")
// }

// wait blocks
testutil.WaitForBlocks(ctx, 200, juno)

t.Cleanup(func() {
_ = ic.Close()
})
}
2 changes: 2 additions & 0 deletions interchaintest/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
testutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
ibclocalhost "github.com/cosmos/ibc-go/v7/modules/light-clients/09-localhost"

feepaytypes "github.com/CosmosContracts/juno/v17/x/feepay/types"
feesharetypes "github.com/CosmosContracts/juno/v17/x/feeshare/types"
tokenfactorytypes "github.com/CosmosContracts/juno/v17/x/tokenfactory/types"
)
Expand Down Expand Up @@ -93,6 +94,7 @@ func junoEncoding() *testutil.TestEncodingConfig {
wasmtypes.RegisterInterfaces(cfg.InterfaceRegistry)
feesharetypes.RegisterInterfaces(cfg.InterfaceRegistry)
tokenfactorytypes.RegisterInterfaces(cfg.InterfaceRegistry)
feepaytypes.RegisterInterfaces(cfg.InterfaceRegistry)

return &cfg
}
Expand Down

0 comments on commit 1477880

Please sign in to comment.