From 5d7e821d7ab4b31cdd845e9712a011efe5aae3c0 Mon Sep 17 00:00:00 2001 From: salman01zp Date: Thu, 18 Jan 2024 16:18:49 +0530 Subject: [PATCH] make test pass --- precompiles/vesting/src/lib.rs | 10 +++-- precompiles/vesting/src/mock.rs | 65 ++++++++++++++++---------------- precompiles/vesting/src/tests.rs | 19 ++++------ 3 files changed, 47 insertions(+), 47 deletions(-) diff --git a/precompiles/vesting/src/lib.rs b/precompiles/vesting/src/lib.rs index d45e3ec94..0174d5e01 100644 --- a/precompiles/vesting/src/lib.rs +++ b/precompiles/vesting/src/lib.rs @@ -118,7 +118,7 @@ where Runtime::AccountId: From, { #[precompile::public("vest()")] - fn vest(handle: &mut impl PrecompileHandle) -> EvmResult { + fn vest(handle: &mut impl PrecompileHandle) -> EvmResult { handle.record_cost(RuntimeHelper::::db_read_gas_cost())?; // Make the call to vest the `msg.sender` account. @@ -128,7 +128,7 @@ where // Dispatch call (if enough gas). RuntimeHelper::::try_dispatch(handle, Some(origin).into(), call)?; - Ok((0)) + Ok(()) } #[precompile::public("vestOther(bytes32)")] @@ -150,7 +150,11 @@ where #[precompile::public("vestedTransfer(bytes32,uint8)")] #[precompile::public("vested_transfer(bytes32,uint8)")] - fn vested_transfer(handle: &mut impl PrecompileHandle, target: H256, index: u8) -> EvmResult { + fn vested_transfer( + handle: &mut impl PrecompileHandle, + target: H256, + index: u8, + ) -> EvmResult { handle.record_cost(RuntimeHelper::::db_read_gas_cost())?; // First get the vesting schedule of the `msg.sender` diff --git a/precompiles/vesting/src/mock.rs b/precompiles/vesting/src/mock.rs index 43fcfb369..6d638eec5 100644 --- a/precompiles/vesting/src/mock.rs +++ b/precompiles/vesting/src/mock.rs @@ -20,34 +20,29 @@ use super::*; use crate::{VestingPrecompile, VestingPrecompileCall}; use frame_support::{ - construct_runtime, - parameter_types, - traits::{ConstU64, Everything, InstanceFilter, WithdrawReasons, Hooks}, + construct_runtime, parameter_types, + traits::{ConstU64, Everything, Hooks, InstanceFilter, WithdrawReasons}, weights::Weight, }; -use serde::{Serialize, Deserialize}; use frame_system::Account; -use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use pallet_evm::{EnsureAddressNever, EnsureAddressOrigin, SubstrateBlockHashMapping}; -use precompile_utils:: - precompile_set::{ - AddressU64, PrecompileAt, - PrecompileSetBuilder, - } -; +use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; +use precompile_utils::precompile_set::{AddressU64, PrecompileAt, PrecompileSetBuilder}; use scale_info::TypeInfo; -use sp_runtime::{ - curve::PiecewiseLinear, - testing::TestXt, - traits::{self, Extrinsic as ExtrinsicT, IdentifyAccount, - IdentityLookup, Verify, Zero, Identity}, - AccountId32, BuildStorage, Perbill, -}; +use serde::{Deserialize, Serialize}; use sp_core::{ self, sr25519::{self, Public as sr25519Public, Signature}, ConstU32, Get, H160, H256, U256, }; +use sp_runtime::{ + curve::PiecewiseLinear, + testing::TestXt, + traits::{ + self, Extrinsic as ExtrinsicT, IdentifyAccount, Identity, IdentityLookup, Verify, Zero, + }, + AccountId32, BuildStorage, Perbill, +}; use tangle_primitives::WrappedAccountId32; pub type AccountId = <::Signer as IdentifyAccount>::AccountId; pub type Balance = u64; @@ -56,7 +51,7 @@ pub type BlockNumber = u64; type Block = frame_system::mocking::MockBlock; const PRECOMPILE_ADDRESS_BYTES: [u8; 32] = [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, ]; #[derive( @@ -84,8 +79,7 @@ pub enum TestAccount { PrecompileAddress, } -impl Default for TestAccount - { +impl Default for TestAccount { fn default() -> Self { Self::Empty } @@ -338,18 +332,22 @@ impl ExtBuilder { .expect("Frame system builds valid default genesis config"); pallet_balances::GenesisConfig:: { - balances: self.balances + balances: self + .balances .iter() - .chain(vec![ - (TestAccount::Alex.into(), 100_000), - (TestAccount::Bobo.into(), 100_000), - (TestAccount::Charlie.into(), 100_000), - ].iter()) + .chain( + vec![ + (TestAccount::Alex.into(), 100_000), + (TestAccount::Bobo.into(), 100_000), + (TestAccount::Charlie.into(), 100_000), + ] + .iter(), + ) .cloned() - .collect() + .collect(), } - .assimilate_storage(&mut t) - .expect("Pallet balances storage can be assimilated"); + .assimilate_storage(&mut t) + .expect("Pallet balances storage can be assimilated"); pallet_vesting::GenesisConfig:: { vesting: vec![ @@ -361,8 +359,9 @@ impl ExtBuilder { (TestAccount::Bobo.into(), 10, 100, 0), (TestAccount::Charlie.into(), 10, 100, 0), ], - }.assimilate_storage(&mut t) - .expect("Pallet vesting storage can be assimilated"); + } + .assimilate_storage(&mut t) + .expect("Pallet vesting storage can be assimilated"); let mut ext = sp_io::TestExternalities::new(t); ext.execute_with(|| { @@ -384,4 +383,4 @@ pub(crate) fn roll_to(n: BlockNumber) { System::on_initialize(System::block_number()); Balances::on_initialize(System::block_number()); } -} \ No newline at end of file +} diff --git a/precompiles/vesting/src/tests.rs b/precompiles/vesting/src/tests.rs index da92689b7..3447439da 100644 --- a/precompiles/vesting/src/tests.rs +++ b/precompiles/vesting/src/tests.rs @@ -17,13 +17,14 @@ // limitations under the License. use crate::mock::{ - AccountId, ExtBuilder, PCall, PrecompilesValue, Runtime, RuntimeCall, RuntimeEvent, - RuntimeOrigin, TestAccount, System, Balance, roll_to, + roll_to, AccountId, Balance, ExtBuilder, PCall, PrecompilesValue, Runtime, RuntimeCall, + RuntimeEvent, RuntimeOrigin, System, TestAccount, }; use frame_support::{assert_ok, traits::OnFinalize}; -use pallet_evm::{Call as EvmCall, AddressMapping}; +use pallet_evm::{AddressMapping, Call as EvmCall}; use pallet_vesting::{ - Call as VestingCall, Event as VestingEvent, Pallet as VestingPallet, Vesting, VestingInfo, MaxVestingSchedulesGet, + Call as VestingCall, Event as VestingEvent, MaxVestingSchedulesGet, Pallet as VestingPallet, + Vesting, VestingInfo, }; use precompile_utils::{ assert_event_emitted, assert_event_not_emitted, precompile_set::AddressU64, prelude::*, @@ -54,16 +55,12 @@ fn test_unimplemented_selector_reverts() { #[test] fn test_claim_vesting_schedule() { ExtBuilder::default().build().execute_with(|| { - let schedules = Vesting::::get(sp_core::sr25519::Public::from(TestAccount::Alex)).unwrap(); + let schedules = + Vesting::::get(sp_core::sr25519::Public::from(TestAccount::Alex)).unwrap(); assert!(!schedules.is_empty()); roll_to(1000); PrecompilesValue::get() - .prepare_test( - TestAccount::Alex, - H160::from_low_u64_be(6), - PCall::vest {}, - ) + .prepare_test(TestAccount::Alex, H160::from_low_u64_be(1), PCall::vest {}) .execute_returns(()); }); } -