From 76f1a4d955d534ac28328ab8358ad116ee947425 Mon Sep 17 00:00:00 2001 From: Dorin Marian Iancu Date: Wed, 27 Nov 2024 10:38:36 +0200 Subject: [PATCH] move test to separate file --- .../weekly-rewards-splitting/src/lib.rs | 57 ------------------- .../tests/encode_decode_test.rs | 57 +++++++++++++++++++ 2 files changed, 57 insertions(+), 57 deletions(-) create mode 100644 energy-integration/common-modules/weekly-rewards-splitting/tests/encode_decode_test.rs diff --git a/energy-integration/common-modules/weekly-rewards-splitting/src/lib.rs b/energy-integration/common-modules/weekly-rewards-splitting/src/lib.rs index 52c71d4dc..5b6686739 100644 --- a/energy-integration/common-modules/weekly-rewards-splitting/src/lib.rs +++ b/energy-integration/common-modules/weekly-rewards-splitting/src/lib.rs @@ -184,60 +184,3 @@ pub trait WeeklyRewardsSplittingModule: } } } - -#[cfg(test)] -mod tests { - use multiversx_sc_scenario::{managed_biguint, DebugApi}; - - use super::*; - - #[derive(TypeAbi, TopEncode, Clone, PartialEq, Debug)] - pub struct OldClaimProgress { - pub energy: Energy, - pub week: Week, - } - - #[test] - fn decode_old_claim_progress_to_new_test() { - DebugApi::dummy(); - - let old_progress = OldClaimProgress { - energy: Energy::new(BigInt::::zero(), 10, managed_biguint!(20)), - week: 2, - }; - let mut old_progress_encoded = ManagedBuffer::::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::::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::::zero(), 10, managed_biguint!(20)), - week: 2, - enter_timestamp: 0, - }; - let mut new_progress_encoded = ManagedBuffer::::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::::zero(), 10, managed_biguint!(20)), - week: 2, - enter_timestamp: 0, - } - ); - } -} diff --git a/energy-integration/common-modules/weekly-rewards-splitting/tests/encode_decode_test.rs b/energy-integration/common-modules/weekly-rewards-splitting/tests/encode_decode_test.rs new file mode 100644 index 000000000..0d917c71c --- /dev/null +++ b/energy-integration/common-modules/weekly-rewards-splitting/tests/encode_decode_test.rs @@ -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 { + pub energy: Energy, + pub week: Week, +} + +#[test] +fn decode_old_claim_progress_to_new_test() { + DebugApi::dummy(); + + let old_progress = OldClaimProgress { + energy: Energy::new(BigInt::::zero(), 10, managed_biguint!(20)), + week: 2, + }; + let mut old_progress_encoded = ManagedBuffer::::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::::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::::zero(), 10, managed_biguint!(20)), + week: 2, + enter_timestamp: 0, + }; + let mut new_progress_encoded = ManagedBuffer::::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::::zero(), 10, managed_biguint!(20)), + week: 2, + enter_timestamp: 0, + } + ); +}