Skip to content

Commit

Permalink
256/269 unit tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
rpatel-figure committed Oct 30, 2024
1 parent cb2d8e0 commit 51a118b
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 42 deletions.
72 changes: 55 additions & 17 deletions src/execute/onboard_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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()),
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -697,6 +710,7 @@ mod tests {
request: None,
},
);
setup_no_attribute_response(&mut deps, None);
onboard_asset(
AssetMetaService::new(deps.as_mut()),
mock_env(),
Expand All @@ -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 {
Expand All @@ -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,
},
);
Expand Down Expand Up @@ -806,6 +830,7 @@ mod tests {
request: None,
},
);
setup_no_attribute_response(&mut deps, None);
onboard_asset(
AssetMetaService::new(deps.as_mut()),
mock_env(),
Expand All @@ -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()),
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -1499,6 +1536,7 @@ mod tests {
let get_onboard_result = |permission_spec: Option<bool>| {
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(),
Expand Down
15 changes: 12 additions & 3 deletions src/execute/update_access_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -211,15 +212,15 @@ 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]
fn test_error_for_provided_funds() {
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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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(
Expand Down
Loading

0 comments on commit 51a118b

Please sign in to comment.