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

fix wasmd sub messages via Burn Plugin #892

Merged
merged 7 commits into from
Nov 21, 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
2 changes: 2 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import (
upgrades "github.com/CosmosContracts/juno/v18/app/upgrades"
testnetV18alpha2 "github.com/CosmosContracts/juno/v18/app/upgrades/testnet/v18.0.0-alpha.2"
testnetV18alpha3 "github.com/CosmosContracts/juno/v18/app/upgrades/testnet/v18.0.0-alpha.3"
testnetV18alpha4 "github.com/CosmosContracts/juno/v18/app/upgrades/testnet/v18.0.0-alpha.4"
v10 "github.com/CosmosContracts/juno/v18/app/upgrades/v10"
v11 "github.com/CosmosContracts/juno/v18/app/upgrades/v11"
v12 "github.com/CosmosContracts/juno/v18/app/upgrades/v12"
Expand Down Expand Up @@ -102,6 +103,7 @@ var (
// testnet
testnetV18alpha2.Upgrade,
testnetV18alpha3.Upgrade,
testnetV18alpha4.Upgrade,

v10.Upgrade,
v11.Upgrade,
Expand Down
12 changes: 10 additions & 2 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,16 @@ func NewAppKeepers(
wasmOpts = append(wasmOpts, querierOpts)

junoBurnerPlugin := junoburn.NewBurnerPlugin(appKeepers.BankKeeper, appKeepers.MintKeeper)
burnOverride := wasmkeeper.WithMessageHandler(wasmkeeper.NewBurnCoinMessageHandler(junoBurnerPlugin))
wasmOpts = append(wasmOpts, burnOverride)

// ref: https://github.com/CosmWasm/wasmd/issues/1735
burnMessageHandler := wasmkeeper.WithMessageHandlerDecorator(func(nested wasmkeeper.Messenger) wasmkeeper.Messenger {
return wasmkeeper.NewMessageHandlerChain(
wasmkeeper.NewBurnCoinMessageHandler(junoBurnerPlugin),
nested,
)
})

wasmOpts = append(wasmOpts, burnMessageHandler)

appKeepers.WasmKeeper = wasmkeeper.NewKeeper(
appCodec,
Expand Down
16 changes: 16 additions & 0 deletions app/upgrades/testnet/v18.0.0-alpha.4/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package v18

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

"github.com/CosmosContracts/juno/v18/app/upgrades"
)

// UpgradeName defines the on-chain upgrade name for the upgrade.
const UpgradeName = "v1800alpha4"

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: upgrades.CreateBlankUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{},
}
40 changes: 40 additions & 0 deletions app/upgrades/testnet/v18.0.0-alpha.4/upgrade_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package v18_test

import (
"testing"

"github.com/stretchr/testify/suite"

"github.com/CosmosContracts/juno/v18/app/apptesting"
v1800alpha4 "github.com/CosmosContracts/juno/v18/app/upgrades/testnet/v18.0.0-alpha.4"
)

type UpgradeTestSuite struct {
apptesting.KeeperTestHelper
}

func (s *UpgradeTestSuite) SetupTest() {
s.Setup()
}

func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(UpgradeTestSuite))
}

// Ensures the test does not error out.
func (s *UpgradeTestSuite) TestUpgrade() {
s.Setup()

preUpgradeChecks(s)

upgradeHeight := int64(5)
s.ConfirmUpgradeSucceeded(v1800alpha4.UpgradeName, upgradeHeight)

postUpgradeChecks(s)
}

func preUpgradeChecks(_ *UpgradeTestSuite) {
}

func postUpgradeChecks(_ *UpgradeTestSuite) {
}
11 changes: 11 additions & 0 deletions interchaintest/chain_start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package interchaintest
import (
"testing"

junoconformance "github.com/CosmosContracts/juno/tests/interchaintest/conformance"
"github.com/strangelove-ventures/interchaintest/v7"
"github.com/strangelove-ventures/interchaintest/v7/chain/cosmos"
"github.com/stretchr/testify/require"
)

