From a66b7af1e9f31b53697a878e9baed9fd75be06d0 Mon Sep 17 00:00:00 2001 From: Olga Kunyavskaya Date: Fri, 15 Dec 2023 13:01:03 +0200 Subject: [PATCH 01/10] remove set_paused_flag --- Cargo.toml | 2 +- eth-connector/src/contract.rs | 10 +++++++--- eth-connector/src/operation.rs | 11 +++++++---- eth-connector/tests/fungible_token_tests.rs | 4 ++-- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a4621b6..c6fb90b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,4 +7,4 @@ members = [ exclude = [ "res/mock_engine", "res/mock_eth_connector" -] +] \ No newline at end of file diff --git a/eth-connector/src/contract.rs b/eth-connector/src/contract.rs index 175c772..548143b 100644 --- a/eth-connector/src/contract.rs +++ b/eth-connector/src/contract.rs @@ -2,7 +2,7 @@ use crate::operation::{ CallDeposit, CallEngineFtTransfer, CallEngineFtTransferCall, CallEngineStorageDeposit, CallEngineStorageUnregister, CallEngineStorageWithdraw, CallEngineWithdraw, CallFtTransfer, CallFtTransferCall, CallMigrate, CallNew, CallRemoveEngineAccount, CallSetAccessRight, - CallSetEngineAccount, CallSetPausedFlags, CallStorageDeposit, CallStorageUnregister, + CallSetEngineAccount, CallPaPauseFeature, CallPaUnpauseFeature, CallStorageDeposit, CallStorageUnregister, CallStorageWithdraw, CallWithdraw, ViewCheckMigrationCorrectness, ViewFtBalanceOf, ViewFtMetadata, ViewFtTotalSupply, ViewGetAccountWithAccessRight, ViewGetBridgeProver, ViewGetPausedFlags, ViewIsEngineAccountExist, ViewIsOwner, ViewIsUsedProof, @@ -176,8 +176,12 @@ impl EthConnectorContract { .args_json(json!({ "sender_id": sender_id.as_ref(), "force": force })) } - pub fn set_paused_flags(&self, paused: PausedMask) -> CallSetPausedFlags { - CallSetPausedFlags::call(&self.contract).args_borsh(paused) + pub fn pa_pause_feature(&self, key: String) -> CallPaPauseFeature { + CallPaPauseFeature::call(&self.contract).args_json(json!({"key": key})) + } + + pub fn pa_unpause_feature(&self, key: String) -> CallPaUnpauseFeature { + CallPaUnpauseFeature::call(&self.contract).args_json(json!({"key": key})) } pub fn set_access_right(&self, account: &impl AsRef) -> CallSetAccessRight { diff --git a/eth-connector/src/operation.rs b/eth-connector/src/operation.rs index a49c74e..945bf94 100644 --- a/eth-connector/src/operation.rs +++ b/eth-connector/src/operation.rs @@ -16,7 +16,8 @@ impl_call_return![ (CallSetEngineAccount, Call::SetEngineAccount), (CallRemoveEngineAccount, Call::RemoveEngineAccount), (CallDeposit, Call::Deposit), - (CallSetPausedFlags, Call::SetPausedFlags), + (CallPaPauseFeature, Call::PaPauseFeature), + (CallPaUnpauseFeature, Call::PaUnpauseFeature), (CallSetAccessRight, Call::SetAccessRight), (CallMigrate, Call::Migrate), ]; @@ -67,7 +68,8 @@ pub(crate) enum Call { EngineStorageDeposit, EngineStorageUnregister, EngineStorageWithdraw, - SetPausedFlags, + PaPauseFeature, + PaUnpauseFeature, SetAccessRight, Migrate, } @@ -92,8 +94,9 @@ impl AsRef for Call { EngineStorageDeposit => "engine_storage_deposit", EngineStorageUnregister => "engine_storage_unregister", EngineStorageWithdraw => "engine_storage_withdraw", - SetPausedFlags => "set_paused_flags", - SetAccessRight => "set_access_right", + PaPauseFeature => "pa_pause_feature", + PaUnpauseFeature => "pa_unpause_feature", + AclGrantRole => "acl_grant_role", Migrate => "migrate", } } diff --git a/eth-connector/tests/fungible_token_tests.rs b/eth-connector/tests/fungible_token_tests.rs index d2407a9..12dfd4d 100644 --- a/eth-connector/tests/fungible_token_tests.rs +++ b/eth-connector/tests/fungible_token_tests.rs @@ -259,10 +259,10 @@ async fn test_storage_balance_bounds() { } #[tokio::test] -async fn test_set_paused_flags() { +async fn test_pa_pause_feature() { let contract = deploy_and_init().await.unwrap(); contract - .set_paused_flags(UNPAUSE_ALL) + .pa_pause_feature("withdraw".to_string()) .max_gas() .transact() .await From a45c6c81c5bf1a4becfc634a84e0ad87a7388401 Mon Sep 17 00:00:00 2001 From: Olga Kunyavskaya Date: Fri, 15 Dec 2023 13:24:58 +0200 Subject: [PATCH 02/10] remove set_access_right --- eth-connector/src/contract.rs | 10 +++++++--- eth-connector/src/operation.rs | 7 +++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/eth-connector/src/contract.rs b/eth-connector/src/contract.rs index 548143b..e046b6c 100644 --- a/eth-connector/src/contract.rs +++ b/eth-connector/src/contract.rs @@ -1,7 +1,7 @@ use crate::operation::{ CallDeposit, CallEngineFtTransfer, CallEngineFtTransferCall, CallEngineStorageDeposit, CallEngineStorageUnregister, CallEngineStorageWithdraw, CallEngineWithdraw, CallFtTransfer, - CallFtTransferCall, CallMigrate, CallNew, CallRemoveEngineAccount, CallSetAccessRight, + CallFtTransferCall, CallMigrate, CallNew, CallRemoveEngineAccount, CallAclGrantRole, CallAclRevokeRole, CallSetEngineAccount, CallPaPauseFeature, CallPaUnpauseFeature, CallStorageDeposit, CallStorageUnregister, CallStorageWithdraw, CallWithdraw, ViewCheckMigrationCorrectness, ViewFtBalanceOf, ViewFtMetadata, ViewFtTotalSupply, ViewGetAccountWithAccessRight, ViewGetBridgeProver, @@ -184,8 +184,12 @@ impl EthConnectorContract { CallPaUnpauseFeature::call(&self.contract).args_json(json!({"key": key})) } - pub fn set_access_right(&self, account: &impl AsRef) -> CallSetAccessRight { - CallSetAccessRight::call(&self.contract).args_json((account.as_ref(),)) + pub fn acl_grant_role(&self, role: String, account_id: String) -> CallAclGrantRole { + CallAclGrantRole::call(&self.contract).args_json(json!({"role": role, "account_id": account_id})) + } + + pub fn acl_revoke_role(&self, role: String, account_id: String) -> CallAclRevokeRole { + CallAclRevokeRole::call(&self.contract).args_json(json!({"role": role, "account_id": account_id})) } pub fn withdraw(&self, recipient_address: Address, amount: Balance) -> CallWithdraw { diff --git a/eth-connector/src/operation.rs b/eth-connector/src/operation.rs index 945bf94..d1fb8cc 100644 --- a/eth-connector/src/operation.rs +++ b/eth-connector/src/operation.rs @@ -18,7 +18,8 @@ impl_call_return![ (CallDeposit, Call::Deposit), (CallPaPauseFeature, Call::PaPauseFeature), (CallPaUnpauseFeature, Call::PaUnpauseFeature), - (CallSetAccessRight, Call::SetAccessRight), + (CallAclRevokeRole, Call::AclRevokeRole), + (CallAclGrantRole, Call::AclGrantRole), (CallMigrate, Call::Migrate), ]; @@ -70,7 +71,8 @@ pub(crate) enum Call { EngineStorageWithdraw, PaPauseFeature, PaUnpauseFeature, - SetAccessRight, + AclRevokeRole, + AclGrantRole, Migrate, } @@ -97,6 +99,7 @@ impl AsRef for Call { PaPauseFeature => "pa_pause_feature", PaUnpauseFeature => "pa_unpause_feature", AclGrantRole => "acl_grant_role", + AclRevokeRole => "acl_revoke_role", Migrate => "migrate", } } From 6c2187f47a0a2fd3d0de23ac8a5479b513cb9b02 Mon Sep 17 00:00:00 2001 From: Olga Kunyavskaya Date: Fri, 15 Dec 2023 14:54:34 +0200 Subject: [PATCH 03/10] remove get_account_with_acceess_right --- eth-connector/src/contract.rs | 6 +++--- eth-connector/src/operation.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/eth-connector/src/contract.rs b/eth-connector/src/contract.rs index e046b6c..4c23751 100644 --- a/eth-connector/src/contract.rs +++ b/eth-connector/src/contract.rs @@ -4,7 +4,7 @@ use crate::operation::{ CallFtTransferCall, CallMigrate, CallNew, CallRemoveEngineAccount, CallAclGrantRole, CallAclRevokeRole, CallSetEngineAccount, CallPaPauseFeature, CallPaUnpauseFeature, CallStorageDeposit, CallStorageUnregister, CallStorageWithdraw, CallWithdraw, ViewCheckMigrationCorrectness, ViewFtBalanceOf, - ViewFtMetadata, ViewFtTotalSupply, ViewGetAccountWithAccessRight, ViewGetBridgeProver, + ViewFtMetadata, ViewFtTotalSupply, ViewAclGetGrantees, ViewGetBridgeProver, ViewGetPausedFlags, ViewIsEngineAccountExist, ViewIsOwner, ViewIsUsedProof, ViewStorageBalanceBounds, ViewStorageBalanceOf, }; @@ -239,8 +239,8 @@ impl EthConnectorContract { ViewGetPausedFlags::view(&self.contract) } - pub fn get_account_with_access_right(&self) -> ViewGetAccountWithAccessRight { - ViewGetAccountWithAccessRight::view(&self.contract) + pub fn acl_get_grantees(&self, role: String, skip: u64, limit: u64) -> ViewAclGetGrantees { + ViewAclGetGrantees::view(&self.contract).args_json(json!({"role": role, "skip": skip, "limit": limit})) } pub fn is_owner(&self) -> ViewIsOwner { diff --git a/eth-connector/src/operation.rs b/eth-connector/src/operation.rs index d1fb8cc..730a43d 100644 --- a/eth-connector/src/operation.rs +++ b/eth-connector/src/operation.rs @@ -45,7 +45,7 @@ impl_view_return![ (ViewCheckMigrationCorrectness => MigrationCheckResult, View::CheckMigrationCorrectness, borsh), (ViewFtMetadata => FungibleTokenMetadata, View::FtMetadata, json), (ViewGetPausedFlags => PausedMask, View::GetPausedFlags, borsh), - (ViewGetAccountWithAccessRight => AccountId, View::GetAccountWithAccessRight, json), + (ViewAclGetGrantees => Vec, View::AclGetGrantees, json), (ViewIsOwner => bool, View::IsOwner, json), (ViewIsUsedProof => bool, View::IsUsedProof, borsh), (ViewGetBridgeProver => AccountId, View::GetBridgeProver, json), @@ -114,7 +114,7 @@ pub enum View { StorageBalanceBounds, IsEngineAccountExist, GetPausedFlags, - GetAccountWithAccessRight, + AclGetGrantees, IsOwner, CheckMigrationCorrectness, IsUsedProof, @@ -132,7 +132,7 @@ impl AsRef for View { StorageBalanceBounds => "storage_balance_bounds", IsEngineAccountExist => "is_engine_account_exist", GetPausedFlags => "get_paused_flags", - GetAccountWithAccessRight => "get_account_with_access_right", + AclGetGrantees => "acl_get_grantees", IsOwner => "is_owner", CheckMigrationCorrectness => "check_migration_correctness", IsUsedProof => "is_used_proof", From 960efaa6d7fe65134ea02e106785ee0bdb70851d Mon Sep 17 00:00:00 2001 From: Olga Kunyavskaya Date: Mon, 18 Dec 2023 09:31:29 +0200 Subject: [PATCH 04/10] remove admin controll --- eth-connector/src/contract.rs | 10 +-- eth-connector/tests/fungible_token_tests.rs | 48 +---------- res/mock_eth_connector/Cargo.lock | 83 +++++++++++++++++++ res/mock_eth_connector/Cargo.toml | 1 + .../src/admin_controlled.rs | 70 ---------------- res/mock_eth_connector/src/lib.rs | 58 +++++++------ 6 files changed, 122 insertions(+), 148 deletions(-) delete mode 100644 res/mock_eth_connector/src/admin_controlled.rs diff --git a/eth-connector/src/contract.rs b/eth-connector/src/contract.rs index 4c23751..6764735 100644 --- a/eth-connector/src/contract.rs +++ b/eth-connector/src/contract.rs @@ -5,10 +5,10 @@ use crate::operation::{ CallSetEngineAccount, CallPaPauseFeature, CallPaUnpauseFeature, CallStorageDeposit, CallStorageUnregister, CallStorageWithdraw, CallWithdraw, ViewCheckMigrationCorrectness, ViewFtBalanceOf, ViewFtMetadata, ViewFtTotalSupply, ViewAclGetGrantees, ViewGetBridgeProver, - ViewGetPausedFlags, ViewIsEngineAccountExist, ViewIsOwner, ViewIsUsedProof, + ViewGetPausedFlags, ViewIsEngineAccountExist, ViewIsUsedProof, ViewStorageBalanceBounds, ViewStorageBalanceOf, }; -use crate::types::{MigrationInputData, PausedMask, Proof}; +use crate::types::{MigrationInputData, Proof}; use aurora_engine_types::types::Address; use aurora_workspace_utils::{Contract, ContractId}; use near_contract_standards::fungible_token::metadata::FungibleTokenMetadata; @@ -82,7 +82,7 @@ impl EthConnectorContract { })) } - pub fn engine_ft_transfer( + pub fn engine_ft_traprnsfer( &self, sender_id: &impl AsRef, receiver_id: &impl AsRef, @@ -243,10 +243,6 @@ impl EthConnectorContract { ViewAclGetGrantees::view(&self.contract).args_json(json!({"role": role, "skip": skip, "limit": limit})) } - pub fn is_owner(&self) -> ViewIsOwner { - ViewIsOwner::view(&self.contract) - } - pub fn is_used_proof(&self, proof: Proof) -> ViewIsUsedProof { ViewIsUsedProof::view(&self.contract).args_borsh(proof) } diff --git a/eth-connector/tests/fungible_token_tests.rs b/eth-connector/tests/fungible_token_tests.rs index 12dfd4d..a81668f 100644 --- a/eth-connector/tests/fungible_token_tests.rs +++ b/eth-connector/tests/fungible_token_tests.rs @@ -2,7 +2,7 @@ use aurora_engine_types::account_id::AccountId; use aurora_engine_types::types::Address; use aurora_workspace_eth_connector::contract::EthConnectorContract; use aurora_workspace_eth_connector::types::{ - MigrationCheckResult, MigrationInputData, Proof, UNPAUSE_ALL, + MigrationCheckResult, MigrationInputData, Proof, }; use aurora_workspace_utils::results::ViewResult; use aurora_workspace_utils::ContractId; @@ -261,6 +261,7 @@ async fn test_storage_balance_bounds() { #[tokio::test] async fn test_pa_pause_feature() { let contract = deploy_and_init().await.unwrap(); + println!("{:?}", contract); contract .pa_pause_feature("withdraw".to_string()) .max_gas() @@ -269,18 +270,6 @@ async fn test_pa_pause_feature() { .unwrap(); } -#[tokio::test] -async fn test_set_access_right() { - let contract = deploy_and_init().await.unwrap(); - let account = AccountId::from_str("test.near").unwrap(); - contract - .set_access_right(&account) - .max_gas() - .transact() - .await - .unwrap(); -} - #[tokio::test] async fn test_withdraw() { let contract = deploy_and_init().await.unwrap(); @@ -356,39 +345,6 @@ async fn test_ft_metadata() { assert_eq!(res.result.decimals, expected.decimals); } -#[tokio::test] -async fn test_get_account_with_access_right() { - let contract = deploy_and_init().await.unwrap(); - let res = contract.get_account_with_access_right().await.unwrap(); - let expected = ViewResult { - result: AccountId::from_str("contract.root").unwrap(), - logs: vec![], - }; - assert_eq!(res, expected); -} - -#[tokio::test] -async fn test_get_paused_flags() { - let contract = deploy_and_init().await.unwrap(); - let res = contract.get_paused_flags().await.unwrap(); - let expected = ViewResult { - result: UNPAUSE_ALL, - logs: vec![], - }; - assert_eq!(res, expected); -} - -#[tokio::test] -async fn test_is_owner() { - let contract = deploy_and_init().await.unwrap(); - let res = contract.is_owner().await.unwrap(); - let expected = ViewResult { - result: true, - logs: vec![], - }; - assert_eq!(res, expected); -} - #[tokio::test] async fn test_check_migration_correctness() { let contract = deploy_and_init().await.unwrap(); diff --git a/res/mock_eth_connector/Cargo.lock b/res/mock_eth_connector/Cargo.lock index 1a1bdbc..e8d32fc 100644 --- a/res/mock_eth_connector/Cargo.lock +++ b/res/mock_eth_connector/Cargo.lock @@ -94,6 +94,12 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + [[package]] name = "bitvec" version = "0.20.4" @@ -374,6 +380,41 @@ dependencies = [ "zeroize", ] +[[package]] +name = "darling" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 1.0.109", +] + +[[package]] +name = "darling_macro" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" +dependencies = [ + "darling_core", + "quote", + "syn 1.0.109", +] + [[package]] name = "derive_more" version = "0.99.17" @@ -462,6 +503,12 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + [[package]] name = "funty" version = "1.1.0" @@ -559,6 +606,12 @@ dependencies = [ "cc", ] +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "impl-codec" version = "0.5.1" @@ -670,6 +723,7 @@ version = "0.1.0" dependencies = [ "aurora-engine-types", "near-contract-standards", + "near-plugins", "near-sdk", ] @@ -733,6 +787,29 @@ dependencies = [ "thiserror", ] +[[package]] +name = "near-plugins" +version = "0.1.0" +source = "git+https://github.com/aurora-is-near/near-plugins?tag=v0.1.0#64c512f96d4b51ccdd1a1aed683ed90fd1ca8c57" +dependencies = [ + "bitflags", + "near-plugins-derive", + "near-sdk", + "serde", +] + +[[package]] +name = "near-plugins-derive" +version = "0.1.0" +source = "git+https://github.com/aurora-is-near/near-plugins?tag=v0.1.0#64c512f96d4b51ccdd1a1aed683ed90fd1ca8c57" +dependencies = [ + "darling", + "proc-macro-crate 0.1.5", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "near-primitives" version = "0.14.0" @@ -1308,6 +1385,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + [[package]] name = "strum" version = "0.24.1" diff --git a/res/mock_eth_connector/Cargo.toml b/res/mock_eth_connector/Cargo.toml index b8b32a3..f8090d2 100644 --- a/res/mock_eth_connector/Cargo.toml +++ b/res/mock_eth_connector/Cargo.toml @@ -9,6 +9,7 @@ crate-type = ["cdylib", "rlib"] [dependencies] aurora-engine-types = { git = "https://github.com/aurora-is-near/aurora-engine.git", branch = "develop", default-features = false, features = ["impl-serde", "borsh-compat"] } near-contract-standards = "4.1" +near-plugins = { git = "https://github.com/aurora-is-near/near-plugins", tag = "v0.1.0" } near-sdk = "4.1" [profile.release] diff --git a/res/mock_eth_connector/src/admin_controlled.rs b/res/mock_eth_connector/src/admin_controlled.rs deleted file mode 100644 index 8ac1509..0000000 --- a/res/mock_eth_connector/src/admin_controlled.rs +++ /dev/null @@ -1,70 +0,0 @@ -#![allow(dead_code)] -use near_sdk::AccountId; - -pub type PausedMask = u8; - -/// Admin control flow flag indicates that all control flow is unpaused (unblocked). -pub const UNPAUSE_ALL: PausedMask = 0; -/// Admin control flow flag indicates that the deposit is paused. -pub const PAUSE_DEPOSIT: PausedMask = 1 << 0; -/// Admin control flow flag indicates that withdrawal is paused. -pub const PAUSE_WITHDRAW: PausedMask = 1 << 1; - -pub trait AdminControlled { - /// Return the current mask representing all paused events. - fn get_paused_flags(&self) -> PausedMask; - - /// Update mask with all paused events. - /// Implementor is responsible for guaranteeing that this function can only be - /// called by owner of the contract. - fn set_paused_flags(&mut self, paused: PausedMask); - - /// Return if the contract is paused for the current flag. - /// If it's owner, result always `false` - unpaused. - fn is_paused(&self, flag: PausedMask) -> bool { - true - } - - /// Asserts the passed paused flag is not set. Returns `PausedError` if paused. - fn assert_not_paused(&self, flag: PausedMask) -> Result<(), error::AdminControlledError> { - Ok(()) - } - - /// Set account access right for contract - fn set_access_right(&mut self, account: &AccountId); - - /// Get account access right for contract - fn get_account_with_access_right(&self) -> AccountId; - - /// Check access right for predecessor account - fn assert_access_right(&self) -> Result<(), error::AdminControlledError> { - Ok(()) - } - - /// Assert only owners of contract access right - fn assert_owner_access_right(&self) -> Result<(), error::AdminControlledError> { - Ok(()) - } - - /// Check is predecessor account ID is owner - fn is_owner(&self) -> bool; -} - -pub mod error { - pub const ERR_PAUSED: &[u8; 10] = b"ERR_PAUSED"; - pub const ERR_ACCESS_RIGHT: &[u8; 16] = b"ERR_ACCESS_RIGHT"; - - pub enum AdminControlledError { - Paused, - AccessRight, - } - - impl AsRef<[u8]> for AdminControlledError { - fn as_ref(&self) -> &[u8] { - match self { - Self::Paused => ERR_PAUSED, - Self::AccessRight => ERR_ACCESS_RIGHT, - } - } - } -} diff --git a/res/mock_eth_connector/src/lib.rs b/res/mock_eth_connector/src/lib.rs index 42e5c0f..4846de0 100644 --- a/res/mock_eth_connector/src/lib.rs +++ b/res/mock_eth_connector/src/lib.rs @@ -1,5 +1,4 @@ #![allow(unused_variables)] -use crate::admin_controlled::{AdminControlled, PausedMask, UNPAUSE_ALL}; use crate::connector::{ ConnectorDeposit, ConnectorFundsFinish, ConnectorWithdraw, EngineFungibleToken, EngineStorageManagement, FinishDepositCallArgs, KnownEngineAccountsManagement, WithdrawResult, @@ -16,20 +15,44 @@ use near_contract_standards::fungible_token::resolver::FungibleTokenResolver; use near_contract_standards::storage_management::{ StorageBalance, StorageBalanceBounds, StorageManagement, }; +use near_plugins::{ + access_control, AccessControlRole, AccessControllable, Pausable, + Upgradable, +}; use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize}; use near_sdk::json_types::U128; use near_sdk::{ - assert_one_yocto, near_bindgen, AccountId, Balance, PanicOnDefault, Promise, PromiseOrValue, + assert_one_yocto, env, near_bindgen, AccountId, Balance, PanicOnDefault, Promise, PromiseOrValue, }; +use near_sdk::serde::{Serialize, Deserialize}; use std::str::FromStr; -mod admin_controlled; mod connector; mod migration; mod proof; +#[derive(AccessControlRole, Deserialize, Serialize, Copy, Clone)] +#[serde(crate = "near_sdk::serde")] +pub enum Role { + PauseManager, + UpgradableCodeStager, + UpgradableCodeDeployer, + Owner, + Engine, + DAO +} + #[near_bindgen] -#[derive(BorshDeserialize, BorshSerialize, PanicOnDefault)] +#[derive(BorshDeserialize, BorshSerialize, PanicOnDefault, Pausable, Upgradable)] +#[access_control(role_type(Role))] +#[pausable(manager_roles(Role::PauseManager, Role::DAO, Role::Owner))] +#[upgradable(access_control_roles( +code_stagers(Role::UpgradableCodeStager, Role::DAO), +code_deployers(Role::UpgradableCodeDeployer, Role::DAO), +duration_initializers(Role::DAO), +duration_update_stagers(Role::DAO), +duration_update_appliers(Role::DAO), +))] pub struct EthConnectorContract; #[near_bindgen] @@ -42,7 +65,12 @@ impl EthConnectorContract { account_with_access_right: AccountId, owner_id: AccountId, ) -> Self { - Self + let mut this = Self{}; + + this.acl_init_super_admin(env::predecessor_account_id()); + this.acl_grant_role("PauseManager".to_string(), env::predecessor_account_id()); + + this } #[result_serializer(borsh)] @@ -179,26 +207,6 @@ impl FungibleTokenMetadataProvider for EthConnectorContract { } } -#[near_bindgen] -impl AdminControlled for EthConnectorContract { - #[result_serializer(borsh)] - fn get_paused_flags(&self) -> PausedMask { - UNPAUSE_ALL - } - - fn set_paused_flags(&mut self, #[serializer(borsh)] paused: PausedMask) {} - - fn set_access_right(&mut self, account: &AccountId) {} - - fn get_account_with_access_right(&self) -> AccountId { - AccountId::from_str("contract.root").unwrap() - } - - fn is_owner(&self) -> bool { - true - } -} - #[near_bindgen] impl ConnectorWithdraw for EthConnectorContract { #[payable] From 498af93068196c1a38abdf0eb3e2a451e60d1612 Mon Sep 17 00:00:00 2001 From: Olga Kunyavskaya Date: Mon, 18 Dec 2023 09:48:03 +0200 Subject: [PATCH 05/10] add tests --- eth-connector/tests/fungible_token_tests.rs | 46 ++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/eth-connector/tests/fungible_token_tests.rs b/eth-connector/tests/fungible_token_tests.rs index a81668f..176c5e4 100644 --- a/eth-connector/tests/fungible_token_tests.rs +++ b/eth-connector/tests/fungible_token_tests.rs @@ -261,7 +261,6 @@ async fn test_storage_balance_bounds() { #[tokio::test] async fn test_pa_pause_feature() { let contract = deploy_and_init().await.unwrap(); - println!("{:?}", contract); contract .pa_pause_feature("withdraw".to_string()) .max_gas() @@ -270,6 +269,51 @@ async fn test_pa_pause_feature() { .unwrap(); } +#[tokio::test] +async fn test_pa_unpause_feature() { + let contract = deploy_and_init().await.unwrap(); + contract + .pa_unpause_feature("withdraw".to_string()) + .max_gas() + .transact() + .await + .unwrap(); +} + + +#[tokio::test] +async fn test_acl_grant_role() { + let contract = deploy_and_init().await.unwrap(); + contract + .acl_grant_role("PauseManager".to_string(), OWNER_ID.to_string()) + .max_gas() + .transact() + .await + .unwrap(); +} + +#[tokio::test] +async fn test_acl_revoke_role() { + let contract = deploy_and_init().await.unwrap(); + contract + .acl_revoke_role("PauseManager".to_string(), OWNER_ID.to_string()) + .max_gas() + .transact() + .await + .unwrap(); +} + +#[tokio::test] +async fn test_acl_get_grantees() { + let contract = deploy_and_init().await.unwrap(); + let res = contract + .acl_get_grantees("PauseManager".to_string(), 0, 1) + .await + .unwrap(); + + assert_eq!(res.result.len(), 1); +} + #[tokio::test] async fn test_withdraw() { let contract = deploy_and_init().await.unwrap(); From 78a6358406448879cf019644d1db191da159920f Mon Sep 17 00:00:00 2001 From: Olga Kunyavskaya Date: Mon, 18 Dec 2023 10:19:41 +0200 Subject: [PATCH 06/10] fix typo --- eth-connector/src/contract.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eth-connector/src/contract.rs b/eth-connector/src/contract.rs index 6764735..d98c82e 100644 --- a/eth-connector/src/contract.rs +++ b/eth-connector/src/contract.rs @@ -82,7 +82,7 @@ impl EthConnectorContract { })) } - pub fn engine_ft_traprnsfer( + pub fn engine_ft_transfer( &self, sender_id: &impl AsRef, receiver_id: &impl AsRef, From 91480f6fe00bea777af2a620d96fe0032eab6ffe Mon Sep 17 00:00:00 2001 From: Olga Kunyavskaya Date: Wed, 20 Dec 2023 18:49:17 +0200 Subject: [PATCH 07/10] set_aurora_engine_account_id --- eth-connector/src/contract.rs | 37 ++++++++++++++------- eth-connector/src/operation.rs | 6 ++++ eth-connector/tests/fungible_token_tests.rs | 22 +++++++++--- res/mock_eth_connector/src/lib.rs | 4 +++ 4 files changed, 53 insertions(+), 16 deletions(-) diff --git a/eth-connector/src/contract.rs b/eth-connector/src/contract.rs index d98c82e..03ee6c0 100644 --- a/eth-connector/src/contract.rs +++ b/eth-connector/src/contract.rs @@ -1,11 +1,12 @@ use crate::operation::{ - CallDeposit, CallEngineFtTransfer, CallEngineFtTransferCall, CallEngineStorageDeposit, - CallEngineStorageUnregister, CallEngineStorageWithdraw, CallEngineWithdraw, CallFtTransfer, - CallFtTransferCall, CallMigrate, CallNew, CallRemoveEngineAccount, CallAclGrantRole, CallAclRevokeRole, - CallSetEngineAccount, CallPaPauseFeature, CallPaUnpauseFeature, CallStorageDeposit, CallStorageUnregister, - CallStorageWithdraw, CallWithdraw, ViewCheckMigrationCorrectness, ViewFtBalanceOf, - ViewFtMetadata, ViewFtTotalSupply, ViewAclGetGrantees, ViewGetBridgeProver, - ViewGetPausedFlags, ViewIsEngineAccountExist, ViewIsUsedProof, + CallAclGrantRole, CallAclRevokeRole, CallDeposit, CallEngineFtTransfer, + CallEngineFtTransferCall, CallEngineStorageDeposit, CallEngineStorageUnregister, + CallEngineStorageWithdraw, CallEngineWithdraw, CallFtTransfer, CallFtTransferCall, CallMigrate, + CallNew, CallPaPauseFeature, CallPaUnpauseFeature, CallRemoveEngineAccount, + CallSetAuroraEngineAccountId, CallSetEngineAccount, CallStorageDeposit, CallStorageUnregister, + CallStorageWithdraw, CallWithdraw, ViewAclGetGrantees, ViewCheckMigrationCorrectness, + ViewFtBalanceOf, ViewFtMetadata, ViewFtTotalSupply, ViewGetAuroraEngineAccountId, + ViewGetBridgeProver, ViewGetPausedFlags, ViewIsEngineAccountExist, ViewIsUsedProof, ViewStorageBalanceBounds, ViewStorageBalanceOf, }; use crate::types::{MigrationInputData, Proof}; @@ -177,19 +178,21 @@ impl EthConnectorContract { } pub fn pa_pause_feature(&self, key: String) -> CallPaPauseFeature { - CallPaPauseFeature::call(&self.contract).args_json(json!({"key": key})) + CallPaPauseFeature::call(&self.contract).args_json(json!({ "key": key })) } pub fn pa_unpause_feature(&self, key: String) -> CallPaUnpauseFeature { - CallPaUnpauseFeature::call(&self.contract).args_json(json!({"key": key})) + CallPaUnpauseFeature::call(&self.contract).args_json(json!({ "key": key })) } pub fn acl_grant_role(&self, role: String, account_id: String) -> CallAclGrantRole { - CallAclGrantRole::call(&self.contract).args_json(json!({"role": role, "account_id": account_id})) + CallAclGrantRole::call(&self.contract) + .args_json(json!({"role": role, "account_id": account_id})) } pub fn acl_revoke_role(&self, role: String, account_id: String) -> CallAclRevokeRole { - CallAclRevokeRole::call(&self.contract).args_json(json!({"role": role, "account_id": account_id})) + CallAclRevokeRole::call(&self.contract) + .args_json(json!({"role": role, "account_id": account_id})) } pub fn withdraw(&self, recipient_address: Address, amount: Balance) -> CallWithdraw { @@ -216,6 +219,11 @@ impl EthConnectorContract { pub fn migrate(&self, data: MigrationInputData) -> CallMigrate { CallMigrate::call(&self.contract).args_borsh(data) } + + pub fn set_aurora_engine_account_id(&self, account_id: String) -> CallSetAuroraEngineAccountId { + CallSetAuroraEngineAccountId::call(&self.contract) + .args_json(json!({ "new_aurora_engine_account_id": account_id })) + } } /// View functions @@ -240,7 +248,8 @@ impl EthConnectorContract { } pub fn acl_get_grantees(&self, role: String, skip: u64, limit: u64) -> ViewAclGetGrantees { - ViewAclGetGrantees::view(&self.contract).args_json(json!({"role": role, "skip": skip, "limit": limit})) + ViewAclGetGrantees::view(&self.contract) + .args_json(json!({"role": role, "skip": skip, "limit": limit})) } pub fn is_used_proof(&self, proof: Proof) -> ViewIsUsedProof { @@ -272,4 +281,8 @@ impl EthConnectorContract { pub fn ft_balance_of(&self, account_id: &impl AsRef) -> ViewFtBalanceOf { ViewFtBalanceOf::view(&self.contract).args_json(json!((account_id.as_ref(),))) } + + pub fn get_aurora_engine_account_id(&self) -> ViewGetAuroraEngineAccountId { + ViewGetAuroraEngineAccountId::view(&self.contract).args_json(json!({})) + } } diff --git a/eth-connector/src/operation.rs b/eth-connector/src/operation.rs index 730a43d..aec3455 100644 --- a/eth-connector/src/operation.rs +++ b/eth-connector/src/operation.rs @@ -21,6 +21,7 @@ impl_call_return![ (CallAclRevokeRole, Call::AclRevokeRole), (CallAclGrantRole, Call::AclGrantRole), (CallMigrate, Call::Migrate), + (CallSetAuroraEngineAccountId, Call::SetAuroraEngineAccountId) ]; impl_call_return![ @@ -49,6 +50,7 @@ impl_view_return![ (ViewIsOwner => bool, View::IsOwner, json), (ViewIsUsedProof => bool, View::IsUsedProof, borsh), (ViewGetBridgeProver => AccountId, View::GetBridgeProver, json), + (ViewGetAuroraEngineAccountId => AccountId, View::GetAuroraEngineAccountId, json) ]; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] @@ -74,6 +76,7 @@ pub(crate) enum Call { AclRevokeRole, AclGrantRole, Migrate, + SetAuroraEngineAccountId, } impl AsRef for Call { @@ -101,6 +104,7 @@ impl AsRef for Call { AclGrantRole => "acl_grant_role", AclRevokeRole => "acl_revoke_role", Migrate => "migrate", + SetAuroraEngineAccountId => "set_aurora_engine_account_id", } } } @@ -119,6 +123,7 @@ pub enum View { CheckMigrationCorrectness, IsUsedProof, GetBridgeProver, + GetAuroraEngineAccountId, } impl AsRef for View { @@ -137,6 +142,7 @@ impl AsRef for View { CheckMigrationCorrectness => "check_migration_correctness", IsUsedProof => "is_used_proof", GetBridgeProver => "get_bridge_prover", + GetAuroraEngineAccountId => "get_aurora_engine_account_id", } } } diff --git a/eth-connector/tests/fungible_token_tests.rs b/eth-connector/tests/fungible_token_tests.rs index 176c5e4..5060590 100644 --- a/eth-connector/tests/fungible_token_tests.rs +++ b/eth-connector/tests/fungible_token_tests.rs @@ -1,9 +1,7 @@ use aurora_engine_types::account_id::AccountId; use aurora_engine_types::types::Address; use aurora_workspace_eth_connector::contract::EthConnectorContract; -use aurora_workspace_eth_connector::types::{ - MigrationCheckResult, MigrationInputData, Proof, -}; +use aurora_workspace_eth_connector::types::{MigrationCheckResult, MigrationInputData, Proof}; use aurora_workspace_utils::results::ViewResult; use aurora_workspace_utils::ContractId; use near_contract_standards::fungible_token::metadata::{FungibleTokenMetadata, FT_METADATA_SPEC}; @@ -280,7 +278,6 @@ async fn test_pa_unpause_feature() { .unwrap(); } - #[tokio::test] async fn test_acl_grant_role() { let contract = deploy_and_init().await.unwrap(); @@ -314,6 +311,23 @@ async fn test_acl_get_grantees() { assert_eq!(res.result.len(), 1); } +#[tokio::test] +async fn test_set_aurora_engine_account_id() { + let contract = deploy_and_init().await.unwrap(); + contract + .set_aurora_engine_account_id("test.near".to_string()) + .max_gas() + .transact() + .await + .unwrap(); +} + +#[tokio::test] +async fn test_get_aurora_engine_account_id() { + let contract = deploy_and_init().await.unwrap(); + contract.get_aurora_engine_account_id().await.unwrap(); +} + #[tokio::test] async fn test_withdraw() { let contract = deploy_and_init().await.unwrap(); diff --git a/res/mock_eth_connector/src/lib.rs b/res/mock_eth_connector/src/lib.rs index 4846de0..6e5da10 100644 --- a/res/mock_eth_connector/src/lib.rs +++ b/res/mock_eth_connector/src/lib.rs @@ -81,6 +81,10 @@ impl EthConnectorContract { pub fn get_bridge_prover(&self) -> AccountId { AccountId::from_str("bridge_prover.root").unwrap() } + + pub fn set_aurora_engine_account_id(&mut self, new_aurora_engine_account_id: AccountId) {} + + pub fn get_aurora_engine_account_id(&self) -> AccountId { env::current_account_id() } } #[near_bindgen] From 787583de526ea89da6624e68ed976f5c0170e7ec Mon Sep 17 00:00:00 2001 From: Olga Kunyavskaya Date: Fri, 22 Dec 2023 12:05:56 +0200 Subject: [PATCH 08/10] fmt --- res/mock_eth_connector/src/lib.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/res/mock_eth_connector/src/lib.rs b/res/mock_eth_connector/src/lib.rs index 6e5da10..b5a236a 100644 --- a/res/mock_eth_connector/src/lib.rs +++ b/res/mock_eth_connector/src/lib.rs @@ -15,16 +15,14 @@ use near_contract_standards::fungible_token::resolver::FungibleTokenResolver; use near_contract_standards::storage_management::{ StorageBalance, StorageBalanceBounds, StorageManagement, }; -use near_plugins::{ - access_control, AccessControlRole, AccessControllable, Pausable, - Upgradable, -}; +use near_plugins::{access_control, AccessControlRole, AccessControllable, Pausable, Upgradable}; use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize}; use near_sdk::json_types::U128; +use near_sdk::serde::{Deserialize, Serialize}; use near_sdk::{ - assert_one_yocto, env, near_bindgen, AccountId, Balance, PanicOnDefault, Promise, PromiseOrValue, + assert_one_yocto, env, near_bindgen, AccountId, Balance, PanicOnDefault, Promise, + PromiseOrValue, }; -use near_sdk::serde::{Serialize, Deserialize}; use std::str::FromStr; mod connector; @@ -39,7 +37,7 @@ pub enum Role { UpgradableCodeDeployer, Owner, Engine, - DAO + DAO, } #[near_bindgen] @@ -47,11 +45,11 @@ pub enum Role { #[access_control(role_type(Role))] #[pausable(manager_roles(Role::PauseManager, Role::DAO, Role::Owner))] #[upgradable(access_control_roles( -code_stagers(Role::UpgradableCodeStager, Role::DAO), -code_deployers(Role::UpgradableCodeDeployer, Role::DAO), -duration_initializers(Role::DAO), -duration_update_stagers(Role::DAO), -duration_update_appliers(Role::DAO), + code_stagers(Role::UpgradableCodeStager, Role::DAO), + code_deployers(Role::UpgradableCodeDeployer, Role::DAO), + duration_initializers(Role::DAO), + duration_update_stagers(Role::DAO), + duration_update_appliers(Role::DAO), ))] pub struct EthConnectorContract; @@ -65,7 +63,7 @@ impl EthConnectorContract { account_with_access_right: AccountId, owner_id: AccountId, ) -> Self { - let mut this = Self{}; + let mut this = Self {}; this.acl_init_super_admin(env::predecessor_account_id()); this.acl_grant_role("PauseManager".to_string(), env::predecessor_account_id()); @@ -84,7 +82,9 @@ impl EthConnectorContract { pub fn set_aurora_engine_account_id(&mut self, new_aurora_engine_account_id: AccountId) {} - pub fn get_aurora_engine_account_id(&self) -> AccountId { env::current_account_id() } + pub fn get_aurora_engine_account_id(&self) -> AccountId { + env::current_account_id() + } } #[near_bindgen] From c1ff238262c6783c33d1cd04a9b9b2a51f52469b Mon Sep 17 00:00:00 2001 From: Olga Kunyavskaya Date: Thu, 4 Jan 2024 12:06:18 +0200 Subject: [PATCH 09/10] check result in tests --- Cargo.toml | 2 +- eth-connector/tests/fungible_token_tests.rs | 24 ++++++++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9e1809c..911b658 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,4 +29,4 @@ serde_json = "1" near-workspaces = "0.9" [patch.crates-io] -parity-secp256k1 = { git = 'https://github.com/paritytech/rust-secp256k1', rev = "d05fd8e" } \ No newline at end of file +parity-secp256k1 = { git = 'https://github.com/paritytech/rust-secp256k1', rev = "d05fd8e" } diff --git a/eth-connector/tests/fungible_token_tests.rs b/eth-connector/tests/fungible_token_tests.rs index 0db6bfa..44e33ae 100644 --- a/eth-connector/tests/fungible_token_tests.rs +++ b/eth-connector/tests/fungible_token_tests.rs @@ -52,13 +52,14 @@ async fn test_ft_transfer() { let amount: U128 = 10.into(); let memo = Some(String::from("some message")); - contract + let result = contract .ft_transfer(&some_acc, amount, memo) .max_gas() .deposit(NearToken::from_yoctonear(1)) .transact() .await .unwrap(); + assert!(result.is_success()); } #[tokio::test] @@ -113,24 +114,26 @@ async fn test_ft_balance_of() { async fn test_set_engine_account() { let contract = deploy_and_init().await.unwrap(); let engine_account = AccountId::from_str("test.near").unwrap(); - contract + let result = contract .set_engine_account(&engine_account) .max_gas() .transact() .await .unwrap(); + assert!(result.is_success()); } #[tokio::test] async fn test_remove_engine_account() { let contract = deploy_and_init().await.unwrap(); let engine_account = AccountId::from_str("test.near").unwrap(); - contract + let result = contract .remove_engine_account(&engine_account) .max_gas() .transact() .await .unwrap(); + assert!(result.is_success()); } #[tokio::test] @@ -260,45 +263,49 @@ async fn test_storage_balance_bounds() { #[tokio::test] async fn test_pa_pause_feature() { let contract = deploy_and_init().await.unwrap(); - contract + let result = contract .pa_pause_feature("withdraw".to_string()) .max_gas() .transact() .await .unwrap(); + assert!(result.is_success()); } #[tokio::test] async fn test_pa_unpause_feature() { let contract = deploy_and_init().await.unwrap(); - contract + let result = contract .pa_unpause_feature("withdraw".to_string()) .max_gas() .transact() .await .unwrap(); + assert!(result.is_success()); } #[tokio::test] async fn test_acl_grant_role() { let contract = deploy_and_init().await.unwrap(); - contract + let result = contract .acl_grant_role("PauseManager".to_string(), OWNER_ID.to_string()) .max_gas() .transact() .await .unwrap(); + assert!(result.is_success()); } #[tokio::test] async fn test_acl_revoke_role() { let contract = deploy_and_init().await.unwrap(); - contract + let result = contract .acl_revoke_role("PauseManager".to_string(), OWNER_ID.to_string()) .max_gas() .transact() .await .unwrap(); + assert!(result.is_success()); } #[tokio::test] @@ -315,12 +322,13 @@ async fn test_acl_get_grantees() { #[tokio::test] async fn test_set_aurora_engine_account_id() { let contract = deploy_and_init().await.unwrap(); - contract + let result = contract .set_aurora_engine_account_id("test.near".to_string()) .max_gas() .transact() .await .unwrap(); + assert!(result.is_success()); } #[tokio::test] From d03e41334fcbf18d104b6425bf990c96e51b468c Mon Sep 17 00:00:00 2001 From: Olga Kunyavskaya Date: Fri, 5 Jan 2024 16:12:49 +0200 Subject: [PATCH 10/10] Update res/mock_eth_connector/Cargo.toml Co-authored-by: Karim --- res/mock_eth_connector/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/res/mock_eth_connector/Cargo.toml b/res/mock_eth_connector/Cargo.toml index 0328080..aba1869 100644 --- a/res/mock_eth_connector/Cargo.toml +++ b/res/mock_eth_connector/Cargo.toml @@ -21,4 +21,4 @@ panic = "abort" overflow-checks = true [patch.crates-io] -parity-secp256k1 = { git = 'https://github.com/paritytech/rust-secp256k1', rev = "d05fd8e" } \ No newline at end of file +parity-secp256k1 = { git = 'https://github.com/paritytech/rust-secp256k1', rev = "d05fd8e" }