Skip to content

Commit

Permalink
added coverage to show token_info in other rpc calls
Browse files Browse the repository at this point in the history
  • Loading branch information
AhzamAkhtar committed Dec 26, 2024
1 parent 1a4e5f7 commit ce5b7cf
Show file tree
Hide file tree
Showing 14 changed files with 355 additions and 5 deletions.
8 changes: 8 additions & 0 deletions digital_asset_types/src/dao/scopes/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,14 @@ pub async fn get_related_for_assets(
}
}

for id in ids.clone() {
if let Ok(t) = get_token_by_id(conn, id.clone()).await {
if let Some(asset) = assets_map.get_mut(&id) {
asset.token_info = Some(t);
}
}
}

let cond = if show_unverified_collections {
Condition::all()
} else {
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async fn test_get_asset_with_show_fungible_scenario_2() {
#[tokio::test]
#[serial]
#[named]
async fn test_get_asset_by_owner_with_show_fungible_scenario() {
async fn test_get_asset_by_owner_with_show_fungible() {
let name = trim_test_name(function_name!());
let setup = TestSetup::new_with_options(
name.clone(),
Expand All @@ -97,17 +97,17 @@ async fn test_get_asset_by_owner_with_show_fungible_scenario() {
.await;

let seeds: Vec<SeedEvent> = seed_accounts([
"7EYnhQoR9YM3N7UoaKRoA44Uy8JeaZV3qyouov87awMs",
"7BajpcYgnxmWK91RhrfsdB3Tm83PcDwPvMC8ZinvtTY6",
"6BRNfDfdq1nKyU1TQiCEQLWyPtD8EwUH9Kt2ahsbidUx",
"AH6wj7T8Ke5nbukjtcobjjs1CDWUcQxndtnLkKAdrSrM",
"7fXKY9tPpvYsdbSNyesUqo27WYC6ZsBEULdtngGHqLCK",
"8Xv3SpX94HHf32Apg4TeSeS3i2p6wuXeE8FBZr168Hti",
]);

apply_migrations_and_delete_data(setup.db.clone()).await;
index_seed_events(&setup, seeds.iter().collect_vec()).await;

let request = r#"
{
"ownerAddress": "2oerfxddTpK5hWAmCMYB6fr9WvNrjEH54CHCWK8sAq7g",
"ownerAddress": "GqPnSDXwp4JFtKS7YZ2HERgBbYLKpKVYy9TpVunzLRa9",
"displayOptions": {
"showFungible": true
}
Expand All @@ -119,3 +119,81 @@ async fn test_get_asset_by_owner_with_show_fungible_scenario() {

insta::assert_json_snapshot!(name, response);
}

#[tokio::test]
#[serial]
#[named]
async fn test_get_asset_by_authority_with_show_fungible() {
let name = trim_test_name(function_name!());
let setup = TestSetup::new_with_options(
name.clone(),
TestSetupOptions {
network: Some(Network::Mainnet),
},
)
.await;

let seeds: Vec<SeedEvent> = seed_accounts([
"AH6wj7T8Ke5nbukjtcobjjs1CDWUcQxndtnLkKAdrSrM",
"7fXKY9tPpvYsdbSNyesUqo27WYC6ZsBEULdtngGHqLCK",
"8Xv3SpX94HHf32Apg4TeSeS3i2p6wuXeE8FBZr168Hti",
]);

apply_migrations_and_delete_data(setup.db.clone()).await;
index_seed_events(&setup, seeds.iter().collect_vec()).await;

let request = r#"
{
"authorityAddress": "2RtGg6fsFiiF1EQzHqbd66AhW7R5bWeQGpTbv2UMkCdW",
"displayOptions": {
"showFungible": true
}
}
"#;

let request: api::GetAssetsByAuthority = serde_json::from_str(request).unwrap();
let response = setup
.das_api
.get_assets_by_authority(request)
.await
.unwrap();

insta::assert_json_snapshot!(name, response);
}

#[tokio::test]
#[serial]
#[named]
async fn test_get_asset_by_creator_with_show_fungible() {
let name = trim_test_name(function_name!());
let setup = TestSetup::new_with_options(
name.clone(),
TestSetupOptions {
network: Some(Network::Mainnet),
},
)
.await;

let seeds: Vec<SeedEvent> = seed_accounts([
"AH6wj7T8Ke5nbukjtcobjjs1CDWUcQxndtnLkKAdrSrM",
"7fXKY9tPpvYsdbSNyesUqo27WYC6ZsBEULdtngGHqLCK",
"8Xv3SpX94HHf32Apg4TeSeS3i2p6wuXeE8FBZr168Hti",
]);

apply_migrations_and_delete_data(setup.db.clone()).await;
index_seed_events(&setup, seeds.iter().collect_vec()).await;

let request = r#"
{
"creatorAddress": "5XvhfmRjwXkGp3jHGmaKpqeerNYjkuZZBYLVQYdeVcRv",
"displayOptions": {
"showFungible": true
}
}
"#;

let request: api::GetAssetsByCreator = serde_json::from_str(request).unwrap();
let response = setup.das_api.get_assets_by_creator(request).await.unwrap();

insta::assert_json_snapshot!(name, response);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
source: integration_tests/tests/integration_tests/show_fungible_flag_tests.rs
expression: response
snapshot_kind: text
---
{
"total": 1,
"limit": 1000,
"cursor": "AH6wj7T8Ke5nbukjtcobjjs1CDWUcQxndtnLkKAdrSrM",
"items": [
{
"interface": "ProgrammableNFT",
"id": "AH6wj7T8Ke5nbukjtcobjjs1CDWUcQxndtnLkKAdrSrM",
"content": {
"$schema": "https://schema.metaplex.com/nft1.0.json",
"json_uri": "https://madlads.s3.us-west-2.amazonaws.com/json/1983.json",
"files": [],
"metadata": {
"name": "Mad Lads #1983",
"symbol": "MAD",
"token_standard": "ProgrammableNonFungible"
},
"links": {}
},
"authorities": [
{
"address": "2RtGg6fsFiiF1EQzHqbd66AhW7R5bWeQGpTbv2UMkCdW",
"scopes": [
"full"
]
}
],
"compression": {
"eligible": false,
"compressed": false,
"data_hash": "",
"creator_hash": "",
"asset_hash": "",
"tree": "",
"seq": 0,
"leaf_id": 0
},
"grouping": [
{
"group_key": "collection",
"group_value": "J1S9H3QjnRtBbbuD4HjPV6RpRhwuk4zKbxsnCHuTgh9w"
}
],
"royalty": {
"royalty_model": "creators",
"target": null,
"percent": 0.042,
"basis_points": 420,
"primary_sale_happened": true,
"locked": false
},
"creators": [
{
"address": "5XvhfmRjwXkGp3jHGmaKpqeerNYjkuZZBYLVQYdeVcRv",
"share": 0,
"verified": true
},
{
"address": "2RtGg6fsFiiF1EQzHqbd66AhW7R5bWeQGpTbv2UMkCdW",
"share": 100,
"verified": true
}
],
"ownership": {
"frozen": true,
"delegated": true,
"delegate": "BPB5idZgbA1DG4XEmnKs62AADRZFf3jY7Kr9mpMGyKPi",
"ownership_model": "single",
"owner": "GqPnSDXwp4JFtKS7YZ2HERgBbYLKpKVYy9TpVunzLRa9"
},
"supply": null,
"mutable": true,
"burnt": false,
"token_info": {
"supply": 1,
"decimals": 0,
"token_program": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
"mint_authority": "FAzbjKo66M3tKhkKqegmWFaYr93FB74B1ChEBdFyKcip",
"freeze_authority": "FAzbjKo66M3tKhkKqegmWFaYr93FB74B1ChEBdFyKcip"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
source: integration_tests/tests/integration_tests/show_fungible_flag_tests.rs
expression: response
snapshot_kind: text
---
{
"total": 1,
"limit": 1000,
"cursor": "AH6wj7T8Ke5nbukjtcobjjs1CDWUcQxndtnLkKAdrSrM",
"items": [
{
"interface": "ProgrammableNFT",
"id": "AH6wj7T8Ke5nbukjtcobjjs1CDWUcQxndtnLkKAdrSrM",
"content": {
"$schema": "https://schema.metaplex.com/nft1.0.json",
"json_uri": "https://madlads.s3.us-west-2.amazonaws.com/json/1983.json",
"files": [],
"metadata": {
"name": "Mad Lads #1983",
"symbol": "MAD",
"token_standard": "ProgrammableNonFungible"
},
"links": {}
},
"authorities": [
{
"address": "2RtGg6fsFiiF1EQzHqbd66AhW7R5bWeQGpTbv2UMkCdW",
"scopes": [
"full"
]
}
],
"compression": {
"eligible": false,
"compressed": false,
"data_hash": "",
"creator_hash": "",
"asset_hash": "",
"tree": "",
"seq": 0,
"leaf_id": 0
},
"grouping": [
{
"group_key": "collection",
"group_value": "J1S9H3QjnRtBbbuD4HjPV6RpRhwuk4zKbxsnCHuTgh9w"
}
],
"royalty": {
"royalty_model": "creators",
"target": null,
"percent": 0.042,
"basis_points": 420,
"primary_sale_happened": true,
"locked": false
},
"creators": [
{
"address": "5XvhfmRjwXkGp3jHGmaKpqeerNYjkuZZBYLVQYdeVcRv",
"share": 0,
"verified": true
},
{
"address": "2RtGg6fsFiiF1EQzHqbd66AhW7R5bWeQGpTbv2UMkCdW",
"share": 100,
"verified": true
}
],
"ownership": {
"frozen": true,
"delegated": true,
"delegate": "BPB5idZgbA1DG4XEmnKs62AADRZFf3jY7Kr9mpMGyKPi",
"ownership_model": "single",
"owner": "GqPnSDXwp4JFtKS7YZ2HERgBbYLKpKVYy9TpVunzLRa9"
},
"supply": null,
"mutable": true,
"burnt": false,
"token_info": {
"supply": 1,
"decimals": 0,
"token_program": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
"mint_authority": "FAzbjKo66M3tKhkKqegmWFaYr93FB74B1ChEBdFyKcip",
"freeze_authority": "FAzbjKo66M3tKhkKqegmWFaYr93FB74B1ChEBdFyKcip"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
source: integration_tests/tests/integration_tests/show_fungible_flag_tests.rs
expression: response
snapshot_kind: text
---
{
"total": 1,
"limit": 1000,
"cursor": "AH6wj7T8Ke5nbukjtcobjjs1CDWUcQxndtnLkKAdrSrM",
"items": [
{
"interface": "ProgrammableNFT",
"id": "AH6wj7T8Ke5nbukjtcobjjs1CDWUcQxndtnLkKAdrSrM",
"content": {
"$schema": "https://schema.metaplex.com/nft1.0.json",
"json_uri": "https://madlads.s3.us-west-2.amazonaws.com/json/1983.json",
"files": [],
"metadata": {
"name": "Mad Lads #1983",
"symbol": "MAD",
"token_standard": "ProgrammableNonFungible"
},
"links": {}
},
"authorities": [
{
"address": "2RtGg6fsFiiF1EQzHqbd66AhW7R5bWeQGpTbv2UMkCdW",
"scopes": [
"full"
]
}
],
"compression": {
"eligible": false,
"compressed": false,
"data_hash": "",
"creator_hash": "",
"asset_hash": "",
"tree": "",
"seq": 0,
"leaf_id": 0
},
"grouping": [
{
"group_key": "collection",
"group_value": "J1S9H3QjnRtBbbuD4HjPV6RpRhwuk4zKbxsnCHuTgh9w"
}
],
"royalty": {
"royalty_model": "creators",
"target": null,
"percent": 0.042,
"basis_points": 420,
"primary_sale_happened": true,
"locked": false
},
"creators": [
{
"address": "5XvhfmRjwXkGp3jHGmaKpqeerNYjkuZZBYLVQYdeVcRv",
"share": 0,
"verified": true
},
{
"address": "2RtGg6fsFiiF1EQzHqbd66AhW7R5bWeQGpTbv2UMkCdW",
"share": 100,
"verified": true
}
],
"ownership": {
"frozen": true,
"delegated": true,
"delegate": "BPB5idZgbA1DG4XEmnKs62AADRZFf3jY7Kr9mpMGyKPi",
"ownership_model": "single",
"owner": "GqPnSDXwp4JFtKS7YZ2HERgBbYLKpKVYy9TpVunzLRa9"
},
"supply": null,
"mutable": true,
"burnt": false,
"token_info": {
"supply": 1,
"decimals": 0,
"token_program": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
"mint_authority": "FAzbjKo66M3tKhkKqegmWFaYr93FB74B1ChEBdFyKcip",
"freeze_authority": "FAzbjKo66M3tKhkKqegmWFaYr93FB74B1ChEBdFyKcip"
}
}
]
}

0 comments on commit ce5b7cf

Please sign in to comment.