From 3aa83d0c0dcef47bddf9ba4a0adc3b35647842ba Mon Sep 17 00:00:00 2001 From: 0o-de-lally <1364012+0o-de-lally@users.noreply.github.com> Date: Wed, 23 Oct 2024 17:12:44 -0400 Subject: [PATCH] patch e2e test --- warehouse/src/load.rs | 8 +++++--- warehouse/tests/test_load.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/warehouse/src/load.rs b/warehouse/src/load.rs index fd892668c..d2f535f6a 100644 --- a/warehouse/src/load.rs +++ b/warehouse/src/load.rs @@ -2,14 +2,16 @@ use crate::table_structs::{WarehouseAccount, WarehouseState}; use anyhow::Result; use sqlx::{sqlite::SqliteQueryResult, SqlitePool}; -pub async fn load_account_state(pool: &SqlitePool, accounts: Vec) -> Result<()> { +pub async fn load_account_state(pool: &SqlitePool, accounts: &Vec) -> Result { + let mut rows = 0; // insert missing accounts for ws in accounts.iter() { - insert_one_account(pool, &ws.account).await?; + let res= insert_one_account(pool, &ws.account).await?; + rows = res.last_insert_rowid(); } // increment the balance changes - Ok(()) + Ok(rows) } pub async fn insert_one_account(pool: &SqlitePool, acc: &WarehouseAccount) -> Result { diff --git a/warehouse/tests/test_load.rs b/warehouse/tests/test_load.rs index d459f07ff..0e0769557 100644 --- a/warehouse/tests/test_load.rs +++ b/warehouse/tests/test_load.rs @@ -1,7 +1,18 @@ +use std::path::PathBuf; + use libra_types::exports::AccountAddress; use libra_warehouse::table_structs::WarehouseAccount; +use libra_warehouse::extract::extract_v5_snapshot; + use sqlx::SqlitePool; +fn v5_state_manifest_fixtures_path() -> PathBuf { + let p = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + let project_root = p.parent().unwrap(); + project_root.join("compatibility/fixtures/v5/state_ver_119757649.17a8/state.manifest") +} + + #[sqlx::test] async fn insert_one_account(pool: SqlitePool) -> anyhow::Result<()> { libra_warehouse::migrate::maybe_init(&pool).await?; @@ -17,3 +28,22 @@ async fn insert_one_account(pool: SqlitePool) -> anyhow::Result<()> { Ok(()) } + + + +#[sqlx::test] + +async fn test_e2e_load_v5_snapshot(pool: SqlitePool) -> anyhow::Result<()> { + libra_warehouse::migrate::maybe_init(&pool).await?; + + let manifest_file = v5_state_manifest_fixtures_path(); + assert!(manifest_file.exists()); + let wa_vec = extract_v5_snapshot(&manifest_file).await?; + // NOTE: the parsing drops 1 blob, which is the 0x1 account, because it would not have the DiemAccount struct on it as a user address would have. + assert!(wa_vec.len() == 17338); + + let res = libra_warehouse::load::load_account_state(&pool, &wa_vec).await?; + + assert!(res == 17338); + Ok(()) +}