Skip to content

Commit

Permalink
patch e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally committed Oct 23, 2024
1 parent 69a2970 commit 3aa83d0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
8 changes: 5 additions & 3 deletions warehouse/src/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<WarehouseState>) -> Result<()> {
pub async fn load_account_state(pool: &SqlitePool, accounts: &Vec<WarehouseState>) -> Result<i64> {
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<SqliteQueryResult> {
Expand Down
30 changes: 30 additions & 0 deletions warehouse/tests/test_load.rs
Original file line number Diff line number Diff line change
@@ -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?;
Expand All @@ -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(())
}

0 comments on commit 3aa83d0

Please sign in to comment.