Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asset_management tests #215

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4a4fd50
Preparing customized vote extrinsic
ndkazu Nov 18, 2022
bb72c60
Add boolean parameter
ndkazu Nov 18, 2022
f49ba5b
Temporary voting extrinsic. Testing needed
ndkazu Nov 18, 2022
78133df
Merge branch 'main' into 126-implement-asset-distributor-pallet-fungi…
ndkazu Nov 18, 2022
2e5254b
Added some comments
ndkazu Nov 18, 2022
57780c6
merge
ndkazu Nov 18, 2022
1500088
merge
ndkazu Nov 18, 2022
ffedcf0
Testing vote...confusinggit add .
ndkazu Nov 18, 2022
1498ff9
Proposal not triggered after vote in tests
ndkazu Nov 19, 2022
4c0ac44
feat: add pallet_utility
cuteolaf Nov 19, 2022
9fa3171
test
ndkazu Nov 19, 2022
2bce40b
tests
ndkazu Nov 19, 2022
cf00ee1
Direct call dispatch works, but the call is not executed by democracy
ndkazu Nov 19, 2022
a115ea7
Fixed asset_management voting, referendum staus is updated with corre…
ndkazu Nov 20, 2022
adb4941
Closed test referendum
ndkazu Nov 20, 2022
2a0ebe1
Added hook to monitor vote status and update results
ndkazu Nov 20, 2022
171ebfe
Tests update
ndkazu Nov 20, 2022
5d8eb3e
Added an event and a few comments to explain the role of some tests
ndkazu Nov 21, 2022
943ea5d
Testing that voting events are correctly emitted
ndkazu Nov 21, 2022
a9c981f
Added more comments and note_preimage check
ndkazu Nov 21, 2022
245feb3
Tests refactoring
ndkazu Nov 21, 2022
92bd713
deposit funds for Virtual_account
ndkazu Nov 22, 2022
c9438b4
Fixed bad_origin error
ndkazu Nov 22, 2022
9a04679
Fixed bad_origin error
ndkazu Nov 22, 2022
4dc06c1
fix
ndkazu Nov 22, 2022
31ffa7c
fixed proposal execution in representative vote session
letodunc Nov 24, 2022
b9ce8ff
Code clean up
ndkazu Nov 24, 2022
bc9e3c8
Added call to demote elected representative & updated testing
ndkazu Nov 24, 2022
46dba2f
Documentation_00
ndkazu Nov 24, 2022
6c2da7f
fix typo
cuteolaf Nov 24, 2022
0aa2954
clippy
ndkazu Nov 24, 2022
51b9b28
Merge branch '126-implement-asset-distributor-pallet-fungible-+-confi…
ndkazu Nov 24, 2022
ab82011
cargo fmt
cuteolaf Nov 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 79 additions & 16 deletions pallets/asset_management/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,83 @@ impl<T: Config> Pallet<T> {
Roles::RepApprovalList::<T>::remove(&who);
Roles::AccountsRolesLog::<T>::insert(&who, Roles::Accounts::REPRESENTATIVE);

Ok(())
}

pub fn create_proposal_hash_and_note(caller: T::AccountId,call:<T as pallet::Config>::Call) -> T::Hash {
let origin = RawOrigin::Signed(caller);
let call_wrap = Box::new(call);
let proposal_hash = T::Hashing::hash_of(&call_wrap);
let proposal_encoded: Vec<u8> = proposal_hash.encode();
match Dem::Pallet::<T>::note_preimage(origin.into(), proposal_encoded.clone()) {
Ok(_) => (),
Err(x) if x == Error::<T>::DuplicatePreimage.into() => (),
Err(x) => panic!("{:?}", x),
}
proposal_hash
}

Ok(())
}

pub fn revoke_representative(who: T::AccountId) -> DispatchResult {
Roles::RepresentativeLog::<T>::mutate(&who, |val| {
let mut val0 = val.clone().unwrap();
val0.activated = false;
*val = Some(val0);
});
Roles::AccountsRolesLog::<T>::remove(&who);

Ok(())
}

pub fn create_proposal_hash_and_note(
caller: T::AccountId,
proposal_call: pallet::Call<T>,
) -> T::Hash {
let origin: <T as frame_system::Config>::Origin = RawOrigin::Signed(caller.clone()).into();
let proposal = Box::new(Self::get_formatted_call(proposal_call.into()));

let call = Call::<T>::execute_call_dispatch { account_id: caller, proposal };
let call_formatted = Self::get_formatted_call(call.into());
let call_dispatch = Box::new(call_formatted);

let proposal_hash = T::Hashing::hash_of(&call_dispatch);
let proposal_encoded: Vec<u8> = call_dispatch.encode();
match Dem::Pallet::<T>::note_preimage(origin, proposal_encoded) {
Ok(_) => (),
Err(x) if x == Error::<T>::DuplicatePreimage.into() => (),
Err(x) => panic!("{:?}", x),
}
proposal_hash
}

pub fn caller_can_vote(caller: &T::AccountId, ownership: Share::Ownership<T>) -> bool {
let owners = ownership.owners;
owners.contains(caller)
}

pub fn balance_to_u128_option(input: <T as Assetss::Config>::Balance) -> Option<u128> {
input.try_into().ok()
}
pub fn u128_to_balance_option(input: u128) -> Option<DemoBalanceOf<T>> {
input.try_into().ok()
}

pub fn get_formatted_call(call: <T as Config>::Call) -> <T as Config>::Call {
call
}

pub fn begin_block(now: T::BlockNumber) -> Weight {
let max_block_weight = Weight::from_ref_time(1000_u64);
if (now % <T as Config>::CheckPeriod::get()).is_zero() {
let indexes = ProposalsIndexes::<T>::iter();
for index in indexes {
//check if the status is Finished
let ref_infos: RefInfos<T> = Dem::Pallet::<T>::referendum_info(index.1).unwrap();
let b = match ref_infos {
pallet_democracy::ReferendumInfo::Finished { approved, end: _ } =>
(1, approved),
_ => (0, false),
};
if b.0 == 1 {
//get the local prop_infos and update vote result if referendum ended
ProposalsLog::<T>::mutate(index.1, |val| {
let mut val0 = val.clone().unwrap();
if b.1 {
val0.vote_result = VoteResult::ACCEPTED
} else {
val0.vote_result = VoteResult::REJECTED
}
*val = Some(val0)
});
}
}
}
max_block_weight
}
}
Loading