diff --git a/eth-connector-tests/src/connector.rs b/eth-connector-tests/src/connector.rs index 2b7e5a2..000f5ad 100644 --- a/eth-connector-tests/src/connector.rs +++ b/eth-connector-tests/src/connector.rs @@ -397,25 +397,26 @@ async fn test_ft_transfer_call_user_message() { let contract = TestContract::new().await.unwrap(); contract.call_deposit_eth_to_near().await.unwrap(); contract.call_deposit_contract().await.unwrap(); - let user_acc = contract.contract_account("eth_recipient").await.unwrap(); - - let receiver_id = contract.contract.id(); - let balance = contract - .get_eth_on_near_balance(user_acc.id()) + contract + .set_and_check_access_right(contract.contract.id()) .await .unwrap(); - assert_eq!(balance.0, DEPOSITED_AMOUNT); - let balance = contract - .get_eth_on_near_balance(contract.contract.id()) - .await - .unwrap(); - assert_eq!(balance.0, DEPOSITED_CONTRACT); + let user_acc = contract.contract_account("eth_recipient").await.unwrap(); + let receiver_id = contract.contract.id(); let transfer_amount: U128 = 50.into(); let memo: Option = None; let message = ""; - // Send to non-engine contract with wrong message should failed + + let is_exist = contract + .contract + .is_engine_account_exist(receiver_id) + .await + .unwrap(); + assert!(is_exist.result); + + // Send to engine contract with wrong message should failed let res = user_acc .ft_transfer_call( &receiver_id, @@ -426,42 +427,41 @@ async fn test_ft_transfer_call_user_message() { .max_gas() .deposit(ONE_YOCTO) .transact() - .await - .unwrap(); - assert!(res.is_success()); - + .await; + if let Err(err) = res { + assert!(contract.check_error_message(&err, "ERR_INVALID_ON_TRANSFER_MESSAGE_FORMAT")); + } let balance = contract.get_eth_on_near_balance(receiver_id).await.unwrap(); - assert_eq!(balance.0, DEPOSITED_CONTRACT + transfer_amount.0); + assert_eq!(balance.0, DEPOSITED_CONTRACT); let balance = contract .get_eth_on_near_balance(user_acc.id()) .await .unwrap(); - assert_eq!(balance.0, DEPOSITED_AMOUNT - transfer_amount.0); + assert_eq!(balance.0, DEPOSITED_AMOUNT); - contract - .set_and_check_access_right(contract.contract.id()) + let balance = contract + .get_eth_on_near_balance(contract.contract.id()) .await .unwrap(); + assert_eq!(balance.0, DEPOSITED_CONTRACT); - contract.set_engine_account(receiver_id).await.unwrap(); - - let is_exist = contract - .contract - .is_engine_account_exist(receiver_id) - .await - .unwrap(); - assert!(is_exist.result); + contract.remove_engine_account(receiver_id).await.unwrap(); - // Send to engine contract with wrong message should failed + // Send to non-engine contract with wrong message should not failed let res = user_acc - .ft_transfer_call(&receiver_id, transfer_amount, memo, message.to_string()) + .ft_transfer_call( + &receiver_id, + transfer_amount, + memo.clone(), + message.to_string(), + ) .max_gas() .deposit(ONE_YOCTO) .transact() - .await; - if let Err(err) = res { - assert!(contract.check_error_message(&err, "ERR_INVALID_ON_TRANSFER_MESSAGE_FORMAT")); - } + .await + .unwrap(); + assert!(res.is_success()); + let balance = contract.get_eth_on_near_balance(receiver_id).await.unwrap(); assert_eq!(balance.0, DEPOSITED_CONTRACT + transfer_amount.0); let balance = contract diff --git a/eth-connector-tests/src/utils.rs b/eth-connector-tests/src/utils.rs index b391da9..1324ff4 100644 --- a/eth-connector-tests/src/utils.rs +++ b/eth-connector-tests/src/utils.rs @@ -254,6 +254,19 @@ impl TestContract { Ok(()) } + pub async fn remove_engine_account(&self, engine_account: &AccountId) -> anyhow::Result<()> { + let res = self + .contract + .remove_engine_account(engine_account) + .max_gas() + .deposit(ONE_YOCTO) + .transact() + .await + .unwrap(); + assert!(res.is_success()); + Ok(()) + } + #[must_use] pub fn mock_proof( &self, diff --git a/eth-connector/src/lib.rs b/eth-connector/src/lib.rs index 993c8b2..569d6ab 100644 --- a/eth-connector/src/lib.rs +++ b/eth-connector/src/lib.rs @@ -248,6 +248,10 @@ impl EthConnectorContract { used_proofs: LookupSet::new(StorageKey::Proof), known_engine_accounts: LookupSet::new(StorageKey::EngineAccounts), }; + + this.known_engine_accounts + .insert(&this.connector.aurora_engine_account_id); + this.register_if_not_exists(&env::current_account_id()); this.register_if_not_exists(owner_id);