Skip to content

Commit

Permalink
Set known engine accounts on init (#87)
Browse files Browse the repository at this point in the history
* set aurora engine contract on init

* fmt
  • Loading branch information
olga24912 authored Jul 3, 2024
1 parent fff5b32 commit fe42244
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 34 deletions.
68 changes: 34 additions & 34 deletions eth-connector-tests/src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = 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,
Expand All @@ -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
Expand Down
13 changes: 13 additions & 0 deletions eth-connector-tests/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions eth-connector/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit fe42244

Please sign in to comment.