diff --git a/warehouse/src/load_account.rs b/warehouse/src/load_account.rs index 44e738d05..c0654ae5f 100644 --- a/warehouse/src/load_account.rs +++ b/warehouse/src/load_account.rs @@ -24,7 +24,7 @@ pub async fn insert_one_account( VALUES ($1,$2) "#, ) - .bind(acc.address.to_string()) + .bind(acc.address.to_hex_literal()) .bind(true) .execute(pool) .await?; diff --git a/warehouse/src/load_coin.rs b/warehouse/src/load_coin.rs index 12ed8ba82..6d544c5c9 100644 --- a/warehouse/src/load_coin.rs +++ b/warehouse/src/load_coin.rs @@ -30,8 +30,8 @@ pub async fn impl_batch_coin_insert(pool: &SqlitePool, batch_accounts: &[Warehou ); query_builder.push_values(filtered, |mut b, acc| { - b.push_bind(acc.account.address.to_hex_literal()).push_bind(true) - .push_bind(acc.balance.as_ref().unwrap().legacy_balance.unwrap() as i64).push_bind(true) + b.push_bind(acc.account.address.to_hex_literal()) + .push_bind(acc.balance.as_ref().unwrap().legacy_balance.unwrap() as i64) .push_bind(0) // todo .push_bind(0) // todo .push_bind(0); // todo diff --git a/warehouse/tests/test_load.rs b/warehouse/tests/test_load.rs index d80ec7aa4..130f12898 100644 --- a/warehouse/tests/test_load.rs +++ b/warehouse/tests/test_load.rs @@ -1,8 +1,8 @@ use std::path::PathBuf; use libra_types::exports::AccountAddress; -use libra_warehouse::table_structs::WarehouseAccount; use libra_warehouse::extract::extract_v5_snapshot; +use libra_warehouse::table_structs::{WarehouseAccount, WarehouseBalance, WarehouseState}; use sqlx::SqlitePool; @@ -12,62 +12,61 @@ fn v5_state_manifest_fixtures_path() -> PathBuf { 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?; let marlon = AccountAddress::random(); - let acc = WarehouseAccount { - address: marlon - }; + let acc = WarehouseAccount { address: marlon }; libra_warehouse::load_account::insert_one_account(&pool, &acc).await?; // second time should error if we are using the same account - assert!(libra_warehouse::load_account::insert_one_account(&pool, &acc).await.is_err()); + assert!( + libra_warehouse::load_account::insert_one_account(&pool, &acc) + .await + .is_err() + ); Ok(()) } #[sqlx::test] -async fn batch_insert(pool: SqlitePool) -> anyhow::Result<()>{ - libra_warehouse::migrate::maybe_init(&pool).await?; +async fn batch_insert_account(pool: SqlitePool) -> anyhow::Result<()> { + libra_warehouse::migrate::maybe_init(&pool).await?; let mut vec_acct: Vec = vec![]; for _i in [..3] { - let acc = WarehouseAccount { - // uniques - address: AccountAddress::random() - }; - vec_acct.push(acc); + let acc = WarehouseAccount { + // uniques + address: AccountAddress::random(), + }; + vec_acct.push(acc); } - libra_warehouse::load_account::impl_batch_insert(&pool, &vec_acct).await?; - Ok(()) + libra_warehouse::load_account::impl_batch_insert(&pool, &vec_acct).await?; + Ok(()) } #[sqlx::test] -async fn batch_duplicates_fail_gracefully(pool: SqlitePool) -> anyhow::Result<()>{ - libra_warehouse::migrate::maybe_init(&pool).await?; +async fn batch_duplicates_fail_gracefully(pool: SqlitePool) -> anyhow::Result<()> { + libra_warehouse::migrate::maybe_init(&pool).await?; let mut vec_acct: Vec = vec![]; // will create duplicates let marlon = AccountAddress::random(); for _i in [..3] { - let acc = WarehouseAccount { - address: marlon - }; - vec_acct.push(acc); + let acc = WarehouseAccount { address: marlon }; + vec_acct.push(acc); } - // should not fail if duplicates exists on same batch - libra_warehouse::load_account::impl_batch_insert(&pool, &vec_acct).await?; + // should not fail if duplicates exists on same batch + libra_warehouse::load_account::impl_batch_insert(&pool, &vec_acct).await?; - // also should not fail if duplicates are on separate batches - libra_warehouse::load_account::impl_batch_insert(&pool, &vec_acct).await?; + // also should not fail if duplicates are on separate batches + libra_warehouse::load_account::impl_batch_insert(&pool, &vec_acct).await?; - Ok(()) + Ok(()) } #[sqlx::test] @@ -86,3 +85,31 @@ async fn test_e2e_load_v5_snapshot(pool: SqlitePool) -> anyhow::Result<()> { assert!(res == 17338); Ok(()) } + +#[sqlx::test] +async fn batch_insert_coin(pool: SqlitePool) -> anyhow::Result<()> { + libra_warehouse::migrate::maybe_init(&pool).await?; + let mut vec_state: Vec = vec![]; + + for _i in [..3] { + let state = WarehouseState { + account: WarehouseAccount { + // uniques + address: AccountAddress::random(), + }, + balance: Some(WarehouseBalance { + balance: 0, + legacy_balance: Some(10), + }), + }; + + vec_state.push(state); + } + + // fist must load accounts + let _res = libra_warehouse::load_account::load_account_state(&pool, &vec_state).await?; + + libra_warehouse::load_coin::impl_batch_coin_insert(&pool, &vec_state).await?; + + Ok(()) +}