From 9fc8aac10cc8c763f9bf2e20b386a6844134a884 Mon Sep 17 00:00:00 2001 From: 0o-de-lally <1364012+0o-de-lally@users.noreply.github.com> Date: Tue, 21 Nov 2023 03:30:16 +0000 Subject: [PATCH] fix balances export on genesis --- tools/genesis/src/compare.rs | 16 ++++++++-------- tools/genesis/tests/json_to_genesis_audit_all.rs | 6 +++++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/tools/genesis/src/compare.rs b/tools/genesis/src/compare.rs index b3c155533..007397b44 100644 --- a/tools/genesis/src/compare.rs +++ b/tools/genesis/src/compare.rs @@ -135,19 +135,20 @@ pub fn compare_recovery_vec_to_genesis_tx( #[derive(Serialize, Deserialize)] struct JsonDump { - balance: GasCoinStoreResource, + account: AccountAddress, + balance: Option, slow: Option, } /// Compare the balances in a recovery file to the balances in a genesis blob. pub fn export_account_balances( - recovery: &mut [LegacyRecovery], + recovery: &[LegacyRecovery], db_reader: &Arc, output: &Path, ) -> anyhow::Result<()> { let mut list: Vec = vec![]; recovery - .iter_mut() + .iter() .progress_with_style(OLProgress::bar()) .with_message("auditing migration") .for_each(|old| { @@ -155,13 +156,13 @@ pub fn export_account_balances( return; }; - let convert_address = + let account = AccountAddress::from_hex_literal(&old.account.as_ref().unwrap().to_hex_literal()) .expect("could not convert address types"); // Ok now let's compare to what's on chain let db_state_view = db_reader.latest_state_checkpoint_view().unwrap(); - let account_state_view = db_state_view.as_account_with_state_view(&convert_address); + let account_state_view = db_state_view.as_account_with_state_view(&account); let slow = account_state_view .get_move_resource::() @@ -169,10 +170,9 @@ pub fn export_account_balances( let balance = account_state_view .get_move_resource::() - .expect("should have move resource") - .expect("should have a GasCoinStoreResource for balance"); + .expect("should have move resource"); - list.push(JsonDump { balance, slow }); + list.push(JsonDump { account, balance, slow }); }); std::fs::write( diff --git a/tools/genesis/tests/json_to_genesis_audit_all.rs b/tools/genesis/tests/json_to_genesis_audit_all.rs index 75357e160..f6ff6c90d 100644 --- a/tools/genesis/tests/json_to_genesis_audit_all.rs +++ b/tools/genesis/tests/json_to_genesis_audit_all.rs @@ -11,7 +11,6 @@ use libra_types::exports::ChainId; use libra_types::legacy_types::legacy_address::LegacyAddress; use support::{path_utils::json_path, test_vals}; -#[ignore] #[test] // test that a genesis blob created from struct, will actually contain the data fn test_correct_supply_arithmetic_all() { @@ -59,6 +58,11 @@ fn test_correct_supply_arithmetic_all() { // NOTE: in the case of a single account being migrated, that account balance will equal the total supply as set in: SupplySettings. i.e. 10B let (db_rw, _) = genesis_reader::bootstrap_db_reader_from_gen_tx(&gen_tx).unwrap(); + + // test dump balances + compare::export_account_balances(&user_accounts, &db_rw.reader, &json_path().parent().unwrap()).unwrap(); + + // audit match compare::compare_recovery_vec_to_genesis_tx( &mut user_accounts, &db_rw.reader,