Skip to content

Commit

Permalink
tests update
Browse files Browse the repository at this point in the history
  • Loading branch information
psorinionut committed Oct 16, 2023
1 parent ca1d47d commit 7c39063
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
6 changes: 3 additions & 3 deletions contracts/mystery-box/tests/mystery_box_setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ where
EgldOrEsdtTokenIdentifier::egld(),
managed_biguint!(10_000),
managed_buffer!(b"ExperiencePoints"),
5_000u64,
3_000u64,
CooldownType::None,
0,
0,
Expand Down Expand Up @@ -117,9 +117,9 @@ where
EgldOrEsdtTokenIdentifier::egld(),
managed_biguint!(10u64),
managed_buffer!(b"FixedValue"),
2_400u64,
4_400u64,
CooldownType::ResetOnCooldown,
5,
2,
2,
)
.into();
Expand Down
16 changes: 9 additions & 7 deletions contracts/mystery-box/tests/mystery_box_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,24 @@ fn test_open_multiple_mystery_box() {
let mut mb_setup = MysteryBoxSetup::new(mystery_box::contract_obj);

mb_setup.b_mock.set_block_epoch(1);
let mb_token_nonce = mb_setup.create_mystery_box(3);
let mb_token_nonce = mb_setup.create_mystery_box(4);

// We need to change the block random seed to properly test the RandomnessSource functionality
mb_setup.b_mock.set_block_epoch(2);
// We change the block random seed to properly test the RandomnessSource functionality
mb_setup.b_mock.set_block_epoch(3);
mb_setup.b_mock.set_block_random_seed(Box::from([2u8; 48]));
mb_setup.open_mystery_box(mb_token_nonce);

// We're still in epoch 2
// The first chosen reward (ExperiencePoints) is on global cooldown,
// So a MysteryBox reward is chosen next (which has no cooldown)
// The user receives directly a new MysteryBox, with a different nonce (new epoch)
// Change the block random seed
mb_setup.b_mock.set_block_random_seed(Box::from([3u8; 48]));
mb_setup.open_mystery_box(mb_token_nonce);

// Keep the block random seed the same for 3 mystery boxes
// This should select the same reward, which allows 2 wins per cooldown
mb_setup.b_mock.set_block_epoch(4);
mb_setup.b_mock.set_block_random_seed(Box::from([4u8; 48]));
mb_setup.open_mystery_box(mb_token_nonce);
mb_setup.open_mystery_box(mb_token_nonce);

// Now a new prize is selected, as the initial one is on cooldown
mb_setup.open_mystery_box(mb_token_nonce);
}

0 comments on commit 7c39063

Please sign in to comment.