Skip to content

Commit

Permalink
State process test (#153)
Browse files Browse the repository at this point in the history
* First commit

* Add balance test

* Try fix

* test total_issuance

* Test the kton part removed

* Add evm related test

* Assert evm account storages

* Update evm storage tests

* Add vesting info test

* Add indices test

* Add staking test

* Add staking test 2

* Fix tests

* Add deposit items test

* Finish staking test

* Add tests for assets

* Test kton transfer to asset pallet

* Test kton total issuance

* Fix todo

* Add parachain support

* Remove ignored case

* Add combine solo,para account tests

* Code clean

* Add filter

* Refactor the test

* Ignore two cases

* Rwrite all tests

* Update evm codes test

* Code format

* Fix indices tests

* Remove debug line

* Format

* Format

* Fix review

Co-authored-by: Xavier Lau <xavier@inv.cafe>
  • Loading branch information
boundless-forest and AurevoirXavier authored Jan 3, 2023
1 parent 60766d0 commit d21847e
Show file tree
Hide file tree
Showing 4 changed files with 714 additions and 13 deletions.
17 changes: 10 additions & 7 deletions tool/state-processor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ use adjust::*;
mod type_registry;
use type_registry::*;

#[cfg(test)]
mod tests;

// std
use std::{
env,
Expand Down Expand Up @@ -85,7 +88,7 @@ impl Processor {
}
}

struct State(Map<String>);
pub struct State(Map<String>);
impl State {
fn from_file(path: &str) -> Result<Self> {
Ok(Self(from_file::<ChainSpec>(path)?.genesis.raw.top))
Expand Down Expand Up @@ -277,18 +280,18 @@ impl State {

// fn transfer(&mut self, from: &str, to: &str, amount: u128) {}

fn unreserve<A>(&mut self, who: A, amount: u128)
fn unreserve<A>(&mut self, account_id_32: A, amount: u128)
where
A: AsRef<[u8]>,
{
let who = who.as_ref();
let (p, i) = if is_evm_address(who) {
(&b"System"[..], &b"Account"[..])
let account_id_32 = account_id_32.as_ref();
let (p, i, h) = if is_evm_address(account_id_32) {
(&b"System"[..], &b"Account"[..], &account_id_32[11..31])
} else {
(&b"AccountMigration"[..], &b"Accounts"[..])
(&b"AccountMigration"[..], &b"Accounts"[..], account_id_32)
};

self.mutate_value(p, i, &blake2_128_concat_to_string(who), |a: &mut AccountInfo| {
self.mutate_value(p, i, &blake2_128_concat_to_string(h), |a: &mut AccountInfo| {
a.data.free += amount;
a.data.reserved -= amount;
});
Expand Down
9 changes: 8 additions & 1 deletion tool/state-processor/src/system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,12 @@ impl Processor {
account_infos.iter_mut().for_each(|(_, v)| v.data.adjust());

log::info!("merge solo remaining balances");
let (mut total_remaining_ring, mut total_remaining_kton) =
(u128::default(), u128::default());

remaining_ring.into_iter().for_each(|(k, v)| {
if let Some(a) = account_infos.get_mut(&k) {
total_remaining_ring += v;
a.data.free += v;
} else {
log::error!(
Expand All @@ -223,14 +227,17 @@ impl Processor {
});
remaining_kton.into_iter().for_each(|(k, v)| {
if let Some(a) = account_infos.get_mut(&k) {
total_remaining_kton += v;
a.data.free_kton_or_misc_frozen += v;
} else {
log::error!(
"`Account({})` not found while merging `RemainingKtonBalance`",
get_last_64(&k)
get_last_64(&k),
);
}
});
log::info!("total_remaining_ring({total_remaining_ring})");
log::info!("total_remaining_kton({total_remaining_kton})");

account_infos
}
Expand Down
Loading

0 comments on commit d21847e

Please sign in to comment.