diff --git a/app/app.go b/app/app.go index fb20cffb..cf1a913b 100644 --- a/app/app.go +++ b/app/app.go @@ -13,10 +13,10 @@ import ( authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" + "github.com/terra-money/core/v2/app/custom_queriers" "github.com/terra-money/core/v2/app/keepers" "github.com/terra-money/core/v2/app/post" "github.com/terra-money/core/v2/app/rpc" - tokenfactorybindings "github.com/terra-money/core/v2/x/tokenfactory/bindings" dbm "github.com/cometbft/cometbft-db" abci "github.com/cometbft/cometbft/abci/types" @@ -478,9 +478,10 @@ func (app *TerraApp) GetWasmOpts(appOpts servertypes.AppOptions) []wasmkeeper.Op wasmOpts = append(wasmOpts, wasmkeeper.WithVMCacheMetrics(prometheus.DefaultRegisterer)) } - wasmOpts = append(wasmOpts, tokenfactorybindings.RegisterCustomPlugins( + wasmOpts = append(wasmOpts, custom_queriers.RegisterCustomPlugins( &app.Keepers.BankKeeper.BaseKeeper, - &app.Keepers.TokenFactoryKeeper)..., + &app.Keepers.TokenFactoryKeeper, + &app.Keepers.AllianceKeeper)..., ) return wasmOpts diff --git a/app/custom_queriers/custom_queriers.go b/app/custom_queriers/custom_queriers.go new file mode 100644 index 00000000..5318a798 --- /dev/null +++ b/app/custom_queriers/custom_queriers.go @@ -0,0 +1,52 @@ +package custom_queriers + +import ( + "encoding/json" + "fmt" + "github.com/CosmWasm/wasmd/x/wasm" + wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" + bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + alliancebindings "github.com/terra-money/alliance/x/alliance/bindings" + alliancekeeper "github.com/terra-money/alliance/x/alliance/keeper" + tokenfactorybindings "github.com/terra-money/core/v2/x/tokenfactory/bindings" + tokenfactorykeeper "github.com/terra-money/core/v2/x/tokenfactory/keeper" + "strings" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +type Querier func(ctx sdk.Context, request json.RawMessage) ([]byte, error) + +func CustomQueriers(queriers ...Querier) func(ctx sdk.Context, request json.RawMessage) ([]byte, error) { + return func(ctx sdk.Context, request json.RawMessage) ([]byte, error) { + for _, querier := range queriers { + res, err := querier(ctx, request) + if err == nil || !strings.Contains(err.Error(), "unknown query") { + return res, err + } + } + return nil, fmt.Errorf("unknown query") + } +} + +func RegisterCustomPlugins( + bank *bankkeeper.BaseKeeper, + tokenFactory *tokenfactorykeeper.Keeper, + allianceKeeper *alliancekeeper.Keeper, +) []wasmkeeper.Option { + tfQuerier := tokenfactorybindings.CustomQuerier(tokenfactorybindings.NewQueryPlugin(bank, tokenFactory)) + allianceQuerier := alliancebindings.CustomQuerier(alliancebindings.NewAllianceQueryPlugin(allianceKeeper)) + queriers := CustomQueriers(tfQuerier, allianceQuerier) + + queryPluginOpt := wasmkeeper.WithQueryPlugins(&wasmkeeper.QueryPlugins{ + Custom: queriers, + }) + messengerDecoratorOpt := wasmkeeper.WithMessageHandlerDecorator( + tokenfactorybindings.CustomMessageDecorator(bank, tokenFactory), + ) + + return []wasm.Option{ + queryPluginOpt, + messengerDecoratorOpt, + } +} diff --git a/app/custom_queriers/custom_queriers_test.go b/app/custom_queriers/custom_queriers_test.go new file mode 100644 index 00000000..3da250a9 --- /dev/null +++ b/app/custom_queriers/custom_queriers_test.go @@ -0,0 +1,109 @@ +package custom_queriers + +import ( + "encoding/json" + "fmt" + "runtime" + "testing" + + "github.com/stretchr/testify/require" + alliancebindings "github.com/terra-money/alliance/x/alliance/bindings" + "github.com/terra-money/alliance/x/alliance/bindings/types" + "github.com/terra-money/core/v2/x/tokenfactory/bindings" + types2 "github.com/terra-money/core/v2/x/tokenfactory/bindings/types" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +func AlwaysErrorQuerier(ctx sdk.Context, request json.RawMessage) ([]byte, error) { + return nil, fmt.Errorf("always error") +} + +func AlwaysUnknownQuerier(ctx sdk.Context, request json.RawMessage) ([]byte, error) { + return nil, fmt.Errorf("unknown query") +} + +func AlwaysGoodQuerier(ctx sdk.Context, request json.RawMessage) ([]byte, error) { + return []byte("good"), nil +} + +func TestCustomQueriers(t *testing.T) { + querier := CustomQueriers(AlwaysUnknownQuerier, AlwaysErrorQuerier, AlwaysGoodQuerier) + _, err := querier(sdk.Context{}, nil) + require.ErrorContainsf(t, err, "always error", "") + + querier = CustomQueriers(AlwaysUnknownQuerier, AlwaysGoodQuerier, AlwaysErrorQuerier) + _, err = querier(sdk.Context{}, nil) + require.NoError(t, err) +} + +func TestWithTfAndAllianceButCallAlliance(t *testing.T) { + tfQuerier := bindings.CustomQuerier(&bindings.QueryPlugin{}) + allianceQuerier := alliancebindings.CustomQuerier(&alliancebindings.QueryPlugin{}) + querier := CustomQueriers(tfQuerier, allianceQuerier) + + query := types.AllianceQuery{ + Alliance: &types.Alliance{Denom: "123"}, + } + bz, err := json.Marshal(query) + require.NoError(t, err) + + defer func() { + if r := recover(); r != nil { + stack := make([]byte, 1024) + runtime.Stack(stack, false) + // We make sure alliance is called here + require.Containsf(t, string(stack), "GetAlliance", "") + } + }() + + // We call querier but it will panic because we don't have a keeper + _, err = querier(sdk.Context{}, bz) + require.Fail(t, "should panic") +} + +func TestWithTfAndAllianceButCallTf(t *testing.T) { + tfQuerier := bindings.CustomQuerier(&bindings.QueryPlugin{}) + allianceQuerier := alliancebindings.CustomQuerier(&alliancebindings.QueryPlugin{}) + querier := CustomQueriers(tfQuerier, allianceQuerier) + + query := types2.TokenFactoryQuery{ + Token: &types2.TokenQuery{ + Params: &types2.GetParams{}, + }, + } + bz, err := json.Marshal(query) + require.NoError(t, err) + + defer func() { + if r := recover(); r != nil { + stack := make([]byte, 1024) + runtime.Stack(stack, false) + // We make sure tf is called here + require.Containsf(t, string(stack), "GetParams", "") + } + }() + + // We call querier but it will panic because we don't have a keeper + _, err = querier(sdk.Context{}, bz) + require.Fail(t, "should panic") +} + +func TestWithTfAndAllianceButRandomCall(t *testing.T) { + tfQuerier := bindings.CustomQuerier(&bindings.QueryPlugin{}) + allianceQuerier := alliancebindings.CustomQuerier(&alliancebindings.QueryPlugin{}) + querier := CustomQueriers(tfQuerier, allianceQuerier) + + query := sdk.NewCoin("denom", sdk.NewInt(1)) + bz, err := json.Marshal(query) + require.NoError(t, err) + + // We call querier but it will panic because we don't have a keeper + _, err = querier(sdk.Context{}, bz) + require.Error(t, err) +} + +func TestRegisterCustomPlugins(t *testing.T) { + options := RegisterCustomPlugins(nil, nil, nil) + require.Len(t, options, 2) +} diff --git a/app/upgrades/v2.11/upgrade.go b/app/upgrades/v2.11/upgrade.go index b5155513..15a1de0a 100644 --- a/app/upgrades/v2.11/upgrade.go +++ b/app/upgrades/v2.11/upgrade.go @@ -1,12 +1,13 @@ package v2_11 import ( - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" ibctransferkeeper "github.com/cosmos/ibc-go/v7/modules/apps/transfer/keeper" transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" custombankkeeper "github.com/terra-money/core/v2/x/bank/keeper" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) type EscrowUpdate struct { diff --git a/cmd/terrad/testnet.go b/cmd/terrad/testnet.go index 19655afa..09274316 100644 --- a/cmd/terrad/testnet.go +++ b/cmd/terrad/testnet.go @@ -22,6 +22,7 @@ import ( "cosmossdk.io/math" "cosmossdk.io/simapp" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" diff --git a/go.mod b/go.mod index c75130c1..6095e9c1 100644 --- a/go.mod +++ b/go.mod @@ -31,7 +31,7 @@ require ( github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.16.0 github.com/stretchr/testify v1.8.4 - github.com/terra-money/alliance v0.3.5 + github.com/terra-money/alliance v0.3.6 go.uber.org/mock v0.3.0 google.golang.org/genproto/googleapis/api v0.0.0-20231212172506-995d672761c0 google.golang.org/grpc v1.60.1 diff --git a/go.sum b/go.sum index c23e9313..078fcbde 100644 --- a/go.sum +++ b/go.sum @@ -1134,8 +1134,8 @@ github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70 github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc= github.com/tendermint/go-amino v0.16.0 h1:GyhmgQKvqF82e2oZeuMSp9JTN0N09emoSZlb2lyGa2E= github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME= -github.com/terra-money/alliance v0.3.5 h1:7bLlw9ZUNaFFxGYiKyJKB7x2SV2+6lVvMYbmBm3OORU= -github.com/terra-money/alliance v0.3.5/go.mod h1:HDiUexeXRUkLkLRw5jLQcHuVt1Sx43HfyVl0kfwW3JM= +github.com/terra-money/alliance v0.3.6 h1:FWfix+mKcCrXvdk29MgfXGj0JThOsBxzK81OiSjUMQc= +github.com/terra-money/alliance v0.3.6/go.mod h1:gyenuDQEwyN6mfiOEkaRBaokgk9ryBeU3eCAiZpVKZg= github.com/terra-money/cosmos-sdk v0.47.10-terra.0 h1:vpod9zXeBp8S8JfP0++YzwCvCEMkJnz3qRmz0pciEQI= github.com/terra-money/cosmos-sdk v0.47.10-terra.0/go.mod h1:UWpgWkhcsBIATS68uUC0del7IiBN4hPv/vqg8Zz23uw= github.com/terra-money/ibc-go/v7 v7.3.1-terra.0 h1:CF+iicqyI4BJsW2zjUrUrTxRRrPWFZC30VqvlRyVl28= diff --git a/integration-tests/src/contracts/custom-queries/.cargo/config b/integration-tests/src/contracts/custom-queries/.cargo/config new file mode 100644 index 00000000..cc2a25b6 --- /dev/null +++ b/integration-tests/src/contracts/custom-queries/.cargo/config @@ -0,0 +1,5 @@ +[alias] +wasm = "build --release --target wasm32-unknown-unknown" +wasm-debug = "build --target wasm32-unknown-unknown" +unit-test = "test --lib" +schema = "run --example schema" \ No newline at end of file diff --git a/integration-tests/src/contracts/custom-queries/.gitignore b/integration-tests/src/contracts/custom-queries/.gitignore new file mode 100644 index 00000000..10b1b8c6 --- /dev/null +++ b/integration-tests/src/contracts/custom-queries/.gitignore @@ -0,0 +1,2 @@ +scripts +target \ No newline at end of file diff --git a/integration-tests/src/contracts/custom-queries/Cargo.lock b/integration-tests/src/contracts/custom-queries/Cargo.lock new file mode 100644 index 00000000..07907913 --- /dev/null +++ b/integration-tests/src/contracts/custom-queries/Cargo.lock @@ -0,0 +1,1032 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9" +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] + +[[package]] +name = "anyhow" +version = "1.0.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" + +[[package]] +name = "autocfg" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" + +[[package]] +name = "base16ct" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" + +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + +[[package]] +name = "bech32" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" + +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bnum" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56953345e39537a3e18bdaeba4cb0c58a78c1f61f361dc0fa7c5c7340ae87c5f" + +[[package]] +name = "bumpalo" +version = "3.15.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ff69b9dd49fd426c69a0db9fc04dd934cdb6645ff000864d98f7e2af8830eaa" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" +dependencies = [ + "serde", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + +[[package]] +name = "cosmwasm-crypto" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9934c79e58d9676edfd592557dee765d2a6ef54c09d5aa2edb06156b00148966" +dependencies = [ + "digest 0.10.7", + "ecdsa", + "ed25519-zebra", + "k256", + "rand_core 0.6.4", + "thiserror", +] + +[[package]] +name = "cosmwasm-derive" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc5e72e330bd3bdab11c52b5ecbdeb6a8697a004c57964caeb5d876f0b088b3c" +dependencies = [ + "syn 1.0.109", +] + +[[package]] +name = "cosmwasm-schema" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3e3a2136e2a60e8b6582f5dffca5d1a683ed77bf38537d330bc1dfccd69010" +dependencies = [ + "cosmwasm-schema-derive", + "schemars", + "serde", + "serde_json", + "thiserror", +] + +[[package]] +name = "cosmwasm-schema-derive" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5d803bea6bd9ed61bd1ee0b4a2eb09ee20dbb539cc6e0b8795614d20952ebb1" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "cosmwasm-std" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef8666e572a3a2519010dde88c04d16e9339ae751b56b2bb35081fe3f7d6be74" +dependencies = [ + "base64", + "bech32", + "bnum", + "cosmwasm-crypto", + "cosmwasm-derive", + "derivative", + "forward_ref", + "hex", + "schemars", + "serde", + "serde-json-wasm", + "sha2 0.10.8", + "static_assertions", + "thiserror", +] + +[[package]] +name = "cosmwasm-storage" +version = "1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66de2ab9db04757bcedef2b5984fbe536903ada4a8a9766717a4a71197ef34f6" +dependencies = [ + "cosmwasm-std", + "serde", +] + +[[package]] +name = "cpufeatures" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-bigint" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" +dependencies = [ + "generic-array", + "rand_core 0.6.4", + "subtle", + "zeroize", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "curve25519-dalek" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" +dependencies = [ + "byteorder", + "digest 0.9.0", + "rand_core 0.5.1", + "subtle", + "zeroize", +] + +[[package]] +name = "custom-queries" +version = "0.0.1" +dependencies = [ + "base64", + "bech32", + "cosmwasm-schema", + "cosmwasm-std", + "cosmwasm-storage", + "cw-storage-plus", + "cw-utils", + "cw2", + "hex", + "schemars", + "serde", + "sha2 0.10.8", + "terra-proto-rs", + "thiserror", +] + +[[package]] +name = "cw-storage-plus" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5ff29294ee99373e2cd5fd21786a3c0ced99a52fec2ca347d565489c61b723c" +dependencies = [ + "cosmwasm-std", + "schemars", + "serde", +] + +[[package]] +name = "cw-utils" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c4a657e5caacc3a0d00ee96ca8618745d050b8f757c709babafb81208d4239c" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cw2", + "schemars", + "semver", + "serde", + "thiserror", +] + +[[package]] +name = "cw2" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6c120b24fbbf5c3bedebb97f2cc85fbfa1c3287e09223428e7e597b5293c1fa" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus", + "schemars", + "semver", + "serde", + "thiserror", +] + +[[package]] +name = "der" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" +dependencies = [ + "const-oid", + "zeroize", +] + +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", +] + +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer 0.10.4", + "const-oid", + "crypto-common", + "subtle", +] + +[[package]] +name = "dyn-clone" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" + +[[package]] +name = "ecdsa" +version = "0.16.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" +dependencies = [ + "der", + "digest 0.10.7", + "elliptic-curve", + "rfc6979", + "signature", + "spki", +] + +[[package]] +name = "ed25519-zebra" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c24f403d068ad0b359e577a77f92392118be3f3c927538f2bb544a5ecd828c6" +dependencies = [ + "curve25519-dalek", + "hashbrown", + "hex", + "rand_core 0.6.4", + "serde", + "sha2 0.9.9", + "zeroize", +] + +[[package]] +name = "either" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" + +[[package]] +name = "elliptic-curve" +version = "0.13.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" +dependencies = [ + "base16ct", + "crypto-bigint", + "digest 0.10.7", + "ff", + "generic-array", + "group", + "pkcs8", + "rand_core 0.6.4", + "sec1", + "subtle", + "zeroize", +] + +[[package]] +name = "ff" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" +dependencies = [ + "rand_core 0.6.4", + "subtle", +] + +[[package]] +name = "flex-error" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c606d892c9de11507fa0dcffc116434f94e105d0bbdc4e405b61519464c49d7b" +dependencies = [ + "paste", +] + +[[package]] +name = "forward_ref" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8cbd1169bd7b4a0a20d92b9af7a7e0422888bd38a6f5ec29c1fd8c1558a272e" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", + "zeroize", +] + +[[package]] +name = "getrandom" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi", + "wasm-bindgen", +] + +[[package]] +name = "group" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" +dependencies = [ + "ff", + "rand_core 0.6.4", + "subtle", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = [ + "ahash", +] + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest 0.10.7", +] + +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "k256" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cadb76004ed8e97623117f3df85b17aaa6626ab0b0831e6573f104df16cd1bcc" +dependencies = [ + "cfg-if", + "ecdsa", + "elliptic-curve", + "once_cell", + "sha2 0.10.8", + "signature", +] + +[[package]] +name = "libc" +version = "0.2.153" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" + +[[package]] +name = "log" +version = "0.4.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" + +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + +[[package]] +name = "num-derive" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "num-traits" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "opaque-debug" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" + +[[package]] +name = "paste" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "proc-macro2" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "prost" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b82eaa1d779e9a4bc1c3217db8ffbeabaae1dca241bf70183242128d48681cd" +dependencies = [ + "bytes", + "prost-derive", +] + +[[package]] +name = "prost-derive" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5d2d8d10f3c6ded6da8b05b5fb3b8a5082514344d56c9f871412d29b4e075b4" +dependencies = [ + "anyhow", + "itertools", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "prost-types" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "213622a1460818959ac1181aaeb2dc9c7f63df720db7d788b3e24eacd1983e13" +dependencies = [ + "prost", +] + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rfc6979" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" +dependencies = [ + "hmac", + "subtle", +] + +[[package]] +name = "ryu" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" + +[[package]] +name = "schemars" +version = "0.8.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45a28f4c49489add4ce10783f7911893516f15afe45d015608d41faca6bc4d29" +dependencies = [ + "dyn-clone", + "schemars_derive", + "serde", + "serde_json", +] + +[[package]] +name = "schemars_derive" +version = "0.8.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c767fd6fa65d9ccf9cf026122c1b555f2ef9a4f0cea69da4d7dbc3e258d30967" +dependencies = [ + "proc-macro2", + "quote", + "serde_derive_internals", + "syn 1.0.109", +] + +[[package]] +name = "sec1" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" +dependencies = [ + "base16ct", + "der", + "generic-array", + "pkcs8", + "subtle", + "zeroize", +] + +[[package]] +name = "semver" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" + +[[package]] +name = "serde" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde-json-wasm" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e9213a07d53faa0b8dd81e767a54a8188a242fdb9be99ab75ec576a774bfdd7" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_bytes" +version = "0.11.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b8497c313fd43ab992087548117643f6fcd935cbf36f176ffda0aacf9591734" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_derive" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.55", +] + +[[package]] +name = "serde_derive_internals" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "serde_json" +version = "1.0.115" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha2" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +dependencies = [ + "block-buffer 0.9.0", + "cfg-if", + "cpufeatures", + "digest 0.9.0", + "opaque-debug", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest 0.10.7", +] + +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest 0.10.7", + "rand_core 0.6.4", +] + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "subtle" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" + +[[package]] +name = "subtle-encoding" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dcb1ed7b8330c5eed5441052651dd7a12c75e2ed88f2ec024ae1fa3a5e59945" +dependencies = [ + "zeroize", +] + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "002a1b3dbf967edfafc32655d0f377ab0bb7b994aa1d32c8cc7e9b8bf3ebb8f0" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tendermint-proto" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e553ed65874c3f35a71eb60d255edfea956274b5af37a0297d54bba039fe45e3" +dependencies = [ + "bytes", + "flex-error", + "num-derive", + "num-traits", + "prost", + "prost-types", + "serde", + "serde_bytes", + "subtle-encoding", + "time", +] + +[[package]] +name = "terra-proto-rs" +version = "4.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4449e79ceeaec8e3c9f1be214a969036dc6a2d36934f173afd5cb242ca1eaf6e" +dependencies = [ + "cosmwasm-std", + "getrandom", + "prost", + "prost-types", + "tendermint-proto", +] + +[[package]] +name = "thiserror" +version = "1.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.55", +] + +[[package]] +name = "time" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8248b6521bb14bc45b4067159b9b6ad792e2d6d754d6c41fb50e29fefe38749" +dependencies = [ + "deranged", + "num-conv", + "powerfmt", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "time-macros" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ba3a3ef41e6672a2f0f001392bb5dcd3ff0a9992d618ca761a11c3121547774" +dependencies = [ + "num-conv", + "time-core", +] + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.55", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.55", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" + +[[package]] +name = "zeroize" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/integration-tests/src/contracts/custom-queries/Cargo.toml b/integration-tests/src/contracts/custom-queries/Cargo.toml new file mode 100644 index 00000000..13578cd1 --- /dev/null +++ b/integration-tests/src/contracts/custom-queries/Cargo.toml @@ -0,0 +1,30 @@ +[package] +name = "custom-queries" +version = "0.0.1" +authors = ["Terra Money "] +edition = "2021" +exclude = ["contract.wasm", "hash.txt"] + +[lib] +crate-type = ["cdylib", "rlib"] + +[features] +backtraces = ["cosmwasm-std/backtraces"] +stargate = ["cosmwasm-std/stargate"] +library = [] + +[dependencies] +cosmwasm-std = { version = "1.5.3", default-features = false ,features = ["stargate", "cosmwasm_1_4"] } +cosmwasm-storage = "1.5.2" +cosmwasm-schema = "1.5.3" +cw-storage-plus = "1.2.0" +cw2 = "1.1.2" +bech32 = "0.9.1" +schemars = "0.8.16" +serde = { version = "1.0.196", default-features = false, features = ["derive"] } +terra-proto-rs = { version = "4.0.4", default-features = false} +thiserror = { version = "1.0.57" } +cw-utils = "1.0.3" +sha2 = {version = "0.10.8"} +base64 = "0.21.7" +hex = "0.4.3" \ No newline at end of file diff --git a/integration-tests/src/contracts/custom-queries/Makefile.toml b/integration-tests/src/contracts/custom-queries/Makefile.toml new file mode 100644 index 00000000..bd19090d --- /dev/null +++ b/integration-tests/src/contracts/custom-queries/Makefile.toml @@ -0,0 +1,57 @@ +[config] +default_to_workspace = false +skip_core_tasks = true + +[tasks.fmt] +command = "cargo" +args = ["fmt", "--all", "--check"] + +[tasks.fmt-apply] +command = "cargo" +args = ["fmt"] + +[tasks.test] +command = "cargo" +args = ["test", "--locked"] + +[tasks.test-cover] +script = """docker run --security-opt seccomp=unconfined -v "${PWD}:/volume" xd009642/tarpaulin""" + +[tasks.test-cover-to-file] +script = "cargo tarpaulin --out Lcov" + +[tasks.lint] +command = "cargo" +args = ["clippy", "--tests", "--", "-D", "warnings"] + +[tasks.build] +command = "cargo" +args = ["build", "--release", "--locked", "--target", "wasm32-unknown-unknown"] + +[tasks.schema] +script = """ +for d in contracts/*; do + if [ -d "$d" ]; then + cd $d + cargo schema + cd ../.. + fi +done +""" + +[tasks.optimize] +script = """ +if [[ $(arch) == "arm64" ]]; then + image="cosmwasm/optimizer-arm64" +else + image="cosmwasm/optimizer" +fi + +docker run --rm -v "$(pwd)":/code \ + --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \ + --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ + ${image}:0.15.0 + +rm -rf scripts/artifacts +mv artifacts/ scripts/ +""" diff --git a/integration-tests/src/contracts/custom-queries/examples/schema.rs b/integration-tests/src/contracts/custom-queries/examples/schema.rs new file mode 100644 index 00000000..e2bd81b7 --- /dev/null +++ b/integration-tests/src/contracts/custom-queries/examples/schema.rs @@ -0,0 +1,12 @@ +use cosmwasm_schema::write_api; +use smart_accounts_packages::{ + instantiate_models::InstantiateMsg, query_models::QueryMsg, sudo_models::SudoMsg, +}; + +fn main() { + write_api! { + instantiate: InstantiateMsg, + sudo: SudoMsg, + query: QueryMsg, + } +} diff --git a/integration-tests/src/contracts/custom-queries/src/custom_query.rs b/integration-tests/src/contracts/custom-queries/src/custom_query.rs new file mode 100644 index 00000000..44c13f98 --- /dev/null +++ b/integration-tests/src/contracts/custom-queries/src/custom_query.rs @@ -0,0 +1,124 @@ +use cosmwasm_schema::{cw_serde, QueryResponses}; +use cosmwasm_std::CustomQuery; + +#[cw_serde] +#[derive(QueryResponses)] +pub enum CustomQueries { + #[returns(AllianceResponse)] + Alliance { denom: String }, + #[returns(DelegationResponse)] + Delegation { denom: String, validator: String, delegator: String }, + #[returns(DelegationRewardsResponse)] + DelegationRewards { denom: String, validator: String, delegator: String }, + + #[returns(TokenFactoryResponses)] + Token(TokenQuery) +} + +#[cw_serde] +pub enum TokenQuery { + FullDenom { creator_addr: String, subdenom: String }, + Admin { denom: String }, + Metadata { denom: String }, + DenomsByCreator { creator: String }, + Params {}, +} + +impl CustomQuery for CustomQueries {} + +#[cw_serde] +pub struct RewardWeightRange { + pub min: String, + pub max: String, +} + +#[cw_serde] +pub struct AllianceResponse { + pub denom: String, + pub reward_weight: String, + pub take_rate: String, + pub total_tokens: String, + pub total_validator_shares: String, + pub reward_start_time: u64, + pub reward_change_rate: String, + pub last_reward_change_time: u64, + pub reward_weight_range: RewardWeightRange, + pub is_initialized: bool, + +} + +#[cw_serde] +pub struct DelegationResponse { + pub delegator: String, + pub validator: String, + pub denom: String, + pub amount: String, +} + +#[cw_serde] +pub struct DelegationRewardsResponse { + pub rewards: Vec, +} + +#[cw_serde] +pub enum TokenFactoryResponses { + FullDenomResponse(FullDenomResponse), + AdminResponse(AdminResponse), + DenumUnit(DenomUnit), + MetadataReponse(MetadataResponse), + DenomsByCreatorResponse(DenomsByCreatorResponse), + ParamsResponse(ParamsResponse), +} + +#[cw_serde] + pub struct FullDenomResponse { + pub denom: String, +} + +#[cw_serde] +pub struct AdminResponse { + pub admin: String, +} + +#[cw_serde] +pub struct DenomUnit { + pub denom: String, + pub exponent: u32, + pub aliases: Vec, +} + +#[cw_serde] +pub struct Metadata { + pub description: String, + pub denom_units: Vec, + pub base: String, + pub display: String, + pub name: String, + pub symbol: String, +} + +#[cw_serde] +pub struct MetadataResponse { + pub metadata: Option, +} + +#[cw_serde] +pub struct DenomsByCreatorResponse { + pub denoms: Vec, +} + +#[cw_serde] +pub struct Coin { + pub denom: String, + pub amount: String, +} + +#[cw_serde] +pub struct Params { + pub denom_creation_fee: Vec, +} + +#[cw_serde] +pub struct ParamsResponse { + pub params: Params, +} \ No newline at end of file diff --git a/integration-tests/src/contracts/custom-queries/src/lib.rs b/integration-tests/src/contracts/custom-queries/src/lib.rs new file mode 100644 index 00000000..638f9551 --- /dev/null +++ b/integration-tests/src/contracts/custom-queries/src/lib.rs @@ -0,0 +1,65 @@ +pub mod custom_query; + +use cosmwasm_std::{entry_point, Deps, DepsMut, Env, MessageInfo, Response, StdError, Binary, QueryRequest, to_json_binary, StdResult}; +use cosmwasm_schema::{cw_serde}; +use cw2::set_contract_version; +use crate::custom_query::{CustomQueries, AllianceResponse, DelegationResponse, DelegationRewardsResponse, TokenQuery, FullDenomResponse, AdminResponse, MetadataResponse, DenomsByCreatorResponse, ParamsResponse}; + +const CONTRACT_NAME: &str = "crates.io:smart-auth"; +const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); + +#[cw_serde] +pub struct InstantiateMsg {} + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn instantiate( + deps: DepsMut, + _env: Env, + _info: MessageInfo, + _msg: InstantiateMsg, +) -> Result { + set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; + Ok(Response::new().add_attribute("contract", format!("{} {}", CONTRACT_NAME, CONTRACT_VERSION))) +} + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn query(deps: Deps, _env: Env, msg: CustomQueries) -> StdResult { + match msg.clone() { + CustomQueries::Alliance {..} => { + let res: AllianceResponse = deps.querier.query(&QueryRequest::Custom(msg))?; + to_json_binary(&res) + }, + CustomQueries::Delegation {..} => { + let res: DelegationResponse = deps.querier.query(&QueryRequest::Custom(msg))?; + to_json_binary(&res) + } + CustomQueries::DelegationRewards {..}=> { + let res: DelegationRewardsResponse = deps.querier.query(&QueryRequest::Custom(msg))?; + to_json_binary(&res) + }, + CustomQueries::Token(TokenQuery) => { + match TokenQuery { + TokenQuery::FullDenom { .. } => { + let res: FullDenomResponse = deps.querier.query(&QueryRequest::Custom(msg))?; + to_json_binary(&res) + }, + TokenQuery::Admin { .. } => { + let res: AdminResponse= deps.querier.query(&QueryRequest::Custom(msg))?; + to_json_binary(&res) + }, + TokenQuery::Metadata { .. } => { + let res: MetadataResponse= deps.querier.query(&QueryRequest::Custom(msg))?; + to_json_binary(&res) + } + TokenQuery::DenomsByCreator { .. } => { + let res: DenomsByCreatorResponse = deps.querier.query(&QueryRequest::Custom(msg))?; + to_json_binary(&res) + } + TokenQuery::Params { .. } => { + let res: ParamsResponse = deps.querier.query(&QueryRequest::Custom(msg))?; + to_json_binary(&res) + } + } + } + } +} \ No newline at end of file diff --git a/integration-tests/src/contracts/custom_queries.wasm b/integration-tests/src/contracts/custom_queries.wasm new file mode 100644 index 00000000..2091733c Binary files /dev/null and b/integration-tests/src/contracts/custom_queries.wasm differ diff --git a/integration-tests/src/modules/alliance/alliance.test.ts b/integration-tests/src/modules/alliance/alliance.test.ts index 804308a9..db47cef4 100644 --- a/integration-tests/src/modules/alliance/alliance.test.ts +++ b/integration-tests/src/modules/alliance/alliance.test.ts @@ -1,19 +1,37 @@ import { getLCDClient, getMnemonics, blockInclusion, votingPeriod } from "../../helpers"; -import { Coin, MsgTransfer, MsgCreateAlliance, Coins, MsgVote, Fee, MsgAllianceDelegate, MsgClaimDelegationRewards, MsgAllianceUndelegate, MsgDeleteAlliance, MsgSubmitProposal } from "@terra-money/feather.js"; +import { + Coin, + MsgTransfer, + MsgCreateAlliance, + Coins, + MsgVote, + Fee, + MsgAllianceDelegate, + MsgClaimDelegationRewards, + MsgAllianceUndelegate, + MsgDeleteAlliance, + MsgSubmitProposal, + MsgStoreCode, MsgInstantiateContract +} from "@terra-money/feather.js"; import { VoteOption } from "@terra-money/terra.proto/cosmos/gov/v1beta1/gov"; import { Height } from "@terra-money/feather.js/dist/core/ibc/core/client/Height"; +import fs from "fs"; +import path from "path"; describe("Alliance Module (https://github.com/terra-money/alliance/tree/release/v0.3.x) ", () => { // Prepare environment clients, accounts and wallets const LCD = getLCDClient(); const accounts = getMnemonics(); const chain1Wallet = LCD.chain1.wallet(accounts.allianceMnemonic); + const allianceWallet2 = LCD.chain2.wallet(accounts.allianceMnemonic); const val2Wallet = LCD.chain2.wallet(accounts.val2); const val2WalletAddress = val2Wallet.key.accAddress("terra"); const val2Address = val2Wallet.key.valAddress("terra"); const allianceAccountAddress = accounts.allianceMnemonic.accAddress("terra"); // This will be populated in the "Must create an alliance" let ibcCoin = Coin.fromString("1uluna"); + let allianceQueryCodeId: number; + let allianceQueryContract: string; // Send uluna from chain-1 to chain-2 using // the same wallet on both chains and start @@ -218,15 +236,88 @@ describe("Alliance Module (https://github.com/terra-money/alliance/tree/release/ }) }); + describe("Alliance wasm queries", () => { + beforeAll(async () => { + + // Deploy query contract + let tx = await allianceWallet2.createAndSignTx({ + msgs: [ + new MsgStoreCode(allianceAccountAddress, fs.readFileSync(path.join(__dirname, "/../../contracts/custom_queries.wasm")).toString("base64")), + ], + chainID: "test-2", + }); + + let result = await LCD.chain2.tx.broadcastSync(tx, "test-2"); + await blockInclusion(); + + let txResult = await LCD.chain2.tx.txInfo(result.txhash, "test-2") as any; + allianceQueryCodeId = Number(txResult.logs[0].events[1].attributes[1].value); + expect(allianceQueryCodeId).toBeDefined(); + + // Instantiate query contract + tx = await allianceWallet2.createAndSignTx({ + msgs: [new MsgInstantiateContract( + allianceAccountAddress, + allianceAccountAddress, + allianceQueryCodeId, + {}, + undefined, + "Alliance query contract" + Math.random(), + )], + chainID: "test-2", + }); + result = await LCD.chain2.tx.broadcastSync(tx, "test-2"); + await blockInclusion(); + + txResult = await LCD.chain2.tx.txInfo(result.txhash, "test-2") as any; + allianceQueryContract = txResult.logs[0].events[1].attributes[0].value; + expect(allianceQueryContract).toBeDefined(); + }) + + test("Must be able to query alliance state in CosmWasm", async () => { + + let res = await LCD.chain2.wasm.contractQuery(allianceQueryContract, { + alliance: { + denom: ibcCoin.denom + } + }) as any; + expect(res.denom).toEqual(ibcCoin.denom); + + res = await LCD.chain2.wasm.contractQuery(allianceQueryContract, { + delegation: { + denom: ibcCoin.denom, + validator: val2Address, + delegator: allianceAccountAddress, + } + }) as any; + expect(res).toStrictEqual({ + delegator: allianceAccountAddress, + validator: val2Address, + denom: ibcCoin.denom, + amount: "1000", + }); + + await blockInclusion(); + res = await LCD.chain2.wasm.contractQuery(allianceQueryContract, { + delegation_rewards: { + denom: ibcCoin.denom, + validator: val2Address, + delegator: allianceAccountAddress, + } + }) as any; + expect(res.rewards.length).toEqual(1); + }) + }) + describe("After delegation", () => { test("Must claim rewards from the alliance", async () => { const allianceWallet2 = LCD.chain2.wallet(accounts.allianceMnemonic); let ibcCoin = (await LCD.chain2.bank.balance(allianceAccountAddress))[0].find(c => c.denom.startsWith("ibc/")) as Coin; let tx = await allianceWallet2.createAndSignTx({ - msgs: [ - new MsgClaimDelegationRewards( - allianceAccountAddress, - val2Address, + msgs: [ + new MsgClaimDelegationRewards( + allianceAccountAddress, + val2Address, ibcCoin.denom, ), ], diff --git a/integration-tests/src/modules/tokenfactory/tokenfactory.test.ts b/integration-tests/src/modules/tokenfactory/tokenfactory.test.ts index fbb73b45..79014180 100644 --- a/integration-tests/src/modules/tokenfactory/tokenfactory.test.ts +++ b/integration-tests/src/modules/tokenfactory/tokenfactory.test.ts @@ -13,6 +13,7 @@ describe("TokenFactory Module (https://github.com/terra-money/core/tree/release/ let contractAddress: string; let subdenom = Math.random().toString(36).substring(7); let factoryDenom: string | undefined = undefined + let customQueryContractAddress: string; // Read the no100 contract, store on chain, // instantiate to be used in the following tests @@ -547,4 +548,54 @@ describe("TokenFactory Module (https://github.com/terra-money/core/tree/release/ expect(res.denoms.length).toBeGreaterThanOrEqual(1); }) }) + + describe("Query using CosmWasm", () => { + beforeAll(async () => { + // Deploy alliance query contract + let tx = await wallet.createAndSignTx({ + msgs: [ + new MsgStoreCode(tokenFactoryWalletAddr, fs.readFileSync(path.join(__dirname, "/../../contracts/custom_queries.wasm")).toString("base64")), + ], + chainID: "test-1", + }); + + let result = await LCD.chain1.tx.broadcastSync(tx, "test-1"); + await blockInclusion(); + + let txResult = await LCD.chain1.tx.txInfo(result.txhash, "test-1") as any; + let customQueryCodeId = Number(txResult.logs[0].events[1].attributes[1].value); + expect(customQueryCodeId).toBeDefined(); + + // Instantiate alliance query contract + tx = await wallet.createAndSignTx({ + msgs: [new MsgInstantiateContract( + tokenFactoryWalletAddr, + tokenFactoryWalletAddr, + customQueryCodeId, + {}, + undefined, + "Alliance query contract" + Math.random(), + )], + chainID: "test-1", + }); + result = await LCD.chain1.tx.broadcastSync(tx, "test-1"); + await blockInclusion(); + + txResult = await LCD.chain1.tx.txInfo(result.txhash, "test-1") as any; + customQueryContractAddress = txResult.logs[0].events[1].attributes[0].value; + expect(customQueryContractAddress).toBeDefined(); + }) + test("Must query token data using contract", async () => { + let res = await LCD.chain1.wasm.contractQuery(customQueryContractAddress, { + token: { + admin: { + denom: factoryDenom + } + } + }) as any; + expect(res).toStrictEqual({ + admin: randomAccountAddr + }); + }) + }) }); \ No newline at end of file diff --git a/x/tokenfactory/bindings/query_plugin.go b/x/tokenfactory/bindings/query_plugin.go index 085d1a1a..0bf55a67 100644 --- a/x/tokenfactory/bindings/query_plugin.go +++ b/x/tokenfactory/bindings/query_plugin.go @@ -21,7 +21,7 @@ func CustomQuerier(qp *QueryPlugin) func(ctx sdk.Context, request json.RawMessag return nil, errorsmod.Wrap(err, "failed query") } if contractQuery.Token == nil { - return nil, errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "nil token field") + return nil, errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "unknown query: nil token field") } tokenQuery := contractQuery.Token @@ -99,7 +99,7 @@ func CustomQuerier(qp *QueryPlugin) func(ctx sdk.Context, request json.RawMessag return bz, nil default: - return nil, wasmvmtypes.UnsupportedRequest{Kind: "unknown token query variant"} + return nil, wasmvmtypes.UnsupportedRequest{Kind: "unknown query"} } } } diff --git a/x/tokenfactory/bindings/wasm.go b/x/tokenfactory/bindings/wasm.go index 1850b774..e0dd9d4b 100644 --- a/x/tokenfactory/bindings/wasm.go +++ b/x/tokenfactory/bindings/wasm.go @@ -1,28 +1,2 @@ package bindings -import ( - "github.com/CosmWasm/wasmd/x/wasm" - wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" - tokenfactorykeeper "github.com/terra-money/core/v2/x/tokenfactory/keeper" - - bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" -) - -func RegisterCustomPlugins( - bank *bankkeeper.BaseKeeper, - tokenFactory *tokenfactorykeeper.Keeper, -) []wasmkeeper.Option { - wasmQueryPlugin := NewQueryPlugin(bank, tokenFactory) - - queryPluginOpt := wasmkeeper.WithQueryPlugins(&wasmkeeper.QueryPlugins{ - Custom: CustomQuerier(wasmQueryPlugin), - }) - messengerDecoratorOpt := wasmkeeper.WithMessageHandlerDecorator( - CustomMessageDecorator(bank, tokenFactory), - ) - - return []wasm.Option{ - queryPluginOpt, - messengerDecoratorOpt, - } -}