Skip to content

Commit

Permalink
fix balances export on genesis
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally committed Nov 21, 2023
1 parent 3a81fc5 commit 9fc8aac
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
16 changes: 8 additions & 8 deletions tools/genesis/src/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,44 +135,44 @@ pub fn compare_recovery_vec_to_genesis_tx(

#[derive(Serialize, Deserialize)]
struct JsonDump {
balance: GasCoinStoreResource,
account: AccountAddress,
balance: Option<GasCoinStoreResource>,
slow: Option<SlowWalletBalance>,
}
/// 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<dyn DbReader>,
output: &Path,
) -> anyhow::Result<()> {
let mut list: Vec<JsonDump> = vec![];

recovery
.iter_mut()
.iter()
.progress_with_style(OLProgress::bar())
.with_message("auditing migration")
.for_each(|old| {
if old.account.is_none() {
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::<SlowWalletBalance>()
.expect("should have a slow wallet struct");

let balance = account_state_view
.get_move_resource::<GasCoinStoreResource>()
.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(
Expand Down
6 changes: 5 additions & 1 deletion tools/genesis/tests/json_to_genesis_audit_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 9fc8aac

Please sign in to comment.