Skip to content

Commit

Permalink
Merge pull request #208 from public-awesome/shanev/206-fix-queries
Browse files Browse the repository at this point in the history
Fix `include_inactive` queries
  • Loading branch information
shanev authored May 10, 2022
2 parents f1bb91f + 00347ef commit 815342f
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 75 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion contracts/marketplace/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sg-marketplace"
version = "0.14.4"
version = "0.15.0"
authors = [
"Shane Vitarana <[email protected]>",
"Jake Hartnell <[email protected]>",
Expand Down
30 changes: 19 additions & 11 deletions contracts/marketplace/schema/query_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,17 @@
"asks": {
"type": "object",
"required": [
"collection",
"include_inactive"
"collection"
],
"properties": {
"collection": {
"type": "string"
},
"include_inactive": {
"type": "boolean"
"type": [
"boolean",
"null"
]
},
"limit": {
"type": [
Expand Down Expand Up @@ -109,15 +111,17 @@
"asks_sorted_by_price": {
"type": "object",
"required": [
"collection",
"include_inactive"
"collection"
],
"properties": {
"collection": {
"type": "string"
},
"include_inactive": {
"type": "boolean"
"type": [
"boolean",
"null"
]
},
"limit": {
"type": [
Expand Down Expand Up @@ -152,15 +156,17 @@
"reverse_asks_sorted_by_price": {
"type": "object",
"required": [
"collection",
"include_inactive"
"collection"
],
"properties": {
"collection": {
"type": "string"
},
"include_inactive": {
"type": "boolean"
"type": [
"boolean",
"null"
]
},
"limit": {
"type": [
Expand Down Expand Up @@ -216,12 +222,14 @@
"asks_by_seller": {
"type": "object",
"required": [
"include_inactive",
"seller"
],
"properties": {
"include_inactive": {
"type": "boolean"
"type": [
"boolean",
"null"
]
},
"limit": {
"type": [
Expand Down
8 changes: 4 additions & 4 deletions contracts/marketplace/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,25 +224,25 @@ pub enum QueryMsg {
/// Return type: `AsksResponse`
Asks {
collection: Collection,
include_inactive: Option<bool>,
start_after: Option<TokenId>,
limit: Option<u32>,
include_inactive: bool,
},
/// Get all asks for a collection, sorted by price
/// Return type: `AsksResponse`
AsksSortedByPrice {
collection: Collection,
include_inactive: Option<bool>,
start_after: Option<AskOffset>,
limit: Option<u32>,
include_inactive: bool,
},
/// Get all asks for a collection, sorted by price in reverse
/// Return type: `AsksResponse`
ReverseAsksSortedByPrice {
collection: Collection,
include_inactive: Option<bool>,
start_before: Option<AskOffset>,
limit: Option<u32>,
include_inactive: bool,
},
/// Count of all asks
/// Return type: `AskCountResponse`
Expand All @@ -251,9 +251,9 @@ pub enum QueryMsg {
/// Return type: `AsksResponse`
AsksBySeller {
seller: Seller,
include_inactive: Option<bool>,
start_after: Option<CollectionOffset>,
limit: Option<u32>,
include_inactive: bool,
},
/// Get data for a specific bid
/// Return type: `BidResponse`
Expand Down
58 changes: 41 additions & 17 deletions contracts/marketplace/src/multitest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,9 +637,9 @@ fn try_query_asks() {
// test before ask is made, without using pagination
let query_asks_msg = QueryMsg::Asks {
collection: collection.to_string(),
include_inactive: Some(true),
start_after: None,
limit: None,
include_inactive: true,
};
let res: AsksResponse = router
.wrap()
Expand Down Expand Up @@ -672,9 +672,9 @@ fn try_query_asks() {
// test pagination, starting when tokens exist
let query_asks_msg = QueryMsg::Asks {
collection: collection.to_string(),
include_inactive: Some(true),
start_after: Some(TOKEN_ID - 1),
limit: None,
include_inactive: true,
};
let res: AsksResponse = router
.wrap()
Expand All @@ -685,9 +685,9 @@ fn try_query_asks() {
// test pagination, starting when token don't exist
let query_asks_msg = QueryMsg::Asks {
collection: collection.to_string(),
include_inactive: Some(true),
start_after: Some(TOKEN_ID),
limit: None,
include_inactive: true,
};
let res: AsksResponse = router
.wrap()
Expand Down Expand Up @@ -781,9 +781,9 @@ fn try_query_sorted_asks() {

let query_asks_msg = QueryMsg::AsksSortedByPrice {
collection: collection.to_string(),
include_inactive: Some(true),
start_after: None,
limit: None,
include_inactive: true,
};
let res: AsksResponse = router
.wrap()
Expand All @@ -797,9 +797,9 @@ fn try_query_sorted_asks() {
let start_after = AskOffset::new(res.asks[0].price, res.asks[0].token_id);
let query_msg = QueryMsg::AsksSortedByPrice {
collection: collection.to_string(),
include_inactive: Some(true),
start_after: Some(start_after),
limit: None,
include_inactive: true,
};

let res: AsksResponse = router
Expand All @@ -812,9 +812,9 @@ fn try_query_sorted_asks() {

let reverse_query_asks_msg = QueryMsg::ReverseAsksSortedByPrice {
collection: collection.to_string(),
include_inactive: Some(true),
start_before: None,
limit: None,
include_inactive: true,
};

let res: AsksResponse = router
Expand All @@ -829,9 +829,9 @@ fn try_query_sorted_asks() {
let start_before = AskOffset::new(res.asks[0].price, res.asks[0].token_id);
let reverse_query_asks_start_before_first_desc_msg = QueryMsg::ReverseAsksSortedByPrice {
collection: collection.to_string(),
include_inactive: Some(true),
start_before: Some(start_before),
limit: None,
include_inactive: true,
};

let res: AsksResponse = router
Expand Down Expand Up @@ -954,9 +954,9 @@ fn try_query_asks_by_seller() {
// owner1 should only have 1 token
let query_asks_msg = QueryMsg::AsksBySeller {
seller: owner.to_string(),
include_inactive: Some(true),
start_after: None,
limit: None,
include_inactive: true,
};
let res: AsksResponse = router
.wrap()
Expand All @@ -967,9 +967,9 @@ fn try_query_asks_by_seller() {
// owner2 should have 2 token
let query_asks_msg = QueryMsg::AsksBySeller {
seller: owner2.to_string(),
include_inactive: Some(true),
start_after: None,
limit: None,
include_inactive: true,
};
let res: AsksResponse = router
.wrap()
Expand All @@ -980,12 +980,12 @@ fn try_query_asks_by_seller() {
// owner2 should have 0 tokens when paginated by a non-existing collection
let query_asks_msg = QueryMsg::AsksBySeller {
seller: owner2.to_string(),
include_inactive: Some(true),
start_after: Some(CollectionOffset::new(
"non-existing-collection".to_string(),
TOKEN_ID,
)),
limit: None,
include_inactive: true,
};
let res: AsksResponse = router
.wrap()
Expand All @@ -996,9 +996,9 @@ fn try_query_asks_by_seller() {
// owner2 should have 2 tokens when paginated by a existing collection
let query_asks_msg = QueryMsg::AsksBySeller {
seller: owner2.to_string(),
include_inactive: Some(true),
start_after: Some(CollectionOffset::new(collection.to_string(), 0)),
limit: None,
include_inactive: true,
};
let res: AsksResponse = router
.wrap()
Expand All @@ -1009,9 +1009,9 @@ fn try_query_asks_by_seller() {
// owner2 should have 1 token when paginated by a existing collection starting after a token
let query_asks_msg = QueryMsg::AsksBySeller {
seller: owner2.to_string(),
include_inactive: Some(true),
start_after: Some(CollectionOffset::new(collection.to_string(), TOKEN_ID + 1)),
limit: None,
include_inactive: true,
};
let res: AsksResponse = router
.wrap()
Expand Down Expand Up @@ -2559,7 +2559,7 @@ fn try_ask_with_filter_inactive() {
let mut router = custom_mock_app();

// Setup intial accounts
let (_, _, creator) = setup_accounts(&mut router).unwrap();
let (owner, _, creator) = setup_accounts(&mut router).unwrap();

// Instantiate and configure contracts
let (marketplace, collection) = setup_contracts(&mut router, &creator).unwrap();
Expand All @@ -2582,14 +2582,38 @@ fn try_ask_with_filter_inactive() {
let res = router.execute_contract(creator.clone(), marketplace.clone(), &set_ask, &[]);
assert!(res.is_ok());

// Move forward in time..
setup_block_time(&mut router, 10000000000);
// transfer nft from creator to owner. Creates a stale ask that needs to be updated
transfer(&mut router, &creator, &owner, &collection, TOKEN_ID);

let update_ask_state = ExecuteMsg::SyncAsk {
collection: collection.to_string(),
token_id: TOKEN_ID,
};
let res = router.execute_contract(
Addr::unchecked("operator"),
marketplace.clone(),
&update_ask_state,
&[],
);
assert!(res.is_ok());

let ask_msg = QueryMsg::Asks {
collection: collection.to_string(),
include_inactive: None,
start_after: None,
limit: None,
};
let res: AsksResponse = router
.wrap()
.query_wasm_smart(marketplace.clone(), &ask_msg)
.unwrap();
assert_eq!(res.asks.len(), 0);

let ask_msg = QueryMsg::Asks {
collection: collection.to_string(),
include_inactive: Some(false),
start_after: None,
limit: None,
include_inactive: false,
};
let res: AsksResponse = router
.wrap()
Expand All @@ -2599,9 +2623,9 @@ fn try_ask_with_filter_inactive() {

let ask_msg = QueryMsg::Asks {
collection: collection.to_string(),
include_inactive: Some(true),
start_after: None,
limit: None,
include_inactive: true,
};
let res: AsksResponse = router
.wrap()
Expand Down
Loading

0 comments on commit 815342f

Please sign in to comment.