-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add/remove relayer keys for fast submit calls
- Loading branch information
Showing
13 changed files
with
543 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
[formatting] | ||
# Align consecutive entries vertically. | ||
align_entries = false | ||
|
||
# Append trailing commas for multi-line arrays. | ||
array_trailing_comma = true | ||
|
||
# Expand arrays to multiple lines that exceed the maximum column width. | ||
array_auto_expand = false | ||
|
||
# Collapse arrays that don't exceed the maximum column width and don't contain comments. | ||
array_auto_collapse = true | ||
|
||
# Omit white space padding from single-line arrays | ||
compact_arrays = true | ||
|
||
# Omit white space padding from the start and end of inline tables. | ||
compact_inline_tables = false | ||
|
||
# Maximum column width in characters, affects array expansion and collapse, this doesn't take whitespace into account. | ||
# Note that this is not set in stone, and works on a best-effort basis. | ||
column_width = 80 | ||
|
||
# Indent based on tables and arrays of tables and their subtables, subtables out of order are not indented. | ||
indent_tables = true | ||
|
||
# The substring that is used for indentation, should be tabs or spaces (but technically can be anything). | ||
indent_string = ' ' | ||
|
||
# Add trailing newline at the end of the file if not present. | ||
trailing_newline = true | ||
|
||
# Alphabetically reorder keys that are not separated by empty lines. | ||
reorder_keys = false | ||
|
||
# Maximum amount of allowed consecutive blank lines. This does not affect the whitespace at the end of the document, as it is always stripped. | ||
allowed_blank_lines = 2 | ||
|
||
# Use CRLF for line endings. | ||
crlf = false |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use near_primitives::transaction::ExecutionStatus; | ||
|
||
pub fn assert_execution_status_failure( | ||
execution_status: ExecutionStatus, | ||
err_msg: &str, | ||
panic_msg: &str, | ||
) { | ||
// Usually the converted to string has either of following two messages formats: | ||
// "Action #0: Smart contract panicked: ERR_MSG [src/some_file.rs:LINE_NUMBER:COLUMN_NUMBER]" | ||
// "right: 'MISMATCHED_DATA': ERR_MSG [src/some_file.rs:LINE_NUMBER:COLUMN_NUMBER]" | ||
// So the ": ERR_MSG [" pattern should catch all invariants of error, even if one of the errors | ||
// message is a subset of another one (e.g. `ERR_MSG_FAILED` is a subset of `ERR_MSG_FAILED_FOO`) | ||
let expected_err_msg_pattern = format!(": {}", err_msg); | ||
|
||
match execution_status { | ||
ExecutionStatus::Failure(err) => { | ||
println!("Error: {}", err); | ||
assert!(err.to_string().contains(&expected_err_msg_pattern)); | ||
} | ||
_ => panic!("{}", panic_msg), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
use crate::prelude::U256; | ||
use crate::test_utils::asserts::assert_execution_status_failure; | ||
use crate::test_utils::{str_to_account_id, AuroraRunner}; | ||
use aurora_engine::parameters::NewCallArgs; | ||
use aurora_engine_types::types::ZERO_YOCTO; | ||
use borsh::BorshSerialize; | ||
use near_crypto::PublicKey; | ||
use near_primitives::account::AccessKeyPermission; | ||
use near_sdk_sim::{ExecutionResult, UserAccount}; | ||
use std::str::FromStr; | ||
|
||
const PUBLIC_KEY: &str = "ed25519:3gyjNWQWMZNrzqWLhwxzQqfeDFyd3KhXjzmwCqzVCRuF"; | ||
const PUBLIC_KEY_BUDGET: u128 = 1_000_000; | ||
|
||
// there are multiple deploy_evm implementations but their API is not good enough | ||
// TODO replace with near-workspaces | ||
fn deploy_evm_with_relayer() -> AuroraAccount { | ||
let aurora_runner = AuroraRunner::default(); | ||
let main_account = near_sdk_sim::init_simulator(None); | ||
|
||
let sim_aurora_account = format!( | ||
"{}.{}", | ||
aurora_runner.aurora_account_id, | ||
main_account.account_id() | ||
); | ||
let contract_account = main_account.deploy( | ||
aurora_runner.code.code(), | ||
sim_aurora_account.parse().unwrap(), | ||
5 * near_sdk_sim::STORAGE_AMOUNT, | ||
); | ||
let prover_account = str_to_account_id("prover.near"); | ||
|
||
let new_args = NewCallArgs { | ||
chain_id: crate::prelude::u256_to_arr(&U256::from(aurora_runner.chain_id)), | ||
owner_id: str_to_account_id(main_account.account_id.as_str()), | ||
bridge_prover_id: prover_account, | ||
upgrade_delay_blocks: 1, | ||
}; | ||
main_account | ||
.call( | ||
contract_account.account_id.clone(), | ||
"new", | ||
&new_args.try_to_vec().unwrap(), | ||
near_sdk_sim::DEFAULT_GAS, | ||
0, | ||
) | ||
.assert_success(); | ||
|
||
AuroraAccount { | ||
owner: main_account, | ||
contract: contract_account, | ||
} | ||
} | ||
|
||
pub struct AuroraAccount { | ||
pub owner: UserAccount, | ||
pub contract: UserAccount, | ||
} | ||
|
||
fn add_relayer_key_call(user: &UserAccount, runner: &AuroraAccount) -> ExecutionResult { | ||
user.call( | ||
runner.contract.account_id.clone(), | ||
"add_relayer_key", | ||
format!("{{\"public_key\": \"{PUBLIC_KEY}\"}}").as_bytes(), | ||
near_sdk_sim::DEFAULT_GAS, | ||
PUBLIC_KEY_BUDGET, | ||
) | ||
} | ||
|
||
fn remove_relayer_key_call(user: &UserAccount, runner: &AuroraAccount) -> ExecutionResult { | ||
user.call( | ||
runner.contract.account_id.clone(), | ||
"remove_relayer_key", | ||
format!("{{\"public_key\": \"{PUBLIC_KEY}\"}}").as_bytes(), | ||
near_sdk_sim::DEFAULT_GAS, | ||
ZERO_YOCTO.as_u128(), | ||
) | ||
} | ||
|
||
#[test] | ||
fn test_relayer_keys_mgmt_access() { | ||
let runner = deploy_evm_with_relayer(); | ||
|
||
let result = add_relayer_key_call(&runner.contract, &runner); | ||
assert_execution_status_failure( | ||
result.outcome().clone().status, | ||
"ERR_NOT_ALLOWED", | ||
"Expected failure as public key does not exist", | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_relayer_keys_mgmt() { | ||
let runner = deploy_evm_with_relayer(); | ||
|
||
add_relayer_key_call(&runner.owner, &runner).assert_success(); | ||
|
||
let pk = PublicKey::from_str(PUBLIC_KEY).unwrap(); | ||
let ak = runner | ||
.contract | ||
.borrow_runtime() | ||
.view_access_key(runner.contract.account_id.clone().as_str(), &pk) | ||
.unwrap(); | ||
let fk = match ak.permission { | ||
AccessKeyPermission::FullAccess => panic!("Expected function access key"), | ||
AccessKeyPermission::FunctionCall(fk) => fk, | ||
}; | ||
assert_eq!(fk.allowance.unwrap(), PUBLIC_KEY_BUDGET); | ||
assert_eq!(fk.method_names.join(","), "submit"); | ||
|
||
remove_relayer_key_call(&runner.owner, &runner).assert_success(); | ||
let ak = runner | ||
.contract | ||
.borrow_runtime() | ||
.view_access_key(runner.contract.account_id.clone().as_str(), &pk); | ||
|
||
assert_eq!(ak, None); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
|
||
pub mod account_id; | ||
pub mod parameters; | ||
pub mod public_key; | ||
pub mod storage; | ||
pub mod types; | ||
|
||
|
Oops, something went wrong.