Skip to content

Commit be618c1

Browse files
committed
chore: use Timestamps instead of Expiration for reserve
1 parent 3ea52cd commit be618c1

File tree

4 files changed

+32
-32
lines changed

4 files changed

+32
-32
lines changed

contracts/asset/src/execute.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
use cosmwasm_std::{BankMsg, Coin, CustomMsg, Deps, DepsMut, Env, MessageInfo, Response};
1+
use cosmwasm_std::{
2+
BankMsg, Coin, CosmosMsg, CustomMsg, Deps, DepsMut, Env, MessageInfo, Response, StdError,
3+
Timestamp,
4+
};
5+
use cw721::Expiration;
26
use cw721::{state::NftInfo, traits::Cw721State};
37

48
use crate::{
@@ -101,7 +105,7 @@ where
101105
check_can_list(deps.as_ref(), &env, info.sender.as_ref(), &nft_info)?;
102106

103107
if let Some(reserved) = listing.reserved {
104-
if !reserved.reserved_until.is_expired(&env.block) {
108+
if !Expiration::AtTime(reserved.reserved_until).is_expired(&env.block) {
105109
return Err(ContractError::ReservedAsset { id: id.clone() });
106110
}
107111
}
@@ -137,7 +141,7 @@ where
137141
check_can_list(deps.as_ref(), &env, info.sender.as_ref(), &nft_info)?;
138142

139143
if let Some(reserved) = &listing.reserved {
140-
if !reserved.reserved_until.is_expired(&env.block) {
144+
if !Expiration::AtTime(reserved.reserved_until).is_expired(&env.block) {
141145
return Err(ContractError::ReservedAsset { id: id.clone() });
142146
}
143147
}
@@ -348,12 +352,6 @@ where
348352
}
349353
}
350354

351-
#[cfg(test)]
352-
use cosmwasm_std::{CosmosMsg, StdError};
353-
354-
#[cfg(test)]
355-
use cw721::Expiration;
356-
357355
#[cfg(test)]
358356
fn expect_ok<T, E: core::fmt::Debug>(res: Result<T, E>) -> T {
359357
match res {
@@ -901,7 +899,7 @@ fn test_buy() {
901899
price: price.clone(),
902900
reserved: Some(Reserve {
903901
reserver: buyer_addr.clone(),
904-
reserved_until: Expiration::AtHeight(env.block.height + 100),
902+
reserved_until: env.block.time.plus_seconds(600),
905903
}),
906904
marketplace_fee_bps: None,
907905
marketplace_fee_recipient: None,
@@ -953,7 +951,7 @@ fn test_buy() {
953951
price: price.clone(),
954952
reserved: Some(Reserve {
955953
reserver: buyer_addr.clone(),
956-
reserved_until: Expiration::AtHeight(env.block.height + 100),
954+
reserved_until: env.block.time.plus_seconds(600),
957955
}),
958956
marketplace_fee_bps: None,
959957
marketplace_fee_recipient: None,
@@ -1135,7 +1133,7 @@ fn test_delist() {
11351133
seller: seller_addr.clone(),
11361134
price: price.clone(),
11371135
reserved: Some(Reserve {
1138-
reserved_until: Expiration::AtHeight(env.block.height + 100),
1136+
reserved_until: env.block.time.plus_seconds(600),
11391137
reserver: seller_addr.clone(),
11401138
}),
11411139
marketplace_fee_bps: None,
@@ -1184,7 +1182,7 @@ fn test_reserve() {
11841182
// cannot reserve unlisted item
11851183
let reservation = Reserve {
11861184
reserver: buyer_addr.clone(),
1187-
reserved_until: Expiration::AtHeight(env.block.height + 100),
1185+
reserved_until: env.block.time.plus_seconds(600),
11881186
};
11891187
let err = expect_err(reserve::<Empty, Empty>(
11901188
deps.as_mut(),
@@ -1293,7 +1291,7 @@ fn test_unreserve() {
12931291

12941292
let reservation = Reserve {
12951293
reserver: reserver_addr.clone(),
1296-
reserved_until: Expiration::AtHeight(env.block.height + 10),
1294+
reserved_until: env.block.time.plus_seconds(600),
12971295
};
12981296

12991297
expect_ok(AssetConfig::<Empty>::default().listings.save(
@@ -1368,7 +1366,7 @@ fn test_unreserve() {
13681366
price: Coin::new(150 as u128, "uxion"),
13691367
reserved: Some(Reserve {
13701368
reserver: reserver_addr.clone(),
1371-
reserved_until: Expiration::AtHeight(env.block.height + 10),
1369+
reserved_until: env.block.time.plus_seconds(600),
13721370
}),
13731371
marketplace_fee_bps: None,
13741372
marketplace_fee_recipient: None,
@@ -1435,7 +1433,7 @@ fn test_unreserve() {
14351433
price: Coin::new(200 as u128, "uxion"),
14361434
reserved: Some(Reserve {
14371435
reserver: reserver_addr.clone(),
1438-
reserved_until: Expiration::AtHeight(env.block.height + 10),
1436+
reserved_until: env.block.time.plus_seconds(600),
14391437
}),
14401438
marketplace_fee_bps: None,
14411439
marketplace_fee_recipient: None,

contracts/asset/src/plugin.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -794,9 +794,9 @@ pub mod default_plugins {
794794
) -> StdResult<bool> {
795795
if let Some(time_lock) = &ctx.data.time_lock {
796796
if let Some(reservation) = &ctx.data.reservation {
797-
if reservation.reserved_until
798-
> Expiration::AtTime(ctx.env.block.time.plus_seconds(time_lock.as_secs()))
799-
{
797+
if Expiration::AtTime(reservation.reserved_until).gt(&Expiration::AtTime(
798+
ctx.env.block.time.plus_seconds(time_lock.as_secs()),
799+
)) {
800800
return Err(cosmwasm_std::StdError::generic_err(format!(
801801
"Reservation end time {} exceeds the collection time lock {}",
802802
reservation.reserved_until,

contracts/asset/src/state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use cosmwasm_schema::cw_serde;
2-
use cosmwasm_std::{Addr, Coin};
2+
use cosmwasm_std::{Addr, Coin, Timestamp};
33
use cw_storage_plus::{IndexList, IndexedMap, Item, Map, MultiIndex};
44
use cw721::{Expiration, state::Cw721Config, traits::Cw721State};
55

@@ -18,7 +18,7 @@ pub struct ListingInfo {
1818
#[cw_serde]
1919
pub struct Reserve {
2020
pub reserver: Addr,
21-
pub reserved_until: Expiration,
21+
pub reserved_until: Timestamp,
2222
}
2323

2424
pub struct AssetConfig<'a, TNftExtension>

contracts/asset/src/test.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@ mod plugins_test {
129129
let deps = mock_dependencies();
130130
let env = env_at(1_000);
131131
let info = message_info(&deps.api.addr_make("marketplace"), &[]);
132-
let mut ctx = build_ctx(deps.as_ref(), env, info);
132+
let mut ctx = build_ctx(deps.as_ref(), env.clone(), info);
133133
ctx.data.time_lock = Some(Duration::from_secs(2_000));
134134
ctx.data.reservation = Some(Reserve {
135135
reserver: Addr::unchecked("reserver"),
136-
reserved_until: Expiration::AtTime(Timestamp::from_seconds(1_500)),
136+
reserved_until: env.block.time.plus_seconds(600),
137137
});
138138

139139
assert!(default_plugins::time_lock_plugin(&mut ctx).is_ok());
@@ -144,11 +144,13 @@ mod plugins_test {
144144
let deps = mock_dependencies();
145145
let env = env_at(1_000);
146146
let info = message_info(&deps.api.addr_make("marketplace"), &[]);
147-
let mut ctx = build_ctx(deps.as_ref(), env, info);
148-
ctx.data.time_lock = Some(Duration::from_secs(2_000));
147+
let mut ctx = build_ctx(deps.as_ref(), env.clone(), info);
148+
ctx.data.time_lock = Some(Duration::from_secs(
149+
env.block.time.plus_seconds(2_000).seconds(),
150+
));
149151
ctx.data.reservation = Some(Reserve {
150152
reserver: Addr::unchecked("reserver"),
151-
reserved_until: Expiration::AtTime(Timestamp::from_seconds(3_500)),
153+
reserved_until: env.block.time.plus_seconds(6000),
152154
});
153155

154156
assert!(default_plugins::time_lock_plugin(&mut ctx).is_err());
@@ -728,10 +730,10 @@ mod asset_pluggable_tests {
728730

729731
let env = env_at(1_000);
730732
let info = message_info(&reserver, &[]);
731-
let mut ctx = build_ctx(deps.as_ref(), env, info);
733+
let mut ctx = build_ctx(deps.as_ref(), env.clone(), info);
732734
let reservation = Reserve {
733735
reserver: reserver.clone(),
734-
reserved_until: Expiration::AtTime(Timestamp::from_seconds(1_500)),
736+
reserved_until: env.block.time.plus_seconds(1_500),
735737
};
736738

737739
let result = contract
@@ -765,10 +767,10 @@ mod asset_pluggable_tests {
765767

766768
let env = env_at(1_000);
767769
let info = message_info(&reserver, &[]);
768-
let mut ctx = build_ctx(deps.as_ref(), env, info);
770+
let mut ctx = build_ctx(deps.as_ref(), env.clone(), info);
769771
let reservation = Reserve {
770772
reserver: reserver.clone(),
771-
reserved_until: Expiration::AtTime(Timestamp::from_seconds(1_200)),
773+
reserved_until: env.block.time.plus_seconds(1_200),
772774
};
773775

774776
let result = contract.on_reserve_plugin(&"token-1".to_string(), &reservation, &mut ctx);
@@ -814,10 +816,10 @@ mod asset_pluggable_tests {
814816

815817
let env = env_at(1_000);
816818
let info = message_info(&reserver, &[]);
817-
let mut ctx = build_ctx(deps.as_ref(), env, info);
819+
let mut ctx = build_ctx(deps.as_ref(), env.clone(), info);
818820
let reservation = Reserve {
819821
reserver: reserver.clone(),
820-
reserved_until: Expiration::AtTime(Timestamp::from_seconds(3_000)),
822+
reserved_until: env.block.time.plus_seconds(3_000),
821823
};
822824

823825
let result = contract.on_reserve_plugin(&"token-1".to_string(), &reservation, &mut ctx);

0 commit comments

Comments
 (0)