Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eth-connector: switch to near-plugins #39

Merged
merged 11 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
parity-secp256k1 = { git = 'https://github.com/paritytech/rust-secp256k1', rev = "d05fd8e" }
53 changes: 35 additions & 18 deletions eth-connector/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use crate::operation::{
CallDeposit, CallEngineFtTransfer, CallEngineFtTransferCall, CallEngineStorageDeposit,
CallEngineStorageUnregister, CallEngineStorageWithdraw, CallEngineWithdraw, CallFtTransfer,
CallFtTransferCall, CallMigrate, CallNew, CallRemoveEngineAccount, CallSetAccessRight,
CallSetEngineAccount, CallSetPausedFlags, CallStorageDeposit, CallStorageUnregister,
CallStorageWithdraw, CallWithdraw, ViewCheckMigrationCorrectness, ViewFtBalanceOf,
ViewFtMetadata, ViewFtTotalSupply, ViewGetAccountWithAccessRight, ViewGetBridgeProver,
ViewGetPausedFlags, ViewIsEngineAccountExist, ViewIsOwner, 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, 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;
Expand Down Expand Up @@ -176,12 +177,22 @@ 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 set_access_right(&self, account: &impl AsRef<str>) -> CallSetAccessRight {
CallSetAccessRight::call(&self.contract).args_json((account.as_ref(),))
pub fn pa_unpause_feature(&self, key: String) -> CallPaUnpauseFeature {
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}))
}

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 {
Expand All @@ -208,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
Expand All @@ -231,12 +247,9 @@ impl EthConnectorContract {
ViewGetPausedFlags::view(&self.contract)
}

pub fn get_account_with_access_right(&self) -> ViewGetAccountWithAccessRight {
ViewGetAccountWithAccessRight::view(&self.contract)
}

pub fn is_owner(&self) -> ViewIsOwner {
ViewIsOwner::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_used_proof(&self, proof: Proof) -> ViewIsUsedProof {
Expand Down Expand Up @@ -268,4 +281,8 @@ impl EthConnectorContract {
pub fn ft_balance_of(&self, account_id: &impl AsRef<str>) -> 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!({}))
}
}
30 changes: 21 additions & 9 deletions eth-connector/src/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ impl_call_return![
(CallSetEngineAccount, Call::SetEngineAccount),
(CallRemoveEngineAccount, Call::RemoveEngineAccount),
(CallDeposit, Call::Deposit),
(CallSetPausedFlags, Call::SetPausedFlags),
(CallSetAccessRight, Call::SetAccessRight),
(CallPaPauseFeature, Call::PaPauseFeature),
(CallPaUnpauseFeature, Call::PaUnpauseFeature),
(CallAclRevokeRole, Call::AclRevokeRole),
(CallAclGrantRole, Call::AclGrantRole),
(CallMigrate, Call::Migrate),
(CallSetAuroraEngineAccountId, Call::SetAuroraEngineAccountId)
];

impl_call_return![
Expand All @@ -44,10 +47,11 @@ 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<AccountId>, View::AclGetGrantees, json),
(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)]
Expand All @@ -68,9 +72,12 @@ pub(crate) enum Call {
EngineStorageDeposit,
EngineStorageUnregister,
EngineStorageWithdraw,
SetPausedFlags,
SetAccessRight,
PaPauseFeature,
PaUnpauseFeature,
AclRevokeRole,
AclGrantRole,
Migrate,
SetAuroraEngineAccountId,
}

impl AsRef<str> for Call {
Expand All @@ -93,9 +100,12 @@ impl AsRef<str> 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",
AclRevokeRole => "acl_revoke_role",
Migrate => "migrate",
SetAuroraEngineAccountId => "set_aurora_engine_account_id",
}
}
}
Expand All @@ -109,11 +119,12 @@ pub enum View {
StorageBalanceBounds,
IsEngineAccountExist,
GetPausedFlags,
GetAccountWithAccessRight,
AclGetGrantees,
IsOwner,
CheckMigrationCorrectness,
IsUsedProof,
GetBridgeProver,
GetAuroraEngineAccountId,
}

impl AsRef<str> for View {
Expand All @@ -127,11 +138,12 @@ impl AsRef<str> 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",
GetBridgeProver => "get_bridge_prover",
GetAuroraEngineAccountId => "get_aurora_engine_account_id",
}
}
}
96 changes: 55 additions & 41 deletions eth-connector/tests/fungible_token_tests.rs
Original file line number Diff line number Diff line change
@@ -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, UNPAUSE_ALL,
};
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};
Expand Down Expand Up @@ -260,28 +258,77 @@ 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
.unwrap();
aleksuss marked this conversation as resolved.
Show resolved Hide resolved
}

#[tokio::test]
async fn test_set_access_right() {
async fn test_pa_unpause_feature() {
let contract = deploy_and_init().await.unwrap();
let account = AccountId::from_str("test.near").unwrap();
contract
.set_access_right(&account)
.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_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();
Expand Down Expand Up @@ -357,39 +404,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();
Expand Down
Loading