Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pgherveou committed Dec 19, 2024
1 parent 24f62b2 commit ee6e7db
Showing 1 changed file with 23 additions and 33 deletions.
56 changes: 23 additions & 33 deletions substrate/frame/revive/src/evm/gas_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,55 +116,45 @@ where
#[cfg(test)]
mod test {
use super::*;
use crate::{tests::Test, Config};

#[test]
fn test_gas_encoding_decoding_works() {
let raw_gas_limit = 111_111_999_999_999u128;
let weight = Weight::from_parts(222_999_999, 333_999_999);
let deposit = 444_999_999u64;

let encoded_gas =
<Test as Config>::EthGasEncoder::encode(raw_gas_limit.into(), weight, deposit);
let encoded_gas = <() as GasEncoder<u64>>::encode(raw_gas_limit.into(), weight, deposit);
assert_eq!(encoded_gas, U256::from(111_112_000_282_929u128));
assert!(encoded_gas > raw_gas_limit.into());

let (decoded_weight, decoded_deposit) =
<Test as Config>::EthGasEncoder::decode(encoded_gas).unwrap();
<() as GasEncoder<u64>>::decode(encoded_gas).unwrap();
assert!(decoded_weight.all_gte(weight));
assert!(weight.mul(2).all_gte(weight));

assert!(decoded_deposit >= deposit);
assert!(deposit * 2 >= decoded_deposit);
}

//#[test]
//fn test_encoding_zero_values_work() {
// let encoded_gas = <Test as Config>::EthGasEncoder::encode(
// Default::default(),
// Default::default(),
// Default::default(),
// );
//
// assert_eq!(encoded_gas, U256::from(1_00_00_00));
//
// let (decoded_weight, decoded_deposit) =
// <Test as Config>::EthGasEncoder::decode(encoded_gas).unwrap();
// assert_eq!(Weight::default(), decoded_weight);
// assert_eq!(0u64, decoded_deposit);
//}
//
//#[test]
//fn test_overflow() {
// assert_eq!(
// None,
// <Test as Config>::EthGasEncoder::decode(65_00u128.into()),
// "Invalid proof size"
// );
// assert_eq!(
// None,
// <Test as Config>::EthGasEncoder::decode(65_00_00u128.into()),
// "Invalid ref_time"
// );
//}
#[test]
fn test_encoding_zero_values_work() {
let encoded_gas = <() as GasEncoder<u64>>::encode(
Default::default(),
Default::default(),
Default::default(),
);

assert_eq!(encoded_gas, U256::from(1_00_00_00));

let (decoded_weight, decoded_deposit) =
<() as GasEncoder<u64>>::decode(encoded_gas).unwrap();
assert_eq!(Weight::default(), decoded_weight);
assert_eq!(0u64, decoded_deposit);
}

#[test]
fn test_overflow() {
assert_eq!(None, <() as GasEncoder<u64>>::decode(65_00u128.into()), "Invalid proof size");
assert_eq!(None, <() as GasEncoder<u64>>::decode(65_00_00u128.into()), "Invalid ref_time");
}
}

0 comments on commit ee6e7db

Please sign in to comment.