Skip to content

Commit

Permalink
update pfm and add ibchook test
Browse files Browse the repository at this point in the history
  • Loading branch information
hoank101 committed May 4, 2024
1 parent 9edc79b commit 5426ae3
Show file tree
Hide file tree
Showing 11 changed files with 514 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,8 @@ func NewComposableApp(
icqModule,
ibcHooksModule,
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)),
wasm08.NewAppModule(app.Wasm08Keeper),
wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)),
pfmModule,
transfermiddlewareModule,
txBoundaryModule,
Expand Down
4 changes: 2 additions & 2 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ func (appKeepers *AppKeepers) initParamsKeeper(appCodec codec.BinaryCodec, legac
keyTable := ibcclienttypes.ParamKeyTable()
keyTable.RegisterParamSet(&ibcconnectiontypes.Params{})
paramsKeeper.Subspace(ibcexported.ModuleName).WithKeyTable(keyTable)
paramsKeeper.Subspace(ibctransfertypes.ModuleName).WithKeyTable(ibctransfertypes.ParamKeyTable())
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(icacontrollertypes.SubModuleName).WithKeyTable(icacontrollertypes.ParamKeyTable())
paramsKeeper.Subspace(icahosttypes.SubModuleName).WithKeyTable(icahosttypes.ParamKeyTable())

Expand All @@ -583,7 +583,7 @@ func (appKeepers *AppKeepers) initParamsKeeper(appCodec codec.BinaryCodec, legac
paramsKeeper.Subspace(icqtypes.ModuleName).WithKeyTable(icqtypes.ParamKeyTable())
paramsKeeper.Subspace(wasm08types.ModuleName)
paramsKeeper.Subspace(wasmtypes.ModuleName)
paramsKeeper.Subspace(transfermiddlewaretypes.ModuleName).WithKeyTable(transfermiddlewaretypes.ParamKeyTable())
paramsKeeper.Subspace(transfermiddlewaretypes.ModuleName)
paramsKeeper.Subspace(stakingmiddlewaretypes.ModuleName)
paramsKeeper.Subspace(ibctransfermiddlewaretypes.ModuleName)

Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,9 @@ replace (
github.com/CosmWasm/wasmvm => github.com/CosmWasm/wasmvm v1.5.2
github.com/cosmos/cosmos-sdk => github.com/notional-labs/cosmos-sdk v0.50.5-patch-validators-trim-tag

// github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8 => github.com/notional-labs/ibc-apps/middleware/packet-forward-middleware/v8 v8.0.0-20240504082418-e4d8c9cb7044
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8 => github.com/notional-labs/ibc-apps/middleware/packet-forward-middleware/v8 v8.0.0-20240503092956-16204721528b
// github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8 => github.com/notional-labs/ibc-apps/middleware/packet-forward-middleware/v8 v8.0.0-20240501060940-654293260efb
github.com/cosmos/ibc-go/v8 => github.com/notional-labs/ibc-go/v8 v8.0.0-20240504081627-8ee51f5d7278

// use cosmos-compatible protobufs
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -828,8 +828,6 @@ github.com/cosmos/ibc-go/modules/capability v1.0.0 h1:r/l++byFtn7jHYa09zlAdSeevo
github.com/cosmos/ibc-go/modules/capability v1.0.0/go.mod h1:D81ZxzjZAe0ZO5ambnvn1qedsFQ8lOwtqicG6liLBco=
github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.1.1-0.20231213092650-57fcdb9a9a9d h1:F4mhR61RZU4KJ38n5CeZrnNINU/KxMfP1sKfk5fTlHA=
github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.1.1-0.20231213092650-57fcdb9a9a9d/go.mod h1:u2FXNcSxzzn5IwjWBA51HKMwiYMRK6/G35VmSJULhP0=
github.com/cosmos/ibc-go/v8 v8.2.1 h1:MTsnZZjxvGD4Fv5pYyx5UkELafSX0rlPt6IfsE2BpTQ=
github.com/cosmos/ibc-go/v8 v8.2.1/go.mod h1:wj3qx75iC/XNnsMqbPDCIGs0G6Y3E/lo3bdqCyoCy+8=
github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM=
github.com/cosmos/ics23/go v0.10.0/go.mod h1:ZfJSmng/TBNTBkFemHHHj5YY7VAU/MBU980F4VU1NG0=
github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76 h1:DdzS1m6o/pCqeZ8VOAit/gyATedRgjvkVI+UCrLpyuU=
Expand Down Expand Up @@ -1389,6 +1387,8 @@ github.com/notional-labs/cosmos-sdk v0.50.5-patch-validators-trim-tag h1:lnMn2O2
github.com/notional-labs/cosmos-sdk v0.50.5-patch-validators-trim-tag/go.mod h1:oV/k6GJgXV9QPoM2fsYDPPsyPBgQbdotv532O6Mz1OQ=
github.com/notional-labs/ibc-apps/middleware/packet-forward-middleware/v8 v8.0.0-20240503092956-16204721528b h1:4T8dAAY8Sou9ib7t+5NW8W+WfCz2PKTG5tubmun9Sko=
github.com/notional-labs/ibc-apps/middleware/packet-forward-middleware/v8 v8.0.0-20240503092956-16204721528b/go.mod h1:dgFaRgM0YjzSBQ8zPLmBaQzMul8eNYPHu5EN84t5rYY=
github.com/notional-labs/ibc-go/v8 v8.0.0-20240504081627-8ee51f5d7278 h1:/NOkBq9mYJIGHWKEYbz2qOSQETw6hBPGzS4/64ZcUsk=
github.com/notional-labs/ibc-go/v8 v8.0.0-20240504081627-8ee51f5d7278/go.mod h1:wj3qx75iC/XNnsMqbPDCIGs0G6Y3E/lo3bdqCyoCy+8=
github.com/nunnatsa/ginkgolinter v0.9.0 h1:Sm0zX5QfjJzkeCjEp+t6d3Ha0jwvoDjleP9XCsrEzOA=
github.com/nunnatsa/ginkgolinter v0.9.0/go.mod h1:FHaMLURXP7qImeH6bvxWJUpyH+2tuqe5j4rW1gxJRmI=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
Expand Down
Binary file not shown.
7 changes: 4 additions & 3 deletions tests/interchaintest/forward_timeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package interchaintest
import (
"context"
"encoding/json"
sdk "github.com/cosmos/cosmos-sdk/types"
"testing"
"time"

Expand Down Expand Up @@ -155,9 +156,9 @@ func TestTimeoutOnForward(t *testing.T) {
secondHopIBCDenom := secondHopDenomTrace.IBCDenom()
thirdHopIBCDenom := thirdHopDenomTrace.IBCDenom()

firstHopEscrowAccount := transfertypes.GetEscrowAddress(abChan.PortID, abChan.ChannelID).String()
secondHopEscrowAccount := transfertypes.GetEscrowAddress(bcChan.PortID, bcChan.ChannelID).String()
thirdHopEscrowAccount := transfertypes.GetEscrowAddress(cdChan.PortID, abChan.ChannelID).String()
firstHopEscrowAccount := sdk.MustBech32ifyAddressBytes(chainA.Config().Bech32Prefix, transfertypes.GetEscrowAddress(abChan.PortID, abChan.ChannelID))
secondHopEscrowAccount := sdk.MustBech32ifyAddressBytes(chainB.Config().Bech32Prefix, transfertypes.GetEscrowAddress(bcChan.PortID, bcChan.ChannelID))
thirdHopEscrowAccount := sdk.MustBech32ifyAddressBytes(chainC.Config().Bech32Prefix, transfertypes.GetEscrowAddress(cdChan.PortID, abChan.ChannelID))

zeroBal := math.ZeroInt()
transferAmount := math.NewInt(100_000)
Expand Down
176 changes: 176 additions & 0 deletions tests/interchaintest/helpers/cosmwasm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
package helpers

import (
"context"
"encoding/json"
"testing"

"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"

sdk "github.com/cosmos/cosmos-sdk/types"

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

func SmartQueryString(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, contractAddr, queryMsg string, res interface{}) error {
var jsonMap map[string]interface{}
if err := json.Unmarshal([]byte(queryMsg), &jsonMap); err != nil {
t.Fatal(err)
}
err := chain.QueryContract(ctx, contractAddr, jsonMap, &res)
return err
}

func StoreContract(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, keyname string, fileLoc string) (codeId string) {
codeId, err := chain.StoreContract(ctx, keyname, fileLoc)
if err != nil {
t.Fatal(err)
}
return codeId
}

func SetupContract(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, keyname string, fileLoc string, message string, extraFlags ...string) (codeId, contract string) {
codeId = StoreContract(t, ctx, chain, keyname, fileLoc)

needsNoAdminFlag := true
// if extraFlags contains "--admin", switch to false
for _, flag := range extraFlags {
if flag == "--admin" {
needsNoAdminFlag = false
}
}

contractAddr, err := chain.InstantiateContract(ctx, keyname, codeId, message, needsNoAdminFlag, extraFlags...)
if err != nil {
t.Fatal(err)
}

return codeId, contractAddr
}

func MigrateContract(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, keyname string, contractAddr string, fileLoc string, message string) (codeId, contract string) {
codeId, err := chain.StoreContract(ctx, keyname, fileLoc)
if err != nil {
t.Fatal(err)
}

// Execute migrate tx
cmd := []string{
"junod", "tx", "wasm", "migrate", contractAddr, codeId, message,
"--node", chain.GetRPCAddress(),
"--home", chain.HomeDir(),
"--chain-id", chain.Config().ChainID,
"--from", keyname,
"--gas", "500000",
"--keyring-dir", chain.HomeDir(),
"--keyring-backend", keyring.BackendTest,
"-y",
}

stdout, _, err := chain.Exec(ctx, cmd, nil)
require.NoError(t, err)

debugOutput(t, string(stdout))

if err := testutil.WaitForBlocks(ctx, 2, chain); err != nil {
t.Fatal(err)
}

return codeId, contractAddr
}

func ExecuteMsgWithAmount(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet, contractAddr, amount, message string) {
// amount is #utoken

// There has to be a way to do this in ictest?
cmd := []string{
"junod", "tx", "wasm", "execute", contractAddr, message,
"--node", chain.GetRPCAddress(),
"--home", chain.HomeDir(),
"--chain-id", chain.Config().ChainID,
"--from", user.KeyName(),
"--gas", "500000",
"--amount", amount,
"--keyring-dir", chain.HomeDir(),
"--keyring-backend", keyring.BackendTest,
"-y",
}
stdout, _, err := chain.Exec(ctx, cmd, nil)
require.NoError(t, err)

debugOutput(t, string(stdout))

if err := testutil.WaitForBlocks(ctx, 2, chain); err != nil {
t.Fatal(err)
}
}

func ExecuteMsgWithFee(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet, contractAddr, amount, feeCoin, message string) {
// amount is #utoken

// There has to be a way to do this in ictest?
cmd := []string{
"junod", "tx", "wasm", "execute", contractAddr, message,
"--node", chain.GetRPCAddress(),
"--home", chain.HomeDir(),
"--chain-id", chain.Config().ChainID,
"--from", user.KeyName(),
"--gas", "500000",
"--fees", feeCoin,
"--keyring-dir", chain.HomeDir(),
"--keyring-backend", keyring.BackendTest,
"-y",
}

if amount != "" {
cmd = append(cmd, "--amount", amount)
}

stdout, _, err := chain.Exec(ctx, cmd, nil)
require.NoError(t, err)

debugOutput(t, string(stdout))

if err := testutil.WaitForBlocks(ctx, 2, chain); err != nil {
t.Fatal(err)
}
}

func ExecuteMsgWithFeeReturn(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet, contractAddr, amount, feeCoin, message string) (*sdk.TxResponse, error) {
// amount is #utoken

// There has to be a way to do this in ictest? (there is, use node.ExecTx)
cmd := []string{
"wasm", "execute", contractAddr, message,
"--output", "json",
"--node", chain.GetRPCAddress(),
"--home", chain.HomeDir(),
"--gas", "500000",
"--fees", feeCoin,
"--keyring-dir", chain.HomeDir(),
}

if amount != "" {
cmd = append(cmd, "--amount", amount)
}

node := chain.GetNode()

txHash, err := node.ExecTx(ctx, user.KeyName(), cmd...)
if err != nil {
return nil, err
}

// convert stdout into a TxResponse
txRes, err := chain.GetTransaction(txHash)
return txRes, err
}

func debugOutput(t *testing.T, stdout string) {
if true {
t.Log(stdout)
}
}
41 changes: 41 additions & 0 deletions tests/interchaintest/helpers/ibchooks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package helpers

import (
"context"
"strings"
"testing"

"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
"github.com/stretchr/testify/require"
)

func GetIBCHooksUserAddress(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, channel, uaddr string) string {
// picad q ibchooks wasm-sender channel-0 "contractAddr" --node http://localhost:26657
cmd := []string{
"picad", "query", "ibchooks", "wasm-sender", channel, uaddr,
"--node", chain.GetRPCAddress(),
"--chain-id", chain.Config().ChainID,
"--output", "json",
}

// This query does not return a type, just prints the string.
stdout, _, err := chain.Exec(ctx, cmd, nil)
require.NoError(t, err)

address := strings.Replace(string(stdout), "\n", "", -1)
return address
}

func GetIBCHookTotalFunds(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, contract string, uaddr string) GetTotalFundsResponse {
var res GetTotalFundsResponse
err := chain.QueryContract(ctx, contract, QueryMsg{GetTotalFunds: &GetTotalFundsQuery{Addr: uaddr}}, &res)
require.NoError(t, err)
return res
}

func GetIBCHookCount(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, contract string, uaddr string) GetCountResponse {
var res GetCountResponse
err := chain.QueryContract(ctx, contract, QueryMsg{GetCount: &GetCountQuery{Addr: uaddr}}, &res)
require.NoError(t, err)
return res
}
95 changes: 95 additions & 0 deletions tests/interchaintest/helpers/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package helpers

import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

// Go based data types for querying on the contract.
// Execute types are not needed here. We just use strings. Could add though in the future and to_string it

// EntryPoint
type QueryMsg struct {
// Tokenfactory Core
GetConfig *struct{} `json:"get_config,omitempty"`
GetBalance *GetBalanceQuery `json:"get_balance,omitempty"`
GetAllBalances *GetAllBalancesQuery `json:"get_all_balances,omitempty"`

// Unity Contract
GetWithdrawalReadyTime *struct{} `json:"get_withdrawal_ready_time,omitempty"`

// IBCHooks
GetCount *GetCountQuery `json:"get_count,omitempty"`
GetTotalFunds *GetTotalFundsQuery `json:"get_total_funds,omitempty"`
}

type GetAllBalancesQuery struct {
Address string `json:"address"`
}
type GetAllBalancesResponse struct {
// or is it wasm Coin type?
Data []sdk.Coin `json:"data"`
}

type GetBalanceQuery struct {
// {"get_balance":{"address":"juno1...","denom":"factory/juno1.../RcqfWz"}}
Address string `json:"address"`
Denom string `json:"denom"`
}
type GetBalanceResponse struct {
// or is it wasm Coin type?
Data sdk.Coin `json:"data"`
}

type WithdrawalTimestampResponse struct {
// {"data":{"withdrawal_ready_timestamp":"1686146048614053435"}}
Data *WithdrawalTimestampObj `json:"data"`
}
type WithdrawalTimestampObj struct {
WithdrawalReadyTimestamp string `json:"withdrawal_ready_timestamp"`
}

type GetTotalFundsQuery struct {
// {"get_total_funds":{"addr":"juno1..."}}
Addr string `json:"addr"`
}
type GetTotalFundsResponse struct {
// {"data":{"total_funds":[{"denom":"ibc/04F5F501207C3626A2C14BFEF654D51C2E0B8F7CA578AB8ED272A66FE4E48097","amount":"1"}]}}
Data *GetTotalFundsObj `json:"data"`
}
type GetTotalFundsObj struct {
TotalFunds []WasmCoin `json:"total_funds"`
}

type WasmCoin struct {
Denom string `json:"denom"`
Amount string `json:"amount"`
}

type GetCountQuery struct {
// {"get_total_funds":{"addr":"juno1..."}}
Addr string `json:"addr"`
}
type GetCountResponse struct {
// {"data":{"count":0}}
Data *GetCountObj `json:"data"`
}
type GetCountObj struct {
Count int64 `json:"count"`
}

type ClockContractResponse struct {
Data *ClockContractObj `json:"data"`
}
type ClockContractObj struct {
Val uint32 `json:"val"`
}

type GetCwHooksDelegationResponse struct {
// {"data":{"validator_address":"%s","delegator_address":"%s","shares":"%s"}}
Data *GetDelegationObj `json:"data"`
}
type GetDelegationObj struct {
ValidatorAddress string `json:"validator_address"`
DelegatorAddress string `json:"delegator_address"`
Shares string `json:"shares"`
}
Loading

0 comments on commit 5426ae3

Please sign in to comment.