Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rashad Alston authored and Rashad Alston committed May 24, 2023
1 parent a9a9228 commit d987efd
Showing 1 changed file with 37 additions and 33 deletions.
70 changes: 37 additions & 33 deletions packages/fuel-indexer-tests/tests/e2e/indexing_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async fn test_can_trigger_and_index_events_with_multiple_args_in_index_handler_p

let mut conn = test_db.pool.acquire().await.unwrap();
let block_row = sqlx::query(
"SELECT * FROM fuel_indexer_test_index1.block ORDER BY height DESC LIMIT 1",
"SELECT * FROM fuel_indexer_test_index1.blockentity ORDER BY height DESC LIMIT 1",
)
.fetch_one(&mut conn)
.await
Expand Down Expand Up @@ -166,7 +166,7 @@ async fn test_can_trigger_and_index_blocks_and_transactions_postgres() {

let mut conn = test_db.pool.acquire().await.unwrap();
let row = sqlx::query(
"SELECT * FROM fuel_indexer_test_index1.block ORDER BY timestamp DESC LIMIT 1",
"SELECT * FROM fuel_indexer_test_index1.blockentity ORDER BY timestamp DESC LIMIT 1",
)
.fetch_one(&mut conn)
.await
Expand All @@ -182,7 +182,7 @@ async fn test_can_trigger_and_index_blocks_and_transactions_postgres() {
assert!(timestamp > 0);

let row = sqlx::query(&format!(
"SELECT * FROM fuel_indexer_test_index1.tx WHERE block = {id}",
"SELECT * FROM fuel_indexer_test_index1.txentity WHERE block = {id}",
))
.fetch_all(&mut conn)
.await
Expand Down Expand Up @@ -255,10 +255,11 @@ async fn test_can_trigger_and_index_transfer_event_postgres() {
node_handle.abort();

let mut conn = test_db.pool.acquire().await.unwrap();
let row = sqlx::query("SELECT * FROM fuel_indexer_test_index1.transfer LIMIT 1")
.fetch_one(&mut conn)
.await
.unwrap();
let row =
sqlx::query("SELECT * FROM fuel_indexer_test_index1.transferentity LIMIT 1")
.fetch_one(&mut conn)
.await
.unwrap();

assert_eq!(row.get::<BigDecimal, usize>(3).to_u64().unwrap(), 1); // value is defined in test contract
assert_eq!(row.get::<&str, usize>(4), defaults::TRANSFER_BASE_ASSET_ID);
Expand All @@ -284,7 +285,7 @@ async fn test_can_trigger_and_index_log_event_postgres() {

let mut conn = test_db.pool.acquire().await.unwrap();
let row = sqlx::query(
"SELECT * FROM fuel_indexer_test_index1.log WHERE ra = 8675309 LIMIT 1",
"SELECT * FROM fuel_indexer_test_index1.logentity WHERE ra = 8675309 LIMIT 1",
)
.fetch_one(&mut conn)
.await
Expand Down Expand Up @@ -348,10 +349,11 @@ async fn test_can_trigger_and_index_scriptresult_event_postgres() {
node_handle.abort();

let mut conn = test_db.pool.acquire().await.unwrap();
let row = sqlx::query("SELECT * FROM fuel_indexer_test_index1.scriptresult LIMIT 1")
.fetch_one(&mut conn)
.await
.unwrap();
let row =
sqlx::query("SELECT * FROM fuel_indexer_test_index1.scriptresultentity LIMIT 1")
.fetch_one(&mut conn)
.await
.unwrap();

let expected = hex::decode(row.get::<String, usize>(3))
.unwrap()
Expand Down Expand Up @@ -384,10 +386,11 @@ async fn test_can_trigger_and_index_transferout_event_postgres() {
node_handle.abort();

let mut conn = test_db.pool.acquire().await.unwrap();
let row = sqlx::query("SELECT * FROM fuel_indexer_test_index1.transferout LIMIT 1")
.fetch_one(&mut conn)
.await
.unwrap();
let row =
sqlx::query("SELECT * FROM fuel_indexer_test_index1.transferoutentity LIMIT 1")
.fetch_one(&mut conn)
.await
.unwrap();

assert_eq!(
row.get::<&str, usize>(2),
Expand Down Expand Up @@ -416,10 +419,11 @@ async fn test_can_trigger_and_index_messageout_event_postgres() {
node_handle.abort();

let mut conn = test_db.pool.acquire().await.unwrap();
let row = sqlx::query("SELECT * FROM fuel_indexer_test_index1.messageout LIMIT 1")
.fetch_one(&mut conn)
.await
.unwrap();
let row =
sqlx::query("SELECT * FROM fuel_indexer_test_index1.messageoutentity LIMIT 1")
.fetch_one(&mut conn)
.await
.unwrap();

let recipient = row.get::<&str, usize>(3);
let amount = row.get::<BigDecimal, usize>(4).to_u64().unwrap();
Expand Down Expand Up @@ -480,7 +484,7 @@ async fn test_can_index_event_with_optional_fields_postgres() {

#[actix_web::test]
#[cfg(all(feature = "e2e", feature = "postgres"))]
async fn test_index_metadata_is_saved_when_indexer_macro_is_called_postgres() {
async fn test_can_index_metadata_is_saved_when_indexer_macro_is_called_postgres() {
let (node_handle, test_db, mut srvc) = setup_test_components().await;

let mut manifest = Manifest::try_from(assets::FUEL_INDEXER_TEST_MANIFEST).unwrap();
Expand Down Expand Up @@ -509,7 +513,7 @@ async fn test_index_metadata_is_saved_when_indexer_macro_is_called_postgres() {

#[actix_web::test]
#[cfg(all(feature = "e2e", feature = "postgres"))]
async fn test_index_respects_start_block_postgres() {
async fn test_indexer_respects_start_block_postgres() {
let (node_handle, test_db, mut srvc) = setup_test_components().await;

let contract = connect_to_deployed_contract().await.unwrap();
Expand All @@ -529,7 +533,7 @@ async fn test_index_respects_start_block_postgres() {

let mut conn = test_db.pool.acquire().await.unwrap();
let pre_check = sqlx::query(&format!(
"SELECT * FROM fuel_indexer_test_index1.block where height = {}",
"SELECT * FROM fuel_indexer_test_index1.blockentity where height = {}",
block_height + 1,
))
.fetch_optional(&mut conn)
Expand All @@ -544,7 +548,7 @@ async fn test_index_respects_start_block_postgres() {
sleep(Duration::from_secs(defaults::INDEXED_EVENT_WAIT)).await;

let first_check = sqlx::query(&format!(
"SELECT * FROM fuel_indexer_test_index1.block where height = {}",
"SELECT * FROM fuel_indexer_test_index1.blockentity where height = {}",
block_height + 1,
))
.fetch_optional(&mut conn)
Expand All @@ -560,7 +564,7 @@ async fn test_index_respects_start_block_postgres() {
node_handle.abort();

let final_check = sqlx::query(&format!(
"SELECT * FROM fuel_indexer_test_index1.block where height = {}",
"SELECT * FROM fuel_indexer_test_index1.blockentity where height = {}",
block_height + 2,
))
.fetch_optional(&mut conn)
Expand All @@ -578,7 +582,7 @@ async fn test_index_respects_start_block_postgres() {

#[actix_web::test]
#[cfg(all(feature = "e2e", feature = "postgres"))]
async fn test_index_respects_end_block_postgres() {
async fn test_indexer_respects_end_block_postgres() {
let (node_handle, test_db, mut srvc) = setup_test_components().await;

let contract = connect_to_deployed_contract().await.unwrap();
Expand All @@ -603,7 +607,7 @@ async fn test_index_respects_end_block_postgres() {

let mut conn = test_db.pool.acquire().await.unwrap();
let first_check = sqlx::query(&format!(
"SELECT * FROM fuel_indexer_test_index1.block where height = {}",
"SELECT * FROM fuel_indexer_test_index1.blockentity where height = {}",
block_height,
))
.fetch_optional(&mut conn)
Expand All @@ -623,7 +627,7 @@ async fn test_index_respects_end_block_postgres() {
node_handle.abort();

let second_check = sqlx::query(&format!(
"SELECT * FROM fuel_indexer_test_index1.block where height = {}",
"SELECT * FROM fuel_indexer_test_index1.blockentity where height = {}",
block_height + 1,
))
.fetch_optional(&mut conn)
Expand All @@ -643,7 +647,7 @@ async fn test_index_respects_end_block_postgres() {
node_handle.abort();

let final_check = sqlx::query(&format!(
"SELECT * FROM fuel_indexer_test_index1.block where height = {}",
"SELECT * FROM fuel_indexer_test_index1.blockentity where height = {}",
block_height + 2,
))
.fetch_optional(&mut conn)
Expand Down Expand Up @@ -679,7 +683,7 @@ async fn test_index_respects_end_block_and_start_block_postgres() {

// Check block before start block is not indexed
let pre_check = sqlx::query(&format!(
"SELECT * FROM fuel_indexer_test_index1.block where height = {}",
"SELECT * FROM fuel_indexer_test_index1.blockentity where height = {}",
block_height,
))
.fetch_optional(&mut conn)
Expand All @@ -695,7 +699,7 @@ async fn test_index_respects_end_block_and_start_block_postgres() {
sleep(Duration::from_secs(defaults::INDEXED_EVENT_WAIT)).await;

let start_block_check = sqlx::query(&format!(
"SELECT * FROM fuel_indexer_test_index1.block where height = {}",
"SELECT * FROM fuel_indexer_test_index1.blockentity where height = {}",
block_height + 1,
))
.fetch_optional(&mut conn)
Expand All @@ -711,7 +715,7 @@ async fn test_index_respects_end_block_and_start_block_postgres() {
sleep(Duration::from_secs(defaults::INDEXED_EVENT_WAIT)).await;

let end_block_check = sqlx::query(&format!(
"SELECT * FROM fuel_indexer_test_index1.block where height = {}",
"SELECT * FROM fuel_indexer_test_index1.blockentity where height = {}",
block_height + 2,
))
.fetch_optional(&mut conn)
Expand All @@ -722,7 +726,7 @@ async fn test_index_respects_end_block_and_start_block_postgres() {

// Check block after end block is not indexed
let post_check = sqlx::query(&format!(
"SELECT * FROM fuel_indexer_test_index1.block where height = {}",
"SELECT * FROM fuel_indexer_test_index1.blockentity where height = {}",
block_height + 3,
))
.fetch_optional(&mut conn)
Expand Down

0 comments on commit d987efd

Please sign in to comment.