From e6d4e2431cc36987573b7b44958a6a52cba955f0 Mon Sep 17 00:00:00 2001 From: Rivers Yang Date: Tue, 18 Oct 2022 22:54:52 +0800 Subject: [PATCH 01/15] Change data structure of appchain messages. --- appchain-anchor/src/appchain_messages.rs | 6 + .../src/assets/wrapped_appchain_nfts.rs | 4 +- appchain-anchor/src/interfaces.rs | 2 +- appchain-anchor/src/lib.rs | 3 +- .../src/permissionless_actions/mod.rs | 249 ++++++++++-------- appchain-anchor/src/storage_migration.rs | 148 +++++++++++ appchain-anchor/src/types.rs | 69 ----- tests/simulator/common/complex_viewer.rs | 25 +- .../contract_interfaces/anchor_viewer.rs | 14 +- .../permissionless_actions.rs | 41 ++- .../contract_interfaces/settings_manager.rs | 16 -- tests/simulator/main.rs | 2 +- ...client.rs => test_beefy_light_client_1.rs} | 66 ++--- tests/simulator/test_beefy_light_client_2.rs | 36 +-- tests/simulator/test_migration.rs | 18 +- tests/simulator/test_transfer_native_near.rs | 3 +- tests/simulator/test_transfer_nft.rs | 5 +- .../simulator/test_wrapped_appchain_token.rs | 27 +- 18 files changed, 413 insertions(+), 321 deletions(-) rename tests/simulator/{test_beefy_light_client.rs => test_beefy_light_client_1.rs} (90%) diff --git a/appchain-anchor/src/appchain_messages.rs b/appchain-anchor/src/appchain_messages.rs index 9fcbfb3..096b395 100644 --- a/appchain-anchor/src/appchain_messages.rs +++ b/appchain-anchor/src/appchain_messages.rs @@ -18,6 +18,7 @@ pub struct BurnAssetPayload { pub sender: String, pub receiver_id: AccountId, pub amount: u128, + pub fee: u128, } #[derive(Clone, Serialize, Deserialize, BorshDeserialize, BorshSerialize)] @@ -26,6 +27,7 @@ pub struct LockPayload { pub sender: String, pub receiver_id: AccountId, pub amount: u128, + pub fee: u128, } #[derive(Clone, Serialize, Deserialize, BorshDeserialize, BorshSerialize)] @@ -58,6 +60,7 @@ pub struct LockNftPayload { pub class: u128, pub instance: u128, pub metadata: TokenMetadata, + pub fee: u128, } #[derive(BorshDeserialize, BorshSerialize, Serialize, Deserialize, Clone)] @@ -290,6 +293,7 @@ impl AppchainAnchor { owner_id_in_appchain: payload.sender, receiver_id_in_near: payload.receiver_id, amount: payload.amount.into(), + fee: payload.fee.into(), }, }); } @@ -317,6 +321,7 @@ impl AppchainAnchor { owner_id_in_appchain: payload.sender, receiver_id_in_near: payload.receiver_id, amount: payload.amount.into(), + fee: payload.fee.into(), }, }); } @@ -416,6 +421,7 @@ impl AppchainAnchor { class_id: payload.class.to_string(), instance_id: payload.instance.to_string(), token_metadata: payload.metadata, + fee: payload.fee.into(), }, }); } diff --git a/appchain-anchor/src/assets/wrapped_appchain_nfts.rs b/appchain-anchor/src/assets/wrapped_appchain_nfts.rs index 2bc1eb1..01b1729 100644 --- a/appchain-anchor/src/assets/wrapped_appchain_nfts.rs +++ b/appchain-anchor/src/assets/wrapped_appchain_nfts.rs @@ -314,7 +314,7 @@ impl AppchainAnchor { appchain_message_nonce, ), ); - processing_context.add_prepaid_gas(Gas::ONE_TERA.mul(T_GAS_FOR_FT_TRANSFER)); + processing_context.add_prepaid_gas(Gas::ONE_TERA.mul(T_GAS_FOR_NFT_TRANSFER)); processing_context.add_prepaid_gas(Gas::ONE_TERA.mul(T_GAS_FOR_RESOLVER_FUNCTION)); MultiTxsOperationProcessingResult::Ok } else { @@ -353,7 +353,7 @@ impl AppchainAnchor { appchain_message_nonce, ), ); - processing_context.add_prepaid_gas(Gas::ONE_TERA.mul(T_GAS_FOR_FT_TRANSFER)); + processing_context.add_prepaid_gas(Gas::ONE_TERA.mul(T_GAS_FOR_MINT_NFT)); processing_context.add_prepaid_gas(Gas::ONE_TERA.mul(T_GAS_FOR_RESOLVER_FUNCTION)); MultiTxsOperationProcessingResult::Ok } diff --git a/appchain-anchor/src/interfaces.rs b/appchain-anchor/src/interfaces.rs index 70b4da9..28038bd 100644 --- a/appchain-anchor/src/interfaces.rs +++ b/appchain-anchor/src/interfaces.rs @@ -238,7 +238,7 @@ pub trait PermissionlessActions { header: Vec, mmr_leaf_for_header: Vec, mmr_proof_for_header: Vec, - ); + ) -> MultiTxsOperationProcessingResult; } pub trait ProtocolSettingsManager { diff --git a/appchain-anchor/src/lib.rs b/appchain-anchor/src/lib.rs index c7b2757..e59a526 100644 --- a/appchain-anchor/src/lib.rs +++ b/appchain-anchor/src/lib.rs @@ -59,11 +59,10 @@ const T_GAS_FOR_FT_TRANSFER: u64 = 10; const T_GAS_FOR_BURN_FUNGIBLE_TOKEN: u64 = 10; const T_GAS_FOR_MINT_FUNGIBLE_TOKEN: u64 = 20; const T_GAS_FOR_NFT_TRANSFER: u64 = 10; -const T_GAS_FOR_MINT_NFT: u64 = 10; +const T_GAS_FOR_MINT_NFT: u64 = 20; const T_GAS_FOR_RESOLVER_FUNCTION: u64 = 10; const T_GAS_FOR_SYNC_STATE_TO_REGISTRY: u64 = 10; const T_GAS_CAP_FOR_MULTI_TXS_PROCESSING: u64 = 130; -const T_GAS_CAP_FOR_PROCESSING_APPCHAIN_MESSAGES: u64 = 240; const T_GAS_FOR_NFT_CONTRACT_INITIALIZATION: u64 = 50; const T_GAS_FOR_REGISTER_VALIDATOR: u64 = 100; const T_GAS_FOR_BURN_WRAPPED_APPCHAIN_TOKEN: u64 = 50; diff --git a/appchain-anchor/src/permissionless_actions/mod.rs b/appchain-anchor/src/permissionless_actions/mod.rs index 3982b8f..73f4344 100644 --- a/appchain-anchor/src/permissionless_actions/mod.rs +++ b/appchain-anchor/src/permissionless_actions/mod.rs @@ -20,12 +20,14 @@ pub enum AppchainEvent { owner_id_in_appchain: String, receiver_id_in_near: AccountId, amount: U128, + fee: U128, }, /// The fact that a certain amount of appchain native token has been locked in the appchain. NativeTokenLocked { owner_id_in_appchain: String, receiver_id_in_near: AccountId, amount: U128, + fee: U128, }, /// The fact that the era switch is planed in the appchain. EraSwitchPlaned { era_number: u32 }, @@ -43,12 +45,7 @@ pub enum AppchainEvent { class_id: String, instance_id: String, token_metadata: TokenMetadata, - }, - /// The fact that a certain amount of bridged native NEAR token has been burnt in the appchain. - NativeNearTokenBurnt { - owner_id_in_appchain: String, - receiver_id_in_near: AccountId, - amount: U128, + fee: U128, }, } @@ -238,69 +235,7 @@ impl PermissionlessActions for AppchainAnchor { } // fn process_appchain_messages(&mut self) -> MultiTxsOperationProcessingResult { - let processing_status = self.permissionless_actions_status.get().unwrap(); - let appchain_messages = self.appchain_messages.get().unwrap(); - let mut processing_context = AppchainMessagesProcessingContext::new(processing_status); - let mut validator_set_histories = self.validator_set_histories.get().unwrap(); - let mut result = MultiTxsOperationProcessingResult::Ok; - while processing_context.used_gas_of_current_function_call() - < Gas::ONE_TERA.mul(T_GAS_CAP_FOR_MULTI_TXS_PROCESSING) - && env::used_gas() < Gas::ONE_TERA.mul(T_GAS_CAP_FOR_PROCESSING_APPCHAIN_MESSAGES) - { - if let Some(processing_nonce) = processing_context.processing_nonce() { - if appchain_messages - .get_processing_result(&processing_nonce) - .is_some() - { - processing_context.clear_processing_nonce(); - processing_context.set_latest_applied_nonce(processing_nonce); - result = MultiTxsOperationProcessingResult::Ok; - continue; - } - if let Some(appchain_message) = appchain_messages.get_message(&processing_nonce) { - result = self.internal_apply_appchain_message( - &mut processing_context, - &mut validator_set_histories, - &appchain_message, - ); - match result { - MultiTxsOperationProcessingResult::Ok => { - processing_context.clear_processing_nonce(); - processing_context.set_latest_applied_nonce(processing_nonce); - } - MultiTxsOperationProcessingResult::NeedMoreGas => (), - MultiTxsOperationProcessingResult::Error(..) => { - // The loop should continue even if it fails to apply a certain message - processing_context.clear_processing_nonce(); - processing_context.set_latest_applied_nonce(processing_nonce); - result = MultiTxsOperationProcessingResult::Ok; - } - } - } else { - result = MultiTxsOperationProcessingResult::Error(format!( - "Missing appchain message with nonce '{}'.", - processing_nonce - )); - break; - } - } else { - if processing_context.latest_applied_nonce() < processing_context.max_nonce() { - processing_context - .set_processing_nonce(processing_context.latest_applied_nonce() + 1); - } else { - break; - } - } - } - self.permissionless_actions_status - .set(processing_context.processing_status()); - self.validator_set_histories.set(&validator_set_histories); - if result.is_ok() - && processing_context.latest_applied_nonce() < processing_context.max_nonce() - { - result = MultiTxsOperationProcessingResult::NeedMoreGas; - } - result + self.internal_process_appchain_message(None) } // fn commit_appchain_challenge(&mut self, appchain_challenge: AppchainChallenge) { @@ -328,7 +263,7 @@ impl PermissionlessActions for AppchainAnchor { header: Vec, mmr_leaf_for_header: Vec, mmr_proof_for_header: Vec, - ) { + ) -> MultiTxsOperationProcessingResult { self.assert_light_client_is_ready(); let mut light_client = self.beefy_light_client_state.get().unwrap(); match light_client.update_state( @@ -351,6 +286,11 @@ impl PermissionlessActions for AppchainAnchor { Err(beefy_light_client::Error::CommitmentAlreadyUpdated) => {} Err(err) => panic!("Failed to update state of beefy light client: {:?}", err), } + if encoded_messages.len() == 0 { + return MultiTxsOperationProcessingResult::Error(format!( + "State of beefy light client has been updated. But there is no message data to be processed." + )); + } if let Err(err) = light_client.verify_solochain_messages( &encoded_messages, &header, @@ -361,26 +301,98 @@ impl PermissionlessActions for AppchainAnchor { } let messages = Decode::decode(&mut &encoded_messages[..]).unwrap(); self.internal_stage_appchain_messages(&messages); + let appchain_messages = self.appchain_messages.get().unwrap(); + let result = if appchain_messages + .get_processing_result(&messages[0].nonce()) + .is_some() + { + MultiTxsOperationProcessingResult::Ok + } else { + if env::prepaid_gas() - env::used_gas() + > Gas::ONE_TERA.mul(T_GAS_CAP_FOR_MULTI_TXS_PROCESSING) + { + self.internal_process_appchain_message(Some(messages[0].nonce())) + } else { + log!("Remained gas is not enough to process an appchain message. Please call function 'process_appchain_messages' to continue."); + MultiTxsOperationProcessingResult::NeedMoreGas + } + }; + if messages.len() > 1 { + log!("There are more appchain message(s) need to be applied. Please call function 'process_appchain_messages' to continue."); + } + result + } +} + +impl AppchainAnchor { + /// Process a certain `AppchainMesaage` + pub fn internal_process_appchain_message( + &mut self, + nonce: Option, + ) -> MultiTxsOperationProcessingResult { let processing_status = self.permissionless_actions_status.get().unwrap(); + let appchain_messages = self.appchain_messages.get().unwrap(); let mut processing_context = AppchainMessagesProcessingContext::new(processing_status); let mut validator_set_histories = self.validator_set_histories.get().unwrap(); - messages.iter().for_each(|raw_message| { - let appchain_messages = self.appchain_messages.get().unwrap(); + let mut result = MultiTxsOperationProcessingResult::Ok; + if processing_context.processing_nonce().is_none() { + if let Some(nonce) = nonce { + processing_context.set_processing_nonce(nonce); + } else if processing_context.latest_applied_nonce() < processing_context.max_nonce() { + processing_context + .set_processing_nonce(processing_context.latest_applied_nonce() + 1); + } + } + if let Some(processing_nonce) = processing_context.processing_nonce() { if appchain_messages - .get_processing_result(&raw_message.nonce()) + .get_processing_result(&processing_nonce) .is_none() { - self.internal_apply_appchain_message( - &mut processing_context, - &mut validator_set_histories, - &appchain_messages.get_message(&raw_message.nonce()).unwrap(), - ); + if let Some(appchain_message) = appchain_messages.get_message(&processing_nonce) { + let start_gas = env::used_gas(); + result = self.internal_apply_appchain_message( + &mut processing_context, + &mut validator_set_histories, + &appchain_message, + ); + log!( + "Gas used for appchain message '{}': {}", + appchain_message.nonce, + (env::used_gas() - start_gas).0 + ); + match result { + MultiTxsOperationProcessingResult::Ok => { + processing_context.clear_processing_nonce(); + processing_context.set_latest_applied_nonce(processing_nonce); + } + MultiTxsOperationProcessingResult::NeedMoreGas => (), + MultiTxsOperationProcessingResult::Error(..) => { + // The loop should continue even if it fails to apply a certain message + processing_context.clear_processing_nonce(); + processing_context.set_latest_applied_nonce(processing_nonce); + result = MultiTxsOperationProcessingResult::Ok; + } + } + } else { + result = MultiTxsOperationProcessingResult::Error(format!( + "Missing appchain message with nonce '{}'.", + processing_nonce + )); + } + } else { + processing_context.clear_processing_nonce(); } - }); + } + self.permissionless_actions_status + .set(processing_context.processing_status()); + self.validator_set_histories.set(&validator_set_histories); + if result.is_ok() + && processing_context.latest_applied_nonce() < processing_context.max_nonce() + { + result = MultiTxsOperationProcessingResult::NeedMoreGas; + } + result } -} - -impl AppchainAnchor { /// Apply a certain `AppchainMessage` pub fn internal_apply_appchain_message( &mut self, @@ -394,6 +406,7 @@ impl AppchainAnchor { owner_id_in_appchain, receiver_id_in_near, amount, + fee, } => { if self.asset_transfer_is_paused { let message = format!("Asset transfer is now paused."); @@ -428,19 +441,31 @@ impl AppchainAnchor { self.record_appchain_message_processing_result(&result); return MultiTxsOperationProcessingResult::Error(message); } - self.internal_unlock_near_fungible_token( + let mut result = self.internal_unlock_near_fungible_token( owner_id_in_appchain, &contract_account_id.unwrap(), receiver_id_in_near, amount, appchain_message.nonce, processing_context, - ) + ); + if result.is_ok() { + let anchor_settings = self.anchor_settings.get().unwrap(); + result = self.internal_mint_wrapped_appchain_token( + Some(owner_id_in_appchain), + &anchor_settings.relayer_account.unwrap(), + fee, + appchain_message.nonce, + processing_context, + ); + } + result } AppchainEvent::NativeTokenLocked { owner_id_in_appchain, receiver_id_in_near, amount, + fee, } => { if self.asset_transfer_is_paused { let message = format!("Asset transfer is now paused."); @@ -465,13 +490,24 @@ impl AppchainAnchor { self.record_appchain_message_processing_result(&result); return MultiTxsOperationProcessingResult::Error(message); } - self.internal_mint_wrapped_appchain_token( + let mut result = self.internal_mint_wrapped_appchain_token( Some(owner_id_in_appchain), receiver_id_in_near, amount, appchain_message.nonce, processing_context, - ) + ); + if result.is_ok() { + let anchor_settings = self.anchor_settings.get().unwrap(); + result = self.internal_mint_wrapped_appchain_token( + Some(owner_id_in_appchain), + &anchor_settings.relayer_account.unwrap(), + fee, + appchain_message.nonce, + processing_context, + ); + } + result } AppchainEvent::EraSwitchPlaned { era_number } => { if let Some(era_number) = processing_context.switching_era_number() { @@ -525,6 +561,7 @@ impl AppchainAnchor { class_id, instance_id, token_metadata, + fee, } => { if self.asset_transfer_is_paused { let message = format!("Asset transfer is now paused."); @@ -535,7 +572,7 @@ impl AppchainAnchor { self.record_appchain_message_processing_result(&result); return MultiTxsOperationProcessingResult::Error(message); } - self.internal_process_locked_nft_in_appchain( + let mut result = self.internal_process_locked_nft_in_appchain( processing_context, appchain_message.nonce, owner_id_in_appchain, @@ -543,35 +580,17 @@ impl AppchainAnchor { class_id, instance_id, token_metadata, - ) - } - AppchainEvent::NativeNearTokenBurnt { - owner_id_in_appchain: _, - receiver_id_in_near, - amount, - } => { - if self.asset_transfer_is_paused { - let message = format!("Asset transfer is now paused."); - let result = AppchainMessageProcessingResult::Error { - nonce: appchain_message.nonce, - message: message.clone(), - }; - self.record_appchain_message_processing_result(&result); - return MultiTxsOperationProcessingResult::Error(message); - } - let mut native_near_token = self.native_near_token.get().unwrap(); - if native_near_token.bridging_state.eq(&BridgingState::Closed) { - let message = format!("Bridging for native NEAR token is now closed."); - let result = AppchainMessageProcessingResult::Error { - nonce: appchain_message.nonce, - message: message.clone(), - }; - self.record_appchain_message_processing_result(&result); - return MultiTxsOperationProcessingResult::Error(message); + ); + if result.is_ok() { + let anchor_settings = self.anchor_settings.get().unwrap(); + result = self.internal_mint_wrapped_appchain_token( + Some(owner_id_in_appchain), + &anchor_settings.relayer_account.unwrap(), + fee, + appchain_message.nonce, + processing_context, + ); } - let result = - native_near_token.unlock_near(receiver_id_in_near, amount, processing_context); - self.native_near_token.set(&native_near_token); result } } diff --git a/appchain-anchor/src/storage_migration.rs b/appchain-anchor/src/storage_migration.rs index e4d2011..d85e5fc 100644 --- a/appchain-anchor/src/storage_migration.rs +++ b/appchain-anchor/src/storage_migration.rs @@ -1,8 +1,53 @@ +use crate::appchain_messages::Offender; use crate::*; use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize}; use near_sdk::collections::{LazyOption, LookupMap}; use near_sdk::{env, near_bindgen, AccountId, Balance}; +#[derive(BorshDeserialize, BorshSerialize, Serialize, Deserialize, Clone)] +#[serde(crate = "near_sdk::serde")] +pub enum OldAppchainEvent { + /// The fact that a certain amount of bridged fungible token has been burnt in the appchain. + NearFungibleTokenBurnt { + contract_account: String, + owner_id_in_appchain: String, + receiver_id_in_near: AccountId, + amount: U128, + }, + /// The fact that a certain amount of appchain native token has been locked in the appchain. + NativeTokenLocked { + owner_id_in_appchain: String, + receiver_id_in_near: AccountId, + amount: U128, + }, + /// The fact that the era switch is planed in the appchain. + EraSwitchPlaned { era_number: u32 }, + /// The fact that the total reward and unprofitable validator list + /// is concluded in the appchain. + EraRewardConcluded { + era_number: u32, + unprofitable_validator_ids: Vec, + offenders: Vec, + }, + /// The fact that a certain non-fungible token is locked in the appchain. + NonFungibleTokenLocked { + owner_id_in_appchain: String, + receiver_id_in_near: AccountId, + class_id: String, + instance_id: String, + token_metadata: TokenMetadata, + }, +} + +#[derive(BorshDeserialize, BorshSerialize, Serialize, Deserialize, Clone)] +#[serde(crate = "near_sdk::serde")] +pub struct OldAppchainMessage { + pub appchain_event: OldAppchainEvent, + // pub block_height: U64, + // pub timestamp: U64, + pub nonce: u32, +} + #[derive(BorshDeserialize, BorshSerialize)] pub struct OldAppchainAnchor { /// The id of corresponding appchain. @@ -116,4 +161,107 @@ impl AppchainAnchor { // new_contract } + /// + pub fn migrate_appchain_messages( + &mut self, + start_nonce: u32, + ) -> MultiTxsOperationProcessingResult { + near_sdk::assert_self(); + let appchain_messages = self.appchain_messages.get().unwrap(); + for nonce in start_nonce..appchain_messages.max_nonce() + 1 { + if env::used_gas() > Gas::ONE_TERA.mul(T_GAS_CAP_FOR_MULTI_TXS_PROCESSING) { + return MultiTxsOperationProcessingResult::Error(format!( + "Not all records are migrated. Call this function again with start_nonce '{}'.", + nonce + )); + } + if let Some(old_data) = env::storage_read(&get_storage_key_in_lookup_array( + &StorageKey::AppchainMessageMap, + &nonce, + )) { + if let Ok(old_version) = OldAppchainMessage::try_from_slice(&old_data) { + env::storage_write( + &get_storage_key_in_lookup_array(&StorageKey::AppchainMessageMap, &nonce), + &AppchainMessage::from_old_version(old_version) + .try_to_vec() + .unwrap(), + ); + } + } + } + MultiTxsOperationProcessingResult::Ok + } +} + +pub fn get_storage_key_in_lookup_array( + prefix: &StorageKey, + index: &T, +) -> Vec { + [prefix.into_bytes(), index.try_to_vec().unwrap()].concat() +} + +impl AppchainEvent { + // + pub fn from_old_version(old_version: OldAppchainEvent) -> Self { + match old_version { + OldAppchainEvent::NearFungibleTokenBurnt { + contract_account, + owner_id_in_appchain, + receiver_id_in_near, + amount, + } => AppchainEvent::NearFungibleTokenBurnt { + contract_account, + owner_id_in_appchain, + receiver_id_in_near, + amount, + fee: 0.into(), + }, + OldAppchainEvent::NativeTokenLocked { + owner_id_in_appchain, + receiver_id_in_near, + amount, + } => AppchainEvent::NativeTokenLocked { + owner_id_in_appchain, + receiver_id_in_near, + amount, + fee: 0.into(), + }, + OldAppchainEvent::EraSwitchPlaned { era_number } => { + AppchainEvent::EraSwitchPlaned { era_number } + } + OldAppchainEvent::EraRewardConcluded { + era_number, + unprofitable_validator_ids, + offenders, + } => AppchainEvent::EraRewardConcluded { + era_number, + unprofitable_validator_ids, + offenders, + }, + OldAppchainEvent::NonFungibleTokenLocked { + owner_id_in_appchain, + receiver_id_in_near, + class_id, + instance_id, + token_metadata, + } => AppchainEvent::NonFungibleTokenLocked { + owner_id_in_appchain, + receiver_id_in_near, + class_id, + instance_id, + token_metadata, + fee: 0.into(), + }, + } + } +} + +impl AppchainMessage { + // + pub fn from_old_version(old_version: OldAppchainMessage) -> Self { + Self { + appchain_event: AppchainEvent::from_old_version(old_version.appchain_event), + nonce: old_version.nonce, + } + } } diff --git a/appchain-anchor/src/types.rs b/appchain-anchor/src/types.rs index 130bddd..3b6f9c2 100644 --- a/appchain-anchor/src/types.rs +++ b/appchain-anchor/src/types.rs @@ -301,75 +301,6 @@ pub struct StakingHistory { pub index: U64, } -#[derive(BorshDeserialize, BorshSerialize, Serialize, Deserialize, Clone)] -#[serde(crate = "near_sdk::serde")] -pub enum AnchorEvent { - /// The event that a certain amount of a NEAR fungible token has been locked - /// in appchain anchor. - NearFungibleTokenLocked { - symbol: String, - sender_id_in_near: AccountId, - receiver_id_in_appchain: String, - amount: U128, - }, - /// The event that a certain amount of a NEAR fungible token has been unlocked and - /// transfered to a receiver in NEAR protocol. - NearFungibleTokenUnlocked { - symbol: String, - sender_id_in_appchain: String, - receiver_id_in_near: AccountId, - amount: U128, - /// The nonce of the appchain message - appchain_message_nonce: u32, - }, - /// The event that the action for unlocking a certain amount of a NEAR fungible token - /// had failed due to some reasons. - FailedToUnlockNearFungibleToken { - symbol: String, - sender_id_in_appchain: String, - receiver_id_in_near: AccountId, - amount: U128, - /// The nonce of the appchain message - appchain_message_nonce: u32, - reason: String, - }, - /// The event that a certain amount of wrapped appchain token is burnt in its contract - /// in NEAR protocol. - WrappedAppchainTokenBurnt { - sender_id_in_near: AccountId, - receiver_id_in_appchain: String, - amount: U128, - }, - /// The event that the action for burning a certain amount of wrapped appchain token - /// had failed due to some reasons. - FailedToBurnWrappedAppchainToken { - sender_id_in_near: AccountId, - receiver_id_in_appchain: String, - amount: U128, - reason: String, - }, - /// The event that a certain amount of wrapped appchain token had been minted in NEAR protocol - WrappedAppchainTokenMinted { - /// The id of sender on the appchain, or `None` in distributing era rewards case - sender_id_in_appchain: Option, - receiver_id_in_near: AccountId, - amount: U128, - /// The nonce of the appchain message - appchain_message_nonce: u32, - }, - /// The event that the action for minting a certain amount of wrapped appchain token - /// had failed due to some reasons. - FailedToMintWrappedAppchainToken { - /// The id of sender on the appchain, or `None` in distributing era rewards case - sender_id_in_appchain: Option, - receiver_id_in_near: AccountId, - amount: U128, - /// The nonce of the appchain message - appchain_message_nonce: u32, - reason: String, - }, -} - #[derive(Serialize, Deserialize, Clone)] #[serde(crate = "near_sdk::serde")] pub struct AppchainValidator { diff --git a/tests/simulator/common/complex_viewer.rs b/tests/simulator/common/complex_viewer.rs index c2894ee..eb6ca8a 100644 --- a/tests/simulator/common/complex_viewer.rs +++ b/tests/simulator/common/complex_viewer.rs @@ -1,6 +1,6 @@ use crate::{common::get_ft_balance_of, contract_interfaces::anchor_viewer}; use appchain_anchor::types::{ - AnchorSettings, AnchorStatus, AppchainCommitment, AppchainSettings, ValidatorProfile, + AnchorSettings, AnchorStatus, AppchainSettings, BeefyLightClientStatus, ValidatorProfile, ValidatorSetInfo, WrappedAppchainToken, }; use near_sdk::{json_types::U64, serde_json, AccountId}; @@ -212,8 +212,8 @@ pub async fn print_user_staking_histories_of( &user.id(), serde_json::to_string(&staking_history).unwrap() ); - index += 1; println!(); + index += 1; } Ok(()) } @@ -240,8 +240,8 @@ pub async fn print_validator_list_of( serde_json::to_string(&validator).unwrap() ); } - index += 1; println!(); + index += 1; } Ok(()) } @@ -264,8 +264,8 @@ pub async fn print_delegator_list_of( era_number, serde_json::to_string(&delegator).unwrap() ); - index += 1; println!(); + index += 1; } Ok(()) } @@ -286,8 +286,8 @@ pub async fn print_validator_reward_histories( validator.id().to_string(), serde_json::to_string(&reward_history).unwrap() ); - index += 1; println!(); + index += 1; } Ok(()) } @@ -311,8 +311,8 @@ pub async fn print_delegator_reward_histories( validator.id().to_string(), serde_json::to_string(&reward_history).unwrap() ); - index += 1; println!(); + index += 1; } Ok(()) } @@ -331,21 +331,20 @@ pub async fn print_unbonded_stakes_of( user.id(), serde_json::to_string(&unbonded_stake).unwrap() ); - index += 1; println!(); + index += 1; } Ok(()) } -pub async fn print_latest_appchain_commitment( +pub async fn print_beefy_light_client_status( worker: &Worker, anchor: &Contract, ) -> anyhow::Result<()> { - let appchain_commitment = - anchor_viewer::get_latest_commitment_of_appchain(worker, &anchor).await?; + let status = anchor_viewer::get_beefy_light_client_status(worker, &anchor).await?; println!( - "Latest appchain commitment: {}", - serde_json::to_string::>(&appchain_commitment).unwrap() + "Beefy light client status: {}", + serde_json::to_string::(&status).unwrap() ); println!(); Ok(()) @@ -395,8 +394,8 @@ pub async fn print_appchain_messages_processing_results( index, serde_json::to_string(&appchain_message).unwrap() ); - index += 1; println!(); + index += 1; } Ok(()) } diff --git a/tests/simulator/contract_interfaces/anchor_viewer.rs b/tests/simulator/contract_interfaces/anchor_viewer.rs index a4bd96a..4892d83 100644 --- a/tests/simulator/contract_interfaces/anchor_viewer.rs +++ b/tests/simulator/contract_interfaces/anchor_viewer.rs @@ -1,8 +1,8 @@ use appchain_anchor::appchain_challenge::AppchainChallenge; use appchain_anchor::types::{ - AnchorSettings, AnchorStatus, AppchainCommitment, AppchainDelegator, - AppchainMessageProcessingResult, AppchainNotificationHistory, AppchainSettings, AppchainState, - AppchainValidator, IndexRange, NativeNearToken, NearFungibleToken, RewardHistory, + AnchorSettings, AnchorStatus, AppchainDelegator, AppchainMessageProcessingResult, + AppchainNotificationHistory, AppchainSettings, AppchainState, AppchainValidator, + BeefyLightClientStatus, IndexRange, NativeNearToken, NearFungibleToken, RewardHistory, StakingHistory, UnbondedStake, UserStakingHistory, ValidatorProfile, ValidatorSetInfo, WrappedAppchainToken, }; @@ -283,15 +283,15 @@ pub async fn get_delegator_rewards_of( .json::>() } -pub async fn get_latest_commitment_of_appchain( +pub async fn get_beefy_light_client_status( worker: &Worker, anchor: &Contract, -) -> anyhow::Result> { +) -> anyhow::Result { anchor - .call(worker, "get_latest_commitment_of_appchain") + .call(worker, "get_beefy_light_client_status") .view() .await? - .json::>() + .json::() } pub async fn get_user_staking_histories_of( diff --git a/tests/simulator/contract_interfaces/permissionless_actions.rs b/tests/simulator/contract_interfaces/permissionless_actions.rs index fd57660..0a4f03a 100644 --- a/tests/simulator/contract_interfaces/permissionless_actions.rs +++ b/tests/simulator/contract_interfaces/permissionless_actions.rs @@ -42,48 +42,39 @@ pub async fn process_appchain_messages( result.json::() } -pub async fn start_updating_state_of_beefy_light_client( +pub async fn process_appchain_messages_with_all_proofs( worker: &Worker, signer: &Account, anchor: &Contract, signed_commitment: Vec, validator_proofs: Vec, - mmr_leaf: Vec, - mmr_proof: Vec, -) -> anyhow::Result { + mmr_leaf_for_mmr_root: Vec, + mmr_proof_for_mmr_root: Vec, + encoded_messages: Vec, + header: Vec, + mmr_leaf_for_header: Vec, + mmr_proof_for_header: Vec, +) -> anyhow::Result { let result = signer .call( worker, anchor.id(), - "start_updating_state_of_beefy_light_client", + "process_appchain_messages_with_all_proofs", ) .args_json(json!({ "signed_commitment": signed_commitment, "validator_proofs": validator_proofs, - "mmr_leaf": mmr_leaf, - "mmr_proof": mmr_proof + "mmr_leaf_for_mmr_root": mmr_leaf_for_mmr_root, + "mmr_proof_for_mmr_root": mmr_proof_for_mmr_root, + "encoded_messages": encoded_messages, + "header": header, + "mmr_leaf_for_header": mmr_leaf_for_header, + "mmr_proof_for_header": mmr_proof_for_header, }))? .gas(300_000_000_000_000) .transact() - .await; - println!("{:?}", result.as_ref().unwrap()); - result -} - -pub async fn try_complete_updating_state_of_beefy_light_client( - worker: &Worker, - signer: &Account, - anchor: &Contract, -) -> anyhow::Result { - let result = signer - .call( - worker, - anchor.id(), - "try_complete_updating_state_of_beefy_light_client", - ) - .gas(300_000_000_000_000) - .transact() .await?; println!("{:?}", result); + println!(); result.json::() } diff --git a/tests/simulator/contract_interfaces/settings_manager.rs b/tests/simulator/contract_interfaces/settings_manager.rs index fc77768..e596652 100644 --- a/tests/simulator/contract_interfaces/settings_manager.rs +++ b/tests/simulator/contract_interfaces/settings_manager.rs @@ -171,19 +171,3 @@ pub async fn turn_on_beefy_light_client_witness_mode( .transact() .await } - -pub async fn turn_off_beefy_light_client_witness_mode( - worker: &Worker, - signer: &Account, - anchor: &Contract, -) -> anyhow::Result { - signer - .call( - worker, - anchor.id(), - "turn_off_beefy_light_client_witness_mode", - ) - .gas(200_000_000_000_000) - .transact() - .await -} diff --git a/tests/simulator/main.rs b/tests/simulator/main.rs index 8fbe35b..70738d7 100644 --- a/tests/simulator/main.rs +++ b/tests/simulator/main.rs @@ -2,7 +2,7 @@ mod common; mod contract_interfaces; mod test_anchor_actions; -mod test_beefy_light_client; +mod test_beefy_light_client_1; mod test_beefy_light_client_2; mod test_equivocation_challenge; mod test_migration; diff --git a/tests/simulator/test_beefy_light_client.rs b/tests/simulator/test_beefy_light_client_1.rs similarity index 90% rename from tests/simulator/test_beefy_light_client.rs rename to tests/simulator/test_beefy_light_client_1.rs index d794a07..d2cea97 100644 --- a/tests/simulator/test_beefy_light_client.rs +++ b/tests/simulator/test_beefy_light_client_1.rs @@ -4,7 +4,7 @@ use crate::{ anchor_viewer, permissionless_actions, settings_manager, staking_actions, }, }; -use appchain_anchor::types::{MultiTxsOperationProcessingResult, ValidatorMerkleProof}; +use appchain_anchor::types::ValidatorMerkleProof; use beefy_light_client::mmr::{MmrLeaf, MmrLeafProof}; use beefy_light_client::{beefy_ecdsa_to_ethereum, commitment::SignedCommitment}; use codec::Decode; @@ -13,8 +13,9 @@ use near_sdk::serde_json; use workspaces::{network::Sandbox, Account, Contract, Worker}; #[tokio::test] -async fn test_beefy_light_client() -> anyhow::Result<()> { +async fn test_beefy_light_client_1() -> anyhow::Result<()> { let worker = workspaces::sandbox().await?; + // let initial_public_keys = vec![ "0x020a1091341fe5664bfa1782d5e04779689068c916b04cb365ec3153755684d9a1".to_string(), // Alice "0x0390084fdbf27d2b79d26a4f13f0ccd982cb755a661969143c37cbc49ef5b91f27".to_string(), // Bob @@ -34,20 +35,12 @@ async fn test_beefy_light_client() -> anyhow::Result<()> { mut appchain_message_nonce, ) = common::test_normal_actions(&worker, false, true, initial_public_keys).await?; // - settings_manager::turn_off_beefy_light_client_witness_mode(&worker, &root, &anchor) - .await - .expect("Failed to call 'turn_off_beefy_light_client_witness_mode'"); - // // Update state of beefy light client // update_state_of_beefy_light_client_1(&worker, &anchor, &users[4]).await?; - common::complex_viewer::print_latest_appchain_commitment(&worker, &anchor).await?; + common::complex_viewer::print_beefy_light_client_status(&worker, &anchor).await?; update_state_of_beefy_light_client_2(&worker, &anchor, &users[1]).await?; - common::complex_viewer::print_latest_appchain_commitment(&worker, &anchor).await?; - // - settings_manager::turn_on_beefy_light_client_witness_mode(&worker, &root, &anchor) - .await - .expect("Failed to call 'turn_on_beefy_light_client_witness_mode'"); + common::complex_viewer::print_beefy_light_client_status(&worker, &anchor).await?; // // Try start and complete switching era1 // @@ -377,15 +370,6 @@ async fn test_beefy_light_client() -> anyhow::Result<()> { common::complex_actions::withdraw_stake_of(&worker, &anchor, &users[2], &oct_token).await?; common::complex_actions::withdraw_stake_of(&worker, &anchor, &users[3], &oct_token).await?; common::complex_actions::withdraw_stake_of(&worker, &anchor, &users[4], &oct_token).await?; - // - // - // - common::complex_viewer::print_validator_list_of(&worker, &anchor, Some(0)).await?; - common::complex_viewer::print_validator_list_of(&worker, &anchor, Some(1)).await?; - common::complex_viewer::print_validator_list_of(&worker, &anchor, Some(2)).await?; - common::complex_viewer::print_validator_list_of(&worker, &anchor, Some(3)).await?; - common::complex_viewer::print_staking_histories(&worker, &anchor).await?; - common::complex_viewer::print_appchain_notifications(&worker, &anchor).await?; Ok(()) } @@ -471,11 +455,11 @@ async fn update_state_of_beefy_light_client_1( let mmr_leaf_1: MmrLeaf = Decode::decode(&mut &*leaf).unwrap(); println!("mmr_leaf_1: {:?}", mmr_leaf_1); - let encoded_mmr_proof_1 = hex!("0800000000000000090000000000000004effbabd0a9fcade34208684b3d5d69a52b2c9bc9265d872c2590636acd6342a0"); + let encoded_mmr_proof_1 = hex!("0800000000000000090000000000000004effbabd0a9fcade34208684b3d5d69a52b2c9bc9265d872c2590636acd6342a0"); let mmr_proof_1 = MmrLeafProof::decode(&mut &encoded_mmr_proof_1[..]); println!("mmr_proof_1: {:?}", mmr_proof_1); // - let result = permissionless_actions::start_updating_state_of_beefy_light_client( + let result = permissionless_actions::process_appchain_messages_with_all_proofs( &worker, &user, &anchor, @@ -483,17 +467,18 @@ async fn update_state_of_beefy_light_client_1( validator_proofs_1, encoded_mmr_leaf_1.to_vec(), encoded_mmr_proof_1.to_vec(), + Vec::new(), + Vec::new(), + Vec::new(), + Vec::new(), ) - .await?; - assert!(result.is_success()); - let result = permissionless_actions::try_complete_updating_state_of_beefy_light_client( - &worker, &user, &anchor, - ) - .await?; + .await + .expect("Failed in calling 'process_appchain_messages_with_all_proofs'"); println!( - "Result of 'try_complete_updating_state_of_beefy_light_client': {}", - serde_json::to_string::(&result).unwrap() + "Result of 'process_appchain_messages_with_all_proofs': {}", + serde_json::to_string(&result).unwrap() ); + // Ok(()) } @@ -583,7 +568,7 @@ async fn update_state_of_beefy_light_client_2( let mmr_proof_2 = MmrLeafProof::decode(&mut &encoded_mmr_proof_2[..]); println!("mmr_proof_2: {:?}", mmr_proof_2); // - let result = permissionless_actions::start_updating_state_of_beefy_light_client( + let result = permissionless_actions::process_appchain_messages_with_all_proofs( &worker, &user, &anchor, @@ -591,16 +576,17 @@ async fn update_state_of_beefy_light_client_2( validator_proofs_2, encoded_mmr_leaf_2.to_vec(), encoded_mmr_proof_2.to_vec(), + Vec::new(), + Vec::new(), + Vec::new(), + Vec::new(), ) - .await?; - assert!(result.is_success()); - let result = permissionless_actions::try_complete_updating_state_of_beefy_light_client( - &worker, &user, &anchor, - ) - .await?; + .await + .expect("Failed in calling 'process_appchain_messages_with_all_proofs'"); println!( - "Result of 'try_complete_updating_state_of_beefy_light_client': {}", - serde_json::to_string::(&result).unwrap() + "Result of 'process_appchain_messages_with_all_proofs': {}", + serde_json::to_string(&result).unwrap() ); + // Ok(()) } diff --git a/tests/simulator/test_beefy_light_client_2.rs b/tests/simulator/test_beefy_light_client_2.rs index 2e898f1..e8b2352 100644 --- a/tests/simulator/test_beefy_light_client_2.rs +++ b/tests/simulator/test_beefy_light_client_2.rs @@ -1,6 +1,5 @@ -use crate::contract_interfaces::settings_manager; use crate::{common, contract_interfaces::permissionless_actions}; -use appchain_anchor::types::{MultiTxsOperationProcessingResult, ValidatorMerkleProof}; +use appchain_anchor::types::ValidatorMerkleProof; use beefy_light_client::commitment::{Commitment, Payload, Signature}; use beefy_light_client::{beefy_ecdsa_to_ethereum, commitment::SignedCommitment}; use beefy_merkle_tree::{merkle_proof, Keccak256}; @@ -16,7 +15,7 @@ const MMR_ROOT_ID: BeefyPayloadId = *b"mh"; #[tokio::test] async fn test_beefy_light_client_2() -> anyhow::Result<()> { let worker = workspaces::sandbox().await?; - const MAX_VALIDATORS: i32 = 85; + const MAX_VALIDATORS: i32 = 35; let secp = Secp256k1::new(); @@ -86,11 +85,7 @@ async fn test_beefy_light_client_2() -> anyhow::Result<()> { _appchain_message_nonce, ) = common::test_normal_actions(&worker, false, true, initial_public_keys).await?; // - settings_manager::turn_off_beefy_light_client_witness_mode(&worker, &root, &anchor) - .await - .expect("Failed to call 'turn_off_beefy_light_client_witness_mode'"); - // - permissionless_actions::start_updating_state_of_beefy_light_client( + let result = permissionless_actions::process_appchain_messages_with_all_proofs( &worker, &root, &anchor, @@ -98,22 +93,17 @@ async fn test_beefy_light_client_2() -> anyhow::Result<()> { validator_proofs, encoded_mmr_leaf.to_vec(), encoded_mmr_proof.to_vec(), + Vec::new(), + Vec::new(), + Vec::new(), + Vec::new(), ) .await - .expect("Failed in calling 'start_updating_state_of_beefy_light_client'"); - loop { - let result = permissionless_actions::try_complete_updating_state_of_beefy_light_client( - &worker, &root, &anchor, - ) - .await - .expect("Failed in calling 'try_complete_updating_state_of_beefy_light_client'"); - println!( - "Result of 'try_complete_updating_state_of_beefy_light_client': {}", - serde_json::to_string::(&result).unwrap() - ); - if !result.is_need_more_gas() { - break; - } - } + .expect("Failed in calling 'process_appchain_messages_with_all_proofs'"); + println!( + "Result of 'process_appchain_messages_with_all_proofs': {}", + serde_json::to_string(&result).unwrap() + ); + // Ok(()) } diff --git a/tests/simulator/test_migration.rs b/tests/simulator/test_migration.rs index 706a44d..274af35 100644 --- a/tests/simulator/test_migration.rs +++ b/tests/simulator/test_migration.rs @@ -1,5 +1,5 @@ use crate::common::{self, complex_actions}; -use near_sdk::json_types::U64; +use near_sdk::{json_types::U64, serde_json::json}; use near_units::parse_near; #[tokio::test] @@ -69,6 +69,21 @@ async fn test_migration() -> anyhow::Result<()> { println!(); assert!(result.is_success()); // + let result = anchor + .call(&worker, "migrate_appchain_messages") + .args_json(json!({ + "start_nonce": 0, + }))? + .gas(300_000_000_000_000) + .transact() + .await?; + println!( + "Result of calling 'migrate_appchain_messages': {:?}", + result + ); + println!(); + assert!(result.is_success()); + // // // common::complex_viewer::print_anchor_status(&worker, &anchor).await?; @@ -99,5 +114,6 @@ async fn test_migration() -> anyhow::Result<()> { &user1_id_in_appchain, ) .await?; + common::complex_viewer::print_appchain_messages(&worker, &anchor).await?; Ok(()) } diff --git a/tests/simulator/test_transfer_native_near.rs b/tests/simulator/test_transfer_native_near.rs index 21f80a9..d1a8b53 100644 --- a/tests/simulator/test_transfer_native_near.rs +++ b/tests/simulator/test_transfer_native_near.rs @@ -1,5 +1,5 @@ use crate::{ - common, + common::{self, to_actual_amount}, contract_interfaces::{native_near_token, permissionless_actions}, }; use appchain_anchor::appchain_messages::{BurnAssetPayload, PayloadType, RawMessage}; @@ -103,6 +103,7 @@ async fn test_transfer_native_near() -> anyhow::Result<()> { sender: user0_id_in_appchain.clone(), receiver_id: users[0].id().to_string().parse().unwrap(), amount: parse_near!("1 N"), + fee: to_actual_amount(1, 18), }; let raw_message = RawMessage { nonce: appchain_message_nonce as u64, diff --git a/tests/simulator/test_transfer_nft.rs b/tests/simulator/test_transfer_nft.rs index 8d62cd1..2871530 100644 --- a/tests/simulator/test_transfer_nft.rs +++ b/tests/simulator/test_transfer_nft.rs @@ -1,5 +1,5 @@ use crate::{ - common, + common::{self, to_actual_amount}, contract_interfaces::{permissionless_actions, wrapped_appchain_nft_manager}, }; use appchain_anchor::{ @@ -129,6 +129,7 @@ async fn test_transfer_nft_to_near() -> anyhow::Result<()> { reference: None, reference_hash: None, }, + fee: to_actual_amount(1, 18), }; let raw_message = RawMessage { nonce: appchain_message_nonce as u64, @@ -183,6 +184,7 @@ async fn test_transfer_nft_to_near() -> anyhow::Result<()> { reference: None, reference_hash: None, }, + fee: to_actual_amount(1, 18), }; let raw_message = RawMessage { nonce: appchain_message_nonce as u64, @@ -256,6 +258,7 @@ async fn test_transfer_nft_to_near() -> anyhow::Result<()> { reference: None, reference_hash: None, }, + fee: to_actual_amount(1, 18), }; let raw_message = RawMessage { nonce: appchain_message_nonce as u64, diff --git a/tests/simulator/test_wrapped_appchain_token.rs b/tests/simulator/test_wrapped_appchain_token.rs index 4a7c3f0..4b5789d 100644 --- a/tests/simulator/test_wrapped_appchain_token.rs +++ b/tests/simulator/test_wrapped_appchain_token.rs @@ -41,6 +41,7 @@ async fn test_wrapped_appchain_token_bridging() -> anyhow::Result<()> { sender: user4_id_in_appchain.clone(), receiver_id: AccountId::from_str("unknown.testnet").unwrap(), amount: total_supply / 10, + fee: common::to_actual_amount(1, 18), }; let raw_message = RawMessage { nonce: appchain_message_nonce as u64, @@ -60,7 +61,9 @@ async fn test_wrapped_appchain_token_bridging() -> anyhow::Result<()> { ) .await .expect("Failed to call 'verify_and_stage_appchain_messages'"); - common::complex_actions::process_appchain_messages(&worker, &users[4], &anchor).await?; + common::complex_actions::process_appchain_messages(&worker, &users[4], &anchor) + .await + .expect("Failed to call 'process_appchain_messages'"); common::complex_viewer::print_appchain_messages(&worker, &anchor).await?; common::complex_viewer::print_appchain_messages_processing_results(&worker, &anchor).await?; common::complex_viewer::print_appchain_notifications(&worker, &anchor).await?; @@ -80,7 +83,8 @@ async fn test_wrapped_appchain_token_bridging() -> anyhow::Result<()> { user0_id_in_appchain, total_supply / 2 - common::to_actual_amount(50000, 18), ) - .await?; + .await + .expect("Failed to call 'burn_wrapped_appchain_token'"); println!("Result of 'burn_wrapped_appchain_token': {:?}", result); assert!(result.is_success()); common::complex_viewer::print_appchain_notifications(&worker, &anchor).await?; @@ -97,6 +101,7 @@ async fn test_wrapped_appchain_token_bridging() -> anyhow::Result<()> { sender: user4_id_in_appchain.clone(), receiver_id: users[1].id().to_string().parse().unwrap(), amount: common::to_actual_amount(60, 18), + fee: common::to_actual_amount(1, 18), }; let raw_message = RawMessage { nonce: appchain_message_nonce as u64, @@ -110,6 +115,7 @@ async fn test_wrapped_appchain_token_bridging() -> anyhow::Result<()> { sender: user4_id_in_appchain.clone(), receiver_id: users[1].id().to_string().parse().unwrap(), amount: common::to_actual_amount(40, 18), + fee: common::to_actual_amount(1, 18), }; let raw_message = RawMessage { nonce: appchain_message_nonce as u64, @@ -132,6 +138,7 @@ async fn test_wrapped_appchain_token_bridging() -> anyhow::Result<()> { sender: user4_id_in_appchain.clone(), receiver_id: users[1].id().to_string().parse().unwrap(), amount: common::to_actual_amount(70, 18), + fee: common::to_actual_amount(1, 18), }; let raw_message = RawMessage { nonce: appchain_message_nonce as u64, @@ -145,6 +152,7 @@ async fn test_wrapped_appchain_token_bridging() -> anyhow::Result<()> { sender: user4_id_in_appchain.clone(), receiver_id: users[1].id().to_string().parse().unwrap(), amount: common::to_actual_amount(30, 18), + fee: common::to_actual_amount(1, 18), }; let raw_message = RawMessage { nonce: appchain_message_nonce as u64, @@ -158,6 +166,7 @@ async fn test_wrapped_appchain_token_bridging() -> anyhow::Result<()> { sender: user4_id_in_appchain.clone(), receiver_id: users[1].id().to_string().parse().unwrap(), amount: common::to_actual_amount(45, 18), + fee: common::to_actual_amount(1, 18), }; let raw_message = RawMessage { nonce: appchain_message_nonce as u64, @@ -171,6 +180,7 @@ async fn test_wrapped_appchain_token_bridging() -> anyhow::Result<()> { sender: user4_id_in_appchain.clone(), receiver_id: users[1].id().to_string().parse().unwrap(), amount: common::to_actual_amount(45, 18), + fee: common::to_actual_amount(1, 18), }; let raw_message = RawMessage { nonce: appchain_message_nonce as u64, @@ -184,6 +194,7 @@ async fn test_wrapped_appchain_token_bridging() -> anyhow::Result<()> { sender: user4_id_in_appchain.clone(), receiver_id: users[1].id().to_string().parse().unwrap(), amount: common::to_actual_amount(45, 18), + fee: common::to_actual_amount(1, 18), }; let raw_message = RawMessage { nonce: appchain_message_nonce as u64, @@ -197,6 +208,7 @@ async fn test_wrapped_appchain_token_bridging() -> anyhow::Result<()> { sender: user4_id_in_appchain.clone(), receiver_id: users[1].id().to_string().parse().unwrap(), amount: common::to_actual_amount(45, 18), + fee: common::to_actual_amount(1, 18), }; let raw_message = RawMessage { nonce: appchain_message_nonce as u64, @@ -223,6 +235,7 @@ async fn test_wrapped_appchain_token_bridging() -> anyhow::Result<()> { sender: user4_id_in_appchain.clone(), receiver_id: users[1].id().to_string().parse().unwrap(), amount: common::to_actual_amount(45, 18), + fee: common::to_actual_amount(1, 18), }; let raw_message = RawMessage { nonce: appchain_message_nonce as u64, @@ -236,6 +249,7 @@ async fn test_wrapped_appchain_token_bridging() -> anyhow::Result<()> { sender: user4_id_in_appchain.clone(), receiver_id: users[1].id().to_string().parse().unwrap(), amount: common::to_actual_amount(45, 18), + fee: common::to_actual_amount(1, 18), }; let raw_message = RawMessage { nonce: appchain_message_nonce as u64, @@ -249,6 +263,7 @@ async fn test_wrapped_appchain_token_bridging() -> anyhow::Result<()> { sender: user4_id_in_appchain.clone(), receiver_id: users[1].id().to_string().parse().unwrap(), amount: common::to_actual_amount(45, 18), + fee: common::to_actual_amount(1, 18), }; let raw_message = RawMessage { nonce: appchain_message_nonce as u64, @@ -268,7 +283,9 @@ async fn test_wrapped_appchain_token_bridging() -> anyhow::Result<()> { ) .await .expect("Failed to call 'verify_and_stage_appchain_messages'"); - common::complex_actions::process_appchain_messages(&worker, &users[3], &anchor).await?; + common::complex_actions::process_appchain_messages(&worker, &users[3], &anchor) + .await + .expect("Failed to call 'process_appchain_messages'"); common::complex_viewer::print_appchain_messages(&worker, &anchor).await?; common::complex_viewer::print_appchain_messages_processing_results(&worker, &anchor).await?; common::complex_viewer::print_appchain_notifications(&worker, &anchor).await?; @@ -352,7 +369,9 @@ async fn test_wrapped_appchain_token_bridging() -> anyhow::Result<()> { ) .await .expect("Failed to call 'verify_and_stage_appchain_messages'"); - common::complex_actions::process_appchain_messages(&worker, &users[3], &anchor).await?; + common::complex_actions::process_appchain_messages(&worker, &users[3], &anchor) + .await + .expect("Failed to call 'process_appchain_messages'"); common::complex_viewer::print_appchain_messages(&worker, &anchor).await?; common::complex_viewer::print_appchain_messages_processing_results(&worker, &anchor).await?; Ok(()) From 15d9c31cf511f8d79efc4bf5f57af5fa544b6ef4 Mon Sep 17 00:00:00 2001 From: Rivers Yang Date: Fri, 21 Oct 2022 10:40:03 +0800 Subject: [PATCH 02/15] Support witness mode in function `process_appchain_messages_with_all_proofs`. --- .../src/permissionless_actions/mod.rs | 48 +++++++++++-------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/appchain-anchor/src/permissionless_actions/mod.rs b/appchain-anchor/src/permissionless_actions/mod.rs index 73f4344..9e4a5d1 100644 --- a/appchain-anchor/src/permissionless_actions/mod.rs +++ b/appchain-anchor/src/permissionless_actions/mod.rs @@ -264,33 +264,39 @@ impl PermissionlessActions for AppchainAnchor { mmr_leaf_for_header: Vec, mmr_proof_for_header: Vec, ) -> MultiTxsOperationProcessingResult { - self.assert_light_client_is_ready(); - let mut light_client = self.beefy_light_client_state.get().unwrap(); - match light_client.update_state( - &signed_commitment, - &validator_proofs - .iter() - .map(|proof| beefy_light_client::ValidatorMerkleProof { - proof: proof.proof.clone(), - number_of_leaves: proof.number_of_leaves.try_into().unwrap_or_default(), - leaf_index: proof.leaf_index.try_into().unwrap_or_default(), - leaf: proof.leaf.clone(), - }) - .collect::>(), - &mmr_leaf_for_mmr_root, - &mmr_proof_for_mmr_root, - ) { - Ok(()) => { - self.beefy_light_client_state.set(&light_client); + let anchor_settings = self.anchor_settings.get().unwrap(); + if anchor_settings.beefy_light_client_witness_mode { + self.assert_relayer(); + } else { + self.assert_light_client_is_ready(); + let mut light_client = self.beefy_light_client_state.get().unwrap(); + match light_client.update_state( + &signed_commitment, + &validator_proofs + .iter() + .map(|proof| beefy_light_client::ValidatorMerkleProof { + proof: proof.proof.clone(), + number_of_leaves: proof.number_of_leaves.try_into().unwrap_or_default(), + leaf_index: proof.leaf_index.try_into().unwrap_or_default(), + leaf: proof.leaf.clone(), + }) + .collect::>(), + &mmr_leaf_for_mmr_root, + &mmr_proof_for_mmr_root, + ) { + Ok(()) => { + self.beefy_light_client_state.set(&light_client); + } + Err(beefy_light_client::Error::CommitmentAlreadyUpdated) => {} + Err(err) => panic!("Failed to update state of beefy light client: {:?}", err), } - Err(beefy_light_client::Error::CommitmentAlreadyUpdated) => {} - Err(err) => panic!("Failed to update state of beefy light client: {:?}", err), } if encoded_messages.len() == 0 { return MultiTxsOperationProcessingResult::Error(format!( - "State of beefy light client has been updated. But there is no message data to be processed." + "There is no message data to be processed." )); } + let light_client = self.beefy_light_client_state.get().unwrap(); if let Err(err) = light_client.verify_solochain_messages( &encoded_messages, &header, From bdd62d0c4c96c31c5361f9eb3a4d89a2f1ba266c Mon Sep 17 00:00:00 2001 From: Rivers Yang Date: Thu, 27 Oct 2022 21:36:56 +0800 Subject: [PATCH 03/15] Fix bug in function `process_appchain_messages_with_all_proofs`. --- .../src/permissionless_actions/mod.rs | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/appchain-anchor/src/permissionless_actions/mod.rs b/appchain-anchor/src/permissionless_actions/mod.rs index 9e4a5d1..af9a9f2 100644 --- a/appchain-anchor/src/permissionless_actions/mod.rs +++ b/appchain-anchor/src/permissionless_actions/mod.rs @@ -264,6 +264,11 @@ impl PermissionlessActions for AppchainAnchor { mmr_leaf_for_header: Vec, mmr_proof_for_header: Vec, ) -> MultiTxsOperationProcessingResult { + if encoded_messages.len() == 0 { + return MultiTxsOperationProcessingResult::Error(format!( + "There is no message data to be processed." + )); + } let anchor_settings = self.anchor_settings.get().unwrap(); if anchor_settings.beefy_light_client_witness_mode { self.assert_relayer(); @@ -290,20 +295,14 @@ impl PermissionlessActions for AppchainAnchor { Err(beefy_light_client::Error::CommitmentAlreadyUpdated) => {} Err(err) => panic!("Failed to update state of beefy light client: {:?}", err), } - } - if encoded_messages.len() == 0 { - return MultiTxsOperationProcessingResult::Error(format!( - "There is no message data to be processed." - )); - } - let light_client = self.beefy_light_client_state.get().unwrap(); - if let Err(err) = light_client.verify_solochain_messages( - &encoded_messages, - &header, - &mmr_leaf_for_header, - &mmr_proof_for_header, - ) { - panic!("Failed in verifying appchain messages: {:?}", err); + if let Err(err) = light_client.verify_solochain_messages( + &encoded_messages, + &header, + &mmr_leaf_for_header, + &mmr_proof_for_header, + ) { + panic!("Failed in verifying appchain messages: {:?}", err); + } } let messages = Decode::decode(&mut &encoded_messages[..]).unwrap(); self.internal_stage_appchain_messages(&messages); From 0dbcb94ebd91c0c7dcf6878a682a49d749711971 Mon Sep 17 00:00:00 2001 From: Rivers Yang Date: Fri, 28 Oct 2022 15:40:49 +0800 Subject: [PATCH 04/15] Fix bug in `RawMessage` definition. --- appchain-anchor/src/appchain_messages.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/appchain-anchor/src/appchain_messages.rs b/appchain-anchor/src/appchain_messages.rs index 096b395..8397eff 100644 --- a/appchain-anchor/src/appchain_messages.rs +++ b/appchain-anchor/src/appchain_messages.rs @@ -84,6 +84,7 @@ pub enum MessagePayload { #[derive(Encode, Decode, Clone)] pub struct RawMessage { + #[codec(compact)] pub nonce: u64, pub payload_type: PayloadType, pub payload: Vec, From 699d8d61c3285ea9e63de271e081a4e7cd0d1f4f Mon Sep 17 00:00:00 2001 From: Rivers Yang Date: Wed, 2 Nov 2022 11:52:07 +0800 Subject: [PATCH 05/15] Fix bug in `auto-unbonding validator`. --- .../distributing_rewards.rs | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/appchain-anchor/src/permissionless_actions/distributing_rewards.rs b/appchain-anchor/src/permissionless_actions/distributing_rewards.rs index c191c1d..d0a36b6 100644 --- a/appchain-anchor/src/permissionless_actions/distributing_rewards.rs +++ b/appchain-anchor/src/permissionless_actions/distributing_rewards.rs @@ -179,21 +179,14 @@ impl AppchainAnchor { let validator_id = unprofitable_validators .get(usize::try_from(unprofitable_validator_index.0).unwrap()) .unwrap(); - if validator_set.contains_validator(validator_id) + if era_number + >= u64::from(protocol_settings.maximum_allowed_unprofitable_era_count) + && validator_set.contains_validator(validator_id) && next_validator_set.contains_validator(validator_id) { - let start_checking_index = match era_number - >= u64::from(protocol_settings.maximum_allowed_unprofitable_era_count) - { - true => { - era_number - - u64::from( - protocol_settings.maximum_allowed_unprofitable_era_count, - ) - + 1 - } - false => 0, - }; + let start_checking_index = era_number + - u64::from(protocol_settings.maximum_allowed_unprofitable_era_count) + + 1; let mut should_be_unbonded = true; for index in start_checking_index..era_number { if let Some(set_of_era) = validator_set_histories.get(&index) { From 494082c480c31091c7c03de5d1572465508efcff Mon Sep 17 00:00:00 2001 From: Rivers Yang Date: Tue, 8 Nov 2022 01:24:22 +0800 Subject: [PATCH 06/15] Apply minor optimization. --- near-vault/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/near-vault/src/lib.rs b/near-vault/src/lib.rs index bbaecde..df7b089 100644 --- a/near-vault/src/lib.rs +++ b/near-vault/src/lib.rs @@ -43,7 +43,7 @@ impl NativeNearTokenReceiver { near_amount: U128, ) { assert!( - env::attached_deposit() == near_amount.0, + env::attached_deposit() >= near_amount.0, "Attached deposit is not equal to the requested amount." ); // @@ -72,7 +72,7 @@ impl NativeNearTokenReceiver { pub fn unlock_near(&mut self, receiver_id: AccountId, amount: U128) { self.assert_anchor(); assert!( - env::account_balance() - env::account_locked_balance() > amount.0, + env::account_balance() - env::account_locked_balance() >= amount.0, "Available balance is not enough." ); Promise::new(receiver_id).transfer(amount.0); From 225f90c7a77cc0a04c53880c31be492d04f49376 Mon Sep 17 00:00:00 2001 From: Rivers Yang Date: Tue, 8 Nov 2022 15:17:31 +0800 Subject: [PATCH 07/15] Update package revision and fix testing code. --- Cargo.lock | 700 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 526 insertions(+), 174 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f67ff89..b9acd65 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -74,7 +74,7 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" dependencies = [ - "getrandom 0.2.7", + "getrandom 0.2.8", "once_cell", "version_check", ] @@ -99,9 +99,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.65" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602" +checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" [[package]] name = "appchain-anchor" @@ -109,7 +109,7 @@ version = "2.4.0" dependencies = [ "beefy-light-client", "ed25519-dalek", - "getrandom 0.2.7", + "getrandom 0.2.8", "hex 0.4.3", "near-contract-standards", "near-sdk", @@ -136,7 +136,7 @@ dependencies = [ "num-format", "parity-scale-codec 2.3.1", "parity-scale-codec 3.2.1", - "secp256k1", + "secp256k1 0.20.3", "tokio", "workspaces", "wrapped-appchain-nft", @@ -183,16 +183,16 @@ dependencies = [ [[package]] name = "async-io" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83e21f3a490c72b3b0cf44962180e60045de2925d8dff97918f7ee43c8f637c7" +checksum = "e8121296a9f05be7f34aa4196b1747243b3b62e048bb7906f644f3fbfc490cf7" dependencies = [ + "async-lock", "autocfg 1.1.0", "concurrent-queue", "futures-lite", "libc", "log", - "once_cell", "parking", "polling", "slab", @@ -201,6 +201,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "async-lock" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8101efe8695a6c17e02911402145357e718ac92d3ff88ae8419e84b1707b685" +dependencies = [ + "event-listener", + "futures-lite", +] + [[package]] name = "async-process" version = "1.5.0" @@ -227,9 +237,9 @@ checksum = "7a40729d2133846d9ed0ea60a8b9541bccddab49cd30f0715a1da672fe9a2524" [[package]] name = "async-trait" -version = "0.1.57" +version = "0.1.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76464446b8bc32758d7e88ee1a804d9914cd9b1cb264c029899680b0be29826f" +checksum = "1e805d94e6b5001b651426cf4cd446b1ab5f319d27bab5c644f61de0a804360c" dependencies = [ "proc-macro2", "quote", @@ -280,16 +290,16 @@ checksum = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7" [[package]] name = "base64" -version = "0.13.0" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "beefy-light-client" version = "0.1.0" -source = "git+https://github.com/octopus-network/beefy-light-client.git?branch=main#113215ed340d3cc3f61dd9f4e8b8a6138f5ab736" +source = "git+https://github.com/octopus-network/beefy-light-client.git?branch=main#4f4a18b9132ed8fcd99e20717db49e929b6ce812" dependencies = [ - "beefy-merkle-tree 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.18)", + "beefy-merkle-tree 4.0.0-dev (git+https://github.com/octopus-network/substrate.git?branch=octopus-v0.9.30)", "blake2-rfc", "borsh", "ckb-merkle-mountain-range", @@ -297,13 +307,12 @@ dependencies = [ "libsecp256k1", "parity-scale-codec 3.2.1", "scale-info", - "serde", ] [[package]] name = "beefy-merkle-tree" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.12#d76f39995315ec36980908e4b99709bd14927044" +source = "git+https://github.com/octopus-network/substrate.git?branch=octopus-v0.9.30#82f5c9999008cbd599a74b0fe554606d6ffceed6" dependencies = [ "tiny-keccak", ] @@ -311,7 +320,7 @@ dependencies = [ [[package]] name = "beefy-merkle-tree" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.18#fc3fd073d3a0acf9933c3994b660ebd7b5833f65" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.12#d76f39995315ec36980908e4b99709bd14927044" dependencies = [ "tiny-keccak", ] @@ -480,15 +489,15 @@ checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" [[package]] name = "bumpalo" -version = "3.11.0" +version = "3.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d" +checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" [[package]] name = "byte-slice-cast" -version = "1.2.1" +version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87c5fdd0166095e1d463fc6cc01aa8ce547ad77a4e84d42eb6762b084e28067e" +checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c" [[package]] name = "byteorder" @@ -547,9 +556,9 @@ checksum = "c1db59621ec70f09c5e9b597b220c7a2b43611f4710dc03ceb8748637775692c" [[package]] name = "cc" -version = "1.0.73" +version = "1.0.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" +checksum = "581f5dba903aac52ea3feb5ec4810848460ee833876f1f9b0fdeab1f19091574" [[package]] name = "cfg-if" @@ -590,9 +599,9 @@ dependencies = [ [[package]] name = "ckb-merkle-mountain-range" -version = "0.4.0" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "530710c310c455ced794feaa13f284c4c5d40ae5d82875392a83da7c5f84a8db" +checksum = "4f061f97d64fd1822664bdfb722f7ae5469a97b77567390f7442be5b5dc82a5b" dependencies = [ "cfg-if 0.1.10", ] @@ -606,6 +615,16 @@ dependencies = [ "bitflags", ] +[[package]] +name = "codespan-reporting" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" +dependencies = [ + "termcolor", + "unicode-width", +] + [[package]] name = "concurrent-queue" version = "1.2.4" @@ -682,12 +701,11 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.11" +version = "0.8.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc" +checksum = "edbafec5fa1f196ca66527c1b12c2ec4745ca14b50f1ad8f9f6f720b55d11fac" dependencies = [ "cfg-if 1.0.0", - "once_cell", ] [[package]] @@ -733,9 +751,9 @@ dependencies = [ [[package]] name = "curl-sys" -version = "0.4.56+curl-7.83.1" +version = "0.4.59+curl-7.86.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6093e169dd4de29e468fa649fbae11cdcd5551c81fe5bf1b0677adad7ef3d26f" +checksum = "6cfce34829f448b08f55b7db6d0009e23e2e86a34e8c2b366269bf5799b4a407" dependencies = [ "cc", "libc", @@ -759,6 +777,50 @@ dependencies = [ "zeroize", ] +[[package]] +name = "cxx" +version = "1.0.80" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b7d4e43b25d3c994662706a1d4fcfc32aaa6afd287502c111b237093bb23f3a" +dependencies = [ + "cc", + "cxxbridge-flags", + "cxxbridge-macro", + "link-cplusplus", +] + +[[package]] +name = "cxx-build" +version = "1.0.80" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84f8829ddc213e2c1368e51a2564c552b65a8cb6a28f31e576270ac81d5e5827" +dependencies = [ + "cc", + "codespan-reporting", + "once_cell", + "proc-macro2", + "quote", + "scratch", + "syn", +] + +[[package]] +name = "cxxbridge-flags" +version = "1.0.80" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e72537424b474af1460806647c41d4b6d35d09ef7fe031c5c2fa5766047cc56a" + +[[package]] +name = "cxxbridge-macro" +version = "1.0.80" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "309e4fb93eed90e1e14bea0da16b209f81813ba9fc7830c20ed151dd7bc0a4d7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "derive_more" version = "0.99.17" @@ -899,14 +961,14 @@ dependencies = [ [[package]] name = "filetime" -version = "0.2.17" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94a7bbaa59354bc20dd75b67f23e2797b4490e9d6928203fb105c79e448c86c" +checksum = "4b9663d381d07ae25dc88dbdf27df458faa83a9b25336bcac83d5e452b5fc9d3" dependencies = [ "cfg-if 1.0.0", "libc", "redox_syscall 0.2.16", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -981,24 +1043,24 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" [[package]] name = "futures-channel" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30bdd20c28fadd505d0fd6712cdfcb0d4b5648baf45faef7f852afb2399bb050" +checksum = "52ba265a92256105f45b719605a571ffe2d1f0fea3807304b522c1d778f79eed" dependencies = [ "futures-core", ] [[package]] name = "futures-core" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e5aa3de05362c3fb88de6531e6296e85cde7739cccad4b9dfeeb7f6ebce56bf" +checksum = "04909a7a7e4633ae6c4a9ab280aeb86da1236243a77b694a49eacd659a4bd3ac" [[package]] name = "futures-io" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbf4d2a7a308fd4578637c0b17c7e1c7ba127b8f6ba00b29f717e9655d85eb68" +checksum = "00f5fb52a06bdcadeb54e8d3671f8888a39697dcb0b81b23b55174030427f4eb" [[package]] name = "futures-lite" @@ -1017,21 +1079,21 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21b20ba5a92e727ba30e72834706623d94ac93a725410b6a6b6fbc1b07f7ba56" +checksum = "39c15cf1a4aa79df40f1bb462fb39676d0ad9e366c2a33b590d7c66f4f81fcf9" [[package]] name = "futures-task" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6508c467c73851293f390476d4491cf4d227dbabcd4170f3bb6044959b294f1" +checksum = "2ffb393ac5d9a6eaa9d3fdf37ae2776656b706e200c8e16b1bdb227f5198e6ea" [[package]] name = "futures-util" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90" +checksum = "197676987abd2f9cadff84926f410af1c183608d36641465df73ae8211dc65d6" dependencies = [ "futures-core", "futures-task", @@ -1062,9 +1124,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" +checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" dependencies = [ "cfg-if 1.0.0", "libc", @@ -1079,9 +1141,9 @@ checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d" [[package]] name = "h2" -version = "0.3.14" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ca32592cf21ac7ccab1825cd87f6c9b3d9022c44d086172ed0966bec8af30be" +checksum = "5f9f29bc9dda355256b2916cf526ab02ce0aeaaaf2bad60d65ef3f12f11dd0f4" dependencies = [ "bytes", "fnv", @@ -1146,9 +1208,9 @@ checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" [[package]] name = "home" -version = "0.5.3" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2456aef2e6b6a9784192ae780c0f15bc57df0e918585282325e8c8ac27737654" +checksum = "747309b4b440c06d57b0b25f2aee03ee9b5e5397d288c60e21fc709bb98a7408" dependencies = [ "winapi", ] @@ -1161,7 +1223,7 @@ checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399" dependencies = [ "bytes", "fnv", - "itoa 1.0.3", + "itoa", ] [[package]] @@ -1189,9 +1251,9 @@ checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" [[package]] name = "hyper" -version = "0.14.20" +version = "0.14.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02c929dc5c39e335a03c405292728118860721b10190d98c2a0f0efd5baafbac" +checksum = "034711faac9d2166cb1baf1a2fb0b60b1f277f8492fd72176c17f3515e1abd3c" dependencies = [ "bytes", "futures-channel", @@ -1202,7 +1264,7 @@ dependencies = [ "http-body", "httparse", "httpdate", - "itoa 1.0.3", + "itoa", "pin-project-lite", "socket2", "tokio", @@ -1226,18 +1288,28 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.48" +version = "0.1.53" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "237a0714f28b1ee39ccec0770ccb544eb02c9ef2c82bb096230eefcffa6468b0" +checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765" dependencies = [ "android_system_properties", "core-foundation-sys", + "iana-time-zone-haiku", "js-sys", - "once_cell", "wasm-bindgen", "winapi", ] +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca" +dependencies = [ + "cxx", + "cxx-build", +] + [[package]] name = "idna" version = "0.2.3" @@ -1300,9 +1372,9 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.5.0" +version = "2.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b" +checksum = "f88c5561171189e69df9d98bcf18fd5f9558300f7ea7b801eb8a0fd748bd8745" [[package]] name = "is_executable" @@ -1315,15 +1387,9 @@ dependencies = [ [[package]] name = "itoa" -version = "0.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" - -[[package]] -name = "itoa" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" +checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" [[package]] name = "js-sys" @@ -1348,9 +1414,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.133" +version = "0.2.137" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0f80d65747a3e43d1596c7c5492d95d5edddaabd45a7fcdb02b95f644164966" +checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" [[package]] name = "libsecp256k1" @@ -1359,7 +1425,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95b09eff1b35ed3b33b877ced3a691fc7a481919c7e29c53c906226fcf55e2a1" dependencies = [ "arrayref", - "base64 0.13.0", + "base64 0.13.1", "digest 0.9.0", "libsecp256k1-core", "libsecp256k1-gen-ecmult", @@ -1410,11 +1476,20 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "link-cplusplus" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9272ab7b96c9046fbc5bc56c06c117cb639fe2d509df0c421cad82d2915cf369" +dependencies = [ + "cc", +] + [[package]] name = "lock_api" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f80bf5aacaf25cbfc8210d1cfb718f2bf3b11c4c54e5afe36c236853a8ec390" +checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" dependencies = [ "autocfg 1.1.0", "scopeguard", @@ -1464,14 +1539,14 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57ee1c23c7c63b0c9250c339ffdc69255f110b298b901b9f6c82547b7b87caaf" +checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de" dependencies = [ "libc", "log", "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -1492,9 +1567,9 @@ dependencies = [ [[package]] name = "native-tls" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd7e2f3618557f980e0b17e8856252eee3c97fa12c54dff0ca290fb6266ca4a9" +checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" dependencies = [ "lazy_static", "libc", @@ -1538,6 +1613,16 @@ dependencies = [ "serde", ] +[[package]] +name = "near-account-id" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d924011380de759c3dc6fdbcda37a19a5c061f56dab69d28a34ecee765e23e4" +dependencies = [ + "borsh", + "serde", +] + [[package]] name = "near-chain-configs" version = "0.14.0" @@ -1557,6 +1642,25 @@ dependencies = [ "tracing", ] +[[package]] +name = "near-chain-configs" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1faf676a95bd1718b06e5957e01a9415fedf7900f32d94d5bcf70abd678b10a2" +dependencies = [ + "anyhow", + "chrono", + "derive_more", + "near-crypto 0.15.0", + "near-primitives 0.15.0", + "num-rational", + "serde", + "serde_json", + "sha2 0.10.6", + "smart-default", + "tracing", +] + [[package]] name = "near-chain-primitives" version = "0.14.0" @@ -1588,7 +1692,7 @@ checksum = "e1065d86012eeea838661434549f33bb6267c9950fd2aadd2af617fe773def38" dependencies = [ "actix", "chrono", - "near-chain-configs", + "near-chain-configs 0.14.0", "near-chain-primitives", "near-chunks-primitives", "near-crypto 0.14.0", @@ -1691,24 +1795,49 @@ dependencies = [ "thiserror", ] +[[package]] +name = "near-crypto" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7754612b47737d277fb818e9fdbb1406e90f9e57151c55c3584d714421976cb6" +dependencies = [ + "arrayref", + "blake2", + "borsh", + "bs58", + "c2-chacha", + "curve25519-dalek", + "derive_more", + "ed25519-dalek", + "near-account-id 0.15.0", + "once_cell", + "primitive-types", + "rand 0.7.3", + "secp256k1 0.24.1", + "serde", + "serde_json", + "subtle", + "thiserror", +] + [[package]] name = "near-jsonrpc-client" -version = "0.4.0-beta.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bba462f54bc35289a1013ed3a2ebfa67cc8b12699f81c12dd67687f200c7b871" +checksum = "384356f354bdf85d0ece627c6af6f38febb5406a4ffb32c5d75429b1a1472e29" dependencies = [ "borsh", "lazy_static", "log", - "near-chain-configs", - "near-crypto 0.14.0", - "near-jsonrpc-primitives", - "near-primitives 0.14.0", + "near-chain-configs 0.15.0", + "near-crypto 0.15.0", + "near-jsonrpc-primitives 0.15.0", + "near-primitives 0.15.0", "reqwest", "serde", "serde_json", "thiserror", - "uuid", + "uuid 1.2.1", ] [[package]] @@ -1717,7 +1846,7 @@ version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34a14ee8ca393c0140cb232789259ebc61b13b4cceb177267d0131f50d0eda6c" dependencies = [ - "near-chain-configs", + "near-chain-configs 0.14.0", "near-client-primitives", "near-crypto 0.14.0", "near-primitives 0.14.0", @@ -1725,7 +1854,22 @@ dependencies = [ "serde", "serde_json", "thiserror", - "uuid", + "uuid 0.8.2", +] + +[[package]] +name = "near-jsonrpc-primitives" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ada226c74f05508c516f109a97b9f23335120d0bfda208f0d187b6bbfe6eef5a" +dependencies = [ + "near-chain-configs 0.15.0", + "near-crypto 0.15.0", + "near-primitives 0.15.0", + "near-rpc-error-macro 0.15.0", + "serde", + "serde_json", + "thiserror", ] [[package]] @@ -1752,7 +1896,7 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78f106c7bbf2a12228daf4af2a976122b030745683ede24b5dc4514e8faaa36c" dependencies = [ - "base64 0.13.0", + "base64 0.13.1", "borsh", "bs58", "byteorder", @@ -1835,6 +1979,36 @@ dependencies = [ "thiserror", ] +[[package]] +name = "near-primitives" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97670b302dce15f09bba50f24c67aa08130fd01528cc61d4415892401e88e974" +dependencies = [ + "borsh", + "byteorder", + "bytesize", + "cfg-if 1.0.0", + "chrono", + "derive_more", + "easy-ext", + "hex 0.4.3", + "near-crypto 0.15.0", + "near-primitives-core 0.15.0", + "near-rpc-error-macro 0.15.0", + "near-vm-errors 0.15.0", + "num-rational", + "once_cell", + "primitive-types", + "rand 0.7.3", + "reed-solomon-erasure", + "serde", + "serde_json", + "smart-default", + "strum", + "thiserror", +] + [[package]] name = "near-primitives-core" version = "0.5.0" @@ -1888,6 +2062,24 @@ dependencies = [ "strum", ] +[[package]] +name = "near-primitives-core" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7929e19d862221949734c4a0063a8f55e7069de3a2ebc2d4f4c13497a5e953cb" +dependencies = [ + "base64 0.13.1", + "borsh", + "bs58", + "derive_more", + "near-account-id 0.15.0", + "num-rational", + "serde", + "serde_repr", + "sha2 0.10.6", + "strum", +] + [[package]] name = "near-rpc-error-core" version = "0.5.0" @@ -1922,6 +2114,17 @@ dependencies = [ "syn", ] +[[package]] +name = "near-rpc-error-core" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36addf90cc04bd547a627b3a292f59d7de4dd6fb5042115419ae901b93ce6c2d" +dependencies = [ + "quote", + "serde", + "syn", +] + [[package]] name = "near-rpc-error-macro" version = "0.5.0" @@ -1958,6 +2161,17 @@ dependencies = [ "syn", ] +[[package]] +name = "near-rpc-error-macro" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b5beb352f3b91d8c491646c2fa4fdbbbf463c7b9c0226951c28f0197de44f99" +dependencies = [ + "near-rpc-error-core 0.15.0", + "serde", + "syn", +] + [[package]] name = "near-sandbox-utils" version = "0.4.1" @@ -1978,7 +2192,7 @@ version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bda34e06e28fb9a09ac54efbdc49f0c9308780fc932aaa81c49c493fde974045" dependencies = [ - "base64 0.13.0", + "base64 0.13.1", "borsh", "bs58", "near-crypto 0.13.0", @@ -2074,6 +2288,19 @@ dependencies = [ "serde", ] +[[package]] +name = "near-vm-errors" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5591c9c8afa83a040cb5c3f29bc52b2efae2c32d4bcaee1bba723738da1a5cf6" +dependencies = [ + "borsh", + "near-account-id 0.15.0", + "near-rpc-error-macro 0.15.0", + "serde", + "strum", +] + [[package]] name = "near-vm-errors" version = "3.1.0" @@ -2093,7 +2320,7 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f024d90451cd3c24d7a0a5cabf3636b192a60eb8e3ff0456f6c18b91152c346d" dependencies = [ - "base64 0.13.0", + "base64 0.13.1", "borsh", "bs58", "byteorder", @@ -2127,12 +2354,12 @@ dependencies = [ [[package]] name = "num-format" -version = "0.4.0" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bafe4179722c2894288ee77a9f044f02811c86af699344c498b0840c698a2465" +checksum = "54b862ff8df690cf089058c98b183676a7ed0f974cc08b426800093227cbff3b" dependencies = [ - "arrayvec 0.4.12", - "itoa 0.4.8", + "arrayvec 0.7.2", + "itoa", ] [[package]] @@ -2169,9 +2396,9 @@ dependencies = [ [[package]] name = "num_cpus" -version = "1.13.1" +version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" +checksum = "f6058e64324c71e02bc2b150e4f3bc8286db6c83092132ffa3f6b1eab0f9def5" dependencies = [ "hermit-abi", "libc", @@ -2188,9 +2415,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.14.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f7254b99e31cad77da24b08ebf628882739a608578bb1bcdfc1f9c21260d7c0" +checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" [[package]] name = "opaque-debug" @@ -2200,9 +2427,9 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "openssl" -version = "0.10.41" +version = "0.10.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "618febf65336490dfcf20b73f885f5651a0c89c64c2d4a8c3662585a70bf5bd0" +checksum = "12fc0523e3bd51a692c8850d075d74dc062ccf251c0110668cbd921917118a13" dependencies = [ "bitflags", "cfg-if 1.0.0", @@ -2232,9 +2459,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.75" +version = "0.9.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5f9bd0c2710541a3cda73d6f9ac4f1b240de4ae261065d309dbe73d9dceb42f" +checksum = "b03b84c3b2d099b81f0953422b4d4ad58761589d0229b5506356afca05a3670a" dependencies = [ "autocfg 1.1.0", "cc", @@ -2325,15 +2552,15 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929" +checksum = "4dc9e0dc2adc1c69d09143aff38d3d30c5c3f0df0dad82e6d25547af174ebec0" dependencies = [ "cfg-if 1.0.0", "libc", "redox_syscall 0.2.16", "smallvec", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -2376,15 +2603,15 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" +checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" [[package]] name = "polling" -version = "2.3.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "899b00b9c8ab553c743b3e11e87c5c7d423b2a2de229ba95b24a756344748011" +checksum = "ab4609a838d88b73d8238967b60dd115cc08d38e2bbaf51ee1e4b695f89122e2" dependencies = [ "autocfg 1.1.0", "cfg-if 1.0.0", @@ -2405,9 +2632,9 @@ dependencies = [ [[package]] name = "ppv-lite86" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "primitive-types" @@ -2442,9 +2669,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.43" +version = "1.0.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" +checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" dependencies = [ "unicode-ident", ] @@ -2573,7 +2800,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom 0.2.7", + "getrandom 0.2.8", ] [[package]] @@ -2688,7 +2915,7 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" dependencies = [ - "getrandom 0.2.7", + "getrandom 0.2.8", "redox_syscall 0.2.16", "thiserror", ] @@ -2704,9 +2931,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.6.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" +checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" dependencies = [ "aho-corasick", "memchr", @@ -2715,9 +2942,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.27" +version = "0.6.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" +checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" [[package]] name = "remove_dir_all" @@ -2730,11 +2957,11 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.11" +version = "0.11.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b75aa69a3f06bbcc66ede33af2af253c6f7a86b1ca0033f60c580a27074fbf92" +checksum = "431949c384f4e2ae07605ccaa56d1d9d2ecdb5cadd4f9577ccfab29f2e5149fc" dependencies = [ - "base64 0.13.0", + "base64 0.13.1", "bytes", "encoding_rs", "futures-core", @@ -2746,10 +2973,10 @@ dependencies = [ "hyper-tls", "ipnet", "js-sys", - "lazy_static", "log", "mime", "native-tls", + "once_cell", "percent-encoding", "pin-project-lite", "serde", @@ -2767,9 +2994,9 @@ dependencies = [ [[package]] name = "ripemd" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74e2ee464e763f6527991a6d532142e3c2016eb9907cc081401c11862c26a840" +checksum = "bd124222d17ad93a644ed9d011a40f4fb64aa54275c08cc216524a9ea82fb09f" dependencies = [ "digest 0.10.5", ] @@ -2780,7 +3007,7 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b18820d944b33caa75a71378964ac46f58517c92b6ae5f762636247c09e78fb" dependencies = [ - "base64 0.13.0", + "base64 0.13.1", "blake2b_simd", "constant_time_eq", "crossbeam-utils", @@ -2821,9 +3048,9 @@ checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" [[package]] name = "scale-info" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "333af15b02563b8182cd863f925bd31ef8fa86a0e095d30c091956057d436153" +checksum = "88d8a765117b237ef233705cc2cc4c6a27fccd46eea6ef0c8c6dae5f3ef407f8" dependencies = [ "cfg-if 1.0.0", "derive_more", @@ -2833,9 +3060,9 @@ dependencies = [ [[package]] name = "scale-info-derive" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53f56acbd0743d29ffa08f911ab5397def774ad01bab3786804cf6ee057fb5e1" +checksum = "cdcd47b380d8c4541044e341dcd9475f55ba37ddc50c908d945fc036a8642496" dependencies = [ "proc-macro-crate 1.2.1", "proc-macro2", @@ -2850,7 +3077,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" dependencies = [ "lazy_static", - "windows-sys", + "windows-sys 0.36.1", ] [[package]] @@ -2859,6 +3086,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "scratch" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898" + [[package]] name = "secp256k1" version = "0.20.3" @@ -2866,7 +3099,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97d03ceae636d0fed5bae6a7f4f664354c5f4fcedf6eef053fef17e49f837d0a" dependencies = [ "rand 0.6.5", - "secp256k1-sys", + "secp256k1-sys 0.4.2", +] + +[[package]] +name = "secp256k1" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff55dc09d460954e9ef2fa8a7ced735a964be9981fd50e870b2b3b0705e14964" +dependencies = [ + "rand 0.8.5", + "secp256k1-sys 0.6.1", ] [[package]] @@ -2878,6 +3121,15 @@ dependencies = [ "cc", ] +[[package]] +name = "secp256k1-sys" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83080e2c2fc1006e625be82e5d1eb6a43b7fd9578b617fcc55814daf286bba4b" +dependencies = [ + "cc", +] + [[package]] name = "security-framework" version = "2.7.0" @@ -2909,18 +3161,18 @@ checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4" [[package]] name = "serde" -version = "1.0.144" +version = "1.0.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f747710de3dcd43b88c9168773254e809d8ddbdf9653b84e2554ab219f17860" +checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.144" +version = "1.0.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94ed3a816fb1d101812f83e789f888322c34e291f894f19590dc310963e87a00" +checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852" dependencies = [ "proc-macro2", "quote", @@ -2929,16 +3181,27 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.85" +version = "1.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" +checksum = "6ce777b7b150d76b9cf60d28b55f5847135a003f7d7350c6be7a773508ce7d45" dependencies = [ "indexmap", - "itoa 1.0.3", + "itoa", "ryu", "serde", ] +[[package]] +name = "serde_repr" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fe39d9fbb0ebf5eb2c7cb7e2a47e4f462fad1379f1166b8ae49ad9eae89a7ca" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -2946,7 +3209,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" dependencies = [ "form_urlencoded", - "itoa 1.0.3", + "itoa", "ryu", "serde", ] @@ -2977,9 +3240,9 @@ dependencies = [ [[package]] name = "sha3" -version = "0.10.5" +version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2904bea16a1ae962b483322a1c7b81d976029203aea1f461e51cd7705db7ba9" +checksum = "bdf0c33fae925bdc080598b84bc15c55e7b9a4a43b3c704da051f977469691c9" dependencies = [ "digest 0.10.5", "keccak", @@ -3006,9 +3269,9 @@ dependencies = [ [[package]] name = "signature" -version = "1.6.3" +version = "1.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "deb766570a2825fa972bceff0d195727876a9cdf2460ab2e52d455dc2de47fd9" +checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" [[package]] name = "siphasher" @@ -3027,9 +3290,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" +checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" [[package]] name = "smart-default" @@ -3088,9 +3351,9 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" -version = "1.0.100" +version = "1.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52205623b1b0f064a4e71182c3b18ae902267282930c6d5462c91b859668426e" +checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" dependencies = [ "proc-macro2", "quote", @@ -3140,20 +3403,29 @@ dependencies = [ "winapi", ] +[[package]] +name = "termcolor" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +dependencies = [ + "winapi-util", +] + [[package]] name = "thiserror" -version = "1.0.35" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c53f98874615aea268107765aa1ed8f6116782501d18e53d08b471733bea6c85" +checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.35" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8b463991b4eab2d801e724172285ec4195c650e8ec79b149e6c2a8e6dd3f783" +checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb" dependencies = [ "proc-macro2", "quote", @@ -3197,9 +3469,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.21.1" +version = "1.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0020c875007ad96677dcc890298f4b942882c5d4eb7cc8f439fc3bf813dc9c95" +checksum = "a9e03c497dc955702ba729190dc4aac6f2a0ce97f913e5b1b5912fc5039d9099" dependencies = [ "autocfg 1.1.0", "bytes", @@ -3207,7 +3479,6 @@ dependencies = [ "memchr", "mio", "num_cpus", - "once_cell", "parking_lot", "pin-project-lite", "signal-hook-registry", @@ -3279,9 +3550,9 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.36" +version = "0.1.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fce9567bd60a67d08a16488756721ba392f24f29006402881e43b19aac64307" +checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" dependencies = [ "cfg-if 1.0.0", "pin-project-lite", @@ -3291,9 +3562,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.22" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11c75893af559bc8e10716548bdef5cb2b983f8e637db9d0e15126b61b484ee2" +checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a" dependencies = [ "proc-macro2", "quote", @@ -3302,9 +3573,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.29" +version = "0.1.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aeea4303076558a00714b823f9ad67d58a3bbda1df83d8827d21193156e22f7" +checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" dependencies = [ "once_cell", ] @@ -3323,9 +3594,9 @@ checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" [[package]] name = "uint" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12f03af7ccf01dd611cc450a0d10dbc9b745770d096473e2faf0ca6e2d66d1e0" +checksum = "a45526d29728d135c2900b0d30573fe3ee79fceb12ef534c7bb30e810a91b601" dependencies = [ "byteorder", "crunchy", @@ -3341,9 +3612,9 @@ checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" [[package]] name = "unicode-ident" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" +checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" [[package]] name = "unicode-normalization" @@ -3354,6 +3625,12 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-width" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" + [[package]] name = "unicode-xid" version = "0.2.4" @@ -3378,7 +3655,16 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" dependencies = [ - "getrandom 0.2.7", + "getrandom 0.2.8", +] + +[[package]] +name = "uuid" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "feb41e78f93363bb2df8b0e86a2ca30eed7806ea16ea0c790d757cf93f79be83" +dependencies = [ + "getrandom 0.2.8", ] [[package]] @@ -3570,6 +3856,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -3582,43 +3877,100 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" dependencies = [ - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_msvc", + "windows_aarch64_msvc 0.36.1", + "windows_i686_gnu 0.36.1", + "windows_i686_msvc 0.36.1", + "windows_x86_64_gnu 0.36.1", + "windows_x86_64_msvc 0.36.1", +] + +[[package]] +name = "windows-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc 0.42.0", + "windows_i686_gnu 0.42.0", + "windows_i686_msvc 0.42.0", + "windows_x86_64_gnu 0.42.0", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc 0.42.0", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" + [[package]] name = "windows_aarch64_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" + [[package]] name = "windows_i686_gnu" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" +[[package]] +name = "windows_i686_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" + [[package]] name = "windows_i686_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" +[[package]] +name = "windows_i686_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" + [[package]] name = "windows_x86_64_gnu" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" + [[package]] name = "windows_x86_64_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" + [[package]] name = "winreg" version = "0.10.1" @@ -3636,7 +3988,7 @@ checksum = "c8b8e4bc0367196fe6386e2c2325c13ee36066392682142d485237e355350e26" dependencies = [ "anyhow", "async-trait", - "base64 0.13.0", + "base64 0.13.1", "borsh", "chrono", "dirs 3.0.2", @@ -3645,7 +3997,7 @@ dependencies = [ "near-account-id 0.14.0", "near-crypto 0.14.0", "near-jsonrpc-client", - "near-jsonrpc-primitives", + "near-jsonrpc-primitives 0.14.0", "near-primitives 0.14.0", "near-sandbox-utils", "portpicker", From 1fab5de9b9a0567b67ebd8abfc7e246fb5780d82 Mon Sep 17 00:00:00 2001 From: Rivers Yang Date: Wed, 9 Nov 2022 21:05:16 +0800 Subject: [PATCH 08/15] Upgrade crate `workspaces` to `v0.6`. --- Cargo.lock | 534 ++---------------- Cargo.toml | 8 +- appchain-anchor/Cargo.toml | 2 +- .../equivocation_challenge.rs | 2 +- appchain-anchor/src/appchain_messages.rs | 2 +- appchain-anchor/src/lib.rs | 9 - .../src/permissionless_actions/mod.rs | 2 +- scripts/cli-samples/reset_state.sh | 4 +- tests/simulator/common/basic_actions.rs | 199 ++++--- tests/simulator/common/complex_actions.rs | 148 +++-- tests/simulator/common/complex_viewer.rs | 225 +++----- tests/simulator/common/mod.rs | 435 +++++++------- .../contract_interfaces/anchor_viewer.rs | 180 +++--- .../contract_interfaces/lifecycle_actions.rs | 22 +- .../contract_interfaces/native_near_token.rs | 12 +- .../near_fungible_token_manager.rs | 9 +- .../permissionless_actions.rs | 25 +- .../contract_interfaces/settings_manager.rs | 89 ++- .../contract_interfaces/staking_actions.rs | 85 ++- .../contract_interfaces/validator_actions.rs | 38 +- .../wrapped_appchain_nft_manager.rs | 16 +- .../wrapped_appchain_token_manager.rs | 23 +- tests/simulator/main.rs | 1 - tests/simulator/test_anchor_actions.rs | 440 ++++++--------- tests/simulator/test_beefy_light_client_1.rs | 277 ++++----- tests/simulator/test_beefy_light_client_2.rs | 109 ---- .../simulator/test_equivocation_challenge.rs | 8 +- tests/simulator/test_migration.rs | 63 +-- tests/simulator/test_sync_staking_amount.rs | 38 +- tests/simulator/test_transfer_native_near.rs | 96 ++-- tests/simulator/test_transfer_nft.rs | 91 ++- .../test_transfer_oct_to_appchain.rs | 15 +- .../simulator/test_wrapped_appchain_token.rs | 63 +-- 33 files changed, 1229 insertions(+), 2041 deletions(-) delete mode 100644 tests/simulator/test_beefy_light_client_2.rs diff --git a/Cargo.lock b/Cargo.lock index b9acd65..f13f57c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,51 +8,6 @@ version = "0.11.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" -[[package]] -name = "actix" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f728064aca1c318585bf4bb04ffcfac9e75e508ab4e8b1bd9ba5dfe04e2cbed5" -dependencies = [ - "actix-rt", - "actix_derive", - "bitflags", - "bytes", - "crossbeam-channel", - "futures-core", - "futures-sink", - "futures-task", - "futures-util", - "log", - "once_cell", - "parking_lot", - "pin-project-lite", - "smallvec", - "tokio", - "tokio-util", -] - -[[package]] -name = "actix-rt" -version = "2.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ea16c295198e958ef31930a6ef37d0fb64e9ca3b6116e6b93a8bdae96ee1000" -dependencies = [ - "futures-core", - "tokio", -] - -[[package]] -name = "actix_derive" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d44b8fee1ced9671ba043476deddef739dd0959bf77030b26b738cc591737a7" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "addr2line" version = "0.17.0" @@ -113,7 +68,7 @@ dependencies = [ "hex 0.4.3", "near-contract-standards", "near-sdk", - "parity-scale-codec 2.3.1", + "parity-scale-codec 3.2.1", ] [[package]] @@ -123,7 +78,6 @@ dependencies = [ "anyhow", "appchain-anchor", "beefy-light-client", - "beefy-merkle-tree 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.12)", "council-keeper", "hex 0.4.3", "hex-literal", @@ -134,9 +88,8 @@ dependencies = [ "near-sdk", "near-units", "num-format", - "parity-scale-codec 2.3.1", "parity-scale-codec 3.2.1", - "secp256k1 0.20.3", + "secp256k1", "tokio", "workspaces", "wrapped-appchain-nft", @@ -188,7 +141,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8121296a9f05be7f34aa4196b1747243b3b62e048bb7906f644f3fbfc490cf7" dependencies = [ "async-lock", - "autocfg 1.1.0", + "autocfg", "concurrent-queue", "futures-lite", "libc", @@ -218,7 +171,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02111fd8655a613c25069ea89fc8d9bb89331fa77486eb3bc059ee757cfa481c" dependencies = [ "async-io", - "autocfg 1.1.0", + "autocfg", "blocking", "cfg-if 1.0.0", "event-listener", @@ -252,15 +205,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a" -[[package]] -name = "autocfg" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dde43e75fd43e8a1bf86103336bc699aa8d17ad1be60c76c0bdfd4828e19b78" -dependencies = [ - "autocfg 1.1.0", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -299,7 +243,7 @@ name = "beefy-light-client" version = "0.1.0" source = "git+https://github.com/octopus-network/beefy-light-client.git?branch=main#4f4a18b9132ed8fcd99e20717db49e929b6ce812" dependencies = [ - "beefy-merkle-tree 4.0.0-dev (git+https://github.com/octopus-network/substrate.git?branch=octopus-v0.9.30)", + "beefy-merkle-tree", "blake2-rfc", "borsh", "ckb-merkle-mountain-range", @@ -317,14 +261,6 @@ dependencies = [ "tiny-keccak", ] -[[package]] -name = "beefy-merkle-tree" -version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.12#d76f39995315ec36980908e4b99709bd14927044" -dependencies = [ - "tiny-keccak", -] - [[package]] name = "binary-install" version = "0.0.2" @@ -556,9 +492,9 @@ checksum = "c1db59621ec70f09c5e9b597b220c7a2b43611f4710dc03ceb8748637775692c" [[package]] name = "cc" -version = "1.0.74" +version = "1.0.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "581f5dba903aac52ea3feb5ec4810848460ee833876f1f9b0fdeab1f19091574" +checksum = "76a284da2e6fe2092f2353e51713435363112dfd60030e22add80be333fb928f" [[package]] name = "cfg-if" @@ -606,15 +542,6 @@ dependencies = [ "cfg-if 0.1.10", ] -[[package]] -name = "cloudabi" -version = "0.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" -dependencies = [ - "bitflags", -] - [[package]] name = "codespan-reporting" version = "0.11.1" @@ -689,16 +616,6 @@ dependencies = [ "cfg-if 1.0.0", ] -[[package]] -name = "crossbeam-channel" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521" -dependencies = [ - "cfg-if 1.0.0", - "crossbeam-utils", -] - [[package]] name = "crossbeam-utils" version = "0.8.12" @@ -779,9 +696,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.80" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b7d4e43b25d3c994662706a1d4fcfc32aaa6afd287502c111b237093bb23f3a" +checksum = "97abf9f0eca9e52b7f81b945524e76710e6cb2366aead23b7d4fbf72e281f888" dependencies = [ "cc", "cxxbridge-flags", @@ -791,9 +708,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.80" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84f8829ddc213e2c1368e51a2564c552b65a8cb6a28f31e576270ac81d5e5827" +checksum = "7cc32cc5fea1d894b77d269ddb9f192110069a8a9c1f1d441195fba90553dea3" dependencies = [ "cc", "codespan-reporting", @@ -806,15 +723,15 @@ dependencies = [ [[package]] name = "cxxbridge-flags" -version = "1.0.80" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e72537424b474af1460806647c41d4b6d35d09ef7fe031c5c2fa5766047cc56a" +checksum = "8ca220e4794c934dc6b1207c3b42856ad4c302f2df1712e9f8d2eec5afaacf1f" [[package]] name = "cxxbridge-macro" -version = "1.0.80" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "309e4fb93eed90e1e14bea0da16b209f81813ba9fc7830c20ed151dd7bc0a4d7" +checksum = "b846f081361125bfc8dc9d3940c84e1fd83ba54bbca7b17cd29483c828be0704" dependencies = [ "proc-macro2", "quote", @@ -1024,10 +941,14 @@ dependencies = [ ] [[package]] -name = "fuchsia-cprng" -version = "0.1.1" +name = "fs2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" +checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213" +dependencies = [ + "libc", + "winapi", +] [[package]] name = "funty" @@ -1357,7 +1278,7 @@ version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" dependencies = [ - "autocfg 1.1.0", + "autocfg", "hashbrown 0.12.3", ] @@ -1491,7 +1412,7 @@ version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" dependencies = [ - "autocfg 1.1.0", + "autocfg", "scopeguard", ] @@ -1603,16 +1524,6 @@ dependencies = [ "serde", ] -[[package]] -name = "near-account-id" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71d258582a1878e6db67400b0504a5099db85718d22c2e07f747fe1706ae7150" -dependencies = [ - "borsh", - "serde", -] - [[package]] name = "near-account-id" version = "0.15.0" @@ -1623,25 +1534,6 @@ dependencies = [ "serde", ] -[[package]] -name = "near-chain-configs" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3632a1c691603cb32dd9944c95d8eadbf2c09f45abd95350ea6848c649036a0b" -dependencies = [ - "anyhow", - "chrono", - "derive_more", - "near-crypto 0.14.0", - "near-primitives 0.14.0", - "num-rational", - "serde", - "serde_json", - "sha2 0.10.6", - "smart-default", - "tracing", -] - [[package]] name = "near-chain-configs" version = "0.15.0" @@ -1661,49 +1553,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "near-chain-primitives" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a734353027698b21633a49d478e564c61ae0171c32f6912bb8844add15d72ebe" -dependencies = [ - "chrono", - "near-crypto 0.14.0", - "near-primitives 0.14.0", - "thiserror", - "tracing", -] - -[[package]] -name = "near-chunks-primitives" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c17f6f22f1ab710731dfba4101f12a99cac120d6af80b99899bd335bb8971477" -dependencies = [ - "near-chain-primitives", - "near-primitives 0.14.0", -] - -[[package]] -name = "near-client-primitives" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1065d86012eeea838661434549f33bb6267c9950fd2aadd2af617fe773def38" -dependencies = [ - "actix", - "chrono", - "near-chain-configs 0.14.0", - "near-chain-primitives", - "near-chunks-primitives", - "near-crypto 0.14.0", - "near-network-primitives", - "near-primitives 0.14.0", - "serde", - "serde_json", - "strum", - "thiserror", -] - [[package]] name = "near-contract-standards" version = "4.0.0" @@ -1769,32 +1618,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "near-crypto" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e75673d69fd7365508f3d32483669fe45b03bfb34e4d9363e90adae9dfb416c" -dependencies = [ - "arrayref", - "blake2", - "borsh", - "bs58", - "c2-chacha", - "curve25519-dalek", - "derive_more", - "ed25519-dalek", - "near-account-id 0.14.0", - "once_cell", - "parity-secp256k1", - "primitive-types", - "rand 0.7.3", - "rand_core 0.5.1", - "serde", - "serde_json", - "subtle", - "thiserror", -] - [[package]] name = "near-crypto" version = "0.15.0" @@ -1813,7 +1636,7 @@ dependencies = [ "once_cell", "primitive-types", "rand 0.7.3", - "secp256k1 0.24.1", + "secp256k1", "serde", "serde_json", "subtle", @@ -1829,32 +1652,15 @@ dependencies = [ "borsh", "lazy_static", "log", - "near-chain-configs 0.15.0", + "near-chain-configs", "near-crypto 0.15.0", - "near-jsonrpc-primitives 0.15.0", + "near-jsonrpc-primitives", "near-primitives 0.15.0", "reqwest", "serde", "serde_json", "thiserror", - "uuid 1.2.1", -] - -[[package]] -name = "near-jsonrpc-primitives" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34a14ee8ca393c0140cb232789259ebc61b13b4cceb177267d0131f50d0eda6c" -dependencies = [ - "near-chain-configs 0.14.0", - "near-client-primitives", - "near-crypto 0.14.0", - "near-primitives 0.14.0", - "near-rpc-error-macro 0.14.0", - "serde", - "serde_json", - "thiserror", - "uuid 0.8.2", + "uuid", ] [[package]] @@ -1863,7 +1669,7 @@ version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ada226c74f05508c516f109a97b9f23335120d0bfda208f0d187b6bbfe6eef5a" dependencies = [ - "near-chain-configs 0.15.0", + "near-chain-configs", "near-crypto 0.15.0", "near-primitives 0.15.0", "near-rpc-error-macro 0.15.0", @@ -1872,24 +1678,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "near-network-primitives" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aa998a1e70ebf8cf3efa76c4562ef36038cc88b4aee60efb708d14273910357" -dependencies = [ - "actix", - "anyhow", - "borsh", - "chrono", - "near-crypto 0.14.0", - "near-primitives 0.14.0", - "serde", - "strum", - "tokio", - "tracing", -] - [[package]] name = "near-primitives" version = "0.5.0" @@ -1950,35 +1738,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "near-primitives" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad1a9a1640539c81f065425c31bffcfbf6b31ef1aeaade59ce905f5df6ac860" -dependencies = [ - "borsh", - "byteorder", - "bytesize", - "chrono", - "derive_more", - "easy-ext", - "hex 0.4.3", - "near-crypto 0.14.0", - "near-primitives-core 0.14.0", - "near-rpc-error-macro 0.14.0", - "near-vm-errors 0.14.0", - "num-rational", - "once_cell", - "primitive-types", - "rand 0.7.3", - "reed-solomon-erasure", - "serde", - "serde_json", - "smart-default", - "strum", - "thiserror", -] - [[package]] name = "near-primitives" version = "0.15.0" @@ -2045,23 +1804,6 @@ dependencies = [ "strum", ] -[[package]] -name = "near-primitives-core" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91d508f0fc340f6461e4e256417685720d3c4c00bb5a939b105160e49137caba" -dependencies = [ - "base64 0.11.0", - "borsh", - "bs58", - "derive_more", - "near-account-id 0.14.0", - "num-rational", - "serde", - "sha2 0.10.6", - "strum", -] - [[package]] name = "near-primitives-core" version = "0.15.0" @@ -2103,17 +1845,6 @@ dependencies = [ "syn", ] -[[package]] -name = "near-rpc-error-core" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93ee0b41c75ef859c193a8ff1dadfa0c8207bc0ac447cc22259721ad769a1408" -dependencies = [ - "quote", - "serde", - "syn", -] - [[package]] name = "near-rpc-error-core" version = "0.15.0" @@ -2150,17 +1881,6 @@ dependencies = [ "syn", ] -[[package]] -name = "near-rpc-error-macro" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e837bd4bacd807073ec5ceb85708da7f721b46a4c2a978de86027fb0034ce31" -dependencies = [ - "near-rpc-error-core 0.14.0", - "serde", - "syn", -] - [[package]] name = "near-rpc-error-macro" version = "0.15.0" @@ -2174,14 +1894,15 @@ dependencies = [ [[package]] name = "near-sandbox-utils" -version = "0.4.1" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bafbc6e0f88ba3c4dd41d947d6ef86367dc2d9b5e0112bde1a5ae8251a71b4f7" +checksum = "201b7e0c5fcff633fb53e743b16c6aea4110e531764ccaa215ea1382db940b45" dependencies = [ "anyhow", "async-process", "binary-install", "chrono", + "fs2", "hex 0.3.2", "home", ] @@ -2276,18 +1997,6 @@ dependencies = [ "serde", ] -[[package]] -name = "near-vm-errors" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0da466a30f0446639cbd788c30865086fac3e8dcb07a79e51d2b0775ed4261e" -dependencies = [ - "borsh", - "near-account-id 0.14.0", - "near-rpc-error-macro 0.14.0", - "serde", -] - [[package]] name = "near-vm-errors" version = "0.15.0" @@ -2347,7 +2056,7 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f6f7833f2cbf2360a6cfd58cd41a53aa7a90bd4c202f5b1c7dd2ed73c57b2c3" dependencies = [ - "autocfg 1.1.0", + "autocfg", "num-integer", "num-traits", ] @@ -2368,7 +2077,7 @@ version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" dependencies = [ - "autocfg 1.1.0", + "autocfg", "num-traits", ] @@ -2378,7 +2087,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07" dependencies = [ - "autocfg 1.1.0", + "autocfg", "num-bigint", "num-integer", "num-traits", @@ -2391,7 +2100,7 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" dependencies = [ - "autocfg 1.1.0", + "autocfg", ] [[package]] @@ -2463,7 +2172,7 @@ version = "0.9.77" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b03b84c3b2d099b81f0953422b4d4ad58761589d0229b5506356afca05a3670a" dependencies = [ - "autocfg 1.1.0", + "autocfg", "cc", "libc", "pkg-config", @@ -2613,7 +2322,7 @@ version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab4609a838d88b73d8238967b60dd115cc08d38e2bbaf51ee1e4b695f89122e2" dependencies = [ - "autocfg 1.1.0", + "autocfg", "cfg-if 1.0.0", "libc", "log", @@ -2697,25 +2406,6 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" -[[package]] -name = "rand" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" -dependencies = [ - "autocfg 0.1.8", - "libc", - "rand_chacha 0.1.1", - "rand_core 0.4.2", - "rand_hc 0.1.0", - "rand_isaac", - "rand_jitter", - "rand_os", - "rand_pcg", - "rand_xorshift", - "winapi", -] - [[package]] name = "rand" version = "0.7.3" @@ -2726,7 +2416,7 @@ dependencies = [ "libc", "rand_chacha 0.2.2", "rand_core 0.5.1", - "rand_hc 0.2.0", + "rand_hc", ] [[package]] @@ -2740,16 +2430,6 @@ dependencies = [ "rand_core 0.6.4", ] -[[package]] -name = "rand_chacha" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" -dependencies = [ - "autocfg 0.1.8", - "rand_core 0.3.1", -] - [[package]] name = "rand_chacha" version = "0.2.2" @@ -2770,21 +2450,6 @@ dependencies = [ "rand_core 0.6.4", ] -[[package]] -name = "rand_core" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" -dependencies = [ - "rand_core 0.4.2", -] - -[[package]] -name = "rand_core" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" - [[package]] name = "rand_core" version = "0.5.1" @@ -2803,15 +2468,6 @@ dependencies = [ "getrandom 0.2.8", ] -[[package]] -name = "rand_hc" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" -dependencies = [ - "rand_core 0.3.1", -] - [[package]] name = "rand_hc" version = "0.2.0" @@ -2821,68 +2477,6 @@ dependencies = [ "rand_core 0.5.1", ] -[[package]] -name = "rand_isaac" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rand_jitter" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" -dependencies = [ - "libc", - "rand_core 0.4.2", - "winapi", -] - -[[package]] -name = "rand_os" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" -dependencies = [ - "cloudabi", - "fuchsia-cprng", - "libc", - "rand_core 0.4.2", - "rdrand", - "winapi", -] - -[[package]] -name = "rand_pcg" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" -dependencies = [ - "autocfg 0.1.8", - "rand_core 0.4.2", -] - -[[package]] -name = "rand_xorshift" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rdrand" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -dependencies = [ - "rand_core 0.3.1", -] - [[package]] name = "redox_syscall" version = "0.1.57" @@ -3092,16 +2686,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898" -[[package]] -name = "secp256k1" -version = "0.20.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97d03ceae636d0fed5bae6a7f4f664354c5f4fcedf6eef053fef17e49f837d0a" -dependencies = [ - "rand 0.6.5", - "secp256k1-sys 0.4.2", -] - [[package]] name = "secp256k1" version = "0.24.1" @@ -3109,16 +2693,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff55dc09d460954e9ef2fa8a7ced735a964be9981fd50e870b2b3b0705e14964" dependencies = [ "rand 0.8.5", - "secp256k1-sys 0.6.1", -] - -[[package]] -name = "secp256k1-sys" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "957da2573cde917463ece3570eab4a0b3f19de6f1646cde62e6fd3868f566036" -dependencies = [ - "cc", + "secp256k1-sys", ] [[package]] @@ -3285,7 +2860,7 @@ version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" dependencies = [ - "autocfg 1.1.0", + "autocfg", ] [[package]] @@ -3473,7 +3048,7 @@ version = "1.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a9e03c497dc955702ba729190dc4aac6f2a0ce97f913e5b1b5912fc5039d9099" dependencies = [ - "autocfg 1.1.0", + "autocfg", "bytes", "libc", "memchr", @@ -3649,15 +3224,6 @@ dependencies = [ "serde", ] -[[package]] -name = "uuid" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" -dependencies = [ - "getrandom 0.2.8", -] - [[package]] name = "uuid" version = "1.2.1" @@ -3982,29 +3548,31 @@ dependencies = [ [[package]] name = "workspaces" -version = "0.4.1" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8b8e4bc0367196fe6386e2c2325c13ee36066392682142d485237e355350e26" +checksum = "fbc74416d48b2deb83004a0fff9d856e46a026c156da4acc4feca044a0a33755" dependencies = [ - "anyhow", + "async-process", "async-trait", "base64 0.13.1", "borsh", + "bs58", "chrono", "dirs 3.0.2", "hex 0.4.3", "libc", - "near-account-id 0.14.0", - "near-crypto 0.14.0", + "near-account-id 0.15.0", + "near-crypto 0.15.0", "near-jsonrpc-client", - "near-jsonrpc-primitives 0.14.0", - "near-primitives 0.14.0", + "near-jsonrpc-primitives", + "near-primitives 0.15.0", "near-sandbox-utils", "portpicker", "rand 0.8.5", "reqwest", "serde", "serde_json", + "thiserror", "tokio", "tokio-retry", "tracing", diff --git a/Cargo.toml b/Cargo.toml index 1048f74..c706c20 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,11 +13,9 @@ near-primitives = "0.5.0" near-units = "0.2.0" hex = "0.4.2" num-format = "0.4.0" -parity-scale-codec = "2.0.0" -secp256k1-test = { package = "secp256k1", version = "0.20.3", features = ["rand-std", "recovery"] } +secp256k1-test = { package = "secp256k1", version = "0.24", features = ["rand-std", "recovery"] } beefy-light-client = { git = "https://github.com/octopus-network/beefy-light-client.git", branch = "main" } -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } -beefy-merkle-tree = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.12", features = ["keccak"], default-features = false } +parity-scale-codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } # remember to include related mock contracts appchain-anchor = { path = "./appchain-anchor" } mock-appchain-registry = { path = "./mock-appchain-registry" } @@ -26,7 +24,7 @@ wrapped-appchain-token = { git = "https://github.com/octopus-network/wrapped-app wrapped-appchain-nft = { git = "https://github.com/octopus-network/wrapped-appchain-nft.git", branch = "main" } council-keeper = { git = "https://github.com/octopus-network/octopus-dao", branch = "main" } tokio = { version = "1.14", features = ["full"] } -workspaces = "0.4" +workspaces = "0.6" [profile.release] codegen-units = 1 diff --git a/appchain-anchor/Cargo.toml b/appchain-anchor/Cargo.toml index 5c694b3..6255bd5 100644 --- a/appchain-anchor/Cargo.toml +++ b/appchain-anchor/Cargo.toml @@ -12,6 +12,6 @@ beefy-light-client = { git = "https://github.com/octopus-network/beefy-light-cli near-sdk = "4.0.0" near-contract-standards = "4.0.0" hex = "0.4.2" -codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] } +parity-scale-codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } getrandom = { version = "0.2", features = ["custom"] } ed25519-dalek = { version = "1.0.1", features = ["alloc"] } diff --git a/appchain-anchor/src/appchain_challenge/equivocation_challenge.rs b/appchain-anchor/src/appchain_challenge/equivocation_challenge.rs index 5e30048..5166730 100644 --- a/appchain-anchor/src/appchain_challenge/equivocation_challenge.rs +++ b/appchain-anchor/src/appchain_challenge/equivocation_challenge.rs @@ -1,7 +1,7 @@ use crate::*; -use codec::{Decode, Encode}; use core::convert::TryFrom; use ed25519_dalek::Verifier; +use parity_scale_codec::{Decode, Encode}; pub type RoundNumber = u32; pub type SetId = u32; diff --git a/appchain-anchor/src/appchain_messages.rs b/appchain-anchor/src/appchain_messages.rs index 8397eff..9723dcb 100644 --- a/appchain-anchor/src/appchain_messages.rs +++ b/appchain-anchor/src/appchain_messages.rs @@ -1,5 +1,5 @@ use crate::*; -use codec::{Decode, Encode}; +use parity_scale_codec::{Decode, Encode}; #[derive(Encode, Decode, Clone, Serialize, Deserialize, BorshDeserialize, BorshSerialize)] #[serde(crate = "near_sdk::serde")] diff --git a/appchain-anchor/src/lib.rs b/appchain-anchor/src/lib.rs index e59a526..d39aa38 100644 --- a/appchain-anchor/src/lib.rs +++ b/appchain-anchor/src/lib.rs @@ -16,7 +16,6 @@ mod validator_profiles; mod validator_set; use core::convert::TryInto; -use getrandom::{register_custom_getrandom, Error}; use near_contract_standards::non_fungible_token::metadata::TokenMetadata; use near_contract_standards::non_fungible_token::TokenId; use near_contract_standards::upgrade::Ownable; @@ -50,8 +49,6 @@ use validator_set::next_validator_set::NextValidatorSet; use validator_set::validator_set_of_era::ValidatorSetOfEra; use validator_set::ValidatorSetViewer; -register_custom_getrandom!(get_random_in_near); - /// Version of this contract (the same as in Cargo.toml) const ANCHOR_VERSION: &str = "v2.4.1"; /// Constants for gas. @@ -621,12 +618,6 @@ impl AppchainAnchor { } } -pub fn get_random_in_near(buf: &mut [u8]) -> Result<(), Error> { - let random = env::random_seed(); - buf.copy_from_slice(&random); - Ok(()) -} - impl IndexedAndClearable for AppchainNotificationHistory { // fn set_index(&mut self, index: &u64) { diff --git a/appchain-anchor/src/permissionless_actions/mod.rs b/appchain-anchor/src/permissionless_actions/mod.rs index af9a9f2..5bfb019 100644 --- a/appchain-anchor/src/permissionless_actions/mod.rs +++ b/appchain-anchor/src/permissionless_actions/mod.rs @@ -5,9 +5,9 @@ use crate::appchain_messages::Offender; use crate::assets::native_near_token::CONTRACT_ACCOUNT_FOR_NATIVE_NEAR_TOKEN; use crate::interfaces::PermissionlessActions; use crate::*; -use codec::Decode; use core::convert::{TryFrom, TryInto}; use near_contract_standards::non_fungible_token::metadata::TokenMetadata; +use parity_scale_codec::Decode; use std::ops::Add; use std::str::FromStr; diff --git a/scripts/cli-samples/reset_state.sh b/scripts/cli-samples/reset_state.sh index 7cee0d8..25a2e9c 100755 --- a/scripts/cli-samples/reset_state.sh +++ b/scripts/cli-samples/reset_state.sh @@ -2,8 +2,8 @@ set -e # export NEAR_ENV=testnet -export ANCHOR_ACCOUNT_ID=xxxx -export END_ERA=yy +export ANCHOR_ACCOUNT_ID=barnacle0928.registry.test_oct.testnet +export END_ERA=0 # # # diff --git a/tests/simulator/common/basic_actions.rs b/tests/simulator/common/basic_actions.rs index 2c19c5f..4c79d79 100644 --- a/tests/simulator/common/basic_actions.rs +++ b/tests/simulator/common/basic_actions.rs @@ -5,7 +5,7 @@ use near_sdk::json_types::U128; use near_sdk::serde_json::json; use near_units::parse_near; use workspaces::network::Sandbox; -use workspaces::{Account, Contract, Worker}; +use workspaces::{error::Error, Account, Contract, Worker}; const TEST_APPCHAIN_ID: &str = "test-appchain"; @@ -37,117 +37,132 @@ pub async fn initialize_contracts_and_users( decimals: 18, }; let oct_token = root - .create_subaccount(worker, "oct-token") + .create_subaccount("oct-token") .initial_balance(parse_near!("10 N")) .transact() .await? .unwrap(); let oct_token = oct_token - .deploy(&worker, &std::fs::read(format!("res/mock_oct_token.wasm"))?) + .deploy(&std::fs::read(format!("res/mock_oct_token.wasm"))?) .await? .unwrap(); - oct_token - .call(worker, "new") + assert!(oct_token + .call("new") .args_json(json!({ "owner_id": root.id(), "total_supply": U128::from(total_supply), "metadata": oct_ft_metadata - }))? + })) .gas(300_000_000_000_000) .transact() - .await?; + .await + .unwrap() + .is_success()); // // deploy appchain registry contract // let appchain_registry = root - .create_subaccount(worker, "appchain-registry") + .create_subaccount("appchain-registry") .initial_balance(parse_near!("100 N")) .transact() .await? .unwrap(); let appchain_registry = appchain_registry - .deploy( - worker, - &std::fs::read(format!("res/mock_appchain_registry.wasm"))?, - ) + .deploy(&std::fs::read(format!("res/mock_appchain_registry.wasm"))?) .await? .unwrap(); - appchain_registry - .call(worker, "new") + assert!(appchain_registry + .call("new") .args_json(json!({ "oct_token": oct_token.id() - }))? + })) .gas(300_000_000_000_000) .transact() - .await?; + .await + .unwrap() + .is_success()); // - // deploy octopus council contract + // create octopus dao account + // + let octopus_dao = root + .create_subaccount("octopus-dao") + .initial_balance(parse_near!("10 N")) + .transact() + .await? + .unwrap(); + // + // deploy council keeper contract // let council_keeper = appchain_registry .as_account() - .create_subaccount(worker, "octopus-council") + .create_subaccount("council-keeper") .initial_balance(parse_near!("10 N")) .transact() .await? .unwrap(); let council_keeper = council_keeper - .deploy(worker, &std::fs::read(format!("res/council_keeper.wasm"))?) + .deploy(&std::fs::read(format!("res/council_keeper.wasm"))?) .await? .unwrap(); - council_keeper - .call(worker, "new") + assert!(council_keeper + .call("new") .args_json(json!({ "max_number_of_council_members": 3, - "dao_contract_account": council_keeper.id().to_string(), - }))? + "dao_contract_account": octopus_dao.id().to_string(), + })) .gas(300_000_000_000_000) .transact() - .await?; + .await + .unwrap() + .is_success()); // // deploy appchain anchor contract // let appchain_anchor = appchain_registry .as_account() - .create_subaccount(worker, TEST_APPCHAIN_ID) + .create_subaccount(TEST_APPCHAIN_ID) .initial_balance(parse_near!("50 N")) .transact() .await? .unwrap(); let appchain_anchor = match with_old_anchor { true => appchain_anchor - .deploy( - worker, - &std::fs::read(format!("res/appchain_anchor_v2.4.0.wasm"))?, - ) + .deploy(&std::fs::read(format!("res/appchain_anchor_v2.4.1.wasm"))?) .await? .unwrap(), false => appchain_anchor - .deploy(worker, &std::fs::read(format!("res/appchain_anchor.wasm"))?) + .deploy(&std::fs::read(format!("res/appchain_anchor.wasm"))?) .await? .unwrap(), }; match with_old_anchor { true => { - root.call(worker, appchain_anchor.id(), "new") + assert!(root + .call(appchain_anchor.id(), "new") .args_json(json!({ "appchain_id": TEST_APPCHAIN_ID.to_string(), "appchain_template_type": AppchainTemplateType::Barnacle, "appchain_registry": appchain_registry.id(), "oct_token": oct_token.id(), - }))? + })) .gas(300_000_000_000_000) .transact() - .await? + .await + .unwrap() + .is_success()) } false => { - root.call(worker, appchain_anchor.id(), "new") + assert!(root + .call(appchain_anchor.id(), "new") .args_json(json!({ "appchain_template_type": AppchainTemplateType::Barnacle, "oct_token": oct_token.id(), - }))? + })) .gas(300_000_000_000_000) .transact() - .await? + .await + .unwrap() + .is_success()); } }; // @@ -155,79 +170,106 @@ pub async fn initialize_contracts_and_users( // let wat_faucet = appchain_anchor .as_account() - .create_subaccount(worker, "wat-faucet") + .create_subaccount("wat-faucet") .initial_balance(parse_near!("5 N")) .transact() .await? .unwrap(); let wat_faucet = wat_faucet - .deploy(worker, &std::fs::read(format!("res/wat_faucet.wasm"))?) + .deploy(&std::fs::read(format!("res/wat_faucet.wasm"))?) .await? .unwrap(); - wat_faucet - .call(worker, "new") + assert!(wat_faucet + .call("new") .gas(300_000_000_000_000) .transact() - .await?; + .await + .unwrap() + .is_success()); // // initialize users' accounts // - register_user_to_ft_contract(worker, appchain_registry.as_account(), &oct_token).await?; - register_user_to_ft_contract(worker, appchain_anchor.as_account(), &oct_token).await?; + register_user_to_ft_contract(appchain_registry.as_account(), &oct_token).await; + register_user_to_ft_contract(appchain_anchor.as_account(), &oct_token).await; // Create users and transfer a certain amount of OCT token to them // alice let alice = root - .create_subaccount(worker, "alice") + .create_subaccount("alice") .initial_balance(parse_near!("50 N")) .transact() .await? .unwrap(); - register_user_to_ft_contract(worker, &alice, &oct_token).await?; - super::call_ft_transfer(worker, &root, &alice, total_supply / 10, &oct_token).await?; + register_user_to_ft_contract(&alice, &oct_token).await; + assert!( + super::call_ft_transfer(&root, &alice, total_supply / 10, &oct_token) + .await + .unwrap() + .is_success() + ); users.push(alice); // bob let bob = root - .create_subaccount(worker, "bob") + .create_subaccount("bob") .initial_balance(parse_near!("50 N")) .transact() .await? .unwrap(); - register_user_to_ft_contract(worker, &bob, &oct_token).await?; - super::call_ft_transfer(worker, &root, &bob, total_supply / 10, &oct_token).await?; + register_user_to_ft_contract(&bob, &oct_token).await; + assert!( + super::call_ft_transfer(&root, &bob, total_supply / 10, &oct_token) + .await + .unwrap() + .is_success() + ); users.push(bob); // charlie let charlie = root - .create_subaccount(worker, "charlie") + .create_subaccount("charlie") .initial_balance(parse_near!("50 N")) .transact() .await? .unwrap(); - register_user_to_ft_contract(worker, &charlie, &oct_token).await?; - super::call_ft_transfer(worker, &root, &charlie, total_supply / 10, &oct_token).await?; + register_user_to_ft_contract(&charlie, &oct_token).await; + assert!( + super::call_ft_transfer(&root, &charlie, total_supply / 10, &oct_token) + .await + .unwrap() + .is_success() + ); users.push(charlie); // dave let dave = root - .create_subaccount(worker, "dave") + .create_subaccount("dave") .initial_balance(parse_near!("50 N")) .transact() .await? .unwrap(); - register_user_to_ft_contract(worker, &dave, &oct_token).await?; - super::call_ft_transfer(worker, &root, &dave, total_supply / 10, &oct_token).await?; + register_user_to_ft_contract(&dave, &oct_token).await; + assert!( + super::call_ft_transfer(&root, &dave, total_supply / 10, &oct_token) + .await + .unwrap() + .is_success() + ); users.push(dave); // eve let eve = root - .create_subaccount(worker, "eve") + .create_subaccount("eve") .initial_balance(parse_near!("50 N")) .transact() .await? .unwrap(); - register_user_to_ft_contract(worker, &eve, &oct_token).await?; - super::call_ft_transfer(worker, &root, &eve, total_supply / 10, &oct_token).await?; + register_user_to_ft_contract(&eve, &oct_token).await; + assert!( + super::call_ft_transfer(&root, &eve, total_supply / 10, &oct_token) + .await + .unwrap() + .is_success() + ); users.push(eve); // relayer let relayer = root - .create_subaccount(worker, "relayer") + .create_subaccount("relayer") .initial_balance(parse_near!("50 N")) .transact() .await? @@ -246,13 +288,12 @@ pub async fn initialize_contracts_and_users( } pub async fn deploy_wrapped_appchain_token_contract( - worker: &Worker, root: &Account, anchor: &Contract, premined_beneficiary: &Account, premined_balance: &U128, users: &Vec, -) -> anyhow::Result { +) -> Result { let wat_ft_metadata = FungibleTokenMetadata { spec: FT_METADATA_SPEC.to_string(), name: "WrappedAppchainToken".to_string(), @@ -263,50 +304,46 @@ pub async fn deploy_wrapped_appchain_token_contract( decimals: 18, }; let wrapped_appchain_token = root - .create_subaccount(worker, "wrapped_appchain_token") + .create_subaccount("wrapped_appchain_token") .initial_balance(parse_near!("50 N")) .transact() .await? .unwrap(); let wrapped_appchain_token = wrapped_appchain_token - .deploy( - worker, - &std::fs::read(format!("res/wrapped_appchain_token.wasm"))?, - ) + .deploy(&std::fs::read(format!("res/wrapped_appchain_token.wasm")).unwrap()) .await? .unwrap(); - wrapped_appchain_token - .call(worker, "new") + assert!(wrapped_appchain_token + .call("new") .args_json(json!({ "owner_id": anchor.id(), "premined_beneficiary": premined_beneficiary.id(), "premined_balance": premined_balance, "metadata": wat_ft_metadata, - }))? + })) .gas(300_000_000_000_000) .transact() - .await?; + .await + .unwrap() + .is_success()); for user in users { - register_user_to_ft_contract(worker, &user, &wrapped_appchain_token).await?; + register_user_to_ft_contract(&user, &wrapped_appchain_token).await; } Ok(wrapped_appchain_token) } // Register the given `user` to fungible token contract -pub async fn register_user_to_ft_contract( - worker: &Worker, - account: &Account, - ft_token_contract: &Contract, -) -> anyhow::Result<()> { - ft_token_contract - .call(worker, "storage_deposit") +pub async fn register_user_to_ft_contract(account: &Account, ft_token_contract: &Contract) { + assert!(ft_token_contract + .call("storage_deposit") .args_json(json!({ "account_id": Some(account.id()), "registration_only": Option::::None, - }))? + })) .gas(20_000_000_000_000) .deposit(near_sdk::env::storage_byte_cost() * 125) .transact() - .await?; - Ok(()) + .await + .unwrap() + .is_success()); } diff --git a/tests/simulator/common/complex_actions.rs b/tests/simulator/common/complex_actions.rs index c06cf60..b607395 100644 --- a/tests/simulator/common/complex_actions.rs +++ b/tests/simulator/common/complex_actions.rs @@ -17,23 +17,19 @@ use appchain_anchor::{ use near_primitives::borsh::BorshSerialize; use near_sdk::{json_types::U64, serde_json}; use parity_scale_codec::Encode; -use workspaces::network::Sandbox; -use workspaces::{Account, Contract, Worker}; +use workspaces::{Account, Contract}; -pub async fn process_appchain_messages( - worker: &Worker, - signer: &Account, - anchor: &Contract, -) -> anyhow::Result<()> { +pub async fn process_appchain_messages(signer: &Account, anchor: &Contract) { loop { - let result = - permissionless_actions::process_appchain_messages(worker, signer, anchor).await?; + let result = permissionless_actions::process_appchain_messages(signer, anchor) + .await + .unwrap(); println!( "Process appchain messages: {}", serde_json::to_string::(&result).unwrap() ); println!(); - print_anchor_status(worker, anchor).await?; + print_anchor_status(anchor).await; match result { MultiTxsOperationProcessingResult::Ok => break, MultiTxsOperationProcessingResult::NeedMoreGas => (), @@ -42,17 +38,15 @@ pub async fn process_appchain_messages( } } } - Ok(()) } pub async fn switch_era( - worker: &Worker, relayer: &Account, anchor: &Contract, era_number: u32, appchain_message_nonce: u32, to_confirm_view_result: bool, -) -> anyhow::Result<()> { +) { if era_number > 0 { let payload = PlanNewEraPayload { new_era: era_number, @@ -64,8 +58,7 @@ pub async fn switch_era( }; let mut raw_messages = Vec::new(); raw_messages.push(raw_message); - permissionless_actions::verify_and_stage_appchain_messages( - worker, + assert!(permissionless_actions::verify_and_stage_appchain_messages( relayer, anchor, raw_messages.encode(), @@ -74,22 +67,21 @@ pub async fn switch_era( Vec::new(), ) .await - .expect("Failed to call 'verify_and_stage_appchain_messages'"); + .unwrap() + .is_success()); } - process_appchain_messages(worker, relayer, anchor).await?; + process_appchain_messages(relayer, anchor).await; if to_confirm_view_result { - let anchor_status = anchor_viewer::get_anchor_status(worker, anchor).await?; + let anchor_status = anchor_viewer::get_anchor_status(anchor).await.unwrap(); println!( "Anchor status: {}", serde_json::to_string::(&anchor_status).unwrap() ); println!(); - let validator_set_info = anchor_viewer::get_validator_set_info_of( - worker, - anchor, - U64::from(u64::from(era_number)), - ) - .await?; + let validator_set_info = + anchor_viewer::get_validator_set_info_of(anchor, U64::from(u64::from(era_number))) + .await + .unwrap(); println!( "Validator set info of era {}: {}", era_number, @@ -97,11 +89,9 @@ pub async fn switch_era( ); println!(); } - Ok(()) } pub async fn distribute_reward_of( - worker: &Worker, relayer: &Account, anchor: &Contract, wrapped_appchain_token: &Contract, @@ -109,9 +99,11 @@ pub async fn distribute_reward_of( era_number: u32, unprofitable_validator_ids: Vec, to_confirm_view_result: bool, -) -> anyhow::Result<()> { +) { let anchor_balance_of_wat = - common::get_ft_balance_of(worker, &anchor.as_account(), &wrapped_appchain_token).await?; + common::get_ft_balance_of(&anchor.as_account(), &wrapped_appchain_token) + .await + .unwrap(); let payload = EraPayoutPayload { end_era: era_number, excluded_validators: unprofitable_validator_ids, @@ -124,8 +116,7 @@ pub async fn distribute_reward_of( }; let mut raw_messages = Vec::new(); raw_messages.push(raw_message); - permissionless_actions::verify_and_stage_appchain_messages( - worker, + assert!(permissionless_actions::verify_and_stage_appchain_messages( relayer, anchor, raw_messages.encode(), @@ -134,128 +125,127 @@ pub async fn distribute_reward_of( Vec::new(), ) .await - .expect("Failed to call 'verify_and_stage_appchain_messages'"); + .unwrap() + .is_success()); if to_confirm_view_result { - let anchor_status = anchor_viewer::get_anchor_status(worker, anchor).await?; + let anchor_status = anchor_viewer::get_anchor_status(anchor).await.unwrap(); println!( "Anchor status: {}", serde_json::to_string::(&anchor_status).unwrap() ); println!(); } - process_appchain_messages(worker, relayer, anchor).await?; + process_appchain_messages(relayer, anchor).await; assert_eq!( - common::get_ft_balance_of(worker, &anchor.as_account(), &wrapped_appchain_token) - .await? + common::get_ft_balance_of(&anchor.as_account(), &wrapped_appchain_token) + .await + .unwrap() .0, anchor_balance_of_wat.0 + common::to_actual_amount(10, 18) ); if to_confirm_view_result { - let anchor_status = anchor_viewer::get_anchor_status(worker, anchor).await?; + let anchor_status = anchor_viewer::get_anchor_status(anchor).await.unwrap(); println!( "Anchor status: {}", serde_json::to_string::(&anchor_status).unwrap() ); println!(); - let validator_set_info = anchor_viewer::get_validator_set_info_of( - worker, - anchor, - U64::from(u64::from(era_number)), - ) - .await?; + let validator_set_info = + anchor_viewer::get_validator_set_info_of(anchor, U64::from(u64::from(era_number))) + .await + .unwrap(); println!( "Validator set info of era {}: {}", era_number, serde_json::to_string::(&validator_set_info).unwrap() ); println!(); - print_appchain_notifications(worker, &anchor).await?; + print_appchain_notifications(&anchor).await; } - Ok(()) } pub async fn withdraw_validator_rewards_of( - worker: &Worker, anchor: &Contract, user: &Account, wrapped_appchain_token: &Contract, end_era: u64, -) -> anyhow::Result<()> { - print_wat_balance_of_anchor(worker, anchor, wrapped_appchain_token).await?; - let wat_balance_before_withdraw = - common::get_ft_balance_of(worker, user, wrapped_appchain_token).await?; - staking_actions::withdraw_validator_rewards( - worker, +) { + print_wat_balance_of_anchor(anchor, wrapped_appchain_token).await; + let wat_balance_before_withdraw = common::get_ft_balance_of(user, wrapped_appchain_token) + .await + .unwrap(); + assert!(staking_actions::withdraw_validator_rewards( user, anchor, &user.id().to_string().parse().unwrap(), ) - .await?; + .await + .unwrap() + .is_success()); println!( "User '{}' withdrawed rewards: {}", &user.id(), - common::get_ft_balance_of(worker, user, wrapped_appchain_token) - .await? + common::get_ft_balance_of(user, wrapped_appchain_token) + .await + .unwrap() .0 - wat_balance_before_withdraw.0 ); println!(); - print_validator_reward_histories(worker, anchor, user, end_era).await?; - Ok(()) + print_validator_reward_histories(anchor, user, end_era).await; } pub async fn withdraw_delegator_rewards_of( - worker: &Worker, anchor: &Contract, user: &Account, validator: &Account, wrapped_appchain_token: &Contract, end_era: u64, -) -> anyhow::Result<()> { - print_wat_balance_of_anchor(worker, anchor, wrapped_appchain_token).await?; - let wat_balance_before_withdraw = - common::get_ft_balance_of(worker, user, wrapped_appchain_token).await?; - staking_actions::withdraw_delegator_rewards( - worker, +) { + print_wat_balance_of_anchor(anchor, wrapped_appchain_token).await; + let wat_balance_before_withdraw = common::get_ft_balance_of(user, wrapped_appchain_token) + .await + .unwrap(); + assert!(staking_actions::withdraw_delegator_rewards( user, anchor, &user.id().to_string().parse().unwrap(), &validator.id().to_string().parse().unwrap(), ) - .await?; + .await + .unwrap() + .is_success()); println!( "User '{}' withdrawed delegator rewards: {}", &user.id(), - common::get_ft_balance_of(worker, user, wrapped_appchain_token) - .await? + common::get_ft_balance_of(user, wrapped_appchain_token) + .await + .unwrap() .0 - wat_balance_before_withdraw.0 ); println!(); - print_delegator_reward_histories(worker, anchor, user, validator, end_era).await?; - Ok(()) + print_delegator_reward_histories(anchor, user, validator, end_era).await; } pub async fn withdraw_stake_of( - worker: &Worker, anchor: &Contract, user: &Account, oct_token: &Contract, ) -> anyhow::Result<()> { - let oct_balance_before_withdraw = common::get_ft_balance_of(worker, user, oct_token).await?; - staking_actions::withdraw_stake( - worker, - user, - anchor, - &user.id().to_string().parse().unwrap(), - ) - .await?; + let oct_balance_before_withdraw = common::get_ft_balance_of(user, oct_token).await?; + assert!( + staking_actions::withdraw_stake(user, anchor, &user.id().to_string().parse().unwrap()) + .await + .unwrap() + .is_success() + ); println!( "User '{}' withdrawed stake: {}", &user.id(), - common::get_ft_balance_of(worker, user, oct_token).await?.0 - oct_balance_before_withdraw.0 + common::get_ft_balance_of(user, oct_token).await?.0 - oct_balance_before_withdraw.0 ); println!(); - print_unbonded_stakes_of(worker, anchor, user).await?; + print_unbonded_stakes_of(anchor, user).await; Ok(()) } diff --git a/tests/simulator/common/complex_viewer.rs b/tests/simulator/common/complex_viewer.rs index eb6ca8a..0378cc6 100644 --- a/tests/simulator/common/complex_viewer.rs +++ b/tests/simulator/common/complex_viewer.rs @@ -4,83 +4,62 @@ use appchain_anchor::types::{ ValidatorSetInfo, WrappedAppchainToken, }; use near_sdk::{json_types::U64, serde_json, AccountId}; -use workspaces::network::Sandbox; -use workspaces::{Account, Contract, Worker}; +use workspaces::{Account, Contract}; -pub async fn print_anchor_status( - worker: &Worker, - anchor: &Contract, -) -> anyhow::Result<()> { - let anchor_status = anchor_viewer::get_anchor_status(worker, anchor).await?; +pub async fn print_anchor_status(anchor: &Contract) { + let anchor_status = anchor_viewer::get_anchor_status(anchor).await.unwrap(); println!( "Anchor status: {}", serde_json::to_string::(&anchor_status).unwrap() ); println!(); - Ok(()) } -pub async fn print_appchain_settings( - worker: &Worker, - anchor: &Contract, -) -> anyhow::Result<()> { - let appchain_settings = anchor_viewer::get_appchain_settings(worker, anchor).await?; +pub async fn print_appchain_settings(anchor: &Contract) { + let appchain_settings = anchor_viewer::get_appchain_settings(anchor).await.unwrap(); println!( "Appchain settings: {}", serde_json::to_string::(&appchain_settings).unwrap() ); println!(); - Ok(()) } -pub async fn print_anchor_settings( - worker: &Worker, - anchor: &Contract, -) -> anyhow::Result<()> { - let anchor_settings = anchor_viewer::get_anchor_settings(worker, anchor).await?; +pub async fn print_anchor_settings(anchor: &Contract) { + let anchor_settings = anchor_viewer::get_anchor_settings(anchor).await.unwrap(); println!( "Anchor settings: {}", serde_json::to_string::(&anchor_settings).unwrap() ); println!(); - Ok(()) } -pub async fn print_validator_set_info_of( - worker: &Worker, - anchor: &Contract, - era_number: U64, -) -> anyhow::Result<()> { - let validator_set_info = - anchor_viewer::get_validator_set_info_of(worker, anchor, era_number).await?; +pub async fn print_validator_set_info_of(anchor: &Contract, era_number: U64) { + let validator_set_info = anchor_viewer::get_validator_set_info_of(anchor, era_number) + .await + .unwrap(); println!( "Validator set {} info: {}", era_number.0, serde_json::to_string::(&validator_set_info).unwrap() ); println!(); - Ok(()) } -pub async fn print_wrapped_appchain_token_info( - worker: &Worker, - anchor: &Contract, -) -> anyhow::Result<()> { - let wrapped_appchain_token_info = - anchor_viewer::get_wrapped_appchain_token(worker, &anchor).await?; +pub async fn print_wrapped_appchain_token_info(anchor: &Contract) { + let wrapped_appchain_token_info = anchor_viewer::get_wrapped_appchain_token(&anchor) + .await + .unwrap(); println!( "Wrapped appchain token: {}", serde_json::to_string::(&wrapped_appchain_token_info).unwrap() ); println!(); - Ok(()) } -pub async fn print_near_fungible_tokens( - worker: &Worker, - anchor: &Contract, -) -> anyhow::Result<()> { - let near_fungible_tokens = anchor_viewer::get_near_fungible_tokens(worker, &anchor).await?; +pub async fn print_near_fungible_tokens(anchor: &Contract) { + let near_fungible_tokens = anchor_viewer::get_near_fungible_tokens(&anchor) + .await + .unwrap(); near_fungible_tokens.iter().for_each(|record| { println!( "Near fungible token: {}", @@ -88,28 +67,22 @@ pub async fn print_near_fungible_tokens( ); println!(); }); - Ok(()) } -pub async fn print_native_near_token( - worker: &Worker, - anchor: &Contract, -) -> anyhow::Result<()> { - let native_near_token = anchor_viewer::get_native_near_token(worker, &anchor).await?; +pub async fn print_native_near_token(anchor: &Contract) { + let native_near_token = anchor_viewer::get_native_near_token(&anchor).await.unwrap(); println!( "Native NEAR token: {}", serde_json::to_string(&native_near_token).unwrap() ); - Ok(()) } pub async fn print_validator_profile( - worker: &Worker, anchor: &Contract, account_id: &AccountId, account_id_in_appchain: &String, -) -> anyhow::Result<()> { - let result = anchor_viewer::get_validator_profile(worker, &anchor, &account_id).await; +) { + let result = anchor_viewer::get_validator_profile(&anchor, &account_id).await; result .as_ref() .expect("Failed calling 'get_validator_profile'"); @@ -120,12 +93,9 @@ pub async fn print_validator_profile( serde_json::to_string::(&validator_profile.unwrap()).unwrap() ); println!(); - let result = anchor_viewer::get_validator_profile_by_id_in_appchain( - worker, - &anchor, - &account_id_in_appchain, - ) - .await; + let result = + anchor_viewer::get_validator_profile_by_id_in_appchain(&anchor, &account_id_in_appchain) + .await; result .as_ref() .expect("Failed calling 'get_validator_profile_by_id_in_appchain'"); @@ -138,19 +108,17 @@ pub async fn print_validator_profile( ); println!(); } - Ok(()) } -pub async fn print_appchain_notifications( - worker: &Worker, - anchor: &Contract, -) -> anyhow::Result<()> { - let index_range = - anchor_viewer::get_index_range_of_appchain_notification_history(worker, anchor).await?; +pub async fn print_appchain_notifications(anchor: &Contract) { + let index_range = anchor_viewer::get_index_range_of_appchain_notification_history(anchor) + .await + .unwrap(); for i in index_range.start_index.0..index_range.end_index.0 + 1 { if let Some(appchain_notification_history) = - anchor_viewer::get_appchain_notification_history(worker, anchor, i.try_into().unwrap()) - .await? + anchor_viewer::get_appchain_notification_history(anchor, i.try_into().unwrap()) + .await + .unwrap() { println!( "Appchain notification history {}: {}", @@ -160,8 +128,9 @@ pub async fn print_appchain_notifications( println!(); } } - let records = - anchor_viewer::get_appchain_notification_histories(worker, anchor, 0, None).await?; + let records = anchor_viewer::get_appchain_notification_histories(anchor, 0, None) + .await + .unwrap(); records.iter().for_each(|record| { println!( "Appchain notification history {}: {}", @@ -170,17 +139,17 @@ pub async fn print_appchain_notifications( ); println!(); }); - Ok(()) } -pub async fn print_staking_histories( - worker: &Worker, - anchor: &Contract, -) -> anyhow::Result<()> { - let index_range = anchor_viewer::get_index_range_of_staking_history(worker, anchor).await?; +pub async fn print_staking_histories(anchor: &Contract) { + let index_range = anchor_viewer::get_index_range_of_staking_history(anchor) + .await + .unwrap(); for i in index_range.start_index.0..index_range.end_index.0 + 1 { if let Some(staking_history) = - anchor_viewer::get_staking_history(worker, anchor, i.try_into().unwrap()).await? + anchor_viewer::get_staking_history(anchor, i.try_into().unwrap()) + .await + .unwrap() { println!( "Staking history {}: {}", @@ -190,20 +159,15 @@ pub async fn print_staking_histories( println!(); } } - Ok(()) } -pub async fn print_user_staking_histories_of( - worker: &Worker, - anchor: &Contract, - user: &Account, -) -> anyhow::Result<()> { +pub async fn print_user_staking_histories_of(anchor: &Contract, user: &Account) { let staking_histories = anchor_viewer::get_user_staking_histories_of( - worker, anchor, user.id().to_string().parse().unwrap(), ) - .await?; + .await + .unwrap(); let mut index = 0; for staking_history in staking_histories { println!( @@ -215,15 +179,12 @@ pub async fn print_user_staking_histories_of( println!(); index += 1; } - Ok(()) } -pub async fn print_validator_list_of( - worker: &Worker, - anchor: &Contract, - era_number: Option, -) -> anyhow::Result<()> { - let validator_list = anchor_viewer::get_validator_list_of(worker, anchor, era_number).await?; +pub async fn print_validator_list_of(anchor: &Contract, era_number: Option) { + let validator_list = anchor_viewer::get_validator_list_of(anchor, era_number) + .await + .unwrap(); let mut index = 0; for validator in validator_list { if let Some(era_number) = era_number { @@ -243,18 +204,13 @@ pub async fn print_validator_list_of( println!(); index += 1; } - Ok(()) } -pub async fn print_delegator_list_of( - worker: &Worker, - anchor: &Contract, - era_number: u64, - validator: &Account, -) -> anyhow::Result<()> { +pub async fn print_delegator_list_of(anchor: &Contract, era_number: u64, validator: &Account) { let delegator_list = - anchor_viewer::get_delegators_of_validator_in_era(worker, &anchor, era_number, validator) - .await?; + anchor_viewer::get_delegators_of_validator_in_era(&anchor, era_number, validator) + .await + .unwrap(); let mut index = 0; for delegator in delegator_list { println!( @@ -267,17 +223,16 @@ pub async fn print_delegator_list_of( println!(); index += 1; } - Ok(()) } pub async fn print_validator_reward_histories( - worker: &Worker, anchor: &Contract, validator: &Account, end_era: u64, -) -> anyhow::Result<()> { - let reward_histories = - anchor_viewer::get_validator_rewards_of(worker, anchor, 0, end_era, validator).await?; +) { + let reward_histories = anchor_viewer::get_validator_rewards_of(anchor, 0, end_era, validator) + .await + .unwrap(); let mut index = 0; for reward_history in reward_histories { println!( @@ -289,19 +244,18 @@ pub async fn print_validator_reward_histories( println!(); index += 1; } - Ok(()) } pub async fn print_delegator_reward_histories( - worker: &Worker, anchor: &Contract, delegator: &Account, validator: &Account, end_era: u64, -) -> anyhow::Result<()> { +) { let reward_histories = - anchor_viewer::get_delegator_rewards_of(worker, anchor, 0, end_era, delegator, validator) - .await?; + anchor_viewer::get_delegator_rewards_of(anchor, 0, end_era, delegator, validator) + .await + .unwrap(); let mut index = 0; for reward_history in reward_histories { println!( @@ -314,15 +268,12 @@ pub async fn print_delegator_reward_histories( println!(); index += 1; } - Ok(()) } -pub async fn print_unbonded_stakes_of( - worker: &Worker, - anchor: &Contract, - user: &Account, -) -> anyhow::Result<()> { - let unbonded_stakes = anchor_viewer::get_unbonded_stakes_of(worker, anchor, user).await?; +pub async fn print_unbonded_stakes_of(anchor: &Contract, user: &Account) { + let unbonded_stakes = anchor_viewer::get_unbonded_stakes_of(anchor, user) + .await + .unwrap(); let mut index = 0; for unbonded_stake in unbonded_stakes { println!( @@ -334,42 +285,34 @@ pub async fn print_unbonded_stakes_of( println!(); index += 1; } - Ok(()) } -pub async fn print_beefy_light_client_status( - worker: &Worker, - anchor: &Contract, -) -> anyhow::Result<()> { - let status = anchor_viewer::get_beefy_light_client_status(worker, &anchor).await?; +pub async fn print_beefy_light_client_status(anchor: &Contract) { + let status = anchor_viewer::get_beefy_light_client_status(&anchor) + .await + .unwrap(); println!( "Beefy light client status: {}", serde_json::to_string::(&status).unwrap() ); println!(); - Ok(()) } -pub async fn print_wat_balance_of_anchor( - worker: &Worker, - anchor: &Contract, - wrapped_appchain_token: &Contract, -) -> anyhow::Result<()> { - let wat_balance_of_anchor = - get_ft_balance_of(worker, &anchor.as_account(), wrapped_appchain_token).await?; +pub async fn print_wat_balance_of_anchor(anchor: &Contract, wrapped_appchain_token: &Contract) { + let wat_balance_of_anchor = get_ft_balance_of(&anchor.as_account(), wrapped_appchain_token) + .await + .unwrap(); println!( "Wrapped appchain token balance of anchor contract: {}", wat_balance_of_anchor.0 ); println!(); - Ok(()) } -pub async fn print_appchain_messages( - worker: &Worker, - anchor: &Contract, -) -> anyhow::Result<()> { - let appchain_messages = anchor_viewer::get_appchain_messages(worker, anchor, 0, None).await?; +pub async fn print_appchain_messages(anchor: &Contract) { + let appchain_messages = anchor_viewer::get_appchain_messages(anchor, 0, None) + .await + .unwrap(); for appchain_message in appchain_messages { println!( "Appchain message '{}': {}", @@ -378,15 +321,12 @@ pub async fn print_appchain_messages( ); println!(); } - Ok(()) } -pub async fn print_appchain_messages_processing_results( - worker: &Worker, - anchor: &Contract, -) -> anyhow::Result<()> { - let appchain_messages = - anchor_viewer::get_appchain_message_processing_results(worker, anchor, 0, None).await?; +pub async fn print_appchain_messages_processing_results(anchor: &Contract) { + let appchain_messages = anchor_viewer::get_appchain_message_processing_results(anchor, 0, None) + .await + .unwrap(); let mut index = 1; for appchain_message in appchain_messages { println!( @@ -397,5 +337,4 @@ pub async fn print_appchain_messages_processing_results( println!(); index += 1; } - Ok(()) } diff --git a/tests/simulator/common/mod.rs b/tests/simulator/common/mod.rs index 6f20875..dc1d672 100644 --- a/tests/simulator/common/mod.rs +++ b/tests/simulator/common/mod.rs @@ -14,64 +14,57 @@ use near_sdk::AccountId; use std::collections::HashMap; use std::str::FromStr; use workspaces::network::Sandbox; -use workspaces::result::CallExecutionDetails; -use workspaces::{Account, Contract, Worker}; +use workspaces::Worker; +use workspaces::{error::Error, result::ExecutionFinalResult, Account, Contract}; const TOTAL_SUPPLY: u128 = 100_000_000; pub async fn call_ft_transfer( - worker: &Worker, sender: &Account, receiver: &Account, amount: u128, ft_token_contract: &Contract, -) -> anyhow::Result<()> { +) -> Result { sender - .call(worker, ft_token_contract.id(), "ft_transfer") + .call(ft_token_contract.id(), "ft_transfer") .args_json(json!({ "receiver_id": receiver.id(), "amount": U128::from(amount), "memo": Option::::None, - }))? + })) .gas(20_000_000_000_000) .deposit(1) .transact() - .await?; - Ok(()) + .await } pub async fn call_ft_transfer_call( - worker: &Worker, sender: &Account, receiver: &Account, amount: u128, msg: String, ft_token_contract: &Contract, -) -> anyhow::Result { +) -> Result { sender - .call(worker, ft_token_contract.id(), "ft_transfer_call") + .call(ft_token_contract.id(), "ft_transfer_call") .args_json(json!({ "receiver_id": receiver.id(), "amount": U128::from(amount), "memo": Option::::None, "msg": msg.clone(), - }))? + })) .gas(300_000_000_000_000) .deposit(1) .transact() .await } -pub async fn get_ft_balance_of( - worker: &Worker, - user: &Account, - ft_contract: &Contract, -) -> anyhow::Result { +pub async fn get_ft_balance_of(user: &Account, ft_contract: &Contract) -> Result { ft_contract - .call(worker, "ft_balance_of") + .call("ft_balance_of") .args_json(json!({ "account_id": user.id() - }))? + })) .view() .await? .json::() @@ -118,46 +111,59 @@ pub async fn test_normal_actions( // Check initial status // assert_eq!( - anchor_viewer::get_appchain_state(worker, &anchor).await?, + anchor_viewer::get_appchain_state(&anchor).await?, AppchainState::Booting ); if to_confirm_view_result { - let anchor_status = anchor_viewer::get_anchor_status(worker, &anchor).await?; + let anchor_status = anchor_viewer::get_anchor_status(&anchor).await?; assert_eq!(anchor_status.total_stake_in_next_era.0, 0); assert_eq!(anchor_status.validator_count_in_next_era.0, 0); } // // // - settings_manager::set_price_of_oct_token(worker, &users[4], &anchor, 2_130_000) - .await - .expect_err("Should fail"); - wrapped_appchain_token_manager::set_price_of_wrapped_appchain_token( - worker, &users[4], &anchor, 110_000, - ) - .await - .expect_err("Should fail"); - settings_manager::set_token_price_maintainer_account(worker, &root, &anchor, &users[4]) + assert!( + settings_manager::set_price_of_oct_token(&users[4], &anchor, 2_130_000) + .await + .unwrap() + .is_failure() + ); + assert!( + wrapped_appchain_token_manager::set_price_of_wrapped_appchain_token( + &users[4], &anchor, 110_000, + ) .await - .expect("Failed in calling 'set_token_price_maintainer_account'"); + .unwrap() + .is_failure() + ); + assert!( + settings_manager::set_token_price_maintainer_account(&root, &anchor, &users[4]) + .await + .unwrap() + .is_success() + ); // // Initialize wrapped appchain token contract. // - wrapped_appchain_token_manager::set_price_of_wrapped_appchain_token( - worker, &users[4], &anchor, 110, - ) - .await - .expect("Failed in calling 'set_price_of_wrapped_appchain_token'"); - wrapped_appchain_token_manager::set_account_of_wrapped_appchain_token( - worker, - &root, - &anchor, - AccountId::from_str(format!("wrapped_appchain_token.{}", root.id()).as_str()).unwrap(), - ) - .await - .expect("Failed in calling 'set_account_of_wrapped_appchain_token'"); + assert!( + wrapped_appchain_token_manager::set_price_of_wrapped_appchain_token( + &users[4], &anchor, 110 + ) + .await + .unwrap() + .is_success() + ); + assert!( + wrapped_appchain_token_manager::set_account_of_wrapped_appchain_token( + &root, + &anchor, + AccountId::from_str(format!("wrapped_appchain_token.{}", root.id()).as_str()).unwrap(), + ) + .await + .unwrap() + .is_success() + ); let wrapped_appchain_token = basic_actions::deploy_wrapped_appchain_token_contract( - worker, &root, &anchor, &wat_faucet.as_account(), @@ -167,36 +173,35 @@ pub async fn test_normal_actions( .await .expect("Failed to deploy wrapped appchain token contract"); if to_confirm_view_result { - complex_viewer::print_wrapped_appchain_token_info(worker, &anchor).await?; + complex_viewer::print_wrapped_appchain_token_info(&anchor).await; } // - call_ft_transfer( - &worker, + assert!(call_ft_transfer( &wat_faucet.as_account(), &users[0], to_actual_amount(TOTAL_SUPPLY / 2, 18), &wrapped_appchain_token, ) .await - .expect("Failed to call 'ft_transfer' of wrapped appchain token contract."); + .unwrap() + .is_success()); // if !with_old_anchor { - settings_manager::set_bonus_for_new_validator( - &worker, + assert!(settings_manager::set_bonus_for_new_validator( &root, &anchor, - to_actual_amount(1, 18), + to_actual_amount(1, 18) ) .await - .expect("Failed to call 'set_bonus_for_new_validator'."); + .unwrap() + .is_success()); } // // user0 register validator (error) // - let user0_balance = get_ft_balance_of(worker, &users[0], &oct_token).await?; + let user0_balance = get_ft_balance_of(&users[0], &oct_token).await?; let amount0 = to_actual_amount(4999, 18); - staking_actions::register_validator( - worker, + assert!(staking_actions::register_validator( &users[0], &oct_token, &anchor, @@ -206,109 +211,107 @@ pub async fn test_normal_actions( HashMap::new(), ) .await - .expect("Failed in calling 'register_validator'"); + .unwrap() + .is_success()); assert_eq!( - get_ft_balance_of(worker, &users[0], &oct_token).await?.0, + get_ft_balance_of(&users[0], &oct_token).await?.0, user0_balance.0 ); if to_confirm_view_result { - let anchor_status = anchor_viewer::get_anchor_status(worker, &anchor).await?; + let anchor_status = anchor_viewer::get_anchor_status(&anchor).await?; assert_eq!(anchor_status.total_stake_in_next_era.0, 0); assert_eq!(anchor_status.validator_count_in_next_era.0, 0); } // // user0 register validator // - let user0_balance = get_ft_balance_of(worker, &users[0], &oct_token).await?; + let user0_balance = get_ft_balance_of(&users[0], &oct_token).await?; let wat_faucet_balance = - get_ft_balance_of(worker, &wat_faucet.as_account(), &wrapped_appchain_token).await?; + get_ft_balance_of(&wat_faucet.as_account(), &wrapped_appchain_token).await?; let amount0 = to_actual_amount(23_000, 18); - staking_actions::register_validator( - worker, + assert!(staking_actions::register_validator( &users[0], &oct_token, &anchor, &user0_id_in_appchain, amount0, - true, + false, HashMap::new(), ) .await - .expect("Failed in calling 'register_validator'"); + .unwrap() + .is_success()); assert_eq!( - get_ft_balance_of(worker, &users[0], &oct_token).await?.0, + get_ft_balance_of(&users[0], &oct_token).await?.0, user0_balance.0 - amount0 ); if !with_old_anchor { assert_eq!( - get_ft_balance_of(worker, &wat_faucet.as_account(), &wrapped_appchain_token) + get_ft_balance_of(&wat_faucet.as_account(), &wrapped_appchain_token) .await? .0, wat_faucet_balance.0 ); } if to_confirm_view_result { - let anchor_status = anchor_viewer::get_anchor_status(worker, &anchor).await?; + let anchor_status = anchor_viewer::get_anchor_status(&anchor).await?; assert_eq!(anchor_status.total_stake_in_next_era.0, amount0); assert_eq!(anchor_status.validator_count_in_next_era.0, 1); complex_viewer::print_validator_profile( - worker, &anchor, &users[0].id().to_string().parse().unwrap(), &user0_id_in_appchain, ) - .await?; + .await; } // // user1 register validator // - let user1_balance = get_ft_balance_of(worker, &users[1], &oct_token).await?; + let user1_balance = get_ft_balance_of(&users[1], &oct_token).await?; let wat_faucet_balance = - get_ft_balance_of(worker, &wat_faucet.as_account(), &wrapped_appchain_token).await?; + get_ft_balance_of(&wat_faucet.as_account(), &wrapped_appchain_token).await?; let amount1 = to_actual_amount(25_000, 18); - staking_actions::register_validator( - worker, + assert!(staking_actions::register_validator( &users[1], &oct_token, &anchor, &user1_id_in_appchain, amount1, - false, + true, HashMap::new(), ) .await - .expect("Failed in calling 'register_validator'"); + .unwrap() + .is_success()); assert_eq!( - get_ft_balance_of(worker, &users[1], &oct_token).await?.0, + get_ft_balance_of(&users[1], &oct_token).await?.0, user1_balance.0 - amount1 ); if !with_old_anchor { assert_eq!( - get_ft_balance_of(worker, &wat_faucet.as_account(), &wrapped_appchain_token) + get_ft_balance_of(&wat_faucet.as_account(), &wrapped_appchain_token) .await? .0, wat_faucet_balance.0 ); } if to_confirm_view_result { - let anchor_status = anchor_viewer::get_anchor_status(worker, &anchor).await?; + let anchor_status = anchor_viewer::get_anchor_status(&anchor).await?; assert_eq!(anchor_status.total_stake_in_next_era.0, amount0 + amount1); assert_eq!(anchor_status.validator_count_in_next_era.0, 2); complex_viewer::print_validator_profile( - worker, &anchor, &users[1].id().to_string().parse().unwrap(), &user1_id_in_appchain, ) - .await?; + .await; } // // user2 register delegator to user0 (error) // - let user2_balance = get_ft_balance_of(worker, &users[2], &oct_token).await?; + let user2_balance = get_ft_balance_of(&users[2], &oct_token).await?; let amount2 = to_actual_amount(199, 18); - staking_actions::register_delegator( - worker, + assert!(staking_actions::register_delegator( &users[2], &oct_token, &anchor, @@ -316,23 +319,30 @@ pub async fn test_normal_actions( amount2, ) .await - .expect("Failed in calling 'register_delegator'"); + .unwrap() + .is_success()); assert_eq!( - get_ft_balance_of(worker, &users[2], &oct_token).await?.0, + get_ft_balance_of(&users[2], &oct_token).await?.0, user2_balance.0 ); if to_confirm_view_result { - let anchor_status = anchor_viewer::get_anchor_status(worker, &anchor).await?; + let anchor_status = anchor_viewer::get_anchor_status(&anchor).await?; assert_eq!(anchor_status.total_stake_in_next_era.0, amount0 + amount1); assert_eq!(anchor_status.validator_count_in_next_era.0, 2); } // + // user1 enable delegation + // + assert!(validator_actions::enable_delegation(&users[0], &anchor) + .await + .unwrap() + .is_success()); + // // user2 register delegator to user0 // - let user2_balance = get_ft_balance_of(worker, &users[2], &oct_token).await?; + let user2_balance = get_ft_balance_of(&users[2], &oct_token).await?; let amount2_0 = to_actual_amount(1000, 18); - staking_actions::register_delegator( - worker, + assert!(staking_actions::register_delegator( &users[2], &oct_token, &anchor, @@ -340,13 +350,14 @@ pub async fn test_normal_actions( amount2_0, ) .await - .expect("Failed in calling 'register_delegator'"); + .unwrap() + .is_success()); assert_eq!( - get_ft_balance_of(worker, &users[2], &oct_token).await?.0, + get_ft_balance_of(&users[2], &oct_token).await?.0, user2_balance.0 - amount2_0 ); if to_confirm_view_result { - let anchor_status = anchor_viewer::get_anchor_status(worker, &anchor).await?; + let anchor_status = anchor_viewer::get_anchor_status(&anchor).await?; assert_eq!( anchor_status.total_stake_in_next_era.0, amount0 + amount1 + amount2_0 @@ -354,12 +365,18 @@ pub async fn test_normal_actions( assert_eq!(anchor_status.validator_count_in_next_era.0, 2); } // + // user1 disable delegation + // + assert!(validator_actions::disable_delegation(&users[1], &anchor) + .await + .unwrap() + .is_success()); + // // user2 register delegator to user1 (error) // - let user2_balance = get_ft_balance_of(worker, &users[2], &oct_token).await?; + let user2_balance = get_ft_balance_of(&users[2], &oct_token).await?; let amount2_1 = to_actual_amount(1000, 18); - staking_actions::register_delegator( - worker, + assert!(staking_actions::register_delegator( &users[2], &oct_token, &anchor, @@ -367,13 +384,14 @@ pub async fn test_normal_actions( amount2_1, ) .await - .expect("Failed in calling 'register_delegator'"); + .unwrap() + .is_success()); assert_eq!( - get_ft_balance_of(worker, &users[2], &oct_token).await?.0, + get_ft_balance_of(&users[2], &oct_token).await?.0, user2_balance.0 ); if to_confirm_view_result { - let anchor_status = anchor_viewer::get_anchor_status(worker, &anchor).await?; + let anchor_status = anchor_viewer::get_anchor_status(&anchor).await?; assert_eq!( anchor_status.total_stake_in_next_era.0, amount0 + amount1 + amount2_0 @@ -383,10 +401,9 @@ pub async fn test_normal_actions( // // user3 register delegator to user0 // - let user3_balance = get_ft_balance_of(worker, &users[3], &oct_token).await?; + let user3_balance = get_ft_balance_of(&users[3], &oct_token).await?; let amount3_0 = to_actual_amount(2000, 18); - staking_actions::register_delegator( - worker, + assert!(staking_actions::register_delegator( &users[3], &oct_token, &anchor, @@ -394,13 +411,14 @@ pub async fn test_normal_actions( amount3_0, ) .await - .expect("Failed in calling 'register_delegator'"); + .unwrap() + .is_success()); assert_eq!( - get_ft_balance_of(worker, &users[3], &oct_token).await?.0, + get_ft_balance_of(&users[3], &oct_token).await?.0, user3_balance.0 - amount3_0 ); if to_confirm_view_result { - let anchor_status = anchor_viewer::get_anchor_status(worker, &anchor).await?; + let anchor_status = anchor_viewer::get_anchor_status(&anchor).await?; assert_eq!( anchor_status.total_stake_in_next_era.0, amount0 + amount1 + amount2_0 + amount3_0 @@ -410,17 +428,20 @@ pub async fn test_normal_actions( // // user0 increase stake // - let user0_balance = get_ft_balance_of(worker, &users[0], &oct_token).await?; + let user0_balance = get_ft_balance_of(&users[0], &oct_token).await?; let amount0_p = to_actual_amount(1_200, 18); - staking_actions::increase_stake(worker, &users[0], &oct_token, &anchor, amount0_p) - .await - .expect("Failed in calling 'increase_stake'"); + assert!( + staking_actions::increase_stake(&users[0], &oct_token, &anchor, amount0_p) + .await + .unwrap() + .is_success() + ); assert_eq!( - get_ft_balance_of(worker, &users[0], &oct_token).await?.0, + get_ft_balance_of(&users[0], &oct_token).await?.0, user0_balance.0 - amount0_p ); if to_confirm_view_result { - let anchor_status = anchor_viewer::get_anchor_status(worker, &anchor).await?; + let anchor_status = anchor_viewer::get_anchor_status(&anchor).await?; assert_eq!( anchor_status.total_stake_in_next_era.0, amount0 + amount1 + amount2_0 + amount3_0 + amount0_p @@ -430,10 +451,9 @@ pub async fn test_normal_actions( // // user2 increase delegation to user0 // - let user2_balance = get_ft_balance_of(worker, &users[2], &oct_token).await?; + let user2_balance = get_ft_balance_of(&users[2], &oct_token).await?; let amount2_0_p = to_actual_amount(500, 18); - staking_actions::increase_delegation( - worker, + assert!(staking_actions::increase_delegation( &users[2], &oct_token, &anchor, @@ -441,13 +461,14 @@ pub async fn test_normal_actions( amount2_0_p, ) .await - .expect("Failed in calling 'increase_delegation'"); + .unwrap() + .is_success()); assert_eq!( - get_ft_balance_of(worker, &users[2], &oct_token).await?.0, + get_ft_balance_of(&users[2], &oct_token).await?.0, user2_balance.0 - amount2_0_p ); if to_confirm_view_result { - let anchor_status = anchor_viewer::get_anchor_status(worker, &anchor).await?; + let anchor_status = anchor_viewer::get_anchor_status(&anchor).await?; assert_eq!( anchor_status.total_stake_in_next_era.0, amount0 + amount1 + amount2_0 + amount3_0 + amount0_p + amount2_0_p @@ -458,52 +479,71 @@ pub async fn test_normal_actions( // Print anchor status and staking histories // if to_confirm_view_result { - complex_viewer::print_anchor_status(worker, &anchor).await?; - complex_viewer::print_wrapped_appchain_token_info(worker, &anchor).await?; - complex_viewer::print_staking_histories(worker, &anchor).await?; - complex_viewer::print_validator_list_of(worker, &anchor, None).await?; + complex_viewer::print_anchor_status(&anchor).await; + complex_viewer::print_wrapped_appchain_token_info(&anchor).await; + complex_viewer::print_staking_histories(&anchor).await; + complex_viewer::print_validator_list_of(&anchor, None).await; } // // Try generate_initial_validator_set // - lifecycle_actions::generate_initial_validator_set(worker, &root, &anchor) + lifecycle_actions::generate_initial_validator_set(&root, &anchor) .await - .expect_err("Should fail"); + .unwrap() + .is_failure(); // // Set appchain settings and try generate_initial_validator_set // - settings_manager::set_rpc_endpoint(worker, &root, &anchor, "rpc_endpoint".to_string()) - .await - .expect("Failed in calling 'set_rpc_endpoint'"); - settings_manager::set_subql_endpoint(worker, &root, &anchor, "subql_endpoint".to_string()) - .await - .expect("Failed in calling 'set_subql_endpoint'"); - settings_manager::set_era_reward(worker, &root, &anchor, to_actual_amount(10, 18)) - .await - .expect("Failed in calling 'set_era_reward'"); - lifecycle_actions::generate_initial_validator_set(worker, &root, &anchor) + assert!( + settings_manager::set_rpc_endpoint(&root, &anchor, "rpc_endpoint".to_string()) + .await + .unwrap() + .is_success() + ); + assert!( + settings_manager::set_subql_endpoint(&root, &anchor, "subql_endpoint".to_string()) + .await + .unwrap() + .is_success() + ); + assert!( + settings_manager::set_era_reward(&root, &anchor, to_actual_amount(10, 18)) + .await + .unwrap() + .is_success() + ); + lifecycle_actions::generate_initial_validator_set(&root, &anchor) .await - .expect_err("Should fail"); + .unwrap() + .is_failure(); // // Change protocol settings and try generate_initial_validator_set // - settings_manager::change_minimum_validator_count(worker, &root, &anchor, 1) - .await - .expect("Failed in calling 'change_minimum_validator_count'"); - lifecycle_actions::generate_initial_validator_set(worker, &root, &anchor) + assert!( + settings_manager::change_minimum_validator_count(&root, &anchor, 1) + .await + .unwrap() + .is_success() + ); + lifecycle_actions::generate_initial_validator_set(&root, &anchor) .await - .expect_err("Should fail"); + .unwrap() + .is_failure(); // // Change price of OCT token and try generate_initial_validator_set // - settings_manager::set_price_of_oct_token(worker, &users[4], &anchor, 2_130_000) - .await - .expect("Failed in calling 'set_price_of_oct_token'"); - lifecycle_actions::generate_initial_validator_set(worker, &root, &anchor) + assert!( + settings_manager::set_price_of_oct_token(&users[4], &anchor, 2_130_000) + .await + .unwrap() + .is_success() + ); + lifecycle_actions::generate_initial_validator_set(&root, &anchor) .await - .expect("Failed in calling 'generate_initial_validator_set'"); + .unwrap() + .is_failure(); assert_eq!( - anchor_viewer::get_appchain_state(worker, &anchor).await?, + anchor_viewer::get_appchain_state(&anchor).await?, AppchainState::Booting ); // @@ -511,86 +551,99 @@ pub async fn test_normal_actions( // let appchain_message_nonce: u32 = 0; if to_confirm_view_result { - complex_viewer::print_anchor_status(worker, &anchor).await?; - complex_viewer::print_staking_histories(worker, &anchor).await?; - complex_viewer::print_validator_set_info_of(worker, &anchor, U64::from(0)).await?; - complex_viewer::print_validator_list_of(worker, &anchor, Some(0)).await?; - complex_viewer::print_delegator_list_of(worker, &anchor, 0, &users[0]).await?; + complex_viewer::print_anchor_status(&anchor).await; + complex_viewer::print_staking_histories(&anchor).await; + complex_viewer::print_validator_set_info_of(&anchor, U64::from(0)).await; + complex_viewer::print_validator_list_of(&anchor, Some(0)).await; + complex_viewer::print_delegator_list_of(&anchor, 0, &users[0]).await; } // // Initialize beefy light client // - lifecycle_actions::initialize_beefy_light_client(worker, &root, &anchor, initial_public_keys) - .await - .expect("Failed in calling 'initialize_beefy_light_client'"); - settings_manager::turn_on_beefy_light_client_witness_mode(&worker, &root, &anchor) - .await - .expect("Failed in calling 'turn_on_beefy_light_client_witness_mode'"); - settings_manager::set_relayer_account(&worker, &root, &anchor, &users[5]) - .await - .expect("Failed to call 'set_relayer_account'"); + assert!( + lifecycle_actions::initialize_beefy_light_client(&root, &anchor, initial_public_keys) + .await + .unwrap() + .is_success() + ); + assert!( + settings_manager::turn_on_beefy_light_client_witness_mode(&root, &anchor) + .await + .unwrap() + .is_success() + ); + assert!( + settings_manager::set_relayer_account(&root, &anchor, &users[5]) + .await + .unwrap() + .is_success() + ); // // Go live // - lifecycle_actions::go_live(worker, &root, &anchor) + assert!(lifecycle_actions::go_live(&root, &anchor) .await - .expect("Failed in calling 'go_live'"); + .unwrap() + .is_success()); assert_eq!( - anchor_viewer::get_appchain_state(worker, &anchor).await?, + anchor_viewer::get_appchain_state(&anchor).await?, AppchainState::Active ); // // Change id in appchain and profile of user0, user1 // - validator_actions::set_validator_id_in_appchain( - worker, + assert!(validator_actions::set_validator_id_in_appchain( &users[0], &anchor, - &user0_id_in_appchain, + &user0_id_in_appchain ) .await - .expect("Failed in calling 'set_validator_id_in_appchain'"); - validator_actions::set_validator_profile(worker, &users[0], &anchor, &user0_profile) - .await - .expect("Failed in calling 'set_validator_profile'"); + .unwrap() + .is_success()); + assert!( + validator_actions::set_validator_profile(&users[0], &anchor, &user0_profile) + .await + .unwrap() + .is_success() + ); if to_confirm_view_result { complex_viewer::print_validator_profile( - worker, &anchor, &users[0].id().to_string().parse().unwrap(), &user0_id_in_appchain, ) - .await?; + .await; } - validator_actions::set_validator_id_in_appchain( - worker, + assert!(validator_actions::set_validator_id_in_appchain( &users[1], &anchor, - &user1_id_in_appchain, + &user1_id_in_appchain ) .await - .expect("Failed in calling 'set_validator_id_in_appchain'"); - validator_actions::set_validator_profile(worker, &users[1], &anchor, &user1_profile) - .await - .expect("Failed in calling 'set_validator_profile'"); + .unwrap() + .is_success()); + assert!( + validator_actions::set_validator_profile(&users[1], &anchor, &user1_profile) + .await + .unwrap() + .is_success() + ); if to_confirm_view_result { complex_viewer::print_validator_profile( - worker, &anchor, &users[1].id().to_string().parse().unwrap(), &user1_id_in_appchain, ) - .await?; + .await; } // // user4 register validator // - let user4_balance = get_ft_balance_of(worker, &users[4], &oct_token).await?; + let user4_balance = get_ft_balance_of(&users[4], &oct_token).await?; let wat_faucet_balance = - get_ft_balance_of(worker, &wat_faucet.as_account(), &wrapped_appchain_token).await?; + get_ft_balance_of(&wat_faucet.as_account(), &wrapped_appchain_token).await?; let amount4 = to_actual_amount(26_000, 18); - staking_actions::register_validator( - worker, + assert!(staking_actions::register_validator( &users[4], &oct_token, &anchor, @@ -600,39 +653,39 @@ pub async fn test_normal_actions( user4_profile, ) .await - .expect("Failed in calling 'register_validator'"); + .unwrap() + .is_success()); assert_eq!( - get_ft_balance_of(worker, &users[4], &oct_token).await?.0, + get_ft_balance_of(&users[4], &oct_token).await?.0, user4_balance.0 - amount4 ); if !with_old_anchor { assert_eq!( - get_ft_balance_of(worker, &wat_faucet.as_account(), &wrapped_appchain_token) + get_ft_balance_of(&wat_faucet.as_account(), &wrapped_appchain_token) .await? .0, wat_faucet_balance.0 - to_actual_amount(1, 18) ); } if to_confirm_view_result { - let anchor_status = anchor_viewer::get_anchor_status(worker, &anchor).await?; + let anchor_status = anchor_viewer::get_anchor_status(&anchor).await?; assert_eq!( anchor_status.total_stake_in_next_era.0, amount0 + amount1 + amount2_0 + amount3_0 + amount0_p + amount2_0_p + amount4 ); assert_eq!(anchor_status.validator_count_in_next_era.0, 3); complex_viewer::print_validator_profile( - worker, &anchor, &users[4].id().to_string().parse().unwrap(), &user4_id_in_appchain, ) - .await?; + .await; } // // Print staking histories // if to_confirm_view_result { - complex_viewer::print_staking_histories(worker, &anchor).await?; + complex_viewer::print_staking_histories(&anchor).await; } // // diff --git a/tests/simulator/contract_interfaces/anchor_viewer.rs b/tests/simulator/contract_interfaces/anchor_viewer.rs index 4892d83..58759b0 100644 --- a/tests/simulator/contract_interfaces/anchor_viewer.rs +++ b/tests/simulator/contract_interfaces/anchor_viewer.rs @@ -10,362 +10,320 @@ use appchain_anchor::AppchainMessage; use near_sdk::json_types::U64; use near_sdk::serde_json::json; use near_sdk::AccountId; -use workspaces::{network::Sandbox, Account, Contract, Worker}; +use workspaces::{error::Error, Account, Contract}; -pub async fn get_anchor_settings( - worker: &Worker, - anchor: &Contract, -) -> anyhow::Result { +pub async fn get_anchor_settings(anchor: &Contract) -> Result { anchor - .call(worker, "get_anchor_settings") + .call("get_anchor_settings") .view() .await? .json::() } -pub async fn get_appchain_settings( - worker: &Worker, - anchor: &Contract, -) -> anyhow::Result { +pub async fn get_appchain_settings(anchor: &Contract) -> Result { anchor - .call(worker, "get_appchain_settings") + .call("get_appchain_settings") .view() .await? .json::() } -pub async fn get_wrapped_appchain_token( - worker: &Worker, - anchor: &Contract, -) -> anyhow::Result { +pub async fn get_wrapped_appchain_token(anchor: &Contract) -> Result { anchor - .call(worker, "get_wrapped_appchain_token") + .call("get_wrapped_appchain_token") .view() .await? .json::() } -pub async fn get_near_fungible_tokens( - worker: &Worker, - anchor: &Contract, -) -> anyhow::Result> { +pub async fn get_near_fungible_tokens(anchor: &Contract) -> Result, Error> { anchor - .call(worker, "get_near_fungible_tokens") + .call("get_near_fungible_tokens") .view() .await? .json::>() } -pub async fn get_native_near_token( - worker: &Worker, - anchor: &Contract, -) -> anyhow::Result { +pub async fn get_native_near_token(anchor: &Contract) -> Result { anchor - .call(worker, "get_native_near_token") + .call("get_native_near_token") .view() .await? .json::() } -pub async fn get_appchain_state( - worker: &Worker, - anchor: &Contract, -) -> anyhow::Result { +pub async fn get_appchain_state(anchor: &Contract) -> Result { anchor - .call(worker, "get_appchain_state") + .call("get_appchain_state") .view() .await? .json::() } -pub async fn get_anchor_status( - worker: &Worker, - anchor: &Contract, -) -> anyhow::Result { +pub async fn get_anchor_status(anchor: &Contract) -> Result { anchor - .call(worker, "get_anchor_status") + .call("get_anchor_status") .view() .await? .json::() } pub async fn get_validator_set_info_of( - worker: &Worker, anchor: &Contract, index: U64, -) -> anyhow::Result { +) -> Result { anchor - .call(worker, "get_validator_set_info_of") - .args_json(json!({ "era_number": index }))? + .call("get_validator_set_info_of") + .args_json(json!({ "era_number": index })) .view() .await? .json::() } pub async fn get_index_range_of_appchain_notification_history( - worker: &Worker, anchor: &Contract, -) -> anyhow::Result { +) -> Result { anchor - .call(worker, "get_index_range_of_appchain_notification_history") + .call("get_index_range_of_appchain_notification_history") .view() .await? .json::() } pub async fn get_appchain_notification_history( - worker: &Worker, anchor: &Contract, index: u64, -) -> anyhow::Result> { +) -> Result, Error> { anchor - .call(worker, "get_appchain_notification_history") - .args_json(json!({ "index": Some(U64::from(index)) }))? + .call("get_appchain_notification_history") + .args_json(json!({ "index": Some(U64::from(index)) })) .view() .await? .json::>() } pub async fn get_appchain_notification_histories( - worker: &Worker, anchor: &Contract, start_index: u64, quantity: Option, -) -> anyhow::Result> { +) -> Result, Error> { anchor - .call(worker, "get_appchain_notification_histories") + .call("get_appchain_notification_histories") .args_json(json!({ "start_index": U64::from(start_index), "quantity": quantity - }))? + })) .view() .await? .json::>() } -pub async fn get_index_range_of_staking_history( - worker: &Worker, - anchor: &Contract, -) -> anyhow::Result { +pub async fn get_index_range_of_staking_history(anchor: &Contract) -> Result { anchor - .call(worker, "get_index_range_of_staking_history") + .call("get_index_range_of_staking_history") .view() .await? .json::() } pub async fn get_staking_history( - worker: &Worker, anchor: &Contract, index: u64, -) -> anyhow::Result> { +) -> Result, Error> { anchor - .call(worker, "get_staking_history") - .args_json(json!({ "index": Some(U64::from(index)) }))? + .call("get_staking_history") + .args_json(json!({ "index": Some(U64::from(index)) })) .view() .await? .json::>() } pub async fn get_validator_list_of( - worker: &Worker, anchor: &Contract, index: Option, -) -> anyhow::Result> { +) -> Result, Error> { let index = index.map_or(None, |i| Some(U64::from(i))); anchor - .call(worker, "get_validator_list_of") + .call("get_validator_list_of") .args_json(json!({ "era_number": index.map_or_else(|| Option::::None, |i| Some(U64::from(i))) - }))? + })) .view() .await? .json::>() } pub async fn get_validator_profile( - worker: &Worker, anchor: &Contract, account_id: &AccountId, -) -> anyhow::Result> { +) -> Result, Error> { anchor - .call(worker, "get_validator_profile") - .args_json(json!({ "validator_id": account_id }))? + .call("get_validator_profile") + .args_json(json!({ "validator_id": account_id })) .view() .await? .json::>() } pub async fn get_validator_profile_by_id_in_appchain( - worker: &Worker, anchor: &Contract, account_id_in_appchain: &String, -) -> anyhow::Result> { +) -> Result, Error> { anchor - .call(worker, "get_validator_profile_by_id_in_appchain") + .call("get_validator_profile_by_id_in_appchain") .args_json(json!({ "validator_id_in_appchain": account_id_in_appchain - }))? + })) .view() .await? .json::>() } pub async fn get_delegators_of_validator_in_era( - worker: &Worker, anchor: &Contract, index: u64, validator: &Account, -) -> anyhow::Result> { +) -> Result, Error> { anchor - .call(worker, "get_delegators_of_validator_in_era") + .call("get_delegators_of_validator_in_era") .args_json(json!({ "era_number": Some(U64::from(index)), "validator_id": validator.id() - }))? + })) .view() .await? .json::>() } pub async fn get_unbonded_stakes_of( - worker: &Worker, anchor: &Contract, account: &Account, -) -> anyhow::Result> { +) -> Result, Error> { anchor - .call(worker, "get_unbonded_stakes_of") + .call("get_unbonded_stakes_of") .args_json(json!({ "account_id": account.id() - }))? + })) .view() .await? .json::>() } pub async fn get_validator_rewards_of( - worker: &Worker, anchor: &Contract, start_era: u64, end_era: u64, validator: &Account, -) -> anyhow::Result> { +) -> Result, Error> { anchor - .call(worker, "get_validator_rewards_of") + .call("get_validator_rewards_of") .args_json(json!({ "start_era": U64::from(start_era), "end_era": U64::from(end_era), "validator_id": validator.id() - }))? + })) .view() .await? .json::>() } pub async fn get_delegator_rewards_of( - worker: &Worker, anchor: &Contract, start_era: u64, end_era: u64, delegator: &Account, validator: &Account, -) -> anyhow::Result> { +) -> Result, Error> { anchor - .call(worker, "get_delegator_rewards_of") + .call("get_delegator_rewards_of") .args_json(json!({ "start_era": U64::from(start_era), "end_era": U64::from(end_era), "delegator_id": delegator.id(), "validator_id": validator.id() - }))? + })) .view() .await? .json::>() } pub async fn get_beefy_light_client_status( - worker: &Worker, anchor: &Contract, -) -> anyhow::Result { +) -> Result { anchor - .call(worker, "get_beefy_light_client_status") + .call("get_beefy_light_client_status") .view() .await? .json::() } pub async fn get_user_staking_histories_of( - worker: &Worker, anchor: &Contract, account_id: AccountId, -) -> anyhow::Result> { +) -> Result, Error> { anchor - .call(worker, "get_user_staking_histories_of") - .args_json(json!({ "account_id": account_id }))? + .call("get_user_staking_histories_of") + .args_json(json!({ "account_id": account_id })) .view() .await? .json::>() } pub async fn get_appchain_messages( - worker: &Worker, anchor: &Contract, start_nonce: u32, quantity: Option, -) -> anyhow::Result> { +) -> Result, Error> { anchor - .call(worker, "get_appchain_messages") + .call("get_appchain_messages") .args_json(json!({ "start_nonce": start_nonce, "quantity": quantity - }))? + })) .view() .await? .json::>() } pub async fn get_appchain_message_processing_results( - worker: &Worker, anchor: &Contract, start_nonce: u32, quantity: Option, -) -> anyhow::Result> { +) -> Result, Error> { anchor - .call(worker, "get_appchain_message_processing_results") + .call("get_appchain_message_processing_results") .args_json(json!({ "start_nonce": start_nonce, "quantity": quantity - }))? + })) .view() .await? .json::>() } pub async fn get_appchain_challenge( - worker: &Worker, anchor: &Contract, index: u64, -) -> anyhow::Result> { +) -> Result, Error> { anchor - .call(worker, "get_appchain_challenge") - .args_json(json!({ "index": Some(U64::from(index)) }))? + .call("get_appchain_challenge") + .args_json(json!({ "index": Some(U64::from(index)) })) .view() .await? .json::>() } pub async fn get_appchain_challenges( - worker: &Worker, anchor: &Contract, start_index: u64, quantity: Option, -) -> anyhow::Result> { +) -> Result, Error> { anchor - .call(worker, "get_appchain_challenges") + .call("get_appchain_challenges") .args_json(json!({ "start_index": U64::from(start_index), "quantity": quantity - }))? + })) .view() .await? .json::>() diff --git a/tests/simulator/contract_interfaces/lifecycle_actions.rs b/tests/simulator/contract_interfaces/lifecycle_actions.rs index 607a518..6932d16 100644 --- a/tests/simulator/contract_interfaces/lifecycle_actions.rs +++ b/tests/simulator/contract_interfaces/lifecycle_actions.rs @@ -1,39 +1,33 @@ use near_sdk::serde_json::json; -use workspaces::{network::Sandbox, result::CallExecutionDetails, Account, Contract, Worker}; +use workspaces::{error::Error, result::ExecutionFinalResult, Account, Contract}; pub async fn generate_initial_validator_set( - worker: &Worker, signer: &Account, anchor: &Contract, -) -> anyhow::Result { +) -> Result { signer - .call(worker, anchor.id(), "generate_initial_validator_set") + .call(anchor.id(), "generate_initial_validator_set") .gas(200_000_000_000_000) .transact() .await } -pub async fn go_live( - worker: &Worker, - signer: &Account, - anchor: &Contract, -) -> anyhow::Result { +pub async fn go_live(signer: &Account, anchor: &Contract) -> Result { signer - .call(worker, anchor.id(), "go_live") + .call(anchor.id(), "go_live") .gas(200_000_000_000_000) .transact() .await } pub async fn initialize_beefy_light_client( - worker: &Worker, signer: &Account, anchor: &Contract, initial_public_keys: Vec, -) -> anyhow::Result { +) -> Result { signer - .call(worker, anchor.id(), "initialize_beefy_light_client") - .args_json(json!({ "initial_public_keys": initial_public_keys }))? + .call(anchor.id(), "initialize_beefy_light_client") + .args_json(json!({ "initial_public_keys": initial_public_keys })) .gas(200_000_000_000_000) .transact() .await diff --git a/tests/simulator/contract_interfaces/native_near_token.rs b/tests/simulator/contract_interfaces/native_near_token.rs index 3699973..4357e50 100644 --- a/tests/simulator/contract_interfaces/native_near_token.rs +++ b/tests/simulator/contract_interfaces/native_near_token.rs @@ -1,24 +1,22 @@ -use workspaces::{network::Sandbox, result::CallExecutionDetails, Account, Contract, Worker}; +use workspaces::{error::Error, result::ExecutionFinalResult, Account, Contract}; pub async fn deploy_near_vault_contract( - worker: &Worker, signer: &Account, anchor: &Contract, -) -> anyhow::Result { +) -> Result { signer - .call(worker, anchor.id(), "deploy_near_vault_contract") + .call(anchor.id(), "deploy_near_vault_contract") .gas(200_000_000_000_000) .transact() .await } pub async fn open_bridging_of_native_near_token( - worker: &Worker, signer: &Account, anchor: &Contract, -) -> anyhow::Result { +) -> Result { signer - .call(worker, anchor.id(), "open_bridging_of_native_near_token") + .call(anchor.id(), "open_bridging_of_native_near_token") .gas(200_000_000_000_000) .transact() .await diff --git a/tests/simulator/contract_interfaces/near_fungible_token_manager.rs b/tests/simulator/contract_interfaces/near_fungible_token_manager.rs index 7820eb2..3a3ec14 100644 --- a/tests/simulator/contract_interfaces/near_fungible_token_manager.rs +++ b/tests/simulator/contract_interfaces/near_fungible_token_manager.rs @@ -1,8 +1,7 @@ use near_sdk::{json_types::U128, serde_json::json, AccountId}; -use workspaces::{network::Sandbox, result::CallExecutionDetails, Account, Contract, Worker}; +use workspaces::{error::Error, result::ExecutionFinalResult, Account, Contract}; pub async fn register_near_fungible_token( - worker: &Worker, signer: &Account, anchor: &Contract, symbol: String, @@ -10,16 +9,16 @@ pub async fn register_near_fungible_token( decimals: u8, contract_account: AccountId, price: U128, -) -> anyhow::Result { +) -> Result { signer - .call(worker, anchor.id(), "register_near_fungible_token") + .call(anchor.id(), "register_near_fungible_token") .args_json(json!({ "symbol": symbol, "name": name, "decimals": decimals, "contract_account": contract_account, "price": price - }))? + })) .gas(200_000_000_000_000) .transact() .await diff --git a/tests/simulator/contract_interfaces/permissionless_actions.rs b/tests/simulator/contract_interfaces/permissionless_actions.rs index 0a4f03a..a379c5f 100644 --- a/tests/simulator/contract_interfaces/permissionless_actions.rs +++ b/tests/simulator/contract_interfaces/permissionless_actions.rs @@ -1,25 +1,24 @@ use appchain_anchor::types::{MultiTxsOperationProcessingResult, ValidatorMerkleProof}; use near_sdk::serde_json::json; -use workspaces::{network::Sandbox, result::CallExecutionDetails, Account, Contract, Worker}; +use workspaces::{error::Error, result::ExecutionFinalResult, Account, Contract}; pub async fn verify_and_stage_appchain_messages( - worker: &Worker, signer: &Account, anchor: &Contract, encoded_messages: Vec, header: Vec, mmr_leaf: Vec, mmr_proof: Vec, -) -> anyhow::Result { +) -> Result { let result = signer - .call(worker, anchor.id(), "verify_and_stage_appchain_messages") + .call(anchor.id(), "verify_and_stage_appchain_messages") .gas(300_000_000_000_000) .args_json(json!({ "encoded_messages": encoded_messages, "header": header, "mmr_leaf": mmr_leaf, "mmr_proof": mmr_proof - }))? + })) .transact() .await; println!("{:?}", result); @@ -28,12 +27,11 @@ pub async fn verify_and_stage_appchain_messages( } pub async fn process_appchain_messages( - worker: &Worker, signer: &Account, anchor: &Contract, -) -> anyhow::Result { +) -> Result { let result = signer - .call(worker, anchor.id(), "process_appchain_messages") + .call(anchor.id(), "process_appchain_messages") .gas(300_000_000_000_000) .transact() .await?; @@ -43,7 +41,6 @@ pub async fn process_appchain_messages( } pub async fn process_appchain_messages_with_all_proofs( - worker: &Worker, signer: &Account, anchor: &Contract, signed_commitment: Vec, @@ -54,13 +51,9 @@ pub async fn process_appchain_messages_with_all_proofs( header: Vec, mmr_leaf_for_header: Vec, mmr_proof_for_header: Vec, -) -> anyhow::Result { +) -> Result { let result = signer - .call( - worker, - anchor.id(), - "process_appchain_messages_with_all_proofs", - ) + .call(anchor.id(), "process_appchain_messages_with_all_proofs") .args_json(json!({ "signed_commitment": signed_commitment, "validator_proofs": validator_proofs, @@ -70,7 +63,7 @@ pub async fn process_appchain_messages_with_all_proofs( "header": header, "mmr_leaf_for_header": mmr_leaf_for_header, "mmr_proof_for_header": mmr_proof_for_header, - }))? + })) .gas(300_000_000_000_000) .transact() .await?; diff --git a/tests/simulator/contract_interfaces/settings_manager.rs b/tests/simulator/contract_interfaces/settings_manager.rs index e596652..683046f 100644 --- a/tests/simulator/contract_interfaces/settings_manager.rs +++ b/tests/simulator/contract_interfaces/settings_manager.rs @@ -2,171 +2,148 @@ use near_sdk::{ json_types::{U128, U64}, serde_json::json, }; -use workspaces::{network::Sandbox, result::CallExecutionDetails, Account, Contract, Worker}; +use workspaces::{error::Error, result::ExecutionFinalResult, Account, Contract}; pub async fn change_minimum_validator_count( - worker: &Worker, signer: &Account, anchor: &Contract, value: u64, -) -> anyhow::Result { +) -> Result { signer - .call(worker, anchor.id(), "change_minimum_validator_count") - .args_json(json!({ "value": U64::from(value) }))? + .call(anchor.id(), "change_minimum_validator_count") + .args_json(json!({ "value": U64::from(value) })) .gas(200_000_000_000_000) .transact() .await } pub async fn set_rpc_endpoint( - worker: &Worker, signer: &Account, anchor: &Contract, value: String, -) -> anyhow::Result { +) -> Result { signer - .call(worker, anchor.id(), "set_rpc_endpoint") - .args_json(json!({ "rpc_endpoint": value }))? + .call(anchor.id(), "set_rpc_endpoint") + .args_json(json!({ "rpc_endpoint": value })) .gas(200_000_000_000_000) .transact() .await } pub async fn set_subql_endpoint( - worker: &Worker, signer: &Account, anchor: &Contract, value: String, -) -> anyhow::Result { +) -> Result { signer - .call(worker, anchor.id(), "set_subql_endpoint") - .args_json(json!({ "subql_endpoint": value }))? + .call(anchor.id(), "set_subql_endpoint") + .args_json(json!({ "subql_endpoint": value })) .gas(200_000_000_000_000) .transact() .await } pub async fn set_era_reward( - worker: &Worker, signer: &Account, anchor: &Contract, value: u128, -) -> anyhow::Result { +) -> Result { signer - .call(worker, anchor.id(), "set_era_reward") - .args_json(json!({ "era_reward": U128::from(value) }))? + .call(anchor.id(), "set_era_reward") + .args_json(json!({ "era_reward": U128::from(value) })) .gas(200_000_000_000_000) .transact() .await } pub async fn set_bonus_for_new_validator( - worker: &Worker, signer: &Account, anchor: &Contract, value: u128, -) -> anyhow::Result { +) -> Result { signer - .call(worker, anchor.id(), "set_bonus_for_new_validator") - .args_json(json!({ "bonus_amount": U128::from(value) }))? + .call(anchor.id(), "set_bonus_for_new_validator") + .args_json(json!({ "bonus_amount": U128::from(value) })) .gas(200_000_000_000_000) .transact() .await } pub async fn set_token_price_maintainer_account( - worker: &Worker, signer: &Account, anchor: &Contract, account: &Account, -) -> anyhow::Result { +) -> Result { signer - .call(worker, anchor.id(), "set_token_price_maintainer_account") + .call(anchor.id(), "set_token_price_maintainer_account") .args_json(json!({ "account_id": account.id() - }))? + })) .gas(200_000_000_000_000) .transact() .await } pub async fn set_relayer_account( - worker: &Worker, signer: &Account, anchor: &Contract, account: &Account, -) -> anyhow::Result { +) -> Result { signer - .call(worker, anchor.id(), "set_relayer_account") + .call(anchor.id(), "set_relayer_account") .args_json(json!({ "account_id": account.id() - }))? + })) .gas(200_000_000_000_000) .transact() .await } pub async fn set_price_of_oct_token( - worker: &Worker, signer: &Account, anchor: &Contract, value: u128, -) -> anyhow::Result { +) -> Result { signer - .call(worker, anchor.id(), "set_price_of_oct_token") - .args_json(json!({ "price": U128::from(value) }))? + .call(anchor.id(), "set_price_of_oct_token") + .args_json(json!({ "price": U128::from(value) })) .gas(200_000_000_000_000) .transact() .await } pub async fn change_unlock_period_of_validator_deposit( - worker: &Worker, signer: &Account, anchor: &Contract, value: u64, -) -> anyhow::Result { +) -> Result { signer - .call( - worker, - anchor.id(), - "change_unlock_period_of_validator_deposit", - ) - .args_json(json!({ "value": U64::from(value) }))? + .call(anchor.id(), "change_unlock_period_of_validator_deposit") + .args_json(json!({ "value": U64::from(value) })) .gas(200_000_000_000_000) .transact() .await } pub async fn change_unlock_period_of_delegator_deposit( - worker: &Worker, signer: &Account, anchor: &Contract, value: u64, -) -> anyhow::Result { +) -> Result { signer - .call( - worker, - anchor.id(), - "change_unlock_period_of_delegator_deposit", - ) - .args_json(json!({ "value": U64::from(value) }))? + .call(anchor.id(), "change_unlock_period_of_delegator_deposit") + .args_json(json!({ "value": U64::from(value) })) .gas(200_000_000_000_000) .transact() .await } pub async fn turn_on_beefy_light_client_witness_mode( - worker: &Worker, signer: &Account, anchor: &Contract, -) -> anyhow::Result { +) -> Result { signer - .call( - worker, - anchor.id(), - "turn_on_beefy_light_client_witness_mode", - ) + .call(anchor.id(), "turn_on_beefy_light_client_witness_mode") .gas(200_000_000_000_000) .transact() .await diff --git a/tests/simulator/contract_interfaces/staking_actions.rs b/tests/simulator/contract_interfaces/staking_actions.rs index 5c40e03..dad7c1c 100644 --- a/tests/simulator/contract_interfaces/staking_actions.rs +++ b/tests/simulator/contract_interfaces/staking_actions.rs @@ -1,10 +1,9 @@ use crate::common; use near_sdk::{json_types::U128, serde_json::json, AccountId}; use std::collections::HashMap; -use workspaces::{network::Sandbox, result::CallExecutionDetails, Account, Contract, Worker}; +use workspaces::{error::Error, result::ExecutionFinalResult, Account, Contract}; pub async fn register_validator( - worker: &Worker, signer: &Account, oct_token: &Contract, anchor: &Contract, @@ -12,9 +11,8 @@ pub async fn register_validator( amount: u128, can_be_delegated_to: bool, profile: HashMap, -) -> anyhow::Result { +) -> Result { let result = common::call_ft_transfer_call( - worker, signer, &anchor.as_account(), amount, @@ -35,15 +33,13 @@ pub async fn register_validator( } pub async fn register_delegator( - worker: &Worker, signer: &Account, oct_token: &Contract, anchor: &Contract, validator_id: &AccountId, amount: u128, -) -> anyhow::Result { - common::call_ft_transfer_call( - worker, +) -> Result { + let result = common::call_ft_transfer_call( signer, &anchor.as_account(), amount, @@ -56,18 +52,19 @@ pub async fn register_delegator( .to_string(), oct_token, ) - .await + .await; + println!("Result of register delegator: {:?}", result); + println!(); + result } pub async fn increase_stake( - worker: &Worker, signer: &Account, oct_token: &Contract, anchor: &Contract, amount: u128, -) -> anyhow::Result { +) -> Result { common::call_ft_transfer_call( - worker, signer, &anchor.as_account(), amount, @@ -83,15 +80,13 @@ pub async fn increase_stake( } pub async fn increase_delegation( - worker: &Worker, signer: &Account, oct_token: &Contract, anchor: &Contract, validator_id: &AccountId, amount: u128, -) -> anyhow::Result { +) -> Result { common::call_ft_transfer_call( - worker, signer, &anchor.as_account(), amount, @@ -108,123 +103,117 @@ pub async fn increase_delegation( } pub async fn decrease_stake( - worker: &Worker, signer: &Account, anchor: &Contract, amount: u128, -) -> anyhow::Result { +) -> Result { signer - .call(worker, anchor.id(), "decrease_stake") - .args_json(json!({ "amount": U128::from(amount) }))? + .call(anchor.id(), "decrease_stake") + .args_json(json!({ "amount": U128::from(amount) })) .gas(200_000_000_000_000) .transact() .await } pub async fn unbond_stake( - worker: &Worker, signer: &Account, anchor: &Contract, -) -> anyhow::Result { +) -> Result { signer - .call(worker, anchor.id(), "unbond_stake") + .call(anchor.id(), "unbond_stake") .gas(200_000_000_000_000) .transact() .await } pub async fn decrease_delegation( - worker: &Worker, signer: &Account, anchor: &Contract, validator_id: &AccountId, amount: u128, -) -> anyhow::Result { +) -> Result { signer - .call(worker, anchor.id(), "decrease_delegation") + .call(anchor.id(), "decrease_delegation") .args_json(json!({ "validator_id": validator_id, "amount": U128::from(amount) - }))? + })) .gas(200_000_000_000_000) .transact() .await } pub async fn unbond_delegation( - worker: &Worker, signer: &Account, anchor: &Contract, validator_id: &AccountId, -) -> anyhow::Result { +) -> Result { signer - .call(worker, anchor.id(), "unbond_delegation") - .args_json(json!({ "validator_id": validator_id }))? + .call(anchor.id(), "unbond_delegation") + .args_json(json!({ "validator_id": validator_id })) .gas(200_000_000_000_000) .transact() .await } pub async fn withdraw_stake( - worker: &Worker, signer: &Account, anchor: &Contract, account_id: &AccountId, -) -> anyhow::Result { +) -> Result { signer - .call(worker, anchor.id(), "withdraw_stake") - .args_json(json!({ "account_id": account_id }))? + .call(anchor.id(), "withdraw_stake") + .args_json(json!({ "account_id": account_id })) .gas(200_000_000_000_000) .transact() .await } pub async fn withdraw_validator_rewards( - worker: &Worker, signer: &Account, anchor: &Contract, validator_id: &AccountId, -) -> anyhow::Result { +) -> Result { signer - .call(worker, anchor.id(), "withdraw_validator_rewards") - .args_json(json!({ "validator_id": validator_id }))? + .call(anchor.id(), "withdraw_validator_rewards") + .args_json(json!({ "validator_id": validator_id })) .gas(200_000_000_000_000) .transact() .await } pub async fn withdraw_delegator_rewards( - worker: &Worker, signer: &Account, anchor: &Contract, delegator_id: &AccountId, validator_id: &AccountId, -) -> anyhow::Result { +) -> Result { signer - .call(worker, anchor.id(), "withdraw_delegator_rewards") + .call(anchor.id(), "withdraw_delegator_rewards") .args_json(json!({ "delegator_id": delegator_id, "validator_id": validator_id - }))? + })) .gas(200_000_000_000_000) .transact() .await } pub async fn change_delegated_validator( - worker: &Worker, signer: &Account, anchor: &Contract, old_validator_id: &AccountId, new_validator_id: &AccountId, -) -> anyhow::Result { - signer - .call(worker, anchor.id(), "change_delegated_validator") +) -> Result { + let result = signer + .call(anchor.id(), "change_delegated_validator") .args_json(json!({ "old_validator_id": old_validator_id, "new_validator_id": new_validator_id - }))? + })) .gas(200_000_000_000_000) .transact() - .await + .await; + println!("Result of 'change_delegated_validator': {:?}", result); + result } diff --git a/tests/simulator/contract_interfaces/validator_actions.rs b/tests/simulator/contract_interfaces/validator_actions.rs index 47f5fa1..80045c4 100644 --- a/tests/simulator/contract_interfaces/validator_actions.rs +++ b/tests/simulator/contract_interfaces/validator_actions.rs @@ -1,32 +1,52 @@ use near_sdk::serde_json::json; use std::collections::HashMap; -use workspaces::{network::Sandbox, result::CallExecutionDetails, Account, Contract, Worker}; +use workspaces::{error::Error, result::ExecutionFinalResult, Account, Contract}; pub async fn set_validator_id_in_appchain( - worker: &Worker, signer: &Account, anchor: &Contract, validator_id_in_appchain: &String, -) -> anyhow::Result { +) -> Result { signer - .call(worker, anchor.id(), "set_validator_id_in_appchain") + .call(anchor.id(), "set_validator_id_in_appchain") .args_json(json!({ "account_id_in_appchain": validator_id_in_appchain - }))? + })) .gas(200_000_000_000_000) .transact() .await } pub async fn set_validator_profile( - worker: &Worker, signer: &Account, anchor: &Contract, profile: &HashMap, -) -> anyhow::Result { +) -> Result { signer - .call(worker, anchor.id(), "set_validator_profile") - .args_json(json!({ "profile": profile }))? + .call(anchor.id(), "set_validator_profile") + .args_json(json!({ "profile": profile })) + .gas(200_000_000_000_000) + .transact() + .await +} + +pub async fn enable_delegation( + signer: &Account, + anchor: &Contract, +) -> Result { + signer + .call(anchor.id(), "enable_delegation") + .gas(200_000_000_000_000) + .transact() + .await +} + +pub async fn disable_delegation( + signer: &Account, + anchor: &Contract, +) -> Result { + signer + .call(anchor.id(), "disable_delegation") .gas(200_000_000_000_000) .transact() .await diff --git a/tests/simulator/contract_interfaces/wrapped_appchain_nft_manager.rs b/tests/simulator/contract_interfaces/wrapped_appchain_nft_manager.rs index 99907fe..1b14b39 100644 --- a/tests/simulator/contract_interfaces/wrapped_appchain_nft_manager.rs +++ b/tests/simulator/contract_interfaces/wrapped_appchain_nft_manager.rs @@ -1,34 +1,32 @@ use near_contract_standards::non_fungible_token::metadata::NFTContractMetadata; use near_sdk::serde_json::json; -use workspaces::{network::Sandbox, result::CallExecutionDetails, Account, Contract, Worker}; +use workspaces::{error::Error, result::ExecutionFinalResult, Account, Contract}; pub async fn register_wrapped_appchain_nft( - worker: &Worker, signer: &Account, anchor: &Contract, class_id: String, metadata: NFTContractMetadata, -) -> anyhow::Result { +) -> Result { signer - .call(worker, anchor.id(), "register_wrapped_appchain_nft") + .call(anchor.id(), "register_wrapped_appchain_nft") .args_json(json!({ "class_id": class_id, "metadata": metadata - }))? + })) .gas(200_000_000_000_000) .transact() .await } pub async fn open_bridging_of_wrapped_appchain_nft( - worker: &Worker, signer: &Account, anchor: &Contract, class_id: String, -) -> anyhow::Result { +) -> Result { signer - .call(worker, anchor.id(), "open_bridging_of_wrapped_appchain_nft") - .args_json(json!({ "class_id": class_id }))? + .call(anchor.id(), "open_bridging_of_wrapped_appchain_nft") + .args_json(json!({ "class_id": class_id })) .gas(200_000_000_000_000) .transact() .await diff --git a/tests/simulator/contract_interfaces/wrapped_appchain_token_manager.rs b/tests/simulator/contract_interfaces/wrapped_appchain_token_manager.rs index 547ac94..c31a79c 100644 --- a/tests/simulator/contract_interfaces/wrapped_appchain_token_manager.rs +++ b/tests/simulator/contract_interfaces/wrapped_appchain_token_manager.rs @@ -1,47 +1,44 @@ use near_sdk::{json_types::U128, serde_json::json, AccountId}; -use workspaces::{network::Sandbox, result::CallExecutionDetails, Account, Contract, Worker}; +use workspaces::{error::Error, result::ExecutionFinalResult, Account, Contract}; pub async fn set_price_of_wrapped_appchain_token( - worker: &Worker, signer: &Account, anchor: &Contract, price: u128, -) -> anyhow::Result { +) -> Result { signer - .call(worker, anchor.id(), "set_price_of_wrapped_appchain_token") - .args_json(json!({ "price": U128::from(price) }))? + .call(anchor.id(), "set_price_of_wrapped_appchain_token") + .args_json(json!({ "price": U128::from(price) })) .gas(200_000_000_000_000) .transact() .await } pub async fn set_account_of_wrapped_appchain_token( - worker: &Worker, signer: &Account, anchor: &Contract, account_id: AccountId, -) -> anyhow::Result { +) -> Result { signer - .call(worker, anchor.id(), "set_account_of_wrapped_appchain_token") - .args_json(json!({ "contract_account": account_id }))? + .call(anchor.id(), "set_account_of_wrapped_appchain_token") + .args_json(json!({ "contract_account": account_id })) .gas(200_000_000_000_000) .transact() .await } pub async fn burn_wrapped_appchain_token( - worker: &Worker, signer: &Account, anchor: &Contract, receiver_id: String, amount: u128, -) -> anyhow::Result { +) -> Result { signer - .call(worker, anchor.id(), "burn_wrapped_appchain_token") + .call(anchor.id(), "burn_wrapped_appchain_token") .args_json(json!({ "receiver_id": receiver_id, "amount": U128::from(amount) - }))? + })) .gas(200_000_000_000_000) .transact() .await diff --git a/tests/simulator/main.rs b/tests/simulator/main.rs index 70738d7..6d054b4 100644 --- a/tests/simulator/main.rs +++ b/tests/simulator/main.rs @@ -3,7 +3,6 @@ mod contract_interfaces; mod test_anchor_actions; mod test_beefy_light_client_1; -mod test_beefy_light_client_2; mod test_equivocation_challenge; mod test_migration; mod test_sync_staking_amount; diff --git a/tests/simulator/test_anchor_actions.rs b/tests/simulator/test_anchor_actions.rs index 60f11a5..0d9a9c4 100644 --- a/tests/simulator/test_anchor_actions.rs +++ b/tests/simulator/test_anchor_actions.rs @@ -1,10 +1,10 @@ use crate::{ common, - contract_interfaces::{anchor_viewer, settings_manager, staking_actions}, + contract_interfaces::{anchor_viewer, settings_manager, staking_actions, validator_actions}, }; use near_sdk::json_types::U64; use std::collections::HashMap; -use workspaces::{network::Sandbox, Account, Contract, Worker}; +use workspaces::{Account, Contract}; #[tokio::test] async fn test_anchor_actions() -> anyhow::Result<()> { @@ -24,25 +24,15 @@ async fn test_anchor_actions() -> anyhow::Result<()> { // Try start and complete switching era1 // appchain_message_nonce += 1; - common::complex_actions::switch_era( - &worker, - &users[5], - &anchor, - 1, - appchain_message_nonce, - false, - ) - .await - .expect("Failed to switch era"); - common::complex_viewer::print_validator_set_info_of(&worker, &anchor, U64::from(1)).await?; - common::complex_viewer::print_validator_list_of(&worker, &anchor, Some(1)).await?; - common::complex_viewer::print_delegator_list_of(&worker, &anchor, 1, &users[0]).await?; + common::complex_actions::switch_era(&users[5], &anchor, 1, appchain_message_nonce, false).await; + common::complex_viewer::print_validator_set_info_of(&anchor, U64::from(1)).await; + common::complex_viewer::print_validator_list_of(&anchor, Some(1)).await; + common::complex_viewer::print_delegator_list_of(&anchor, 1, &users[0]).await; // // Distribut reward of era0 // appchain_message_nonce += 1; common::complex_actions::distribute_reward_of( - &worker, &users[5], &anchor, &wrapped_appchain_token, @@ -51,28 +41,19 @@ async fn test_anchor_actions() -> anyhow::Result<()> { Vec::new(), false, ) - .await - .expect("Failed to distribute rewards"); - common::complex_viewer::print_wrapped_appchain_token_info(&worker, &anchor).await?; - common::complex_viewer::print_validator_reward_histories(&worker, &anchor, &users[0], 0) - .await?; - common::complex_viewer::print_validator_reward_histories(&worker, &anchor, &users[1], 0) - .await?; - common::complex_viewer::print_delegator_reward_histories( - &worker, &anchor, &users[2], &users[0], 0, - ) - .await?; - common::complex_viewer::print_delegator_reward_histories( - &worker, &anchor, &users[3], &users[0], 0, - ) - .await?; - common::complex_viewer::print_validator_reward_histories(&worker, &anchor, &users[4], 0) - .await?; + .await; + common::complex_viewer::print_wrapped_appchain_token_info(&anchor).await; + common::complex_viewer::print_validator_reward_histories(&anchor, &users[0], 0).await; + common::complex_viewer::print_validator_reward_histories(&anchor, &users[1], 0).await; + common::complex_viewer::print_delegator_reward_histories(&anchor, &users[2], &users[0], 0) + .await; + common::complex_viewer::print_delegator_reward_histories(&&anchor, &users[3], &users[0], 0) + .await; + common::complex_viewer::print_validator_reward_histories(&anchor, &users[4], 0).await; // // // test_staking_actions( - &worker, &root, &oct_token, &wrapped_appchain_token, @@ -86,7 +67,6 @@ async fn test_anchor_actions() -> anyhow::Result<()> { } async fn test_staking_actions( - worker: &Worker, root: &Account, oct_token: &Contract, wrapped_appchain_token: &Contract, @@ -107,74 +87,77 @@ async fn test_staking_actions( // // user1 decrease stake // - staking_actions::decrease_stake( - &worker, + assert!(staking_actions::decrease_stake( &users[1], &anchor, - common::to_actual_amount(1000, 18), + common::to_actual_amount(1000, 18) ) .await - .expect("Failed to decrease stake"); - common::complex_viewer::print_anchor_status(&worker, &anchor).await?; - let unbonded_stakes = anchor_viewer::get_unbonded_stakes_of(&worker, &anchor, &users[1]) + .unwrap() + .is_success()); + common::complex_viewer::print_anchor_status(&anchor).await; + let unbonded_stakes = anchor_viewer::get_unbonded_stakes_of(&anchor, &users[1]) .await .expect("Failed to unbond stakes"); assert!(unbonded_stakes.len() == 0); // // user2 decrease delegation // - staking_actions::decrease_delegation( - &worker, + assert!(staking_actions::decrease_delegation( &users[2], &anchor, &users[0].id().to_string().parse().unwrap(), common::to_actual_amount(200, 18), ) .await - .expect("Failed to decrease delegation"); - common::complex_viewer::print_anchor_status(&worker, &anchor).await?; - let unbonded_stakes = anchor_viewer::get_unbonded_stakes_of(&worker, &anchor, &users[2]) + .unwrap() + .is_success()); + common::complex_viewer::print_anchor_status(&anchor).await; + let unbonded_stakes = anchor_viewer::get_unbonded_stakes_of(&anchor, &users[2]) .await .expect("Failed to unbond stakes"); assert!(unbonded_stakes.len() == 0); // // user3 change delegated validator // - staking_actions::change_delegated_validator( - &worker, + assert!(staking_actions::change_delegated_validator( + &users[3], + &anchor, + &users[0].id().to_string().parse().unwrap(), + &users[1].id().to_string().parse().unwrap(), + ) + .await + .unwrap() + .is_failure()); + assert!(validator_actions::enable_delegation(&users[1], &anchor) + .await + .unwrap() + .is_success()); + assert!(staking_actions::change_delegated_validator( &users[3], &anchor, &users[0].id().to_string().parse().unwrap(), &users[1].id().to_string().parse().unwrap(), ) .await - .expect("Failed to change delegated validator"); + .unwrap() + .is_failure()); // // Print staking histories // - common::complex_viewer::print_staking_histories(&worker, &anchor).await?; + common::complex_viewer::print_staking_histories(&anchor).await; // // Try start and complete switching era2 // appchain_message_nonce += 1; - common::complex_actions::switch_era( - &worker, - &users[5], - &anchor, - 2, - appchain_message_nonce, - true, - ) - .await - .expect("Failed to switch era"); - common::complex_viewer::print_validator_list_of(&worker, &anchor, Some(2)).await?; - common::complex_viewer::print_delegator_list_of(&worker, &anchor, 2, &users[0]).await?; + common::complex_actions::switch_era(&users[5], &anchor, 2, appchain_message_nonce, true).await; + common::complex_viewer::print_validator_list_of(&anchor, Some(2)).await; + common::complex_viewer::print_delegator_list_of(&anchor, 2, &users[0]).await; // // Distribute reward of era1 // appchain_message_nonce += 1; common::complex_actions::distribute_reward_of( - &worker, &users[5], &anchor, &wrapped_appchain_token, @@ -183,80 +166,68 @@ async fn test_staking_actions( [user0_id_in_appchain.clone()].to_vec(), true, ) - .await - .expect("Failed to distribute rewards"); - common::complex_viewer::print_wrapped_appchain_token_info(&worker, &anchor).await?; - common::complex_viewer::print_staking_histories(&worker, &anchor).await?; - common::complex_viewer::print_validator_reward_histories(&worker, &anchor, &users[0], 1) - .await?; - common::complex_viewer::print_validator_reward_histories(&worker, &anchor, &users[1], 1) - .await?; - common::complex_viewer::print_delegator_reward_histories( - &worker, &anchor, &users[2], &users[0], 1, - ) - .await?; - common::complex_viewer::print_delegator_reward_histories( - &worker, &anchor, &users[3], &users[0], 1, - ) - .await?; - common::complex_viewer::print_validator_reward_histories(&worker, &anchor, &users[4], 1) - .await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[0]).await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[1]).await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[2]).await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[3]).await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[4]).await?; + .await; + common::complex_viewer::print_wrapped_appchain_token_info(&anchor).await; + common::complex_viewer::print_staking_histories(&anchor).await; + common::complex_viewer::print_validator_reward_histories(&anchor, &users[0], 1).await; + common::complex_viewer::print_validator_reward_histories(&anchor, &users[1], 1).await; + common::complex_viewer::print_delegator_reward_histories(&anchor, &users[2], &users[0], 1) + .await; + common::complex_viewer::print_delegator_reward_histories(&anchor, &users[3], &users[0], 1) + .await; + common::complex_viewer::print_validator_reward_histories(&anchor, &users[4], 1).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[0]).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[1]).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[2]).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[3]).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[4]).await; // // Change unlock period for testing // - settings_manager::change_unlock_period_of_validator_deposit(&worker, &root, &anchor, 3) - .await - .expect("Failed in calling 'change_unlock_period_of_validator_deposit'"); - settings_manager::change_unlock_period_of_delegator_deposit(&worker, &root, &anchor, 1) - .await - .expect("Failed in calling 'change_unlock_period_of_delegator_deposit'"); + assert!( + settings_manager::change_unlock_period_of_validator_deposit(&root, &anchor, 3) + .await + .unwrap() + .is_success() + ); + assert!( + settings_manager::change_unlock_period_of_delegator_deposit(&root, &anchor, 1) + .await + .unwrap() + .is_success() + ); // // user3 unbond delegation // - staking_actions::unbond_delegation( - &worker, + assert!(staking_actions::unbond_delegation( &users[2], &anchor, &users[0].id().to_string().parse().unwrap(), ) .await - .expect("Failed to unbond delegation"); - common::complex_viewer::print_anchor_status(&worker, &anchor).await?; - let unbonded_stakes = anchor_viewer::get_unbonded_stakes_of(&worker, &anchor, &users[2]) + .unwrap() + .is_success()); + common::complex_viewer::print_anchor_status(&anchor).await; + let unbonded_stakes = anchor_viewer::get_unbonded_stakes_of(&anchor, &users[2]) .await .expect("Failed to unbond stakes"); assert!(unbonded_stakes.len() == 1); // // Print staking histories // - common::complex_viewer::print_staking_histories(&worker, &anchor).await?; + common::complex_viewer::print_staking_histories(&anchor).await; // // Try start and complete switching era3 // appchain_message_nonce += 1; - common::complex_actions::switch_era( - &worker, - &users[5], - &anchor, - 3, - appchain_message_nonce, - true, - ) - .await - .expect("Failed to switch era"); - common::complex_viewer::print_validator_list_of(&worker, &anchor, Some(3)).await?; - common::complex_viewer::print_delegator_list_of(&worker, &anchor, 3, &users[0]).await?; + common::complex_actions::switch_era(&users[5], &anchor, 3, appchain_message_nonce, true).await; + common::complex_viewer::print_validator_list_of(&anchor, Some(3)).await; + common::complex_viewer::print_delegator_list_of(&anchor, 3, &users[0]).await; // // Distribute reward of era2 // appchain_message_nonce += 1; common::complex_actions::distribute_reward_of( - &worker, &users[5], &anchor, &wrapped_appchain_token, @@ -265,72 +236,54 @@ async fn test_staking_actions( [user0_id_in_appchain.clone(), user4_id_in_appchain.clone()].to_vec(), true, ) - .await - .expect("Failed to distribute rewards"); - common::complex_viewer::print_wrapped_appchain_token_info(&worker, &anchor).await?; - common::complex_viewer::print_staking_histories(&worker, &anchor).await?; - common::complex_viewer::print_validator_reward_histories(&worker, &anchor, &users[0], 2) - .await?; - common::complex_viewer::print_validator_reward_histories(&worker, &anchor, &users[1], 2) - .await?; - common::complex_viewer::print_delegator_reward_histories( - &worker, &anchor, &users[2], &users[0], 2, - ) - .await?; - common::complex_viewer::print_delegator_reward_histories( - &worker, &anchor, &users[3], &users[0], 2, - ) - .await?; - common::complex_viewer::print_validator_reward_histories(&worker, &anchor, &users[4], 2) - .await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[0]).await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[1]).await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[2]).await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[3]).await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[4]).await?; + .await; + common::complex_viewer::print_wrapped_appchain_token_info(&anchor).await; + common::complex_viewer::print_staking_histories(&anchor).await; + common::complex_viewer::print_validator_reward_histories(&anchor, &users[0], 2).await; + common::complex_viewer::print_validator_reward_histories(&anchor, &users[1], 2).await; + common::complex_viewer::print_delegator_reward_histories(&anchor, &users[2], &users[0], 2) + .await; + common::complex_viewer::print_delegator_reward_histories(&anchor, &users[3], &users[0], 2) + .await; + common::complex_viewer::print_validator_reward_histories(&anchor, &users[4], 2).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[0]).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[1]).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[2]).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[3]).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[4]).await; // // user0 unbond stake // - // let result = staking_actions::unbond_stake(&users[0], &anchor).await?; + // let result = staking_actions::unbond_stake(&users[0], &anchor).await; // assert!(result.is_success()); - // common::complex_viewer::print_anchor_status(&worker, &anchor).await?; - // let unbonded_stakes = anchor_viewer::get_unbonded_stakes_of(&worker, &anchor, &users[0]).await?; + // common::complex_viewer::print_anchor_status(&anchor).await; + // let unbonded_stakes = anchor_viewer::get_unbonded_stakes_of(&anchor, &users[0]).await; // assert!(unbonded_stakes.len() == 0); // // user1 unbond stake // - // let result = staking_actions::unbond_stake(&users[1], &anchor).await?; + // let result = staking_actions::unbond_stake(&users[1], &anchor).await; // assert!(result.is_success()); - // common::complex_viewer::print_anchor_status(&worker, &anchor).await?; - // let unbonded_stakes = anchor_viewer::get_unbonded_stakes_of(&worker, &anchor, &users[1]).await?; + // common::complex_viewer::print_anchor_status(&anchor).await; + // let unbonded_stakes = anchor_viewer::get_unbonded_stakes_of(&anchor, &users[1]).await; // assert!(unbonded_stakes.len() == 1); // // Print staking histories // - common::complex_viewer::print_staking_histories(&worker, &anchor).await?; + common::complex_viewer::print_staking_histories(&anchor).await; // // Try start and complete switching era4 // appchain_message_nonce += 1; - common::complex_actions::switch_era( - &worker, - &users[5], - &anchor, - 4, - appchain_message_nonce, - true, - ) - .await - .expect("Failed to switch era"); - common::complex_viewer::print_validator_list_of(&worker, &anchor, Some(4)).await?; - common::complex_viewer::print_delegator_list_of(&worker, &anchor, 4, &users[0]).await?; + common::complex_actions::switch_era(&users[5], &anchor, 4, appchain_message_nonce, true).await; + common::complex_viewer::print_validator_list_of(&anchor, Some(4)).await; + common::complex_viewer::print_delegator_list_of(&anchor, 4, &users[0]).await; // // Distribute reward of era3 // - common::complex_viewer::print_validator_set_info_of(&worker, &anchor, U64::from(3)).await?; + common::complex_viewer::print_validator_set_info_of(&anchor, U64::from(3)).await; appchain_message_nonce += 1; common::complex_actions::distribute_reward_of( - &worker, &users[5], &anchor, &wrapped_appchain_token, @@ -339,32 +292,23 @@ async fn test_staking_actions( [user0_id_in_appchain.clone(), user4_id_in_appchain.clone()].to_vec(), true, ) - .await - .expect("Failed to distribute rewards"); - common::complex_viewer::print_wrapped_appchain_token_info(&worker, &anchor).await?; - common::complex_viewer::print_staking_histories(&worker, &anchor).await?; - common::complex_viewer::print_validator_reward_histories(&worker, &anchor, &users[0], 3) - .await?; - common::complex_viewer::print_validator_reward_histories(&worker, &anchor, &users[1], 3) - .await?; - common::complex_viewer::print_delegator_reward_histories( - &worker, &anchor, &users[2], &users[0], 3, - ) - .await?; - common::complex_viewer::print_delegator_reward_histories( - &worker, &anchor, &users[3], &users[0], 3, - ) - .await?; - common::complex_viewer::print_validator_reward_histories(&worker, &anchor, &users[4], 3) - .await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[0]).await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[1]).await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[2]).await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[3]).await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[4]).await?; + .await; + common::complex_viewer::print_wrapped_appchain_token_info(&anchor).await; + common::complex_viewer::print_staking_histories(&anchor).await; + common::complex_viewer::print_validator_reward_histories(&anchor, &users[0], 3).await; + common::complex_viewer::print_validator_reward_histories(&anchor, &users[1], 3).await; + common::complex_viewer::print_delegator_reward_histories(&anchor, &users[2], &users[0], 3) + .await; + common::complex_viewer::print_delegator_reward_histories(&anchor, &users[3], &users[0], 3) + .await; + common::complex_viewer::print_validator_reward_histories(&anchor, &users[4], 3).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[0]).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[1]).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[2]).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[3]).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[4]).await; appchain_message_nonce += 1; common::complex_actions::distribute_reward_of( - &worker, &users[5], &anchor, &wrapped_appchain_token, @@ -373,51 +317,33 @@ async fn test_staking_actions( Vec::new(), true, ) - .await - .expect("Failed to distribute rewards"); - common::complex_viewer::print_wrapped_appchain_token_info(&worker, &anchor).await?; - common::complex_viewer::print_validator_reward_histories(&worker, &anchor, &users[0], 3) - .await?; - common::complex_viewer::print_validator_reward_histories(&worker, &anchor, &users[1], 3) - .await?; - common::complex_viewer::print_delegator_reward_histories( - &worker, &anchor, &users[2], &users[0], 3, - ) - .await?; - common::complex_viewer::print_delegator_reward_histories( - &worker, &anchor, &users[3], &users[0], 3, - ) - .await?; - common::complex_viewer::print_validator_reward_histories(&worker, &anchor, &users[4], 3) - .await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[0]).await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[1]).await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[2]).await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[3]).await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[4]).await?; + .await; + common::complex_viewer::print_wrapped_appchain_token_info(&anchor).await; + common::complex_viewer::print_validator_reward_histories(&anchor, &users[0], 3).await; + common::complex_viewer::print_validator_reward_histories(&anchor, &users[1], 3).await; + common::complex_viewer::print_delegator_reward_histories(&anchor, &users[2], &users[0], 3) + .await; + common::complex_viewer::print_delegator_reward_histories(&anchor, &users[3], &users[0], 3) + .await; + common::complex_viewer::print_validator_reward_histories(&anchor, &users[4], 3).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[0]).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[1]).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[2]).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[3]).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[4]).await; // // Try start and complete switching era5 // appchain_message_nonce += 1; - common::complex_actions::switch_era( - &worker, - &users[5], - &anchor, - 5, - appchain_message_nonce, - true, - ) - .await - .expect("Failed to switch era"); - common::complex_viewer::print_validator_list_of(&worker, &anchor, Some(5)).await?; - common::complex_viewer::print_delegator_list_of(&worker, &anchor, 5, &users[0]).await?; + common::complex_actions::switch_era(&users[5], &anchor, 5, appchain_message_nonce, true).await; + common::complex_viewer::print_validator_list_of(&anchor, Some(5)).await; + common::complex_viewer::print_delegator_list_of(&anchor, 5, &users[0]).await; // // Distribute reward of era4 // - common::complex_viewer::print_validator_set_info_of(&worker, &anchor, U64::from(4)).await?; + common::complex_viewer::print_validator_set_info_of(&anchor, U64::from(4)).await; appchain_message_nonce += 1; common::complex_actions::distribute_reward_of( - &worker, &users[5], &anchor, &wrapped_appchain_token, @@ -426,110 +352,92 @@ async fn test_staking_actions( Vec::new(), true, ) - .await - .expect("Failed to distribute rewards"); - common::complex_viewer::print_wrapped_appchain_token_info(&worker, &anchor).await?; - common::complex_viewer::print_staking_histories(&worker, &anchor).await?; - common::complex_viewer::print_validator_reward_histories(&worker, &anchor, &users[0], 4) - .await?; - common::complex_viewer::print_validator_reward_histories(&worker, &anchor, &users[1], 4) - .await?; - common::complex_viewer::print_delegator_reward_histories( - &worker, &anchor, &users[2], &users[0], 4, - ) - .await?; - common::complex_viewer::print_delegator_reward_histories( - &worker, &anchor, &users[3], &users[0], 4, - ) - .await?; - common::complex_viewer::print_validator_reward_histories(&worker, &anchor, &users[4], 4) - .await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[0]).await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[1]).await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[2]).await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[3]).await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[4]).await?; + .await; + common::complex_viewer::print_wrapped_appchain_token_info(&anchor).await; + common::complex_viewer::print_staking_histories(&anchor).await; + common::complex_viewer::print_validator_reward_histories(&anchor, &users[0], 4).await; + common::complex_viewer::print_validator_reward_histories(&anchor, &users[1], 4).await; + common::complex_viewer::print_delegator_reward_histories(&anchor, &users[2], &users[0], 4) + .await; + common::complex_viewer::print_delegator_reward_histories(&anchor, &users[3], &users[0], 4) + .await; + common::complex_viewer::print_validator_reward_histories(&anchor, &users[4], 4).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[0]).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[1]).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[2]).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[3]).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[4]).await; // // Withdraw validator rewards // common::complex_actions::withdraw_validator_rewards_of( - &worker, &anchor, &users[0], &wrapped_appchain_token, 3, ) - .await - .expect("Failed in calling 'withdraw_validator_rewards_of'"); + .await; common::complex_actions::withdraw_validator_rewards_of( - &worker, &anchor, &users[1], &wrapped_appchain_token, 3, ) - .await - .expect("Failed in calling 'withdraw_validator_rewards_of'"); + .await; common::complex_actions::withdraw_validator_rewards_of( - &worker, &anchor, &users[4], &wrapped_appchain_token, 3, ) - .await - .expect("Failed in calling 'withdraw_validator_rewards_of'"); + .await; // // Withdraw delegator rewards // common::complex_actions::withdraw_delegator_rewards_of( - &worker, &anchor, &users[2], &users[0], &wrapped_appchain_token, 3, ) - .await - .expect("Failed in calling 'withdraw_delegator_rewards_of'"); + .await; common::complex_actions::withdraw_delegator_rewards_of( - &worker, &anchor, &users[3], &users[0], &wrapped_appchain_token, 3, ) - .await - .expect("Failed in calling 'withdraw_delegator_rewards_of'"); + .await; // // Withdraw stake // - common::complex_actions::withdraw_stake_of(&worker, &anchor, &users[0], &oct_token) + common::complex_actions::withdraw_stake_of(&anchor, &users[0], &oct_token) .await .expect("Failed in calling 'withdraw_stake_of'"); - common::complex_actions::withdraw_stake_of(&worker, &anchor, &users[1], &oct_token) + common::complex_actions::withdraw_stake_of(&anchor, &users[1], &oct_token) .await .expect("Failed in calling 'withdraw_stake_of'"); - common::complex_actions::withdraw_stake_of(&worker, &anchor, &users[2], &oct_token) + common::complex_actions::withdraw_stake_of(&anchor, &users[2], &oct_token) .await .expect("Failed in calling 'withdraw_stake_of'"); - common::complex_actions::withdraw_stake_of(&worker, &anchor, &users[3], &oct_token) + common::complex_actions::withdraw_stake_of(&anchor, &users[3], &oct_token) .await .expect("Failed in calling 'withdraw_stake_of'"); - common::complex_actions::withdraw_stake_of(&worker, &anchor, &users[4], &oct_token) + common::complex_actions::withdraw_stake_of(&anchor, &users[4], &oct_token) .await .expect("Failed in calling 'withdraw_stake_of'"); // // Print whole status // - common::complex_viewer::print_anchor_status(&worker, &anchor).await?; - common::complex_viewer::print_wrapped_appchain_token_info(&worker, &anchor).await?; - common::complex_viewer::print_validator_list_of(&worker, &anchor, Some(0)).await?; - common::complex_viewer::print_validator_list_of(&worker, &anchor, Some(1)).await?; - common::complex_viewer::print_validator_list_of(&worker, &anchor, Some(2)).await?; - common::complex_viewer::print_validator_list_of(&worker, &anchor, Some(3)).await?; - common::complex_viewer::print_staking_histories(&worker, &anchor).await?; - common::complex_viewer::print_appchain_notifications(&worker, &anchor).await?; + common::complex_viewer::print_anchor_status(&anchor).await; + common::complex_viewer::print_wrapped_appchain_token_info(&anchor).await; + common::complex_viewer::print_validator_list_of(&anchor, Some(0)).await; + common::complex_viewer::print_validator_list_of(&anchor, Some(1)).await; + common::complex_viewer::print_validator_list_of(&anchor, Some(2)).await; + common::complex_viewer::print_validator_list_of(&anchor, Some(3)).await; + common::complex_viewer::print_staking_histories(&anchor).await; + common::complex_viewer::print_appchain_notifications(&anchor).await; Ok(()) } diff --git a/tests/simulator/test_beefy_light_client_1.rs b/tests/simulator/test_beefy_light_client_1.rs index d2cea97..afbcc16 100644 --- a/tests/simulator/test_beefy_light_client_1.rs +++ b/tests/simulator/test_beefy_light_client_1.rs @@ -7,10 +7,10 @@ use crate::{ use appchain_anchor::types::ValidatorMerkleProof; use beefy_light_client::mmr::{MmrLeaf, MmrLeafProof}; use beefy_light_client::{beefy_ecdsa_to_ethereum, commitment::SignedCommitment}; -use codec::Decode; use hex_literal::hex; use near_sdk::serde_json; -use workspaces::{network::Sandbox, Account, Contract, Worker}; +use parity_scale_codec::Decode; +use workspaces::{Account, Contract}; #[tokio::test] async fn test_beefy_light_client_1() -> anyhow::Result<()> { @@ -37,31 +37,22 @@ async fn test_beefy_light_client_1() -> anyhow::Result<()> { // // Update state of beefy light client // - update_state_of_beefy_light_client_1(&worker, &anchor, &users[4]).await?; - common::complex_viewer::print_beefy_light_client_status(&worker, &anchor).await?; - update_state_of_beefy_light_client_2(&worker, &anchor, &users[1]).await?; - common::complex_viewer::print_beefy_light_client_status(&worker, &anchor).await?; + update_state_of_beefy_light_client_1(&anchor, &users[4]).await?; + common::complex_viewer::print_beefy_light_client_status(&anchor).await; + update_state_of_beefy_light_client_2(&anchor, &users[1]).await?; + common::complex_viewer::print_beefy_light_client_status(&anchor).await; // // Try start and complete switching era1 // appchain_message_nonce += 1; - common::complex_actions::switch_era( - &worker, - &users[5], - &anchor, - 1, - appchain_message_nonce, - true, - ) - .await?; - common::complex_viewer::print_validator_list_of(&worker, &anchor, Some(1)).await?; - common::complex_viewer::print_delegator_list_of(&worker, &anchor, 1, &users[0]).await?; + common::complex_actions::switch_era(&users[5], &anchor, 1, appchain_message_nonce, true).await; + common::complex_viewer::print_validator_list_of(&anchor, Some(1)).await; + common::complex_viewer::print_delegator_list_of(&anchor, 1, &users[0]).await; // // Distribut reward of era0 // appchain_message_nonce += 1; common::complex_actions::distribute_reward_of( - &worker, &users[5], &anchor, &wrapped_appchain_token, @@ -70,42 +61,33 @@ async fn test_beefy_light_client_1() -> anyhow::Result<()> { Vec::new(), true, ) - .await?; - common::complex_viewer::print_wrapped_appchain_token_info(&worker, &anchor).await?; - common::complex_viewer::print_validator_reward_histories(&worker, &anchor, &users[0], 0) - .await?; - common::complex_viewer::print_validator_reward_histories(&worker, &anchor, &users[1], 0) - .await?; - common::complex_viewer::print_delegator_reward_histories( - &worker, &anchor, &users[2], &users[0], 0, - ) - .await?; - common::complex_viewer::print_delegator_reward_histories( - &worker, &anchor, &users[3], &users[0], 0, - ) - .await?; - common::complex_viewer::print_validator_reward_histories(&worker, &anchor, &users[4], 0) - .await?; + .await; + common::complex_viewer::print_wrapped_appchain_token_info(&anchor).await; + common::complex_viewer::print_validator_reward_histories(&anchor, &users[0], 0).await; + common::complex_viewer::print_validator_reward_histories(&anchor, &users[1], 0).await; + common::complex_viewer::print_delegator_reward_histories(&anchor, &users[2], &users[0], 0) + .await; + common::complex_viewer::print_delegator_reward_histories(&anchor, &users[3], &users[0], 0) + .await; + common::complex_viewer::print_validator_reward_histories(&anchor, &users[4], 0).await; // // user1 decrease stake // - let result = staking_actions::decrease_stake( - &worker, + assert!(staking_actions::decrease_stake( &users[1], &anchor, - common::to_actual_amount(1000, 18), + common::to_actual_amount(1000, 18) ) - .await?; - assert!(result.is_success()); - common::complex_viewer::print_anchor_status(&worker, &anchor).await?; - let unbonded_stakes = - anchor_viewer::get_unbonded_stakes_of(&worker, &anchor, &users[1]).await?; + .await + .unwrap() + .is_success()); + common::complex_viewer::print_anchor_status(&anchor).await; + let unbonded_stakes = anchor_viewer::get_unbonded_stakes_of(&anchor, &users[1]).await?; assert!(unbonded_stakes.len() == 0); // // user2 decrease delegation // let result = staking_actions::decrease_delegation( - &worker, &users[2], &anchor, &users[0].id().to_string().parse().unwrap(), @@ -113,35 +95,25 @@ async fn test_beefy_light_client_1() -> anyhow::Result<()> { ) .await?; assert!(result.is_success()); - common::complex_viewer::print_anchor_status(&worker, &anchor).await?; - let unbonded_stakes = - anchor_viewer::get_unbonded_stakes_of(&worker, &anchor, &users[2]).await?; + common::complex_viewer::print_anchor_status(&anchor).await; + let unbonded_stakes = anchor_viewer::get_unbonded_stakes_of(&anchor, &users[2]).await?; assert!(unbonded_stakes.len() == 0); // // Print staking histories // - common::complex_viewer::print_staking_histories(&worker, &anchor).await?; + common::complex_viewer::print_staking_histories(&anchor).await; // // Try start and complete switching era2 // appchain_message_nonce += 1; - common::complex_actions::switch_era( - &worker, - &users[5], - &anchor, - 2, - appchain_message_nonce, - true, - ) - .await?; - common::complex_viewer::print_validator_list_of(&worker, &anchor, Some(2)).await?; - common::complex_viewer::print_delegator_list_of(&worker, &anchor, 2, &users[0]).await?; + common::complex_actions::switch_era(&users[5], &anchor, 2, appchain_message_nonce, true).await; + common::complex_viewer::print_validator_list_of(&anchor, Some(2)).await; + common::complex_viewer::print_delegator_list_of(&anchor, 2, &users[0]).await; // // Distribute reward of era1 // appchain_message_nonce += 1; common::complex_actions::distribute_reward_of( - &worker, &users[5], &anchor, &wrapped_appchain_token, @@ -150,78 +122,58 @@ async fn test_beefy_light_client_1() -> anyhow::Result<()> { Vec::new(), true, ) - .await?; - common::complex_viewer::print_wrapped_appchain_token_info(&worker, &anchor).await?; - common::complex_viewer::print_validator_reward_histories(&worker, &anchor, &users[0], 1) - .await?; - common::complex_viewer::print_validator_reward_histories(&worker, &anchor, &users[1], 1) - .await?; - common::complex_viewer::print_delegator_reward_histories( - &worker, &anchor, &users[2], &users[0], 1, - ) - .await?; - common::complex_viewer::print_delegator_reward_histories( - &worker, &anchor, &users[3], &users[0], 1, - ) - .await?; - common::complex_viewer::print_validator_reward_histories(&worker, &anchor, &users[4], 1) - .await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[0]).await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[1]).await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[2]).await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[3]).await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[4]).await?; + .await; + common::complex_viewer::print_wrapped_appchain_token_info(&anchor).await; + common::complex_viewer::print_validator_reward_histories(&anchor, &users[0], 1).await; + common::complex_viewer::print_validator_reward_histories(&anchor, &users[1], 1).await; + common::complex_viewer::print_delegator_reward_histories(&anchor, &users[2], &users[0], 1) + .await; + common::complex_viewer::print_delegator_reward_histories(&anchor, &users[3], &users[0], 1) + .await; + common::complex_viewer::print_validator_reward_histories(&anchor, &users[4], 1).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[0]).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[1]).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[2]).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[3]).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[4]).await; // // Change unlock period for testing // let result = - settings_manager::change_unlock_period_of_validator_deposit(&worker, &root, &anchor, 3) - .await?; + settings_manager::change_unlock_period_of_validator_deposit(&root, &anchor, 3).await?; assert!(result.is_success()); let result = - settings_manager::change_unlock_period_of_delegator_deposit(&worker, &root, &anchor, 1) - .await?; + settings_manager::change_unlock_period_of_delegator_deposit(&root, &anchor, 1).await?; assert!(result.is_success()); // // user3 unbond delegation // let result = staking_actions::unbond_delegation( - &worker, &users[2], &anchor, &users[0].id().to_string().parse().unwrap(), ) .await?; assert!(result.is_success()); - common::complex_viewer::print_anchor_status(&worker, &anchor).await?; - let unbonded_stakes = - anchor_viewer::get_unbonded_stakes_of(&worker, &anchor, &users[2]).await?; + common::complex_viewer::print_anchor_status(&anchor).await; + let unbonded_stakes = anchor_viewer::get_unbonded_stakes_of(&anchor, &users[2]).await?; assert!(unbonded_stakes.len() == 1); // // Print staking histories // - common::complex_viewer::print_staking_histories(&worker, &anchor).await?; + common::complex_viewer::print_staking_histories(&anchor).await; // // Try start and complete switching era3 // appchain_message_nonce += 1; - common::complex_actions::switch_era( - &worker, - &users[5], - &anchor, - 3, - appchain_message_nonce, - true, - ) - .await?; - common::complex_viewer::print_validator_list_of(&worker, &anchor, Some(3)).await?; - common::complex_viewer::print_delegator_list_of(&worker, &anchor, 3, &users[0]).await?; + common::complex_actions::switch_era(&users[5], &anchor, 3, appchain_message_nonce, true).await; + common::complex_viewer::print_validator_list_of(&anchor, Some(3)).await; + common::complex_viewer::print_delegator_list_of(&anchor, 3, &users[0]).await; // // Distribute reward of era2 // appchain_message_nonce += 1; common::complex_actions::distribute_reward_of( - &worker, &users[5], &anchor, &wrapped_appchain_token, @@ -230,61 +182,44 @@ async fn test_beefy_light_client_1() -> anyhow::Result<()> { Vec::new(), true, ) - .await?; - common::complex_viewer::print_wrapped_appchain_token_info(&worker, &anchor).await?; - common::complex_viewer::print_validator_reward_histories(&worker, &anchor, &users[0], 2) - .await?; - common::complex_viewer::print_validator_reward_histories(&worker, &anchor, &users[1], 2) - .await?; - common::complex_viewer::print_delegator_reward_histories( - &worker, &anchor, &users[2], &users[0], 2, - ) - .await?; - common::complex_viewer::print_delegator_reward_histories( - &worker, &anchor, &users[3], &users[0], 2, - ) - .await?; - common::complex_viewer::print_validator_reward_histories(&worker, &anchor, &users[4], 2) - .await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[0]).await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[1]).await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[2]).await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[3]).await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[4]).await?; + .await; + common::complex_viewer::print_wrapped_appchain_token_info(&anchor).await; + common::complex_viewer::print_validator_reward_histories(&anchor, &users[0], 2).await; + common::complex_viewer::print_validator_reward_histories(&anchor, &users[1], 2).await; + common::complex_viewer::print_delegator_reward_histories(&anchor, &users[2], &users[0], 2) + .await; + common::complex_viewer::print_delegator_reward_histories(&anchor, &users[3], &users[0], 2) + .await; + common::complex_viewer::print_validator_reward_histories(&anchor, &users[4], 2).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[0]).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[1]).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[2]).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[3]).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[4]).await; // // user0 unbond stake // - let result = staking_actions::unbond_stake(&worker, &users[0], &anchor).await?; + let result = staking_actions::unbond_stake(&users[0], &anchor).await?; assert!(result.is_success()); - common::complex_viewer::print_anchor_status(&worker, &anchor).await?; - let unbonded_stakes = - anchor_viewer::get_unbonded_stakes_of(&worker, &anchor, &users[0]).await?; + common::complex_viewer::print_anchor_status(&anchor).await; + let unbonded_stakes = anchor_viewer::get_unbonded_stakes_of(&anchor, &users[0]).await?; assert!(unbonded_stakes.len() == 0); // // Print staking histories // - common::complex_viewer::print_staking_histories(&worker, &anchor).await?; + common::complex_viewer::print_staking_histories(&anchor).await; // // Try start and complete switching era3 // appchain_message_nonce += 1; - common::complex_actions::switch_era( - &worker, - &users[5], - &anchor, - 4, - appchain_message_nonce, - true, - ) - .await?; - common::complex_viewer::print_validator_list_of(&worker, &anchor, Some(4)).await?; - common::complex_viewer::print_delegator_list_of(&worker, &anchor, 4, &users[0]).await?; + common::complex_actions::switch_era(&users[5], &anchor, 4, appchain_message_nonce, true).await; + common::complex_viewer::print_validator_list_of(&anchor, Some(4)).await; + common::complex_viewer::print_delegator_list_of(&anchor, 4, &users[0]).await; // // Distribute reward of era3 // appchain_message_nonce += 1; common::complex_actions::distribute_reward_of( - &worker, &users[5], &anchor, &wrapped_appchain_token, @@ -293,88 +228,75 @@ async fn test_beefy_light_client_1() -> anyhow::Result<()> { Vec::new(), true, ) - .await?; - common::complex_viewer::print_wrapped_appchain_token_info(&worker, &anchor).await?; - common::complex_viewer::print_validator_reward_histories(&worker, &anchor, &users[0], 3) - .await?; - common::complex_viewer::print_validator_reward_histories(&worker, &anchor, &users[1], 3) - .await?; - common::complex_viewer::print_delegator_reward_histories( - &worker, &anchor, &users[2], &users[0], 3, - ) - .await?; - common::complex_viewer::print_delegator_reward_histories( - &worker, &anchor, &users[3], &users[0], 3, - ) - .await?; - common::complex_viewer::print_validator_reward_histories(&worker, &anchor, &users[4], 3) - .await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[0]).await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[1]).await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[2]).await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[3]).await?; - common::complex_viewer::print_unbonded_stakes_of(&worker, &anchor, &users[4]).await?; + .await; + common::complex_viewer::print_wrapped_appchain_token_info(&anchor).await; + common::complex_viewer::print_validator_reward_histories(&anchor, &users[0], 3).await; + common::complex_viewer::print_validator_reward_histories(&anchor, &users[1], 3).await; + common::complex_viewer::print_delegator_reward_histories(&anchor, &users[2], &users[0], 3) + .await; + common::complex_viewer::print_delegator_reward_histories(&anchor, &users[3], &users[0], 3) + .await; + common::complex_viewer::print_validator_reward_histories(&anchor, &users[4], 3).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[0]).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[1]).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[2]).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[3]).await; + common::complex_viewer::print_unbonded_stakes_of(&anchor, &users[4]).await; // // Withdraw validator rewards // common::complex_actions::withdraw_validator_rewards_of( - &worker, &anchor, &users[0], &wrapped_appchain_token, 3, ) - .await?; + .await; common::complex_actions::withdraw_validator_rewards_of( - &worker, &anchor, &users[1], &wrapped_appchain_token, 3, ) - .await?; + .await; common::complex_actions::withdraw_validator_rewards_of( - &worker, &anchor, &users[4], &wrapped_appchain_token, 3, ) - .await?; + .await; // // Withdraw delegator rewards // common::complex_actions::withdraw_delegator_rewards_of( - &worker, &anchor, &users[2], &users[0], &wrapped_appchain_token, 3, ) - .await?; + .await; common::complex_actions::withdraw_delegator_rewards_of( - &worker, &anchor, &users[3], &users[0], &wrapped_appchain_token, 3, ) - .await?; + .await; // // Withdraw stake // - common::complex_actions::withdraw_stake_of(&worker, &anchor, &users[0], &oct_token).await?; - common::complex_actions::withdraw_stake_of(&worker, &anchor, &users[1], &oct_token).await?; - common::complex_actions::withdraw_stake_of(&worker, &anchor, &users[2], &oct_token).await?; - common::complex_actions::withdraw_stake_of(&worker, &anchor, &users[3], &oct_token).await?; - common::complex_actions::withdraw_stake_of(&worker, &anchor, &users[4], &oct_token).await?; + common::complex_actions::withdraw_stake_of(&anchor, &users[0], &oct_token).await?; + common::complex_actions::withdraw_stake_of(&anchor, &users[1], &oct_token).await?; + common::complex_actions::withdraw_stake_of(&anchor, &users[2], &oct_token).await?; + common::complex_actions::withdraw_stake_of(&anchor, &users[3], &oct_token).await?; + common::complex_actions::withdraw_stake_of(&anchor, &users[4], &oct_token).await?; Ok(()) } async fn update_state_of_beefy_light_client_1( - worker: &Worker, anchor: &Contract, user: &Account, ) -> anyhow::Result<()> { @@ -460,7 +382,6 @@ async fn update_state_of_beefy_light_client_1( println!("mmr_proof_1: {:?}", mmr_proof_1); // let result = permissionless_actions::process_appchain_messages_with_all_proofs( - &worker, &user, &anchor, encoded_signed_commitment_1.to_vec(), @@ -483,7 +404,6 @@ async fn update_state_of_beefy_light_client_1( } async fn update_state_of_beefy_light_client_2( - worker: &Worker, anchor: &Contract, user: &Account, ) -> anyhow::Result<()> { @@ -569,7 +489,6 @@ async fn update_state_of_beefy_light_client_2( println!("mmr_proof_2: {:?}", mmr_proof_2); // let result = permissionless_actions::process_appchain_messages_with_all_proofs( - &worker, &user, &anchor, encoded_signed_commitment_2.to_vec(), diff --git a/tests/simulator/test_beefy_light_client_2.rs b/tests/simulator/test_beefy_light_client_2.rs deleted file mode 100644 index e8b2352..0000000 --- a/tests/simulator/test_beefy_light_client_2.rs +++ /dev/null @@ -1,109 +0,0 @@ -use crate::{common, contract_interfaces::permissionless_actions}; -use appchain_anchor::types::ValidatorMerkleProof; -use beefy_light_client::commitment::{Commitment, Payload, Signature}; -use beefy_light_client::{beefy_ecdsa_to_ethereum, commitment::SignedCommitment}; -use beefy_merkle_tree::{merkle_proof, Keccak256}; -use codec::Encode; -use hex_literal::hex; -use near_sdk::serde_json; -use secp256k1_test::{rand::thread_rng, Message as SecpMessage, Secp256k1}; -use std::convert::TryInto; - -type BeefyPayloadId = [u8; 2]; -const MMR_ROOT_ID: BeefyPayloadId = *b"mh"; - -#[tokio::test] -async fn test_beefy_light_client_2() -> anyhow::Result<()> { - let worker = workspaces::sandbox().await?; - const MAX_VALIDATORS: i32 = 35; - - let secp = Secp256k1::new(); - - let mut initial_public_keys = Vec::new(); - let mut origin_initial_public_keys = Vec::new(); - let payload = Payload(vec![( - MMR_ROOT_ID, - hex!("67678b4a811dc055ff865fdfdda11c7464a9c77a988af4fcdea92e38ae6c6320").to_vec(), - )]); - let commitment = Commitment { - payload, - block_number: 9, - validator_set_id: 0, - }; - let commitment_hash = commitment.hash(); - let msg = SecpMessage::from_slice(&commitment_hash[..]).unwrap(); - let mut signed_commitment = SignedCommitment { - commitment, - signatures: vec![], - }; - - for _ in 0..MAX_VALIDATORS { - let (privkey, pubkey) = secp.generate_keypair(&mut thread_rng()); - origin_initial_public_keys.push(pubkey.serialize().to_vec()); - // println!("pubkey: {:?}", pubkey); - // println!("prikey: {:?}", privkey); - let validator_address = beefy_ecdsa_to_ethereum(&pubkey.serialize()); - // println!("validator_address: {:?}", validator_address); - initial_public_keys.push(validator_address); - let (recover_id, signature) = secp.sign_recoverable(&msg, &privkey).serialize_compact(); - - let mut buf = [0_u8; 65]; - buf[0..64].copy_from_slice(&signature[..]); - buf[64] = recover_id.to_i32() as u8; - - signed_commitment.signatures.push(Some(Signature(buf))); - } - let encoded_signed_commitment = signed_commitment.encode(); - - let mut validator_proofs = Vec::new(); - for i in 0..initial_public_keys.len() { - let proof = merkle_proof::(initial_public_keys.clone(), i); - validator_proofs.push(ValidatorMerkleProof { - proof: proof.proof, - number_of_leaves: proof.number_of_leaves.try_into().unwrap(), - leaf_index: proof.leaf_index.try_into().unwrap(), - leaf: proof.leaf, - }); - } - - let encoded_mmr_leaf = hex!("c5010016000000e961cf2536958785869a8f1892c478ff5f91c5a01ece8a50d7f52cc5d31f96d3010000000000000005000000304803fa5a91d9852caafe04b4b867a4ed27a07a5bee3d1507b4b187a68777a20000000000000000000000000000000000000000000000000000000000000000"); - let encoded_mmr_proof = hex!("16000000000000001900000000000000143b96661a7161a6a760af588ebdefc79401e1c046d889d59f76d824406f713188c58385673dc5fffca2611dec971872597fa18462ec82f781d44c7f51f888460a927066f988d8d2b5c193a0fca08920bc21c56dfd2ea44fdcd9ceb97acd22e1a5dc8d1b12b23542b45f9e025bc4e611129aae70a08a7180839c8b698becf48e2326479d9be91711c950d8584e9f9dd49b6424e13d590afc8b00a41d5be40c4fb5"); - // - let initial_public_keys = origin_initial_public_keys - .iter() - .map(|pk_bytes| format!("0x{}", hex::encode(pk_bytes))) - .collect(); - let ( - root, - _oct_token, - _wrapped_appchain_token, - _registry, - _council, - anchor, - _wat_faucet, - _users, - _appchain_message_nonce, - ) = common::test_normal_actions(&worker, false, true, initial_public_keys).await?; - // - let result = permissionless_actions::process_appchain_messages_with_all_proofs( - &worker, - &root, - &anchor, - encoded_signed_commitment.to_vec(), - validator_proofs, - encoded_mmr_leaf.to_vec(), - encoded_mmr_proof.to_vec(), - Vec::new(), - Vec::new(), - Vec::new(), - Vec::new(), - ) - .await - .expect("Failed in calling 'process_appchain_messages_with_all_proofs'"); - println!( - "Result of 'process_appchain_messages_with_all_proofs': {}", - serde_json::to_string(&result).unwrap() - ); - // - Ok(()) -} diff --git a/tests/simulator/test_equivocation_challenge.rs b/tests/simulator/test_equivocation_challenge.rs index 79bf4cd..4e01626 100644 --- a/tests/simulator/test_equivocation_challenge.rs +++ b/tests/simulator/test_equivocation_challenge.rs @@ -11,22 +11,22 @@ async fn test_equivocation_challenge() -> anyhow::Result<()> { // if let Ok(challenge) = serde_json::from_str::("{\"EquivocationChallenge\":{\"submitter_account\":\"tt.testnet\",\"proof\":{\"set_id\":0,\"equivocation\":{\"Prevote\":{\"round_number\":2,\"identity\":[209,124,45,120,35,235,242,96,253,19,143,45,126,39,209,20,192,20,93,150,139,95,245,0,97,37,242,65,79,173,174,105],\"first\":[{\"target_hash\":[96,43,40,162,148,136,214,36,237,150,130,159,164,176,134,217,188,7,156,28,26,245,153,173,235,220,148,113,142,54,86,172],\"target_number\":2},[160,8,125,180,57,254,58,164,29,247,251,21,218,43,228,81,110,42,54,245,139,100,113,120,8,169,186,72,79,1,10,44,124,214,240,57,158,28,5,246,112,141,249,88,85,136,172,109,27,246,217,212,175,90,35,66,230,60,7,116,132,238,222,10]],\"second\":[{\"target_hash\":[55,65,109,173,2,87,56,21,245,65,225,251,11,255,55,219,64,83,133,115,5,161,227,232,204,172,40,117,127,126,63,225],\"target_number\":1},[182,116,59,76,20,131,229,152,169,61,221,96,84,126,111,231,69,122,21,132,2,242,18,172,118,22,204,130,230,203,228,28,91,196,141,105,180,223,209,205,3,210,217,106,135,148,174,214,169,196,82,106,255,89,109,197,73,142,237,71,179,42,184,7]]}}}}}") { let result = users[3] - .call(&worker, anchor.id(), "commit_appchain_challenge") + .call(anchor.id(), "commit_appchain_challenge") .args_json(json!({ "appchain_challenge": challenge - }))? + })) .gas(300_000_000_000_000) .transact() .await?; assert!(result.is_success()); // - let appchain_challenge = anchor_viewer::get_appchain_challenge(&worker, &anchor, 0).await?; + let appchain_challenge = anchor_viewer::get_appchain_challenge(&anchor, 0).await?; println!( "Appchain challenge 0: {}", serde_json::to_string(&appchain_challenge).unwrap() ); // - let appchain_challenges = anchor_viewer::get_appchain_challenges(&worker, &anchor, 0, None).await?; + let appchain_challenges = anchor_viewer::get_appchain_challenges(&anchor, 0, None).await?; let mut index = 0; for appchain_challenge in appchain_challenges { println!( diff --git a/tests/simulator/test_migration.rs b/tests/simulator/test_migration.rs index 274af35..df377dc 100644 --- a/tests/simulator/test_migration.rs +++ b/tests/simulator/test_migration.rs @@ -25,22 +25,12 @@ async fn test_migration() -> anyhow::Result<()> { // Try start and complete switching era1 // appchain_message_nonce += 1; - complex_actions::switch_era( - &worker, - &users[5], - &anchor, - 1, - appchain_message_nonce, - false, - ) - .await - .expect("Failed to switch era 1."); + complex_actions::switch_era(&users[5], &anchor, 1, appchain_message_nonce, false).await; // // Distribut reward of era0 // appchain_message_nonce += 1; complex_actions::distribute_reward_of( - &worker, &users[5], &anchor, &wrapped_appchain_token, @@ -49,19 +39,20 @@ async fn test_migration() -> anyhow::Result<()> { Vec::new(), false, ) - .await - .expect("Failed to distribute reward of era 0."); + .await; // - root.call(&worker, anchor.id(), "store_wasm_of_self") + assert!(root + .call(anchor.id(), "store_wasm_of_self") .args(std::fs::read(format!("res/appchain_anchor.wasm"))?) .gas(300_000_000_000_000) .deposit(parse_near!("30 N")) .transact() .await - .expect("Failed in calling 'store_wasm_of_self'"); + .unwrap() + .is_success()); // let result = root - .call(&worker, anchor.id(), "update_self") + .call(anchor.id(), "update_self") .gas(300_000_000_000_000) .transact() .await?; @@ -70,10 +61,10 @@ async fn test_migration() -> anyhow::Result<()> { assert!(result.is_success()); // let result = anchor - .call(&worker, "migrate_appchain_messages") + .call("migrate_appchain_messages") .args_json(json!({ "start_nonce": 0, - }))? + })) .gas(300_000_000_000_000) .transact() .await?; @@ -86,34 +77,32 @@ async fn test_migration() -> anyhow::Result<()> { // // // - common::complex_viewer::print_anchor_status(&worker, &anchor).await?; - common::complex_viewer::print_wrapped_appchain_token_info(&worker, &anchor).await?; - common::complex_viewer::print_appchain_settings(&worker, &anchor).await?; - common::complex_viewer::print_anchor_settings(&worker, &anchor).await?; - common::complex_viewer::print_validator_set_info_of(&worker, &anchor, U64::from(0)).await?; - common::complex_viewer::print_validator_list_of(&worker, &anchor, Some(0)).await?; - common::complex_viewer::print_validator_list_of(&worker, &anchor, Some(1)).await?; - common::complex_viewer::print_validator_list_of(&worker, &anchor, Some(2)).await?; - common::complex_viewer::print_validator_list_of(&worker, &anchor, Some(3)).await?; - common::complex_viewer::print_user_staking_histories_of(&worker, &anchor, &users[0]).await?; - common::complex_viewer::print_user_staking_histories_of(&worker, &anchor, &users[1]).await?; - common::complex_viewer::print_user_staking_histories_of(&worker, &anchor, &users[2]).await?; - common::complex_viewer::print_user_staking_histories_of(&worker, &anchor, &users[3]).await?; - common::complex_viewer::print_user_staking_histories_of(&worker, &anchor, &users[4]).await?; + common::complex_viewer::print_anchor_status(&anchor).await; + common::complex_viewer::print_wrapped_appchain_token_info(&anchor).await; + common::complex_viewer::print_appchain_settings(&anchor).await; + common::complex_viewer::print_anchor_settings(&anchor).await; + common::complex_viewer::print_validator_set_info_of(&anchor, U64::from(0)).await; + common::complex_viewer::print_validator_list_of(&anchor, Some(0)).await; + common::complex_viewer::print_validator_list_of(&anchor, Some(1)).await; + common::complex_viewer::print_validator_list_of(&anchor, Some(2)).await; + common::complex_viewer::print_validator_list_of(&anchor, Some(3)).await; + common::complex_viewer::print_user_staking_histories_of(&anchor, &users[0]).await; + common::complex_viewer::print_user_staking_histories_of(&anchor, &users[1]).await; + common::complex_viewer::print_user_staking_histories_of(&anchor, &users[2]).await; + common::complex_viewer::print_user_staking_histories_of(&anchor, &users[3]).await; + common::complex_viewer::print_user_staking_histories_of(&anchor, &users[4]).await; common::complex_viewer::print_validator_profile( - &worker, &anchor, &users[0].id().to_string().parse().unwrap(), &user0_id_in_appchain, ) - .await?; + .await; common::complex_viewer::print_validator_profile( - &worker, &anchor, &users[1].id().to_string().parse().unwrap(), &user1_id_in_appchain, ) - .await?; - common::complex_viewer::print_appchain_messages(&worker, &anchor).await?; + .await; + common::complex_viewer::print_appchain_messages(&anchor).await; Ok(()) } diff --git a/tests/simulator/test_sync_staking_amount.rs b/tests/simulator/test_sync_staking_amount.rs index 7d89750..2743a20 100644 --- a/tests/simulator/test_sync_staking_amount.rs +++ b/tests/simulator/test_sync_staking_amount.rs @@ -24,22 +24,12 @@ async fn test_sync_staking_amount() -> anyhow::Result<()> { // Try start and complete switching era1 // appchain_message_nonce += 1; - complex_actions::switch_era( - &worker, - &users[5], - &anchor, - 1, - appchain_message_nonce, - false, - ) - .await - .expect("Failed to switch era 1."); + complex_actions::switch_era(&users[5], &anchor, 1, appchain_message_nonce, false).await; // // Distribut reward of era0 // appchain_message_nonce += 1; complex_actions::distribute_reward_of( - &worker, &users[5], &anchor, &wrapped_appchain_token, @@ -48,27 +38,17 @@ async fn test_sync_staking_amount() -> anyhow::Result<()> { Vec::new(), false, ) - .await - .expect("Failed to distribute reward of era 0."); + .await; // // Try start and complete switching era2 // appchain_message_nonce += 1; - complex_actions::switch_era( - &worker, - &users[5], - &anchor, - 2, - appchain_message_nonce, - false, - ) - .await - .expect("Failed to switch era 2."); + complex_actions::switch_era(&users[5], &anchor, 2, appchain_message_nonce, false).await; // // // let result = council_keeper - .call(&worker, "get_living_appchain_ids") + .call("get_living_appchain_ids") .view() .await? .json::>() @@ -79,7 +59,7 @@ async fn test_sync_staking_amount() -> anyhow::Result<()> { ); // let result = council_keeper - .call(&worker, "get_council_members") + .call("get_council_members") .view() .await? .json::>() @@ -90,11 +70,11 @@ async fn test_sync_staking_amount() -> anyhow::Result<()> { ); // let result = council_keeper - .call(&worker, "get_ranked_validator_stakes") + .call("get_ranked_validator_stakes") .args_json(json!( { "start_index": 0, "quantity": null, - }))? + })) .view() .await? .json::>() @@ -105,11 +85,11 @@ async fn test_sync_staking_amount() -> anyhow::Result<()> { ); // let result = council_keeper - .call(&worker, "get_council_change_histories") + .call("get_council_change_histories") .args_json(json!( { "start_index": "0", "quantity": null, - }))? + })) .view() .await? .json::>() diff --git a/tests/simulator/test_transfer_native_near.rs b/tests/simulator/test_transfer_native_near.rs index d1a8b53..0fbe672 100644 --- a/tests/simulator/test_transfer_native_near.rs +++ b/tests/simulator/test_transfer_native_near.rs @@ -26,25 +26,36 @@ async fn test_transfer_native_near() -> anyhow::Result<()> { // // // - native_near_token::deploy_near_vault_contract(&worker, &users[0], &anchor) - .await - .expect_err("Should fail."); - // - root.call(&worker, anchor.id(), "store_wasm_of_near_vault_contract") + assert!( + native_near_token::deploy_near_vault_contract(&users[0], &anchor) + .await + .unwrap() + .is_failure() + ); + // + assert!(root + .call(anchor.id(), "store_wasm_of_near_vault_contract") .args(std::fs::read(format!("res/near_vault.wasm"))?) .gas(300_000_000_000_000) .deposit(parse_near!("2 N")) .transact() .await - .expect("Failed in calling 'store_wasm_of_near_vault_contract'."); + .unwrap() + .is_success()); // - native_near_token::deploy_near_vault_contract(&worker, &users[0], &anchor) - .await - .expect_err("Should fail."); + assert!( + native_near_token::deploy_near_vault_contract(&users[0], &anchor) + .await + .unwrap() + .is_failure() + ); // - native_near_token::deploy_near_vault_contract(&worker, &root, &anchor) - .await - .expect("Failed to deploy native near token receiver contract."); + assert!( + native_near_token::deploy_near_vault_contract(&root, &anchor) + .await + .unwrap() + .is_success() + ); // // // @@ -52,48 +63,53 @@ async fn test_transfer_native_near() -> anyhow::Result<()> { "0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d".to_string(); let receiver_account = AccountId::from_str(format!("near-vault.{}", anchor.id()).as_str()).unwrap(); - let old_balance = users[0].view_account(&worker).await?.balance; + let old_balance = users[0].view_account().await?.balance; println!("Balance of users[0]: {}", old_balance); - users[0] - .call(&worker, &receiver_account, "deposit_near_for_appchain_user") + assert!(users[0] + .call(&receiver_account, "deposit_near_for_appchain_user") .args_json(json!({ "receiver_id_in_appchain": user0_id_in_appchain, "near_amount": U128::from(parse_near!("1 N")), - }))? + })) .gas(200_000_000_000_000) .deposit(parse_near!("1 N")) .transact() .await - .expect("Failed in calling 'deposit_near_for_appchain_user'"); - let new_balance = users[0].view_account(&worker).await?.balance; + .unwrap() + .is_success()); + let new_balance = users[0].view_account().await?.balance; println!("Balance of users[0]: {}", new_balance); assert!(old_balance - new_balance > parse_near!("1 N")); - common::complex_viewer::print_appchain_notifications(&worker, &anchor).await?; + common::complex_viewer::print_appchain_notifications(&anchor).await; // // // - native_near_token::open_bridging_of_native_near_token(&worker, &root, &anchor) - .await - .expect("Failed to open bridging of native NEAR token."); + assert!( + native_near_token::open_bridging_of_native_near_token(&root, &anchor) + .await + .unwrap() + .is_success() + ); // - let old_balance = users[0].view_account(&worker).await?.balance; + let old_balance = users[0].view_account().await?.balance; println!("Balance of users[0]: {}", old_balance); - users[0] - .call(&worker, &receiver_account, "deposit_near_for_appchain_user") + assert!(users[0] + .call(&receiver_account, "deposit_near_for_appchain_user") .args_json(json!({ "receiver_id_in_appchain": user0_id_in_appchain, "near_amount": U128::from(parse_near!("1 N")), - }))? + })) .gas(200_000_000_000_000) .deposit(parse_near!("1 N")) .transact() .await - .expect("Failed in calling 'deposit_near_for_appchain_user'"); - let new_balance = users[0].view_account(&worker).await?.balance; + .unwrap() + .is_success()); + let new_balance = users[0].view_account().await?.balance; println!("Balance of users[0]: {}", new_balance); assert!(old_balance - new_balance > parse_near!("1 N")); - common::complex_viewer::print_appchain_notifications(&worker, &anchor).await?; - common::complex_viewer::print_native_near_token(&worker, &anchor).await?; + common::complex_viewer::print_appchain_notifications(&anchor).await; + common::complex_viewer::print_native_near_token(&anchor).await; // // // @@ -112,8 +128,7 @@ async fn test_transfer_native_near() -> anyhow::Result<()> { }; let mut raw_messages = Vec::new(); raw_messages.push(raw_message); - permissionless_actions::verify_and_stage_appchain_messages( - &worker, + assert!(permissionless_actions::verify_and_stage_appchain_messages( &users[5], &anchor, raw_messages.encode(), @@ -122,18 +137,19 @@ async fn test_transfer_native_near() -> anyhow::Result<()> { Vec::new(), ) .await - .expect("Failed to call 'verify_and_stage_appchain_messages'"); + .unwrap() + .is_success()); // - let old_balance = users[0].view_account(&worker).await?.balance; + let old_balance = users[0].view_account().await?.balance; println!("Balance of users[0]: {}", old_balance); - common::complex_actions::process_appchain_messages(&worker, &users[4], &anchor).await?; - let new_balance = users[0].view_account(&worker).await?.balance; + common::complex_actions::process_appchain_messages(&users[4], &anchor).await; + let new_balance = users[0].view_account().await?.balance; println!("Balance of users[0]: {}", new_balance); assert!(new_balance - old_balance == parse_near!("1 N")); - common::complex_viewer::print_appchain_messages(&worker, &anchor).await?; - common::complex_viewer::print_appchain_messages_processing_results(&worker, &anchor).await?; - common::complex_viewer::print_appchain_notifications(&worker, &anchor).await?; - common::complex_viewer::print_native_near_token(&worker, &anchor).await?; + common::complex_viewer::print_appchain_messages(&anchor).await; + common::complex_viewer::print_appchain_messages_processing_results(&anchor).await; + common::complex_viewer::print_appchain_notifications(&anchor).await; + common::complex_viewer::print_native_near_token(&anchor).await; // Ok(()) } diff --git a/tests/simulator/test_transfer_nft.rs b/tests/simulator/test_transfer_nft.rs index 2871530..446c837 100644 --- a/tests/simulator/test_transfer_nft.rs +++ b/tests/simulator/test_transfer_nft.rs @@ -35,8 +35,7 @@ async fn test_transfer_nft_to_near() -> anyhow::Result<()> { // // // - wrapped_appchain_nft_manager::register_wrapped_appchain_nft( - &worker, + assert!(wrapped_appchain_nft_manager::register_wrapped_appchain_nft( &users[0], &anchor, "nft_class1".to_string(), @@ -51,10 +50,10 @@ async fn test_transfer_nft_to_near() -> anyhow::Result<()> { }, ) .await - .expect_err("Should fail"); + .unwrap() + .is_failure()); // - wrapped_appchain_nft_manager::register_wrapped_appchain_nft( - &worker, + assert!(wrapped_appchain_nft_manager::register_wrapped_appchain_nft( &root, &anchor, "nft_class1".to_string(), @@ -69,23 +68,21 @@ async fn test_transfer_nft_to_near() -> anyhow::Result<()> { }, ) .await - .expect_err("Should fail"); + .unwrap() + .is_failure()); // - root.call( - &worker, - anchor.id(), - "store_wasm_of_wrapped_appchain_nft_contract", - ) - .args(std::fs::read(format!("res/wrapped_appchain_nft.wasm"))?) - .gas(300_000_000_000_000) - .deposit(parse_near!("30 N")) - .transact() - .await - .expect("Failed in calling 'store_wasm_of_wrapped_appchain_nft_contract'"); + assert!(root + .call(anchor.id(), "store_wasm_of_wrapped_appchain_nft_contract") + .args(std::fs::read(format!("res/wrapped_appchain_nft.wasm"))?) + .gas(300_000_000_000_000) + .deposit(parse_near!("30 N")) + .transact() + .await + .unwrap() + .is_success()); // let class_id = "1".to_string(); - wrapped_appchain_nft_manager::register_wrapped_appchain_nft( - &worker, + assert!(wrapped_appchain_nft_manager::register_wrapped_appchain_nft( &root, &anchor, class_id.clone(), @@ -100,7 +97,8 @@ async fn test_transfer_nft_to_near() -> anyhow::Result<()> { }, ) .await - .expect("Failed to register wrapped appchain nft"); + .unwrap() + .is_success()); // // // @@ -138,8 +136,7 @@ async fn test_transfer_nft_to_near() -> anyhow::Result<()> { }; let mut raw_messages = Vec::new(); raw_messages.push(raw_message); - permissionless_actions::verify_and_stage_appchain_messages( - &worker, + assert!(permissionless_actions::verify_and_stage_appchain_messages( &users[5], &anchor, raw_messages.encode(), @@ -148,16 +145,16 @@ async fn test_transfer_nft_to_near() -> anyhow::Result<()> { Vec::new(), ) .await - .expect("Failed to call 'verify_and_stage_appchain_messages'"); - common::complex_actions::process_appchain_messages(&worker, &users[4], &anchor).await?; - common::complex_viewer::print_appchain_messages(&worker, &anchor).await?; - common::complex_viewer::print_appchain_messages_processing_results(&worker, &anchor).await?; - common::complex_viewer::print_appchain_notifications(&worker, &anchor).await?; + .unwrap() + .is_success()); + common::complex_actions::process_appchain_messages(&users[4], &anchor).await; + common::complex_viewer::print_appchain_messages(&anchor).await; + common::complex_viewer::print_appchain_messages_processing_results(&anchor).await; + common::complex_viewer::print_appchain_notifications(&anchor).await; // // // let result = wrapped_appchain_nft_manager::open_bridging_of_wrapped_appchain_nft( - &worker, &root, &anchor, class_id.clone(), @@ -193,8 +190,7 @@ async fn test_transfer_nft_to_near() -> anyhow::Result<()> { }; let mut raw_messages = Vec::new(); raw_messages.push(raw_message); - permissionless_actions::verify_and_stage_appchain_messages( - &worker, + assert!(permissionless_actions::verify_and_stage_appchain_messages( &users[5], &anchor, raw_messages.encode(), @@ -203,17 +199,17 @@ async fn test_transfer_nft_to_near() -> anyhow::Result<()> { Vec::new(), ) .await - .expect("Failed to call 'verify_and_stage_appchain_messages'"); - common::complex_actions::process_appchain_messages(&worker, &users[4], &anchor).await?; - common::complex_viewer::print_appchain_messages(&worker, &anchor).await?; - common::complex_viewer::print_appchain_messages_processing_results(&worker, &anchor).await?; - common::complex_viewer::print_appchain_notifications(&worker, &anchor).await?; + .unwrap() + .is_success()); + common::complex_actions::process_appchain_messages(&users[4], &anchor).await; + common::complex_viewer::print_appchain_messages(&anchor).await; + common::complex_viewer::print_appchain_messages_processing_results(&anchor).await; + common::complex_viewer::print_appchain_notifications(&anchor).await; // // // - users[0] + assert!(users[0] .call( - &worker, &AccountId::from_str( format!("{}.{}", class_id.clone(), anchor.id().to_string()).as_str(), ) @@ -228,13 +224,14 @@ async fn test_transfer_nft_to_near() -> anyhow::Result<()> { "msg": serde_json::ser::to_string(&NFTTransferMessage::BridgeToAppchain { receiver_id_in_appchain: user0_id_in_appchain.clone(), }).unwrap(), - }))? + })) .gas(300_000_000_000_000) .deposit(1) .transact() .await - .expect("Failed to transfer nft"); - common::complex_viewer::print_appchain_notifications(&worker, &anchor).await?; + .unwrap() + .is_success()); + common::complex_viewer::print_appchain_notifications(&anchor).await; // // // @@ -267,8 +264,7 @@ async fn test_transfer_nft_to_near() -> anyhow::Result<()> { }; let mut raw_messages = Vec::new(); raw_messages.push(raw_message); - permissionless_actions::verify_and_stage_appchain_messages( - &worker, + assert!(permissionless_actions::verify_and_stage_appchain_messages( &users[5], &anchor, raw_messages.encode(), @@ -277,10 +273,11 @@ async fn test_transfer_nft_to_near() -> anyhow::Result<()> { Vec::new(), ) .await - .expect("Failed to call 'verify_and_stage_appchain_messages'"); - common::complex_actions::process_appchain_messages(&worker, &users[4], &anchor).await?; - common::complex_viewer::print_appchain_messages(&worker, &anchor).await?; - common::complex_viewer::print_appchain_messages_processing_results(&worker, &anchor).await?; - common::complex_viewer::print_appchain_notifications(&worker, &anchor).await?; + .unwrap() + .is_success()); + common::complex_actions::process_appchain_messages(&users[4], &anchor).await; + common::complex_viewer::print_appchain_messages(&anchor).await; + common::complex_viewer::print_appchain_messages_processing_results(&anchor).await; + common::complex_viewer::print_appchain_notifications(&anchor).await; Ok(()) } diff --git a/tests/simulator/test_transfer_oct_to_appchain.rs b/tests/simulator/test_transfer_oct_to_appchain.rs index 84b863b..6ac04db 100644 --- a/tests/simulator/test_transfer_oct_to_appchain.rs +++ b/tests/simulator/test_transfer_oct_to_appchain.rs @@ -8,8 +8,7 @@ async fn test_transfer_oct_to_appchain() -> anyhow::Result<()> { let (root, oct_token, _, _registry, _council, anchor, _wat_faucet, users, _) = common::test_normal_actions(&worker, false, false, vec!["0x00".to_string()]).await?; // - near_fungible_token_manager::register_near_fungible_token( - &worker, + assert!(near_fungible_token_manager::register_near_fungible_token( &root, &anchor, "OCT".to_string(), @@ -19,11 +18,11 @@ async fn test_transfer_oct_to_appchain() -> anyhow::Result<()> { U128::from(1000000), ) .await - .expect("Failed to register NEAR fungible token"); - common::complex_viewer::print_near_fungible_tokens(&worker, &anchor).await?; + .unwrap() + .is_success()); + common::complex_viewer::print_near_fungible_tokens(&anchor).await; // - common::call_ft_transfer_call( - &worker, + assert!(common::call_ft_transfer_call( &users[0], &anchor.as_account(), common::to_actual_amount(200, 18), @@ -34,7 +33,7 @@ async fn test_transfer_oct_to_appchain() -> anyhow::Result<()> { }) .to_string(), &oct_token, - ).await?; - common::complex_viewer::print_appchain_notifications(&worker, &anchor).await?; + ).await.unwrap().is_success()); + common::complex_viewer::print_appchain_notifications(&anchor).await; Ok(()) } diff --git a/tests/simulator/test_wrapped_appchain_token.rs b/tests/simulator/test_wrapped_appchain_token.rs index 4b5789d..56ef6b6 100644 --- a/tests/simulator/test_wrapped_appchain_token.rs +++ b/tests/simulator/test_wrapped_appchain_token.rs @@ -34,8 +34,7 @@ async fn test_wrapped_appchain_token_bridging() -> anyhow::Result<()> { // // Mint wrapped appchain token for user1 (error) // - let user1_wat_balance = - common::get_ft_balance_of(&worker, &users[1], &wrapped_appchain_token).await?; + let user1_wat_balance = common::get_ft_balance_of(&users[1], &wrapped_appchain_token).await?; appchain_message_nonce += 1; let payload = LockPayload { sender: user4_id_in_appchain.clone(), @@ -50,8 +49,7 @@ async fn test_wrapped_appchain_token_bridging() -> anyhow::Result<()> { }; let mut raw_messages = Vec::new(); raw_messages.push(raw_message); - permissionless_actions::verify_and_stage_appchain_messages( - &worker, + assert!(permissionless_actions::verify_and_stage_appchain_messages( &users[5], &anchor, raw_messages.encode(), @@ -60,15 +58,14 @@ async fn test_wrapped_appchain_token_bridging() -> anyhow::Result<()> { Vec::new(), ) .await - .expect("Failed to call 'verify_and_stage_appchain_messages'"); - common::complex_actions::process_appchain_messages(&worker, &users[4], &anchor) - .await - .expect("Failed to call 'process_appchain_messages'"); - common::complex_viewer::print_appchain_messages(&worker, &anchor).await?; - common::complex_viewer::print_appchain_messages_processing_results(&worker, &anchor).await?; - common::complex_viewer::print_appchain_notifications(&worker, &anchor).await?; + .unwrap() + .is_success()); + common::complex_actions::process_appchain_messages(&users[4], &anchor).await; + common::complex_viewer::print_appchain_messages(&anchor).await; + common::complex_viewer::print_appchain_messages_processing_results(&anchor).await; + common::complex_viewer::print_appchain_notifications(&anchor).await; assert_eq!( - common::get_ft_balance_of(&worker, &users[1], &wrapped_appchain_token) + common::get_ft_balance_of(&users[1], &wrapped_appchain_token) .await? .0, user1_wat_balance.0 @@ -77,7 +74,6 @@ async fn test_wrapped_appchain_token_bridging() -> anyhow::Result<()> { // Burn wrapped appchain token from user0 // let result = wrapped_appchain_token_manager::burn_wrapped_appchain_token( - &worker, &users[0], &anchor, user0_id_in_appchain, @@ -87,13 +83,12 @@ async fn test_wrapped_appchain_token_bridging() -> anyhow::Result<()> { .expect("Failed to call 'burn_wrapped_appchain_token'"); println!("Result of 'burn_wrapped_appchain_token': {:?}", result); assert!(result.is_success()); - common::complex_viewer::print_appchain_notifications(&worker, &anchor).await?; - common::complex_viewer::print_wrapped_appchain_token_info(&worker, &anchor).await?; + common::complex_viewer::print_appchain_notifications(&anchor).await; + common::complex_viewer::print_wrapped_appchain_token_info(&anchor).await; // // Mint wrapped appchain token for user1 // - let user1_wat_balance = - common::get_ft_balance_of(&worker, &users[1], &wrapped_appchain_token).await?; + let user1_wat_balance = common::get_ft_balance_of(&users[1], &wrapped_appchain_token).await?; let mut raw_messages = Vec::new(); // appchain_message_nonce += 1; @@ -272,8 +267,7 @@ async fn test_wrapped_appchain_token_bridging() -> anyhow::Result<()> { }; raw_messages.push(raw_message); // - permissionless_actions::verify_and_stage_appchain_messages( - &worker, + assert!(permissionless_actions::verify_and_stage_appchain_messages( &users[5], &anchor, raw_messages.encode(), @@ -282,16 +276,15 @@ async fn test_wrapped_appchain_token_bridging() -> anyhow::Result<()> { Vec::new(), ) .await - .expect("Failed to call 'verify_and_stage_appchain_messages'"); - common::complex_actions::process_appchain_messages(&worker, &users[3], &anchor) - .await - .expect("Failed to call 'process_appchain_messages'"); - common::complex_viewer::print_appchain_messages(&worker, &anchor).await?; - common::complex_viewer::print_appchain_messages_processing_results(&worker, &anchor).await?; - common::complex_viewer::print_appchain_notifications(&worker, &anchor).await?; - common::complex_viewer::print_wrapped_appchain_token_info(&worker, &anchor).await?; + .unwrap() + .is_success()); + common::complex_actions::process_appchain_messages(&users[3], &anchor).await; + common::complex_viewer::print_appchain_messages(&anchor).await; + common::complex_viewer::print_appchain_messages_processing_results(&anchor).await; + common::complex_viewer::print_appchain_notifications(&anchor).await; + common::complex_viewer::print_wrapped_appchain_token_info(&anchor).await; assert_eq!( - common::get_ft_balance_of(&worker, &users[1], &wrapped_appchain_token) + common::get_ft_balance_of(&users[1], &wrapped_appchain_token) .await? .0, user1_wat_balance.0 + common::to_actual_amount(515, 18) @@ -358,8 +351,7 @@ async fn test_wrapped_appchain_token_bridging() -> anyhow::Result<()> { }; raw_messages.push(raw_message); // - permissionless_actions::verify_and_stage_appchain_messages( - &worker, + assert!(permissionless_actions::verify_and_stage_appchain_messages( &users[5], &anchor, raw_messages.encode(), @@ -368,11 +360,10 @@ async fn test_wrapped_appchain_token_bridging() -> anyhow::Result<()> { Vec::new(), ) .await - .expect("Failed to call 'verify_and_stage_appchain_messages'"); - common::complex_actions::process_appchain_messages(&worker, &users[3], &anchor) - .await - .expect("Failed to call 'process_appchain_messages'"); - common::complex_viewer::print_appchain_messages(&worker, &anchor).await?; - common::complex_viewer::print_appchain_messages_processing_results(&worker, &anchor).await?; + .unwrap() + .is_success()); + common::complex_actions::process_appchain_messages(&users[3], &anchor).await; + common::complex_viewer::print_appchain_messages(&anchor).await; + common::complex_viewer::print_appchain_messages_processing_results(&anchor).await; Ok(()) } From 00bec3ac7e8788566771e4f1658e2965c27aab0b Mon Sep 17 00:00:00 2001 From: Rivers Yang Date: Wed, 9 Nov 2022 22:53:50 +0800 Subject: [PATCH 09/15] Update version. --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- appchain-anchor/Cargo.toml | 2 +- appchain-anchor/src/lib.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f13f57c..979242b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -60,7 +60,7 @@ checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" [[package]] name = "appchain-anchor" -version = "2.4.0" +version = "2.5.0" dependencies = [ "beefy-light-client", "ed25519-dalek", @@ -73,7 +73,7 @@ dependencies = [ [[package]] name = "appchain-anchor-wrapper" -version = "2.4.1" +version = "2.5.0" dependencies = [ "anyhow", "appchain-anchor", diff --git a/Cargo.toml b/Cargo.toml index c706c20..8d418d5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "appchain-anchor-wrapper" -version = "2.4.1" +version = "2.5.0" authors = ["Octopus Network"] edition = "2021" diff --git a/appchain-anchor/Cargo.toml b/appchain-anchor/Cargo.toml index 6255bd5..7c83149 100644 --- a/appchain-anchor/Cargo.toml +++ b/appchain-anchor/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "appchain-anchor" -version = "2.4.0" +version = "2.5.0" authors = ["Octopus Network"] edition = "2021" diff --git a/appchain-anchor/src/lib.rs b/appchain-anchor/src/lib.rs index d39aa38..f54203b 100644 --- a/appchain-anchor/src/lib.rs +++ b/appchain-anchor/src/lib.rs @@ -50,7 +50,7 @@ use validator_set::validator_set_of_era::ValidatorSetOfEra; use validator_set::ValidatorSetViewer; /// Version of this contract (the same as in Cargo.toml) -const ANCHOR_VERSION: &str = "v2.4.1"; +const ANCHOR_VERSION: &str = "v2.5.0"; /// Constants for gas. const T_GAS_FOR_FT_TRANSFER: u64 = 10; const T_GAS_FOR_BURN_FUNGIBLE_TOKEN: u64 = 10; From 54017f4b004f0f19c3b8853eb7bb8d8e08baee79 Mon Sep 17 00:00:00 2001 From: Rivers Yang Date: Mon, 28 Nov 2022 15:36:11 +0800 Subject: [PATCH 10/15] Fix errors after rebase to `v2.4.0`. --- Cargo.lock | 331 ++++++++++++++++++++++++------------- appchain-anchor/src/lib.rs | 7 +- 2 files changed, 219 insertions(+), 119 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 979242b..34a74b2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -36,9 +36,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "0.7.19" +version = "0.7.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" +checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" dependencies = [ "memchr", ] @@ -129,20 +129,20 @@ version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e14485364214912d3b19cc3435dde4df66065127f05fa0d75c712f36f12c2f28" dependencies = [ - "concurrent-queue", + "concurrent-queue 1.2.4", "event-listener", "futures-core", ] [[package]] name = "async-io" -version = "1.10.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8121296a9f05be7f34aa4196b1747243b3b62e048bb7906f644f3fbfc490cf7" +checksum = "8c374dda1ed3e7d8f0d9ba58715f924862c63eae6849c92d3a18e7fbde9e2794" dependencies = [ "async-lock", "autocfg", - "concurrent-queue", + "concurrent-queue 2.0.0", "futures-lite", "libc", "log", @@ -151,7 +151,7 @@ dependencies = [ "slab", "socket2", "waker-fn", - "winapi", + "windows-sys 0.42.0", ] [[package]] @@ -166,20 +166,20 @@ dependencies = [ [[package]] name = "async-process" -version = "1.5.0" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02111fd8655a613c25069ea89fc8d9bb89331fa77486eb3bc059ee757cfa481c" +checksum = "6381ead98388605d0d9ff86371043b5aa922a3905824244de40dc263a14fcba4" dependencies = [ "async-io", + "async-lock", "autocfg", "blocking", "cfg-if 1.0.0", "event-listener", "futures-lite", "libc", - "once_cell", "signal-hook", - "winapi", + "windows-sys 0.42.0", ] [[package]] @@ -221,7 +221,7 @@ dependencies = [ "cc", "cfg-if 1.0.0", "libc", - "miniz_oxide", + "miniz_oxide 0.5.4", "object", "rustc-demangle", ] @@ -305,7 +305,7 @@ dependencies = [ "funty 2.0.0", "radium 0.7.0", "tap", - "wyz 0.5.0", + "wyz 0.5.1", ] [[package]] @@ -360,16 +360,16 @@ dependencies = [ [[package]] name = "blocking" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6ccb65d468978a086b69884437ded69a90faab3bbe6e67f242173ea728acccc" +checksum = "3c67b173a56acffd6d2326fb7ab938ba0b00a71480e14902b2591c87bc5741e8" dependencies = [ "async-channel", + "async-lock", "async-task", "atomic-waker", "fastrand", "futures-lite", - "once_cell", ] [[package]] @@ -443,9 +443,9 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "bytes" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" +checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c" [[package]] name = "bytesize" @@ -492,9 +492,9 @@ checksum = "c1db59621ec70f09c5e9b597b220c7a2b43611f4710dc03ceb8748637775692c" [[package]] name = "cc" -version = "1.0.76" +version = "1.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76a284da2e6fe2092f2353e51713435363112dfd60030e22add80be333fb928f" +checksum = "e9f73505338f7d905b19d18738976aae232eb46b8efc15554ffc56deb5d9ebe4" [[package]] name = "cfg-if" @@ -510,9 +510,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.22" +version = "0.4.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfd4d1b31faaa3a89d7934dbded3111da0d2ef28e3ebccdb4f0179f5929d1ef1" +checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f" dependencies = [ "iana-time-zone", "js-sys", @@ -561,6 +561,15 @@ dependencies = [ "cache-padded", ] +[[package]] +name = "concurrent-queue" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd7bef69dc86e3c610e4e7aed41035e2a7ed12e72dd7530f61327a6579a4390b" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "constant_time_eq" version = "0.1.5" @@ -618,9 +627,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.12" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edbafec5fa1f196ca66527c1b12c2ec4745ca14b50f1ad8f9f6f720b55d11fac" +checksum = "4fb766fa798726286dbbb842f174001dab8abc7b627a1dd86e0b7222a95d929f" dependencies = [ "cfg-if 1.0.0", ] @@ -696,9 +705,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.81" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97abf9f0eca9e52b7f81b945524e76710e6cb2366aead23b7d4fbf72e281f888" +checksum = "d4a41a86530d0fe7f5d9ea779916b7cadd2d4f9add748b99c2c029cbbdfaf453" dependencies = [ "cc", "cxxbridge-flags", @@ -708,9 +717,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.81" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cc32cc5fea1d894b77d269ddb9f192110069a8a9c1f1d441195fba90553dea3" +checksum = "06416d667ff3e3ad2df1cd8cd8afae5da26cf9cec4d0825040f88b5ca659a2f0" dependencies = [ "cc", "codespan-reporting", @@ -723,15 +732,15 @@ dependencies = [ [[package]] name = "cxxbridge-flags" -version = "1.0.81" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ca220e4794c934dc6b1207c3b42856ad4c302f2df1712e9f8d2eec5afaacf1f" +checksum = "820a9a2af1669deeef27cb271f476ffd196a2c4b6731336011e0ba63e2c7cf71" [[package]] name = "cxxbridge-macro" -version = "1.0.81" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b846f081361125bfc8dc9d3940c84e1fd83ba54bbca7b17cd29483c828be0704" +checksum = "a08a6e2fcc370a089ad3b4aaf54db3b1b4cee38ddabce5896b33eb693275f470" dependencies = [ "proc-macro2", "quote", @@ -762,9 +771,9 @@ dependencies = [ [[package]] name = "digest" -version = "0.10.5" +version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adfbc57365a37acbd2ebf2b64d7e69bb766e2fea813521ed536f5d0520dcf86c" +checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" dependencies = [ "block-buffer 0.10.3", "crypto-common", @@ -801,6 +810,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "dyn-clone" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f94fa09c2aeea5b8839e414b7b841bf429fd25b9c522116ac97ee87856d88b2" + [[package]] name = "easy-ext" version = "0.2.9" @@ -902,12 +917,12 @@ dependencies = [ [[package]] name = "flate2" -version = "1.0.24" +version = "1.0.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f82b0f4c27ad9f8bfd1f3208d882da2b09c301bc1c828fd3a00d0216d2fbbff6" +checksum = "a8a2db397cb1c8772f31494cb8917e48cd1e64f0fa7efac59fbd741a0a8ce841" dependencies = [ "crc32fast", - "miniz_oxide", + "miniz_oxide 0.6.2", ] [[package]] @@ -1274,9 +1289,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.9.1" +version = "1.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" +checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" dependencies = [ "autocfg", "hashbrown 0.12.3", @@ -1323,15 +1338,21 @@ dependencies = [ [[package]] name = "keccak" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9b7d56ba4a8344d6be9729995e6b06f928af29998cdf79fe390cbf6b1fee838" +checksum = "3afef3b6eff9ce9d8ff9b3601125eec7f0c8cbac7abd14f355d053fa56c98768" +dependencies = [ + "cpufeatures", +] [[package]] name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +dependencies = [ + "spin", +] [[package]] name = "libc" @@ -1458,6 +1479,15 @@ dependencies = [ "adler", ] +[[package]] +name = "miniz_oxide" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa" +dependencies = [ + "adler", +] + [[package]] name = "mio" version = "0.8.5" @@ -1504,6 +1534,18 @@ dependencies = [ "tempfile", ] +[[package]] +name = "near-abi" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "885db39b08518fa700b73fa2214e8adbbfba316ba82dd510f50519173eadaf73" +dependencies = [ + "borsh", + "schemars", + "semver", + "serde", +] + [[package]] name = "near-account-id" version = "0.5.0" @@ -1516,9 +1558,9 @@ dependencies = [ [[package]] name = "near-account-id" -version = "0.13.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de83d74a9241be8cc4eb3055216966b58bf8c463e8e285c0dc553925acdd19fa" +checksum = "71d258582a1878e6db67400b0504a5099db85718d22c2e07f747fe1706ae7150" dependencies = [ "borsh", "serde", @@ -1555,11 +1597,12 @@ dependencies = [ [[package]] name = "near-contract-standards" -version = "4.0.0" +version = "4.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6466c6aaad18800ff6a3cd104427dc8fd79e144714135224b8289b1dc43f7167" +checksum = "7bacc932e79b26472797adfb21689294b6f90960d1570daaf1e0b682b59fcb35" dependencies = [ "near-sdk", + "schemars", "serde", "serde_json", ] @@ -1593,9 +1636,9 @@ dependencies = [ [[package]] name = "near-crypto" -version = "0.13.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8ecf0b8b31aa7f4e60f629f72213a2617ca4a5f45cd1ae9ed2cf7cecfebdbb7" +checksum = "1e75673d69fd7365508f3d32483669fe45b03bfb34e4d9363e90adae9dfb416c" dependencies = [ "arrayref", "blake2", @@ -1605,8 +1648,7 @@ dependencies = [ "curve25519-dalek", "derive_more", "ed25519-dalek", - "libc", - "near-account-id 0.13.0", + "near-account-id 0.14.0", "once_cell", "parity-secp256k1", "primitive-types", @@ -1645,9 +1687,9 @@ dependencies = [ [[package]] name = "near-jsonrpc-client" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "384356f354bdf85d0ece627c6af6f38febb5406a4ffb32c5d75429b1a1472e29" +checksum = "d1335ffce1476da6516dcd22b26cece1a495fc725c0e8fec1879073752ac068d" dependencies = [ "borsh", "lazy_static", @@ -1711,9 +1753,9 @@ dependencies = [ [[package]] name = "near-primitives" -version = "0.13.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a2ba19282e79a4485a77736b679d276b09870bbf8042a18e0f0ae36347489c5" +checksum = "8ad1a9a1640539c81f065425c31bffcfbf6b31ef1aeaade59ce905f5df6ac860" dependencies = [ "borsh", "byteorder", @@ -1722,10 +1764,10 @@ dependencies = [ "derive_more", "easy-ext", "hex 0.4.3", - "near-crypto 0.13.0", - "near-primitives-core 0.13.0", - "near-rpc-error-macro 0.13.0", - "near-vm-errors 0.13.0", + "near-crypto 0.14.0", + "near-primitives-core 0.14.0", + "near-rpc-error-macro 0.14.0", + "near-vm-errors 0.14.0", "num-rational", "once_cell", "primitive-types", @@ -1789,15 +1831,15 @@ dependencies = [ [[package]] name = "near-primitives-core" -version = "0.13.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb561feb392bb8c4f540256073446e6689af087bf6356e8dddcf75fc279f201f" +checksum = "91d508f0fc340f6461e4e256417685720d3c4c00bb5a939b105160e49137caba" dependencies = [ "base64 0.11.0", "borsh", "bs58", "derive_more", - "near-account-id 0.13.0", + "near-account-id 0.14.0", "num-rational", "serde", "sha2 0.10.6", @@ -1836,9 +1878,9 @@ dependencies = [ [[package]] name = "near-rpc-error-core" -version = "0.13.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77fdd7ea8d8f786878651c37691515d5053f827ae60894aa40c16882b78f77c9" +checksum = "93ee0b41c75ef859c193a8ff1dadfa0c8207bc0ac447cc22259721ad769a1408" dependencies = [ "quote", "serde", @@ -1872,11 +1914,11 @@ dependencies = [ [[package]] name = "near-rpc-error-macro" -version = "0.13.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e521842b6ae864dfe5391afbbe2df9e9d8427c26e9333b2e0b65cd42094f7607" +checksum = "8e837bd4bacd807073ec5ceb85708da7f721b46a4c2a978de86027fb0034ce31" dependencies = [ - "near-rpc-error-core 0.13.0", + "near-rpc-error-core 0.14.0", "serde", "syn", ] @@ -1894,9 +1936,9 @@ dependencies = [ [[package]] name = "near-sandbox-utils" -version = "0.6.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201b7e0c5fcff633fb53e743b16c6aea4110e531764ccaa215ea1382db940b45" +checksum = "a4b2da180a368a12da1949e9940af2457cbce83acb85743b8834b6c9b4111e9f" dependencies = [ "anyhow", "async-process", @@ -1909,19 +1951,22 @@ dependencies = [ [[package]] name = "near-sdk" -version = "4.0.0" +version = "4.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda34e06e28fb9a09ac54efbdc49f0c9308780fc932aaa81c49c493fde974045" +checksum = "15eb3de2defe3626260cc209a6cdb985c6b27b0bd4619fad97dcfae002c3c5bd" dependencies = [ "base64 0.13.1", "borsh", "bs58", - "near-crypto 0.13.0", - "near-primitives 0.13.0", - "near-primitives-core 0.13.0", + "near-abi", + "near-crypto 0.14.0", + "near-primitives 0.14.0", + "near-primitives-core 0.14.0", "near-sdk-macros", "near-sys", "near-vm-logic", + "once_cell", + "schemars", "serde", "serde_json", "wee_alloc", @@ -1929,9 +1974,9 @@ dependencies = [ [[package]] name = "near-sdk-macros" -version = "4.0.0" +version = "4.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72064fcc15a623a0d40a6c199ea5cbdc30a83cae4816889d46f218acf31bfba8" +checksum = "4907affc9f5ed559456509188ff0024f1f2099c0830e6bdb66eb61d5b75912c0" dependencies = [ "Inflector", "proc-macro2", @@ -1987,13 +2032,13 @@ dependencies = [ [[package]] name = "near-vm-errors" -version = "0.13.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e02faf2bc1f6ef82b965cfe44389808fb5594f7aca4b596766117f4ce74df20" +checksum = "d0da466a30f0446639cbd788c30865086fac3e8dcb07a79e51d2b0775ed4261e" dependencies = [ "borsh", - "near-account-id 0.13.0", - "near-rpc-error-macro 0.13.0", + "near-account-id 0.14.0", + "near-rpc-error-macro 0.14.0", "serde", ] @@ -2025,23 +2070,24 @@ dependencies = [ [[package]] name = "near-vm-logic" -version = "0.13.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f024d90451cd3c24d7a0a5cabf3636b192a60eb8e3ff0456f6c18b91152c346d" +checksum = "81b534828419bacbf1f7b11ef7b00420f248c548c485d3f0cfda8bb6931152f2" dependencies = [ "base64 0.13.1", "borsh", "bs58", "byteorder", - "near-account-id 0.13.0", - "near-crypto 0.13.0", - "near-primitives 0.13.0", - "near-primitives-core 0.13.0", - "near-vm-errors 0.13.0", + "near-account-id 0.14.0", + "near-crypto 0.14.0", + "near-primitives 0.14.0", + "near-primitives-core 0.14.0", + "near-vm-errors 0.14.0", "ripemd", "serde", "sha2 0.10.6", "sha3", + "zeropool-bn", ] [[package]] @@ -2136,9 +2182,9 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "openssl" -version = "0.10.42" +version = "0.10.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12fc0523e3bd51a692c8850d075d74dc062ccf251c0110668cbd921917118a13" +checksum = "020433887e44c27ff16365eaa2d380547a94544ad509aff6eb5b6e3e0b27b376" dependencies = [ "bitflags", "cfg-if 1.0.0", @@ -2168,9 +2214,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.77" +version = "0.9.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b03b84c3b2d099b81f0953422b4d4ad58761589d0229b5506356afca05a3670a" +checksum = "07d5c8cb6e57b3a3612064d7b18b117912b4ce70955c2504d4b741c9e244b132" dependencies = [ "autocfg", "cc", @@ -2318,16 +2364,16 @@ checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" [[package]] name = "polling" -version = "2.4.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab4609a838d88b73d8238967b60dd115cc08d38e2bbaf51ee1e4b695f89122e2" +checksum = "9f7d73f1eaed1ca1fb37b54dcc9b38e3b17d6c7b8ecb7abfffcac8d0351f17d4" dependencies = [ "autocfg", "cfg-if 1.0.0", "libc", "log", "wepoll-ffi", - "winapi", + "windows-sys 0.42.0", ] [[package]] @@ -2551,9 +2597,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.12" +version = "0.11.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "431949c384f4e2ae07605ccaa56d1d9d2ecdb5cadd4f9577ccfab29f2e5149fc" +checksum = "68cc60575865c7831548863cc02356512e3f1dc2f3f82cb837d7fc4cc8f3c97c" dependencies = [ "base64 0.13.1", "bytes", @@ -2592,7 +2638,7 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd124222d17ad93a644ed9d011a40f4fb64aa54275c08cc216524a9ea82fb09f" dependencies = [ - "digest 0.10.5", + "digest 0.10.6", ] [[package]] @@ -2674,6 +2720,30 @@ dependencies = [ "windows-sys 0.36.1", ] +[[package]] +name = "schemars" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a5fb6c61f29e723026dc8e923d94c694313212abbecbbe5f55a7748eec5b307" +dependencies = [ + "dyn-clone", + "schemars_derive", + "serde", + "serde_json", +] + +[[package]] +name = "schemars_derive" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f188d036977451159430f3b8dc82ec76364a42b7e289c2b18a9a18f4470058e9" +dependencies = [ + "proc-macro2", + "quote", + "serde_derive_internals", + "syn", +] + [[package]] name = "scopeguard" version = "1.1.0" @@ -2736,18 +2806,29 @@ checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4" [[package]] name = "serde" -version = "1.0.147" +version = "1.0.148" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965" +checksum = "e53f64bb4ba0191d6d0676e1b141ca55047d83b74f5607e6d8eb88126c52c2dc" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.147" +version = "1.0.148" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852" +checksum = "a55492425aa53521babf6137309e7d34c20bbfbbfcfe2c7f3a047fd1f6b92c0c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_derive_internals" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c" dependencies = [ "proc-macro2", "quote", @@ -2756,9 +2837,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.87" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ce777b7b150d76b9cf60d28b55f5847135a003f7d7350c6be7a773508ce7d45" +checksum = "020ff22c755c2ed3f8cf162dbb41a7268d934702f3ed3631656ea597e08fc3db" dependencies = [ "indexmap", "itoa", @@ -2810,7 +2891,7 @@ checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" dependencies = [ "cfg-if 1.0.0", "cpufeatures", - "digest 0.10.5", + "digest 0.10.6", ] [[package]] @@ -2819,7 +2900,7 @@ version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bdf0c33fae925bdc080598b84bc15c55e7b9a4a43b3c704da051f977469691c9" dependencies = [ - "digest 0.10.5", + "digest 0.10.6", "keccak", ] @@ -2890,6 +2971,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + [[package]] name = "static_assertions" version = "1.1.0" @@ -2926,9 +3013,9 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" -version = "1.0.103" +version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" +checksum = "4ae548ec36cf198c0ef7710d3c230987c2d6d7bd98ad6edc0274462724c585ce" dependencies = [ "proc-macro2", "quote", @@ -3009,9 +3096,9 @@ dependencies = [ [[package]] name = "time" -version = "0.1.44" +version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" dependencies = [ "libc", "wasi 0.10.0+wasi-snapshot-preview1", @@ -3044,9 +3131,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.21.2" +version = "1.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e03c497dc955702ba729190dc4aac6f2a0ce97f913e5b1b5912fc5039d9099" +checksum = "d76ce4a75fb488c605c54bf610f221cea8b0dafb53333c1a67e8ee199dcd2ae3" dependencies = [ "autocfg", "bytes", @@ -3226,9 +3313,9 @@ dependencies = [ [[package]] name = "uuid" -version = "1.2.1" +version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "feb41e78f93363bb2df8b0e86a2ca30eed7806ea16ea0c790d757cf93f79be83" +checksum = "422ee0de9031b5b948b97a8fc04e3aa35230001a722ddd27943e0be31564ce4c" dependencies = [ "getrandom 0.2.8", ] @@ -3548,9 +3635,9 @@ dependencies = [ [[package]] name = "workspaces" -version = "0.6.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbc74416d48b2deb83004a0fff9d856e46a026c156da4acc4feca044a0a33755" +checksum = "1f54d9286e6dc20dd6d7676de27ace7b0d4f755164fe14c1f07bcbdd08d54052" dependencies = [ "async-process", "async-trait", @@ -3605,9 +3692,9 @@ checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214" [[package]] name = "wyz" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30b31594f29d27036c383b53b59ed3476874d518f0efb151b27a4c275141390e" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" dependencies = [ "tap", ] @@ -3642,6 +3729,20 @@ dependencies = [ "synstructure", ] +[[package]] +name = "zeropool-bn" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71e61de68ede9ffdd69c01664f65a178c5188b73f78faa21f0936016a888ff7c" +dependencies = [ + "borsh", + "byteorder", + "crunchy", + "lazy_static", + "rand 0.8.5", + "rustc-hex", +] + [[package]] name = "zip" version = "0.5.13" diff --git a/appchain-anchor/src/lib.rs b/appchain-anchor/src/lib.rs index f54203b..899fa13 100644 --- a/appchain-anchor/src/lib.rs +++ b/appchain-anchor/src/lib.rs @@ -18,7 +18,6 @@ mod validator_set; use core::convert::TryInto; use near_contract_standards::non_fungible_token::metadata::TokenMetadata; use near_contract_standards::non_fungible_token::TokenId; -use near_contract_standards::upgrade::Ownable; use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize}; use near_sdk::collections::{LazyOption, LookupMap, UnorderedSet}; use near_sdk::json_types::{U128, U64}; @@ -466,13 +465,13 @@ impl AppchainAnchor { } #[near_bindgen] -impl Ownable for AppchainAnchor { +impl AppchainAnchor { // - fn get_owner(&self) -> AccountId { + pub fn get_owner(&self) -> AccountId { self.owner.clone() } // - fn set_owner(&mut self, owner: AccountId) { + pub fn set_owner(&mut self, owner: AccountId) { self.assert_owner(); assert!(!owner.eq(&self.owner), "Owner is not changed.",); self.owner = owner; From 5bfe4db1377401b002294b32a76b3181036fd5dc Mon Sep 17 00:00:00 2001 From: Rivers Yang Date: Mon, 5 Dec 2022 16:09:26 +0800 Subject: [PATCH 11/15] Add log in function `internal_stage_appchain_messages`. --- appchain-anchor/src/appchain_messages.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/appchain-anchor/src/appchain_messages.rs b/appchain-anchor/src/appchain_messages.rs index 9723dcb..b4fc422 100644 --- a/appchain-anchor/src/appchain_messages.rs +++ b/appchain-anchor/src/appchain_messages.rs @@ -82,7 +82,8 @@ pub enum MessagePayload { LockNft(LockNftPayload), } -#[derive(Encode, Decode, Clone)] +#[derive(Encode, Decode, Clone, Serialize, Deserialize)] +#[serde(crate = "near_sdk::serde")] pub struct RawMessage { #[codec(compact)] pub nonce: u64, @@ -265,6 +266,10 @@ impl AppchainAnchor { message.nonce as u32 > processing_status.latest_applied_appchain_message_nonce }) .for_each(|raw_message| { + log!( + "Received message: {}", + serde_json::to_string(raw_message).unwrap() + ); self.internal_stage_raw_message(&mut appchain_messages, raw_message) }); self.appchain_messages.set(&appchain_messages); From eb3cbaf66597110919b0b78efeda1d7cec83393a Mon Sep 17 00:00:00 2001 From: Rivers Yang Date: Mon, 12 Dec 2022 14:20:47 +0800 Subject: [PATCH 12/15] Change authority for function `change_minimum_validator_deposit`. --- appchain-anchor/src/lib.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/appchain-anchor/src/lib.rs b/appchain-anchor/src/lib.rs index 899fa13..c0bca43 100644 --- a/appchain-anchor/src/lib.rs +++ b/appchain-anchor/src/lib.rs @@ -320,7 +320,7 @@ impl AppchainAnchor { assert_eq!( env::predecessor_account_id(), self.owner, - "Function can only be called by owner." + "This function can only be called by owner." ); } // Assert that the function is called by appchain registry. @@ -332,6 +332,14 @@ impl AppchainAnchor { ); } // + fn assert_registry(&self) { + assert_eq!( + env::predecessor_account_id(), + self.appchain_registry, + "This function can only be called by appchain registry contract." + ) + } + // fn assert_token_price_maintainer(&self) { let anchor_settings = self.anchor_settings.get().unwrap(); let token_price_maintainer_account = anchor_settings From b4ce3ec1cb1ea2fb57df6951757a92ba1aefbb94 Mon Sep 17 00:00:00 2001 From: Rivers Yang Date: Tue, 13 Dec 2022 14:55:25 +0800 Subject: [PATCH 13/15] Optimize implementation for validator set cleaning. --- appchain-anchor/src/lookup_array.rs | 5 ++ appchain-anchor/src/validator_set/mod.rs | 14 +++--- .../src/validator_set/validator_set_of_era.rs | 50 +++++++++++++++++-- 3 files changed, 59 insertions(+), 10 deletions(-) diff --git a/appchain-anchor/src/lookup_array.rs b/appchain-anchor/src/lookup_array.rs index bbd1733..5442f42 100644 --- a/appchain-anchor/src/lookup_array.rs +++ b/appchain-anchor/src/lookup_array.rs @@ -152,6 +152,11 @@ where match result { MultiTxsOperationProcessingResult::Ok => { self.lookup_map.remove_raw(&index.try_to_vec().unwrap()); + if *index == self.start_index && *index < self.end_index { + self.start_index += 1; + } else if *index == self.end_index && *index > self.start_index { + self.end_index -= 1; + } } MultiTxsOperationProcessingResult::NeedMoreGas => { self.lookup_map.insert(index, &record); diff --git a/appchain-anchor/src/validator_set/mod.rs b/appchain-anchor/src/validator_set/mod.rs index e0b9761..9e108cd 100644 --- a/appchain-anchor/src/validator_set/mod.rs +++ b/appchain-anchor/src/validator_set/mod.rs @@ -130,19 +130,21 @@ impl ValidatorSet { validator_id_set_of_delegator.clear(); self.delegator_id_to_validator_id_set.remove(&delegator_id); } + delegator_id_set.remove(&delegator_id); if env::used_gas() > Gas::ONE_TERA.mul(T_GAS_CAP_FOR_MULTI_TXS_PROCESSING) { + self.validator_id_to_delegator_id_set + .insert(&validator_id, &delegator_id_set); return MultiTxsOperationProcessingResult::NeedMoreGas; } } - delegator_id_set.clear(); self.validator_id_to_delegator_id_set.remove(&validator_id); - self.validators.remove(&validator_id); - if env::used_gas() > Gas::ONE_TERA.mul(T_GAS_CAP_FOR_MULTI_TXS_PROCESSING) { - return MultiTxsOperationProcessingResult::NeedMoreGas; - } + } + self.validators.remove(&validator_id); + self.validator_id_set.remove(&validator_id); + if env::used_gas() > Gas::ONE_TERA.mul(T_GAS_CAP_FOR_MULTI_TXS_PROCESSING) { + return MultiTxsOperationProcessingResult::NeedMoreGas; } } - self.validator_id_set.clear(); self.total_stake = 0; MultiTxsOperationProcessingResult::Ok } diff --git a/appchain-anchor/src/validator_set/validator_set_of_era.rs b/appchain-anchor/src/validator_set/validator_set_of_era.rs index 7647a84..cff42a1 100644 --- a/appchain-anchor/src/validator_set/validator_set_of_era.rs +++ b/appchain-anchor/src/validator_set/validator_set_of_era.rs @@ -248,11 +248,53 @@ impl ValidatorSetOfEra { } /// pub fn clear(&mut self) -> MultiTxsOperationProcessingResult { - let mut result = self.clear_reward_distribution_records(); - if result.is_ok() { - result = self.validator_set.clear(); + let validator_ids = self.validator_set.validator_id_set.to_vec(); + for validator_id in validator_ids { + if let Some(mut delegator_id_set) = self + .validator_set + .validator_id_to_delegator_id_set + .get(&validator_id) + { + let delegator_ids = delegator_id_set.to_vec(); + for delegator_id in delegator_ids { + self.delegator_rewards + .remove(&(delegator_id.clone(), validator_id.clone())); + self.validator_set + .delegators + .remove(&(delegator_id.clone(), validator_id.clone())); + if let Some(mut validator_id_set_of_delegator) = self + .validator_set + .delegator_id_to_validator_id_set + .get(&delegator_id) + { + validator_id_set_of_delegator.clear(); + self.validator_set + .delegator_id_to_validator_id_set + .remove(&delegator_id); + } + delegator_id_set.remove(&delegator_id); + if env::used_gas() > Gas::ONE_TERA.mul(T_GAS_CAP_FOR_MULTI_TXS_PROCESSING) { + self.validator_set + .validator_id_to_delegator_id_set + .insert(&validator_id, &delegator_id_set); + return MultiTxsOperationProcessingResult::NeedMoreGas; + } + } + self.validator_set + .validator_id_to_delegator_id_set + .remove(&validator_id); + } + self.validator_rewards.remove(&validator_id); + self.validator_set.validators.remove(&validator_id); + self.validator_set.validator_id_set.remove(&validator_id); + if env::used_gas() > Gas::ONE_TERA.mul(T_GAS_CAP_FOR_MULTI_TXS_PROCESSING) { + return MultiTxsOperationProcessingResult::NeedMoreGas; + } } - result + self.validator_set.total_stake = 0; + self.valid_total_stake = 0; + self.unprofitable_validator_id_set.clear(); + MultiTxsOperationProcessingResult::Ok } // pub fn apply_staking_fact(&mut self, staking_fact: &StakingFact) { From 8ee1984a9971a4a8bd37214737decb01736c2783 Mon Sep 17 00:00:00 2001 From: Rivers Yang Date: Fri, 16 Dec 2022 15:43:27 +0800 Subject: [PATCH 14/15] Fix error after rebase to `v2.4.1`. --- appchain-anchor/src/lib.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/appchain-anchor/src/lib.rs b/appchain-anchor/src/lib.rs index c0bca43..559ef17 100644 --- a/appchain-anchor/src/lib.rs +++ b/appchain-anchor/src/lib.rs @@ -324,14 +324,6 @@ impl AppchainAnchor { ); } // Assert that the function is called by appchain registry. - fn assert_registry(&self) { - assert_eq!( - env::predecessor_account_id(), - self.appchain_registry, - "Function can only be called by appchain registry contract." - ); - } - // fn assert_registry(&self) { assert_eq!( env::predecessor_account_id(), From 785c5f5e468310d1d4fd4a864e2e0c357eb90a9a Mon Sep 17 00:00:00 2001 From: Rivers Yang Date: Wed, 15 Feb 2023 14:17:18 +0800 Subject: [PATCH 15/15] Add scripts for deployment by github workflow. --- .github/workflows/deploy_testnet_barnacle.yml | 31 +++++++++++++++++++ scripts/ci/deploy_testnet.sh | 11 +++++++ 2 files changed, 42 insertions(+) create mode 100644 .github/workflows/deploy_testnet_barnacle.yml create mode 100755 scripts/ci/deploy_testnet.sh diff --git a/.github/workflows/deploy_testnet_barnacle.yml b/.github/workflows/deploy_testnet_barnacle.yml new file mode 100644 index 0000000..01044d1 --- /dev/null +++ b/.github/workflows/deploy_testnet_barnacle.yml @@ -0,0 +1,31 @@ +name: Appchain anchor contract deployment on testnet (barnacle appchain) + +on: + push: + branches: ["main"] + pull_request: + branches: ["main"] + +env: + CARGO_TERM_COLOR: always + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: "18" + - run: npm install -g near-cli + - run: rustup target add wasm32-unknown-unknown + - name: Build + run: ./build.sh + - run: mkdir ~/.near-credentials + - run: mkdir ~/.near-credentials/testnet + - name: Retrieve the pk of anchor contract and save it to near credentials folder + env: + BARNACLE_ANCHOR_PK: ${{ secrets.BARNACLE_ANCHOR_PK }} + run: echo $BARNACLE_ANCHOR_PK > ~/.near-credentials/testnet/barnacle0928.registry.test_oct.testnet.json + - name: Deploy anchor contract to testnet (barnacle appchain) + run: ./scripts/ci/deploy_testnet.sh barnacle0928 diff --git a/scripts/ci/deploy_testnet.sh b/scripts/ci/deploy_testnet.sh new file mode 100755 index 0000000..cdc107c --- /dev/null +++ b/scripts/ci/deploy_testnet.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -e +# +export NEAR_ENV=testnet +export APPCHAIN_ID=$1 +export REGISTRY_ACCOUNT_ID=registry.test_oct.testnet +export ANCHOR_ACCOUNT_ID=$APPCHAIN_ID'.'$REGISTRY_ACCOUNT_ID +# +near deploy --accountId $ANCHOR_ACCOUNT_ID --initFunction 'migrate_state' --initArgs '{}' --wasmFile res/appchain_anchor.wasm --force +# +near call $ANCHOR_ACCOUNT_ID migrate_appchain_messages '{"start_nonce":0}' --accountId $ANCHOR_ACCOUNT_ID --gas 300000000000000