@@ -10,9 +10,9 @@ use crate::sandbox::{
1010 interface:: IntoContractType ,
1111 mpc_contract:: {
1212 assert_running_return_participants, assert_running_return_threshold,
13- get_participant_attestation , get_state , get_tee_accounts ,
14- prepay_and_submit_participant_info , prepay_attestation_grants , submit_participant_info ,
15- vote_add_launcher_hash, vote_for_hash,
13+ available_attestation_grants , get_config , get_participant_attestation , get_state ,
14+ get_tee_accounts , prepay_and_submit_participant_info , prepay_attestation_grants ,
15+ submit_participant_info , vote_add_launcher_hash, vote_for_hash,
1616 } ,
1717 resharing_utils:: conclude_resharing,
1818 sign_utils:: DomainResponseTest ,
@@ -25,13 +25,22 @@ use mpc_primitives::hash::{LauncherDockerComposeHash, LauncherImageHash, NodeIma
2525use near_mpc_contract_interface:: deposits:: STORAGE_BYTE_COST_YOCTONEAR ;
2626use near_mpc_contract_interface:: method_names;
2727use near_mpc_contract_interface:: types:: {
28- self as dtos, Attestation , Config , MockAttestation , Protocol ,
28+ self as dtos, Attestation , MockAttestation , Protocol , VerifiedAttestation ,
2929} ;
3030use near_workspaces:: types:: { KeyType , NearToken , SecretKey } ;
3131use near_workspaces:: { AccessKey , Account , Contract } ;
3232use rand:: SeedableRng ;
3333use test_utils:: attestation:: { image_digest, p2p_tls_key} ;
3434
35+ fn mock_expiring_at ( expiry_timestamp_seconds : u64 ) -> MockAttestation {
36+ MockAttestation :: WithConstraints {
37+ mpc_docker_image_hash : None ,
38+ launcher_docker_compose_hash : None ,
39+ expiry_timestamp_seconds : Some ( expiry_timestamp_seconds) ,
40+ expected_measurements : None ,
41+ }
42+ }
43+
3544/// Tests the basic code hash voting mechanism including threshold behavior and vote stability.
3645/// Validates that votes below threshold don't allow hashes, reaching threshold allows them,
3746/// and additional votes don't change the allowed state or latest hash.
@@ -457,12 +466,7 @@ async fn clean_invalid_attestations__should_remove_expired_entries() -> Result<(
457466 let block_info = worker. view_block ( ) . await ?;
458467 let expiry_timestamp_seconds =
459468 block_info. timestamp ( ) / 1_000_000_000 + ATTESTATION_EXPIRY_SECONDS ;
460- let expiring_attestation = Attestation :: Mock ( MockAttestation :: WithConstraints {
461- mpc_docker_image_hash : None ,
462- launcher_docker_compose_hash : None ,
463- expiry_timestamp_seconds : Some ( expiry_timestamp_seconds) ,
464- expected_measurements : None ,
465- } ) ;
469+ let expiring_attestation = Attestation :: Mock ( mock_expiring_at ( expiry_timestamp_seconds) ) ;
466470 let submit_result = prepay_and_submit_participant_info (
467471 stale_account,
468472 & contract,
@@ -595,10 +599,9 @@ async fn get_attestation_returns_none_when_tls_key_is_not_associated_with_an_att
595599
596600 assert ! ( validation_success) ;
597601
598- let attestation_for_tls_key_2: Option < Attestation > =
599- get_participant_attestation ( & contract, & tls_key_2)
600- . await
601- . unwrap ( ) ;
602+ let attestation_for_tls_key_2 = get_participant_attestation ( & contract, & tls_key_2)
603+ . await
604+ . unwrap ( ) ;
602605
603606 assert_eq ! ( attestation_for_tls_key_2, None ) ;
604607}
@@ -630,19 +633,10 @@ async fn get_attestation_returns_some_when_tls_key_associated_with_an_attestatio
630633 // as-is (a stored mock's expiry is `min(submitted, now + default window)`) and
631634 // the two attestations stay distinct.
632635 let now_seconds = worker. view_block ( ) . await . unwrap ( ) . timestamp ( ) / 1_000_000_000 ;
633- let participant_1_attestation = Attestation :: Mock ( MockAttestation :: WithConstraints {
634- mpc_docker_image_hash : None ,
635- launcher_docker_compose_hash : None ,
636- expiry_timestamp_seconds : Some ( now_seconds + 1_000 ) ,
637- expected_measurements : None ,
638- } ) ;
636+ let participant_1_attestation = Attestation :: Mock ( mock_expiring_at ( now_seconds + 1_000 ) ) ;
639637
640- let participant_2_attestation = Attestation :: Mock ( MockAttestation :: WithConstraints {
641- mpc_docker_image_hash : None ,
642- launcher_docker_compose_hash : None ,
643- expiry_timestamp_seconds : Some ( now_seconds + 2_000 ) ,
644- expected_measurements : None ,
645- } ) ;
638+ let participant_2_mock = mock_expiring_at ( now_seconds + 2_000 ) ;
639+ let participant_2_attestation = Attestation :: Mock ( participant_2_mock. clone ( ) ) ;
646640
647641 assert_ne ! (
648642 participant_1_attestation, participant_2_attestation,
@@ -671,12 +665,14 @@ async fn get_attestation_returns_some_when_tls_key_associated_with_an_attestatio
671665 . is_success ( ) ;
672666 assert ! ( validation_success, "Submitting attestation failed." ) ;
673667
674- let attestation_for_tls_key_2: Option < Attestation > =
675- get_participant_attestation ( & contract, & tls_key_2)
676- . await
677- . unwrap ( ) ;
668+ let attestation_for_tls_key_2 = get_participant_attestation ( & contract, & tls_key_2)
669+ . await
670+ . unwrap ( ) ;
678671
679- assert_eq ! ( attestation_for_tls_key_2, Some ( participant_2_attestation) ) ;
672+ assert_eq ! (
673+ attestation_for_tls_key_2,
674+ Some ( VerifiedAttestation :: Mock ( participant_2_mock) )
675+ ) ;
680676}
681677
682678#[ tokio:: test]
@@ -698,19 +694,10 @@ async fn get_attestation_overwrites_when_same_tls_key_is_reused() {
698694 // as-is (a stored mock's expiry is `min(submitted, now + default window)`) and
699695 // the two attestations stay distinct.
700696 let now_seconds = worker. view_block ( ) . await . unwrap ( ) . timestamp ( ) / 1_000_000_000 ;
701- let first_attestation = Attestation :: Mock ( MockAttestation :: WithConstraints {
702- mpc_docker_image_hash : None ,
703- launcher_docker_compose_hash : None ,
704- expiry_timestamp_seconds : Some ( now_seconds + 1_000 ) ,
705- expected_measurements : None ,
706- } ) ;
697+ let first_attestation = Attestation :: Mock ( mock_expiring_at ( now_seconds + 1_000 ) ) ;
707698
708- let second_attestation = Attestation :: Mock ( MockAttestation :: WithConstraints {
709- mpc_docker_image_hash : None ,
710- launcher_docker_compose_hash : None ,
711- expiry_timestamp_seconds : Some ( now_seconds + 2_000 ) ,
712- expected_measurements : None ,
713- } ) ;
699+ let second_mock = mock_expiring_at ( now_seconds + 2_000 ) ;
700+ let second_attestation = Attestation :: Mock ( second_mock. clone ( ) ) ;
714701
715702 assert_ne ! (
716703 first_attestation, second_attestation,
@@ -742,14 +729,13 @@ async fn get_attestation_overwrites_when_same_tls_key_is_reused() {
742729 assert ! ( validation_success, "Second attestation submission failed" ) ;
743730
744731 // Now the latest attestation should be returned
745- let attestation_for_tls_key: Option < Attestation > =
746- get_participant_attestation ( & contract, & tls_key)
747- . await
748- . unwrap ( ) ;
732+ let attestation_for_tls_key = get_participant_attestation ( & contract, & tls_key)
733+ . await
734+ . unwrap ( ) ;
749735
750736 assert_eq ! (
751737 attestation_for_tls_key,
752- Some ( second_attestation ) ,
738+ Some ( VerifiedAttestation :: Mock ( second_mock ) ) ,
753739 "Expected the second attestation to overwrite the first for the same TLS key"
754740 ) ;
755741}
@@ -841,12 +827,7 @@ async fn test_verify_tee_expired_attestation_triggers_resharing() -> Result<()>
841827 . find ( |node| node. account_id == * target_account. id ( ) )
842828 . expect ( "target participant not found" ) ;
843829
844- let expiring_attestation = Attestation :: Mock ( MockAttestation :: WithConstraints {
845- mpc_docker_image_hash : None ,
846- launcher_docker_compose_hash : None ,
847- expiry_timestamp_seconds : Some ( expiry_timestamp) ,
848- expected_measurements : None ,
849- } ) ;
830+ let expiring_attestation = Attestation :: Mock ( mock_expiring_at ( expiry_timestamp) ) ;
850831
851832 let submit_result = submit_participant_info (
852833 target_account,
@@ -963,12 +944,7 @@ async fn verify_tee__should_keep_participants_and_stop_signing_when_kickout_drop
963944 // Compute the expiry timestamp from the current block time.
964945 let block_info = worker. view_block ( ) . await ?;
965946 let expiry_timestamp = block_info. timestamp ( ) / 1_000_000_000 + ATTESTATION_EXPIRY_SECONDS ;
966- let expiring_attestation = Attestation :: Mock ( MockAttestation :: WithConstraints {
967- mpc_docker_image_hash : None ,
968- launcher_docker_compose_hash : None ,
969- expiry_timestamp_seconds : Some ( expiry_timestamp) ,
970- expected_measurements : None ,
971- } ) ;
947+ let expiring_attestation = Attestation :: Mock ( mock_expiring_at ( expiry_timestamp) ) ;
972948
973949 // Submit an expiring attestation for every participant past the first `remaining_valid`.
974950 let internal_participants: Participants = ( & initial_participants) . into_contract_type ( ) ;
@@ -1088,11 +1064,7 @@ async fn prepay_and_submit_a_constrained_mock__should_use_at_most_half_a_grant_f
10881064 } ) ;
10891065 let node = worker. dev_create_account ( ) . await ?;
10901066 let tls_key = bogus_ed25519_public_key ( ) ;
1091- let config: Config = contract
1092- . view ( method_names:: CONFIG )
1093- . args_json ( serde_json:: json!( { } ) )
1094- . await ?
1095- . json ( ) ?;
1067+ let config = get_config ( & contract) . await ?;
10961068 let before = contract. as_account ( ) . view_account ( ) . await ?;
10971069
10981070 // When
@@ -1102,11 +1074,7 @@ async fn prepay_and_submit_a_constrained_mock__should_use_at_most_half_a_grant_f
11021074 assert ! ( submission. is_success( ) , "submission failed: {submission:?}" ) ;
11031075
11041076 // Then
1105- let remaining: u32 = contract
1106- . view ( method_names:: AVAILABLE_ATTESTATION_GRANTS )
1107- . args_json ( serde_json:: json!( { "account_id" : node. id( ) } ) )
1108- . await ?
1109- . json ( ) ?;
1077+ let remaining = available_attestation_grants ( & contract, node. id ( ) ) . await ?;
11101078 assert_eq ! ( remaining, GRANTS - 1 , "the row must outlive the submission" ) ;
11111079
11121080 let after = contract. as_account ( ) . view_account ( ) . await ?;
@@ -1163,11 +1131,7 @@ async fn submit_participant_info__should_store_a_new_entry_against_a_prepaid_gra
11631131 ) ;
11641132 let stored = get_participant_attestation ( & contract, & fresh_tls_key) . await ?;
11651133 assert ! ( stored. is_some( ) , "the entry should be stored on-chain" ) ;
1166- let remaining: u32 = contract
1167- . view ( method_names:: AVAILABLE_ATTESTATION_GRANTS )
1168- . args_json ( serde_json:: json!( { "account_id" : outsider. id( ) } ) )
1169- . await ?
1170- . json ( ) ?;
1134+ let remaining = available_attestation_grants ( & contract, outsider. id ( ) ) . await ?;
11711135 assert_eq ! ( remaining, 0 , "storing a new entry should consume the grant" ) ;
11721136 Ok ( ( ) )
11731137}
0 commit comments