From 51a118b2f310f7ff009376a5bd5e1023a1676c1f Mon Sep 17 00:00:00 2001 From: Ravi Patel <82118011+rpatel-figure@users.noreply.github.com> Date: Wed, 30 Oct 2024 13:55:37 -0500 Subject: [PATCH] 256/269 unit tests passing --- src/execute/onboard_asset.rs | 72 ++++++++++++++----- src/execute/update_access_routes.rs | 15 +++- src/execute/verify_asset.rs | 16 ++++- src/query/query_asset_scope_attribute.rs | 18 +++-- ...ery_asset_scope_attribute_by_asset_type.rs | 17 +++-- src/service/asset_meta_service.rs | 23 +++++- src/testutil/test_utilities.rs | 16 +++-- 7 files changed, 135 insertions(+), 42 deletions(-) diff --git a/src/execute/onboard_asset.rs b/src/execute/onboard_asset.rs index 36e40c26..772e7361 100644 --- a/src/execute/onboard_asset.rs +++ b/src/execute/onboard_asset.rs @@ -315,7 +315,7 @@ mod tests { }; use crate::testutil::test_utilities::{ assert_single_item, get_default_asset_definition_input, get_default_verifier_detail, - single_attribute_for_key, + setup_no_attribute_response, single_attribute_for_key, }; use crate::util::constants::{NEW_ASSET_ONBOARDING_STATUS_KEY, NHASH}; use crate::util::functions::{ @@ -504,8 +504,19 @@ mod tests { fn test_onboard_asset_errors_on_asset_not_found() { let mut deps = mock_provenance_dependencies(); setup_test_suite(&mut deps, &InstArgs::default()); + setup_no_attribute_response(&mut deps, None); + // Some random scope address unrelated to the default scope address, which is mocked during setup_test_suite let bogus_scope_address = "scope1qp9szrgvvpy5ph5fmxrzs2euyltssfc3lu"; + ScopeRequest::mock_response( + &mut deps.querier, + ScopeResponse { + scope: None, + sessions: vec![], + records: vec![], + request: None, + }, + ); let err = onboard_asset( AssetMetaService::new(deps.as_mut()), @@ -540,6 +551,7 @@ mod tests { fn test_onboard_asset_errors_on_asset_pending_status() { let mut deps = mock_provenance_dependencies(); setup_test_suite(&mut deps, &InstArgs::default()); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()).unwrap(); let err = onboard_asset( @@ -590,6 +602,7 @@ mod tests { let mut deps = mock_provenance_dependencies(); let instantiate_args = InstArgs::default(); setup_test_suite(&mut deps, &instantiate_args); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()).unwrap(); test_verify_asset(&mut deps, &instantiate_args.env, TestVerifyAsset::default()).unwrap(); let err = onboard_asset( @@ -697,6 +710,7 @@ mod tests { request: None, }, ); + setup_no_attribute_response(&mut deps, None); onboard_asset( AssetMetaService::new(deps.as_mut()), mock_env(), @@ -718,6 +732,22 @@ mod tests { test_instantiate_success(deps.as_mut(), &InstArgs::default()); // Setup the default scope and add a record, but make sure the record is not formed properly let scope = get_default_scope(); + let malformed_record = vec![RecordWrapper { + record: Some(Record { + name: "record-name".to_string(), + session_id: DEFAULT_SESSION_ADDRESS.to_string().into(), + specification_id: DEFAULT_RECORD_SPEC_ADDRESS.to_string().into(), + process: Some(Process { + process_id: Some(ProcessId::Address(String::new())), + method: String::new(), + name: String::new(), + }), + inputs: vec![], + outputs: vec![], + }), + record_id_info: None, + record_spec_id_info: None, + }]; ScopeRequest::mock_response( &mut deps.querier, ScopeResponse { @@ -727,22 +757,16 @@ mod tests { scope_spec_id_info: None, }), sessions: vec![], - records: vec![RecordWrapper { - record: Some(Record { - name: "record-name".to_string(), - session_id: DEFAULT_SESSION_ADDRESS.to_string().into(), - specification_id: DEFAULT_RECORD_SPEC_ADDRESS.to_string().into(), - process: Some(Process { - process_id: Some(ProcessId::Address(String::new())), - method: String::new(), - name: String::new(), - }), - inputs: vec![], - outputs: vec![], - }), - record_id_info: None, - record_spec_id_info: None, - }], + records: malformed_record.to_owned(), + request: None, + }, + ); + RecordsRequest::mock_response( + &mut deps.querier, + RecordsResponse { + scope: None, + sessions: vec![], + records: malformed_record, request: None, }, ); @@ -806,6 +830,7 @@ mod tests { request: None, }, ); + setup_no_attribute_response(&mut deps, None); onboard_asset( AssetMetaService::new(deps.as_mut()), mock_env(), @@ -825,6 +850,7 @@ mod tests { fn test_onboard_asset_success() { let mut deps = mock_provenance_dependencies(); setup_test_suite(&mut deps, &InstArgs::default()); + setup_no_attribute_response(&mut deps, None); let result = onboard_asset( AssetMetaService::new(deps.as_mut()), @@ -944,6 +970,7 @@ mod tests { ..InstArgs::default() }, ); + setup_no_attribute_response(&mut deps, None); let response = test_onboard_asset(&mut deps, TestOnboardAsset::default()).unwrap(); test_no_money_moved_in_response( &response, @@ -956,6 +983,7 @@ mod tests { let mut deps = mock_provenance_dependencies(); let instantiate_args = InstArgs::default(); setup_test_suite(&mut deps, &instantiate_args); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()).unwrap(); let payment_detail_before_retry = load_fee_payment_detail( deps.as_ref().storage, @@ -1079,6 +1107,7 @@ mod tests { }, ) .expect("adding the second verifier should succeed without error"); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()).unwrap(); let payment_detail_before = load_fee_payment_detail( deps.as_ref().storage, @@ -1183,6 +1212,7 @@ mod tests { ..InstArgs::default() }; setup_test_suite(&mut deps, &instantiate_args); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()).unwrap(); test_verify_asset( &mut deps, @@ -1198,6 +1228,7 @@ mod tests { AssetOnboardingStatus::Denied, "sanity check: the onboarding status should be set to denied after the verifier marks the asset as success = false", ); + // TODO: Adjust mock? let response = test_onboard_asset(&mut deps, TestOnboardAsset::default()).unwrap(); test_no_money_moved_in_response( &response, @@ -1240,11 +1271,13 @@ mod tests { }, ) .expect("adding the secondary asset definition should succeed"); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()) .expect("onboarding as the default asset type should succeed"); let existing_scope_attribute = AssetMetaService::new(deps.as_mut()) .get_asset_by_asset_type(DEFAULT_SCOPE_ADDRESS, DEFAULT_ASSET_TYPE) .expect("the existing asset type should have an asset scope attribute"); + setup_no_attribute_response(&mut deps, None); let subsequent_response = test_onboard_asset( &mut deps, TestOnboardAsset { @@ -1323,8 +1356,10 @@ mod tests { }, ) .expect("adding the secondary asset definition should succeed"); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()) .expect("onboarding as the default asset type should succeed"); + setup_no_attribute_response(&mut deps, None); test_onboard_asset( &mut deps, TestOnboardAsset { @@ -1365,6 +1400,7 @@ mod tests { let mut deps = mock_provenance_dependencies(); // Set up the contract as normal, but make subsequent onboards free setup_test_suite(&mut deps, &InstArgs::default()); + setup_no_attribute_response(&mut deps, None); let secondary_verifier = VerifierDetailV2::new( DEFAULT_VERIFIER_ADDRESS, Uint128::new(300), @@ -1420,6 +1456,7 @@ mod tests { let mut deps = mock_provenance_dependencies(); let instantiate_args = InstArgs::default(); setup_test_suite(&mut deps, &instantiate_args); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()).unwrap(); test_verify_asset(&mut deps, &instantiate_args.env, TestVerifyAsset::default()).unwrap(); let service = AssetMetaService::new(deps.as_mut()); @@ -1499,6 +1536,7 @@ mod tests { let get_onboard_result = |permission_spec: Option| { let mut deps = mock_provenance_dependencies(); setup_test_suite(&mut deps, &InstArgs::default()); + setup_no_attribute_response(&mut deps, None); execute( deps.as_mut(), mock_env(), diff --git a/src/execute/update_access_routes.rs b/src/execute/update_access_routes.rs index 0118f88f..b9dd362c 100644 --- a/src/execute/update_access_routes.rs +++ b/src/execute/update_access_routes.rs @@ -196,7 +196,8 @@ mod tests { DEFAULT_SCOPE_ADDRESS, DEFAULT_SENDER_ADDRESS, DEFAULT_VERIFIER_ADDRESS, }; use crate::testutil::test_utilities::{ - assert_single_item, empty_mock_info, setup_test_suite, single_attribute_for_key, InstArgs, + assert_single_item, empty_mock_info, setup_no_attribute_response, setup_test_suite, + single_attribute_for_key, InstArgs, }; use crate::testutil::update_access_routes_helpers::{ test_update_access_routes, TestUpdateAccessRoutes, @@ -211,8 +212,7 @@ mod tests { use cosmwasm_std::{coin, from_json, Addr}; use provwasm_mocks::mock_provenance_dependencies; use provwasm_std::types::provenance::attribute::v1::{ - AttributeType, MsgUpdateAttributeRequest, QueryAttributeRequest, QueryAttributeResponse, - QueryAttributesRequest, QueryAttributesResponse, + AttributeType, MsgUpdateAttributeRequest, }; #[test] @@ -220,6 +220,7 @@ mod tests { let mut deps = mock_provenance_dependencies(); let instantiate_args = InstArgs::default(); setup_test_suite(&mut deps, &instantiate_args); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()) .expect("expected the default asset onboarding to succeed"); let err = update_access_routes( @@ -248,6 +249,7 @@ mod tests { let mut deps = mock_provenance_dependencies(); let instantiate_args = InstArgs::default(); setup_test_suite(&mut deps, &instantiate_args); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()) .expect("expected the default asset onboarding to succeed"); let err = update_access_routes( @@ -276,6 +278,7 @@ mod tests { let mut deps = mock_provenance_dependencies(); let instantiate_args = InstArgs::default(); setup_test_suite(&mut deps, &instantiate_args); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()) .expect("expected the default asset onboarding to succeed"); let err = update_access_routes( @@ -308,6 +311,7 @@ mod tests { let mut deps = mock_provenance_dependencies(); let instantiate_args = InstArgs::default(); setup_test_suite(&mut deps, &instantiate_args); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()) .expect("expected the default asset onboarding to succeed"); let err = update_access_routes( @@ -347,6 +351,7 @@ mod tests { let mut deps = mock_provenance_dependencies(); let instantiate_args = InstArgs::default(); setup_test_suite(&mut deps, &instantiate_args); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()) .expect("expected the default asset onboarding to succeed"); let attribute_before_update = AssetMetaService::new(deps.as_mut()).get_asset_by_asset_type(DEFAULT_SCOPE_ADDRESS, DEFAULT_ASSET_TYPE).expect( @@ -493,6 +498,7 @@ mod tests { let mut deps = mock_provenance_dependencies(); let instantiate_args = InstArgs::default(); setup_test_suite(&mut deps, &instantiate_args); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()) .expect("expected the default asset onboarding to succeed"); test_update_access_routes( @@ -511,6 +517,7 @@ mod tests { let mut deps = mock_provenance_dependencies(); let instantiate_args = InstArgs::default(); setup_test_suite(&mut deps, &instantiate_args); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()) .expect("expected the default asset onboarding to succeed"); test_update_access_routes( @@ -545,6 +552,7 @@ mod tests { let mut deps = mock_provenance_dependencies(); let instantiate_args = InstArgs::default(); setup_test_suite(&mut deps, &instantiate_args); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()) .expect("expected the default asset onboarding to succeed"); test_verify_asset(&mut deps, &instantiate_args.env, TestVerifyAsset::default()) @@ -608,6 +616,7 @@ mod tests { fn test_successful_update_through_execute_function() { let mut deps = mock_provenance_dependencies(); setup_test_suite(&mut deps, &InstArgs::default()); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()) .expect("expected the default asset onboarding to succeed"); execute( diff --git a/src/execute/verify_asset.rs b/src/execute/verify_asset.rs index 30bb7739..dbde9ed4 100644 --- a/src/execute/verify_asset.rs +++ b/src/execute/verify_asset.rs @@ -184,7 +184,8 @@ mod tests { DEFAULT_ASSET_TYPE, DEFAULT_CONTRACT_BASE_NAME, DEFAULT_SECONDARY_ASSET_TYPE, }; use crate::testutil::test_utilities::{ - get_default_asset_definition_input, get_default_verifier_detail, single_attribute_for_key, + get_default_asset_definition_input, get_default_verifier_detail, + setup_no_attribute_response, single_attribute_for_key, }; use crate::util::constants::{ ASSET_EVENT_TYPE_KEY, ASSET_SCOPE_ADDRESS_KEY, ASSET_TYPE_KEY, @@ -217,6 +218,7 @@ mod tests { let mut deps = mock_provenance_dependencies(); let instantiate_args = InstArgs::default(); setup_test_suite(&mut deps, &instantiate_args); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()).unwrap(); let err = verify_asset( &instantiate_args.env, @@ -237,6 +239,7 @@ mod tests { let mut deps = mock_provenance_dependencies(); let instantiate_args = InstArgs::default(); setup_test_suite(&mut deps, &instantiate_args); + setup_no_attribute_response(&mut deps, None); let err = verify_asset( &instantiate_args.env, @@ -276,6 +279,7 @@ mod tests { let mut deps = mock_provenance_dependencies(); let instantiate_args = InstArgs::default(); setup_test_suite(&mut deps, &instantiate_args); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()).unwrap(); @@ -330,6 +334,7 @@ mod tests { let mut deps = mock_provenance_dependencies(); let instantiate_args = InstArgs::default(); setup_test_suite(&mut deps, &instantiate_args); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()).unwrap(); let result = verify_asset( @@ -358,6 +363,7 @@ mod tests { let mut deps = mock_provenance_dependencies(); let instantiate_args = InstArgs::default(); setup_test_suite(&mut deps, &instantiate_args); + setup_no_attribute_response(&mut deps, None); test_onboard_asset( &mut deps, TestOnboardAsset { @@ -408,6 +414,7 @@ mod tests { let mut deps = mock_provenance_dependencies(); let instantiate_args = InstArgs::default(); setup_test_suite(&mut deps, &instantiate_args); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()).unwrap(); test_verify_asset( &mut deps, @@ -455,11 +462,13 @@ mod tests { let instantiate_args = InstArgs::default_with_additional_asset_types(vec![DEFAULT_SECONDARY_ASSET_TYPE]); setup_test_suite(&mut deps, &instantiate_args); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()).unwrap(); let default_attribute = AssetMetaService::new(deps.as_mut()) .get_asset_by_asset_type(DEFAULT_SCOPE_ADDRESS, DEFAULT_ASSET_TYPE) .unwrap(); // onboard asset for secondary class + setup_no_attribute_response(&mut deps, None); test_onboard_asset( &mut deps, TestOnboardAsset { @@ -589,7 +598,9 @@ mod tests { let instantiate_args = InstArgs::default_with_additional_asset_types(vec![DEFAULT_SECONDARY_ASSET_TYPE]); setup_test_suite(&mut deps, &instantiate_args); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()).unwrap(); + // TODO: Mock needed here probably let err = test_verify_asset( &mut deps, &instantiate_args.env, @@ -617,6 +628,7 @@ mod tests { let mut deps = mock_provenance_dependencies(); let instantiate_args = InstArgs::default(); setup_test_suite(&mut deps, &instantiate_args); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()).unwrap(); let response = test_verify_asset(&mut deps, &instantiate_args.env, TestVerifyAsset::default()) @@ -637,6 +649,7 @@ mod tests { let mut deps = mock_provenance_dependencies(); let instantiate_args = InstArgs::default(); setup_test_suite(&mut deps, &instantiate_args); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()).unwrap(); let response = test_verify_asset( &mut deps, @@ -670,6 +683,7 @@ mod tests { ..InstArgs::default() }; setup_test_suite(&mut deps, &instantiate_args); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()) .expect("onboarding when free should succeed"); let response = diff --git a/src/query/query_asset_scope_attribute.rs b/src/query/query_asset_scope_attribute.rs index bd1c8aa9..68514287 100644 --- a/src/query/query_asset_scope_attribute.rs +++ b/src/query/query_asset_scope_attribute.rs @@ -193,10 +193,11 @@ pub fn may_query_scope_attribute_by_scope_address>( mod tests { use cosmwasm_std::{from_json, StdError}; use provwasm_mocks::mock_provenance_dependencies; + use provwasm_std::types::provenance::metadata::v1::ScopeRequest; use crate::testutil::onboard_asset_helpers::{test_onboard_asset, TestOnboardAsset}; use crate::testutil::test_constants::DEFAULT_SCOPE_ADDRESS; - use crate::testutil::test_utilities::setup_test_suite; + use crate::testutil::test_utilities::{setup_no_attribute_response, setup_test_suite}; use crate::{ core::{ error::ContractError, @@ -216,8 +217,10 @@ mod tests { fn test_successful_query_result() { let mut deps = mock_provenance_dependencies(); setup_test_suite(&mut deps, &InstArgs::default()); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()) .expect("expected the asset onboard to succeed"); + // TODO: Add mock for QueryAttributeRequest (singular) here? let binary_from_asset_uuid = query_asset_scope_attribute( &deps.as_ref(), AssetIdentifier::asset_uuid(DEFAULT_ASSET_UUID), @@ -249,6 +252,10 @@ mod tests { fn test_query_failure_for_missing_scope() { let mut deps = mock_provenance_dependencies(); test_instantiate_success(deps.as_mut(), &InstArgs::default()); + ScopeRequest::mock_failed_response( + &mut deps.querier, + String::from("scope fetch failed due to invalid address"), + ); let error = query_asset_scope_attribute( &deps.as_ref(), AssetIdentifier::scope_address("missing-scope-address"), @@ -258,12 +265,8 @@ mod tests { ContractError::Std(e) => match e { StdError::GenericErr { msg, .. } => { assert!( - msg.contains("metadata not found"), - "the error should be from the metadata module", - ); - assert!( - msg.contains("get_scope"), - "the error should denote that the scope fetch was the failure", + msg.contains("scope fetch failed due to invalid address"), + "the error should be due to the metadata module scope fetch" ); } _ => panic!("unexpected StdError encountered: {:?}", e), @@ -288,6 +291,7 @@ mod tests { DEFAULT_SCOPE_SPEC_ADDRESS, "test-owner", ); + setup_no_attribute_response(&mut deps, Some(scope_address.to_owned())); let binary = query_asset_scope_attribute( &deps.as_ref(), AssetIdentifier::scope_address(&scope_address), diff --git a/src/query/query_asset_scope_attribute_by_asset_type.rs b/src/query/query_asset_scope_attribute_by_asset_type.rs index 56ba2abc..ecf9ee46 100644 --- a/src/query/query_asset_scope_attribute_by_asset_type.rs +++ b/src/query/query_asset_scope_attribute_by_asset_type.rs @@ -202,10 +202,11 @@ pub fn may_query_scope_attribute_by_scope_address_and_asset_type< mod tests { use cosmwasm_std::{from_json, StdError}; use provwasm_mocks::mock_provenance_dependencies; + use provwasm_std::types::provenance::metadata::v1::ScopeRequest; use crate::testutil::onboard_asset_helpers::{test_onboard_asset, TestOnboardAsset}; use crate::testutil::test_constants::{DEFAULT_ASSET_TYPE, DEFAULT_SCOPE_ADDRESS}; - use crate::testutil::test_utilities::setup_test_suite; + use crate::testutil::test_utilities::{setup_no_attribute_response, setup_test_suite}; use crate::{ core::{ error::ContractError, @@ -225,6 +226,7 @@ mod tests { fn test_successful_query_result() { let mut deps = mock_provenance_dependencies(); setup_test_suite(&mut deps, &InstArgs::default()); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()) .expect("expected the asset onboard to succeed"); let binary_from_asset_uuid = query_asset_scope_attribute_by_asset_type( @@ -260,6 +262,10 @@ mod tests { fn test_query_failure_for_missing_scope() { let mut deps = mock_provenance_dependencies(); test_instantiate_success(deps.as_mut(), &InstArgs::default()); + ScopeRequest::mock_failed_response( + &mut deps.querier, + String::from("scope fetch failed due to invalid address"), + ); let error = query_asset_scope_attribute_by_asset_type( &deps.as_ref(), AssetIdentifier::scope_address("missing-scope-address"), @@ -270,12 +276,8 @@ mod tests { ContractError::Std(e) => match e { StdError::GenericErr { msg, .. } => { assert!( - msg.contains("metadata not found"), - "the error should be from the metadata module", - ); - assert!( - msg.contains("get_scope"), - "the error should denote that the scope fetch was the failure", + msg.contains("scope fetch failed due to invalid address"), + "the error should be due to the metadata module scope fetch" ); } _ => panic!("unexpected StdError encountered: {:?}", e), @@ -327,6 +329,7 @@ mod tests { DEFAULT_SCOPE_SPEC_ADDRESS, "test-owner", ); + setup_no_attribute_response(&mut deps, Some(scope_address.to_owned())); let binary = query_asset_scope_attribute_by_asset_type( &deps.as_ref(), AssetIdentifier::scope_address(&scope_address), diff --git a/src/service/asset_meta_service.rs b/src/service/asset_meta_service.rs index edf16208..ec1a3575 100644 --- a/src/service/asset_meta_service.rs +++ b/src/service/asset_meta_service.rs @@ -385,6 +385,7 @@ mod tests { }; use crate::testutil::test_utilities::{ empty_mock_info, get_default_asset_definition, get_duped_fee_payment_detail, + setup_no_attribute_response, }; use crate::util::functions::{ try_into_add_attribute_request, try_into_custom_fee_request, @@ -427,7 +428,7 @@ mod tests { use provwasm_mocks::mock_provenance_dependencies; use provwasm_std::types::provenance::attribute::v1::{ Attribute, AttributeType, MsgAddAttributeRequest, MsgUpdateAttributeRequest, - QueryAttributesRequest, QueryAttributesResponse, + QueryAttributeRequest, QueryAttributeResponse, }; use provwasm_std::types::provenance::msgfees::v1::MsgAssessCustomMsgFeeRequest; @@ -435,6 +436,7 @@ mod tests { fn has_asset_returns_false_if_asset_does_not_have_the_attribute() { let mut deps = mock_provenance_dependencies(); setup_test_suite(&mut deps, &InstArgs::default()); + setup_no_attribute_response(&mut deps, None); let repository = AssetMetaService::new(deps.as_mut()); let result = repository .has_asset(DEFAULT_SCOPE_ADDRESS, DEFAULT_ASSET_TYPE) @@ -449,6 +451,7 @@ mod tests { fn has_asset_returns_true_if_asset_has_attribute() { let mut deps = mock_provenance_dependencies(); setup_test_suite(&mut deps, &InstArgs::default()); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()).unwrap(); let repository = AssetMetaService::new(deps.as_mut()); @@ -488,6 +491,7 @@ mod tests { fn add_asset_generates_proper_messages() { let mut deps = mock_provenance_dependencies(); setup_test_suite(&mut deps, &InstArgs::default()); + setup_no_attribute_response(&mut deps, None); let repository = AssetMetaService::new(deps.as_mut()); @@ -568,6 +572,7 @@ mod tests { fn get_asset_returns_error_if_asset_does_not_exist() { let mut deps = mock_provenance_dependencies(); setup_test_suite(&mut deps, &InstArgs::default()); + setup_no_attribute_response(&mut deps, None); let repository = AssetMetaService::new(deps.as_mut()); let err = repository @@ -594,6 +599,7 @@ mod tests { fn get_asset_returns_asset_if_exists() { let mut deps = mock_provenance_dependencies(); setup_test_suite(&mut deps, &InstArgs::default()); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()).unwrap(); let repository = AssetMetaService::new(deps.as_mut()); @@ -612,6 +618,7 @@ mod tests { fn try_get_asset_returns_none_if_asset_does_not_exist() { let mut deps = mock_provenance_dependencies(); setup_test_suite(&mut deps, &InstArgs::default()); + setup_no_attribute_response(&mut deps, None); let repository = AssetMetaService::new(deps.as_mut()); let result = repository @@ -628,6 +635,7 @@ mod tests { fn try_get_asset_returns_asset_if_exists() { let mut deps = mock_provenance_dependencies(); setup_test_suite(&mut deps, &InstArgs::default()); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()).unwrap(); let repository = AssetMetaService::new(deps.as_mut()); @@ -681,9 +689,9 @@ mod tests { fn test_existing_verifier_detail_access_routes_merged() { let mut deps = mock_provenance_dependencies(); // set up existing attribute with pre-existing access routes - QueryAttributesRequest::mock_response( + QueryAttributeRequest::mock_response( &mut deps.querier, - QueryAttributesResponse { + QueryAttributeResponse { account: DEFAULT_SCOPE_ADDRESS.to_string(), attributes: vec![Attribute { name: generate_asset_attribute_name( @@ -832,6 +840,7 @@ mod tests { let mut deps = mock_provenance_dependencies(); let instantiate_args = InstArgs::default(); setup_test_suite(&mut deps, &instantiate_args); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()).unwrap(); // Establish some access routes with blank strings to prove that they get filtered out in the verification process test_verify_asset( @@ -883,6 +892,7 @@ mod tests { let mut deps = mock_provenance_dependencies(); let instantiate_args = InstArgs::default(); setup_test_suite(&mut deps, &instantiate_args); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()).unwrap(); // Establish some access routes with blank strings to prove that they get filtered out in the verification process test_verify_asset( @@ -919,6 +929,7 @@ mod tests { let mut deps = mock_provenance_dependencies(); let instantiate_args = InstArgs::default(); setup_test_suite(&mut deps, &instantiate_args); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()).unwrap(); // Establish some access routes with blank strings to prove that they get filtered out in the verification process test_verify_asset( @@ -966,6 +977,7 @@ mod tests { let mut deps = mock_provenance_dependencies(); let instantiate_args = InstArgs::default(); setup_test_suite(&mut deps, &instantiate_args); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()).unwrap(); // Use two AccessRoutes with the same route but different names test_verify_asset( @@ -1013,6 +1025,7 @@ mod tests { let mut deps = mock_provenance_dependencies(); let instantiate_args = InstArgs::default(); setup_test_suite(&mut deps, &instantiate_args); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()).unwrap(); // Use two AccessRoutes with the same route but different names test_verify_asset( @@ -1064,6 +1077,7 @@ mod tests { let mut deps = mock_provenance_dependencies(); let instantiate_args = InstArgs::default(); setup_test_suite(&mut deps, &instantiate_args); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()).unwrap(); // Use two AccessRoutes with the same route but different names test_verify_asset( @@ -1114,6 +1128,7 @@ mod tests { let mut deps = mock_provenance_dependencies(); let instantiate_args = InstArgs::default(); setup_test_suite(&mut deps, &instantiate_args); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()).unwrap(); // Establish some access routes with blank strings to prove that they get filtered out in the verification process test_verify_asset( @@ -1157,6 +1172,7 @@ mod tests { let mut deps = mock_provenance_dependencies(); let instantiate_args = InstArgs::default(); setup_test_suite(&mut deps, &instantiate_args); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()).unwrap(); let repository = AssetMetaService::new(deps.as_mut()); let original_attribute_value = repository @@ -1261,6 +1277,7 @@ mod tests { let mut deps = mock_provenance_dependencies(); let instantiate_args = InstArgs::default(); setup_test_suite(&mut deps, &instantiate_args); + setup_no_attribute_response(&mut deps, None); test_onboard_asset(&mut deps, TestOnboardAsset::default()).unwrap(); load_fee_payment_detail( deps.as_ref().storage, diff --git a/src/testutil/test_utilities.rs b/src/testutil/test_utilities.rs index e115fa6f..25a3df47 100644 --- a/src/testutil/test_utilities.rs +++ b/src/testutil/test_utilities.rs @@ -228,11 +228,20 @@ pub fn setup_test_suite(deps: &mut MockOwnedDeps, args: &InstArgs) { }, ); RecordsRequest::mock_response(&mut deps.querier, get_default_records()); - // TODO: May be incorrect to put these here +} + +/// Sets up mock queries for no attributes to be returned for a given scope address (defaults to the happy path address). +/// This can be called before [test_onboard_asset](crate::testutil::onboard_asset_helpers::test_onboard_asset) +/// if a successful asset onboarding outcome is desired to ensure that there is no existing conflicting attribute +/// on an asset that would prevent its onboarding. [intercept_add_or_update_attribute] will then update the mock attribute +/// query result after onboarding to mark the asset as onboarded. +pub fn setup_no_attribute_response(deps: &mut MockOwnedDeps, address: Option) { QueryAttributeRequest::mock_response( &mut deps.querier, QueryAttributeResponse { - account: args.env.contract.address.to_string(), + account: address + .to_owned() + .unwrap_or(DEFAULT_SCOPE_ADDRESS.to_string()), attributes: vec![], pagination: None, }, @@ -240,12 +249,11 @@ pub fn setup_test_suite(deps: &mut MockOwnedDeps, args: &InstArgs) { QueryAttributesRequest::mock_response( &mut deps.querier, QueryAttributesResponse { - account: args.env.contract.address.to_string(), + account: address.unwrap_or(DEFAULT_SCOPE_ADDRESS.to_string()), attributes: vec![], pagination: None, }, ); - // END TODO } pub fn test_instantiate_success(deps: DepsMut, args: &InstArgs) -> Response {