From a745030e1829072826b1cfe06aa7cc97c1616ca5 Mon Sep 17 00:00:00 2001 From: Humanalgorithm Date: Thu, 28 Apr 2022 17:10:26 -0400 Subject: [PATCH 01/33] escrow 721 basic setup --- Cargo.lock | 34 +++++++++++++++++++++ contracts/escrow721/.cargo/config | 4 +++ contracts/escrow721/Cargo.toml | 46 +++++++++++++++++++++++++++++ contracts/escrow721/src/contract.rs | 21 +++++++++++++ contracts/escrow721/src/lib.rs | 3 ++ contracts/escrow721/src/msg.rs | 12 ++++++++ e2e/full_test.go | 43 +++++++++++++++++++++++++-- 7 files changed, 161 insertions(+), 2 deletions(-) create mode 100644 contracts/escrow721/.cargo/config create mode 100644 contracts/escrow721/Cargo.toml create mode 100644 contracts/escrow721/src/contract.rs create mode 100644 contracts/escrow721/src/lib.rs create mode 100644 contracts/escrow721/src/msg.rs diff --git a/Cargo.lock b/Cargo.lock index 792c461e..489e8006 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -235,6 +235,22 @@ dependencies = [ "serde", ] +[[package]] +name = "cw721-base" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b61200af4e027af2d7485dbdc37c2a9c4093b6b2f2b811732329ef456076f97e" +dependencies = [ + "cosmwasm-std", + "cw-storage-plus", + "cw-utils", + "cw2", + "cw721", + "schemars", + "serde", + "thiserror", +] + [[package]] name = "der" version = "0.4.5" @@ -302,6 +318,24 @@ dependencies = [ "zeroize", ] +[[package]] +name = "escrow721" +version = "0.12.0" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cosmwasm-storage", + "cw-storage-plus", + "cw-utils", + "cw2", + "cw20-ics20", + "cw721", + "cw721-base", + "schemars", + "serde", + "thiserror", +] + [[package]] name = "ff" version = "0.10.1" diff --git a/contracts/escrow721/.cargo/config b/contracts/escrow721/.cargo/config new file mode 100644 index 00000000..624255c7 --- /dev/null +++ b/contracts/escrow721/.cargo/config @@ -0,0 +1,4 @@ +[alias] +wasm = "build --release --target wasm32-unknown-unknown" +unit-test = "test --lib" +schema = "run --example schema" \ No newline at end of file diff --git a/contracts/escrow721/Cargo.toml b/contracts/escrow721/Cargo.toml new file mode 100644 index 00000000..acc86030 --- /dev/null +++ b/contracts/escrow721/Cargo.toml @@ -0,0 +1,46 @@ +[package] +authors = ["Michael Scotto"] +edition = "2021" +name = "escrow721" +version = "0.12.0" + + +exclude = [ + # Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication. + "contract.wasm", + "hash.txt", +] + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +crate-type = ["cdylib", "rlib"] + +[features] +# for more explicit tests, cargo test --features=backtraces +backtraces = ["cosmwasm-std/backtraces"] +# use library feature to disable all instantiate/execute/query exports +library = [] + +[package.metadata.scripts] +optimize = """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 \ + cosmwasm/rust-optimizer:0.12.3 +""" + +[dependencies] +cosmwasm-std = { version = "1.0.0-beta8", features = ["stargate"] } +cosmwasm-storage = { version = "1.0.0-beta8" } +cw-storage-plus = "0.13.2" +cw-utils = "0.13.2" +cw2 = "0.13.2" +cw20-ics20 = { version = "0.13.2", features = ["library"] } +cw721 = "0.13.2" +cw721-base = { version = "0.13.2", features = ["library"] } +schemars = "0.8.8" +serde = { version = "1.0.133", default-features = false, features = ["derive"] } +thiserror = { version = "1.0.30" } + +[dev-dependencies] +cosmwasm-schema = { version = "1.0.0-beta8" } diff --git a/contracts/escrow721/src/contract.rs b/contracts/escrow721/src/contract.rs new file mode 100644 index 00000000..650cf366 --- /dev/null +++ b/contracts/escrow721/src/contract.rs @@ -0,0 +1,21 @@ +#[cfg(not(feature = "library"))] +use cosmwasm_std::entry_point; +use cosmwasm_std::{ MessageInfo, DepsMut, Env, StdResult, Empty +}; +use cw721_base::msg::InstantiateMsg; +use cw721_base; + +pub type CW721ContractWrapper<'a> = cw721_base::Cw721Contract<'a, Empty, Empty>; + + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn instantiate( + deps: DepsMut, + _env: Env, + _info: MessageInfo, + msg: InstantiateMsg, +) -> StdResult { + + CW721ContractWrapper::default() + .instantiate(deps, _env, _info, msg) +} diff --git a/contracts/escrow721/src/lib.rs b/contracts/escrow721/src/lib.rs new file mode 100644 index 00000000..fff0fdc1 --- /dev/null +++ b/contracts/escrow721/src/lib.rs @@ -0,0 +1,3 @@ +pub mod contract; + +// pub mod msg; \ No newline at end of file diff --git a/contracts/escrow721/src/msg.rs b/contracts/escrow721/src/msg.rs new file mode 100644 index 00000000..ca76528c --- /dev/null +++ b/contracts/escrow721/src/msg.rs @@ -0,0 +1,12 @@ +use cw20_ics20::state::ChannelInfo; +use cw721::Cw721ReceiveMsg; +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; + +// use crate::state::ChannelState; + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +pub struct InstantiateMsg { + // Default timeout for ics721 packets, specified in seconds + pub default_timeout: u64, +} diff --git a/e2e/full_test.go b/e2e/full_test.go index 6ee854a3..6070ce47 100644 --- a/e2e/full_test.go +++ b/e2e/full_test.go @@ -1,6 +1,7 @@ package e2e_test import ( + "fmt" "io/ioutil" "testing" "time" @@ -64,6 +65,14 @@ var ( } } ` + + escrow721Template = ` + { + "name": "escrow721Channel1transfer-nft", + "symbol": "esw721_1_transfer-nft", + "minter": "%s" + } + ` ) type Account struct { @@ -104,7 +113,7 @@ func GetAccountsAndBalances(accs []Account) ([]authtypes.GenesisAccount, []bankt } return genAccs, balances } -func TestMinter(t *testing.T) { +func TestICS721(t *testing.T) { accs := GetAccounts() genAccs, balances := GetAccountsAndBalances(accs) @@ -125,7 +134,6 @@ func TestMinter(t *testing.T) { pub1 := priv1.PubKey() addr1 := sdk.AccAddress(pub1.Address()) - // minter b, err := ioutil.ReadFile("contracts/ics721.wasm") require.NoError(t, err) @@ -138,4 +146,35 @@ func TestMinter(t *testing.T) { require.NotNil(t, res) require.Equal(t, res.CodeID, uint64(1)) println("ICS721.wasm has loaded!") + + b, err = ioutil.ReadFile("contracts/escrow721.wasm") + require.NoError(t, err) + + res, err = msgServer.StoreCode(sdk.WrapSDKContext(ctx), &wasmtypes.MsgStoreCode{ + Sender: addr1.String(), + WASMByteCode: b, + }) + require.NoError(t, err) + require.NotNil(t, res) + require.Equal(t, res.CodeID, uint64(2)) + println("escrow721.wasm has loaded!") + + creator := accs[0] + + instantiateMsgRaw := []byte( + fmt.Sprintf(escrow721Template, + creator.Address.String(), + ), + ) + instantiateRes, err := msgServer.InstantiateContract(sdk.WrapSDKContext(ctx), &wasmtypes.MsgInstantiateContract{ + Sender: creator.Address.String(), + Admin: creator.Address.String(), + CodeID: 2, + Label: "Escrow721", + Msg: instantiateMsgRaw, + Funds: sdk.NewCoins(sdk.NewInt64Coin("ustars", 1_000_000_000)), + }) + require.NoError(t, err) + require.NotNil(t, instantiateRes) + require.NotEmpty(t, instantiateRes.Address) } From ed9bb6d4c26d76c3f249b15ad69af49c7ce5a1f9 Mon Sep 17 00:00:00 2001 From: Humanalgorithm Date: Thu, 28 Apr 2022 17:12:42 -0400 Subject: [PATCH 02/33] fix formatting --- contracts/escrow721/src/contract.rs | 10 +++------- contracts/escrow721/src/lib.rs | 2 -- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/contracts/escrow721/src/contract.rs b/contracts/escrow721/src/contract.rs index 650cf366..ae2b4e70 100644 --- a/contracts/escrow721/src/contract.rs +++ b/contracts/escrow721/src/contract.rs @@ -1,13 +1,11 @@ #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; -use cosmwasm_std::{ MessageInfo, DepsMut, Env, StdResult, Empty -}; -use cw721_base::msg::InstantiateMsg; +use cosmwasm_std::{DepsMut, Empty, Env, MessageInfo, StdResult}; use cw721_base; +use cw721_base::msg::InstantiateMsg; pub type CW721ContractWrapper<'a> = cw721_base::Cw721Contract<'a, Empty, Empty>; - #[cfg_attr(not(feature = "library"), entry_point)] pub fn instantiate( deps: DepsMut, @@ -15,7 +13,5 @@ pub fn instantiate( _info: MessageInfo, msg: InstantiateMsg, ) -> StdResult { - - CW721ContractWrapper::default() - .instantiate(deps, _env, _info, msg) + CW721ContractWrapper::default().instantiate(deps, _env, _info, msg) } diff --git a/contracts/escrow721/src/lib.rs b/contracts/escrow721/src/lib.rs index fff0fdc1..2943dbb5 100644 --- a/contracts/escrow721/src/lib.rs +++ b/contracts/escrow721/src/lib.rs @@ -1,3 +1 @@ pub mod contract; - -// pub mod msg; \ No newline at end of file From 74ce4e30ae1577edafd01be3408773d501221086 Mon Sep 17 00:00:00 2001 From: Humanalgorithm Date: Fri, 29 Apr 2022 13:18:16 -0400 Subject: [PATCH 03/33] working query owner of --- contracts/escrow721/src/contract.rs | 73 ++++++++++++++++++++++++-- contracts/escrow721/src/lib.rs | 1 + contracts/escrow721/src/msg.rs | 10 ++++ e2e/full_test.go | 79 ++++++++++++++++++++++++----- 4 files changed, 145 insertions(+), 18 deletions(-) diff --git a/contracts/escrow721/src/contract.rs b/contracts/escrow721/src/contract.rs index ae2b4e70..f02b7044 100644 --- a/contracts/escrow721/src/contract.rs +++ b/contracts/escrow721/src/contract.rs @@ -1,10 +1,15 @@ #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; -use cosmwasm_std::{DepsMut, Empty, Env, MessageInfo, StdResult}; -use cw721_base; -use cw721_base::msg::InstantiateMsg; +use cosmwasm_std::{DepsMut, Deps, Empty, Env, MessageInfo, StdResult, to_binary, Binary, StdError}; +use cw721::{Cw721Execute, OwnerOfResponse}; +use cw721_base::Cw721Contract; +use cw721_base::msg::{InstantiateMsg, MintMsg, ExecuteMsg, QueryMsg}; +use cw721_base::ContractError; +use cw721_base::helpers::Cw721Contract as Cw721ContractHelper; +use crate::msg; -pub type CW721ContractWrapper<'a> = cw721_base::Cw721Contract<'a, Empty, Empty>; + +pub type CW721ContractWrapper<'a> = Cw721Contract<'a, Empty, Empty>; #[cfg_attr(not(feature = "library"), entry_point)] pub fn instantiate( @@ -15,3 +20,63 @@ pub fn instantiate( ) -> StdResult { CW721ContractWrapper::default().instantiate(deps, _env, _info, msg) } + +pub fn transfer( + deps: DepsMut, + env: Env, + info: MessageInfo, + recipient: String, + token_id: String, +) -> Result { + + CW721ContractWrapper::default().transfer_nft(deps, env, info, recipient, token_id) + +} + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn execute( + deps: DepsMut, + env: Env, + info: MessageInfo, + msg: ExecuteMsg, +) -> Result { + println!("in the execute"); + match msg { + ExecuteMsg::Mint(msg ) => mint(deps, env, info, msg), + _ => Err(ContractError::Expired { }) + } +} + +pub fn mint( + deps: DepsMut, + _env: Env, + info: MessageInfo, + msg: MintMsg, +) -> Result { + + CW721ContractWrapper::default().mint(deps, _env, info, msg) +} + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn query( + deps: Deps, + _env: Env, + msg: QueryMsg + ) -> StdResult { + println!("in the query"); + match msg { + // QueryMsg::OwnerOf{token_id,include_expired}=>to_binary( + // get_owner(deps, _env, token_id, true) + // ), + _ => CW721ContractWrapper::default().query(deps, _env, msg.into()), +}} + +pub fn get_owner( + deps: Deps, + env: Env, + token_id: String, + include_expired: bool, +) -> StdResult { + print!("in the get owner"); + Cw721ContractHelper(env.contract.address).owner_of(&deps.querier, token_id, include_expired) +} \ No newline at end of file diff --git a/contracts/escrow721/src/lib.rs b/contracts/escrow721/src/lib.rs index 2943dbb5..1041aa71 100644 --- a/contracts/escrow721/src/lib.rs +++ b/contracts/escrow721/src/lib.rs @@ -1 +1,2 @@ pub mod contract; +pub mod msg; \ No newline at end of file diff --git a/contracts/escrow721/src/msg.rs b/contracts/escrow721/src/msg.rs index ca76528c..be3d82de 100644 --- a/contracts/escrow721/src/msg.rs +++ b/contracts/escrow721/src/msg.rs @@ -10,3 +10,13 @@ pub struct InstantiateMsg { // Default timeout for ics721 packets, specified in seconds pub default_timeout: u64, } + + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub enum QueryMsg { + + GetOwner { + token_id: String + } +} \ No newline at end of file diff --git a/e2e/full_test.go b/e2e/full_test.go index 6070ce47..f3e425b8 100644 --- a/e2e/full_test.go +++ b/e2e/full_test.go @@ -21,20 +21,6 @@ import ( var ( // whitelist - instantiateWhiteListTemplate = ` - { - "members":[%s], - "start_time": "%d", - "end_time": "%d", - "unit_price": { - "amount": "50000000", - "denom": "ustars" - }, - "per_address_limit": 1, - "member_limit": 1000 - } - ` - instantiateMinterTemplate = ` { "base_token_uri": "ipfs://...", @@ -177,4 +163,69 @@ func TestICS721(t *testing.T) { require.NoError(t, err) require.NotNil(t, instantiateRes) require.NotEmpty(t, instantiateRes.Address) + + escrow721Address := instantiateRes.Address + + escrow721MintTemplate := ` + { "mint": { + "token_id": "%s", + "owner": "%s", + "token_uri": "ipfs://abc123", + "extension": {} + } + } + ` + mintMsgRaw := []byte( + fmt.Sprintf(escrow721MintTemplate, + "1", + creator.Address.String(), + ), + ) + _, mintErr := msgServer.ExecuteContract(sdk.WrapSDKContext(ctx), &wasmtypes.MsgExecuteContract{ + Contract: escrow721Address, + Sender: accs[0].Address.String(), + Msg: mintMsgRaw, + }) + require.NoError(t, err) + require.NotNil(t, instantiateRes) + require.NotEmpty(t, instantiateRes.Address) + require.NoError(t, mintErr) + + mintMsgRaw = []byte( + fmt.Sprintf(escrow721MintTemplate, + "2", + creator.Address.String(), + ), + ) + _, mintErr = msgServer.ExecuteContract(sdk.WrapSDKContext(ctx), &wasmtypes.MsgExecuteContract{ + Contract: escrow721Address, + Sender: creator.Address.String(), + Msg: mintMsgRaw, + }) + require.NoError(t, err) + require.NotNil(t, instantiateRes) + require.NotEmpty(t, instantiateRes.Address) + require.NoError(t, mintErr) + + addr, _ := sdk.AccAddressFromBech32(escrow721Address) + result, err := app.WasmKeeper.QuerySmart(ctx, addr, []byte(`{"owner_of": {"token_id": "1"}}`)) + expected_result := fmt.Sprintf("{\"owner\":\"%s\",\"approvals\":[]}", creator.Address.String()) + require.Equal(t, string(result), expected_result) + require.NoError(t, err) + + // q. + + // pub struct MintMsg { + // /// Unique ID of the NFT + // pub token_id: String, + // /// The owner of the newly minter NFT + // pub owner: String, + // /// Universal resource identifier for this NFT + // /// Should point to a JSON file that conforms to the ERC721 + // /// Metadata JSON Schema + // pub token_uri: Option, + // /// Any custom extension used by this contract + // pub extension: T, + // } + } From 96994464168664c62ed678c5cb387780b146d238 Mon Sep 17 00:00:00 2001 From: Humanalgorithm Date: Fri, 27 May 2022 19:19:57 -0400 Subject: [PATCH 04/33] compiling build with two key tuple key --- Cargo.lock | 25 +++++++------ contracts/escrow721/Cargo.toml | 4 +-- contracts/escrow721/src/contract.rs | 56 +++++++++++++++-------------- contracts/escrow721/src/msg.rs | 2 +- contracts/ics721/Cargo.toml | 3 +- contracts/ics721/src/contract.rs | 2 +- contracts/ics721/src/ibc.rs | 2 +- contracts/ics721/src/msg.rs | 2 +- e2e/full_test.go | 15 -------- 9 files changed, 49 insertions(+), 62 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 489e8006..bf4fe899 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -224,31 +224,29 @@ dependencies = [ ] [[package]] -name = "cw721" +name = "cw721-base-ibc" version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b9fd71276795554c35899bb3a378561ed0c288d231113e9915f6ee1f42b7b5" +source = "git+https://github.com/public-awesome/cw721-ibc.git#ac79307b4e70f24536ea986953cc54c504bf6f61" dependencies = [ "cosmwasm-std", + "cw-storage-plus", "cw-utils", + "cw2", + "cw721-ibc", "schemars", "serde", + "thiserror", ] [[package]] -name = "cw721-base" +name = "cw721-ibc" version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b61200af4e027af2d7485dbdc37c2a9c4093b6b2f2b811732329ef456076f97e" +source = "git+https://github.com/public-awesome/cw721-ibc.git#ac79307b4e70f24536ea986953cc54c504bf6f61" dependencies = [ "cosmwasm-std", - "cw-storage-plus", "cw-utils", - "cw2", - "cw721", "schemars", "serde", - "thiserror", ] [[package]] @@ -329,8 +327,8 @@ dependencies = [ "cw-utils", "cw2", "cw20-ics20", - "cw721", - "cw721-base", + "cw721-base-ibc", + "cw721-ibc", "schemars", "serde", "thiserror", @@ -422,7 +420,8 @@ dependencies = [ "cw-utils", "cw2", "cw20-ics20", - "cw721", + "cw721-base-ibc", + "cw721-ibc", "schemars", "serde", "thiserror", diff --git a/contracts/escrow721/Cargo.toml b/contracts/escrow721/Cargo.toml index acc86030..f925e41e 100644 --- a/contracts/escrow721/Cargo.toml +++ b/contracts/escrow721/Cargo.toml @@ -36,8 +36,8 @@ cw-storage-plus = "0.13.2" cw-utils = "0.13.2" cw2 = "0.13.2" cw20-ics20 = { version = "0.13.2", features = ["library"] } -cw721 = "0.13.2" -cw721-base = { version = "0.13.2", features = ["library"] } +cw721-base-ibc = { git = "https://github.com/public-awesome/cw721-ibc.git", version="0.13.2"} +cw721-ibc = { git = "https://github.com/public-awesome/cw721-ibc.git", version="0.13.2"} schemars = "0.8.8" serde = { version = "1.0.133", default-features = false, features = ["derive"] } thiserror = { version = "1.0.30" } diff --git a/contracts/escrow721/src/contract.rs b/contracts/escrow721/src/contract.rs index f02b7044..0be4e310 100644 --- a/contracts/escrow721/src/contract.rs +++ b/contracts/escrow721/src/contract.rs @@ -1,13 +1,12 @@ #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; -use cosmwasm_std::{DepsMut, Deps, Empty, Env, MessageInfo, StdResult, to_binary, Binary, StdError}; -use cw721::{Cw721Execute, OwnerOfResponse}; -use cw721_base::Cw721Contract; -use cw721_base::msg::{InstantiateMsg, MintMsg, ExecuteMsg, QueryMsg}; -use cw721_base::ContractError; -use cw721_base::helpers::Cw721Contract as Cw721ContractHelper; -use crate::msg; - +use cosmwasm_std::{ + to_binary, Binary, Deps, DepsMut, Empty, Env, MessageInfo, StdError, StdResult +}; +use cw721_ibc::{Cw721Execute, OwnerOfResponse, Cw721Query}; +use cw721_base_ibc::helpers::Cw721Contract as Cw721ContractHelper; +use cw721_base_ibc::msg::{ExecuteMsg, InstantiateMsg, MintMsg, QueryMsg}; +use cw721_base_ibc::{ContractError, Cw721Contract}; pub type CW721ContractWrapper<'a> = Cw721Contract<'a, Empty, Empty>; @@ -26,11 +25,10 @@ pub fn transfer( env: Env, info: MessageInfo, recipient: String, + class_id: String, token_id: String, ) -> Result { - - CW721ContractWrapper::default().transfer_nft(deps, env, info, recipient, token_id) - + CW721ContractWrapper::default().transfer_nft(deps, env, info, recipient, class_id, token_id) } #[cfg_attr(not(feature = "library"), entry_point)] @@ -42,8 +40,8 @@ pub fn execute( ) -> Result { println!("in the execute"); match msg { - ExecuteMsg::Mint(msg ) => mint(deps, env, info, msg), - _ => Err(ContractError::Expired { }) + ExecuteMsg::Mint(msg) => mint(deps, env, info, msg), + _ => Err(ContractError::Expired {}), } } @@ -58,25 +56,29 @@ pub fn mint( } #[cfg_attr(not(feature = "library"), entry_point)] -pub fn query( - deps: Deps, - _env: Env, - msg: QueryMsg - ) -> StdResult { - println!("in the query"); +pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { match msg { - // QueryMsg::OwnerOf{token_id,include_expired}=>to_binary( - // get_owner(deps, _env, token_id, true) - // ), - _ => CW721ContractWrapper::default().query(deps, _env, msg.into()), -}} + QueryMsg::OwnerOf { + class_id, + token_id, + include_expired, + } => to_binary(&get_owner( + deps, + _env, + class_id, + token_id, + include_expired.unwrap_or(false), + )?), + _ => CW721ContractWrapper::default().query(deps, _env, msg.into()), + } +} pub fn get_owner( deps: Deps, env: Env, + class_id: String, token_id: String, include_expired: bool, ) -> StdResult { - print!("in the get owner"); - Cw721ContractHelper(env.contract.address).owner_of(&deps.querier, token_id, include_expired) -} \ No newline at end of file + CW721ContractWrapper::default().owner_of(deps, env, class_id, token_id, include_expired) +} diff --git a/contracts/escrow721/src/msg.rs b/contracts/escrow721/src/msg.rs index be3d82de..3f4e8bf4 100644 --- a/contracts/escrow721/src/msg.rs +++ b/contracts/escrow721/src/msg.rs @@ -1,5 +1,5 @@ use cw20_ics20::state::ChannelInfo; -use cw721::Cw721ReceiveMsg; +use cw721_ibc::Cw721ReceiveMsg; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; diff --git a/contracts/ics721/Cargo.toml b/contracts/ics721/Cargo.toml index b42a5800..6f782208 100644 --- a/contracts/ics721/Cargo.toml +++ b/contracts/ics721/Cargo.toml @@ -36,7 +36,8 @@ cw-storage-plus = "0.13.2" cw-utils = "0.13.2" cw2 = "0.13.2" cw20-ics20 = { version = "0.13.2", features = ["library"] } -cw721 = "0.13.2" +cw721-base-ibc = { git = "https://github.com/public-awesome/cw721-ibc.git", version="0.13.2"} +cw721-ibc = { git = "https://github.com/public-awesome/cw721-ibc.git", version="0.13.2"} schemars = "0.8.8" serde = { version = "1.0.133", default-features = false, features = ["derive"] } thiserror = { version = "1.0.30" } diff --git a/contracts/ics721/src/contract.rs b/contracts/ics721/src/contract.rs index 1dca045a..5063ef24 100644 --- a/contracts/ics721/src/contract.rs +++ b/contracts/ics721/src/contract.rs @@ -6,7 +6,7 @@ use cosmwasm_std::{ }; use cw2::set_contract_version; use cw20_ics20::msg::{ListChannelsResponse, PortResponse}; -use cw721::Cw721ReceiveMsg; +use cw721_ibc::Cw721ReceiveMsg; use cw_utils::nonpayable; use crate::error::ContractError; diff --git a/contracts/ics721/src/ibc.rs b/contracts/ics721/src/ibc.rs index c48b9f9e..af5b6517 100644 --- a/contracts/ics721/src/ibc.rs +++ b/contracts/ics721/src/ibc.rs @@ -1,6 +1,6 @@ use cw20_ics20::ibc::Ics20Ack; use cw20_ics20::state::ChannelInfo; -use cw721::Cw721ExecuteMsg; +use cw721_ibc::Cw721ExecuteMsg; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; diff --git a/contracts/ics721/src/msg.rs b/contracts/ics721/src/msg.rs index b057b33d..997c0294 100644 --- a/contracts/ics721/src/msg.rs +++ b/contracts/ics721/src/msg.rs @@ -1,5 +1,5 @@ use cw20_ics20::state::ChannelInfo; -use cw721::Cw721ReceiveMsg; +use cw721_ibc::Cw721ReceiveMsg; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; diff --git a/e2e/full_test.go b/e2e/full_test.go index f3e425b8..99b5cbfc 100644 --- a/e2e/full_test.go +++ b/e2e/full_test.go @@ -213,19 +213,4 @@ func TestICS721(t *testing.T) { require.Equal(t, string(result), expected_result) require.NoError(t, err) - // q. - - // pub struct MintMsg { - // /// Unique ID of the NFT - // pub token_id: String, - // /// The owner of the newly minter NFT - // pub owner: String, - // /// Universal resource identifier for this NFT - // /// Should point to a JSON file that conforms to the ERC721 - // /// Metadata JSON Schema - // pub token_uri: Option, - // /// Any custom extension used by this contract - // pub extension: T, - // } - } From ed8e7cc0bde4038776f65c168bd69fc2a1f96b48 Mon Sep 17 00:00:00 2001 From: Humanalgorithm Date: Fri, 27 May 2022 19:34:54 -0400 Subject: [PATCH 05/33] ics 721 tests pass --- contracts/escrow721/src/contract.rs | 2 -- contracts/escrow721/src/msg.rs | 2 -- contracts/ics721/src/contract.rs | 2 +- contracts/ics721/src/contract_test.rs | 18 +++++++++++------- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/contracts/escrow721/src/contract.rs b/contracts/escrow721/src/contract.rs index 0be4e310..0a138551 100644 --- a/contracts/escrow721/src/contract.rs +++ b/contracts/escrow721/src/contract.rs @@ -4,7 +4,6 @@ use cosmwasm_std::{ to_binary, Binary, Deps, DepsMut, Empty, Env, MessageInfo, StdError, StdResult }; use cw721_ibc::{Cw721Execute, OwnerOfResponse, Cw721Query}; -use cw721_base_ibc::helpers::Cw721Contract as Cw721ContractHelper; use cw721_base_ibc::msg::{ExecuteMsg, InstantiateMsg, MintMsg, QueryMsg}; use cw721_base_ibc::{ContractError, Cw721Contract}; @@ -51,7 +50,6 @@ pub fn mint( info: MessageInfo, msg: MintMsg, ) -> Result { - CW721ContractWrapper::default().mint(deps, _env, info, msg) } diff --git a/contracts/escrow721/src/msg.rs b/contracts/escrow721/src/msg.rs index 3f4e8bf4..8246a02c 100644 --- a/contracts/escrow721/src/msg.rs +++ b/contracts/escrow721/src/msg.rs @@ -1,5 +1,3 @@ -use cw20_ics20::state::ChannelInfo; -use cw721_ibc::Cw721ReceiveMsg; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; diff --git a/contracts/ics721/src/contract.rs b/contracts/ics721/src/contract.rs index 5063ef24..8b983156 100644 --- a/contracts/ics721/src/contract.rs +++ b/contracts/ics721/src/contract.rs @@ -84,7 +84,7 @@ pub fn execute_transfer( // build ics721 packet let packet = Ics721Packet::new( - env.contract.address.as_ref(), + &msg.class_id, None, msg.token_ids .iter() diff --git a/contracts/ics721/src/contract_test.rs b/contracts/ics721/src/contract_test.rs index 84e82560..95cc26f1 100644 --- a/contracts/ics721/src/contract_test.rs +++ b/contracts/ics721/src/contract_test.rs @@ -9,6 +9,7 @@ mod contact_testing { use cosmwasm_std::{CosmosMsg, IbcEndpoint}; use cw2::{get_contract_version, ContractVersion}; use cw20_ics20::state::ChannelInfo; + use cw721_ibc::Cw721ReceiveMsg; use cosmwasm_std::testing::mock_dependencies; @@ -342,7 +343,7 @@ mod contact_testing { }, Attribute { key: "class_id".into(), - value: "cosmos2contract".into(), + value: "abc/123/collection-addr".into(), }, Attribute { key: "token_ids".into(), @@ -350,7 +351,7 @@ mod contact_testing { }, ]; let expected_ics721_packet = Ics721Packet::new( - mock_env().contract.address.as_ref(), + &"abc/123/collection-addr".to_string(), None, transfer_msg .token_ids @@ -399,6 +400,7 @@ mod contact_testing { let cw721_receive_msg = Cw721ReceiveMsg { sender: sender_address_str.to_string(), + class_id:"abc/123/collection-addr".to_string(), token_id: "1".to_string(), msg: to_binary(&transfer_msg).unwrap(), }; @@ -425,7 +427,7 @@ mod contact_testing { }, Attribute { key: "class_id".into(), - value: "cosmos2contract".into(), + value: "abc/123/collection-addr".into(), }, Attribute { key: "token_ids".into(), @@ -433,7 +435,7 @@ mod contact_testing { }, ]; let expected_ics721_packet = Ics721Packet::new( - mock_env().contract.address.as_ref(), + &"abc/123/collection-addr".to_string(), None, transfer_msg .token_ids @@ -484,6 +486,7 @@ mod contact_testing { let cw721_receive_msg = Cw721ReceiveMsg { sender: sender_address_str.to_string(), + class_id: "class_id_1".to_string(), token_id: "1".to_string(), msg: to_binary(&transfer_msg).unwrap(), }; @@ -525,6 +528,7 @@ mod contact_testing { let cw_721_receive_sender = "sender_address_receive_path"; let cw721_receive_msg = ExecuteMsg::Receive(Cw721ReceiveMsg { sender: cw_721_receive_sender.to_string(), + class_id: "abc/123/collection-addr".to_string(), token_id: "1".to_string(), msg: to_binary(&transfer_msg).unwrap(), }); @@ -551,7 +555,7 @@ mod contact_testing { }, Attribute { key: "class_id".into(), - value: "cosmos2contract".into(), + value: "abc/123/collection-addr".into(), }, Attribute { key: "token_ids".into(), @@ -560,7 +564,7 @@ mod contact_testing { ]; let expected_ics721_packet = Ics721Packet::new( - mock_env().contract.address.as_ref(), + &"abc/123/collection-addr".to_string(), None, transfer_msg .token_ids @@ -628,7 +632,7 @@ mod contact_testing { }, Attribute { key: "class_id".into(), - value: "cosmos2contract".into(), + value: "abc/123/collection-addr".into(), }, Attribute { key: "token_ids".into(), From 294f83a2100f9dedb866271aa43520f55b3ca95b Mon Sep 17 00:00:00 2001 From: Humanalgorithm Date: Fri, 27 May 2022 19:59:21 -0400 Subject: [PATCH 06/33] working mint test in e2etest --- contracts/escrow721/src/contract.rs | 8 +++----- e2e/full_test.go | 5 ++++- schema/execute_msg.json | 4 ++++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/contracts/escrow721/src/contract.rs b/contracts/escrow721/src/contract.rs index 0a138551..84fb9336 100644 --- a/contracts/escrow721/src/contract.rs +++ b/contracts/escrow721/src/contract.rs @@ -1,7 +1,7 @@ #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - to_binary, Binary, Deps, DepsMut, Empty, Env, MessageInfo, StdError, StdResult + to_binary, Binary, Deps, DepsMut, Empty, Env, MessageInfo, StdResult }; use cw721_ibc::{Cw721Execute, OwnerOfResponse, Cw721Query}; use cw721_base_ibc::msg::{ExecuteMsg, InstantiateMsg, MintMsg, QueryMsg}; @@ -9,8 +9,8 @@ use cw721_base_ibc::{ContractError, Cw721Contract}; pub type CW721ContractWrapper<'a> = Cw721Contract<'a, Empty, Empty>; -#[cfg_attr(not(feature = "library"), entry_point)] -pub fn instantiate( + +pub fn instantiate_entry( deps: DepsMut, _env: Env, _info: MessageInfo, @@ -30,7 +30,6 @@ pub fn transfer( CW721ContractWrapper::default().transfer_nft(deps, env, info, recipient, class_id, token_id) } -#[cfg_attr(not(feature = "library"), entry_point)] pub fn execute( deps: DepsMut, env: Env, @@ -53,7 +52,6 @@ pub fn mint( CW721ContractWrapper::default().mint(deps, _env, info, msg) } -#[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { match msg { QueryMsg::OwnerOf { diff --git a/e2e/full_test.go b/e2e/full_test.go index 99b5cbfc..2bc93652 100644 --- a/e2e/full_test.go +++ b/e2e/full_test.go @@ -168,6 +168,7 @@ func TestICS721(t *testing.T) { escrow721MintTemplate := ` { "mint": { + "class_id": "%s", "token_id": "%s", "owner": "%s", "token_uri": "ipfs://abc123", @@ -177,6 +178,7 @@ func TestICS721(t *testing.T) { ` mintMsgRaw := []byte( fmt.Sprintf(escrow721MintTemplate, + "omni/stars/transfer-nft", "1", creator.Address.String(), ), @@ -193,6 +195,7 @@ func TestICS721(t *testing.T) { mintMsgRaw = []byte( fmt.Sprintf(escrow721MintTemplate, + "omni/stars/transfer-nft", "2", creator.Address.String(), ), @@ -208,7 +211,7 @@ func TestICS721(t *testing.T) { require.NoError(t, mintErr) addr, _ := sdk.AccAddressFromBech32(escrow721Address) - result, err := app.WasmKeeper.QuerySmart(ctx, addr, []byte(`{"owner_of": {"token_id": "1"}}`)) + result, err := app.WasmKeeper.QuerySmart(ctx, addr, []byte(`{"owner_of": {"token_id": "1", "class_id": "omni/stars/transfer-nft"}}`)) expected_result := fmt.Sprintf("{\"owner\":\"%s\",\"approvals\":[]}", creator.Address.String()) require.Equal(t, string(result), expected_result) require.NoError(t, err) diff --git a/schema/execute_msg.json b/schema/execute_msg.json index 3e6c2efc..b742bffa 100644 --- a/schema/execute_msg.json +++ b/schema/execute_msg.json @@ -36,11 +36,15 @@ "description": "Cw721ReceiveMsg should be de/serialized under `Receive()` variant in a ExecuteMsg", "type": "object", "required": [ + "class_id", "msg", "sender", "token_id" ], "properties": { + "class_id": { + "type": "string" + }, "msg": { "$ref": "#/definitions/Binary" }, From 0326a7c2c1a1c2a826325678df6f51026f5e97d3 Mon Sep 17 00:00:00 2001 From: Humanalgorithm Date: Fri, 27 May 2022 20:09:48 -0400 Subject: [PATCH 07/33] fix lint: --- contracts/escrow721/src/contract.rs | 10 +++------- contracts/escrow721/src/lib.rs | 2 +- contracts/escrow721/src/msg.rs | 8 ++------ contracts/ics721/src/contract_test.rs | 10 +++++----- 4 files changed, 11 insertions(+), 19 deletions(-) diff --git a/contracts/escrow721/src/contract.rs b/contracts/escrow721/src/contract.rs index 84fb9336..b7b4f42a 100644 --- a/contracts/escrow721/src/contract.rs +++ b/contracts/escrow721/src/contract.rs @@ -1,15 +1,11 @@ #[cfg(not(feature = "library"))] -use cosmwasm_std::entry_point; -use cosmwasm_std::{ - to_binary, Binary, Deps, DepsMut, Empty, Env, MessageInfo, StdResult -}; -use cw721_ibc::{Cw721Execute, OwnerOfResponse, Cw721Query}; +use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Empty, Env, MessageInfo, StdResult}; use cw721_base_ibc::msg::{ExecuteMsg, InstantiateMsg, MintMsg, QueryMsg}; use cw721_base_ibc::{ContractError, Cw721Contract}; +use cw721_ibc::{Cw721Execute, Cw721Query, OwnerOfResponse}; pub type CW721ContractWrapper<'a> = Cw721Contract<'a, Empty, Empty>; - pub fn instantiate_entry( deps: DepsMut, _env: Env, @@ -65,7 +61,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { token_id, include_expired.unwrap_or(false), )?), - _ => CW721ContractWrapper::default().query(deps, _env, msg.into()), + _ => CW721ContractWrapper::default().query(deps, _env, msg), } } diff --git a/contracts/escrow721/src/lib.rs b/contracts/escrow721/src/lib.rs index 1041aa71..112ecadc 100644 --- a/contracts/escrow721/src/lib.rs +++ b/contracts/escrow721/src/lib.rs @@ -1,2 +1,2 @@ pub mod contract; -pub mod msg; \ No newline at end of file +pub mod msg; diff --git a/contracts/escrow721/src/msg.rs b/contracts/escrow721/src/msg.rs index 8246a02c..705f9c73 100644 --- a/contracts/escrow721/src/msg.rs +++ b/contracts/escrow721/src/msg.rs @@ -9,12 +9,8 @@ pub struct InstantiateMsg { pub default_timeout: u64, } - #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum QueryMsg { - - GetOwner { - token_id: String - } -} \ No newline at end of file + GetOwner { token_id: String }, +} diff --git a/contracts/ics721/src/contract_test.rs b/contracts/ics721/src/contract_test.rs index 95cc26f1..f5bfcecb 100644 --- a/contracts/ics721/src/contract_test.rs +++ b/contracts/ics721/src/contract_test.rs @@ -351,7 +351,7 @@ mod contact_testing { }, ]; let expected_ics721_packet = Ics721Packet::new( - &"abc/123/collection-addr".to_string(), + "abc/123/collection-addr", None, transfer_msg .token_ids @@ -400,7 +400,7 @@ mod contact_testing { let cw721_receive_msg = Cw721ReceiveMsg { sender: sender_address_str.to_string(), - class_id:"abc/123/collection-addr".to_string(), + class_id: "abc/123/collection-addr".to_string(), token_id: "1".to_string(), msg: to_binary(&transfer_msg).unwrap(), }; @@ -435,7 +435,7 @@ mod contact_testing { }, ]; let expected_ics721_packet = Ics721Packet::new( - &"abc/123/collection-addr".to_string(), + "abc/123/collection-addr", None, transfer_msg .token_ids @@ -486,7 +486,7 @@ mod contact_testing { let cw721_receive_msg = Cw721ReceiveMsg { sender: sender_address_str.to_string(), - class_id: "class_id_1".to_string(), + class_id: "class_id_1".to_string(), token_id: "1".to_string(), msg: to_binary(&transfer_msg).unwrap(), }; @@ -564,7 +564,7 @@ mod contact_testing { ]; let expected_ics721_packet = Ics721Packet::new( - &"abc/123/collection-addr".to_string(), + "abc/123/collection-addr", None, transfer_msg .token_ids From 65f2db50a3b3696bf983810c83dc298a343fafd6 Mon Sep 17 00:00:00 2001 From: Humanalgorithm Date: Tue, 31 May 2022 15:57:13 -0400 Subject: [PATCH 08/33] refactor e2etest --- e2e/full_test.go | 140 ++++++++++++++++++++++++----------------------- 1 file changed, 71 insertions(+), 69 deletions(-) diff --git a/e2e/full_test.go b/e2e/full_test.go index 2bc93652..db212828 100644 --- a/e2e/full_test.go +++ b/e2e/full_test.go @@ -11,6 +11,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/public-awesome/stargaze/v4/app" "github.com/public-awesome/stargaze/v4/testutil/simapp" "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto" @@ -19,39 +20,6 @@ import ( ) var ( - // whitelist - - instantiateMinterTemplate = ` - { - "base_token_uri": "ipfs://...", - "num_tokens": 100, - "sg721_code_id": 3, - "sg721_instantiate_msg": { - "name": "Collection Name", - "symbol": "SYM", - "minter": "%s", - "collection_info": { - "contract_uri": "ipfs://...", - "creator": "%s", - "description": "Stargaze Monkeys", - "image": "https://example.com/image.png", - "external_link" : "https://stargaze.zone", - "royalty_info": { - "payment_address": "%s", - "share": "0.1" - } - } - }, - "start_time": "%d", - "whitelist" : %s, - "per_address_limit": %d, - "unit_price": { - "amount": "100000000", - "denom": "ustars" - } - } - ` - escrow721Template = ` { "name": "escrow721Channel1transfer-nft", @@ -59,6 +27,17 @@ var ( "minter": "%s" } ` + + escrow721MintTemplate = ` + { "mint": { + "class_id": "%s", + "token_id": "%s", + "owner": "%s", + "token_uri": "ipfs://abc123", + "extension": {} + } + } + ` ) type Account struct { @@ -99,16 +78,16 @@ func GetAccountsAndBalances(accs []Account) ([]authtypes.GenesisAccount, []bankt } return genAccs, balances } -func TestICS721(t *testing.T) { - accs := GetAccounts() +func LoadChain(t *testing.T) (addr1 sdk.AccAddress, ctx sdk.Context, app *app.App, accs []Account) { + accs = GetAccounts() genAccs, balances := GetAccountsAndBalances(accs) - app := simapp.SetupWithGenesisAccounts(t, t.TempDir(), genAccs, balances...) + app = simapp.SetupWithGenesisAccounts(t, t.TempDir(), genAccs, balances...) startDateTime, err := time.Parse(time.RFC3339Nano, "2022-03-11T20:59:00Z") require.NoError(t, err) - ctx := app.BaseApp.NewContext(false, tmproto.Header{Height: 1, ChainID: "stargaze-1", Time: startDateTime}) + ctx = app.BaseApp.NewContext(false, tmproto.Header{Height: 1, ChainID: "stargaze-1", Time: startDateTime}) // wasm params wasmParams := app.WasmKeeper.GetParams(ctx) @@ -118,12 +97,16 @@ func TestICS721(t *testing.T) { priv1 := secp256k1.GenPrivKey() pub1 := priv1.PubKey() - addr1 := sdk.AccAddress(pub1.Address()) + addr1 = sdk.AccAddress(pub1.Address()) + return addr1, ctx, app, accs +} +func LoadICS721(t *testing.T, addr1 sdk.AccAddress, ctx sdk.Context, app *app.App) ( + msgServer wasmtypes.MsgServer, err error) { b, err := ioutil.ReadFile("contracts/ics721.wasm") require.NoError(t, err) - msgServer := wasmkeeper.NewMsgServerImpl(wasmkeeper.NewDefaultPermissionKeeper(app.WasmKeeper)) + msgServer = wasmkeeper.NewMsgServerImpl(wasmkeeper.NewDefaultPermissionKeeper(app.WasmKeeper)) res, err := msgServer.StoreCode(sdk.WrapSDKContext(ctx), &wasmtypes.MsgStoreCode{ Sender: addr1.String(), WASMByteCode: b, @@ -132,11 +115,15 @@ func TestICS721(t *testing.T) { require.NotNil(t, res) require.Equal(t, res.CodeID, uint64(1)) println("ICS721.wasm has loaded!") + return msgServer, err +} - b, err = ioutil.ReadFile("contracts/escrow721.wasm") +func LoadEscrow721(t *testing.T, addr1 sdk.AccAddress, ctx sdk.Context, + app *app.App, msgServer wasmtypes.MsgServer) { + b, err := ioutil.ReadFile("contracts/escrow721.wasm") require.NoError(t, err) - res, err = msgServer.StoreCode(sdk.WrapSDKContext(ctx), &wasmtypes.MsgStoreCode{ + res, err := msgServer.StoreCode(sdk.WrapSDKContext(ctx), &wasmtypes.MsgStoreCode{ Sender: addr1.String(), WASMByteCode: b, }) @@ -144,7 +131,11 @@ func TestICS721(t *testing.T) { require.NotNil(t, res) require.Equal(t, res.CodeID, uint64(2)) println("escrow721.wasm has loaded!") +} +func InstantiateEscrow721(t *testing.T, ctx sdk.Context, + msgServer wasmtypes.MsgServer, accs []Account) ( + instantiateRes *wasmtypes.MsgInstantiateContractResponse) { creator := accs[0] instantiateMsgRaw := []byte( @@ -163,27 +154,14 @@ func TestICS721(t *testing.T) { require.NoError(t, err) require.NotNil(t, instantiateRes) require.NotEmpty(t, instantiateRes.Address) + return instantiateRes +} +func ExecuteMint(t *testing.T, ctx sdk.Context, msgServer wasmtypes.MsgServer, accs []Account, + instantiateRes *wasmtypes.MsgInstantiateContractResponse, mintMsgRaw []byte, err error) (mintErr error) { escrow721Address := instantiateRes.Address - escrow721MintTemplate := ` - { "mint": { - "class_id": "%s", - "token_id": "%s", - "owner": "%s", - "token_uri": "ipfs://abc123", - "extension": {} - } - } - ` - mintMsgRaw := []byte( - fmt.Sprintf(escrow721MintTemplate, - "omni/stars/transfer-nft", - "1", - creator.Address.String(), - ), - ) - _, mintErr := msgServer.ExecuteContract(sdk.WrapSDKContext(ctx), &wasmtypes.MsgExecuteContract{ + _, mintErr = msgServer.ExecuteContract(sdk.WrapSDKContext(ctx), &wasmtypes.MsgExecuteContract{ Contract: escrow721Address, Sender: accs[0].Address.String(), Msg: mintMsgRaw, @@ -192,7 +170,25 @@ func TestICS721(t *testing.T) { require.NotNil(t, instantiateRes) require.NotEmpty(t, instantiateRes.Address) require.NoError(t, mintErr) + return mintErr +} + +func MintTwoNFTs(t *testing.T) ( + app *app.App, ctx sdk.Context, instantiateRes *wasmtypes.MsgInstantiateContractResponse, creator Account) { + addr1, ctx, app, accs := LoadChain(t) + msgServer, err := LoadICS721(t, addr1, ctx, app) + LoadEscrow721(t, addr1, ctx, app, msgServer) + instantiateRes = InstantiateEscrow721(t, ctx, msgServer, accs) + creator = accs[0] + mintMsgRaw := []byte( + fmt.Sprintf(escrow721MintTemplate, + "omni/stars/transfer-nft", + "1", + creator.Address.String(), + ), + ) + ExecuteMint(t, ctx, msgServer, accs, instantiateRes, mintMsgRaw, err) mintMsgRaw = []byte( fmt.Sprintf(escrow721MintTemplate, "omni/stars/transfer-nft", @@ -200,18 +196,24 @@ func TestICS721(t *testing.T) { creator.Address.String(), ), ) - _, mintErr = msgServer.ExecuteContract(sdk.WrapSDKContext(ctx), &wasmtypes.MsgExecuteContract{ - Contract: escrow721Address, - Sender: creator.Address.String(), - Msg: mintMsgRaw, - }) - require.NoError(t, err) - require.NotNil(t, instantiateRes) - require.NotEmpty(t, instantiateRes.Address) - require.NoError(t, mintErr) + ExecuteMint(t, ctx, msgServer, accs, instantiateRes, mintMsgRaw, err) + return app, ctx, instantiateRes, creator +} + +func TestLoadChain(t *testing.T) { + LoadChain(t) +} +func TestMinting(t *testing.T) { + MintTwoNFTs(t) +} + +func TestQueryAfterMint(t *testing.T) { + app, ctx, instantiateRes, creator := MintTwoNFTs(t) + escrow721Address := instantiateRes.Address addr, _ := sdk.AccAddressFromBech32(escrow721Address) - result, err := app.WasmKeeper.QuerySmart(ctx, addr, []byte(`{"owner_of": {"token_id": "1", "class_id": "omni/stars/transfer-nft"}}`)) + result, err := app.WasmKeeper.QuerySmart( + ctx, addr, []byte(`{"owner_of": {"token_id": "1", "class_id": "omni/stars/transfer-nft"}}`)) expected_result := fmt.Sprintf("{\"owner\":\"%s\",\"approvals\":[]}", creator.Address.String()) require.Equal(t, string(result), expected_result) require.NoError(t, err) From 837d0f44fe372221e989c25d97edbfc06373052e Mon Sep 17 00:00:00 2001 From: Humanalgorithm Date: Thu, 2 Jun 2022 11:47:22 -0400 Subject: [PATCH 09/33] stashing to share code --- contracts/escrow721/src/contract.rs | 47 +++++++---- e2e/account.go | 13 +++ e2e/execute.go | 107 ++++++++++++++++++++++++ e2e/full_test.go | 122 ++++++++++------------------ e2e/query.go | 36 ++++++++ e2e/template.go | 39 +++++++++ 6 files changed, 270 insertions(+), 94 deletions(-) create mode 100644 e2e/account.go create mode 100644 e2e/execute.go create mode 100644 e2e/query.go create mode 100644 e2e/template.go diff --git a/contracts/escrow721/src/contract.rs b/contracts/escrow721/src/contract.rs index b7b4f42a..e8c729da 100644 --- a/contracts/escrow721/src/contract.rs +++ b/contracts/escrow721/src/contract.rs @@ -1,12 +1,15 @@ +use std::error::Error; + +use cosmwasm_std::StdError; #[cfg(not(feature = "library"))] use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Empty, Env, MessageInfo, StdResult}; -use cw721_base_ibc::msg::{ExecuteMsg, InstantiateMsg, MintMsg, QueryMsg}; +use cw721_base_ibc::msg::{InstantiateMsg, MintMsg, QueryMsg}; use cw721_base_ibc::{ContractError, Cw721Contract}; use cw721_ibc::{Cw721Execute, Cw721Query, OwnerOfResponse}; pub type CW721ContractWrapper<'a> = Cw721Contract<'a, Empty, Empty>; -pub fn instantiate_entry( +pub fn instantiate( deps: DepsMut, _env: Env, _info: MessageInfo, @@ -26,26 +29,34 @@ pub fn transfer( CW721ContractWrapper::default().transfer_nft(deps, env, info, recipient, class_id, token_id) } -pub fn execute( +pub fn mint( deps: DepsMut, - env: Env, + _env: Env, info: MessageInfo, - msg: ExecuteMsg, + class_id: String, + token_id: String, + token_uri: String, + receiver: String ) -> Result { - println!("in the execute"); - match msg { - ExecuteMsg::Mint(msg) => mint(deps, env, info, msg), - _ => Err(ContractError::Expired {}), - } + let mint_msg = MintMsg { + class_id, + token_id, + owner: receiver, + token_uri: Some(token_uri), + extension: Empty {} + }; + CW721ContractWrapper::default().mint(deps, _env, info, mint_msg) } -pub fn mint( +pub fn burn( deps: DepsMut, _env: Env, info: MessageInfo, - msg: MintMsg, + class_id: String, + token_id: String, ) -> Result { - CW721ContractWrapper::default().mint(deps, _env, info, msg) + CW721ContractWrapper::default().burn( + deps, _env, info, class_id, token_id) } pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { @@ -72,5 +83,13 @@ pub fn get_owner( token_id: String, include_expired: bool, ) -> StdResult { - CW721ContractWrapper::default().owner_of(deps, env, class_id, token_id, include_expired) + // CW721ContractWrapper::default().owner_of(deps, env, class_id, token_id, include_expired) + match include_expired { + true => Ok(OwnerOfResponse { + owner: "abc123".to_string(), + approvals: vec![] + }), + false => Err(StdError::GenericErr { msg: "abc123".to_string() } ) + } + } diff --git a/e2e/account.go b/e2e/account.go new file mode 100644 index 00000000..cf61867e --- /dev/null +++ b/e2e/account.go @@ -0,0 +1,13 @@ +package e2e_test + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/tendermint/tendermint/crypto" + "github.com/tendermint/tendermint/crypto/secp256k1" +) + +type Account struct { + PrivKey secp256k1.PrivKey + PubKey crypto.PubKey + Address sdk.AccAddress +} diff --git a/e2e/execute.go b/e2e/execute.go new file mode 100644 index 00000000..b50c1819 --- /dev/null +++ b/e2e/execute.go @@ -0,0 +1,107 @@ +package e2e_test + +import ( + "fmt" + "testing" + + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/public-awesome/stargaze/v4/app" + "github.com/stretchr/testify/require" +) + +func InstantiateEscrow721(t *testing.T, ctx sdk.Context, + msgServer wasmtypes.MsgServer, accs []Account) ( + instantiateRes *wasmtypes.MsgInstantiateContractResponse) { + creator := accs[0] + + instantiateMsgRaw := []byte( + fmt.Sprintf(escrow721Template, + creator.Address.String(), + ), + ) + instantiateRes, err := msgServer.InstantiateContract(sdk.WrapSDKContext(ctx), &wasmtypes.MsgInstantiateContract{ + Sender: creator.Address.String(), + Admin: creator.Address.String(), + CodeID: 2, + Label: "Escrow721", + Msg: instantiateMsgRaw, + Funds: sdk.NewCoins(sdk.NewInt64Coin("ustars", 1_000_000_000)), + }) + require.NoError(t, err) + require.NotNil(t, instantiateRes) + require.NotEmpty(t, instantiateRes.Address) + return instantiateRes +} + +func ExecuteMint(t *testing.T, ctx sdk.Context, msgServer wasmtypes.MsgServer, accs []Account, + instantiateRes *wasmtypes.MsgInstantiateContractResponse, mintMsgRaw []byte, err error) (mintErr error) { + escrow721Address := instantiateRes.Address + + _, mintErr = msgServer.ExecuteContract(sdk.WrapSDKContext(ctx), &wasmtypes.MsgExecuteContract{ + Contract: escrow721Address, + Sender: accs[0].Address.String(), + Msg: mintMsgRaw, + }) + require.NoError(t, err) + require.NotNil(t, instantiateRes) + require.NotEmpty(t, instantiateRes.Address) + require.NoError(t, mintErr) + return mintErr +} + +func ExecuteBurn(t *testing.T, ctx sdk.Context, msgServer wasmtypes.MsgServer, accs []Account, + instantiateRes *wasmtypes.MsgInstantiateContractResponse, burnMsgRaw []byte, err error) (burnErr error) { + escrow721Address := instantiateRes.Address + + _, burnErr = msgServer.ExecuteContract(sdk.WrapSDKContext(ctx), &wasmtypes.MsgExecuteContract{ + Contract: escrow721Address, + Sender: accs[0].Address.String(), + Msg: burnMsgRaw, + }) + require.NoError(t, err) + require.NotNil(t, instantiateRes) + require.NotEmpty(t, instantiateRes.Address) + require.NoError(t, burnErr) + return burnErr +} + +func ExecuteBurnError(t *testing.T, ctx sdk.Context, msgServer wasmtypes.MsgServer, accs []Account, + instantiateRes *wasmtypes.MsgInstantiateContractResponse, burnMsgRaw []byte, err error) (burnErr error) { + escrow721Address := instantiateRes.Address + + _, burnErr = msgServer.ExecuteContract(sdk.WrapSDKContext(ctx), &wasmtypes.MsgExecuteContract{ + Contract: escrow721Address, + Sender: accs[0].Address.String(), + Msg: burnMsgRaw, + }) + require.NoError(t, err) + require.NotNil(t, instantiateRes) + require.NotEmpty(t, instantiateRes.Address) + require.EqualError(t, burnErr, "cw721_base_ibc::state::TokenInfo> not found: execute wasm contract failed") + return burnErr +} + +func ExecuteGetOwner(t *testing.T, ctx sdk.Context, app *app.App, msgServer wasmtypes.MsgServer, accs []Account, + instantiateRes *wasmtypes.MsgInstantiateContractResponse, getOwnerMsgRaw []byte, err error) ( + result []byte) { + escrow721Address := instantiateRes.Address + + // result, ownerErr = msgServer.ExecuteContract(sdk.WrapSDKContext(ctx), &wasmtypes.MsgExecuteContract{ + // Contract: escrow721Address, + // Sender: accs[0].Address.String(), + // Msg: getOwnerMsgRaw, + // }) + // require.NoError(t, err) + // require.NotNil(t, instantiateRes) + // require.NotEmpty(t, instantiateRes.Address) + // require.NoError(t, ownerErr) + addr, _ := sdk.AccAddressFromBech32(escrow721Address) + result, _ = app.WasmKeeper.QuerySmart( + ctx, addr, []byte(`{"owner_of": {"token_id": "1", "class_id": "omni/stars/transfer-nft"}}`)) + + rawDecodedText := string(result) + println("data here is: ", rawDecodedText) + + return result +} diff --git a/e2e/full_test.go b/e2e/full_test.go index db212828..92fed940 100644 --- a/e2e/full_test.go +++ b/e2e/full_test.go @@ -14,38 +14,10 @@ import ( "github.com/public-awesome/stargaze/v4/app" "github.com/public-awesome/stargaze/v4/testutil/simapp" "github.com/stretchr/testify/require" - "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/secp256k1" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" ) -var ( - escrow721Template = ` - { - "name": "escrow721Channel1transfer-nft", - "symbol": "esw721_1_transfer-nft", - "minter": "%s" - } - ` - - escrow721MintTemplate = ` - { "mint": { - "class_id": "%s", - "token_id": "%s", - "owner": "%s", - "token_uri": "ipfs://abc123", - "extension": {} - } - } - ` -) - -type Account struct { - PrivKey secp256k1.PrivKey - PubKey crypto.PubKey - Address sdk.AccAddress -} - func GetAccounts() []Account { accounts := make([]Account, 0, 150) for i := 0; i < 150; i++ { @@ -133,53 +105,15 @@ func LoadEscrow721(t *testing.T, addr1 sdk.AccAddress, ctx sdk.Context, println("escrow721.wasm has loaded!") } -func InstantiateEscrow721(t *testing.T, ctx sdk.Context, - msgServer wasmtypes.MsgServer, accs []Account) ( - instantiateRes *wasmtypes.MsgInstantiateContractResponse) { - creator := accs[0] - - instantiateMsgRaw := []byte( - fmt.Sprintf(escrow721Template, - creator.Address.String(), - ), - ) - instantiateRes, err := msgServer.InstantiateContract(sdk.WrapSDKContext(ctx), &wasmtypes.MsgInstantiateContract{ - Sender: creator.Address.String(), - Admin: creator.Address.String(), - CodeID: 2, - Label: "Escrow721", - Msg: instantiateMsgRaw, - Funds: sdk.NewCoins(sdk.NewInt64Coin("ustars", 1_000_000_000)), - }) - require.NoError(t, err) - require.NotNil(t, instantiateRes) - require.NotEmpty(t, instantiateRes.Address) - return instantiateRes -} - -func ExecuteMint(t *testing.T, ctx sdk.Context, msgServer wasmtypes.MsgServer, accs []Account, - instantiateRes *wasmtypes.MsgInstantiateContractResponse, mintMsgRaw []byte, err error) (mintErr error) { - escrow721Address := instantiateRes.Address - - _, mintErr = msgServer.ExecuteContract(sdk.WrapSDKContext(ctx), &wasmtypes.MsgExecuteContract{ - Contract: escrow721Address, - Sender: accs[0].Address.String(), - Msg: mintMsgRaw, - }) - require.NoError(t, err) - require.NotNil(t, instantiateRes) - require.NotEmpty(t, instantiateRes.Address) - require.NoError(t, mintErr) - return mintErr -} - func MintTwoNFTs(t *testing.T) ( - app *app.App, ctx sdk.Context, instantiateRes *wasmtypes.MsgInstantiateContractResponse, creator Account) { + app *app.App, ctx sdk.Context, + instantiateRes *wasmtypes.MsgInstantiateContractResponse, accs []Account, + msgServer wasmtypes.MsgServer, err error) { addr1, ctx, app, accs := LoadChain(t) - msgServer, err := LoadICS721(t, addr1, ctx, app) + msgServer, err = LoadICS721(t, addr1, ctx, app) LoadEscrow721(t, addr1, ctx, app, msgServer) instantiateRes = InstantiateEscrow721(t, ctx, msgServer, accs) - creator = accs[0] + creator := accs[0] mintMsgRaw := []byte( fmt.Sprintf(escrow721MintTemplate, @@ -197,7 +131,7 @@ func MintTwoNFTs(t *testing.T) ( ), ) ExecuteMint(t, ctx, msgServer, accs, instantiateRes, mintMsgRaw, err) - return app, ctx, instantiateRes, creator + return app, ctx, instantiateRes, accs, msgServer, err } func TestLoadChain(t *testing.T) { @@ -208,14 +142,42 @@ func TestMinting(t *testing.T) { MintTwoNFTs(t) } +func TestBurn(t *testing.T) { + app, ctx, instantiateRes, accs, msgServer, err := MintTwoNFTs(t) + burnMsgRaw := []byte( + fmt.Sprintf(escrow721BurnTemplate, + "omni/stars/transfer-nft", + "1", + ), + ) + ExecuteBurn(t, ctx, msgServer, accs, instantiateRes, burnMsgRaw, err) + RunQueryEmpty(t, ctx, app, instantiateRes, accs[0]) + ExecuteBurnError(t, ctx, msgServer, accs, instantiateRes, burnMsgRaw, err) + + burnMsgRawFake := []byte( + fmt.Sprintf(escrow721BurnTemplate, + "super_fake_class", + "1", + ), + ) + ExecuteBurnError(t, ctx, msgServer, accs, instantiateRes, burnMsgRawFake, err) +} + func TestQueryAfterMint(t *testing.T) { - app, ctx, instantiateRes, creator := MintTwoNFTs(t) - escrow721Address := instantiateRes.Address - addr, _ := sdk.AccAddressFromBech32(escrow721Address) - result, err := app.WasmKeeper.QuerySmart( - ctx, addr, []byte(`{"owner_of": {"token_id": "1", "class_id": "omni/stars/transfer-nft"}}`)) - expected_result := fmt.Sprintf("{\"owner\":\"%s\",\"approvals\":[]}", creator.Address.String()) - require.Equal(t, string(result), expected_result) - require.NoError(t, err) + app, ctx, instantiateRes, accs, _, _ := MintTwoNFTs(t) + RunQuerySuccess(t, ctx, app, instantiateRes, accs[0]) +} + +func TestGetOwner(t *testing.T) { + app, ctx, instantiateRes, accs, msgServer, err := MintTwoNFTs(t) + getOwnerMsgRaw := []byte( + fmt.Sprintf(escrow721GetOwnerTemplate, + "omni/stars/transfer-nft", + "1", + ), + ) + ExecuteGetOwner(t, ctx, app, msgServer, accs, instantiateRes, getOwnerMsgRaw, err) + // println("result is ", result) + // println("ownerErr is ", ownerErr) } diff --git a/e2e/query.go b/e2e/query.go new file mode 100644 index 00000000..3dfce2d9 --- /dev/null +++ b/e2e/query.go @@ -0,0 +1,36 @@ +package e2e_test + +import ( + "fmt" + "testing" + + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/public-awesome/stargaze/v4/app" + "github.com/stretchr/testify/require" +) + +func RunQuerySuccess(t *testing.T, ctx sdk.Context, app *app.App, + instantiateRes *wasmtypes.MsgInstantiateContractResponse, creator Account) { + escrow721Address := instantiateRes.Address + + addr, _ := sdk.AccAddressFromBech32(escrow721Address) + result, err := app.WasmKeeper.QuerySmart( + ctx, addr, []byte(`{"owner_of": {"token_id": "1", "class_id": "omni/stars/transfer-nft"}}`)) + expected_result := fmt.Sprintf("{\"owner\":\"%s\",\"approvals\":[]}", creator.Address.String()) + require.Equal(t, string(result), expected_result) + require.NoError(t, err) +} + +func RunQueryEmpty(t *testing.T, ctx sdk.Context, app *app.App, + instantiateRes *wasmtypes.MsgInstantiateContractResponse, creator Account) { + escrow721Address := instantiateRes.Address + + addr, _ := sdk.AccAddressFromBech32(escrow721Address) + result, err := app.WasmKeeper.QuerySmart( + ctx, addr, []byte(`{"owner_of": {"token_id": "1", "class_id": "omni/stars/transfer-nft"}}`)) + expected_result := "" + require.Equal(t, string(result), expected_result) + require.EqualError(t, err, "cw721_base_ibc::state::TokenInfo> not found: query wasm contract failed") +} diff --git a/e2e/template.go b/e2e/template.go new file mode 100644 index 00000000..6344af24 --- /dev/null +++ b/e2e/template.go @@ -0,0 +1,39 @@ +package e2e_test + +var ( + escrow721Template = ` + { + "name": "escrow721Channel1transfer-nft", + "symbol": "esw721_1_transfer-nft", + "minter": "%s" + } + ` + + escrow721MintTemplate = ` + { "mint": { + "class_id": "%s", + "token_id": "%s", + "owner": "%s", + "token_uri": "ipfs://abc123", + "extension": {} + } + } + ` + + escrow721BurnTemplate = ` + { "burn": { + "class_id": "%s", + "token_id": "%s" + } + } + ` + + escrow721GetOwnerTemplate = ` + { + "owner_of": { + "class_id": "%s", + "token_id": "%s" + } + } + ` +) From a1d0e4043b867cfa39e7211cce7e71160f56a587 Mon Sep 17 00:00:00 2001 From: Humanalgorithm Date: Thu, 2 Jun 2022 17:11:55 -0400 Subject: [PATCH 10/33] working get owner query --- Cargo.lock | 153 ++++++++++++++++++++++++++++ contracts/escrow721/Cargo.toml | 5 +- contracts/escrow721/src/contract.rs | 34 ++++--- contracts/escrow721/src/lib.rs | 2 +- e2e/execute.go | 22 +--- e2e/full_test.go | 60 ++++++----- e2e/template.go | 7 +- 7 files changed, 215 insertions(+), 68 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bf4fe899..9c1092ed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -223,6 +223,34 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cw721" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b9fd71276795554c35899bb3a378561ed0c288d231113e9915f6ee1f42b7b5" +dependencies = [ + "cosmwasm-std", + "cw-utils", + "schemars", + "serde", +] + +[[package]] +name = "cw721-base" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b61200af4e027af2d7485dbdc37c2a9c4093b6b2f2b811732329ef456076f97e" +dependencies = [ + "cosmwasm-std", + "cw-storage-plus", + "cw-utils", + "cw2", + "cw721", + "schemars", + "serde", + "thiserror", +] + [[package]] name = "cw721-base-ibc" version = "0.13.2" @@ -331,6 +359,7 @@ dependencies = [ "cw721-ibc", "schemars", "serde", + "sg721", "thiserror", ] @@ -344,6 +373,16 @@ dependencies = [ "subtle", ] +[[package]] +name = "form_urlencoded" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" +dependencies = [ + "matches", + "percent-encoding", +] + [[package]] name = "forward_ref" version = "1.0.0" @@ -427,6 +466,17 @@ dependencies = [ "thiserror", ] +[[package]] +name = "idna" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" +dependencies = [ + "matches", + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "itoa" version = "1.0.1" @@ -451,12 +501,24 @@ version = "0.2.124" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "21a41fed9d98f27ab1c6d161da622a4fa35e8a54a8adc24bbf3ddd0ef70b0e50" +[[package]] +name = "matches" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" + [[package]] name = "opaque-debug" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" +[[package]] +name = "percent-encoding" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" + [[package]] name = "pkcs8" version = "0.7.6" @@ -590,6 +652,55 @@ dependencies = [ "serde", ] +[[package]] +name = "sg-std" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8333ebd66ab56cd6f83368598c3f810e95b41a10fd81ac3e447792996824deba" +dependencies = [ + "cosmwasm-std", + "cw-utils", + "cw721", + "cw721-base", + "schemars", + "serde", + "thiserror", +] + +[[package]] +name = "sg1" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b9b26273bdcfd32e1f8adfd99a4d168717fa5adc570c8b67b4081037791e212" +dependencies = [ + "cosmwasm-std", + "cw-utils", + "serde", + "sg-std", + "thiserror", +] + +[[package]] +name = "sg721" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10578a37c6be874e4db80d9d9231d834c751154c6b2c8f1e5facff03edf4ab08" +dependencies = [ + "cosmwasm-std", + "cosmwasm-storage", + "cw-storage-plus", + "cw-utils", + "cw2", + "cw721", + "cw721-base", + "schemars", + "serde", + "sg-std", + "sg1", + "thiserror", + "url", +] + [[package]] name = "sha2" version = "0.9.9" @@ -665,6 +776,21 @@ dependencies = [ "syn", ] +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" + [[package]] name = "typenum" version = "1.15.0" @@ -683,12 +809,39 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "unicode-bidi" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" + +[[package]] +name = "unicode-normalization" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9" +dependencies = [ + "tinyvec", +] + [[package]] name = "unicode-xid" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" +[[package]] +name = "url" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" +dependencies = [ + "form_urlencoded", + "idna", + "matches", + "percent-encoding", +] + [[package]] name = "version_check" version = "0.9.4" diff --git a/contracts/escrow721/Cargo.toml b/contracts/escrow721/Cargo.toml index f925e41e..39a4f371 100644 --- a/contracts/escrow721/Cargo.toml +++ b/contracts/escrow721/Cargo.toml @@ -36,8 +36,9 @@ cw-storage-plus = "0.13.2" cw-utils = "0.13.2" cw2 = "0.13.2" cw20-ics20 = { version = "0.13.2", features = ["library"] } -cw721-base-ibc = { git = "https://github.com/public-awesome/cw721-ibc.git", version="0.13.2"} -cw721-ibc = { git = "https://github.com/public-awesome/cw721-ibc.git", version="0.13.2"} +sg721 = { version = "0.12.0", features = ["library"] } +cw721-base-ibc = { git = "https://github.com/public-awesome/cw721-ibc.git", version = "0.13.2", features = ["library"]} +cw721-ibc = { git = "https://github.com/public-awesome/cw721-ibc.git", version = "0.13.2"} schemars = "0.8.8" serde = { version = "1.0.133", default-features = false, features = ["derive"] } thiserror = { version = "1.0.30" } diff --git a/contracts/escrow721/src/contract.rs b/contracts/escrow721/src/contract.rs index e8c729da..7bd30d0d 100644 --- a/contracts/escrow721/src/contract.rs +++ b/contracts/escrow721/src/contract.rs @@ -1,14 +1,16 @@ use std::error::Error; - +use cosmwasm_std::Response; +use cosmwasm_std::entry_point; use cosmwasm_std::StdError; #[cfg(not(feature = "library"))] use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Empty, Env, MessageInfo, StdResult}; -use cw721_base_ibc::msg::{InstantiateMsg, MintMsg, QueryMsg}; +use cw721_base_ibc::msg::{InstantiateMsg, MintMsg, QueryMsg, ExecuteMsg}; use cw721_base_ibc::{ContractError, Cw721Contract}; use cw721_ibc::{Cw721Execute, Cw721Query, OwnerOfResponse}; pub type CW721ContractWrapper<'a> = Cw721Contract<'a, Empty, Empty>; +#[cfg_attr(not(feature = "library"), entry_point)] pub fn instantiate( deps: DepsMut, _env: Env, @@ -18,6 +20,17 @@ pub fn instantiate( CW721ContractWrapper::default().instantiate(deps, _env, _info, msg) } +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn execute( + deps: DepsMut, + env: Env, + info: MessageInfo, + msg: ExecuteMsg, +) -> Result, ContractError> { + CW721ContractWrapper::default().execute(deps, env, info, msg) + +} + pub fn transfer( deps: DepsMut, env: Env, @@ -59,6 +72,7 @@ pub fn burn( deps, _env, info, class_id, token_id) } +#[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { match msg { QueryMsg::OwnerOf { @@ -68,14 +82,16 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { } => to_binary(&get_owner( deps, _env, - class_id, + class_id.to_string(), token_id, include_expired.unwrap_or(false), )?), - _ => CW721ContractWrapper::default().query(deps, _env, msg), + _ => Err(StdError::GenericErr { msg: "Unsupported message type".to_string() } ) + } } + pub fn get_owner( deps: Deps, env: Env, @@ -83,13 +99,5 @@ pub fn get_owner( token_id: String, include_expired: bool, ) -> StdResult { - // CW721ContractWrapper::default().owner_of(deps, env, class_id, token_id, include_expired) - match include_expired { - true => Ok(OwnerOfResponse { - owner: "abc123".to_string(), - approvals: vec![] - }), - false => Err(StdError::GenericErr { msg: "abc123".to_string() } ) - } - + CW721ContractWrapper::default().owner_of(deps, env, class_id, token_id, include_expired) } diff --git a/contracts/escrow721/src/lib.rs b/contracts/escrow721/src/lib.rs index 112ecadc..1041aa71 100644 --- a/contracts/escrow721/src/lib.rs +++ b/contracts/escrow721/src/lib.rs @@ -1,2 +1,2 @@ pub mod contract; -pub mod msg; +pub mod msg; \ No newline at end of file diff --git a/e2e/execute.go b/e2e/execute.go index b50c1819..2ea70bc0 100644 --- a/e2e/execute.go +++ b/e2e/execute.go @@ -83,25 +83,13 @@ func ExecuteBurnError(t *testing.T, ctx sdk.Context, msgServer wasmtypes.MsgServ } func ExecuteGetOwner(t *testing.T, ctx sdk.Context, app *app.App, msgServer wasmtypes.MsgServer, accs []Account, - instantiateRes *wasmtypes.MsgInstantiateContractResponse, getOwnerMsgRaw []byte, err error) ( - result []byte) { + instantiateRes *wasmtypes.MsgInstantiateContractResponse, getOwnerMsgRaw []byte, err error) { escrow721Address := instantiateRes.Address - // result, ownerErr = msgServer.ExecuteContract(sdk.WrapSDKContext(ctx), &wasmtypes.MsgExecuteContract{ - // Contract: escrow721Address, - // Sender: accs[0].Address.String(), - // Msg: getOwnerMsgRaw, - // }) - // require.NoError(t, err) - // require.NotNil(t, instantiateRes) - // require.NotEmpty(t, instantiateRes.Address) - // require.NoError(t, ownerErr) addr, _ := sdk.AccAddressFromBech32(escrow721Address) - result, _ = app.WasmKeeper.QuerySmart( - ctx, addr, []byte(`{"owner_of": {"token_id": "1", "class_id": "omni/stars/transfer-nft"}}`)) + result, _ := app.WasmKeeper.QuerySmart( + ctx, addr, getOwnerMsgRaw) - rawDecodedText := string(result) - println("data here is: ", rawDecodedText) - - return result + expected_result := string(fmt.Sprintf(`{"owner":"%s","approvals":[]}`, accs[0].Address)) + require.Equal(t, string(result), expected_result) } diff --git a/e2e/full_test.go b/e2e/full_test.go index 92fed940..a4d91379 100644 --- a/e2e/full_test.go +++ b/e2e/full_test.go @@ -142,40 +142,38 @@ func TestMinting(t *testing.T) { MintTwoNFTs(t) } -func TestBurn(t *testing.T) { - app, ctx, instantiateRes, accs, msgServer, err := MintTwoNFTs(t) - burnMsgRaw := []byte( - fmt.Sprintf(escrow721BurnTemplate, - "omni/stars/transfer-nft", - "1", - ), - ) - ExecuteBurn(t, ctx, msgServer, accs, instantiateRes, burnMsgRaw, err) - RunQueryEmpty(t, ctx, app, instantiateRes, accs[0]) - ExecuteBurnError(t, ctx, msgServer, accs, instantiateRes, burnMsgRaw, err) - - burnMsgRawFake := []byte( - fmt.Sprintf(escrow721BurnTemplate, - "super_fake_class", - "1", - ), - ) - ExecuteBurnError(t, ctx, msgServer, accs, instantiateRes, burnMsgRawFake, err) -} - -func TestQueryAfterMint(t *testing.T) { - app, ctx, instantiateRes, accs, _, _ := MintTwoNFTs(t) - RunQuerySuccess(t, ctx, app, instantiateRes, accs[0]) -} +// func TestBurn(t *testing.T) { +// app, ctx, instantiateRes, accs, msgServer, err := MintTwoNFTs(t) +// burnMsgRaw := []byte( +// fmt.Sprintf(escrow721BurnTemplate, +// "omni/stars/transfer-nft", +// "1", +// ), +// ) +// ExecuteBurn(t, ctx, msgServer, accs, instantiateRes, burnMsgRaw, err) +// RunQueryEmpty(t, ctx, app, instantiateRes, accs[0]) +// ExecuteBurnError(t, ctx, msgServer, accs, instantiateRes, burnMsgRaw, err) + +// burnMsgRawFake := []byte( +// fmt.Sprintf(escrow721BurnTemplate, +// "super_fake_class", +// "1", +// ), +// ) +// ExecuteBurnError(t, ctx, msgServer, accs, instantiateRes, burnMsgRawFake, err) +// } + +// func TestQueryAfterMint(t *testing.T) { +// app, ctx, instantiateRes, accs, _, _ := MintTwoNFTs(t) +// RunQuerySuccess(t, ctx, app, instantiateRes, accs[0]) +// } func TestGetOwner(t *testing.T) { app, ctx, instantiateRes, accs, msgServer, err := MintTwoNFTs(t) - getOwnerMsgRaw := []byte( - fmt.Sprintf(escrow721GetOwnerTemplate, - "omni/stars/transfer-nft", - "1", - ), - ) + getOwnerMsgRaw := []byte(fmt.Sprintf(escrow721GetOwnerTemplate, + "omni/stars/transfer-nft", + "1", + )) ExecuteGetOwner(t, ctx, app, msgServer, accs, instantiateRes, getOwnerMsgRaw, err) // println("result is ", result) // println("ownerErr is ", ownerErr) diff --git a/e2e/template.go b/e2e/template.go index 6344af24..22b7b548 100644 --- a/e2e/template.go +++ b/e2e/template.go @@ -30,10 +30,9 @@ var ( escrow721GetOwnerTemplate = ` { - "owner_of": { + "owner_of": { "class_id": "%s", - "token_id": "%s" - } - } + "token_id": "%s"} + } ` ) From f6e8f15725b76d83c9069aa223f02adc2e00077f Mon Sep 17 00:00:00 2001 From: Humanalgorithm Date: Thu, 2 Jun 2022 17:16:51 -0400 Subject: [PATCH 11/33] uncomment test --- e2e/execute.go | 2 +- e2e/full_test.go | 52 +++++++++++++++++++++++------------------------- e2e/query.go | 3 +-- 3 files changed, 27 insertions(+), 30 deletions(-) diff --git a/e2e/execute.go b/e2e/execute.go index 2ea70bc0..6cc21faa 100644 --- a/e2e/execute.go +++ b/e2e/execute.go @@ -78,7 +78,7 @@ func ExecuteBurnError(t *testing.T, ctx sdk.Context, msgServer wasmtypes.MsgServ require.NoError(t, err) require.NotNil(t, instantiateRes) require.NotEmpty(t, instantiateRes.Address) - require.EqualError(t, burnErr, "cw721_base_ibc::state::TokenInfo> not found: execute wasm contract failed") + require.EqualError(t, burnErr, "cw721_base_ibc::state::TokenInfo not found: execute wasm contract failed") return burnErr } diff --git a/e2e/full_test.go b/e2e/full_test.go index a4d91379..882f5ad2 100644 --- a/e2e/full_test.go +++ b/e2e/full_test.go @@ -142,31 +142,31 @@ func TestMinting(t *testing.T) { MintTwoNFTs(t) } -// func TestBurn(t *testing.T) { -// app, ctx, instantiateRes, accs, msgServer, err := MintTwoNFTs(t) -// burnMsgRaw := []byte( -// fmt.Sprintf(escrow721BurnTemplate, -// "omni/stars/transfer-nft", -// "1", -// ), -// ) -// ExecuteBurn(t, ctx, msgServer, accs, instantiateRes, burnMsgRaw, err) -// RunQueryEmpty(t, ctx, app, instantiateRes, accs[0]) -// ExecuteBurnError(t, ctx, msgServer, accs, instantiateRes, burnMsgRaw, err) - -// burnMsgRawFake := []byte( -// fmt.Sprintf(escrow721BurnTemplate, -// "super_fake_class", -// "1", -// ), -// ) -// ExecuteBurnError(t, ctx, msgServer, accs, instantiateRes, burnMsgRawFake, err) -// } - -// func TestQueryAfterMint(t *testing.T) { -// app, ctx, instantiateRes, accs, _, _ := MintTwoNFTs(t) -// RunQuerySuccess(t, ctx, app, instantiateRes, accs[0]) -// } +func TestBurn(t *testing.T) { + app, ctx, instantiateRes, accs, msgServer, err := MintTwoNFTs(t) + burnMsgRaw := []byte( + fmt.Sprintf(escrow721BurnTemplate, + "omni/stars/transfer-nft", + "1", + ), + ) + ExecuteBurn(t, ctx, msgServer, accs, instantiateRes, burnMsgRaw, err) + RunQueryEmpty(t, ctx, app, instantiateRes, accs[0]) + ExecuteBurnError(t, ctx, msgServer, accs, instantiateRes, burnMsgRaw, err) + + burnMsgRawFake := []byte( + fmt.Sprintf(escrow721BurnTemplate, + "super_fake_class", + "1", + ), + ) + ExecuteBurnError(t, ctx, msgServer, accs, instantiateRes, burnMsgRawFake, err) +} + +func TestQueryAfterMint(t *testing.T) { + app, ctx, instantiateRes, accs, _, _ := MintTwoNFTs(t) + RunQuerySuccess(t, ctx, app, instantiateRes, accs[0]) +} func TestGetOwner(t *testing.T) { app, ctx, instantiateRes, accs, msgServer, err := MintTwoNFTs(t) @@ -175,7 +175,5 @@ func TestGetOwner(t *testing.T) { "1", )) ExecuteGetOwner(t, ctx, app, msgServer, accs, instantiateRes, getOwnerMsgRaw, err) - // println("result is ", result) - // println("ownerErr is ", ownerErr) } diff --git a/e2e/query.go b/e2e/query.go index 3dfce2d9..ee23629c 100644 --- a/e2e/query.go +++ b/e2e/query.go @@ -31,6 +31,5 @@ func RunQueryEmpty(t *testing.T, ctx sdk.Context, app *app.App, ctx, addr, []byte(`{"owner_of": {"token_id": "1", "class_id": "omni/stars/transfer-nft"}}`)) expected_result := "" require.Equal(t, string(result), expected_result) - require.EqualError(t, err, "cw721_base_ibc::state::TokenInfo> not found: query wasm contract failed") + require.EqualError(t, err, "cw721_base_ibc::state::TokenInfo not found: query wasm contract failed") } From 1979b7de8c09cfe7bf8d78a8839ae3adbbf376ca Mon Sep 17 00:00:00 2001 From: Humanalgorithm Date: Thu, 2 Jun 2022 17:19:10 -0400 Subject: [PATCH 12/33] lint --- contracts/escrow721/src/contract.rs | 29 +++++++++++++---------------- contracts/escrow721/src/lib.rs | 2 +- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/contracts/escrow721/src/contract.rs b/contracts/escrow721/src/contract.rs index 7bd30d0d..1ca7d2b4 100644 --- a/contracts/escrow721/src/contract.rs +++ b/contracts/escrow721/src/contract.rs @@ -1,10 +1,9 @@ -use std::error::Error; -use cosmwasm_std::Response; use cosmwasm_std::entry_point; +use cosmwasm_std::Response; use cosmwasm_std::StdError; #[cfg(not(feature = "library"))] use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Empty, Env, MessageInfo, StdResult}; -use cw721_base_ibc::msg::{InstantiateMsg, MintMsg, QueryMsg, ExecuteMsg}; +use cw721_base_ibc::msg::{ExecuteMsg, InstantiateMsg, MintMsg, QueryMsg}; use cw721_base_ibc::{ContractError, Cw721Contract}; use cw721_ibc::{Cw721Execute, Cw721Query, OwnerOfResponse}; @@ -28,7 +27,6 @@ pub fn execute( msg: ExecuteMsg, ) -> Result, ContractError> { CW721ContractWrapper::default().execute(deps, env, info, msg) - } pub fn transfer( @@ -46,17 +44,17 @@ pub fn mint( deps: DepsMut, _env: Env, info: MessageInfo, - class_id: String, - token_id: String, + class_id: String, + token_id: String, token_uri: String, - receiver: String + receiver: String, ) -> Result { let mint_msg = MintMsg { class_id, token_id, owner: receiver, - token_uri: Some(token_uri), - extension: Empty {} + token_uri: Some(token_uri), + extension: Empty {}, }; CW721ContractWrapper::default().mint(deps, _env, info, mint_msg) } @@ -65,11 +63,10 @@ pub fn burn( deps: DepsMut, _env: Env, info: MessageInfo, - class_id: String, + class_id: String, token_id: String, ) -> Result { - CW721ContractWrapper::default().burn( - deps, _env, info, class_id, token_id) + CW721ContractWrapper::default().burn(deps, _env, info, class_id, token_id) } #[cfg_attr(not(feature = "library"), entry_point)] @@ -82,16 +79,16 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { } => to_binary(&get_owner( deps, _env, - class_id.to_string(), + class_id, token_id, include_expired.unwrap_or(false), )?), - _ => Err(StdError::GenericErr { msg: "Unsupported message type".to_string() } ) - + _ => Err(StdError::GenericErr { + msg: "Unsupported message type".to_string(), + }), } } - pub fn get_owner( deps: Deps, env: Env, diff --git a/contracts/escrow721/src/lib.rs b/contracts/escrow721/src/lib.rs index 1041aa71..112ecadc 100644 --- a/contracts/escrow721/src/lib.rs +++ b/contracts/escrow721/src/lib.rs @@ -1,2 +1,2 @@ pub mod contract; -pub mod msg; \ No newline at end of file +pub mod msg; From 16cd95d6ec7cc22134ab3a79090fd63ea655f579 Mon Sep 17 00:00:00 2001 From: Humanalgorithm Date: Thu, 2 Jun 2022 17:38:55 -0400 Subject: [PATCH 13/33] working get nft info --- contracts/escrow721/src/contract.rs | 18 +++++++++++++++++- e2e/execute.go | 12 ++++++++++++ e2e/full_test.go | 10 ++++++++++ e2e/template.go | 8 ++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/contracts/escrow721/src/contract.rs b/contracts/escrow721/src/contract.rs index 1ca7d2b4..a983035a 100644 --- a/contracts/escrow721/src/contract.rs +++ b/contracts/escrow721/src/contract.rs @@ -5,7 +5,7 @@ use cosmwasm_std::StdError; use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Empty, Env, MessageInfo, StdResult}; use cw721_base_ibc::msg::{ExecuteMsg, InstantiateMsg, MintMsg, QueryMsg}; use cw721_base_ibc::{ContractError, Cw721Contract}; -use cw721_ibc::{Cw721Execute, Cw721Query, OwnerOfResponse}; +use cw721_ibc::{Cw721Execute, Cw721Query, OwnerOfResponse, NftInfoResponse}; pub type CW721ContractWrapper<'a> = Cw721Contract<'a, Empty, Empty>; @@ -83,6 +83,14 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { token_id, include_expired.unwrap_or(false), )?), + QueryMsg::NftInfo { + class_id, + token_id, + } => to_binary(&nft_info( + deps, + class_id, + token_id + )?), _ => Err(StdError::GenericErr { msg: "Unsupported message type".to_string(), }), @@ -98,3 +106,11 @@ pub fn get_owner( ) -> StdResult { CW721ContractWrapper::default().owner_of(deps, env, class_id, token_id, include_expired) } + +fn nft_info( + deps: Deps, + class_id: String, + token_id: String, +) -> StdResult> { + CW721ContractWrapper::default().nft_info(deps, class_id, token_id) +} diff --git a/e2e/execute.go b/e2e/execute.go index 6cc21faa..28ef484e 100644 --- a/e2e/execute.go +++ b/e2e/execute.go @@ -93,3 +93,15 @@ func ExecuteGetOwner(t *testing.T, ctx sdk.Context, app *app.App, msgServer wasm expected_result := string(fmt.Sprintf(`{"owner":"%s","approvals":[]}`, accs[0].Address)) require.Equal(t, string(result), expected_result) } + +func ExecuteGetNFTInfo(t *testing.T, ctx sdk.Context, app *app.App, msgServer wasmtypes.MsgServer, accs []Account, + instantiateRes *wasmtypes.MsgInstantiateContractResponse, getNFTInfoMsgRaw []byte, err error) { + escrow721Address := instantiateRes.Address + + addr, _ := sdk.AccAddressFromBech32(escrow721Address) + result, _ := app.WasmKeeper.QuerySmart( + ctx, addr, getNFTInfoMsgRaw) + + expected_result := string(`{"token_uri":"ipfs://abc123","extension":{}}`) + require.Equal(t, string(result), expected_result) +} diff --git a/e2e/full_test.go b/e2e/full_test.go index 882f5ad2..441c0210 100644 --- a/e2e/full_test.go +++ b/e2e/full_test.go @@ -177,3 +177,13 @@ func TestGetOwner(t *testing.T) { ExecuteGetOwner(t, ctx, app, msgServer, accs, instantiateRes, getOwnerMsgRaw, err) } + +func TestGetNFTInfo(t *testing.T) { + app, ctx, instantiateRes, accs, msgServer, err := MintTwoNFTs(t) + getNFTInfoMsgRaw := []byte(fmt.Sprintf(escrow721GetNFTInfoTemplate, + "omni/stars/transfer-nft", + "1", + )) + ExecuteGetNFTInfo(t, ctx, app, msgServer, accs, instantiateRes, getNFTInfoMsgRaw, err) + +} diff --git a/e2e/template.go b/e2e/template.go index 22b7b548..004bb716 100644 --- a/e2e/template.go +++ b/e2e/template.go @@ -35,4 +35,12 @@ var ( "token_id": "%s"} } ` + + escrow721GetNFTInfoTemplate = ` + { + "nft_info": { + "class_id": "%s", + "token_id": "%s"} + } + ` ) From e22d94cc97ce330c216c983b4a454a25825b81d0 Mon Sep 17 00:00:00 2001 From: Humanalgorithm Date: Thu, 2 Jun 2022 17:42:20 -0400 Subject: [PATCH 14/33] fix lint --- contracts/escrow721/src/contract.rs | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/contracts/escrow721/src/contract.rs b/contracts/escrow721/src/contract.rs index a983035a..bfcbf180 100644 --- a/contracts/escrow721/src/contract.rs +++ b/contracts/escrow721/src/contract.rs @@ -5,7 +5,7 @@ use cosmwasm_std::StdError; use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Empty, Env, MessageInfo, StdResult}; use cw721_base_ibc::msg::{ExecuteMsg, InstantiateMsg, MintMsg, QueryMsg}; use cw721_base_ibc::{ContractError, Cw721Contract}; -use cw721_ibc::{Cw721Execute, Cw721Query, OwnerOfResponse, NftInfoResponse}; +use cw721_ibc::{Cw721Execute, Cw721Query, NftInfoResponse, OwnerOfResponse}; pub type CW721ContractWrapper<'a> = Cw721Contract<'a, Empty, Empty>; @@ -83,14 +83,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { token_id, include_expired.unwrap_or(false), )?), - QueryMsg::NftInfo { - class_id, - token_id, - } => to_binary(&nft_info( - deps, - class_id, - token_id - )?), + QueryMsg::NftInfo { class_id, token_id } => to_binary(&nft_info(deps, class_id, token_id)?), _ => Err(StdError::GenericErr { msg: "Unsupported message type".to_string(), }), @@ -107,10 +100,6 @@ pub fn get_owner( CW721ContractWrapper::default().owner_of(deps, env, class_id, token_id, include_expired) } -fn nft_info( - deps: Deps, - class_id: String, - token_id: String, -) -> StdResult> { +fn nft_info(deps: Deps, class_id: String, token_id: String) -> StdResult> { CW721ContractWrapper::default().nft_info(deps, class_id, token_id) } From 57ae1b11e4d6db2b10194c7c3c11f8e292fe70c5 Mon Sep 17 00:00:00 2001 From: Humanalgorithm Date: Thu, 2 Jun 2022 19:28:17 -0400 Subject: [PATCH 15/33] working transfer NFT --- e2e/execute.go | 31 +++++++++++-------------------- e2e/full_test.go | 17 ++++++++++++++--- e2e/query.go | 24 ++++++++++++++++++++++++ e2e/template.go | 9 +++++++++ 4 files changed, 58 insertions(+), 23 deletions(-) diff --git a/e2e/execute.go b/e2e/execute.go index 28ef484e..ef2d5674 100644 --- a/e2e/execute.go +++ b/e2e/execute.go @@ -82,26 +82,17 @@ func ExecuteBurnError(t *testing.T, ctx sdk.Context, msgServer wasmtypes.MsgServ return burnErr } -func ExecuteGetOwner(t *testing.T, ctx sdk.Context, app *app.App, msgServer wasmtypes.MsgServer, accs []Account, - instantiateRes *wasmtypes.MsgInstantiateContractResponse, getOwnerMsgRaw []byte, err error) { +func ExecuteTransferNFT(t *testing.T, ctx sdk.Context, app *app.App, msgServer wasmtypes.MsgServer, accs []Account, + instantiateRes *wasmtypes.MsgInstantiateContractResponse, transferMsgRaw []byte, err error) { escrow721Address := instantiateRes.Address - addr, _ := sdk.AccAddressFromBech32(escrow721Address) - result, _ := app.WasmKeeper.QuerySmart( - ctx, addr, getOwnerMsgRaw) - - expected_result := string(fmt.Sprintf(`{"owner":"%s","approvals":[]}`, accs[0].Address)) - require.Equal(t, string(result), expected_result) -} - -func ExecuteGetNFTInfo(t *testing.T, ctx sdk.Context, app *app.App, msgServer wasmtypes.MsgServer, accs []Account, - instantiateRes *wasmtypes.MsgInstantiateContractResponse, getNFTInfoMsgRaw []byte, err error) { - escrow721Address := instantiateRes.Address - - addr, _ := sdk.AccAddressFromBech32(escrow721Address) - result, _ := app.WasmKeeper.QuerySmart( - ctx, addr, getNFTInfoMsgRaw) - - expected_result := string(`{"token_uri":"ipfs://abc123","extension":{}}`) - require.Equal(t, string(result), expected_result) + _, transferErr := msgServer.ExecuteContract(sdk.WrapSDKContext(ctx), &wasmtypes.MsgExecuteContract{ + Contract: escrow721Address, + Sender: accs[0].Address.String(), + Msg: transferMsgRaw, + }) + require.NoError(t, err) + require.NotNil(t, instantiateRes) + require.NotEmpty(t, instantiateRes.Address) + require.NoError(t, transferErr) } diff --git a/e2e/full_test.go b/e2e/full_test.go index 441c0210..6bb078f3 100644 --- a/e2e/full_test.go +++ b/e2e/full_test.go @@ -169,12 +169,12 @@ func TestQueryAfterMint(t *testing.T) { } func TestGetOwner(t *testing.T) { - app, ctx, instantiateRes, accs, msgServer, err := MintTwoNFTs(t) + app, ctx, instantiateRes, accs, msgServer, _ := MintTwoNFTs(t) getOwnerMsgRaw := []byte(fmt.Sprintf(escrow721GetOwnerTemplate, "omni/stars/transfer-nft", "1", )) - ExecuteGetOwner(t, ctx, app, msgServer, accs, instantiateRes, getOwnerMsgRaw, err) + RunGetOwner(t, ctx, app, msgServer, accs, instantiateRes, getOwnerMsgRaw, accs[0].Address) } @@ -184,6 +184,17 @@ func TestGetNFTInfo(t *testing.T) { "omni/stars/transfer-nft", "1", )) - ExecuteGetNFTInfo(t, ctx, app, msgServer, accs, instantiateRes, getNFTInfoMsgRaw, err) + RunGetNFTInfo(t, ctx, app, msgServer, accs, instantiateRes, getNFTInfoMsgRaw, err) + +} +func TestTransfer(t *testing.T) { + app, ctx, instantiateRes, accs, msgServer, err := MintTwoNFTs(t) + transferMsgRaw := []byte(fmt.Sprintf(escrow721TransferNFTTemplate, + "omni/stars/transfer-nft", + "1", + accs[1].Address.String(), + )) + ExecuteTransferNFT(t, ctx, app, msgServer, accs, instantiateRes, transferMsgRaw, err) + RunGetOwner(t, ctx, app, msgServer, accs, instantiateRes, transferMsgRaw, accs[1].Address) } diff --git a/e2e/query.go b/e2e/query.go index ee23629c..1e919c74 100644 --- a/e2e/query.go +++ b/e2e/query.go @@ -33,3 +33,27 @@ func RunQueryEmpty(t *testing.T, ctx sdk.Context, app *app.App, require.Equal(t, string(result), expected_result) require.EqualError(t, err, "cw721_base_ibc::state::TokenInfo not found: query wasm contract failed") } + +func RunGetOwner(t *testing.T, ctx sdk.Context, app *app.App, msgServer wasmtypes.MsgServer, accs []Account, + instantiateRes *wasmtypes.MsgInstantiateContractResponse, getOwnerMsgRaw []byte, owner sdk.Address) { + escrow721Address := instantiateRes.Address + + addr, _ := sdk.AccAddressFromBech32(escrow721Address) + result, _ := app.WasmKeeper.QuerySmart( + ctx, addr, getOwnerMsgRaw) + + expected_result := string(fmt.Sprintf(`{"owner":"%s","approvals":[]}`, owner.String())) + require.Equal(t, string(result), expected_result) +} + +func RunGetNFTInfo(t *testing.T, ctx sdk.Context, app *app.App, msgServer wasmtypes.MsgServer, accs []Account, + instantiateRes *wasmtypes.MsgInstantiateContractResponse, getNFTInfoMsgRaw []byte, err error) { + escrow721Address := instantiateRes.Address + + addr, _ := sdk.AccAddressFromBech32(escrow721Address) + result, _ := app.WasmKeeper.QuerySmart( + ctx, addr, getNFTInfoMsgRaw) + + expected_result := string(`{"token_uri":"ipfs://abc123","extension":{}}`) + require.Equal(t, string(result), expected_result) +} diff --git a/e2e/template.go b/e2e/template.go index 004bb716..7c7a4d15 100644 --- a/e2e/template.go +++ b/e2e/template.go @@ -43,4 +43,13 @@ var ( "token_id": "%s"} } ` + + escrow721TransferNFTTemplate = ` + { + "transfer_nft": { + "class_id": "%s", + "token_id": "%s", + "recipient": "%s"} + } + ` ) From c3568f0b4ab07a70d7f422b3c1353f1abd2e7160 Mon Sep 17 00:00:00 2001 From: Humanalgorithm Date: Thu, 2 Jun 2022 19:37:40 -0400 Subject: [PATCH 16/33] remove unnecesary code --- e2e/full_test.go | 12 ++++++------ e2e/query.go | 13 ------------- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/e2e/full_test.go b/e2e/full_test.go index 6bb078f3..c1f9aeb8 100644 --- a/e2e/full_test.go +++ b/e2e/full_test.go @@ -163,11 +163,6 @@ func TestBurn(t *testing.T) { ExecuteBurnError(t, ctx, msgServer, accs, instantiateRes, burnMsgRawFake, err) } -func TestQueryAfterMint(t *testing.T) { - app, ctx, instantiateRes, accs, _, _ := MintTwoNFTs(t) - RunQuerySuccess(t, ctx, app, instantiateRes, accs[0]) -} - func TestGetOwner(t *testing.T) { app, ctx, instantiateRes, accs, msgServer, _ := MintTwoNFTs(t) getOwnerMsgRaw := []byte(fmt.Sprintf(escrow721GetOwnerTemplate, @@ -196,5 +191,10 @@ func TestTransfer(t *testing.T) { accs[1].Address.String(), )) ExecuteTransferNFT(t, ctx, app, msgServer, accs, instantiateRes, transferMsgRaw, err) - RunGetOwner(t, ctx, app, msgServer, accs, instantiateRes, transferMsgRaw, accs[1].Address) + + getOwnerMsgRaw := []byte(fmt.Sprintf(escrow721GetOwnerTemplate, + "omni/stars/transfer-nft", + "1", + )) + RunGetOwner(t, ctx, app, msgServer, accs, instantiateRes, getOwnerMsgRaw, accs[1].Address) } diff --git a/e2e/query.go b/e2e/query.go index 1e919c74..e584b9a8 100644 --- a/e2e/query.go +++ b/e2e/query.go @@ -10,18 +10,6 @@ import ( "github.com/stretchr/testify/require" ) -func RunQuerySuccess(t *testing.T, ctx sdk.Context, app *app.App, - instantiateRes *wasmtypes.MsgInstantiateContractResponse, creator Account) { - escrow721Address := instantiateRes.Address - - addr, _ := sdk.AccAddressFromBech32(escrow721Address) - result, err := app.WasmKeeper.QuerySmart( - ctx, addr, []byte(`{"owner_of": {"token_id": "1", "class_id": "omni/stars/transfer-nft"}}`)) - expected_result := fmt.Sprintf("{\"owner\":\"%s\",\"approvals\":[]}", creator.Address.String()) - require.Equal(t, string(result), expected_result) - require.NoError(t, err) -} - func RunQueryEmpty(t *testing.T, ctx sdk.Context, app *app.App, instantiateRes *wasmtypes.MsgInstantiateContractResponse, creator Account) { escrow721Address := instantiateRes.Address @@ -41,7 +29,6 @@ func RunGetOwner(t *testing.T, ctx sdk.Context, app *app.App, msgServer wasmtype addr, _ := sdk.AccAddressFromBech32(escrow721Address) result, _ := app.WasmKeeper.QuerySmart( ctx, addr, getOwnerMsgRaw) - expected_result := string(fmt.Sprintf(`{"owner":"%s","approvals":[]}`, owner.String())) require.Equal(t, string(result), expected_result) } From 69458d8485a0b8f9e3e37e0203b16bf92990e80f Mon Sep 17 00:00:00 2001 From: Humanalgorithm Date: Thu, 2 Jun 2022 21:12:21 -0400 Subject: [PATCH 17/33] no error save class --- Cargo.lock | 36 +++++++++++++++++++++++++---- contracts/escrow721/Cargo.toml | 4 ++-- contracts/escrow721/src/contract.rs | 19 +++++++++++++-- contracts/escrow721/src/lib.rs | 1 + contracts/escrow721/src/msg.rs | 12 ---------- contracts/escrow721/src/state.rs | 3 +++ e2e/execute.go | 15 ++++++++++++ e2e/full_test.go | 15 ++++++++++++ e2e/template.go | 7 ++++++ 9 files changed, 91 insertions(+), 21 deletions(-) create mode 100644 contracts/escrow721/src/state.rs diff --git a/Cargo.lock b/Cargo.lock index 9c1092ed..0db6f0f0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -251,6 +251,21 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cw721-base-ibc" +version = "0.13.2" +source = "git+https://github.com/public-awesome/cw721-ibc.git?branch=main#eee3b4e2336a38687e629b1881f0cdcd6ad585b3" +dependencies = [ + "cosmwasm-std", + "cw-storage-plus", + "cw-utils", + "cw2", + "cw721-ibc 0.13.2 (git+https://github.com/public-awesome/cw721-ibc.git?branch=main)", + "schemars", + "serde", + "thiserror", +] + [[package]] name = "cw721-base-ibc" version = "0.13.2" @@ -260,12 +275,23 @@ dependencies = [ "cw-storage-plus", "cw-utils", "cw2", - "cw721-ibc", + "cw721-ibc 0.13.2 (git+https://github.com/public-awesome/cw721-ibc.git)", "schemars", "serde", "thiserror", ] +[[package]] +name = "cw721-ibc" +version = "0.13.2" +source = "git+https://github.com/public-awesome/cw721-ibc.git?branch=main#eee3b4e2336a38687e629b1881f0cdcd6ad585b3" +dependencies = [ + "cosmwasm-std", + "cw-utils", + "schemars", + "serde", +] + [[package]] name = "cw721-ibc" version = "0.13.2" @@ -355,8 +381,8 @@ dependencies = [ "cw-utils", "cw2", "cw20-ics20", - "cw721-base-ibc", - "cw721-ibc", + "cw721-base-ibc 0.13.2 (git+https://github.com/public-awesome/cw721-ibc.git?branch=main)", + "cw721-ibc 0.13.2 (git+https://github.com/public-awesome/cw721-ibc.git?branch=main)", "schemars", "serde", "sg721", @@ -459,8 +485,8 @@ dependencies = [ "cw-utils", "cw2", "cw20-ics20", - "cw721-base-ibc", - "cw721-ibc", + "cw721-base-ibc 0.13.2 (git+https://github.com/public-awesome/cw721-ibc.git)", + "cw721-ibc 0.13.2 (git+https://github.com/public-awesome/cw721-ibc.git)", "schemars", "serde", "thiserror", diff --git a/contracts/escrow721/Cargo.toml b/contracts/escrow721/Cargo.toml index 39a4f371..17e43892 100644 --- a/contracts/escrow721/Cargo.toml +++ b/contracts/escrow721/Cargo.toml @@ -37,8 +37,8 @@ cw-utils = "0.13.2" cw2 = "0.13.2" cw20-ics20 = { version = "0.13.2", features = ["library"] } sg721 = { version = "0.12.0", features = ["library"] } -cw721-base-ibc = { git = "https://github.com/public-awesome/cw721-ibc.git", version = "0.13.2", features = ["library"]} -cw721-ibc = { git = "https://github.com/public-awesome/cw721-ibc.git", version = "0.13.2"} +cw721-base-ibc = { git = "https://github.com/public-awesome/cw721-ibc.git", version = "0.13.2", branch="main", features = ["library"]} +cw721-ibc = { git = "https://github.com/public-awesome/cw721-ibc.git", branch="main", version = "0.13.2"} schemars = "0.8.8" serde = { version = "1.0.133", default-features = false, features = ["derive"] } thiserror = { version = "1.0.30" } diff --git a/contracts/escrow721/src/contract.rs b/contracts/escrow721/src/contract.rs index bfcbf180..2de234f4 100644 --- a/contracts/escrow721/src/contract.rs +++ b/contracts/escrow721/src/contract.rs @@ -3,11 +3,12 @@ use cosmwasm_std::Response; use cosmwasm_std::StdError; #[cfg(not(feature = "library"))] use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Empty, Env, MessageInfo, StdResult}; -use cw721_base_ibc::msg::{ExecuteMsg, InstantiateMsg, MintMsg, QueryMsg}; +use cw721_base_ibc::msg::{InstantiateMsg, MintMsg, QueryMsg, ExecuteMsg}; use cw721_base_ibc::{ContractError, Cw721Contract}; use cw721_ibc::{Cw721Execute, Cw721Query, NftInfoResponse, OwnerOfResponse}; pub type CW721ContractWrapper<'a> = Cw721Contract<'a, Empty, Empty>; +use crate::state::{CLASS_STORAGE}; #[cfg_attr(not(feature = "library"), entry_point)] pub fn instantiate( @@ -26,7 +27,21 @@ pub fn execute( info: MessageInfo, msg: ExecuteMsg, ) -> Result, ContractError> { - CW721ContractWrapper::default().execute(deps, env, info, msg) + println!("we are in execute~!"); + match msg { + ExecuteMsg::SaveClass { class_id, class_uri } => save_class(deps, class_id, class_uri), + _ => CW721ContractWrapper::default().execute(deps, env, info, msg) + } +} + +pub fn save_class( + deps: DepsMut, + class_id: String, + class_uri: String, +) -> Result, ContractError> { + + CLASS_STORAGE.save(deps.storage, class_id, &class_uri)?; + Ok(Response::default()) } pub fn transfer( diff --git a/contracts/escrow721/src/lib.rs b/contracts/escrow721/src/lib.rs index 112ecadc..4934c19d 100644 --- a/contracts/escrow721/src/lib.rs +++ b/contracts/escrow721/src/lib.rs @@ -1,2 +1,3 @@ pub mod contract; pub mod msg; +pub mod state; diff --git a/contracts/escrow721/src/msg.rs b/contracts/escrow721/src/msg.rs index 705f9c73..fc0311a6 100644 --- a/contracts/escrow721/src/msg.rs +++ b/contracts/escrow721/src/msg.rs @@ -1,16 +1,4 @@ use schemars::JsonSchema; use serde::{Deserialize, Serialize}; -// use crate::state::ChannelState; -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct InstantiateMsg { - // Default timeout for ics721 packets, specified in seconds - pub default_timeout: u64, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum QueryMsg { - GetOwner { token_id: String }, -} diff --git a/contracts/escrow721/src/state.rs b/contracts/escrow721/src/state.rs new file mode 100644 index 00000000..e5286647 --- /dev/null +++ b/contracts/escrow721/src/state.rs @@ -0,0 +1,3 @@ +use cw_storage_plus::Map; + +pub const CLASS_STORAGE: Map = Map::new("class_storage"); diff --git a/e2e/execute.go b/e2e/execute.go index ef2d5674..3fd6c4ad 100644 --- a/e2e/execute.go +++ b/e2e/execute.go @@ -96,3 +96,18 @@ func ExecuteTransferNFT(t *testing.T, ctx sdk.Context, app *app.App, msgServer w require.NotEmpty(t, instantiateRes.Address) require.NoError(t, transferErr) } + +func ExecuteSaveClass(t *testing.T, ctx sdk.Context, app *app.App, msgServer wasmtypes.MsgServer, accs []Account, + instantiateRes *wasmtypes.MsgInstantiateContractResponse, saveClassMsgRaw []byte, err error) { + escrow721Address := instantiateRes.Address + + _, transferErr := msgServer.ExecuteContract(sdk.WrapSDKContext(ctx), &wasmtypes.MsgExecuteContract{ + Contract: escrow721Address, + Sender: accs[0].Address.String(), + Msg: saveClassMsgRaw, + }) + require.NoError(t, err) + require.NotNil(t, instantiateRes) + require.NotEmpty(t, instantiateRes.Address) + require.NoError(t, transferErr) +} diff --git a/e2e/full_test.go b/e2e/full_test.go index c1f9aeb8..97b6581b 100644 --- a/e2e/full_test.go +++ b/e2e/full_test.go @@ -198,3 +198,18 @@ func TestTransfer(t *testing.T) { )) RunGetOwner(t, ctx, app, msgServer, accs, instantiateRes, getOwnerMsgRaw, accs[1].Address) } + +func TestSaveClass(t *testing.T) { + app, ctx, instantiateRes, accs, msgServer, err := MintTwoNFTs(t) + saveClassMsgRaw := []byte(fmt.Sprintf(escrow721SaveClassTemplate, + "omni/stars/transfer-nft", + "abc123_class_uri", + )) + ExecuteTransferNFT(t, ctx, app, msgServer, accs, instantiateRes, saveClassMsgRaw, err) + + // getOwnerMsgRaw := []byte(fmt.Sprintf(escrow721GetOwnerTemplate, + // "omni/stars/transfer-nft", + // "1", + // )) + // RunGetOwner(t, ctx, app, msgServer, accs, instantiateRes, getOwnerMsgRaw, accs[1].Address) +} diff --git a/e2e/template.go b/e2e/template.go index 7c7a4d15..3a752e6d 100644 --- a/e2e/template.go +++ b/e2e/template.go @@ -52,4 +52,11 @@ var ( "recipient": "%s"} } ` + escrow721SaveClassTemplate = ` + { + "save_class": { + "class_id": "%s", + "class_uri": "%s"} + } + ` ) From ceac2116c303890a20bb1b2ac9586cd0a28e911a Mon Sep 17 00:00:00 2001 From: Humanalgorithm Date: Thu, 2 Jun 2022 22:36:25 -0400 Subject: [PATCH 18/33] working has class --- Cargo.lock | 221 +++++++++++++++++----------- contracts/escrow721/src/contract.rs | 5 + contracts/escrow721/src/msg.rs | 4 - e2e/full_test.go | 35 ++++- e2e/query.go | 11 ++ e2e/template.go | 7 + 6 files changed, 181 insertions(+), 102 deletions(-) delete mode 100644 contracts/escrow721/src/msg.rs diff --git a/Cargo.lock b/Cargo.lock index 0db6f0f0..5fd79822 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,12 +2,24 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "base16ct" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349a06037c7bf932dd7e7d1f653678b2038b9ad46a74102f1fc7bd7872678cce" + [[package]] name = "base64" version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" +[[package]] +name = "base64ct" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dea908e7347a8c64e378c17e30ef880ad73e3b4498346b055c2c00ea342f3179" + [[package]] name = "block-buffer" version = "0.9.0" @@ -31,15 +43,15 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "const-oid" -version = "0.6.2" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d6f2aa4d0537bcc1c74df8755072bd31c1ef1a3a1b85a68e8404a8c353b7b8b" +checksum = "e4c78c047431fee22c1a7bb92e00ad095a02a983affe4d8a72e2a2c62c1b94f3" [[package]] name = "cosmwasm-crypto" -version = "1.0.0-beta8" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37e70111e9701c3ec43bfbff0e523cd4cb115876b4d3433813436dd0934ee962" +checksum = "5eb0afef2325df81aadbf9be1233f522ed8f6e91df870c764bc44cca2b1415bd" dependencies = [ "digest", "ed25519-zebra", @@ -50,18 +62,18 @@ dependencies = [ [[package]] name = "cosmwasm-derive" -version = "1.0.0-beta8" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58bc2ad5d86be5f6068833f63e20786768db6890019c095dd7775232184fb7b3" +checksum = "4b36e527620a2a3e00e46b6e731ab6c9b68d11069c986f7d7be8eba79ef081a4" dependencies = [ "syn", ] [[package]] name = "cosmwasm-schema" -version = "1.0.0-beta8" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d75f6a05667d8613b24171ef2c77a8bf6fb9c14f9e3aaa39aa10e0c6416ed67" +checksum = "772e80bbad231a47a2068812b723a1ff81dd4a0d56c9391ac748177bea3a61da" dependencies = [ "schemars", "serde_json", @@ -69,9 +81,9 @@ dependencies = [ [[package]] name = "cosmwasm-std" -version = "1.0.0-beta8" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "915ca82bd944f116f3a9717481f3fa657e4a73f28c4887288761ebb24e6fbe10" +checksum = "875994993c2082a6fcd406937bf0fca21c349e4a624f3810253a14fa83a3a195" dependencies = [ "base64", "cosmwasm-crypto", @@ -86,9 +98,9 @@ dependencies = [ [[package]] name = "cosmwasm-storage" -version = "1.0.0-beta8" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c4be9fd8c9d3ae7d0c32a925ecbc20707007ce0cba1f7538c0d78b7a2d3729b" +checksum = "d18403b07304d15d304dad11040d45bbcaf78d603b4be3fb5e2685c16f9229b5" dependencies = [ "cosmwasm-std", "serde", @@ -111,9 +123,9 @@ checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" [[package]] name = "crypto-bigint" -version = "0.2.11" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f83bd3bb4314701c568e340cd8cf78c975aa0ca79e03d3f6d1677d5b0c9c0c03" +checksum = "03c6a1d5fa1de37e071642dfa44ec552ca5b299adb128fab16138e24b548fd21" dependencies = [ "generic-array", "rand_core 0.6.3", @@ -146,9 +158,9 @@ dependencies = [ [[package]] name = "cw-controllers" -version = "0.13.2" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc6d042b14823b0e9f33f5cdd67a1eb9b16a7d79f7547b1a73c8870b518b97b" +checksum = "4f0bc6019b4d3d81e11f5c384bcce7173e2210bd654d75c6c9668e12cca05dfa" dependencies = [ "cosmwasm-std", "cw-storage-plus", @@ -160,9 +172,9 @@ dependencies = [ [[package]] name = "cw-storage-plus" -version = "0.13.2" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9336ecef1e19d56cf6e3e932475fc6a3dee35eec5a386e07917a1d1ba6bb0e35" +checksum = "648b1507290bbc03a8d88463d7cd9b04b1fa0155e5eef366c4fa052b9caaac7a" dependencies = [ "cosmwasm-std", "schemars", @@ -171,9 +183,9 @@ dependencies = [ [[package]] name = "cw-utils" -version = "0.13.2" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "babd2c090f39d07ce5bf2556962305e795daa048ce20a93709eb591476e4a29e" +checksum = "9dbaecb78c8e8abfd6b4258c7f4fbeb5c49a5e45ee4d910d3240ee8e1d714e1b" dependencies = [ "cosmwasm-std", "schemars", @@ -183,9 +195,9 @@ dependencies = [ [[package]] name = "cw2" -version = "0.13.2" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "993df11574f29574dd443eb0c189484bb91bc0638b6de3e32ab7f9319c92122d" +checksum = "04cf4639517490dd36b333bbd6c4fbd92e325fd0acf4683b41753bc5eb63bfc1" dependencies = [ "cosmwasm-std", "cw-storage-plus", @@ -195,9 +207,9 @@ dependencies = [ [[package]] name = "cw20" -version = "0.13.2" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "356d364602c5fe763544ea00d485b825d6ef519a2fc6a3145528d7df3a603f40" +checksum = "4cb782b8f110819a4eb5dbbcfed25ffba49ec16bbe32b4ad8da50a5ce68fec05" dependencies = [ "cosmwasm-std", "cw-utils", @@ -207,9 +219,9 @@ dependencies = [ [[package]] name = "cw20-ics20" -version = "0.13.2" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2700b19cec661cbe243f62be9f35493f84929013b28f5819433aad2daf21cd9c" +checksum = "a8cd854000f897836dc941da0cb691643678c690f485823477c62b8597d08ea1" dependencies = [ "cosmwasm-std", "cw-controllers", @@ -254,7 +266,7 @@ dependencies = [ [[package]] name = "cw721-base-ibc" version = "0.13.2" -source = "git+https://github.com/public-awesome/cw721-ibc.git?branch=main#eee3b4e2336a38687e629b1881f0cdcd6ad585b3" +source = "git+https://github.com/public-awesome/cw721-ibc.git?branch=main#87dc9af8b5edc2eac0ecf40164c7e379b68ec19a" dependencies = [ "cosmwasm-std", "cw-storage-plus", @@ -269,7 +281,7 @@ dependencies = [ [[package]] name = "cw721-base-ibc" version = "0.13.2" -source = "git+https://github.com/public-awesome/cw721-ibc.git#ac79307b4e70f24536ea986953cc54c504bf6f61" +source = "git+https://github.com/public-awesome/cw721-ibc.git#87dc9af8b5edc2eac0ecf40164c7e379b68ec19a" dependencies = [ "cosmwasm-std", "cw-storage-plus", @@ -284,7 +296,7 @@ dependencies = [ [[package]] name = "cw721-ibc" version = "0.13.2" -source = "git+https://github.com/public-awesome/cw721-ibc.git?branch=main#eee3b4e2336a38687e629b1881f0cdcd6ad585b3" +source = "git+https://github.com/public-awesome/cw721-ibc.git?branch=main#87dc9af8b5edc2eac0ecf40164c7e379b68ec19a" dependencies = [ "cosmwasm-std", "cw-utils", @@ -295,7 +307,7 @@ dependencies = [ [[package]] name = "cw721-ibc" version = "0.13.2" -source = "git+https://github.com/public-awesome/cw721-ibc.git#ac79307b4e70f24536ea986953cc54c504bf6f61" +source = "git+https://github.com/public-awesome/cw721-ibc.git#87dc9af8b5edc2eac0ecf40164c7e379b68ec19a" dependencies = [ "cosmwasm-std", "cw-utils", @@ -305,9 +317,9 @@ dependencies = [ [[package]] name = "der" -version = "0.4.5" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79b71cca7d95d7681a4b3b9cdf63c8dbc3730d0584c2c74e31416d64a90493f4" +checksum = "6919815d73839e7ad218de758883aae3a257ba6759ce7a9992501efbb53d705c" dependencies = [ "const-oid", ] @@ -329,13 +341,13 @@ checksum = "21e50f3adc76d6a43f5ed73b698a87d0760ca74617f60f7c3b879003536fdd28" [[package]] name = "ecdsa" -version = "0.12.4" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43ee23aa5b4f68c7a092b5c3beb25f50c406adc75e2363634f242f28ab255372" +checksum = "d0d69ae62e0ce582d56380743515fefaf1a8c70cec685d9677636d7e30ae9dc9" dependencies = [ "der", "elliptic-curve", - "hmac", + "rfc6979", "signature", ] @@ -356,16 +368,18 @@ dependencies = [ [[package]] name = "elliptic-curve" -version = "0.10.6" +version = "0.11.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "beca177dcb8eb540133e7680baff45e7cc4d93bf22002676cec549f82343721b" +checksum = "25b477563c2bfed38a3b7a60964c49e058b2510ad3f12ba3483fd8f62c2306d6" dependencies = [ + "base16ct", "crypto-bigint", + "der", "ff", "generic-array", "group", - "pkcs8", "rand_core 0.6.3", + "sec1", "subtle", "zeroize", ] @@ -391,9 +405,9 @@ dependencies = [ [[package]] name = "ff" -version = "0.10.1" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0f40b2dcd8bc322217a5f6559ae5f9e9d1de202a2ecee2e9eafcbece7562a4f" +checksum = "131655483be284720a17d74ff97592b8e76576dc25563148601df2d7c9080924" dependencies = [ "rand_core 0.6.3", "subtle", @@ -449,9 +463,9 @@ dependencies = [ [[package]] name = "group" -version = "0.10.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c363a5301b8f153d80747126a04b3c82073b9fe3130571a9d170cacdeaf7912" +checksum = "bc5ac374b108929de78460075f3dc439fa66df9d8fc77e8f12caa5165fcf0c89" dependencies = [ "ff", "rand_core 0.6.3", @@ -505,27 +519,28 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" +checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" [[package]] name = "k256" -version = "0.9.6" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "903ae2481bcdfdb7b68e0a9baa4b7c9aff600b9ae2e8e5bb5833b8c91ab851ea" +checksum = "19c3a5e0a0b8450278feda242592512e09f61c72e018b8cd5c859482802daf2d" dependencies = [ "cfg-if", "ecdsa", "elliptic-curve", + "sec1", "sha2", ] [[package]] name = "libc" -version = "0.2.124" +version = "0.2.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21a41fed9d98f27ab1c6d161da622a4fa35e8a54a8adc24bbf3ddd0ef70b0e50" +checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" [[package]] name = "matches" @@ -547,21 +562,22 @@ checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" [[package]] name = "pkcs8" -version = "0.7.6" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee3ef9b64d26bad0536099c816c6734379e45bbd5f14798def6809e5cc350447" +checksum = "7cabda3fb821068a9a4fab19a683eac3af12edf0f34b94a8be53c4972b8149d0" dependencies = [ "der", "spki", + "zeroize", ] [[package]] name = "proc-macro2" -version = "1.0.37" +version = "1.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec757218438d5fda206afc041538b2f6d889286160d649a86a24d37e1235afd1" +checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] @@ -591,17 +607,28 @@ dependencies = [ "getrandom 0.2.6", ] +[[package]] +name = "rfc6979" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96ef608575f6392792f9ecf7890c00086591d29a83910939d430753f7c050525" +dependencies = [ + "crypto-bigint", + "hmac", + "zeroize", +] + [[package]] name = "ryu" -version = "1.0.9" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f" +checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695" [[package]] name = "schemars" -version = "0.8.8" +version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6b5a3c80cea1ab61f4260238409510e814e38b4b563c06044edf91e7dc070e3" +checksum = "1847b767a3d62d95cbf3d8a9f0e421cf57a0d8aa4f411d4b16525afb0284d4ed" dependencies = [ "dyn-clone", "schemars_derive", @@ -611,9 +638,9 @@ dependencies = [ [[package]] name = "schemars_derive" -version = "0.8.8" +version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41ae4dce13e8614c46ac3c38ef1c0d668b101df6ac39817aebdaa26642ddae9b" +checksum = "af4d7e1b012cb3d9129567661a63755ea4b8a7386d339dc945ae187e403c6743" dependencies = [ "proc-macro2", "quote", @@ -621,35 +648,48 @@ dependencies = [ "syn", ] +[[package]] +name = "sec1" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08da66b8b0965a5555b6bd6639e68ccba85e1e2506f5fbb089e93f8a04e1a2d1" +dependencies = [ + "der", + "generic-array", + "pkcs8", + "subtle", + "zeroize", +] + [[package]] name = "semver" -version = "1.0.7" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d65bd28f48be7196d222d95b9243287f48d27aca604e08497513019ff0502cc4" +checksum = "8cb243bdfdb5936c8dc3c45762a19d12ab4550cdc753bc247637d4ec35a040fd" [[package]] name = "serde" -version = "1.0.136" +version = "1.0.137" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789" +checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1" dependencies = [ "serde_derive", ] [[package]] name = "serde-json-wasm" -version = "0.3.2" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "042ac496d97e5885149d34139bad1d617192770d7eb8f1866da2317ff4501853" +checksum = "479b4dbc401ca13ee8ce902851b834893251404c4f3c65370a49e047a6be09a5" dependencies = [ "serde", ] [[package]] name = "serde_derive" -version = "1.0.136" +version = "1.0.137" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9" +checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be" dependencies = [ "proc-macro2", "quote", @@ -658,9 +698,9 @@ dependencies = [ [[package]] name = "serde_derive_internals" -version = "0.25.0" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dbab34ca63057a1f15280bdf3c39f2b1eb1b54c17e98360e511637aef7418c6" +checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c" dependencies = [ "proc-macro2", "quote", @@ -669,9 +709,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.79" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e8d9fa5c3b304765ce1fd9c4c8a3de2c8db365a5b91be52f186efc675681d95" +checksum = "9b7ce2b32a1aed03c558dc61a5cd328f15aff2dbc17daad8fb8af04d2100e15c" dependencies = [ "itoa", "ryu", @@ -742,9 +782,9 @@ dependencies = [ [[package]] name = "signature" -version = "1.3.2" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2807892cfa58e081aa1f1111391c7a0649d4fa127a4ffbe34bcbfb35a1171a4" +checksum = "02658e48d89f2bec991f9a78e69cfa4c316f8d6a6c4ec12fae1aeb263d486788" dependencies = [ "digest", "rand_core 0.6.3", @@ -752,10 +792,11 @@ dependencies = [ [[package]] name = "spki" -version = "0.4.1" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c01a0c15da1b0b0e1494112e7af814a678fec9bd157881b49beac661e9b6f32" +checksum = "44d01ac02a6ccf3e07db148d2be087da624fea0221a16152ed01f0496a6b0a27" dependencies = [ + "base64ct", "der", ] @@ -773,29 +814,29 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" -version = "1.0.91" +version = "1.0.96" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b683b2b825c8eef438b77c36a06dc262294da3d5a5813fac20da149241dcd44d" +checksum = "0748dd251e24453cb8717f0354206b91557e4ec8703673a4b30208f2abaf1ebf" dependencies = [ "proc-macro2", "quote", - "unicode-xid", + "unicode-ident", ] [[package]] name = "thiserror" -version = "1.0.30" +version = "1.0.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417" +checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.30" +version = "1.0.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b" +checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a" dependencies = [ "proc-macro2", "quote", @@ -841,6 +882,12 @@ version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" +[[package]] +name = "unicode-ident" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee" + [[package]] name = "unicode-normalization" version = "0.1.19" @@ -850,12 +897,6 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-xid" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" - [[package]] name = "url" version = "2.2.2" @@ -888,6 +929,6 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "zeroize" -version = "1.4.3" +version = "1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d68d9dcec5f9b43a30d38c49f91dfedfaac384cb8f085faca366c26207dd1619" +checksum = "94693807d016b2f2d2e14420eb3bfcca689311ff775dcf113d74ea624b7cdf07" diff --git a/contracts/escrow721/src/contract.rs b/contracts/escrow721/src/contract.rs index 2de234f4..11123b7d 100644 --- a/contracts/escrow721/src/contract.rs +++ b/contracts/escrow721/src/contract.rs @@ -99,6 +99,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { include_expired.unwrap_or(false), )?), QueryMsg::NftInfo { class_id, token_id } => to_binary(&nft_info(deps, class_id, token_id)?), + QueryMsg::HasClass { class_id } => to_binary(&has_class(deps, class_id)), _ => Err(StdError::GenericErr { msg: "Unsupported message type".to_string(), }), @@ -118,3 +119,7 @@ pub fn get_owner( fn nft_info(deps: Deps, class_id: String, token_id: String) -> StdResult> { CW721ContractWrapper::default().nft_info(deps, class_id, token_id) } + +fn has_class(deps: Deps, class_id: String) -> bool { + CLASS_STORAGE.has(deps.storage, class_id) +} \ No newline at end of file diff --git a/contracts/escrow721/src/msg.rs b/contracts/escrow721/src/msg.rs deleted file mode 100644 index fc0311a6..00000000 --- a/contracts/escrow721/src/msg.rs +++ /dev/null @@ -1,4 +0,0 @@ -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; - - diff --git a/e2e/full_test.go b/e2e/full_test.go index 97b6581b..a810d0c5 100644 --- a/e2e/full_test.go +++ b/e2e/full_test.go @@ -134,6 +134,15 @@ func MintTwoNFTs(t *testing.T) ( return app, ctx, instantiateRes, accs, msgServer, err } +func SaveClass(t *testing.T, ctx sdk.Context, app *app.App, msgServer wasmtypes.MsgServer, accs []Account, + instantiateRes *wasmtypes.MsgInstantiateContractResponse, err error) { + saveClassMsgRaw := []byte(fmt.Sprintf(escrow721SaveClassTemplate, + "omni/stars/transfer-nft", + "abc123_class_uri", + )) + ExecuteSaveClass(t, ctx, app, msgServer, accs, instantiateRes, saveClassMsgRaw, err) +} + func TestLoadChain(t *testing.T) { LoadChain(t) } @@ -201,15 +210,25 @@ func TestTransfer(t *testing.T) { func TestSaveClass(t *testing.T) { app, ctx, instantiateRes, accs, msgServer, err := MintTwoNFTs(t) - saveClassMsgRaw := []byte(fmt.Sprintf(escrow721SaveClassTemplate, + SaveClass(t, ctx, app, msgServer, accs, instantiateRes, err) +} + +func TestHasClassTrue(t *testing.T) { + app, ctx, instantiateRes, accs, msgServer, err := MintTwoNFTs(t) + SaveClass(t, ctx, app, msgServer, accs, instantiateRes, err) + + hasClassMsgRaw := []byte(fmt.Sprintf(escrow721HasClassTemplate, "omni/stars/transfer-nft", - "abc123_class_uri", )) - ExecuteTransferNFT(t, ctx, app, msgServer, accs, instantiateRes, saveClassMsgRaw, err) + RunHasClass(t, ctx, app, msgServer, accs, instantiateRes, hasClassMsgRaw, "true") +} + +func TestHasClassFalse(t *testing.T) { + app, ctx, instantiateRes, accs, msgServer, err := MintTwoNFTs(t) + SaveClass(t, ctx, app, msgServer, accs, instantiateRes, err) - // getOwnerMsgRaw := []byte(fmt.Sprintf(escrow721GetOwnerTemplate, - // "omni/stars/transfer-nft", - // "1", - // )) - // RunGetOwner(t, ctx, app, msgServer, accs, instantiateRes, getOwnerMsgRaw, accs[1].Address) + hasClassMsgRaw := []byte(fmt.Sprintf(escrow721HasClassTemplate, + "omni/fake-channel/transfer-nft", + )) + RunHasClass(t, ctx, app, msgServer, accs, instantiateRes, hasClassMsgRaw, "false") } diff --git a/e2e/query.go b/e2e/query.go index e584b9a8..690c12bf 100644 --- a/e2e/query.go +++ b/e2e/query.go @@ -44,3 +44,14 @@ func RunGetNFTInfo(t *testing.T, ctx sdk.Context, app *app.App, msgServer wasmty expected_result := string(`{"token_uri":"ipfs://abc123","extension":{}}`) require.Equal(t, string(result), expected_result) } + +func RunHasClass(t *testing.T, ctx sdk.Context, app *app.App, msgServer wasmtypes.MsgServer, accs []Account, + instantiateRes *wasmtypes.MsgInstantiateContractResponse, hasClassMsgRaw []byte, expected string) { + escrow721Address := instantiateRes.Address + + addr, _ := sdk.AccAddressFromBech32(escrow721Address) + result, _ := app.WasmKeeper.QuerySmart( + ctx, addr, hasClassMsgRaw) + + require.Equal(t, string(expected), string(result)) +} diff --git a/e2e/template.go b/e2e/template.go index 3a752e6d..6b809228 100644 --- a/e2e/template.go +++ b/e2e/template.go @@ -59,4 +59,11 @@ var ( "class_uri": "%s"} } ` + + escrow721HasClassTemplate = ` + { + "has_class": { + "class_id": "%s"} + } + ` ) From f2c06f21181c7f2c0c8cc3620eca82955870dbd3 Mon Sep 17 00:00:00 2001 From: Humanalgorithm Date: Thu, 2 Jun 2022 22:37:28 -0400 Subject: [PATCH 19/33] fix lint --- contracts/escrow721/src/contract.rs | 20 +++++++++++--------- contracts/escrow721/src/lib.rs | 1 - 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/contracts/escrow721/src/contract.rs b/contracts/escrow721/src/contract.rs index 11123b7d..1272ea5a 100644 --- a/contracts/escrow721/src/contract.rs +++ b/contracts/escrow721/src/contract.rs @@ -3,12 +3,12 @@ use cosmwasm_std::Response; use cosmwasm_std::StdError; #[cfg(not(feature = "library"))] use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Empty, Env, MessageInfo, StdResult}; -use cw721_base_ibc::msg::{InstantiateMsg, MintMsg, QueryMsg, ExecuteMsg}; +use cw721_base_ibc::msg::{ExecuteMsg, InstantiateMsg, MintMsg, QueryMsg}; use cw721_base_ibc::{ContractError, Cw721Contract}; use cw721_ibc::{Cw721Execute, Cw721Query, NftInfoResponse, OwnerOfResponse}; pub type CW721ContractWrapper<'a> = Cw721Contract<'a, Empty, Empty>; -use crate::state::{CLASS_STORAGE}; +use crate::state::CLASS_STORAGE; #[cfg_attr(not(feature = "library"), entry_point)] pub fn instantiate( @@ -29,17 +29,19 @@ pub fn execute( ) -> Result, ContractError> { println!("we are in execute~!"); match msg { - ExecuteMsg::SaveClass { class_id, class_uri } => save_class(deps, class_id, class_uri), - _ => CW721ContractWrapper::default().execute(deps, env, info, msg) + ExecuteMsg::SaveClass { + class_id, + class_uri, + } => save_class(deps, class_id, class_uri), + _ => CW721ContractWrapper::default().execute(deps, env, info, msg), } } pub fn save_class( deps: DepsMut, - class_id: String, - class_uri: String, + class_id: String, + class_uri: String, ) -> Result, ContractError> { - CLASS_STORAGE.save(deps.storage, class_id, &class_uri)?; Ok(Response::default()) } @@ -99,7 +101,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { include_expired.unwrap_or(false), )?), QueryMsg::NftInfo { class_id, token_id } => to_binary(&nft_info(deps, class_id, token_id)?), - QueryMsg::HasClass { class_id } => to_binary(&has_class(deps, class_id)), + QueryMsg::HasClass { class_id } => to_binary(&has_class(deps, class_id)), _ => Err(StdError::GenericErr { msg: "Unsupported message type".to_string(), }), @@ -122,4 +124,4 @@ fn nft_info(deps: Deps, class_id: String, token_id: String) -> StdResult bool { CLASS_STORAGE.has(deps.storage, class_id) -} \ No newline at end of file +} diff --git a/contracts/escrow721/src/lib.rs b/contracts/escrow721/src/lib.rs index 4934c19d..3407c199 100644 --- a/contracts/escrow721/src/lib.rs +++ b/contracts/escrow721/src/lib.rs @@ -1,3 +1,2 @@ pub mod contract; -pub mod msg; pub mod state; From 766fd885421aaa99ef1ca207b00173f5430e2aa1 Mon Sep 17 00:00:00 2001 From: Humanalgorithm Date: Fri, 3 Jun 2022 10:54:23 -0400 Subject: [PATCH 20/33] working GetClass implementation --- contracts/escrow721/src/contract.rs | 13 ++++++++++++- e2e/full_test.go | 22 ++++++++++++++++++++++ e2e/query.go | 22 ++++++++++++++++++++++ e2e/template.go | 6 ++++++ 4 files changed, 62 insertions(+), 1 deletion(-) diff --git a/contracts/escrow721/src/contract.rs b/contracts/escrow721/src/contract.rs index 1272ea5a..95baa44a 100644 --- a/contracts/escrow721/src/contract.rs +++ b/contracts/escrow721/src/contract.rs @@ -27,7 +27,6 @@ pub fn execute( info: MessageInfo, msg: ExecuteMsg, ) -> Result, ContractError> { - println!("we are in execute~!"); match msg { ExecuteMsg::SaveClass { class_id, @@ -73,6 +72,7 @@ pub fn mint( token_uri: Some(token_uri), extension: Empty {}, }; + CW721ContractWrapper::default().mint(deps, _env, info, mint_msg) } @@ -102,6 +102,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { )?), QueryMsg::NftInfo { class_id, token_id } => to_binary(&nft_info(deps, class_id, token_id)?), QueryMsg::HasClass { class_id } => to_binary(&has_class(deps, class_id)), + QueryMsg::GetClass { class_id } => to_binary(&get_class(deps, class_id)?), _ => Err(StdError::GenericErr { msg: "Unsupported message type".to_string(), }), @@ -125,3 +126,13 @@ fn nft_info(deps: Deps, class_id: String, token_id: String) -> StdResult bool { CLASS_STORAGE.has(deps.storage, class_id) } + +fn get_class(deps: Deps, class_id: String) -> StdResult<(String, String)> { + match CLASS_STORAGE.load(deps.storage, class_id.clone()) { + Ok(class_uri) => Ok((class_id, class_uri)), + Err(_) => Err(StdError::generic_err(format!( + "Class {} not found", + class_id + ))), + } +} diff --git a/e2e/full_test.go b/e2e/full_test.go index a810d0c5..44d71553 100644 --- a/e2e/full_test.go +++ b/e2e/full_test.go @@ -232,3 +232,25 @@ func TestHasClassFalse(t *testing.T) { )) RunHasClass(t, ctx, app, msgServer, accs, instantiateRes, hasClassMsgRaw, "false") } + +func TestGetClassSuccess(t *testing.T) { + app, ctx, instantiateRes, accs, msgServer, err := MintTwoNFTs(t) + SaveClass(t, ctx, app, msgServer, accs, instantiateRes, err) + + getClassMsgRaw := []byte(fmt.Sprintf(escrow721GetClassTemplate, + "omni/stars/transfer-nft", + )) + expected := `["omni/stars/transfer-nft","abc123_class_uri"]` + RunGetClass(t, ctx, app, msgServer, accs, instantiateRes, getClassMsgRaw, expected) +} + +func TestGetClassFail(t *testing.T) { + app, ctx, instantiateRes, accs, msgServer, err := MintTwoNFTs(t) + SaveClass(t, ctx, app, msgServer, accs, instantiateRes, err) + + getClassMsgRaw := []byte(fmt.Sprintf(escrow721GetClassTemplate, + "omni/some_fake_class/transfer-nft", + )) + expected := `Generic error: Class omni/some_fake_class/transfer-nft not found: query wasm contract failed` + RunGetClassError(t, ctx, app, msgServer, accs, instantiateRes, getClassMsgRaw, expected) +} diff --git a/e2e/query.go b/e2e/query.go index 690c12bf..80055afb 100644 --- a/e2e/query.go +++ b/e2e/query.go @@ -55,3 +55,25 @@ func RunHasClass(t *testing.T, ctx sdk.Context, app *app.App, msgServer wasmtype require.Equal(t, string(expected), string(result)) } + +func RunGetClass(t *testing.T, ctx sdk.Context, app *app.App, msgServer wasmtypes.MsgServer, accs []Account, + instantiateRes *wasmtypes.MsgInstantiateContractResponse, getClassMsgRaw []byte, expected string) { + escrow721Address := instantiateRes.Address + + addr, _ := sdk.AccAddressFromBech32(escrow721Address) + result, _ := app.WasmKeeper.QuerySmart( + ctx, addr, getClassMsgRaw) + + require.Equal(t, string(expected), string(result)) +} + +func RunGetClassError(t *testing.T, ctx sdk.Context, app *app.App, msgServer wasmtypes.MsgServer, accs []Account, + instantiateRes *wasmtypes.MsgInstantiateContractResponse, getClassMsgRaw []byte, expected string) { + escrow721Address := instantiateRes.Address + + addr, _ := sdk.AccAddressFromBech32(escrow721Address) + _, err := app.WasmKeeper.QuerySmart( + ctx, addr, getClassMsgRaw) + + require.EqualError(t, err, expected) +} diff --git a/e2e/template.go b/e2e/template.go index 6b809228..0a5341af 100644 --- a/e2e/template.go +++ b/e2e/template.go @@ -66,4 +66,10 @@ var ( "class_id": "%s"} } ` + escrow721GetClassTemplate = ` + { + "get_class": { + "class_id": "%s"} + } + ` ) From 50b8d1198a8e1c09d875bbbe32a142e3d77e2af9 Mon Sep 17 00:00:00 2001 From: Humanalgorithm Date: Fri, 3 Jun 2022 11:39:54 -0400 Subject: [PATCH 21/33] regen schema, refactor test --- e2e/full_test.go | 14 +++++++++----- e2e/query.go | 15 ++++++--------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/e2e/full_test.go b/e2e/full_test.go index 44d71553..94407882 100644 --- a/e2e/full_test.go +++ b/e2e/full_test.go @@ -160,7 +160,8 @@ func TestBurn(t *testing.T) { ), ) ExecuteBurn(t, ctx, msgServer, accs, instantiateRes, burnMsgRaw, err) - RunQueryEmpty(t, ctx, app, instantiateRes, accs[0]) + query_msg := []byte(`{"owner_of": {"token_id": "1", "class_id": "omni/stars/transfer-nft"}}`) + RunQueryEmpty(t, ctx, app, instantiateRes, accs[0], query_msg) ExecuteBurnError(t, ctx, msgServer, accs, instantiateRes, burnMsgRaw, err) burnMsgRawFake := []byte( @@ -178,17 +179,19 @@ func TestGetOwner(t *testing.T) { "omni/stars/transfer-nft", "1", )) - RunGetOwner(t, ctx, app, msgServer, accs, instantiateRes, getOwnerMsgRaw, accs[0].Address) + expected_response := string(fmt.Sprintf(`{"owner":"%s","approvals":[]}`, accs[0].Address.String())) + RunGetOwner(t, ctx, app, msgServer, accs, instantiateRes, getOwnerMsgRaw, expected_response) } func TestGetNFTInfo(t *testing.T) { - app, ctx, instantiateRes, accs, msgServer, err := MintTwoNFTs(t) + app, ctx, instantiateRes, accs, msgServer, _ := MintTwoNFTs(t) getNFTInfoMsgRaw := []byte(fmt.Sprintf(escrow721GetNFTInfoTemplate, "omni/stars/transfer-nft", "1", )) - RunGetNFTInfo(t, ctx, app, msgServer, accs, instantiateRes, getNFTInfoMsgRaw, err) + expected_result := string(`{"token_uri":"ipfs://abc123","extension":{}}`) + RunGetNFTInfo(t, ctx, app, msgServer, accs, instantiateRes, getNFTInfoMsgRaw, expected_result) } @@ -205,7 +208,8 @@ func TestTransfer(t *testing.T) { "omni/stars/transfer-nft", "1", )) - RunGetOwner(t, ctx, app, msgServer, accs, instantiateRes, getOwnerMsgRaw, accs[1].Address) + expected_response := string(fmt.Sprintf(`{"owner":"%s","approvals":[]}`, accs[1].Address.String())) + RunGetOwner(t, ctx, app, msgServer, accs, instantiateRes, getOwnerMsgRaw, expected_response) } func TestSaveClass(t *testing.T) { diff --git a/e2e/query.go b/e2e/query.go index 80055afb..7316ccc6 100644 --- a/e2e/query.go +++ b/e2e/query.go @@ -1,7 +1,6 @@ package e2e_test import ( - "fmt" "testing" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" @@ -11,38 +10,36 @@ import ( ) func RunQueryEmpty(t *testing.T, ctx sdk.Context, app *app.App, - instantiateRes *wasmtypes.MsgInstantiateContractResponse, creator Account) { + instantiateRes *wasmtypes.MsgInstantiateContractResponse, creator Account, queryMsgRaw []byte) { escrow721Address := instantiateRes.Address addr, _ := sdk.AccAddressFromBech32(escrow721Address) result, err := app.WasmKeeper.QuerySmart( - ctx, addr, []byte(`{"owner_of": {"token_id": "1", "class_id": "omni/stars/transfer-nft"}}`)) + ctx, addr, queryMsgRaw) expected_result := "" require.Equal(t, string(result), expected_result) require.EqualError(t, err, "cw721_base_ibc::state::TokenInfo not found: query wasm contract failed") } func RunGetOwner(t *testing.T, ctx sdk.Context, app *app.App, msgServer wasmtypes.MsgServer, accs []Account, - instantiateRes *wasmtypes.MsgInstantiateContractResponse, getOwnerMsgRaw []byte, owner sdk.Address) { + instantiateRes *wasmtypes.MsgInstantiateContractResponse, getOwnerMsgRaw []byte, expected_response string) { escrow721Address := instantiateRes.Address addr, _ := sdk.AccAddressFromBech32(escrow721Address) result, _ := app.WasmKeeper.QuerySmart( ctx, addr, getOwnerMsgRaw) - expected_result := string(fmt.Sprintf(`{"owner":"%s","approvals":[]}`, owner.String())) - require.Equal(t, string(result), expected_result) + require.Equal(t, string(result), expected_response) } func RunGetNFTInfo(t *testing.T, ctx sdk.Context, app *app.App, msgServer wasmtypes.MsgServer, accs []Account, - instantiateRes *wasmtypes.MsgInstantiateContractResponse, getNFTInfoMsgRaw []byte, err error) { + instantiateRes *wasmtypes.MsgInstantiateContractResponse, getNFTInfoMsgRaw []byte, expected_response string) { escrow721Address := instantiateRes.Address addr, _ := sdk.AccAddressFromBech32(escrow721Address) result, _ := app.WasmKeeper.QuerySmart( ctx, addr, getNFTInfoMsgRaw) - expected_result := string(`{"token_uri":"ipfs://abc123","extension":{}}`) - require.Equal(t, string(result), expected_result) + require.Equal(t, string(result), expected_response) } func RunHasClass(t *testing.T, ctx sdk.Context, app *app.App, msgServer wasmtypes.MsgServer, accs []Account, From a694720471c33a9edd97b918655e0995cef7fb7e Mon Sep 17 00:00:00 2001 From: Humanalgorithm Date: Wed, 22 Jun 2022 22:36:00 -0400 Subject: [PATCH 22/33] fix class storage map --- contracts/escrow721/src/contract.rs | 6 +++--- contracts/escrow721/src/state.rs | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/contracts/escrow721/src/contract.rs b/contracts/escrow721/src/contract.rs index 95baa44a..34457cde 100644 --- a/contracts/escrow721/src/contract.rs +++ b/contracts/escrow721/src/contract.rs @@ -41,7 +41,7 @@ pub fn save_class( class_id: String, class_uri: String, ) -> Result, ContractError> { - CLASS_STORAGE.save(deps.storage, class_id, &class_uri)?; + CLASS_STORAGE.save(deps.storage, &class_id, &class_uri)?; Ok(Response::default()) } @@ -124,11 +124,11 @@ fn nft_info(deps: Deps, class_id: String, token_id: String) -> StdResult bool { - CLASS_STORAGE.has(deps.storage, class_id) + CLASS_STORAGE.has(deps.storage, &class_id) } fn get_class(deps: Deps, class_id: String) -> StdResult<(String, String)> { - match CLASS_STORAGE.load(deps.storage, class_id.clone()) { + match CLASS_STORAGE.load(deps.storage, &class_id.clone()) { Ok(class_uri) => Ok((class_id, class_uri)), Err(_) => Err(StdError::generic_err(format!( "Class {} not found", diff --git a/contracts/escrow721/src/state.rs b/contracts/escrow721/src/state.rs index e5286647..48c55834 100644 --- a/contracts/escrow721/src/state.rs +++ b/contracts/escrow721/src/state.rs @@ -1,3 +1,5 @@ use cw_storage_plus::Map; -pub const CLASS_STORAGE: Map = Map::new("class_storage"); +// This map is used to store key: class_id to data: class_uri +// per the save_class method in contracts/escrow721/src/contract.rs +pub const CLASS_STORAGE: Map<&str, String> = Map::new("class_storage"); From b3cdbed84ebc3845e018ddb3f2c07b231ed63562 Mon Sep 17 00:00:00 2001 From: Humanalgorithm Date: Wed, 22 Jun 2022 22:42:35 -0400 Subject: [PATCH 23/33] adding response attributes --- contracts/escrow721/src/contract.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/contracts/escrow721/src/contract.rs b/contracts/escrow721/src/contract.rs index 34457cde..cbbde2fd 100644 --- a/contracts/escrow721/src/contract.rs +++ b/contracts/escrow721/src/contract.rs @@ -1,6 +1,5 @@ use cosmwasm_std::entry_point; -use cosmwasm_std::Response; -use cosmwasm_std::StdError; +use cosmwasm_std::{Response, StdError, attr}; #[cfg(not(feature = "library"))] use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Empty, Env, MessageInfo, StdResult}; use cw721_base_ibc::msg::{ExecuteMsg, InstantiateMsg, MintMsg, QueryMsg}; @@ -42,7 +41,13 @@ pub fn save_class( class_uri: String, ) -> Result, ContractError> { CLASS_STORAGE.save(deps.storage, &class_id, &class_uri)?; - Ok(Response::default()) + Ok(Response::default().add_attributes(vec![ + attr("action", "save_class"), + attr("class_id", class_id), + attr("class_uri", class_uri), + ]) + +) } pub fn transfer( From dac2db1e39a2072c1e6bac0e8a3e4c5717cc3ff9 Mon Sep 17 00:00:00 2001 From: Humanalgorithm Date: Wed, 22 Jun 2022 22:43:25 -0400 Subject: [PATCH 24/33] fix format --- contracts/escrow721/src/contract.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/contracts/escrow721/src/contract.rs b/contracts/escrow721/src/contract.rs index cbbde2fd..69cfcc47 100644 --- a/contracts/escrow721/src/contract.rs +++ b/contracts/escrow721/src/contract.rs @@ -1,5 +1,5 @@ use cosmwasm_std::entry_point; -use cosmwasm_std::{Response, StdError, attr}; +use cosmwasm_std::{attr, Response, StdError}; #[cfg(not(feature = "library"))] use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Empty, Env, MessageInfo, StdResult}; use cw721_base_ibc::msg::{ExecuteMsg, InstantiateMsg, MintMsg, QueryMsg}; @@ -45,9 +45,7 @@ pub fn save_class( attr("action", "save_class"), attr("class_id", class_id), attr("class_uri", class_uri), - ]) - -) + ])) } pub fn transfer( From edce0d0e68fbc370f8f88ba5b47ddda27a30bece Mon Sep 17 00:00:00 2001 From: Humanalgorithm Date: Wed, 22 Jun 2022 23:22:55 -0400 Subject: [PATCH 25/33] updating cargo versions --- .circleci/config.yml | 2 +- Cargo.lock | 36 +++++++++++++++++----------------- contracts/escrow721/Cargo.toml | 14 ++++++------- contracts/ics721/Cargo.toml | 14 ++++++------- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index fe1c95dd..6aba5ee2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -113,7 +113,7 @@ jobs: - run: name: Install check_contract # Uses --debug for compilation speed - command: cargo install --debug --version 1.0.0-beta4 --features iterator --example check_contract -- cosmwasm-vm + command: cargo install --debug --version 1.0.0 --features iterator --example check_contract -- cosmwasm-vm - save_cache: paths: - /usr/local/cargo/registry diff --git a/Cargo.lock b/Cargo.lock index 5fd79822..a68614a3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -335,9 +335,9 @@ dependencies = [ [[package]] name = "dyn-clone" -version = "1.0.5" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21e50f3adc76d6a43f5ed73b698a87d0760ca74617f60f7c3b879003536fdd28" +checksum = "140206b78fb2bc3edbcfc9b5ccbd0b30699cfe8d348b8b31b330e47df5291a5a" [[package]] name = "ecdsa" @@ -452,13 +452,13 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9be70c98951c83b8d2f8f60d7065fa6d5146873094452a1008da8c2f1e4205ad" +checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" dependencies = [ "cfg-if", "libc", - "wasi 0.10.2+wasi-snapshot-preview1", + "wasi 0.11.0+wasi-snapshot-preview1", ] [[package]] @@ -573,18 +573,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.39" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f" +checksum = "dd96a1e8ed2596c337f8eae5f24924ec83f5ad5ab21ea8e455d3566c69fbcaf7" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.18" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1" +checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804" dependencies = [ "proc-macro2", ] @@ -604,7 +604,7 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" dependencies = [ - "getrandom 0.2.6", + "getrandom 0.2.7", ] [[package]] @@ -663,9 +663,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.9" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cb243bdfdb5936c8dc3c45762a19d12ab4550cdc753bc247637d4ec35a040fd" +checksum = "a41d061efea015927ac527063765e73601444cdc344ba855bc7bd44578b25e1c" [[package]] name = "serde" @@ -814,9 +814,9 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" -version = "1.0.96" +version = "1.0.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0748dd251e24453cb8717f0354206b91557e4ec8703673a4b30208f2abaf1ebf" +checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd" dependencies = [ "proc-macro2", "quote", @@ -884,9 +884,9 @@ checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" [[package]] name = "unicode-ident" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee" +checksum = "5bd2fe26506023ed7b5e1e315add59d6f584c621d037f9368fea9cfb988f368c" [[package]] name = "unicode-normalization" @@ -923,9 +923,9 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] name = "wasi" -version = "0.10.2+wasi-snapshot-preview1" +version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "zeroize" diff --git a/contracts/escrow721/Cargo.toml b/contracts/escrow721/Cargo.toml index 17e43892..d104669e 100644 --- a/contracts/escrow721/Cargo.toml +++ b/contracts/escrow721/Cargo.toml @@ -30,12 +30,12 @@ optimize = """docker run --rm -v "$(pwd)":/code \ """ [dependencies] -cosmwasm-std = { version = "1.0.0-beta8", features = ["stargate"] } -cosmwasm-storage = { version = "1.0.0-beta8" } -cw-storage-plus = "0.13.2" -cw-utils = "0.13.2" -cw2 = "0.13.2" -cw20-ics20 = { version = "0.13.2", features = ["library"] } +cosmwasm-std = { version = "1.0.0", features = ["stargate"] } +cosmwasm-storage = { version = "1.0.0" } +cw-storage-plus = "0.13.4" +cw-utils = "0.13.4" +cw2 = "0.13.4" +cw20-ics20 = { version = "0.13.4", features = ["library"] } sg721 = { version = "0.12.0", features = ["library"] } cw721-base-ibc = { git = "https://github.com/public-awesome/cw721-ibc.git", version = "0.13.2", branch="main", features = ["library"]} cw721-ibc = { git = "https://github.com/public-awesome/cw721-ibc.git", branch="main", version = "0.13.2"} @@ -44,4 +44,4 @@ serde = { version = "1.0.133", default-features = false, features = ["derive"] } thiserror = { version = "1.0.30" } [dev-dependencies] -cosmwasm-schema = { version = "1.0.0-beta8" } +cosmwasm-schema = { version = "1.0.0" } diff --git a/contracts/ics721/Cargo.toml b/contracts/ics721/Cargo.toml index 6f782208..b5e3452f 100644 --- a/contracts/ics721/Cargo.toml +++ b/contracts/ics721/Cargo.toml @@ -30,12 +30,12 @@ optimize = """docker run --rm -v "$(pwd)":/code \ """ [dependencies] -cosmwasm-std = { version = "1.0.0-beta8", features = ["stargate"] } -cosmwasm-storage = { version = "1.0.0-beta8" } -cw-storage-plus = "0.13.2" -cw-utils = "0.13.2" -cw2 = "0.13.2" -cw20-ics20 = { version = "0.13.2", features = ["library"] } +cosmwasm-std = { version = "1.0.0", features = ["stargate"] } +cosmwasm-storage = { version = "1.0.0" } +cw-storage-plus = "0.13.4" +cw-utils = "0.13.4" +cw2 = "0.13.4" +cw20-ics20 = { version = "0.13.4", features = ["library"] } cw721-base-ibc = { git = "https://github.com/public-awesome/cw721-ibc.git", version="0.13.2"} cw721-ibc = { git = "https://github.com/public-awesome/cw721-ibc.git", version="0.13.2"} schemars = "0.8.8" @@ -43,4 +43,4 @@ serde = { version = "1.0.133", default-features = false, features = ["derive"] } thiserror = { version = "1.0.30" } [dev-dependencies] -cosmwasm-schema = { version = "1.0.0-beta8" } +cosmwasm-schema = { version = "1.0.0" } From 086c1372db84069d70b9907cc12301d92dd8ca2b Mon Sep 17 00:00:00 2001 From: Humanalgorithm Date: Wed, 22 Jun 2022 23:34:33 -0400 Subject: [PATCH 26/33] updating cargo cw721-ibc versions --- Cargo.lock | 28 ++++++++++++++-------------- contracts/escrow721/Cargo.toml | 4 ++-- contracts/ics721/Cargo.toml | 4 ++-- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a68614a3..5eb14871 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -265,14 +265,14 @@ dependencies = [ [[package]] name = "cw721-base-ibc" -version = "0.13.2" -source = "git+https://github.com/public-awesome/cw721-ibc.git?branch=main#87dc9af8b5edc2eac0ecf40164c7e379b68ec19a" +version = "0.13.4" +source = "git+https://github.com/public-awesome/cw721-ibc.git?branch=main#35615da5cd4f26869f481896e66f771ac4b5421b" dependencies = [ "cosmwasm-std", "cw-storage-plus", "cw-utils", "cw2", - "cw721-ibc 0.13.2 (git+https://github.com/public-awesome/cw721-ibc.git?branch=main)", + "cw721-ibc 0.13.4 (git+https://github.com/public-awesome/cw721-ibc.git?branch=main)", "schemars", "serde", "thiserror", @@ -280,14 +280,14 @@ dependencies = [ [[package]] name = "cw721-base-ibc" -version = "0.13.2" -source = "git+https://github.com/public-awesome/cw721-ibc.git#87dc9af8b5edc2eac0ecf40164c7e379b68ec19a" +version = "0.13.4" +source = "git+https://github.com/public-awesome/cw721-ibc.git#35615da5cd4f26869f481896e66f771ac4b5421b" dependencies = [ "cosmwasm-std", "cw-storage-plus", "cw-utils", "cw2", - "cw721-ibc 0.13.2 (git+https://github.com/public-awesome/cw721-ibc.git)", + "cw721-ibc 0.13.4 (git+https://github.com/public-awesome/cw721-ibc.git)", "schemars", "serde", "thiserror", @@ -295,8 +295,8 @@ dependencies = [ [[package]] name = "cw721-ibc" -version = "0.13.2" -source = "git+https://github.com/public-awesome/cw721-ibc.git?branch=main#87dc9af8b5edc2eac0ecf40164c7e379b68ec19a" +version = "0.13.4" +source = "git+https://github.com/public-awesome/cw721-ibc.git?branch=main#35615da5cd4f26869f481896e66f771ac4b5421b" dependencies = [ "cosmwasm-std", "cw-utils", @@ -306,8 +306,8 @@ dependencies = [ [[package]] name = "cw721-ibc" -version = "0.13.2" -source = "git+https://github.com/public-awesome/cw721-ibc.git#87dc9af8b5edc2eac0ecf40164c7e379b68ec19a" +version = "0.13.4" +source = "git+https://github.com/public-awesome/cw721-ibc.git#35615da5cd4f26869f481896e66f771ac4b5421b" dependencies = [ "cosmwasm-std", "cw-utils", @@ -395,8 +395,8 @@ dependencies = [ "cw-utils", "cw2", "cw20-ics20", - "cw721-base-ibc 0.13.2 (git+https://github.com/public-awesome/cw721-ibc.git?branch=main)", - "cw721-ibc 0.13.2 (git+https://github.com/public-awesome/cw721-ibc.git?branch=main)", + "cw721-base-ibc 0.13.4 (git+https://github.com/public-awesome/cw721-ibc.git?branch=main)", + "cw721-ibc 0.13.4 (git+https://github.com/public-awesome/cw721-ibc.git?branch=main)", "schemars", "serde", "sg721", @@ -499,8 +499,8 @@ dependencies = [ "cw-utils", "cw2", "cw20-ics20", - "cw721-base-ibc 0.13.2 (git+https://github.com/public-awesome/cw721-ibc.git)", - "cw721-ibc 0.13.2 (git+https://github.com/public-awesome/cw721-ibc.git)", + "cw721-base-ibc 0.13.4 (git+https://github.com/public-awesome/cw721-ibc.git)", + "cw721-ibc 0.13.4 (git+https://github.com/public-awesome/cw721-ibc.git)", "schemars", "serde", "thiserror", diff --git a/contracts/escrow721/Cargo.toml b/contracts/escrow721/Cargo.toml index d104669e..6f898a99 100644 --- a/contracts/escrow721/Cargo.toml +++ b/contracts/escrow721/Cargo.toml @@ -37,8 +37,8 @@ cw-utils = "0.13.4" cw2 = "0.13.4" cw20-ics20 = { version = "0.13.4", features = ["library"] } sg721 = { version = "0.12.0", features = ["library"] } -cw721-base-ibc = { git = "https://github.com/public-awesome/cw721-ibc.git", version = "0.13.2", branch="main", features = ["library"]} -cw721-ibc = { git = "https://github.com/public-awesome/cw721-ibc.git", branch="main", version = "0.13.2"} +cw721-base-ibc = { git = "https://github.com/public-awesome/cw721-ibc.git", version = "0.13.4", branch="main", features = ["library"]} +cw721-ibc = { git = "https://github.com/public-awesome/cw721-ibc.git", branch="main", version = "0.13.4"} schemars = "0.8.8" serde = { version = "1.0.133", default-features = false, features = ["derive"] } thiserror = { version = "1.0.30" } diff --git a/contracts/ics721/Cargo.toml b/contracts/ics721/Cargo.toml index b5e3452f..a12fc3be 100644 --- a/contracts/ics721/Cargo.toml +++ b/contracts/ics721/Cargo.toml @@ -36,8 +36,8 @@ cw-storage-plus = "0.13.4" cw-utils = "0.13.4" cw2 = "0.13.4" cw20-ics20 = { version = "0.13.4", features = ["library"] } -cw721-base-ibc = { git = "https://github.com/public-awesome/cw721-ibc.git", version="0.13.2"} -cw721-ibc = { git = "https://github.com/public-awesome/cw721-ibc.git", version="0.13.2"} +cw721-base-ibc = { git = "https://github.com/public-awesome/cw721-ibc.git", version="0.13.4"} +cw721-ibc = { git = "https://github.com/public-awesome/cw721-ibc.git", version="0.13.4"} schemars = "0.8.8" serde = { version = "1.0.133", default-features = false, features = ["derive"] } thiserror = { version = "1.0.30" } From b54636852215f1db2913a85d7c016826d5e006ab Mon Sep 17 00:00:00 2001 From: Humanalgorithm Date: Wed, 22 Jun 2022 23:47:58 -0400 Subject: [PATCH 27/33] change to get nft --- contracts/escrow721/src/contract.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/escrow721/src/contract.rs b/contracts/escrow721/src/contract.rs index 69cfcc47..1f1be030 100644 --- a/contracts/escrow721/src/contract.rs +++ b/contracts/escrow721/src/contract.rs @@ -103,7 +103,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { token_id, include_expired.unwrap_or(false), )?), - QueryMsg::NftInfo { class_id, token_id } => to_binary(&nft_info(deps, class_id, token_id)?), + QueryMsg::NftInfo { class_id, token_id } => to_binary(&get_nft(deps, class_id, token_id)?), QueryMsg::HasClass { class_id } => to_binary(&has_class(deps, class_id)), QueryMsg::GetClass { class_id } => to_binary(&get_class(deps, class_id)?), _ => Err(StdError::GenericErr { @@ -122,7 +122,7 @@ pub fn get_owner( CW721ContractWrapper::default().owner_of(deps, env, class_id, token_id, include_expired) } -fn nft_info(deps: Deps, class_id: String, token_id: String) -> StdResult> { +fn get_nft(deps: Deps, class_id: String, token_id: String) -> StdResult> { CW721ContractWrapper::default().nft_info(deps, class_id, token_id) } From 4fe8d488c2165d13b45ef6fb4de12feb0a3322a1 Mon Sep 17 00:00:00 2001 From: Humanalgorithm Date: Wed, 22 Jun 2022 23:51:16 -0400 Subject: [PATCH 28/33] change to getnft --- contracts/ics721/src/contract.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/ics721/src/contract.rs b/contracts/ics721/src/contract.rs index 8b983156..0066bfd9 100644 --- a/contracts/ics721/src/contract.rs +++ b/contracts/ics721/src/contract.rs @@ -149,7 +149,7 @@ fn query_list(deps: Deps) -> StdResult { channels: channels?, }) } - + pub fn query_channel(deps: Deps, id: String) -> StdResult { let info = CHANNEL_INFO.load(deps.storage, &id)?; let _class_ids: StdResult> = CHANNEL_STATE From 337d22876b6c9ca824fbb4c9d9f0d68e05b7d1fe Mon Sep 17 00:00:00 2001 From: Humanalgorithm Date: Thu, 23 Jun 2022 11:43:37 -0400 Subject: [PATCH 29/33] fix lint --- contracts/ics721/src/contract.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/ics721/src/contract.rs b/contracts/ics721/src/contract.rs index 0066bfd9..8b983156 100644 --- a/contracts/ics721/src/contract.rs +++ b/contracts/ics721/src/contract.rs @@ -149,7 +149,7 @@ fn query_list(deps: Deps) -> StdResult { channels: channels?, }) } - + pub fn query_channel(deps: Deps, id: String) -> StdResult { let info = CHANNEL_INFO.load(deps.storage, &id)?; let _class_ids: StdResult> = CHANNEL_STATE From f0d7981b4ad1c0134062b51094f90454a4b72dd5 Mon Sep 17 00:00:00 2001 From: Humanalgorithm Date: Thu, 23 Jun 2022 15:41:42 -0400 Subject: [PATCH 30/33] refactory query logic --- contracts/ics721/src/contract.rs | 75 ++------------------------- contracts/ics721/src/contract_test.rs | 37 +++++++++---- contracts/ics721/src/ibc_test.rs | 4 +- contracts/ics721/src/lib.rs | 1 + contracts/ics721/src/query.rs | 72 +++++++++++++++++++++++++ 5 files changed, 106 insertions(+), 83 deletions(-) create mode 100644 contracts/ics721/src/query.rs diff --git a/contracts/ics721/src/contract.rs b/contracts/ics721/src/contract.rs index 8b983156..b1275363 100644 --- a/contracts/ics721/src/contract.rs +++ b/contracts/ics721/src/contract.rs @@ -1,18 +1,14 @@ #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; -use cosmwasm_std::{ - from_binary, to_binary, Addr, Binary, Deps, DepsMut, Env, IbcMsg, IbcQuery, MessageInfo, Order, - PortIdResponse, Response, StdResult, -}; +use cosmwasm_std::{from_binary, to_binary, Addr, DepsMut, Env, IbcMsg, MessageInfo, Response}; use cw2::set_contract_version; -use cw20_ics20::msg::{ListChannelsResponse, PortResponse}; use cw721_ibc::Cw721ReceiveMsg; use cw_utils::nonpayable; use crate::error::ContractError; use crate::ibc::Ics721Packet; -use crate::msg::{ChannelResponse, ExecuteMsg, InstantiateMsg, QueryMsg, TransferMsg}; -use crate::state::{Config, CHANNEL_INFO, CHANNEL_STATE, CONFIG}; +use crate::msg::{ExecuteMsg, InstantiateMsg, TransferMsg}; +use crate::state::{Config, CHANNEL_INFO, CONFIG}; // version info for migration info const CONTRACT_NAME: &str = "crates.io:sg721-ics721"; @@ -118,68 +114,3 @@ pub fn execute_transfer( .add_attribute("token_ids", &packet.token_ids.join(",")); Ok(res) } - -// TODO: Alot of this query code is copy pasta. -// Find a way to make it generic or put into a package. -#[cfg_attr(not(feature = "library"), entry_point)] -pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { - match msg { - QueryMsg::Port {} => to_binary(&query_port(deps)?), - QueryMsg::ListChannels {} => to_binary(&query_list(deps)?), - QueryMsg::Channel { id } => to_binary(&query_channel(deps, id)?), - QueryMsg::Tokens { - channel_id, - class_id, - } => to_binary(&query_tokens(deps, channel_id, class_id)?), - } -} - -fn query_port(deps: Deps) -> StdResult { - let query = IbcQuery::PortId {}.into(); - let PortIdResponse { port_id } = deps.querier.query(&query)?; - Ok(PortResponse { port_id }) -} - -fn query_list(deps: Deps) -> StdResult { - let channels: StdResult> = CHANNEL_INFO - .range(deps.storage, None, None, Order::Ascending) - .map(|r| r.map(|(_, v)| v)) - .collect(); - Ok(ListChannelsResponse { - channels: channels?, - }) -} - -pub fn query_channel(deps: Deps, id: String) -> StdResult { - let info = CHANNEL_INFO.load(deps.storage, &id)?; - let _class_ids: StdResult> = CHANNEL_STATE - .sub_prefix(&id) - .range(deps.storage, None, None, Order::Ascending) - .map(|r| { - let (class_id_token_id, _) = r?; - Ok(class_id_token_id.0) - }) - .collect(); - - let class_ids_resp = _class_ids; - match class_ids_resp { - Ok(mut class_id_vec) => Ok(ChannelResponse { - info, - class_ids: { - class_id_vec.sort(); - class_id_vec.dedup(); - class_id_vec - }, - }), - Err(msg) => Err(msg), - } -} - -// TODO: https://github.com/public-awesome/contracts/issues/59 -pub fn query_tokens( - _deps: Deps, - _channel_id: String, - _class_id: String, -) -> StdResult { - todo!() -} diff --git a/contracts/ics721/src/contract_test.rs b/contracts/ics721/src/contract_test.rs index f5bfcecb..62828c9b 100644 --- a/contracts/ics721/src/contract_test.rs +++ b/contracts/ics721/src/contract_test.rs @@ -1,15 +1,26 @@ #[cfg(test)] mod contact_testing { + use core::panic; + use super::super::*; + use crate::msg::{ChannelResponse, ExecuteMsg, InstantiateMsg, QueryMsg, TransferMsg}; + use crate::query; + use crate::state::CHANNEL_STATE; use crate::test_constants::*; use crate::test_helpers::*; use cosmwasm_std::testing::mock_env; - use cosmwasm_std::{from_binary, to_binary, Attribute, Coin, StdError}; + use cosmwasm_std::Deps; + use cosmwasm_std::{ + from_binary, to_binary, Addr, Attribute, Coin, MessageInfo, Response, StdError, + }; use cosmwasm_std::{CosmosMsg, IbcEndpoint}; use cw2::{get_contract_version, ContractVersion}; + use cw20_ics20::msg::ListChannelsResponse; use cw20_ics20::state::ChannelInfo; + use cw20_ics20::ContractError; use cw721_ibc::Cw721ReceiveMsg; + use query::{query, query_channel}; use cosmwasm_std::testing::mock_dependencies; @@ -59,9 +70,8 @@ mod contact_testing { #[test] fn test_query_channel_list_success() { let deps = setup(&[TEST_CHANNEL_0_DATA, TEST_CHANNEL_1_DATA]); - let result = query_list(deps.as_ref()); - - let expected_list: StdResult = Ok(ListChannelsResponse { + let result = query(deps.as_ref(), mock_env(), QueryMsg::ListChannels {}); + let expected_list = ListChannelsResponse { channels: vec![ ChannelInfo { id: CHANNEL_FROM_STARS_TO_OMNI.to_string(), @@ -80,8 +90,12 @@ mod contact_testing { connection_id: CONNECTION_1.to_string(), }, ], - }); - assert_eq!(result, expected_list); + }; + let expected_list_bin = to_binary(&expected_list).unwrap(); + match result { + Ok(bin) => assert_eq!(bin, expected_list_bin), + Err(_err) => panic!("Query failed for test_query_channel_list_success"), + } } #[test] @@ -89,11 +103,14 @@ mod contact_testing { let mut deps = setup(&[TEST_CHANNEL_0_DATA, TEST_CHANNEL_1_DATA]); CHANNEL_INFO.remove(&mut deps.storage, CHANNEL_FROM_STARS_TO_OMNI); CHANNEL_INFO.remove(&mut deps.storage, CHANNEL_FROM_STARS_TO_GB); - let result = query_list(deps.as_ref()); + let result = query(deps.as_ref(), mock_env(), QueryMsg::ListChannels {}); - let expected_list: StdResult = - Ok(ListChannelsResponse { channels: vec![] }); - assert_eq!(result, expected_list); + let expected_list = ListChannelsResponse { channels: vec![] }; + let expected_list_bin = to_binary(&expected_list).unwrap(); + match result { + Ok(bin) => assert_eq!(bin, expected_list_bin), + Err(_err) => panic!("Query failed for test_query_channel_list_empty"), + } } #[test] diff --git a/contracts/ics721/src/ibc_test.rs b/contracts/ics721/src/ibc_test.rs index 3cd00f1d..170d3709 100644 --- a/contracts/ics721/src/ibc_test.rs +++ b/contracts/ics721/src/ibc_test.rs @@ -4,15 +4,17 @@ mod ibc_testing { use std::vec; use super::super::*; + use crate::query; use crate::test_constants::{ CHANNEL_FROM_OMNI_TO_STARS, CHANNEL_FROM_STARS_TO_OMNI, CONNECTION_0, TEST_CHANNEL_0_DATA, TEST_CHANNEL_1_DATA, }; use crate::test_helpers::*; + use cosmwasm_std::CosmosMsg::Wasm; use cosmwasm_std::WasmMsg::Execute; + use query::query_channel; - use crate::contract::query_channel; use cosmwasm_std::testing::mock_dependencies; use cosmwasm_std::testing::mock_env; use cosmwasm_std::{ diff --git a/contracts/ics721/src/lib.rs b/contracts/ics721/src/lib.rs index 9d7f63d5..ac4c8e78 100644 --- a/contracts/ics721/src/lib.rs +++ b/contracts/ics721/src/lib.rs @@ -2,6 +2,7 @@ pub mod contract; mod error; pub mod ibc; pub mod msg; +pub mod query; pub mod state; mod test_constants; mod test_helpers; diff --git a/contracts/ics721/src/query.rs b/contracts/ics721/src/query.rs new file mode 100644 index 00000000..374d72d7 --- /dev/null +++ b/contracts/ics721/src/query.rs @@ -0,0 +1,72 @@ +use crate::msg::{ChannelResponse, QueryMsg}; +use crate::state::{CHANNEL_INFO, CHANNEL_STATE}; + +#[cfg(not(feature = "library"))] +use cosmwasm_std::entry_point; +use cosmwasm_std::{to_binary, Binary, Deps, Env, IbcQuery, Order, PortIdResponse, StdResult}; +use cw20_ics20::msg::{ListChannelsResponse, PortResponse}; + +// TODO: Alot of this query code is copy pasta. +// Find a way to make it generic or put into a package. +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { + match msg { + QueryMsg::Port {} => to_binary(&query_port(deps)?), + QueryMsg::ListChannels {} => to_binary(&query_list(deps)?), + QueryMsg::Channel { id } => to_binary(&query_channel(deps, id)?), + QueryMsg::Tokens { + channel_id, + class_id, + } => to_binary(&query_tokens(deps, channel_id, class_id)?), + } +} + +fn query_port(deps: Deps) -> StdResult { + let query = IbcQuery::PortId {}.into(); + let PortIdResponse { port_id } = deps.querier.query(&query)?; + Ok(PortResponse { port_id }) +} + +fn query_list(deps: Deps) -> StdResult { + let channels: StdResult> = CHANNEL_INFO + .range(deps.storage, None, None, Order::Ascending) + .map(|r| r.map(|(_, v)| v)) + .collect(); + Ok(ListChannelsResponse { + channels: channels?, + }) +} + +pub fn query_channel(deps: Deps, id: String) -> StdResult { + let info = CHANNEL_INFO.load(deps.storage, &id)?; + let _class_ids: StdResult> = CHANNEL_STATE + .sub_prefix(&id) + .range(deps.storage, None, None, Order::Ascending) + .map(|r| { + let (class_id_token_id, _) = r?; + Ok(class_id_token_id.0) + }) + .collect(); + + let class_ids_resp = _class_ids; + match class_ids_resp { + Ok(mut class_id_vec) => Ok(ChannelResponse { + info, + class_ids: { + class_id_vec.sort(); + class_id_vec.dedup(); + class_id_vec + }, + }), + Err(msg) => Err(msg), + } +} + +// TODO: https://github.com/public-awesome/contracts/issues/59 +pub fn query_tokens( + _deps: Deps, + _channel_id: String, + _class_id: String, +) -> StdResult { + todo!() +} From 36c93d5b76433083d7f49333fad64701e56c1b99 Mon Sep 17 00:00:00 2001 From: Humanalgorithm Date: Thu, 23 Jun 2022 15:44:21 -0400 Subject: [PATCH 31/33] remove non needed comment --- contracts/ics721/src/query.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/contracts/ics721/src/query.rs b/contracts/ics721/src/query.rs index 374d72d7..8eb89e3d 100644 --- a/contracts/ics721/src/query.rs +++ b/contracts/ics721/src/query.rs @@ -6,8 +6,6 @@ use cosmwasm_std::entry_point; use cosmwasm_std::{to_binary, Binary, Deps, Env, IbcQuery, Order, PortIdResponse, StdResult}; use cw20_ics20::msg::{ListChannelsResponse, PortResponse}; -// TODO: Alot of this query code is copy pasta. -// Find a way to make it generic or put into a package. #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { match msg { From 4ffd6f2d4413732eb8b5d5f18e886d21a921c737 Mon Sep 17 00:00:00 2001 From: Humanalgorithm Date: Thu, 23 Jun 2022 18:58:59 -0400 Subject: [PATCH 32/33] changing query functions to public --- contracts/escrow721/src/contract.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contracts/escrow721/src/contract.rs b/contracts/escrow721/src/contract.rs index 1f1be030..433d5213 100644 --- a/contracts/escrow721/src/contract.rs +++ b/contracts/escrow721/src/contract.rs @@ -122,15 +122,15 @@ pub fn get_owner( CW721ContractWrapper::default().owner_of(deps, env, class_id, token_id, include_expired) } -fn get_nft(deps: Deps, class_id: String, token_id: String) -> StdResult> { +pub fn get_nft(deps: Deps, class_id: String, token_id: String) -> StdResult> { CW721ContractWrapper::default().nft_info(deps, class_id, token_id) } -fn has_class(deps: Deps, class_id: String) -> bool { +pub fn has_class(deps: Deps, class_id: String) -> bool { CLASS_STORAGE.has(deps.storage, &class_id) } -fn get_class(deps: Deps, class_id: String) -> StdResult<(String, String)> { +pub fn get_class(deps: Deps, class_id: String) -> StdResult<(String, String)> { match CLASS_STORAGE.load(deps.storage, &class_id.clone()) { Ok(class_uri) => Ok((class_id, class_uri)), Err(_) => Err(StdError::generic_err(format!( From accb69e67ae359158ef2b7c3789312a3488bce38 Mon Sep 17 00:00:00 2001 From: Humanalgorithm Date: Thu, 23 Jun 2022 18:59:44 -0400 Subject: [PATCH 33/33] fix lint --- contracts/escrow721/src/contract.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/contracts/escrow721/src/contract.rs b/contracts/escrow721/src/contract.rs index 433d5213..291b0dab 100644 --- a/contracts/escrow721/src/contract.rs +++ b/contracts/escrow721/src/contract.rs @@ -122,7 +122,11 @@ pub fn get_owner( CW721ContractWrapper::default().owner_of(deps, env, class_id, token_id, include_expired) } -pub fn get_nft(deps: Deps, class_id: String, token_id: String) -> StdResult> { +pub fn get_nft( + deps: Deps, + class_id: String, + token_id: String, +) -> StdResult> { CW721ContractWrapper::default().nft_info(deps, class_id, token_id) }