Skip to content

Commit 16d73bc

Browse files
committed
fix(tests): node accounts in the handle factory; shared deposit in the config test
MpcCluster::contract_handle resolved keys via user_accounts only, so propose_and_vote_contract_update panicked with "unknown user account" for the node accounts that propose and vote; the lookup now falls back to node_keys. test_propose_update_config attached a hardcoded 0.1 NEAR, which the shared deposit rule (32 KiB overhead + payload = ~0.335 NEAR for a config proposal) rejects; the test computes the deposit through the shared function instead.
1 parent c9c4cea commit 16d73bc

2 files changed

Lines changed: 29 additions & 8 deletions

File tree

crates/contract/tests/sandbox/upgrade_from_current_contract.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ use crate::sandbox::{
1616
},
1717
};
1818
use mpc_contract::update::UpdateId;
19+
use near_mpc_contract_interface::deposits::{
20+
STORAGE_BYTE_COST_YOCTONEAR, propose_update_required_deposit_yoctonear,
21+
};
1922
use near_mpc_contract_interface::method_names;
2023
use near_mpc_contract_interface::types::{ProposeUpdateArgs, ProtocolContractState};
2124
use near_workspaces::types::NearToken;
@@ -124,15 +127,26 @@ async fn test_propose_update_config() {
124127
resolve_verification_tera_gas: 16,
125128
};
126129

130+
let propose_args = ProposeUpdateArgs {
131+
code: None,
132+
config: Some(new_config.clone()),
133+
};
134+
let deposit = NearToken::from_yoctonear(
135+
propose_update_required_deposit_yoctonear(
136+
propose_args
137+
.payload_bytes()
138+
.expect("config serializes to JSON"),
139+
STORAGE_BYTE_COST_YOCTONEAR,
140+
)
141+
.expect("the deposit for a config proposal fits in u128"),
142+
);
143+
127144
let mut proposals = Vec::with_capacity(mpc_signer_accounts.len());
128145
for account in &mpc_signer_accounts {
129146
let propose_execution = account
130147
.call(contract.id(), method_names::PROPOSE_UPDATE)
131-
.args_borsh((ProposeUpdateArgs {
132-
code: None,
133-
config: Some(new_config.clone()),
134-
},))
135-
.deposit(NearToken::from_millinear(100))
148+
.args_borsh((propose_args.clone(),))
149+
.deposit(deposit)
136150
.transact()
137151
.await
138152
.unwrap();

crates/e2e-tests/src/cluster.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -792,17 +792,24 @@ impl MpcCluster {
792792
Ok(())
793793
}
794794

795-
pub fn user_client(&self, account_id: &AccountId) -> anyhow::Result<NearKitCaller> {
795+
pub fn client_for(&self, account_id: &AccountId) -> anyhow::Result<NearKitCaller> {
796796
let key = self
797797
.user_accounts
798798
.get(account_id)
799-
.with_context(|| format!("unknown user account: {account_id}"))?;
799+
.or_else(|| {
800+
self.nodes
801+
.iter()
802+
.zip(self.node_keys.iter())
803+
.find(|(node, _)| node.account_id() == account_id)
804+
.map(|(_, key)| key)
805+
})
806+
.with_context(|| format!("unknown account: {account_id}"))?;
800807
self.blockchain.client_for(account_id.as_ref(), key)
801808
}
802809

803810
pub fn contract_handle(&self, account_id: &AccountId) -> MpcContractHandle<NearKitCaller> {
804811
self.contract
805-
.handle_for(self.user_client(account_id).unwrap())
812+
.handle_for(self.client_for(account_id).unwrap())
806813
}
807814

808815
pub fn default_user_account(&self) -> &AccountId {

0 commit comments

Comments
 (0)