Skip to content

Commit

Permalink
Refactor test harness.
Browse files Browse the repository at this point in the history
  • Loading branch information
ray-kast committed Aug 4, 2022
1 parent 4e64a76 commit 5e9d661
Show file tree
Hide file tree
Showing 10 changed files with 428 additions and 405 deletions.
3 changes: 1 addition & 2 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,5 @@ 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"
lazy_static = "1.4.0"
449 changes: 68 additions & 381 deletions crates/core/src/db/mod.rs

Large diffs are not rendered by default.

24 changes: 11 additions & 13 deletions crates/core/src/db/queries/collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,43 +173,41 @@ fn make_by_market_cap_query_string(order_direction: OrderDirection) -> String {

#[cfg(test)]
mod tests {
use chrono::{TimeZone, Utc};

use crate::db::test::DATABASE;
use crate::db::test::prelude::*;

#[test]
fn test_collections_featured_by_marketcap_returns_non_empty() {
let pool = &DATABASE;
let conn = connect();

let result = super::by_market_cap(
&pool.get().expect("failed to aquire database connection"),
&conn,
None::<Vec<String>>,
crate::db::custom_types::OrderDirection::Desc,
OrderDirection::Desc,
Utc.ymd(1901, 1, 1).and_hms(0, 0, 0),
Utc.ymd(3000, 1, 1).and_hms(0, 0, 0),
50,
0,
)
.expect("failed query");
.unwrap();

assert!(!result.is_empty(), "expected at least one row");
assert!(!result.is_empty(), "Expected at least one row");
}

#[test]
fn test_collections_featured_by_volume_returns_non_empty() {
let pool = &DATABASE;
let conn = connect();

let result = super::by_volume(
&pool.get().expect("failed to aquire database connection"),
&conn,
None::<Vec<String>>,
crate::db::custom_types::OrderDirection::Desc,
OrderDirection::Desc,
Utc.ymd(1901, 1, 1).and_hms(0, 0, 0),
Utc.ymd(3000, 1, 1).and_hms(0, 0, 0),
50,
0,
)
.expect("failed query");
.unwrap();

assert!(!result.is_empty(), "expected at least one row");
assert!(!result.is_empty(), "Expected at least one row");
}
}
10 changes: 3 additions & 7 deletions crates/core/src/db/queries/nft_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,16 +306,12 @@ pub fn store_creators(

#[cfg(test)]
mod tests {
use crate::db::test::DATABASE;
use crate::db::test::prelude::*;

#[test]
fn test_store_creators_minimal_passes() {
let pool = &DATABASE;
let conn = connect();

let _ = super::store_creators(
&pool.get().expect("failed to aquire database connection"),
Vec::<String>::new(),
)
.expect("failed query");
std::mem::drop(super::store_creators(&conn, Vec::<String>::new()).unwrap());
}
}
27 changes: 27 additions & 0 deletions crates/core/test_migrations/2022-08-04-200854_seed_nfts/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
delete from metadatas where address = any(array [
'meta_address_0',
'meta_address_1',
'meta_address_2',
'meta_address_3',
'collection_address'
]);

delete from metadata_jsons where metadata_address = any(array [
'meta_address_0',
'meta_address_1',
'meta_address_2',
'meta_address_3',
'collection_address'
]);

delete from metadata_collection_keys where collection_address = any(array [
'collection_mint'
]);

delete from current_metadata_owners where mint_address = any(array [
'mint_0',
'mint_1',
'mint_2',
'mint_3',
'collection_mint'
]);
198 changes: 198 additions & 0 deletions crates/core/test_migrations/2022-08-04-200854_seed_nfts/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
insert into metadatas values (
'meta_address_0', -- address
'Metadata 0', -- name
'NFT', -- symbol
'https://example.com/0.json', -- uri
1000, -- seller_fee_basis_points
'updater', -- update_authority_address
'mint_0', -- mint_address
false, -- primary_sale_happened
false, -- is_mutable
1337, -- edition_nonce
'edition', -- edition_pda
'NonFungible', -- token_standard
1, -- slot
false -- burned
), (
'meta_address_1', -- address
'Metadata 1', -- name
'NFT', -- symbol
'https://example.com/1.json', -- uri
1000, -- seller_fee_basis_points
'updater', -- update_authority_address
'mint_1', -- mint_address
false, -- primary_sale_happened
false, -- is_mutable
1337, -- edition_nonce
'edition', -- edition_pda
'NonFungible', -- token_standard
1, -- slot
false -- burned
), (
'meta_address_2', -- address
'Metadata 2', -- name
'NFT', -- symbol
'https://example.com/2.json', -- uri
1000, -- seller_fee_basis_points
'updater', -- update_authority_address
'mint_2', -- mint_address
false, -- primary_sale_happened
false, -- is_mutable
1337, -- edition_nonce
'edition', -- edition_pda
'NonFungible', -- token_standard
1, -- slot
false -- burned
), (
'meta_address_3', -- address
'Metadata 3', -- name
'NFT', -- symbol
'https://example.com/3.json', -- uri
1000, -- seller_fee_basis_points
'updater', -- update_authority_address
'mint_3', -- mint_address
false, -- primary_sale_happened
false, -- is_mutable
1337, -- edition_nonce
'edition', -- edition_pda
'NonFungible', -- token_standard
1, -- slot
false -- burned
), (
'collection_address', -- address
'Collection', -- name
'COLL', -- symbol
'https://example.com/c.json', -- uri
1000, -- seller_fee_basis_points
'updater', -- update_authority_address
'collection_mint', -- mint_address
false, -- primary_sale_happened
false, -- is_mutable
1337, -- edition_nonce
'Edition', -- edition_pda
'NonFungible', -- token_standard
1, -- slot
false -- burned
);

insert into metadata_jsons values (
'meta_address_0', -- metadata_address
'00', -- fingerprint
'2020-01-01', -- updated_at
'An NFT', -- description
'https://example.com/0.jpg', -- image
'https://example.com/0.mkv', -- animation_url
'https://example.com/0', -- external_url
'test', -- category
'{}', -- raw_content
'seeded', -- model
'https://example.com/0.json', -- fetch_uri
1, -- slot
0 -- write_version
), (
'meta_address_1', -- metadata_address
'01', -- fingerprint
'2020-01-01', -- updated_at
'An NFT', -- description
'https://example.com/1.jpg', -- image
'https://example.com/1.mkv', -- animation_url
'https://example.com/1', -- external_url
'test', -- category
'{}', -- raw_content
'seeded', -- model
'https://example.com/1.json', -- fetch_uri
1, -- slot
0 -- write_version
), (
'meta_address_2', -- metadata_address
'02', -- fingerprint
'2020-01-01', -- updated_at
'An NFT', -- description
'https://example.com/2.jpg', -- image
'https://example.com/2.mkv', -- animation_url
'https://example.com/2', -- external_url
'test', -- category
'{}', -- raw_content
'seeded', -- model
'https://example.com/2.json', -- fetch_uri
1, -- slot
0 -- write_version
), (
'meta_address_3', -- metadata_address
'03', -- fingerprint
'2020-01-01', -- updated_at
'An NFT', -- description
'https://example.com/3.jpg', -- image
'https://example.com/3.mkv', -- animation_url
'https://example.com/3', -- external_url
'test', -- category
'{}', -- raw_content
'seeded', -- model
'https://example.com/3.json', -- fetch_uri
1, -- slot
0 -- write_version
), (
'collection_address', -- metadata_address
'c0', -- fingerprint
'2020-01-01', -- updated_at
'An NFT collection', -- description
'https://example.com/c.jpg', -- image
'https://example.com/c.mkv', -- animation_url
'https://example.com/c', -- external_url
'test', -- category
'{}', -- raw_content
'seeded', -- model
'https://example.com/c.json', -- fetch_uri
1, -- slot
0 -- write_version
);

insert into metadata_collection_keys values (
'meta_address_0', -- metadata_address
'collection_mint', -- collection_address
true -- verified
), (
'meta_address_1', -- metadata_address
'collection_mint', -- collection_address
true -- verified
), (
'meta_address_2', -- metadata_address
'collection_mint', -- collection_address
true -- verified
), (
'meta_address_3', -- metadata_address
'collection_mint', -- collection_address
true -- verified
);

insert into current_metadata_owners values (
'mint_0', -- mint_address
'meta_owner', -- owner_address
'ata_owner', -- token_account_address
'2020-01-01', -- updated_at
1 -- slot
), (
'mint_1', -- mint_address
'meta_owner', -- owner_address
'ata_owner', -- token_account_address
'2020-01-01', -- updated_at
1 -- slot
), (
'mint_2', -- mint_address
'meta_owner', -- owner_address
'ata_owner', -- token_account_address
'2020-01-01', -- updated_at
1 -- slot
), (
'mint_3', -- mint_address
'meta_owner', -- owner_address
'ata_owner', -- token_account_address
'2020-01-01', -- updated_at
1 -- slot
), (
'collection_mint', -- mint_address
'meta_owner', -- owner_address
'ata_owner', -- token_account_address
'2020-01-01', -- updated_at
1 -- slot
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
delete from auction_houses where address = any(array [
'ah_address'
]);

delete from listings where id = any(array [
'00000000-0000-0000-0001-000000000000'::uuid,
'00000000-0000-0000-0001-000000000001',
'00000000-0000-0000-0001-000000000002',
'00000000-0000-0000-0001-000000000003'
]);

delete from purchases where id = any(array [
'00000000-0000-0000-0002-000000000003'::uuid
]);
Loading

0 comments on commit 5e9d661

Please sign in to comment.