Skip to content

Commit

Permalink
Refactore tests for AccountId
Browse files Browse the repository at this point in the history
  • Loading branch information
mrLSD committed Jun 29, 2023
1 parent 245df69 commit e899d9b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 75 deletions.
24 changes: 3 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions eth-connector-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ hex = "0.4.3"
ethabi = "18.0"
rlp = { version = "0.5.0", default-features = false }
aurora-engine-migration-tool = { git = "https://github.com/aurora-is-near/aurora-engine-migration-tool.git" }
aurora-workspace-eth-connector = { git = "https://github.com/aurora-is-near/aurora-workspace.git", ref = "e9ddcc0bc4634509299695d3df6ebcc2e4f86c94" }
aurora-workspace-utils = { git = "https://github.com/aurora-is-near/aurora-workspace.git", ref = "e9ddcc0bc4634509299695d3df6ebcc2e4f86c94" }
aurora-workspace-eth-connector = { git = "https://github.com/aurora-is-near/aurora-workspace.git", rev = "7510af1bfd0c70713c7a48891e4a448ce0571cca" }
aurora-workspace-utils = { git = "https://github.com/aurora-is-near/aurora-workspace.git", rev = "7510af1bfd0c70713c7a48891e4a448ce0571cca" }

[features]
migration-tests = []
32 changes: 5 additions & 27 deletions eth-connector-tests/src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,6 @@ async fn test_ft_transfer_call_user_message() {
.contract
.is_engine_account_exist(receiver_id)
.await
.transact()
.await
.unwrap();
assert!(is_exist.result);

Expand Down Expand Up @@ -503,8 +501,6 @@ async fn test_set_and_check_engine_account() {
.contract
.is_engine_account_exist(contract.contract.id())
.await
.transact()
.await
.unwrap();
assert!(is_exist.result);
}
Expand Down Expand Up @@ -1275,14 +1271,12 @@ async fn test_storage_deposit() {
.contract
.storage_balance_bounds()
.await
.transact()
.await
.unwrap()
.result;

let res = contract
.contract
.storage_deposit(Some(user_acc.id().clone()), None)
.storage_deposit(Some(&user_acc.id().clone()), None)

This comment has been minimized.

Copy link
@aleksuss

aleksuss Jun 29, 2023

Collaborator

.clone() is redundant here. You need a reference.

.max_gas()
.deposit(bounds.min.0)
.transact()
Expand All @@ -1297,8 +1291,6 @@ async fn test_storage_deposit() {
.contract
.storage_balance_of(contract.contract.id().clone())
.await
.transact()
.await
.unwrap()
.result;
assert_eq!(balance.available.0, 0);
Expand Down Expand Up @@ -1491,13 +1483,11 @@ async fn test_engine_storage_deposit() {
.contract
.storage_balance_bounds()
.await
.transact()
.await
.unwrap()
.result;

let res = user_acc
.engine_storage_deposit(user_acc.id().clone(), Some(user_acc.id().clone()), None)
.engine_storage_deposit(user_acc.id().clone(), Some(&user_acc.id().clone()), None)

This comment has been minimized.

Copy link
@aleksuss

aleksuss Jun 29, 2023

Collaborator

And here.

.max_gas()
.deposit(bounds.min.0)
.transact()
Expand All @@ -1513,7 +1503,7 @@ async fn test_engine_storage_deposit() {

let res = contract
.contract
.engine_storage_deposit(user_acc.id().clone(), Some(user_acc.id().clone()), None)
.engine_storage_deposit(user_acc.id().clone(), Some(&user_acc.id().clone()), None)
.max_gas()
.deposit(bounds.min.0)
.transact()
Expand All @@ -1528,8 +1518,6 @@ async fn test_engine_storage_deposit() {
.contract
.storage_balance_of(contract.contract.id().clone())
.await
.transact()
.await
.unwrap()
.result;
assert_eq!(balance.available.0, 0);
Expand All @@ -1545,8 +1533,6 @@ async fn test_engine_storage_withdraw() {
.contract
.storage_balance_bounds()
.await
.transact()
.await
.unwrap()
.result;

Expand All @@ -1568,7 +1554,7 @@ async fn test_engine_storage_withdraw() {

let res = contract
.contract
.engine_storage_deposit(user_acc.id().clone(), Some(user_acc.id().clone()), None)
.engine_storage_deposit(user_acc.id().clone(), Some(&user_acc.id().clone()), None)
.max_gas()
.deposit(bounds.min.0)
.transact()
Expand Down Expand Up @@ -1600,8 +1586,6 @@ async fn test_engine_storage_unregister() {
.contract
.storage_balance_bounds()
.await
.transact()
.await
.unwrap()
.result;

Expand All @@ -1621,7 +1605,7 @@ async fn test_engine_storage_unregister() {

let res = contract
.contract
.engine_storage_deposit(user_acc.id().clone(), Some(user_acc.id().clone()), None)
.engine_storage_deposit(user_acc.id().clone(), Some(&user_acc.id().clone()), None)
.max_gas()
.deposit(bounds.min.0)
.transact()
Expand Down Expand Up @@ -1681,16 +1665,12 @@ async fn test_manage_engine_accounts() {
.contract
.is_engine_account_exist(&acc1)
.await
.transact()
.await
.unwrap();
assert!(is_exist.result);
let is_exist = contract
.contract
.is_engine_account_exist(&acc2)
.await
.transact()
.await
.unwrap();
assert!(is_exist.result);

Expand All @@ -1706,8 +1686,6 @@ async fn test_manage_engine_accounts() {
.contract
.is_engine_account_exist(&acc1)
.await
.transact()
.await
.unwrap();
assert!(!is_exist.result);
}
Expand Down
6 changes: 0 additions & 6 deletions eth-connector-tests/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,6 @@ async fn test_migration_state() {
.contract
.check_migration_correctness(args)
.await
.transact()
.await
.unwrap()
.result;
assert_eq!(res, MigrationCheckResult::Success);
Expand All @@ -186,8 +184,6 @@ async fn test_migration_state() {
.contract
.check_migration_correctness(args)
.await
.transact()
.await
.unwrap()
.result;
assert_eq!(res, MigrationCheckResult::Success);
Expand All @@ -208,8 +204,6 @@ async fn test_migration_state() {
.contract
.check_migration_correctness(args)
.await
.transact()
.await
.unwrap()
.result;
assert_eq!(res, MigrationCheckResult::Success);
Expand Down
26 changes: 7 additions & 19 deletions eth-connector-tests/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ impl TestContract {
.contract
.is_used_proof(proof)
.await
.transact()
.await
.expect("call_is_used_proof")
.result)
}
Expand All @@ -152,8 +150,6 @@ impl TestContract {
.contract
.ft_balance_of(account.clone())
.await
.transact()
.await
.expect("get_eth_on_near_balance")
.result)
}
Expand All @@ -163,8 +159,6 @@ impl TestContract {
.contract
.ft_total_supply()
.await
.transact()
.await
.expect("total_supply")
.result)
}
Expand All @@ -183,17 +177,11 @@ impl TestContract {

pub async fn register_user(&self, user: &str) -> anyhow::Result<AccountId> {
let account_id = AccountId::try_from(user.to_string())?;
let bounds = self
.contract
.storage_balance_bounds()
.await
.transact()
.await?
.result;
let bounds = self.contract.storage_balance_bounds().await?.result;

let res = self
.contract
.storage_deposit(Some(account_id.clone()), None)
.storage_deposit(Some(&account_id.clone()), None)
.max_gas()
.deposit(bounds.min.into())
.transact()
Expand All @@ -214,15 +202,15 @@ impl TestContract {
anyhow::bail!("set_access_right failed");
}

let res = self
let res: String = self
.contract
.get_account_with_access_right()
.await
.transact()
.await?
.result;
.result
.into();
let acc_id = AccountId::try_from(res.clone())?;

if &res != acc {
if &acc_id != acc {
anyhow::bail!("check access_right fail: {res:?} != {acc:?}");
}
Ok(())
Expand Down

0 comments on commit e899d9b

Please sign in to comment.