From 46b3ea3f9d18391aca228a46ede9f4e18ea19ce5 Mon Sep 17 00:00:00 2001 From: Facundo Lerena Date: Wed, 25 Oct 2023 16:54:00 -0300 Subject: [PATCH] Modified tests again for weight to fee contract --- test-cases/weight-to-fee/lib.rs | 53 ++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 7 deletions(-) diff --git a/test-cases/weight-to-fee/lib.rs b/test-cases/weight-to-fee/lib.rs index 5c83aef..d02067e 100644 --- a/test-cases/weight-to-fee/lib.rs +++ b/test-cases/weight-to-fee/lib.rs @@ -26,16 +26,25 @@ mod weight_to_fee { #[cfg(test)] const GAS_AMOUNT: u64 = 42; - #[cfg(test)] - const EXPECTED: u128 = 100; // as seen in integration tests - #[cfg(test)] mod tests { use super::*; #[ink::test] - fn integration_weight_to_fee() { + fn integration_weight_to_fee_value_1() { + // Given + let contract = WeightToFee::new(); + + // When + let fee = contract.weight_to_fee(GAS_AMOUNT); + + // Then + assert_eq!(fee.clone(), 1 * GAS_AMOUNT as u128); + } + + #[ink::test] + fn integration_weight_to_fee_value_100() { // Given let contract = WeightToFee::new(); @@ -43,7 +52,7 @@ mod weight_to_fee { let fee = contract.weight_to_fee(GAS_AMOUNT); // Then - assert_eq!(fee.clone(), EXPECTED * GAS_AMOUNT as u128); + assert_eq!(fee.clone(), 100 * GAS_AMOUNT as u128); } } @@ -55,7 +64,37 @@ mod weight_to_fee { type E2EResult = std::result::Result>; #[ink_e2e::test] - async fn end_to_end_weigth_to_fee(mut client: ink_e2e::Client) -> E2EResult<()> { + async fn end_to_end_weigth_to_fee_1(mut client: ink_e2e::Client) -> E2EResult<()> { + // Given + let constructor = WeightToFeeRef::new(); + + let contract_acc_id = client + .instantiate("weight-to-fee", &ink_e2e::alice(), constructor, 0, None) + .await + .expect("instantiate failed") + .account_id; + + // When + let fee = client + .call( + &ink_e2e::bob(), + build_message::(contract_acc_id) + .call(|contract| contract.weight_to_fee(GAS_AMOUNT)), // calling weight_to_fee with GAS_AMOUNT + 0, + None, + ) + .await + .expect("weight-to-fee failed") + .return_value(); + + // Then + assert_eq!(fee, 1 * GAS_AMOUNT as u128); + + Ok(()) + } + + #[ink_e2e::test] + async fn end_to_end_weigth_to_fee_100(mut client: ink_e2e::Client) -> E2EResult<()> { // Given let constructor = WeightToFeeRef::new(); @@ -79,7 +118,7 @@ mod weight_to_fee { .return_value(); // Then - assert_eq!(fee, EXPECTED * GAS_AMOUNT as u128); + assert_eq!(fee, 100 * GAS_AMOUNT as u128); Ok(()) }