Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate Packet Forward Middleware #3911

Merged
merged 27 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
89b8b23
added initial packet forward middleware integration
nicolaslara Jan 3, 2023
0820107
gofumpt
nicolaslara Jan 3, 2023
b987095
Merge branch 'main' into nicolas/packet-forward-middleware
nicolaslara Jan 4, 2023
aa7dd10
updated go.mod
nicolaslara Jan 4, 2023
f084a4b
correct value
nicolaslara Jan 4, 2023
b2654a1
Merge branch 'main' into nicolas/packet-forward-middleware
nicolaslara Jan 23, 2023
9d87a60
updating to match upstream
nicolaslara Jan 23, 2023
58859b4
added params
nicolaslara Jan 23, 2023
85a936f
gofumpt
nicolaslara Jan 23, 2023
bf161a3
Merge branch 'main' into nicolas/packet-forward-middleware
nicolaslara Jan 24, 2023
0b6df24
added PFM to upgrades
nicolaslara Jan 24, 2023
0e67297
go imports
nicolaslara Jan 24, 2023
19f81c4
added e2e test for PFM+wasm hoks
nicolaslara Jan 26, 2023
dd322be
refactor
nicolaslara Jan 27, 2023
a4f7082
refactored for reusability and added comments
nicolaslara Jan 27, 2023
03b1d09
Merge branch 'main' into nicolas/packet-forward-middleware
nicolaslara Jan 30, 2023
293a16c
updated to latest version that allows native json
nicolaslara Jan 30, 2023
fea6d54
removed unnecessary param
nicolaslara Jan 30, 2023
9168bb8
Merge branch 'main' into nicolas/packet-forward-middleware
nicolaslara Jan 30, 2023
6542dc3
Merge branch 'main' into nicolas/packet-forward-middleware
nicolaslara Feb 7, 2023
a014a31
reordering imports after merge
nicolaslara Feb 7, 2023
8208bfc
added denom check
nicolaslara Feb 7, 2023
66c2ccc
added changelog
nicolaslara Feb 7, 2023
9dbf94d
Update tests/e2e/e2e_test.go
nicolaslara Feb 8, 2023
ef52182
requiring the txs to succeed
nicolaslara Feb 8, 2023
080b7e6
fixed e2e tests
nicolaslara Feb 8, 2023
8b308ac
Merge branch 'main' into nicolas/packet-forward-middleware
nicolaslara Feb 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 39 additions & 6 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ import (
ibchost "github.com/cosmos/ibc-go/v4/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/v4/modules/core/keeper"

packetforward "github.com/strangelove-ventures/packet-forward-middleware/v4/router"
packetforwardkeeper "github.com/strangelove-ventures/packet-forward-middleware/v4/router/keeper"
packetforwardtypes "github.com/strangelove-ventures/packet-forward-middleware/v4/router/types"

// IBC Transfer: Defines the "transfer" IBC port
transfer "github.com/cosmos/ibc-go/v4/modules/apps/transfer"

Expand Down Expand Up @@ -145,6 +149,7 @@ type AppKeepers struct {
TransferStack *ibchooks.IBCMiddleware
Ics20WasmHooks *ibchooks.WasmHooks
HooksICS4Wrapper ibchooks.ICS4Middleware
PacketForwardKeeper *packetforwardkeeper.Keeper

// keys to access the substores
keys map[string]*sdk.KVStoreKey
Expand Down Expand Up @@ -444,19 +449,24 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
appKeepers.GovKeeper = &govKeeper
}

// Create the IBC Transfer Stack from bottom to top:
// WireICS20PreWasmKeeper Create the IBC Transfer Stack from bottom to top:
//
// * SendPacket. Originates from the transferKeeper and and goes up the stack:
// * SendPacket. Originates from the transferKeeper and goes up the stack:
// transferKeeper.SendPacket -> ibc_rate_limit.SendPacket -> ibc_hooks.SendPacket -> channel.SendPacket
// * RecvPacket, message that originates from core IBC and goes down to app, the flow is the other way
// channel.RecvPacket -> ibc_hooks.OnRecvPacket -> ibc_rate_limit.OnRecvPacket -> transfer.OnRecvPacket
// channel.RecvPacket -> ibc_hooks.OnRecvPacket -> ibc_rate_limit.OnRecvPacket -> forward.OnRecvPacket -> transfer.OnRecvPacket
//
// Note that the forward middleware is only integrated on the "reveive" direction. It can be safely skipped when sending.
// Note also that the forward middleware is called "router", but we are using the name "forward" for clarity
// This may later be renamed upstream: https://github.com/strangelove-ventures/packet-forward-middleware/issues/10
//
// After this, the wasm keeper is required to be set on both
// appkeepers.WasmHooks AND appKeepers.RateLimitingICS4Wrapper
func (appKeepers *AppKeepers) WireICS20PreWasmKeeper(
appCodec codec.Codec,
bApp *baseapp.BaseApp,
hooksKeeper *ibchookskeeper.Keeper) {
hooksKeeper *ibchookskeeper.Keeper,
) {
// Setup the ICS4Wrapper used by the hooks middleware
osmoPrefix := sdk.GetConfig().GetBech32AccountAddrPrefix()
wasmHooks := ibchooks.NewWasmHooks(hooksKeeper, nil, osmoPrefix) // The contract keeper needs to be set later
Expand Down Expand Up @@ -494,10 +504,31 @@ func (appKeepers *AppKeepers) WireICS20PreWasmKeeper(
)
appKeepers.TransferKeeper = &transferKeeper
appKeepers.RawIcs20TransferAppModule = transfer.NewAppModule(*appKeepers.TransferKeeper)
transferIBCModule := transfer.NewIBCModule(*appKeepers.TransferKeeper)

// Packet Forward Middleware
// Initialize packet forward middleware router
appKeepers.PacketForwardKeeper = packetforwardkeeper.NewKeeper(
appCodec,
appKeepers.keys[packetforwardtypes.StoreKey],
appKeepers.GetSubspace(packetforwardtypes.ModuleName),
appKeepers.TransferKeeper,
appKeepers.IBCKeeper.ChannelKeeper,
appKeepers.DistrKeeper,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhh, why does it need this? Community pool?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, the fee can be configured via a param as a percentage of the send and it funds the community pool.

Ideally this should go to stakers IMO, but the fee defaults to 0, so we can change that later

Copy link
Member

@ValarDragon ValarDragon Jan 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RIP, this is bad module design imo, should be a middleware responsibility. (Fee at the base transport layer bad design)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please expand on this @ValarDragon ? Would love to understand your perspective so we can improve it. I'm not sure what you mean, as this is the keeper for the IBC middleware.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why your transport layer for packet sending should have bips of fee bundled in at default. This is equivalent in design practice to saying our API for bank sends should take in a fee parameter as well, and have bips of all sends be captured.

You could in principle want this, but this can be pushed to wrappers of the main object, rather than being the main thing you import. (I'd prefer no capability of this in what we import, than having such a parameter forced)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(NOTE: This is very minor on the overall work going into this. Awesome job on the module! And I think my first comment "bad module design imo" was too harsh for the severity of opinion actually held)

appKeepers.BankKeeper,
// The ICS4Wrapper is replaced by the HooksICS4Wrapper instead of the channel so that sending can be overridden by the middleware
appKeepers.HooksICS4Wrapper,
)
packetForwardMiddleware := packetforward.NewIBCMiddleware(
transfer.NewIBCModule(*appKeepers.TransferKeeper),
appKeepers.PacketForwardKeeper,
0,
packetforwardkeeper.DefaultForwardTransferPacketTimeoutTimestamp,
packetforwardkeeper.DefaultRefundTransferPacketTimeoutTimestamp,
)

// RateLimiting IBC Middleware
rateLimitingTransferModule := ibcratelimit.NewIBCModule(transferIBCModule, appKeepers.RateLimitingICS4Wrapper)
rateLimitingTransferModule := ibcratelimit.NewIBCModule(packetForwardMiddleware, appKeepers.RateLimitingICS4Wrapper)

// Hooks Middleware
hooksTransferModule := ibchooks.NewIBCMiddleware(&rateLimitingTransferModule, &appKeepers.HooksICS4Wrapper)
appKeepers.TransferStack = &hooksTransferModule
Expand Down Expand Up @@ -572,6 +603,7 @@ func (appKeepers *AppKeepers) initParamsKeeper(appCodec codec.BinaryCodec, legac
paramsKeeper.Subspace(twaptypes.ModuleName)
paramsKeeper.Subspace(ibcratelimittypes.ModuleName)
paramsKeeper.Subspace(concentratedliquiditytypes.ModuleName)
paramsKeeper.Subspace(packetforwardtypes.ModuleName).WithKeyTable(packetforwardtypes.ParamKeyTable())

return paramsKeeper
}
Expand Down Expand Up @@ -672,5 +704,6 @@ func KVStoreKeys() []string {
valsetpreftypes.StoreKey,
protorevtypes.StoreKey,
ibchookstypes.StoreKey,
packetforwardtypes.StoreKey,
}
}
2 changes: 2 additions & 0 deletions app/keepers/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
transfer "github.com/cosmos/ibc-go/v4/modules/apps/transfer"
ibc "github.com/cosmos/ibc-go/v4/modules/core"
ibcclientclient "github.com/cosmos/ibc-go/v4/modules/core/02-client/client"
"github.com/strangelove-ventures/packet-forward-middleware/v4/router"

"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/auth"
Expand Down Expand Up @@ -101,4 +102,5 @@ var AppModuleBasics = []module.AppModuleBasic{
ica.AppModuleBasic{},
ibc_hooks.AppModuleBasic{},
ibc_rate_limit.AppModuleBasic{},
router.AppModuleBasic{},
}
3 changes: 2 additions & 1 deletion app/upgrades/v15/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v15

import (
store "github.com/cosmos/cosmos-sdk/store/types"
packetforwardtypes "github.com/strangelove-ventures/packet-forward-middleware/v4/router/types"

"github.com/osmosis-labs/osmosis/v14/app/upgrades"
cltypes "github.com/osmosis-labs/osmosis/v14/x/concentrated-liquidity/types"
Expand All @@ -17,7 +18,7 @@ var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{
Added: []string{poolmanagertypes.StoreKey, cltypes.StoreKey, valsetpreftypes.StoreKey, protorevtypes.StoreKey},
Added: []string{poolmanagertypes.StoreKey, cltypes.StoreKey, valsetpreftypes.StoreKey, protorevtypes.StoreKey, packetforwardtypes.StoreKey},
Deleted: []string{},
},
}
2 changes: 2 additions & 0 deletions app/upgrades/v15/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
packetforwardtypes "github.com/strangelove-ventures/packet-forward-middleware/v4/router/types"

"github.com/osmosis-labs/osmosis/v14/app/keepers"
"github.com/osmosis-labs/osmosis/v14/app/upgrades"
Expand All @@ -23,6 +24,7 @@ func CreateUpgradeHandler(
poolmanagerParams := poolmanagertypes.NewParams(keepers.GAMMKeeper.GetParams(ctx).PoolCreationFee)

keepers.PoolManagerKeeper.SetParams(ctx, poolmanagerParams)
keepers.PacketForwardKeeper.SetParams(ctx, packetforwardtypes.DefaultParams())

// N.B: pool id in gamm is to be deprecated in the future
// Instead,it is moved to poolmanager.
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/golangci/golangci-lint v1.50.1
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/iancoleman/orderedmap v0.2.0
github.com/mattn/go-sqlite3 v1.14.16
github.com/ory/dockertest/v3 v3.9.1
github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3
Expand All @@ -26,6 +27,7 @@ require (
github.com/spf13/cobra v1.6.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.15.0
github.com/strangelove-ventures/packet-forward-middleware/v4 v4.0.3
github.com/stretchr/testify v1.8.1
github.com/tendermint/tendermint v0.34.24
github.com/tendermint/tm-db v0.6.8-0.20220506192307-f628bb5dc95b
Expand Down Expand Up @@ -314,4 +316,5 @@ replace (
github.com/tendermint/tendermint => github.com/informalsystems/tendermint v0.34.24
// use grpc compatible with cosmos protobufs
google.golang.org/grpc => google.golang.org/grpc v1.33.2

)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,8 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
github.com/huin/goupnp v1.0.0/go.mod h1:n9v9KO1tAxYH82qOn+UTIFQDmx5n1Zxd/ClZDMX7Bnc=
github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3iZrZfqZzyLl6l7F3c6L1oWn7OICBi6o=
github.com/iancoleman/orderedmap v0.2.0 h1:sq1N/TFpYH++aViPcaKjys3bDClUEU7s5B+z6jq8pNA=
github.com/iancoleman/orderedmap v0.2.0/go.mod h1:N0Wam8K1arqPXNWjMo21EXnBPOPp36vB07FNRdD2geA=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
Expand Down Expand Up @@ -1057,6 +1059,8 @@ github.com/stbenjam/no-sprintf-host-port v0.1.1 h1:tYugd/yrm1O0dV+ThCbaKZh195Dfm
github.com/stbenjam/no-sprintf-host-port v0.1.1/go.mod h1:TLhvtIvONRzdmkFiio4O8LHsN9N74I+PhRquPsxpL0I=
github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570/go.mod h1:8OR4w3TdeIHIh1g6EMY5p0gVNOovcWC+1vpc7naMuAw=
github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3/go.mod h1:hpGUWaI9xL8pRQCTXQgocU38Qw1g0Us7n5PxxTwTCYU=
github.com/strangelove-ventures/packet-forward-middleware/v4 v4.0.3 h1:3E7I9C+gM7n0+OkI7JmvWH5PGD6pZOIc1+mUUooh6dI=
github.com/strangelove-ventures/packet-forward-middleware/v4 v4.0.3/go.mod h1:AG8F5pdk3x1h7PlRvPoMem3623W+w8HJHrWYkVJ51kk=
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI=
Expand Down
134 changes: 105 additions & 29 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ package e2e
import (
"encoding/json"
"fmt"
"github.com/iancoleman/orderedmap"
"github.com/osmosis-labs/osmosis/v14/tests/e2e/configurer/chain"
"io"
"os"
"path/filepath"
"strconv"
"strings"
"time"

packetforwardingtypes "github.com/strangelove-ventures/packet-forward-middleware/v4/router/types"

ibchookskeeper "github.com/osmosis-labs/osmosis/x/ibc-hooks/keeper"

paramsutils "github.com/cosmos/cosmos-sdk/x/params/client/utils"
Expand All @@ -25,6 +29,30 @@ import (
"github.com/osmosis-labs/osmosis/v14/tests/e2e/initialization"
)

// Reusable Checks

// CheckBalance Checks the balance of an address
func (s *IntegrationTestSuite) CheckBalance(node *chain.NodeConfig, addr string, amount int64) {
// check the balance of the contract
s.Eventually(func() bool {
nicolaslara marked this conversation as resolved.
Show resolved Hide resolved
balance, err := node.QueryBalances(addr)
s.Require().NoError(err)
if len(balance) == 0 {
return false
}
// check that the amount is in one of the balances inside the balance list
for _, b := range balance {
if b.Amount.Int64() == amount {
return true
}
}
return false
},
1*time.Minute,
10*time.Millisecond,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that CI might be flaky and blocking requests due to retrying this too frequently. I've run into similar issues before where AFAIR increasing this number helped.

I looked into the node logs: https://github.com/osmosis-labs/osmosis/suites/10828110105/artifacts/545247532 and they seem okay. So I'm guessing it might be some setup problem

Copy link
Contributor Author

@nicolaslara nicolaslara Feb 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried increasing it and it didn't help, but somehow it works (locally) after I added the Require() you suggested

)
}

func (s *IntegrationTestSuite) TestConcentratedLiquidity() {
chainA := s.configurer.GetChainConfig(0)
node1, err := chainA.GetDefaultNode()
Expand Down Expand Up @@ -292,55 +320,52 @@ func (s *IntegrationTestSuite) TestIBCTokenTransferRateLimiting() {
node.WasmExecute(contracts[0], `{"remove_path": {"channel_id": "channel-0", "denom": "uosmo"}}`, initialization.ValidatorWalletName)
}

func (s *IntegrationTestSuite) TestIBCWasmHooks() {
if s.skipIBC {
s.T().Skip("Skipping IBC tests")
}
chainA := s.configurer.GetChainConfig(0)
chainB := s.configurer.GetChainConfig(1)

nodeA, err := chainA.GetDefaultNode()
s.NoError(err)
nodeB, err := chainB.GetDefaultNode()
s.NoError(err)

// copy the contract from x/rate-limit/testdata/
func (s *IntegrationTestSuite) UploadAndInstantiateCounter(chain *chain.Config) string {
// copy the contract from tests/ibc-hooks/bytecode
wd, err := os.Getwd()
s.NoError(err)
// co up two levels
projectDir := filepath.Dir(filepath.Dir(wd))
err = copyFile(projectDir+"/tests/ibc-hooks/bytecode/counter.wasm", wd+"/scripts/counter.wasm")
s.NoError(err)
node, err := chain.GetDefaultNode()
s.NoError(err)

nodeA.StoreWasmCode("counter.wasm", initialization.ValidatorWalletName)
chainA.LatestCodeId = int(nodeA.QueryLatestWasmCodeID())
nodeA.InstantiateWasmContract(
strconv.Itoa(chainA.LatestCodeId),
node.StoreWasmCode("counter.wasm", initialization.ValidatorWalletName)
chain.LatestCodeId = int(node.QueryLatestWasmCodeID())
node.InstantiateWasmContract(
strconv.Itoa(chain.LatestCodeId),
`{"count": 0}`,
initialization.ValidatorWalletName)

contracts, err := nodeA.QueryContractsFromId(chainA.LatestCodeId)
contracts, err := node.QueryContractsFromId(chain.LatestCodeId)
s.NoError(err)
s.Require().Len(contracts, 1, "Wrong number of contracts for the counter")
contractAddr := contracts[0]
return contractAddr
}

func (s *IntegrationTestSuite) TestIBCWasmHooks() {
if s.skipIBC {
s.T().Skip("Skipping IBC tests")
}
chainA := s.configurer.GetChainConfig(0)
chainB := s.configurer.GetChainConfig(1)

nodeA, err := chainA.GetDefaultNode()
s.NoError(err)
nodeB, err := chainB.GetDefaultNode()
s.NoError(err)

contractAddr := s.UploadAndInstantiateCounter(chainA)

transferAmount := int64(10)
validatorAddr := nodeB.GetWallet(initialization.ValidatorWalletName)
nodeB.SendIBCTransfer(validatorAddr, contractAddr, fmt.Sprintf("%duosmo", transferAmount),
fmt.Sprintf(`{"wasm":{"contract":"%s","msg": {"increment": {}} }}`, contractAddr))

// check the balance of the contract
s.Eventually(func() bool {
balance, err := nodeA.QueryBalances(contractAddr)
s.Require().NoError(err)
if len(balance) == 0 {
return false
}
return balance[0].Amount.Int64() == transferAmount
},
1*time.Minute,
10*time.Millisecond,
)
s.CheckBalance(nodeA, contractAddr, transferAmount)

// sender wasm addr
senderBech32, err := ibchookskeeper.DeriveIntermediateSender("channel-0", validatorAddr, "osmo")
Expand All @@ -359,6 +384,57 @@ func (s *IntegrationTestSuite) TestIBCWasmHooks() {
)
}

// TestPacketForwarding sends a packet from chainA to chainB, and forwards it
// back to chainA with a custom memo to execute the counter contract on chain A
func (s *IntegrationTestSuite) TestPacketForwarding() {
ValarDragon marked this conversation as resolved.
Show resolved Hide resolved
if s.skipIBC {
s.T().Skip("Skipping IBC tests")
}
chainA := s.configurer.GetChainConfig(0)

nodeA, err := chainA.GetDefaultNode()
s.NoError(err)

// Instantiate the counter contract on chain A
contractAddr := s.UploadAndInstantiateCounter(chainA)

transferAmount := int64(10)
validatorAddr := nodeA.GetWallet(initialization.ValidatorWalletName)
// Specify that the counter contract should be called on chain A when the packet is received
contractCallMemo := []byte(fmt.Sprintf(`{"wasm":{"contract":"%s","msg": {"increment": {}} }}`, contractAddr))
// Generate the forward metadata
forwardMetadata := packetforwardingtypes.ForwardMetadata{
Receiver: contractAddr,
Port: "transfer",
Channel: "channel-0",
Next: packetforwardingtypes.NewJSONObject(false, contractCallMemo, orderedmap.OrderedMap{}), // The packet sent to chainA will have this memo
}
memoData := packetforwardingtypes.PacketMetadata{Forward: &forwardMetadata}
forwardMemo, err := json.Marshal(memoData)
s.NoError(err)
// Send the transfer from chainA to chainB. ChainB will parse the memo and forward the packet back to chainA
nodeA.SendIBCTransfer(validatorAddr, validatorAddr, fmt.Sprintf("%duosmo", transferAmount), string(forwardMemo))

// check the balance of the contract
s.CheckBalance(nodeA, contractAddr, transferAmount)

// sender wasm addr
senderBech32, err := ibchookskeeper.DeriveIntermediateSender("channel-0", validatorAddr, "osmo")
var response map[string]interface{}
s.Eventually(func() bool {
response, err = nodeA.QueryWasmSmart(contractAddr, fmt.Sprintf(`{"get_count": {"addr": "%s"}}`, senderBech32))
if err != nil {
return false
}
count := response["count"].(float64)
// check if denom contains "uosmo"
return err == nil && count == 0
Copy link
Member

@ValarDragon ValarDragon Feb 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to handle this TODO right? IMO we should ensure exact osmo amount received, in order to be certain that our default post-upgrade parameter has no fee taken.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that comment is a leftover from previous code. The balance check is done above (line419) but it's not checking the denom, just the amount. I'll add the denom check.

},
15*time.Second,
10*time.Millisecond,
)
}

// TestAddToExistingLockPostUpgrade ensures addToExistingLock works for locks created preupgrade.
func (s *IntegrationTestSuite) TestAddToExistingLockPostUpgrade() {
if s.skipUpgrade {
Expand Down