Skip to content

Commit

Permalink
Merge pull request #27 from Jurshsmith/fix-contract-state-delete-test
Browse files Browse the repository at this point in the history
Fix contract state delete test in CI
  • Loading branch information
Jurshsmith authored Oct 17, 2023
2 parents 97541c2 + d1d6bac commit ea39400
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
2 changes: 1 addition & 1 deletion chaindexing-tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod db;
pub mod factory;
pub mod test_runner;
mod tests;
pub mod tests;
4 changes: 3 additions & 1 deletion chaindexing-tests/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use chaindexing::{Chaindexing, ChaindexingRepo, HasRawQueryClient, Repo};
use chaindexing_tests::db;
use chaindexing_tests::{db, tests};

#[tokio::main]
async fn main() {
db::setup();
let repo = ChaindexingRepo::new(db::database_url().as_str());
let raw_query_client = repo.get_raw_query_client().await;
Chaindexing::run_internal_migrations(&raw_query_client).await;

tests::setup().await;
}
4 changes: 4 additions & 0 deletions chaindexing-tests/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
mod contract_states;
mod events_ingester;

pub async fn setup() {
contract_states::setup().await;
}
30 changes: 10 additions & 20 deletions chaindexing-tests/src/tests/contract_states.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(test)]
mod tests {
use chaindexing::{Chaindexing, ChaindexingRepo, EventContext, HasRawQueryClient};
use chaindexing::{ChaindexingRepo, EventContext, HasRawQueryClient};

use super::*;
use crate::factory::{bayc_contract, transfer_event_with_contract};
Expand All @@ -9,13 +9,7 @@ mod tests {
#[tokio::test]
pub async fn creates_state() {
let bayc_contract = bayc_contract().add_state_migrations(NftStateMigrations);

let mut raw_query_client = test_runner::new_repo().get_raw_query_client().await;
Chaindexing::run_migrations_for_contract_states(
&raw_query_client,
&vec![bayc_contract.clone()],
)
.await;
let raw_query_txn_client =
ChaindexingRepo::get_raw_query_txn_client(&mut raw_query_client).await;
let event_context = EventContext::new(
Expand All @@ -40,13 +34,7 @@ mod tests {
#[tokio::test]
pub async fn updates_state() {
let bayc_contract = bayc_contract().add_state_migrations(NftStateMigrations);

let mut raw_query_client = test_runner::new_repo().get_raw_query_client().await;
Chaindexing::run_migrations_for_contract_states(
&raw_query_client,
&vec![bayc_contract.clone()],
)
.await;
let raw_query_txn_client =
ChaindexingRepo::get_raw_query_txn_client(&mut raw_query_client).await;
let event_context = EventContext::new(
Expand Down Expand Up @@ -77,13 +65,7 @@ mod tests {
#[tokio::test]
pub async fn deletes_state() {
let bayc_contract = bayc_contract().add_state_migrations(NftStateMigrations);

let mut raw_query_client = test_runner::new_repo().get_raw_query_client().await;
Chaindexing::run_migrations_for_contract_states(
&raw_query_client,
&vec![bayc_contract.clone()],
)
.await;
let raw_query_txn_client =
ChaindexingRepo::get_raw_query_txn_client(&mut raw_query_client).await;
let event_context = EventContext::new(
Expand All @@ -104,9 +86,11 @@ mod tests {
}
}

use chaindexing::{ContractState, ContractStateMigrations};
use chaindexing::{Chaindexing, ContractState, ContractStateMigrations, HasRawQueryClient};
use serde::{Deserialize, Serialize};

use crate::{factory::bayc_contract, test_runner};

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
struct NftState {
token_id: i32,
Expand All @@ -126,3 +110,9 @@ impl ContractStateMigrations for NftStateMigrations {
]
}
}

pub async fn setup() {
let bayc_contract = bayc_contract().add_state_migrations(NftStateMigrations);
let raw_query_client = test_runner::new_repo().get_raw_query_client().await;
Chaindexing::run_migrations_for_contract_states(&raw_query_client, &vec![bayc_contract]).await;
}

0 comments on commit ea39400

Please sign in to comment.