use crate::sandbox::{ common::SandboxTestSetup, upgrade_from_current_contract::current_contract_proposal, utils::consts::{CURRENT_CONTRACT_DEPLOY_DEPOSIT, GAS_FOR_VOTE_UPDATE}, }; use mpc_contract::update::UpdateId; use near_mpc_contract_interface::method_names; #[tokio::test] async fn test_high_gas_deposit_config_value_passes_upgrades() { let (saw_completion, saw_failure) = run_upgrade_scenario(1).await; assert!(saw_completion, "Update never completed"); assert!(!saw_failure, "Upgrade unexpectedly failed"); } #[tokio::test] async fn test_zero_gas_deposit_config_value_fails_upgrades() { let (saw_completion, saw_failure) = run_upgrade_scenario(0).await; assert!( saw_failure, "Upgrade never failed; expected failure with zero gas" ); assert!( !saw_completion, "Upgrade unexpectedly completed with zero gas" ); } async fn run_upgrade_scenario(min_gas: u64) -> (bool, bool) { let init_config = near_mpc_contract_interface::types::InitConfig { contract_upgrade_deposit_tera_gas: Some(min_gas), ..Default::default() }; let SandboxTestSetup { contract, mpc_signer_accounts, .. } = SandboxTestSetup::builder() .with_init_config(init_config) .with_number_of_participants(3) .build() .await; let execution = mpc_signer_accounts[0] .call(contract.id(), method_names::PROPOSE_UPDATE) .args_borsh(current_contract_proposal()) .max_gas() .deposit(CURRENT_CONTRACT_DEPLOY_DEPOSIT) .transact() .await .unwrap(); assert!(execution.is_success()); let proposal_id: UpdateId = execution.json().unwrap(); let mut saw_completion = false; let mut saw_failure = false; for voter in mpc_signer_accounts { let execution = voter .call(contract.id(), method_names::VOTE_UPDATE) .args_json(serde_json::json!({ "id": proposal_id })) .gas(GAS_FOR_VOTE_UPDATE) .transact() .await .unwrap(); dbg!(&execution); if !execution.is_success() { saw_failure = true; break; } let update_completed: bool = execution.json().expect("Vote cast was unsuccessful"); if update_completed { saw_completion = true; break; } } (saw_completion, saw_failure) } #[tokio::test] async fn contract_configuration_can_be_set_on_initialization() { let init_config = near_mpc_contract_interface::types::InitConfig { key_event_timeout_blocks: Some(11), tee_upgrade_deadline_duration_seconds: Some(22), contract_upgrade_deposit_tera_gas: Some(33), sign_call_gas_attachment_requirement_tera_gas: Some(44), ckd_call_gas_attachment_requirement_tera_gas: Some(55), return_signature_and_clean_state_on_success_call_tera_gas: Some(66), return_ck_and_clean_state_on_success_call_tera_gas: Some(77), fail_on_timeout_tera_gas: Some(88), clean_tee_status_tera_gas: Some(99), clean_invalid_attestations_tera_gas: Some(101), cleanup_orphaned_node_migrations_tera_gas: Some(11), remove_non_participant_update_votes_tera_gas: Some(12), clean_foreign_chain_data_tera_gas: Some(13), remove_non_participant_tee_verifier_votes_tera_gas: Some(14), }; let SandboxTestSetup { contract, .. } = SandboxTestSetup::builder() .with_init_config(init_config.clone()) .with_number_of_participants(2) .build() .await; let stored_config: near_mpc_contract_interface::types::InitConfig = contract .view(method_names::CONFIG) .await .unwrap() .json() .unwrap(); assert_eq!(stored_config, init_config); }