Skip to content

Commit

Permalink
Total issuance assertions (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
AurevoirXavier authored Feb 10, 2023
1 parent 1a63edb commit 6a75a6a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
13 changes: 8 additions & 5 deletions tool/state-processor/src/system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ where
pub fn process_system(&mut self) -> &mut Self {
// System storage items.
// https://github.dev/darwinia-network/substrate/blob/darwinia-v0.12.5/frame/system/src/lib.rs#L545
let solo_account_infos = self.process_solo_account_infos();
let (solo_account_infos, ring_remaining, kton_remaining) =
self.process_solo_account_infos();
let para_account_infos = self.process_para_account_infos();
let (ring_total_issuance_storage, kton_total_issuance_storage) = self.process_balances();
let mut accounts = Map::default();
Expand Down Expand Up @@ -77,12 +78,14 @@ where

log::info!("`ring_total_issuance({ring_total_issuance})`");
log::info!("`ring_total_issuance_storage({ring_total_issuance_storage})`");
assert_eq!(ring_total_issuance - ring_remaining, ring_total_issuance_storage);

log::info!("set `Balances::TotalIssuance`");
self.shell_state.insert_value(b"Balances", b"TotalIssuance", "", ring_total_issuance);

log::info!("`kton_total_issuance({kton_total_issuance})`");
log::info!("`kton_total_issuance_storage({kton_total_issuance_storage})`");
assert_eq!(kton_total_issuance - kton_remaining, kton_total_issuance_storage);

let mut kton_details = AssetDetails {
owner: ROOT,
Expand Down Expand Up @@ -228,7 +231,7 @@ where
self
}

fn process_solo_account_infos(&mut self) -> Map<AccountInfo> {
fn process_solo_account_infos(&mut self) -> (Map<AccountInfo>, Balance, Balance) {
let mut account_infos = <Map<AccountInfo>>::default();
let mut remaining_ring = <Map<u128>>::default();
let mut remaining_kton = <Map<u128>>::default();
Expand Down Expand Up @@ -257,6 +260,8 @@ where
);
}
});
log::info!("total_remaining_ring({total_remaining_ring})");

remaining_kton.into_iter().for_each(|(k, v)| {
if let Some(a) = account_infos.get_mut(&k) {
total_remaining_kton += v;
Expand All @@ -268,11 +273,9 @@ where
);
}
});

log::info!("total_remaining_ring({total_remaining_ring})");
log::info!("total_remaining_kton({total_remaining_kton})");

account_infos
(account_infos, total_remaining_ring, total_remaining_kton)
}

fn process_para_account_infos(&mut self) -> Map<AccountInfo> {
Expand Down
9 changes: 6 additions & 3 deletions tool/state-processor/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,10 @@ fn ring_total_issuance() {
&mut migrated_total_issuance,
);

// FIXME: https://github.com/darwinia-network/darwinia-2.0/issues/244
// assert_eq!(migrated_total_issuance, solo_issuance * GWEI + para_issuance);
assert_eq!(
migrated_total_issuance - 155_223_151_710_u128,
solo_issuance * GWEI + para_issuance
);
});
}

Expand Down Expand Up @@ -347,7 +349,8 @@ fn kton_total_issuance() {
&blake2_128_concat_to_string(KTON_ID.encode()),
&mut details,
);
assert!(details.supply - total_issuance * GWEI < 200 * GWEI);

assert_eq!(details.supply - 4_999_999_999_u128, total_issuance * GWEI);
});
}

Expand Down

0 comments on commit 6a75a6a

Please sign in to comment.