Expand All @@ -18,6 +21,14 @@ func TestBasicJunoStart(t *testing.T) {
chains := CreateThisBranchChain(t, 1, 0)
ic, ctx, _, _ := BuildInitialChain(t, chains)

chain := chains[0].(*cosmos.CosmosChain)

const userFunds = int64(10_000_000_000)
users := interchaintest.GetAndFundTestUsers(t, ctx, t.Name(), userFunds, chain)
chainUser := users[0]

junoconformance.ConformanceCosmWasm(t, ctx, chain, chainUser)

require.NotNil(t, ic)
require.NotNil(t, ctx)

Expand Down
37 changes: 37 additions & 0 deletions interchaintest/conformance/cosmwasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@ package junoconformance

import (
"context"
"fmt"
"testing"

"github.com/CosmosContracts/juno/tests/interchaintest/helpers"
"github.com/strangelove-ventures/interchaintest/v7/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v7/ibc"
"github.com/stretchr/testify/require"

wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
)

// ConformanceCosmWasm validates that store, instantiate, execute, and query work on a CosmWasm contract.
func ConformanceCosmWasm(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet) {
std(t, ctx, chain, user)
subMsg(t, ctx, chain, user)
}

func std(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet) {
_, contractAddr := helpers.SetupContract(t, ctx, chain, user.KeyName(), "contracts/cw_template.wasm", `{"count":0}`)
helpers.ExecuteMsgWithFee(t, ctx, chain, user, contractAddr, "", "10000"+chain.Config().Denom, `{"increment":{}}`)

Expand All @@ -21,3 +29,32 @@ func ConformanceCosmWasm(t *testing.T, ctx context.Context, chain *cosmos.Cosmos

require.Equal(t, int64(1), res.Data.Count)
}

func subMsg(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet) {
// ref: https://github.com/CosmWasm/wasmd/issues/1735

// === execute a contract sub message ===
_, senderContractAddr := helpers.SetupContract(t, ctx, chain, user.KeyName(), "contracts/cw721_base.wasm.gz", fmt.Sprintf(`{"name":"Reece #00001", "symbol":"juno-reece-test-#00001", "minter":"%s"}`, user.FormattedAddress()))
_, receiverContractAddr := helpers.SetupContract(t, ctx, chain, user.KeyName(), "contracts/cw721_receiver.wasm.gz", `{}`)

// mint a token
res, err := helpers.ExecuteMsgWithFeeReturn(t, ctx, chain, user, senderContractAddr, "", "10000"+chain.Config().Denom, fmt.Sprintf(`{"mint":{"token_id":"00000", "owner":"%s"}}`, user.FormattedAddress()))
fmt.Println("First", res)
require.NoError(t, err)

// this purposely will fail with the current, we are just validating the messsage is not unknown.
// sub message of unknown means the `wasmkeeper.WithMessageHandlerDecorator` is not setup properly.
fail := "ImZhaWwi"
res2, err := helpers.ExecuteMsgWithFeeReturn(t, ctx, chain, user, senderContractAddr, "", "10000"+chain.Config().Denom, fmt.Sprintf(`{"send_nft": { "contract": "%s", "token_id": "00000", "msg": "%s" }}`, receiverContractAddr, fail))
require.NoError(t, err)
fmt.Println("Second", res2)
require.NotEqualValues(t, wasmtypes.ErrUnknownMsg.ABCICode(), res2.Code)
require.NotContains(t, res2.RawLog, "unknown message from the contract")

success := "InN1Y2NlZWQi"
res3, err := helpers.ExecuteMsgWithFeeReturn(t, ctx, chain, user, senderContractAddr, "", "10000"+chain.Config().Denom, fmt.Sprintf(`{"send_nft": { "contract": "%s", "token_id": "00000", "msg": "%s" }}`, receiverContractAddr, success))
require.NoError(t, err)
fmt.Println("Third", res3)
require.EqualValues(t, 0, res3.Code)
require.NotContains(t, res3.RawLog, "unknown message from the contract")
}
5 changes: 4 additions & 1 deletion interchaintest/contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ A list of the contracts here which are pre-compiled in other repos.
> ibchooks_counter.wasm -> <https://github.com/osmosis-labs/osmosis/blob/64393a14e18b2562d72a3892eec716197a3716c7/tests/ibc-hooks/bytecode/counter.wasm>
> cw_testburn.wasm -> <https://github.com/Reecepbcups/cw-testburn>
> clock_example.wasm -> <https://github.com/Reecepbcups/cw-clock-example>
> juno_staking_hooks_example.wasm -> <https://github.com/Reecepbcups/cw-juno-staking-hooks-example>
> juno_staking_hooks_example.wasm -> <https://github.com/Reecepbcups/cw-juno-staking-hooks-example>

> cw721_base - https://github.com/CosmWasm/cw-nfts/releases/download/v0.17.0/cw721_base.wasm
> cw721-receiver - https://github.com/CosmWasm/cw-nfts/pull/144
Binary file added interchaintest/contracts/cw721_base.wasm.gz
Binary file not shown.
Binary file added interchaintest/contracts/cw721_receiver.wasm.gz
Binary file not shown.
45 changes: 22 additions & 23 deletions interchaintest/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ require (
github.com/cosmos/cosmos-sdk v0.47.5
github.com/cosmos/gogoproto v1.4.10
github.com/cosmos/ibc-go/v7 v7.3.1
github.com/docker/docker v24.0.5+incompatible
// github.com/skip-mev/pob/tests/integration v0.1.0
github.com/strangelove-ventures/interchaintest/v7 v7.0.0-20231018200122-b988aa9a3a4b
github.com/docker/docker v24.0.7+incompatible
github.com/strangelove-ventures/interchaintest/v7 v7.0.0
github.com/stretchr/testify v1.8.4
go.uber.org/zap v1.25.0
go.uber.org/zap v1.26.0
)

require (
github.com/cosmos/ibc-go/modules/capability v1.0.0-rc1 // indirect
github.com/cosmos/interchain-security/v3 v3.1.1-0.20231102122221-81650a84f989 // indirect
github.com/opencontainers/runc v1.1.5 // indirect
)

require (
cloud.google.com/go v0.110.4 // indirect
cloud.google.com/go/compute v1.21.0 // indirect
cloud.google.com/go v0.110.7 // indirect
cloud.google.com/go/compute v1.23.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.1 // indirect
cloud.google.com/go/storage v1.30.1 // indirect
Expand All @@ -63,7 +63,6 @@ require (
github.com/armon/go-metrics v0.4.1 // indirect
github.com/avast/retry-go/v4 v4.5.0 // indirect
github.com/aws/aws-sdk-go v1.44.203 // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
Expand All @@ -73,7 +72,7 @@ require (
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chzyer/readline v1.5.1 // indirect
github.com/cockroachdb/errors v1.10.0 // indirect
github.com/cockroachdb/errors v1.11.1 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/coinbase/rosetta-sdk-go/types v1.0.0 // indirect
Expand Down Expand Up @@ -118,16 +117,16 @@ require (
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/gogo/googleapis v1.4.1 // indirect
github.com/gogo/protobuf v1.3.3 // indirect
github.com/golang/glog v1.1.0 // indirect
github.com/golang/glog v1.1.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/orderedcode v0.0.1 // indirect
github.com/google/s2a-go v0.1.4 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
github.com/googleapis/gax-go/v2 v2.11.0 // indirect
github.com/gorilla/handlers v1.5.1 // indirect
Expand Down Expand Up @@ -192,16 +191,16 @@ require (
github.com/pierrec/xxHash v0.1.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/client_golang v1.17.0 // indirect
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.11.0 // indirect
github.com/prometheus/procfs v0.11.1 // indirect
github.com/rakyll/statik v0.1.7 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/rs/cors v1.8.3 // indirect
github.com/rs/zerolog v1.30.0 // indirect
github.com/rs/zerolog v1.31.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/afero v1.9.5 // indirect
Expand All @@ -227,19 +226,19 @@ require (
golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.10.0 // indirect
golang.org/x/sync v0.3.0
golang.org/x/oauth2 v0.11.0 // indirect
golang.org/x/sync v0.4.0
golang.org/x/sys v0.13.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/tools v0.12.0 // indirect
golang.org/x/tools v0.13.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.126.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/grpc v1.58.3 // indirect
google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230913181813-007df8e322eb // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
Expand All @@ -257,6 +256,6 @@ require (
modernc.org/strutil v1.1.3 // indirect
modernc.org/token v1.0.1 // indirect
nhooyr.io/websocket v1.8.7 // indirect
pgregory.net/rapid v1.0.0 // indirect
pgregory.net/rapid v1.1.0 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Loading
Loading