-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c90362f
commit 76f1a4d
Showing
2 changed files
with
57 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
energy-integration/common-modules/weekly-rewards-splitting/tests/encode_decode_test.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
multiversx_sc::imports!(); | ||
multiversx_sc::derive_imports!(); | ||
|
||
use common_structs::Week; | ||
use energy_query::Energy; | ||
use multiversx_sc_scenario::{managed_biguint, DebugApi}; | ||
use weekly_rewards_splitting::ClaimProgress; | ||
|
||
#[derive(TypeAbi, TopEncode, Clone, PartialEq, Debug)] | ||
pub struct OldClaimProgress<M: ManagedTypeApi> { | ||
pub energy: Energy<M>, | ||
pub week: Week, | ||
} | ||
|
||
#[test] | ||
fn decode_old_claim_progress_to_new_test() { | ||
DebugApi::dummy(); | ||
|
||
let old_progress = OldClaimProgress { | ||
energy: Energy::new(BigInt::<DebugApi>::zero(), 10, managed_biguint!(20)), | ||
week: 2, | ||
}; | ||
let mut old_progress_encoded = ManagedBuffer::<DebugApi>::new(); | ||
let _ = old_progress.top_encode(&mut old_progress_encoded); | ||
|
||
let new_progress_decoded = ClaimProgress::top_decode(old_progress_encoded).unwrap(); | ||
assert_eq!( | ||
new_progress_decoded, | ||
ClaimProgress { | ||
energy: Energy::new(BigInt::<DebugApi>::zero(), 10, managed_biguint!(20)), | ||
week: 2, | ||
enter_timestamp: 0, | ||
} | ||
); | ||
} | ||
|
||
#[test] | ||
fn encoded_decode_new_progress_test() { | ||
DebugApi::dummy(); | ||
|
||
let new_progress = ClaimProgress { | ||
energy: Energy::new(BigInt::<DebugApi>::zero(), 10, managed_biguint!(20)), | ||
week: 2, | ||
enter_timestamp: 0, | ||
}; | ||
let mut new_progress_encoded = ManagedBuffer::<DebugApi>::new(); | ||
let _ = new_progress.top_encode(&mut new_progress_encoded); | ||
let new_progress_decoded = ClaimProgress::top_decode(new_progress_encoded).unwrap(); | ||
assert_eq!( | ||
new_progress_decoded, | ||
ClaimProgress { | ||
energy: Energy::new(BigInt::<DebugApi>::zero(), 10, managed_biguint!(20)), | ||
week: 2, | ||
enter_timestamp: 0, | ||
} | ||
); | ||
} |