Skip to content

Commit

Permalink
fix: wasmbinding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Lockwarr committed Nov 11, 2024
1 parent 10689fd commit 4d3cb47
Show file tree
Hide file tree
Showing 3 changed files with 282 additions and 397 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ require (
cosmossdk.io/collections v0.4.0 // indirect
cosmossdk.io/depinject v1.0.0 // indirect
cosmossdk.io/x/circuit v0.1.1 // indirect
cosmossdk.io/x/nft v0.1.1 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.2 // indirect
Expand Down Expand Up @@ -84,6 +85,7 @@ require (
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/iavl v1.2.0 // indirect
github.com/cosmos/ibc-go/modules/apps/callbacks v0.2.1-0.20231113120333-342c00b0f8bd // indirect
github.com/cosmos/ics23/go v0.11.0 // indirect
github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect
github.com/creachadair/atomicfile v0.3.3 // indirect
Expand Down
76 changes: 41 additions & 35 deletions testutil/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import (
"encoding/json"
"fmt"
"os"
"time"

"cosmossdk.io/log"
"cosmossdk.io/math"

icacontrollerkeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/keeper"
icacontrollertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types"
icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types"
"github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
ibctesting "github.com/cosmos/ibc-go/v8/testing"
Expand All @@ -27,8 +31,6 @@ import (

"github.com/Nolus-Protocol/nolus-core/app"
"github.com/Nolus-Protocol/nolus-core/app/params"

ictxstypes "github.com/Nolus-Protocol/nolus-core/x/interchaintxs/types"
)

var (
Expand All @@ -37,7 +39,7 @@ var (

TestInterchainID = "owner_id"

Connection = "connection-0"
Connection = "connection-1"

// TestVersion defines a reusable interchainaccounts version string for testing purposes.
TestVersion = string(icatypes.ModuleCdc.MustMarshalJSON(&icatypes.Metadata{
Expand Down Expand Up @@ -65,7 +67,7 @@ type IBCConnectionTestSuite struct {
ChainA *ibctesting.TestChain
ChainB *ibctesting.TestChain

Path *ibctesting.Path
// Path *ibctesting.Path
TransferPath *ibctesting.Path
}

Expand All @@ -77,20 +79,7 @@ func (suite *IBCConnectionTestSuite) SetupTest() {
suite.ChainA = suite.Coordinator.GetChain(ibctesting.GetChainID(1))
suite.ChainB = suite.Coordinator.GetChain(ibctesting.GetChainID(2))

// move chains to the next block
suite.ChainA.NextBlock()
suite.ChainB.NextBlock()

// path := ibctesting.NewPath(suite.ChainA, suite.ChainB) // clientID, connectionID, channelID empty
// suite.Coordinator.Setup(path) // clientID, connectionID, channelID filled
// suite.Require().Equal("07-tendermint-0", path.EndpointA.ClientID)
// suite.Require().Equal("connection-0", path.EndpointA.ClientID)
// suite.Require().Equal("channel-0", path.EndpointA.ClientID)

// suite.Path = NewICAPath(suite.ChainA, suite.ChainB)

suite.ConfigureTransferChannel()
// suite.Coordinator.Setup(suite.Path)
}

func (suite *IBCConnectionTestSuite) ConfigureTransferChannel() {
Expand Down Expand Up @@ -130,28 +119,42 @@ func (suite *IBCConnectionTestSuite) InstantiateTestContract(ctx sdk.Context, fu
return addr
}

func NewICAPath(chainA, chainB *ibctesting.TestChain) *ibctesting.Path {
func calculateTrustPeriod(unbondingPeriod time.Duration, defaultTrustPeriodFraction string) (time.Duration, error) {
trustDec, err := math.LegacyNewDecFromStr(defaultTrustPeriodFraction)
if err != nil {
return time.Duration(0), err
}
trustPeriod := time.Duration(trustDec.MulInt64(unbondingPeriod.Nanoseconds()).TruncateInt64())

return trustPeriod, nil
}

func NewICAPath(chainA, chainB *ibctesting.TestChain, icaowner string) *ibctesting.Path {
path := ibctesting.NewPath(chainA, chainB)
path.EndpointA.Counterparty = path.EndpointB
path.EndpointB.Counterparty = path.EndpointA

path.EndpointA.ChannelConfig.PortID = icatypes.HostPortID
path.EndpointA.ChannelConfig.PortID = icatypes.ControllerPortPrefix + icaowner
path.EndpointB.ChannelConfig.PortID = icatypes.HostPortID
path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED
path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED
path.EndpointA.ChannelConfig.Order = channeltypes.UNORDERED
path.EndpointB.ChannelConfig.Order = channeltypes.UNORDERED
path.EndpointA.ChannelConfig.Version = TestVersion
path.EndpointB.ChannelConfig.Version = TestVersion

path.EndpointA.ClientConfig.(*ibctesting.TendermintConfig).UnbondingPeriod = 3600000000000
path.EndpointA.ClientConfig.(*ibctesting.TendermintConfig).TrustingPeriod = 1200000000000
unbondingPeriodA := time.Duration(3600000000000)
unbondingPeriodB := time.Duration(3600000000000)
trustingPeriodFraction := "0.1"

path.EndpointA.ClientConfig.(*ibctesting.TendermintConfig).UnbondingPeriod = unbondingPeriodA
path.EndpointA.ClientConfig.(*ibctesting.TendermintConfig).TrustingPeriod, _ = calculateTrustPeriod(unbondingPeriodA, trustingPeriodFraction)

path.EndpointB.ClientConfig.(*ibctesting.TendermintConfig).UnbondingPeriod = 3600000000000
path.EndpointB.ClientConfig.(*ibctesting.TendermintConfig).TrustingPeriod = 1200000000000
path.EndpointB.ClientConfig.(*ibctesting.TendermintConfig).UnbondingPeriod = unbondingPeriodB
path.EndpointB.ClientConfig.(*ibctesting.TendermintConfig).TrustingPeriod, _ = calculateTrustPeriod(unbondingPeriodB, trustingPeriodFraction)
return path
}

// SetupICAPath invokes the InterchainAccounts entrypoint and subsequent channel handshake handlers.
func SetupICAPath(path *ibctesting.Path, owner string) error {
func (suite *IBCConnectionTestSuite) SetupICAPath(path *ibctesting.Path, owner string) error {
if err := RegisterInterchainAccount(path.EndpointA, owner); err != nil {
return err
}
Expand All @@ -169,32 +172,35 @@ func SetupICAPath(path *ibctesting.Path, owner string) error {

// RegisterInterchainAccount is a helper function for starting the channel handshake.
func RegisterInterchainAccount(endpoint *ibctesting.Endpoint, owner string) error {
icaOwner, _ := ictxstypes.NewICAOwner(owner, TestInterchainID)
portID, err := icatypes.NewControllerPortID(icaOwner.String())
portID, err := icatypes.NewControllerPortID(owner)
if err != nil {
return err
}

ctx := endpoint.Chain.GetContext()

channelSequence := endpoint.Chain.App.GetIBCKeeper().ChannelKeeper.GetNextChannelSequence(ctx)
channelSequence := endpoint.Chain.App.GetIBCKeeper().ChannelKeeper.GetNextChannelSequence(endpoint.Chain.GetContext())

a, ok := endpoint.Chain.App.(*app.App)
if !ok {
return fmt.Errorf("not NolusZoneApp")
return fmt.Errorf("not NolusApp")
}

// TODO(pr0n00gler): are we sure it's okay?
if err := a.ICAControllerKeeper.RegisterInterchainAccount(ctx, endpoint.ConnectionID, icaOwner.String(), ""); err != nil {
icaMsgServer := icacontrollerkeeper.NewMsgServerImpl(a.ICAControllerKeeper)
_, err = icaMsgServer.RegisterInterchainAccount(endpoint.Chain.GetContext(), &icacontrollertypes.MsgRegisterInterchainAccount{
Owner: owner,
ConnectionId: endpoint.ConnectionID,
Version: TestVersion,
Ordering: channeltypes.UNORDERED,
})
if err != nil {
return err
}

// commit state changes for proof verification
endpoint.Chain.NextBlock()

// update port/channel ids
endpoint.ChannelID = channeltypes.FormatChannelIdentifier(channelSequence)
endpoint.ChannelConfig.PortID = portID
endpoint.ChannelConfig.Version = TestVersion

return nil
}
Expand Down
Loading

0 comments on commit 4d3cb47

Please sign in to comment.