Skip to content

Commit

Permalink
basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Austin Milt authored and ray-kast committed Aug 4, 2022
1 parent 5e8eeb6 commit 4e64a76
Show file tree
Hide file tree
Showing 5 changed files with 439 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,7 @@ base64 = { version = "0.13.0", optional = true }
cid = { version = "0.7.0", optional = true }
url = "2.2.2"
md5 = { version = "0.7.0", optional = true }


[dev-dependencies]
lazy_static = "1.4.0"
375 changes: 375 additions & 0 deletions crates/core/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,378 @@ pub fn connect(args: ConnectArgs, mode: ConnectMode) -> Result<ConnectResult> {

Ok(ConnectResult { pool, ty, migrated })
}

#[cfg(test)]
pub mod test {
use diesel::{insert_into, prelude::*};
use uuid::Uuid;

use super::{
connect, models,
schema::{
auction_houses, listings, metadata_collection_keys, metadata_jsons, metadatas,
purchases,
},
ConnectArgs,
};
use crate::prelude::*;

fn initialize() -> super::Pool {
let conn_args = ConnectArgs {
database_read_url: None,
database_write_url: Some(
"postgres://postgres:holap1ex@localhost:5337/holaplex-indexer".into(),
),
database_url: None,
};
let (pool, _) = connect(conn_args, crate::db::ConnectMode::Write)
.expect("failed to connect to database");
let conn = pool.get().expect("failed to get connection to database");

let nft_a_metadata_address = Borrowed("metadata_a");
let nft_b_metadata_address = Borrowed("metadata_b");
let nft_c_metadata_address = Borrowed("metadata_c");
let nft_d_metadata_address = Borrowed("metadata_d");
let nft_d_purchase_id = Some(
Uuid::parse_str("00000000-0000-0000-0000-000000000009").expect("failed to parse UUID"),
);
let collection_metadata_address = Borrowed("collection_a");
let auction_house_address = Borrowed("auction_house_a");
let seller_address = Borrowed("seller_a");
let buyer_address = Borrowed("buyer_a");

insert_into(metadata_collection_keys::table)
.values(vec![
models::MetadataCollectionKey {
metadata_address: nft_a_metadata_address.clone(),
collection_address: collection_metadata_address.clone(),
verified: true,
},
models::MetadataCollectionKey {
metadata_address: nft_b_metadata_address.clone(),
collection_address: collection_metadata_address.clone(),
verified: true,
},
models::MetadataCollectionKey {
metadata_address: nft_c_metadata_address.clone(),
collection_address: collection_metadata_address.clone(),
verified: true,
},
models::MetadataCollectionKey {
metadata_address: nft_d_metadata_address.clone(),
collection_address: collection_metadata_address.clone(),
verified: true,
},
])
.on_conflict_do_nothing()
.execute(&conn)
.expect("failed to seed metadata_collection_keys");

insert_into(metadatas::table)
.values(vec![
models::Metadata {
address: nft_a_metadata_address.clone(),
name: Borrowed("nft A"),
symbol: Borrowed("symbol"),
uri: Borrowed("http://example.com/nft-a-uri"),
seller_fee_basis_points: 100,
update_authority_address: Borrowed("update authority"),
mint_address: collection_metadata_address.clone(),
primary_sale_happened: true,
is_mutable: false,
edition_nonce: None,
edition_pda: Borrowed("nft edition pda"),
token_standard: None,
slot: Some(0),
burned: false,
},
models::Metadata {
address: nft_b_metadata_address.clone(),
name: Borrowed("nft B"),
symbol: Borrowed("symbol"),
uri: Borrowed("http://example.com/nft-b-uri"),
seller_fee_basis_points: 100,
update_authority_address: Borrowed("update authority"),
mint_address: collection_metadata_address.clone(),
primary_sale_happened: true,
is_mutable: false,
edition_nonce: None,
edition_pda: Borrowed("nft edition pda"),
token_standard: None,
slot: Some(0),
burned: false,
},
models::Metadata {
address: nft_c_metadata_address.clone(),
name: Borrowed("nft C"),
symbol: Borrowed("symbol"),
uri: Borrowed("http://example.com/nft-c-uri"),
seller_fee_basis_points: 100,
update_authority_address: Borrowed("update authority"),
mint_address: collection_metadata_address.clone(),
primary_sale_happened: true,
is_mutable: false,
edition_nonce: None,
edition_pda: Borrowed("nft edition pda"),
token_standard: None,
slot: Some(0),
burned: false,
},
models::Metadata {
address: nft_d_metadata_address.clone(),
name: Borrowed("nft D"),
symbol: Borrowed("symbol"),
uri: Borrowed("http://example.com/nft-d-uri"),
seller_fee_basis_points: 100,
update_authority_address: Borrowed("update authority"),
mint_address: collection_metadata_address.clone(),
primary_sale_happened: true,
is_mutable: false,
edition_nonce: None,
edition_pda: Borrowed("nft edition pda"),
token_standard: None,
slot: Some(0),
burned: false,
},
models::Metadata {
address: collection_metadata_address.clone(),
name: Borrowed("collection name"),
symbol: Borrowed("symbol"),
uri: Borrowed("http://example.com/collection-uri"),
seller_fee_basis_points: 100,
update_authority_address: Borrowed("update authority"),
mint_address: Borrowed("collection mint"),
primary_sale_happened: true,
is_mutable: false,
edition_nonce: None,
edition_pda: Borrowed("collection edition pda"),
token_standard: None,
slot: Some(0),
burned: false,
},
])
.on_conflict_do_nothing()
.execute(&conn)
.expect("failed to seed metadatas");

insert_into(auction_houses::table)
.values(vec![models::AuctionHouse {
address: auction_house_address.clone(),
treasury_mint: Borrowed("So11111111111111111111111111111111111111112"),
auction_house_treasury: Borrowed("treasury"),
treasury_withdrawal_destination: Borrowed("treasury withdrawal"),
fee_withdrawal_destination: Borrowed("fee withdrawal"),
authority: Borrowed("auction house authority"),
creator: Borrowed("auction house creator"),
bump: 0,
treasury_bump: 0,
fee_payer_bump: 0,
seller_fee_basis_points: 100,
requires_sign_off: false,
can_change_sale_price: false,
auction_house_fee_account: Borrowed("auction house fee account"),
}])
.on_conflict_do_nothing()
.execute(&conn)
.expect("failed to seed auction_houses");

insert_into(listings::table)
.values(vec![
models::Listing {
id: Some(
Uuid::parse_str("00000000-0000-0000-0000-000000000001")
.expect("failed to parse UUID"),
),
trade_state: Borrowed("nft_a trade state"),
auction_house: auction_house_address.clone(),
seller: seller_address.clone(),
metadata: nft_a_metadata_address.clone(),
purchase_id: None,
price: 1,
token_size: 1,
trade_state_bump: 0,
created_at: NaiveDate::from_ymd(2020, 1, 2).and_hms(0, 0, 0),
canceled_at: None,
slot: 0,
write_version: Some(0),
},
models::Listing {
id: Some(
Uuid::parse_str("00000000-0000-0000-0000-000000000002")
.expect("failed to parse UUID"),
),
trade_state: Borrowed("nft_b trade state"),
auction_house: auction_house_address.clone(),
seller: seller_address.clone(),
metadata: nft_b_metadata_address.clone(),
purchase_id: None,
price: 1,
token_size: 1,
trade_state_bump: 0,
created_at: NaiveDate::from_ymd(2020, 1, 2).and_hms(0, 0, 0),
canceled_at: None,
slot: 0,
write_version: Some(0),
},
models::Listing {
id: Some(
Uuid::parse_str("00000000-0000-0000-0000-000000000003")
.expect("failed to parse UUID"),
),
trade_state: Borrowed("nft_c trade state"),
auction_house: auction_house_address.clone(),
seller: seller_address.clone(),
metadata: nft_c_metadata_address.clone(),
purchase_id: None,
price: 1,
token_size: 1,
trade_state_bump: 0,
created_at: NaiveDate::from_ymd(2020, 1, 2).and_hms(0, 0, 0),
canceled_at: None,
slot: 0,
write_version: Some(0),
},
models::Listing {
id: Some(
Uuid::parse_str("00000000-0000-0000-0000-000000000004")
.expect("failed to parse UUID"),
),
trade_state: Borrowed("nft_d trade state"),
auction_house: auction_house_address.clone(),
seller: seller_address.clone(),
metadata: nft_d_metadata_address.clone(),
purchase_id: nft_d_purchase_id.clone(),
price: 1,
token_size: 1,
trade_state_bump: 0,
created_at: NaiveDate::from_ymd(2020, 1, 2).and_hms(0, 0, 0),
canceled_at: None,
slot: 0,
write_version: Some(0),
},
])
.on_conflict_do_nothing()
.execute(&conn)
.expect("failed to seed purchases");

insert_into(purchases::table)
.values(vec![models::Purchase {
id: nft_d_purchase_id.clone(),
buyer: buyer_address.clone(),
seller: seller_address.clone(),
auction_house: auction_house_address.clone(),
metadata: nft_d_metadata_address.clone(),
token_size: 1,
price: 1,
created_at: NaiveDate::from_ymd(2020, 1, 2).and_hms(0, 0, 0),
slot: 0,
write_version: None,
}])
.on_conflict_do_nothing()
.execute(&conn)
.expect("failed to seed purchases");

insert_into(metadata_jsons::table)
.values(vec![
models::MetadataJson {
metadata_address: nft_a_metadata_address,
fingerprint: Borrowed(&Vec::<u8>::new()),
updated_at: NaiveDate::from_ymd(2020, 1, 2).and_hms(0, 0, 0),
description: Some(Borrowed("nft A description")),
image: Some(Borrowed("http://example.com/nft-a-image")),
animation_url: Some(Borrowed("http://example.com/nft-a-animation")),
external_url: Some(Borrowed("http://example.com/nft-a-external")),
category: Some(Borrowed("nft A category")),
raw_content: Borrowed(
&serde_json::from_str("{}")
.expect("Failed to deserialize metadata content"),
),
model: Some(Borrowed("model")),
fetch_uri: Borrowed("http://example.com/nft-a-fetch-uri"),
slot: 0,
write_version: 0,
},
models::MetadataJson {
metadata_address: nft_b_metadata_address,
fingerprint: Borrowed(&Vec::<u8>::new()),
updated_at: NaiveDate::from_ymd(2020, 1, 2).and_hms(0, 0, 0),
description: Some(Borrowed("nft B description")),
image: Some(Borrowed("http://example.com/nft-b-image")),
animation_url: Some(Borrowed("http://example.com/nft-b-animation")),
external_url: Some(Borrowed("http://example.com/nft-b-external")),
category: Some(Borrowed("nft B category")),
raw_content: Borrowed(
&serde_json::from_str("{}")
.expect("Failed to deserialize metadata content"),
),
model: Some(Borrowed("model")),
fetch_uri: Borrowed("http://example.com/nft-b-fetch-uri"),
slot: 0,
write_version: 0,
},
models::MetadataJson {
metadata_address: nft_c_metadata_address,
fingerprint: Borrowed(&Vec::<u8>::new()),
updated_at: NaiveDate::from_ymd(2020, 1, 2).and_hms(0, 0, 0),
description: Some(Borrowed("nft C description")),
image: Some(Borrowed("http://example.com/nft-c-image")),
animation_url: Some(Borrowed("http://example.com/nft-c-animation")),
external_url: Some(Borrowed("http://example.com/nft-c-external")),
category: Some(Borrowed("nft C category")),
raw_content: Borrowed(
&serde_json::from_str("{}")
.expect("Failed to deserialize metadata content"),
),
model: Some(Borrowed("model")),
fetch_uri: Borrowed("http://example.com/nft-c-fetch-uri"),
slot: 0,
write_version: 0,
},
models::MetadataJson {
metadata_address: nft_d_metadata_address,
fingerprint: Borrowed(&Vec::<u8>::new()),
updated_at: NaiveDate::from_ymd(2020, 1, 2).and_hms(0, 0, 0),
description: Some(Borrowed("nft C description")),
image: Some(Borrowed("http://example.com/nft-c-image")),
animation_url: Some(Borrowed("http://example.com/nft-c-animation")),
external_url: Some(Borrowed("http://example.com/nft-c-external")),
category: Some(Borrowed("nft B category")),
raw_content: Borrowed(
&serde_json::from_str("{}")
.expect("Failed to deserialize metadata content"),
),
model: Some(Borrowed("model")),
fetch_uri: Borrowed("http://example.com/nft-c-fetch-uri"),
slot: 0,
write_version: 0,
},
models::MetadataJson {
metadata_address: collection_metadata_address,
fingerprint: Borrowed(&Vec::<u8>::new()),
updated_at: NaiveDate::from_ymd(2020, 1, 2).and_hms(0, 0, 0),
description: Some(Borrowed("collection description")),
image: Some(Borrowed("http://example.com/collection-image")),
animation_url: Some(Borrowed("http://example.com/collection-animation")),
external_url: Some(Borrowed("http://example.com/collection-external")),
category: Some(Borrowed("collection category")),
raw_content: Borrowed(
&serde_json::from_str("{}")
.expect("Failed to deserialize metadata content"),
),
model: Some(Borrowed("model")),
fetch_uri: Borrowed("http://example.com/collection-fetch-uri"),
slot: 0,
write_version: 0,
},
])
.on_conflict_do_nothing()
.execute(&conn)
.expect("failed to seed metadata_jsons");

pool
}

lazy_static::lazy_static! {
pub static ref DATABASE: super::Pool = initialize();
}
}
Loading

0 comments on commit 4e64a76

Please sign in to comment.