Skip to content

Commit 27e284b

Browse files
release: 2.2.0 (#94)
2 parents 507452e + 3d9f28f commit 27e284b

File tree

11 files changed

+87
-8
lines changed

11 files changed

+87
-8
lines changed

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contract/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sweat_jar"
3-
version = "2.1.0"
3+
version = "2.2.0"
44
authors = ["Sweat Economy"]
55
edition = "2021"
66

contract/src/claim/api.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ use sweat_jar_model::{
99
};
1010

1111
use crate::{
12-
common::Timestamp,
12+
common::{
13+
gas_data::{GAS_FOR_AFTER_CLAIM, GAS_FOR_FT_TRANSFER},
14+
Timestamp,
15+
},
1316
event::{emit, ClaimEventItem, EventKind},
17+
internal::assert_gas,
1418
jar::model::Jar,
1519
Contract, ContractExt, JarsStorage,
1620
};
@@ -135,6 +139,11 @@ impl Contract {
135139
now: Timestamp,
136140
) -> PromiseOrValue<ClaimedAmountView> {
137141
use crate::ft_interface::FungibleTokenInterface;
142+
143+
assert_gas(GAS_FOR_FT_TRANSFER.as_gas() * 2 + GAS_FOR_AFTER_CLAIM.as_gas(), || {
144+
format!("claim_interest: number of jars: {}", jars_before_transfer.len())
145+
});
146+
138147
self.ft_contract()
139148
.ft_transfer(account_id, claimed_amount.get_total().0, "claim", &None)
140149
.then(after_claim_call(claimed_amount, jars_before_transfer, event, now))

contract/src/event.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ mod test {
193193
fn test_contract_version() {
194194
let admin = admin();
195195
let context = Context::new(admin);
196-
assert_eq!(context.contract().contract_version(), "sweat_jar-2.1.0");
196+
assert_eq!(context.contract().contract_version(), "sweat_jar-2.2.0");
197197
}
198198

199199
#[test]
@@ -206,7 +206,7 @@ mod test {
206206
.to_json_event_string(),
207207
r#"EVENT_JSON:{
208208
"standard": "sweat_jar",
209-
"version": "2.1.0",
209+
"version": "2.2.0",
210210
"event": "top_up",
211211
"data": {
212212
"id": 10,
@@ -234,7 +234,7 @@ mod test {
234234
.to_json_event_string(),
235235
r#"EVENT_JSON:{
236236
"standard": "sweat_jar",
237-
"version": "2.1.0",
237+
"version": "2.2.0",
238238
"event": "create_jar",
239239
"data": {
240240
"id": 555,

contract/src/jar/api.rs

+13
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,17 @@ impl JarApi for Contract {
191191

192192
result
193193
}
194+
195+
fn unlock_jars_for_account(&mut self, account_id: AccountId) {
196+
self.assert_manager();
197+
198+
let jars = self
199+
.account_jars
200+
.get_mut(&account_id)
201+
.expect("Account doesn't have jars");
202+
203+
for jar in &mut jars.jars {
204+
jar.is_pending_withdraw = false;
205+
}
206+
}
194207
}

contract/src/jar/view.rs

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ impl From<Jar> for JarView {
1313
principal: U128(value.principal),
1414
claimed_balance: U128(value.claimed_balance),
1515
is_penalty_applied: value.is_penalty_applied,
16+
is_pending_withdraw: value.is_pending_withdraw,
1617
}
1718
}
1819
}
@@ -27,6 +28,7 @@ impl From<&Jar> for JarView {
2728
principal: U128(value.principal),
2829
claimed_balance: U128(value.claimed_balance),
2930
is_penalty_applied: value.is_penalty_applied,
31+
is_pending_withdraw: value.is_pending_withdraw,
3032
}
3133
}
3234
}

contract/src/tests.rs

+52
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,58 @@ fn get_interest_after_withdraw() {
388388
assert_eq!(12_000_000, interest.amount.total.0);
389389
}
390390

391+
#[test]
392+
#[should_panic(expected = "Can be performed only by admin")]
393+
fn unlock_not_by_manager() {
394+
let alice = alice();
395+
let admin = admin();
396+
397+
let reference_product = generate_product();
398+
399+
let mut reference_jar = Jar::generate(0, &alice, &reference_product.id).principal(100);
400+
reference_jar.is_pending_withdraw = true;
401+
let jars = &[reference_jar];
402+
403+
let mut context = Context::new(admin).with_products(&[reference_product]).with_jars(jars);
404+
405+
context.switch_account(&alice);
406+
context.contract().unlock_jars_for_account(alice);
407+
}
408+
409+
#[test]
410+
fn unlock_by_manager() {
411+
let alice = alice();
412+
let admin = admin();
413+
414+
let reference_product = generate_product();
415+
416+
let reference_jar_id = 0;
417+
let mut reference_jar = Jar::generate(reference_jar_id, &alice, &reference_product.id).principal(100);
418+
reference_jar.is_pending_withdraw = true;
419+
let jars = &[reference_jar];
420+
421+
let mut context = Context::new(admin.clone())
422+
.with_products(&[reference_product])
423+
.with_jars(jars);
424+
425+
assert!(
426+
context
427+
.contract()
428+
.get_jar(alice.clone(), reference_jar_id.into())
429+
.is_pending_withdraw
430+
);
431+
432+
context.switch_account(&admin);
433+
context.contract().unlock_jars_for_account(alice.clone());
434+
435+
assert!(
436+
!context
437+
.contract()
438+
.get_jar(alice.clone(), reference_jar_id.into())
439+
.is_pending_withdraw
440+
);
441+
}
442+
391443
#[test]
392444
fn test_u32() {
393445
let n = U32(12345678);

model/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sweat-jar-model"
3-
version = "2.1.0"
3+
version = "2.2.0"
44
publish = false
55
edition = "2021"
66

model/src/api.rs

+2
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ pub trait JarApi {
162162
fn restake(&mut self, jar_id: JarIdView) -> JarView;
163163

164164
fn restake_all(&mut self) -> Vec<JarView>;
165+
166+
fn unlock_jars_for_account(&mut self, account_id: AccountId);
165167
}
166168

167169
#[make_integration_version]

model/src/jar.rs

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub struct JarView {
2323
pub principal: U128,
2424
pub claimed_balance: U128,
2525
pub is_penalty_applied: bool,
26+
pub is_pending_withdraw: bool,
2627
}
2728

2829
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]

res/sweat_jar.wasm

2.41 KB
Binary file not shown.

0 commit comments

Comments
 (0)