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

Cherry pick sender and e2e for v14.x #3945

Merged
merged 8 commits into from
Jan 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ import (
v8 "github.com/osmosis-labs/osmosis/v13/app/upgrades/v8"
v9 "github.com/osmosis-labs/osmosis/v13/app/upgrades/v9"
_ "github.com/osmosis-labs/osmosis/v13/client/docs/statik"
ibc_hooks "github.com/osmosis-labs/osmosis/x/ibc-hooks"
)

const appName = "OsmosisApp"
Expand All @@ -77,7 +76,7 @@ var (
maccPerms = moduleAccountPermissions

// module accounts that are allowed to receive tokens.
allowedReceivingModAcc = map[string]bool{ibc_hooks.WasmHookModuleAccountAddr.String(): true}
allowedReceivingModAcc = map[string]bool{}

// TODO: Refactor wasm items into a wasm.go file
// WasmProposalsEnabled enables all x/wasm proposals when it's value is "true"
Expand Down
3 changes: 2 additions & 1 deletion app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,8 @@ func (appKeepers *AppKeepers) WireICS20PreWasmKeeper(
bApp *baseapp.BaseApp,
hooksKeeper *ibchookskeeper.Keeper) {
// Setup the ICS4Wrapper used by the hooks middleware
wasmHooks := ibchooks.NewWasmHooks(hooksKeeper, nil) // The contract keeper needs to be set later
osmoPrefix := sdk.GetConfig().GetBech32AccountAddrPrefix()
wasmHooks := ibchooks.NewWasmHooks(hooksKeeper, nil, osmoPrefix) // The contract keeper needs to be set later
appKeepers.Ics20WasmHooks = &wasmHooks
appKeepers.HooksICS4Wrapper = ibchooks.NewICS4Middleware(
appKeepers.IBCKeeper.ChannelKeeper,
Expand Down
18 changes: 11 additions & 7 deletions app/upgrades/v13/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
abci "github.com/tendermint/tendermint/abci/types"

"github.com/osmosis-labs/osmosis/v13/app/apptesting"
ibc_hooks "github.com/osmosis-labs/osmosis/x/ibc-hooks"
)

type UpgradeTestSuite struct {
Expand Down Expand Up @@ -56,8 +55,10 @@ func (suite *UpgradeTestSuite) TestUpgrade() {
{
"Test that the upgrade succeeds",
func() {
acc := suite.App.AccountKeeper.GetAccount(suite.Ctx, ibc_hooks.WasmHookModuleAccountAddr)
suite.App.AccountKeeper.RemoveAccount(suite.Ctx, acc)
// The module doesn't need an account anymore, but when the upgrade happened we did:
//acc := suite.App.AccountKeeper.GetAccount(suite.Ctx, ibc_hooks.WasmHookModuleAccountAddr)
//suite.App.AccountKeeper.RemoveAccount(suite.Ctx, acc)

// Because of SDK version map bug, we can't do the following, and instaed do a massive hack
// vm := suite.App.UpgradeKeeper.GetModuleVersionMap(suite.Ctx)
// delete(vm, ibc_hooks.ModuleName)
Expand All @@ -69,13 +70,16 @@ func (suite *UpgradeTestSuite) TestUpgrade() {
versionStore := prefix.NewStore(store, []byte{upgradetypes.VersionMapByte})
versionStore.Delete([]byte(ibchookstypes.ModuleName))

hasAcc := suite.App.AccountKeeper.HasAccount(suite.Ctx, ibc_hooks.WasmHookModuleAccountAddr)
suite.Require().False(hasAcc)
// Same comment as above: this was the case when the upgrade happened, but we don't have accounts anymore
//hasAcc := suite.App.AccountKeeper.HasAccount(suite.Ctx, ibc_hooks.WasmHookModuleAccountAddr)
//suite.Require().False(hasAcc)

},
func() { dummyUpgrade(suite) },
func() {
hasAcc := suite.App.AccountKeeper.HasAccount(suite.Ctx, ibc_hooks.WasmHookModuleAccountAddr)
suite.Require().True(hasAcc)
// Same comment as pre-upgrade. We had an account, but now we don't anymore
//hasAcc := suite.App.AccountKeeper.HasAccount(suite.Ctx, ibc_hooks.WasmHookModuleAccountAddr)
//suite.Require().True(hasAcc)
},
},
{
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ require (
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
github.com/osmosis-labs/osmosis/osmomath v0.0.0-20230106133904-bf95f2df4908
github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230106095152-4f77cc5e42af
github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.0-20230106110415-61e4300ada92
github.com/osmosis-labs/osmosis/osmomath v0.0.0-20230105183030-bccf5202f260
github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230107103045-bd927ebeed7e
github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.0-20230107103145-55fa2321dbd4
github.com/pkg/errors v0.9.1
github.com/rakyll/statik v0.1.7
github.com/spf13/cast v1.5.0
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -853,12 +853,12 @@ github.com/osmosis-labs/cosmos-sdk v0.45.1-0.20221118211718-545aed73e94e h1:A3by
github.com/osmosis-labs/cosmos-sdk v0.45.1-0.20221118211718-545aed73e94e/go.mod h1:rud0OaBIuq3+qOqtwT4SR7Q7iSzRp7w41fjninTjfnQ=
github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3 h1:YlmchqTmlwdWSmrRmXKR+PcU96ntOd8u10vTaTZdcNY=
github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3/go.mod h1:lV6KnqXYD/ayTe7310MHtM3I2q8Z6bBfMAi+bhwPYtI=
github.com/osmosis-labs/osmosis/osmomath v0.0.0-20230106133904-bf95f2df4908 h1:N7JvlXT8N82iN7NDzX6CXFOFrpFTWqSfJuAZcInQ+/Y=
github.com/osmosis-labs/osmosis/osmomath v0.0.0-20230106133904-bf95f2df4908/go.mod h1:KrzYoNtnWUH75rj1XAsSR4nymlHFU7jeVOx7/1KMe0k=
github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230106095152-4f77cc5e42af h1:/UyyIUTH2FZaN7xULcA2SQ6+bKD9fsau4PJkYWMir3g=
github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230106095152-4f77cc5e42af/go.mod h1:K4de+n3DtLdueen98dOzaRXZvqMd8JvigL8O1xW445o=
github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.0-20230106110415-61e4300ada92 h1:aXAru0jzeTjrSmFEcqIXUI23yaE0RqpwKg04HK1sYcs=
github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.0-20230106110415-61e4300ada92/go.mod h1:UyXr/YYabkU+pQ85RDjUMJe2kbffcnOHWlk3NSfWA34=
github.com/osmosis-labs/osmosis/osmomath v0.0.0-20230105183030-bccf5202f260 h1:+EbINXzHQyDtHje2CND357A22H2zUpceTtwJClC9IAM=
github.com/osmosis-labs/osmosis/osmomath v0.0.0-20230105183030-bccf5202f260/go.mod h1:KrzYoNtnWUH75rj1XAsSR4nymlHFU7jeVOx7/1KMe0k=
github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230107103045-bd927ebeed7e h1:CV1wJzCnutpfqUE/OiwBv0b3mPQTAzpA8WPcvojuNxo=
github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230107103045-bd927ebeed7e/go.mod h1:K4de+n3DtLdueen98dOzaRXZvqMd8JvigL8O1xW445o=
github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.0-20230107103145-55fa2321dbd4 h1:YsCGVv8R9DaxPXR8d8p2o+pPw7V5/MXw924TN177XaQ=
github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.0-20230107103145-55fa2321dbd4/go.mod h1:wvVANZFT8i2pawEwZhxQJ40ngoWXXODv30UsHhA53m8=
github.com/osmosis-labs/wasmd v0.29.2-0.20221222131554-7c8ea36a6e30 h1:6uMi7HhPSwvKKU7j5NqljseFTEz4I7qHr+IPnnn42Ck=
github.com/osmosis-labs/wasmd v0.29.2-0.20221222131554-7c8ea36a6e30/go.mod h1:5fDYJyMXBq6u2iuHqqOTYiZ5NitIOeIW5k7qEXqbwJE=
github.com/otiai10/copy v1.2.0/go.mod h1:rrF5dJ5F0t/EWSYODDu4j9/vEeYHMkc8jt0zJChqQWw=
Expand Down
2 changes: 1 addition & 1 deletion go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ github.com/opencontainers/selinux v1.8.2/go.mod h1:MUIHuUEvKB1wtJjQdOyYRgOnLD2xA
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
github.com/openzipkin/zipkin-go v0.2.5/go.mod h1:KpXfKdgRDnnhsxw4pNIH9Md5lyFqKUa4YDFlwRYAMyE=
github.com/ory/dockertest v3.3.5+incompatible/go.mod h1:1vX4m9wsvi00u5bseYwXaSnhNrne+V0E6LAcBILJdPs=
github.com/osmosis-labs/osmosis/osmomath v0.0.0-20230106110532-e17f2f459464/go.mod h1:KrzYoNtnWUH75rj1XAsSR4nymlHFU7jeVOx7/1KMe0k=
github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230105183030-bccf5202f260/go.mod h1:K4de+n3DtLdueen98dOzaRXZvqMd8JvigL8O1xW445o=
github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.0-20230107103145-55fa2321dbd4/go.mod h1:wvVANZFT8i2pawEwZhxQJ40ngoWXXODv30UsHhA53m8=
github.com/otiai10/copy v1.7.0/go.mod h1:rmRl6QPdJj6EiUqXQ/4Nn2lLXoNQjFCQbbNrxgc/t3U=
github.com/otiai10/mint v1.3.3 h1:7JgpsBaN0uMkyju4tbYHu0mnM55hNKVYLsXmwr15NQI=
github.com/otiai10/mint v1.3.3/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc=
Expand Down
11 changes: 11 additions & 0 deletions tests/e2e/configurer/chain/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ func (n *NodeConfig) SubmitParamChangeProposal(proposalJson, from string) {
n.LogActionF("successfully submitted param change proposal")
}

func (n *NodeConfig) SendIBCTransfer(from, recipient, amount, memo string) {
n.LogActionF("IBC sending %s from %s to %s. memo: %s", amount, from, recipient, memo)

cmd := []string{"osmosisd", "tx", "ibc-transfer", "transfer", "transfer", "channel-0", recipient, amount, fmt.Sprintf("--from=%s", from), "--memo", memo}

_, _, err := n.containerManager.ExecTxCmdWithSuccessString(n.t, n.chainId, n.Name, cmd, "code: 0")
require.NoError(n.t, err)

n.LogActionF("successfully submitted sent IBC transfer")
}

func (n *NodeConfig) FailIBCTransfer(from, recipient, amount string) {
n.LogActionF("IBC sending %s from %s to %s", amount, from, recipient)

Expand Down
40 changes: 40 additions & 0 deletions tests/e2e/configurer/chain/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package chain

import (
"context"
"encoding/base64"
"encoding/json"
"fmt"
"io"
Expand Down Expand Up @@ -110,6 +111,45 @@ func (n *NodeConfig) QueryContractsFromId(codeId int) ([]string, error) {
return contractsResponse.Contracts, nil
}

func (n *NodeConfig) QueryLatestWasmCodeID() uint64 {
path := "/cosmwasm/wasm/v1/code"

bz, err := n.QueryGRPCGateway(path)
require.NoError(n.t, err)

var response wasmtypes.QueryCodesResponse
err = util.Cdc.UnmarshalJSON(bz, &response)
require.NoError(n.t, err)
if len(response.CodeInfos) == 0 {
return 0
}
return response.CodeInfos[len(response.CodeInfos)-1].CodeID
}

func (n *NodeConfig) QueryWasmSmart(contract string, msg string) (map[string]interface{}, error) {
// base64-encode the msg
encodedMsg := base64.StdEncoding.EncodeToString([]byte(msg))
path := fmt.Sprintf("/cosmwasm/wasm/v1/contract/%s/smart/%s", contract, encodedMsg)

bz, err := n.QueryGRPCGateway(path)
if err != nil {
return nil, err
}

var response wasmtypes.QuerySmartContractStateResponse
err = util.Cdc.UnmarshalJSON(bz, &response)
if err != nil {
return nil, err
}

var responseJSON map[string]interface{}
err = json.Unmarshal(response.Data, &responseJSON)
if err != nil {
return nil, err
}
return responseJSON, nil
}

func (n *NodeConfig) QueryPropTally(proposalNumber int) (sdk.Int, sdk.Int, sdk.Int, sdk.Int, error) {
path := fmt.Sprintf("cosmos/gov/v1beta1/proposals/%d/tally", proposalNumber)
bz, err := n.QueryGRPCGateway(path)
Expand Down
76 changes: 75 additions & 1 deletion tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package e2e
import (
"encoding/json"
"fmt"
ibchookskeeper "github.com/osmosis-labs/osmosis/x/ibc-hooks/keeper"
"io"
"os"
"path/filepath"
"strconv"
"strings"
"time"

paramsutils "github.com/cosmos/cosmos-sdk/x/params/client/utils"
Expand Down Expand Up @@ -163,7 +165,7 @@ func (s *IntegrationTestSuite) TestIBCTokenTransferRateLimiting() {
s.NoError(err)

node.StoreWasmCode("rate_limiter.wasm", initialization.ValidatorWalletName)
chainA.LatestCodeId = 1
chainA.LatestCodeId = int(node.QueryLatestWasmCodeID())
node.InstantiateWasmContract(
strconv.Itoa(chainA.LatestCodeId),
fmt.Sprintf(`{"gov_module": "%s", "ibc_module": "%s", "paths": [{"channel_id": "channel-0", "denom": "%s", "quotas": [{"name":"testQuota", "duration": 86400, "send_recv": [1, 1]}] } ] }`, node.PublicAddress, node.PublicAddress, initialization.OsmoToken.Denom),
Expand Down Expand Up @@ -228,6 +230,78 @@ 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/
wd, err := os.Getwd()
s.NoError(err)
// co up two levels
projectDir := filepath.Dir(filepath.Dir(wd))
fmt.Println(wd, projectDir)
err = copyFile(projectDir+"/tests/ibc-hooks/bytecode/counter.wasm", wd+"/scripts/counter.wasm")
s.NoError(err)

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

// Using code_id 1 because this is the only contract right now. This may need to change if more contracts are added
contracts, err := nodeA.QueryContractsFromId(chainA.LatestCodeId)
s.NoError(err)
s.Require().Len(contracts, 1, "Wrong number of contracts for the counter")
contractAddr := contracts[0]

validatorAddr := nodeB.GetWallet(initialization.ValidatorWalletName)
fmt.Println("validatorAddr", validatorAddr)
nodeB.SendIBCTransfer(validatorAddr, contractAddr, "10uosmo",
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() == 10
},
1*time.Minute,
10*time.Millisecond,
)

// sender wasm addr
senderBech32, err := ibchookskeeper.DeriveIntermediateSender("channel-0", validatorAddr, "osmo")
fmt.Println("sender", senderBech32)

var response map[string]interface{}
s.Eventually(func() bool {
response, err = nodeA.QueryWasmSmart(contractAddr, fmt.Sprintf(`{"get_total_funds": {"addr": "%s"}}`, senderBech32))
totalFunds := response["total_funds"].([]interface{})[0]
amount := totalFunds.(map[string]interface{})["amount"].(string)
denom := totalFunds.(map[string]interface{})["denom"].(string)
// check if denom contains "uosmo"
return err == nil && amount == "10" && strings.Contains(denom, "ibc")
},
15*time.Second,
10*time.Millisecond,
)
fmt.Println("response", response)

}

// TestAddToExistingLockPostUpgrade ensures addToExistingLock works for locks created preupgrade.
func (s *IntegrationTestSuite) TestAddToExistingLockPostUpgrade() {
if s.skipUpgrade {
Expand Down
16 changes: 9 additions & 7 deletions tests/ibc-hooks/ibc_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ package ibc_hooks_test
import (
"encoding/json"
"fmt"
ibchookskeeper "github.com/osmosis-labs/osmosis/x/ibc-hooks/keeper"
"testing"
"time"

wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"

"github.com/osmosis-labs/osmosis/osmoutils"
"github.com/osmosis-labs/osmosis/v13/x/gamm/pool-models/balancer"
gammtypes "github.com/osmosis-labs/osmosis/v13/x/gamm/types"
minttypes "github.com/osmosis-labs/osmosis/v13/x/mint/types"
ibchooks "github.com/osmosis-labs/osmosis/x/ibc-hooks"

"github.com/osmosis-labs/osmosis/osmoutils"

"github.com/osmosis-labs/osmosis/v13/app/apptesting"

Expand Down Expand Up @@ -329,14 +328,17 @@ func (suite *HooksTestSuite) TestFundTracking() {
addr.String(),
fmt.Sprintf(`{"wasm": {"contract": "%s", "msg": {"increment": {} } } }`, addr))

senderLocalAcc, err := ibchookskeeper.DeriveIntermediateSender("channel-0", suite.chainB.SenderAccount.GetAddress().String(), "osmo")
suite.Require().NoError(err)

state := suite.chainA.QueryContract(
&suite.Suite, addr,
[]byte(fmt.Sprintf(`{"get_count": {"addr": "%s"}}`, ibchooks.WasmHookModuleAccountAddr)))
[]byte(fmt.Sprintf(`{"get_count": {"addr": "%s"}}`, senderLocalAcc)))
suite.Require().Equal(`{"count":0}`, state)

state = suite.chainA.QueryContract(
&suite.Suite, addr,
[]byte(fmt.Sprintf(`{"get_total_funds": {"addr": "%s"}}`, ibchooks.WasmHookModuleAccountAddr)))
[]byte(fmt.Sprintf(`{"get_total_funds": {"addr": "%s"}}`, senderLocalAcc)))
suite.Require().Equal(`{"total_funds":[{"denom":"ibc/C053D637CCA2A2BA030E2C5EE1B28A16F71CCB0E45E8BE52766DC1B241B77878","amount":"1"}]}`, state)

suite.receivePacketWithSequence(
Expand All @@ -345,12 +347,12 @@ func (suite *HooksTestSuite) TestFundTracking() {

state = suite.chainA.QueryContract(
&suite.Suite, addr,
[]byte(fmt.Sprintf(`{"get_count": {"addr": "%s"}}`, ibchooks.WasmHookModuleAccountAddr)))
[]byte(fmt.Sprintf(`{"get_count": {"addr": "%s"}}`, senderLocalAcc)))
suite.Require().Equal(`{"count":1}`, state)

state = suite.chainA.QueryContract(
&suite.Suite, addr,
[]byte(fmt.Sprintf(`{"get_total_funds": {"addr": "%s"}}`, ibchooks.WasmHookModuleAccountAddr)))
[]byte(fmt.Sprintf(`{"get_total_funds": {"addr": "%s"}}`, senderLocalAcc)))
suite.Require().Equal(`{"total_funds":[{"denom":"ibc/C053D637CCA2A2BA030E2C5EE1B28A16F71CCB0E45E8BE52766DC1B241B77878","amount":"2"}]}`, state)

// Check that the token has now been transferred to the contract
Expand Down
55 changes: 55 additions & 0 deletions tests/ibc-hooks/test_hooks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash
#
# This script can be used to manually test the ibc hooks. It is meant as a guid and not to be run directly
# without taking into account the context in which it's being run.
# The script uses `jenv` (https://github.com/nicolaslara/jenv) to easily generate the json strings passed
# to some of the commands. If you don't want to use it you can generate the json manually or modify this script.
#
set -o errexit -o nounset -o pipefail -o xtrace
shopt -s expand_aliases

alias chainA="osmosisd --node http://localhost:26657 --chain-id localosmosis-a"
alias chainB="osmosisd --node http://localhost:36657 --chain-id localosmosis-b"

# setup the keys
echo "bottom loan skill merry east cradle onion journey palm apology verb edit desert impose absurd oil bubble sweet glove shallow size build burst effort" | osmosisd --keyring-backend test keys add validator --recover || echo "key exists"
echo "increase bread alpha rigid glide amused approve oblige print asset idea enact lawn proof unfold jeans rabbit audit return chuckle valve rather cactus great" | osmosisd --keyring-backend test keys add faucet --recover || echo "key exists"

VALIDATOR=$(osmosisd keys show validator -a)

args="--keyring-backend test --gas auto --gas-prices 0.1uosmo --gas-adjustment 1.3 --broadcast-mode block --yes"
TX_FLAGS=($args)

# send money to the validator on both chains
chainA tx bank send faucet "$VALIDATOR" 1000000000uosmo "${TX_FLAGS[@]}"
chainB tx bank send faucet "$VALIDATOR" 1000000000uosmo "${TX_FLAGS[@]}"

# store and instantiate the contract
chainA tx wasm store ./bytecode/counter.wasm --from validator "${TX_FLAGS[@]}"
CONTRACT_ID=$(chainA query wasm list-code -o json | jq -r '.code_infos[-1].code_id')
chainA tx wasm instantiate "$CONTRACT_ID" '{"count": 0}' --from validator --no-admin --label=counter "${TX_FLAGS[@]}"

# get the contract address
export CONTRACT_ADDRESS=$(chainA query wasm list-contract-by-code 1 -o json | jq -r '.contracts | [last][0]')

denom=$(chainA query bank balances "$CONTRACT_ADDRESS" -o json | jq -r '.balances[0].denom')
balance=$(chainA query bank balances "$CONTRACT_ADDRESS" -o json | jq -r '.balances[0].amount')

# send ibc transaction to execite the contract
MEMO=$(jenv -c '{"wasm":{"contract":$CONTRACT_ADDRESS,"msg": {"increment": {}} }}' )
chainB tx ibc-transfer transfer transfer channel-0 $CONTRACT_ADDRESS 10uosmo \
--from validator -y \
--memo "$MEMO"

# wait for the ibc round trip
sleep 16

new_balance=$(chainA query bank balances "$CONTRACT_ADDRESS" -o json | jq -r '.balances[0].amount')
export ADDR_IN_CHAIN_A=$(chainA q ibchooks wasm-sender channel-0 "$VALIDATOR")
QUERY=$(jenv -c -r '{"get_total_funds": {"addr": $ADDR_IN_CHAIN_A}}')
funds=$(chainA query wasm contract-state smart "$CONTRACT_ADDRESS" "$QUERY" -o json | jq -c -r '.data.total_funds[]')
QUERY=$(jenv -c -r '{"get_count": {"addr": $ADDR_IN_CHAIN_A}}')
count=$(chainA query wasm contract-state smart "$CONTRACT_ADDRESS" "$QUERY" -o json | jq -r '.data.count')

echo "funds: $funds, count: $count"
echo "denom: $denom, old balance: $balance, new balance: $new_balance"
Loading