Skip to content

Commit

Permalink
Added reset functionality + fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vladbucur1 committed Aug 8, 2024
1 parent 15c2cc8 commit f29280c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion contracts/on-chain-claim/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub trait OnChainClaimContract:

address_info_mapper.update(|address_info| {
address_info.current_streak = 1;
address_info.total_epochs_claimed = 1;
address_info.total_epochs_claimed += 1;
address_info.last_epoch_claimed = current_epoch;

self.new_claim_event(&caller, address_info);
Expand Down
19 changes: 16 additions & 3 deletions contracts/on-chain-claim/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,23 @@ fn check_after_claim() {
assert_eq!(address_info.last_epoch_claimed, 21);
})
.set_state_step(SetStateStep::new().block_epoch(25))
.whitebox_call_check(
&on_chain_claim_whitebox,
ScCallStep::new()
.from(USER1_ADDR)
.to(SC_ADDR)
.no_expect(),
|sc| {
sc.claim();
},
|r| {
r.assert_user_error("missed epoch");
},
)
.whitebox_call(
&on_chain_claim_whitebox,
ScCallStep::new().from(USER1_ADDR),
|sc| sc.claim(),
|sc| sc.reset(),
)
.whitebox_query(&on_chain_claim_whitebox, |sc| {
let address = AddressValue::from(USER1_ADDR).to_address();
Expand Down Expand Up @@ -552,7 +565,7 @@ fn test_best_streak() {
.whitebox_call(
&on_chain_claim_whitebox,
ScCallStep::new().from(USER1_ADDR),
|sc| sc.claim(),
|sc| sc.reset(),
)
.whitebox_query(&on_chain_claim_whitebox, |sc| {
let address = AddressValue::from(USER1_ADDR).to_address();
Expand Down Expand Up @@ -725,7 +738,7 @@ fn on_chain_claim_whitebox() {
.whitebox_call(
&on_chain_claim_whitebox,
ScCallStep::new().from(USER1_ADDR),
|sc| sc.claim(),
|sc| sc.reset(),
)
.whitebox_query(&on_chain_claim_whitebox, |sc| {
let address = AddressValue::from(USER1_ADDR).to_address();
Expand Down

0 comments on commit f29280c

Please sign in to comment.