diff --git a/integration-tests/contracts/modules/ft/Cargo.lock b/integration-tests/contracts/modules/ft/Cargo.lock index 0b33fc369..55188b20d 100644 --- a/integration-tests/contracts/modules/ft/Cargo.lock +++ b/integration-tests/contracts/modules/ft/Cargo.lock @@ -108,9 +108,9 @@ checksum = "28c122c3980598d243d63d9a704629a2d748d101f278052ff068be5a4423ab6f" [[package]] name = "coreum-wasm-sdk" -version = "0.2.1" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb106415d1ea995f54efbc3165fa0cc8d0b3a292a1fb2e74dcd1eb0447e7584e" +checksum = "de2207655b1d9ddbb228d96b9900d8726ebead2d382a893492806230ead2daa0" dependencies = [ "chrono", "cosmwasm-schema", @@ -365,9 +365,9 @@ dependencies = [ [[package]] name = "dyn-clone" -version = "1.0.14" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23d2f3407d9a573d666de4b5bdf10569d73ca9478087346697dcbae6244bfbcd" +checksum = "545b22097d44f8a9581187cdf93de7a71e4722bf51200cfaba810865b49a495d" [[package]] name = "ecdsa" @@ -550,9 +550,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.149" +version = "0.2.150" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" +checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" [[package]] name = "num-traits" @@ -650,7 +650,7 @@ dependencies = [ "itertools 0.11.0", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -790,7 +790,7 @@ checksum = "67c5609f394e5c2bd7fc51efda478004ea80ef42fee983d5c67a65e34f32c0e3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -884,9 +884,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.38" +version = "2.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" +checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" dependencies = [ "proc-macro2", "quote", @@ -910,7 +910,7 @@ checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] diff --git a/integration-tests/contracts/modules/ft/Cargo.toml b/integration-tests/contracts/modules/ft/Cargo.toml index be26ef65e..4aee70a95 100644 --- a/integration-tests/contracts/modules/ft/Cargo.toml +++ b/integration-tests/contracts/modules/ft/Cargo.toml @@ -28,11 +28,11 @@ backtraces = ["cosmwasm-std/backtraces"] library = [] [dependencies] -cosmwasm-std = "1.4.1" -cosmwasm-storage = "1.4.1" +cosmwasm-std = "1.5.0" +cosmwasm-storage = "1.5.0" cw-storage-plus = "1.1.0" cw2 = "1.1.1" thiserror = "1.0.50" -coreum-wasm-sdk = "0.2.1" +coreum-wasm-sdk = "0.2.3" cosmwasm-schema = "1.4.1" cw-ownable = "0.5.1" diff --git a/integration-tests/contracts/modules/ft/README.md b/integration-tests/contracts/modules/ft/README.md index ab1ead004..c0fae1f6b 100644 --- a/integration-tests/contracts/modules/ft/README.md +++ b/integration-tests/contracts/modules/ft/README.md @@ -27,9 +27,9 @@ For more detailed information of the AssetFT module and functionality go to [Ass # Messages -### Mint (amount) [Mint](https://github.com/CoreumFoundation/coreum/tree/master/x/asset/ft/spec#mint) +### Mint (amount, recipient) [Mint](https://github.com/CoreumFoundation/coreum/tree/master/x/asset/ft/spec#mint) -The contract (issuer) will mint the amount of tokens provided. +The contract (issuer) will mint the amount of tokens provided to the corresponding recipient. ### Burn (amount) [Burn](https://github.com/CoreumFoundation/coreum/tree/master/x/asset/ft/spec#burn) @@ -55,10 +55,6 @@ Globally unfreezes the token. Sets a whitelisted limit for an account. -### MintAndSend (account, amount) - -Combines the Mint feature described above with a bank transfer for convenience. - # Queries ### Params diff --git a/integration-tests/contracts/modules/ft/src/contract.rs b/integration-tests/contracts/modules/ft/src/contract.rs index 295b07ccb..2e30087c3 100644 --- a/integration-tests/contracts/modules/ft/src/contract.rs +++ b/integration-tests/contracts/modules/ft/src/contract.rs @@ -4,8 +4,8 @@ use coreum_wasm_sdk::assetft::{ }; use coreum_wasm_sdk::core::{CoreumMsg, CoreumQueries, CoreumResult}; use coreum_wasm_sdk::pagination::PageRequest; -use cosmwasm_std::{coin, entry_point, to_binary, Binary, Deps, QueryRequest, StdResult}; -use cosmwasm_std::{Coin, DepsMut, Env, MessageInfo, Response, SubMsg}; +use cosmwasm_std::{coin, entry_point, to_json_binary, Binary, Deps, QueryRequest, StdResult}; +use cosmwasm_std::{DepsMut, Env, MessageInfo, Response}; use cw2::set_contract_version; use cw_ownable::{assert_owner, initialize_owner}; @@ -62,27 +62,28 @@ pub fn execute( msg: ExecuteMsg, ) -> CoreumResult<ContractError> { match msg { - ExecuteMsg::Mint { amount } => mint(deps, info, amount), + ExecuteMsg::Mint { amount, recipient } => mint(deps, info, amount, recipient), ExecuteMsg::Burn { amount } => burn(deps, info, amount), ExecuteMsg::Freeze { account, amount } => freeze(deps, info, account, amount), ExecuteMsg::Unfreeze { account, amount } => unfreeze(deps, info, account, amount), + ExecuteMsg::SetFrozen { account, amount } => set_frozen(deps, info, account, amount), ExecuteMsg::GloballyFreeze {} => globally_freeze(deps, info), ExecuteMsg::GloballyUnfreeze {} => globally_unfreeze(deps, info), ExecuteMsg::SetWhitelistedLimit { account, amount } => { set_whitelisted_limit(deps, info, account, amount) } - ExecuteMsg::MintAndSend { account, amount } => mint_and_send(deps, info, account, amount), ExecuteMsg::UpgradeTokenV1 { ibc_enabled } => upgrate_token_v1(deps, info, ibc_enabled), } } // ********** Transactions ********** -fn mint(deps: DepsMut, info: MessageInfo, amount: u128) -> CoreumResult<ContractError> { +fn mint(deps: DepsMut, info: MessageInfo, amount: u128, recipient: Option<String>) -> CoreumResult<ContractError> { assert_owner(deps.storage, &info.sender)?; let denom = DENOM.load(deps.storage)?; let msg = CoreumMsg::AssetFT(assetft::Msg::Mint { coin: coin(amount, denom.clone()), + recipient, }); Ok(Response::new() @@ -149,6 +150,27 @@ fn unfreeze( .add_message(msg)) } +fn set_frozen( + deps: DepsMut, + info: MessageInfo, + account: String, + amount: u128, +) -> CoreumResult<ContractError> { + assert_owner(deps.storage, &info.sender)?; + let denom = DENOM.load(deps.storage)?; + + let msg = CoreumMsg::AssetFT(assetft::Msg::SetFrozen { + account, + coin: coin(amount, denom.clone()), + }); + + Ok(Response::new() + .add_attribute("method", "set_frozen") + .add_attribute("denom", denom) + .add_attribute("amount", amount.to_string()) + .add_message(msg)) +} + fn globally_freeze(deps: DepsMut, info: MessageInfo) -> CoreumResult<ContractError> { assert_owner(deps.storage, &info.sender)?; let denom = DENOM.load(deps.storage)?; @@ -198,34 +220,6 @@ fn set_whitelisted_limit( .add_message(msg)) } -fn mint_and_send( - deps: DepsMut, - info: MessageInfo, - account: String, - amount: u128, -) -> CoreumResult<ContractError> { - assert_owner(deps.storage, &info.sender)?; - let denom = DENOM.load(deps.storage)?; - - let mint_msg = SubMsg::new(CoreumMsg::AssetFT(assetft::Msg::Mint { - coin: coin(amount, denom.clone()), - })); - - let send_msg = SubMsg::new(cosmwasm_std::BankMsg::Send { - to_address: account, - amount: vec![Coin { - amount: amount.into(), - denom: denom.clone(), - }], - }); - - Ok(Response::new() - .add_attribute("method", "mint_and_send") - .add_attribute("denom", denom) - .add_attribute("amount", amount.to_string()) - .add_submessages([mint_msg, send_msg])) -} - fn upgrate_token_v1( deps: DepsMut, info: MessageInfo, @@ -250,17 +244,17 @@ fn upgrate_token_v1( #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps<CoreumQueries>, _env: Env, msg: QueryMsg) -> StdResult<Binary> { match msg { - QueryMsg::Params {} => to_binary(&query_params(deps)?), - QueryMsg::Token {} => to_binary(&query_token(deps)?), - QueryMsg::Tokens { issuer } => to_binary(&query_tokens(deps, issuer)?), - QueryMsg::FrozenBalance { account } => to_binary(&query_frozen_balance(deps, account)?), + QueryMsg::Params {} => to_json_binary(&query_params(deps)?), + QueryMsg::Token {} => to_json_binary(&query_token(deps)?), + QueryMsg::Tokens { issuer } => to_json_binary(&query_tokens(deps, issuer)?), + QueryMsg::FrozenBalance { account } => to_json_binary(&query_frozen_balance(deps, account)?), QueryMsg::WhitelistedBalance { account } => { - to_binary(&query_whitelisted_balance(deps, account)?) + to_json_binary(&query_whitelisted_balance(deps, account)?) } - QueryMsg::Balance { account } => to_binary(&query_balance(deps, account)?), - QueryMsg::FrozenBalances { account } => to_binary(&query_frozen_balances(deps, account)?), + QueryMsg::Balance { account } => to_json_binary(&query_balance(deps, account)?), + QueryMsg::FrozenBalances { account } => to_json_binary(&query_frozen_balances(deps, account)?), QueryMsg::WhitelistedBalances { account } => { - to_binary(&query_whitelisted_balances(deps, account)?) + to_json_binary(&query_whitelisted_balances(deps, account)?) } } } diff --git a/integration-tests/contracts/modules/ft/src/msg.rs b/integration-tests/contracts/modules/ft/src/msg.rs index dd1cae77a..a28b31793 100644 --- a/integration-tests/contracts/modules/ft/src/msg.rs +++ b/integration-tests/contracts/modules/ft/src/msg.rs @@ -17,15 +17,14 @@ pub struct InstantiateMsg { #[cw_serde] pub enum ExecuteMsg { - Mint { amount: u128 }, + Mint { amount: u128, recipient: Option<String> }, Burn { amount: u128 }, Freeze { account: String, amount: u128 }, Unfreeze { account: String, amount: u128 }, + SetFrozen { account: String, amount: u128 }, GloballyFreeze {}, GloballyUnfreeze {}, SetWhitelistedLimit { account: String, amount: u128 }, - // custom message we use to show the submission of multiple messages - MintAndSend { account: String, amount: u128 }, UpgradeTokenV1 { ibc_enabled: bool }, } diff --git a/integration-tests/contracts/modules/nft.go b/integration-tests/contracts/modules/nft.go index 94a0bac79..cdf5e0b25 100644 --- a/integration-tests/contracts/modules/nft.go +++ b/integration-tests/contracts/modules/nft.go @@ -24,10 +24,11 @@ type IssueNFTRequest struct { // //nolint:tagliatelle type NftMintRequest struct { - ID string `json:"id"` - URI string `json:"uri"` - URIHash string `json:"uri_hash"` - Data string `json:"data"` + ID string `json:"id"` + URI string `json:"uri"` + URIHash string `json:"uri_hash"` + Data string `json:"data"` + Recipient string `json:"recipient"` } // NftIDRequest is used to query NFT with ID. diff --git a/integration-tests/contracts/modules/nft/Cargo.lock b/integration-tests/contracts/modules/nft/Cargo.lock index 20e233f0e..5f092cb10 100644 --- a/integration-tests/contracts/modules/nft/Cargo.lock +++ b/integration-tests/contracts/modules/nft/Cargo.lock @@ -108,9 +108,9 @@ checksum = "28c122c3980598d243d63d9a704629a2d748d101f278052ff068be5a4423ab6f" [[package]] name = "coreum-wasm-sdk" -version = "0.2.1" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb106415d1ea995f54efbc3165fa0cc8d0b3a292a1fb2e74dcd1eb0447e7584e" +checksum = "de2207655b1d9ddbb228d96b9900d8726ebead2d382a893492806230ead2daa0" dependencies = [ "chrono", "cosmwasm-schema", @@ -365,9 +365,9 @@ dependencies = [ [[package]] name = "dyn-clone" -version = "1.0.14" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23d2f3407d9a573d666de4b5bdf10569d73ca9478087346697dcbae6244bfbcd" +checksum = "545b22097d44f8a9581187cdf93de7a71e4722bf51200cfaba810865b49a495d" [[package]] name = "ecdsa" @@ -536,9 +536,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.149" +version = "0.2.150" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" +checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" [[package]] name = "nft" @@ -650,7 +650,7 @@ dependencies = [ "itertools 0.11.0", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -790,7 +790,7 @@ checksum = "67c5609f394e5c2bd7fc51efda478004ea80ef42fee983d5c67a65e34f32c0e3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -884,9 +884,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.38" +version = "2.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" +checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" dependencies = [ "proc-macro2", "quote", @@ -910,7 +910,7 @@ checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] diff --git a/integration-tests/contracts/modules/nft/Cargo.toml b/integration-tests/contracts/modules/nft/Cargo.toml index af69fbcf8..b16cf4fdf 100644 --- a/integration-tests/contracts/modules/nft/Cargo.toml +++ b/integration-tests/contracts/modules/nft/Cargo.toml @@ -28,11 +28,11 @@ backtraces = ["cosmwasm-std/backtraces"] library = [] [dependencies] -cosmwasm-std = "1.4.1" -cosmwasm-storage = "1.4.1" +cosmwasm-std = "1.5.0" +cosmwasm-storage = "1.5.0" cw-storage-plus = "1.1.0" cw2 = "1.1.1" thiserror = { version = "1.0.50" } -coreum-wasm-sdk = "0.2.1" -cosmwasm-schema = "1.4.1" +coreum-wasm-sdk = "0.2.3" +cosmwasm-schema = "1.5.0" cw-ownable = "0.5.1" diff --git a/integration-tests/contracts/modules/nft/src/contract.rs b/integration-tests/contracts/modules/nft/src/contract.rs index 7cbbac968..241c565f6 100644 --- a/integration-tests/contracts/modules/nft/src/contract.rs +++ b/integration-tests/contracts/modules/nft/src/contract.rs @@ -7,7 +7,7 @@ use coreum_wasm_sdk::core::{CoreumMsg, CoreumQueries, CoreumResult}; use coreum_wasm_sdk::nft; use coreum_wasm_sdk::pagination::PageRequest; use cosmwasm_std::{ - entry_point, to_binary, Binary, Deps, DepsMut, Env, MessageInfo, QueryRequest, Response, + entry_point, to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, QueryRequest, Response, StdResult, }; use cw2::set_contract_version; @@ -68,7 +68,8 @@ pub fn execute( uri, uri_hash, data, - } => mint(deps, info, id, uri, uri_hash, data), + recipient, + } => mint(deps, info, id, uri, uri_hash, data, recipient), ExecuteMsg::Burn { id } => burn(deps, info, id), ExecuteMsg::Freeze { id } => freeze(deps, info, id), ExecuteMsg::Unfreeze { id } => unfreeze(deps, info, id), @@ -95,6 +96,7 @@ fn mint( uri: Option<String>, uri_hash: Option<String>, data: Option<Binary>, + recipient: Option<String>, ) -> CoreumResult<ContractError> { assert_owner(deps.storage, &info.sender)?; let class_id = CLASS_ID.load(deps.storage)?; @@ -105,6 +107,7 @@ fn mint( uri, uri_hash, data, + recipient }); Ok(Response::new() @@ -309,26 +312,26 @@ fn remove_from_class_whitelist( #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps<CoreumQueries>, _env: Env, msg: QueryMsg) -> StdResult<Binary> { match msg { - QueryMsg::Params {} => to_binary(&query_params(deps)?), - QueryMsg::Class {} => to_binary(&query_class(deps)?), - QueryMsg::Classes { issuer } => to_binary(&query_classes(deps, issuer)?), - QueryMsg::Frozen { id } => to_binary(&query_frozen(deps, id)?), - QueryMsg::Whitelisted { id, account } => to_binary(&query_whitelisted(deps, id, account)?), + QueryMsg::Params {} => to_json_binary(&query_params(deps)?), + QueryMsg::Class {} => to_json_binary(&query_class(deps)?), + QueryMsg::Classes { issuer } => to_json_binary(&query_classes(deps, issuer)?), + QueryMsg::Frozen { id } => to_json_binary(&query_frozen(deps, id)?), + QueryMsg::Whitelisted { id, account } => to_json_binary(&query_whitelisted(deps, id, account)?), QueryMsg::WhitelistedAccountsForNft { id } => { - to_binary(&query_whitelisted_accounts_for_nft(deps, id)?) + to_json_binary(&query_whitelisted_accounts_for_nft(deps, id)?) } - QueryMsg::Balance { owner } => to_binary(&query_balance(deps, owner)?), - QueryMsg::Owner { id } => to_binary(&query_owner(deps, id)?), - QueryMsg::Supply {} => to_binary(&query_supply(deps)?), - QueryMsg::Nft { id } => to_binary(&query_nft(deps, id)?), - QueryMsg::Nfts { owner } => to_binary(&query_nfts(deps, owner)?), - QueryMsg::ClassNft {} => to_binary(&query_nft_class(deps)?), - QueryMsg::ClassesNft {} => to_binary(&query_nft_classes(deps)?), - QueryMsg::BurntNft { nft_id } => to_binary(&query_burnt_nft(deps, nft_id)?), - QueryMsg::BurntNftsInClass {} => to_binary(&query_burnt_nfts_in_class(deps)?), - QueryMsg::ClassFrozen { account } => to_binary(&query_class_frozen(deps, account)?), - QueryMsg::ClassFrozenAccounts {} => to_binary(&query_class_frozen_accounts(deps)?), - QueryMsg::ClassWhitelistedAccounts {} => to_binary(&query_class_whitelisted_accounts(deps)?), + QueryMsg::Balance { owner } => to_json_binary(&query_balance(deps, owner)?), + QueryMsg::Owner { id } => to_json_binary(&query_owner(deps, id)?), + QueryMsg::Supply {} => to_json_binary(&query_supply(deps)?), + QueryMsg::Nft { id } => to_json_binary(&query_nft(deps, id)?), + QueryMsg::Nfts { owner } => to_json_binary(&query_nfts(deps, owner)?), + QueryMsg::ClassNft {} => to_json_binary(&query_nft_class(deps)?), + QueryMsg::ClassesNft {} => to_json_binary(&query_nft_classes(deps)?), + QueryMsg::BurntNft { nft_id } => to_json_binary(&query_burnt_nft(deps, nft_id)?), + QueryMsg::BurntNftsInClass {} => to_json_binary(&query_burnt_nfts_in_class(deps)?), + QueryMsg::ClassFrozen { account } => to_json_binary(&query_class_frozen(deps, account)?), + QueryMsg::ClassFrozenAccounts {} => to_json_binary(&query_class_frozen_accounts(deps)?), + QueryMsg::ClassWhitelistedAccounts {} => to_json_binary(&query_class_whitelisted_accounts(deps)?), } } diff --git a/integration-tests/contracts/modules/nft/src/msg.rs b/integration-tests/contracts/modules/nft/src/msg.rs index fa493ec73..fa9c2c867 100644 --- a/integration-tests/contracts/modules/nft/src/msg.rs +++ b/integration-tests/contracts/modules/nft/src/msg.rs @@ -20,6 +20,7 @@ pub enum ExecuteMsg { uri: Option<String>, uri_hash: Option<String>, data: Option<Binary>, + recipient: Option<String>, }, Burn { id: String, diff --git a/integration-tests/modules/assetft_test.go b/integration-tests/modules/assetft_test.go index 1aacc8575..d01d4c392 100644 --- a/integration-tests/modules/assetft_test.go +++ b/integration-tests/modules/assetft_test.go @@ -5186,9 +5186,10 @@ func TestAssetFTIssuingSmartContractIsAllowedToSendAndReceive(t *testing.T) { // mint to itself amountToMint := sdkmath.NewInt(500) - mintPayload, err := json.Marshal(map[ftMethod]amountBodyFTRequest{ + mintPayload, err := json.Marshal(map[ftMethod]amountRecipientBodyFTRequest{ ftMethodMint: { - Amount: amountToMint.String(), + Amount: amountToMint.String(), + Recipient: contractAddr, }, }) requireT.NoError(err) @@ -5197,23 +5198,23 @@ func TestAssetFTIssuingSmartContractIsAllowedToSendAndReceive(t *testing.T) { requireT.NoError(err) // mint to someone else - amountToMintAndSend := sdkmath.NewInt(100) - mintAndSendPayload, err := json.Marshal(map[ftMethod]accountAmountBodyFTRequest{ - ftMethodMintAndSend: { - Account: recipient.String(), - Amount: amountToMintAndSend.String(), + amountToMint = sdkmath.NewInt(100) + mintPayload, err = json.Marshal(map[ftMethod]amountRecipientBodyFTRequest{ + ftMethodMint: { + Amount: amountToMint.String(), + Recipient: recipient.String(), }, }) requireT.NoError(err) - _, err = chain.Wasm.ExecuteWASMContract(ctx, txf, admin, contractAddr, mintAndSendPayload, sdk.Coin{}) + _, err = chain.Wasm.ExecuteWASMContract(ctx, txf, admin, contractAddr, mintPayload, sdk.Coin{}) requireT.NoError(err) // send back to smart contract msgSend := &banktypes.MsgSend{ FromAddress: recipient.String(), ToAddress: contractAddr, - Amount: sdk.NewCoins(sdk.NewCoin(denom, amountToMintAndSend)), + Amount: sdk.NewCoins(sdk.NewCoin(denom, amountToMint)), } _, err = client.BroadcastTx( ctx, diff --git a/integration-tests/modules/wasm_test.go b/integration-tests/modules/wasm_test.go index b216fa12a..0aab6fee5 100644 --- a/integration-tests/modules/wasm_test.go +++ b/integration-tests/modules/wasm_test.go @@ -59,6 +59,11 @@ type amountBodyFTRequest struct { Amount string `json:"amount"` } +type amountRecipientBodyFTRequest struct { + Amount string `json:"amount"` + Recipient string `json:"recipient"` +} + type accountAmountBodyFTRequest struct { Account string `json:"account"` Amount string `json:"amount"` @@ -80,10 +85,10 @@ const ( ftMethodBurn ftMethod = "burn" ftMethodFreeze ftMethod = "freeze" ftMethodUnfreeze ftMethod = "unfreeze" + ftMethodSetFrozen ftMethod = "set_frozen" ftMethodGloballyFreeze ftMethod = "globally_freeze" ftMethodGloballyUnfreeze ftMethod = "globally_unfreeze" ftMethodSetWhitelistedLimit ftMethod = "set_whitelisted_limit" - ftMethodMintAndSend ftMethod = "mint_and_send" // query. ftMethodParams ftMethod = "params" ftMethodTokens ftMethod = "tokens" @@ -783,6 +788,38 @@ func TestWASMFungibleTokenInContract(t *testing.T) { newAmount := issuanceAmount.Add(amountToMint) requireT.Equal(newAmount.String(), balanceRes.Balance.Amount.String()) + // ********** Mint (sending to someone) ********** + + amountToMint = sdkmath.NewInt(100) + whitelistPayload, err := json.Marshal(map[ftMethod]accountAmountBodyFTRequest{ + ftMethodSetWhitelistedLimit: { + Account: recipient2.String(), + Amount: amountToMint.String(), + }, + }) + requireT.NoError(err) + + _, err = chain.Wasm.ExecuteWASMContract(ctx, txf, admin, contractAddr, whitelistPayload, sdk.Coin{}) + requireT.NoError(err) + + mintPayload, err = json.Marshal(map[ftMethod]amountRecipientBodyFTRequest{ + ftMethodMint: { + Amount: amountToMint.String(), + Recipient: recipient2.String(), + }, + }) + requireT.NoError(err) + + _, err = chain.Wasm.ExecuteWASMContract(ctx, txf, admin, contractAddr, mintPayload, sdk.Coin{}) + requireT.NoError(err) + + balanceRes, err = bankClient.Balance(ctx, &banktypes.QueryBalanceRequest{ + Address: recipient2.String(), + Denom: denom, + }) + requireT.NoError(err) + requireT.Equal(amountToMint.String(), balanceRes.Balance.Amount.String()) + // ********** Burn ********** amountToBurn := sdkmath.NewInt(100) @@ -846,6 +883,27 @@ func TestWASMFungibleTokenInContract(t *testing.T) { requireT.NoError(err) requireT.Equal(amountToFreeze.Sub(amountToUnfreeze).String(), frozenRes.Balance.Amount.String()) + // ********** SetFrozen ********** + + amountToSetFrozen := sdkmath.NewInt(30) + setFrozenPayload, err := json.Marshal(map[ftMethod]accountAmountBodyFTRequest{ + ftMethodSetFrozen: { + Account: recipient1.String(), + Amount: amountToSetFrozen.String(), + }, + }) + requireT.NoError(err) + + _, err = chain.Wasm.ExecuteWASMContract(ctx, txf, admin, contractAddr, setFrozenPayload, sdk.Coin{}) + requireT.NoError(err) + + frozenRes, err = ftClient.FrozenBalance(ctx, &assetfttypes.QueryFrozenBalanceRequest{ + Account: recipient1.String(), + Denom: denom, + }) + requireT.NoError(err) + requireT.Equal(amountToSetFrozen.String(), frozenRes.Balance.Amount.String()) + // ********** GloballyFreeze ********** globallyFreezePayload, err := json.Marshal(map[ftMethod]struct{}{ @@ -881,7 +939,7 @@ func TestWASMFungibleTokenInContract(t *testing.T) { // ********** Whitelisting ********** amountToWhitelist := sdkmath.NewInt(100) - whitelistPayload, err := json.Marshal(map[ftMethod]accountAmountBodyFTRequest{ + whitelistPayload, err = json.Marshal(map[ftMethod]accountAmountBodyFTRequest{ ftMethodSetWhitelistedLimit: { Account: recipient1.String(), Amount: amountToWhitelist.String(), @@ -899,38 +957,6 @@ func TestWASMFungibleTokenInContract(t *testing.T) { requireT.NoError(err) requireT.Equal(amountToWhitelist.String(), whitelistedRes.Balance.Amount.String()) - // ********** MintAndSend ********** - - amountToMintAndSend := sdkmath.NewInt(100) - whitelistPayload, err = json.Marshal(map[ftMethod]accountAmountBodyFTRequest{ - ftMethodSetWhitelistedLimit: { - Account: recipient2.String(), - Amount: amountToMintAndSend.String(), - }, - }) - requireT.NoError(err) - - _, err = chain.Wasm.ExecuteWASMContract(ctx, txf, admin, contractAddr, whitelistPayload, sdk.Coin{}) - requireT.NoError(err) - - mintAndSendPayload, err := json.Marshal(map[ftMethod]accountAmountBodyFTRequest{ - ftMethodMintAndSend: { - Account: recipient2.String(), - Amount: amountToMintAndSend.String(), - }, - }) - requireT.NoError(err) - - _, err = chain.Wasm.ExecuteWASMContract(ctx, txf, admin, contractAddr, mintAndSendPayload, sdk.Coin{}) - requireT.NoError(err) - - balanceRes, err = bankClient.Balance(ctx, &banktypes.QueryBalanceRequest{ - Address: recipient2.String(), - Denom: denom, - }) - requireT.NoError(err) - requireT.Equal(amountToWhitelist.String(), balanceRes.Balance.Amount.String()) - // ********** Query ********** // ********** Params ********** @@ -1008,7 +1034,7 @@ func TestWASMFungibleTokenInContract(t *testing.T) { var wasmFrozenBalanceRes assetfttypes.QueryFrozenBalanceResponse requireT.NoError(json.Unmarshal(queryOut, &wasmFrozenBalanceRes)) requireT.Equal( - sdk.NewCoin(denom, amountToFreeze.Sub(amountToUnfreeze)).String(), wasmFrozenBalanceRes.Balance.String(), + sdk.NewCoin(denom, amountToSetFrozen).String(), wasmFrozenBalanceRes.Balance.String(), ) // ********** FrozenBalances ********** @@ -1024,7 +1050,7 @@ func TestWASMFungibleTokenInContract(t *testing.T) { var wasmFrozenBalancesRes assetfttypes.QueryFrozenBalancesResponse requireT.NoError(json.Unmarshal(queryOut, &wasmFrozenBalancesRes)) requireT.Equal( - sdk.NewCoin(denom, amountToFreeze.Sub(amountToUnfreeze)).String(), wasmFrozenBalancesRes.Balances[0].String(), + sdk.NewCoin(denom, amountToSetFrozen).String(), wasmFrozenBalancesRes.Balances[0].String(), ) // ********** WhitelistedBalance ********** @@ -1070,6 +1096,7 @@ func TestWASMNonFungibleTokenInContract(t *testing.T) { admin := chain.GenAccount() recipient := chain.GenAccount() + mintRecipient := chain.GenAccount() requireT := require.New(t) chain.Faucet.FundAccounts(ctx, t, @@ -1184,6 +1211,83 @@ func TestWASMNonFungibleTokenInContract(t *testing.T) { expectedNFT1, nftResp.Nft, ) + nftOwner, err := nftClient.Owner(ctx, &nfttypes.QueryOwnerRequest{ + ClassId: classID, + Id: mintNFTReq1.ID, + }) + requireT.NoError(err) + requireT.Equal(nftOwner.Owner, contractAddr) + + // ********** Mint (to someone) ********** + + issueClassReqNoWhitelist := moduleswasm.IssueNFTRequest{ + Name: "name", + Symbol: "symbol", + Description: "description", + URI: "https://my-nft-class-meta.invalid/1", + URIHash: "hash", + Data: encodedData, + Features: []assetnfttypes.ClassFeature{ + assetnfttypes.ClassFeature_burning, + assetnfttypes.ClassFeature_freezing, + assetnfttypes.ClassFeature_disable_sending, + }, + RoyaltyRate: royaltyRate.String(), + } + issuerNFTInstantiatePayload, err = json.Marshal(issueClassReqNoWhitelist) + requireT.NoError(err) + + // instantiate new contract + contractAddrNoWhitelist, _, err := chain.Wasm.DeployAndInstantiateWASMContract( + ctx, + txf, + admin, + moduleswasm.NftWASM, + integration.InstantiateConfig{ + AccessType: wasmtypes.AccessTypeUnspecified, + Payload: issuerNFTInstantiatePayload, + Label: "non_fungible_token", + }, + ) + requireT.NoError(err) + + classIDNoWhitelist := assetnfttypes.BuildClassID(issueClassReq.Symbol, sdk.MustAccAddressFromBech32(contractAddrNoWhitelist)) + + mintNFTReq1NoWhitelist := moduleswasm.NftMintRequest{ + ID: "id-1", + Recipient: mintRecipient.String(), + } + + // mint + mintPayload, err = json.Marshal(map[moduleswasm.NftMethod]moduleswasm.NftMintRequest{ + moduleswasm.NftMethodMint: mintNFTReq1NoWhitelist, + }) + requireT.NoError(err) + + _, err = chain.Wasm.ExecuteWASMContract(ctx, txf, admin, contractAddrNoWhitelist, mintPayload, sdk.Coin{}) + requireT.NoError(err) + + nftResp, err = nftClient.NFT(ctx, &nfttypes.QueryNFTRequest{ + ClassId: classIDNoWhitelist, + Id: mintNFTReq1NoWhitelist.ID, + }) + requireT.NoError(err) + + expectedNFT1 = &nfttypes.NFT{ + ClassId: classIDNoWhitelist, + Id: mintNFTReq1NoWhitelist.ID, + } + requireT.Equal( + expectedNFT1, nftResp.Nft, + ) + + nftOwner, err = nftClient.Owner(ctx, &nfttypes.QueryOwnerRequest{ + ClassId: classIDNoWhitelist, + Id: mintNFTReq1NoWhitelist.ID, + }) + requireT.NoError(err) + requireT.Equal(nftOwner.Owner, mintRecipient.String()) + // ********** Freeze ********** freezePayload, err := json.Marshal(map[moduleswasm.NftMethod]moduleswasm.NftIDRequest{ diff --git a/x/wasm/handler/message.go b/x/wasm/handler/message.go index 5972b2548..38e0638d0 100644 --- a/x/wasm/handler/message.go +++ b/x/wasm/handler/message.go @@ -24,6 +24,7 @@ type assetFTMsg struct { Burn *assetfttypes.MsgBurn `json:"Burn"` Freeze *assetfttypes.MsgFreeze `json:"Freeze"` Unfreeze *assetfttypes.MsgUnfreeze `json:"Unfreeze"` + SetFrozen *assetfttypes.MsgSetFrozen `json:"SetFrozen"` GloballyFreeze *assetfttypes.MsgGloballyFreeze `json:"GloballyFreeze"` GloballyUnfreeze *assetfttypes.MsgGloballyUnfreeze `json:"GloballyUnfreeze"` SetWhitelistedLimit *assetfttypes.MsgSetWhitelistedLimit `json:"SetWhitelistedLimit"` @@ -48,11 +49,12 @@ type assetNFTMsgIssueClass struct { // //nolint:tagliatelle // we keep the name same as consume type assetNFTMsgMint struct { - ClassID string `json:"class_id"` - ID string `json:"id"` - URI string `json:"uri"` - URIHash string `json:"uri_hash"` - Data string `json:"data"` + ClassID string `json:"class_id"` + ID string `json:"id"` + URI string `json:"uri"` + URIHash string `json:"uri_hash"` + Data string `json:"data"` + Recipient string `json:"recipient"` } // assetNFTMsg represents asset nft module messages integrated with the wasm handler. @@ -150,6 +152,10 @@ func decodeAssetFTMessage(assetFTMsg *assetFTMsg, sender string) (sdk.Msg, error assetFTMsg.Unfreeze.Sender = sender return assetFTMsg.Unfreeze, nil } + if assetFTMsg.SetFrozen != nil { + assetFTMsg.SetFrozen.Sender = sender + return assetFTMsg.SetFrozen, nil + } if assetFTMsg.GloballyFreeze != nil { assetFTMsg.GloballyFreeze.Sender = sender return assetFTMsg.GloballyFreeze, nil @@ -206,12 +212,13 @@ func decodeAssetNFTMessage(assetNFTMsg *assetNFTMsg, sender string) (sdk.Msg, er } } return &assetnfttypes.MsgMint{ - Sender: sender, - ClassID: assetNFTMsg.Mint.ClassID, - ID: assetNFTMsg.Mint.ID, - URI: assetNFTMsg.Mint.URI, - URIHash: assetNFTMsg.Mint.URIHash, - Data: data, + Sender: sender, + ClassID: assetNFTMsg.Mint.ClassID, + ID: assetNFTMsg.Mint.ID, + URI: assetNFTMsg.Mint.URI, + URIHash: assetNFTMsg.Mint.URIHash, + Data: data, + Recipient: assetNFTMsg.Mint.Recipient, }, nil } if assetNFTMsg.Burn != nil {