Skip to content

Commit

Permalink
fix: unpause eth connector after init in tests (#938)
Browse files Browse the repository at this point in the history
## Description

The changes in the PR unpause all features of the eth connector since
they are now paused after initialization by default.
  • Loading branch information
aleksuss committed Jul 22, 2024
1 parent 932412d commit 5cd8278
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 30 deletions.
45 changes: 16 additions & 29 deletions engine-tests-connector/src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,7 @@ async fn test_ft_transfer_call_eth() -> anyhow::Result<()> {
);

let transfer_amount: U128 = 50.into();
let fee: u128 = 30;
let mut msg = U256::from(fee).as_byte_slice().to_vec();
msg.append(
&mut validate_eth_address(RECIPIENT_ETH_ADDRESS)
.as_bytes()
.to_vec(),
);

let message = [CONTRACT_ACC, hex::encode(msg).as_str()].join(":");
let message = ft_transfer_msg(CONTRACT_ACC, 30, RECIPIENT_ETH_ADDRESS);
let memo: Option<String> = None;
let res = user_acc
.call(contract.engine_contract.id(), "ft_transfer_call")
Expand Down Expand Up @@ -288,7 +280,7 @@ async fn test_ft_transfer_call_without_fee() -> anyhow::Result<()> {
);

let transfer_amount: U128 = 50.into();
let message = RECIPIENT_ETH_ADDRESS;
let message = ft_transfer_msg("relayer.root", 0, RECIPIENT_ETH_ADDRESS);
let memo: Option<String> = None;
let res = user_acc
.call(contract.engine_contract.id(), "ft_transfer_call")
Expand All @@ -302,7 +294,7 @@ async fn test_ft_transfer_call_without_fee() -> anyhow::Result<()> {
.deposit(ONE_YOCTO)
.transact()
.await?;
assert!(res.is_success());
assert!(res.is_success(), "{res:#?}");

assert_eq!(
contract.get_eth_on_near_balance(user_acc.id()).await?.0,
Expand Down Expand Up @@ -592,14 +584,7 @@ async fn test_ft_transfer_call_without_relayer() -> anyhow::Result<()> {
);

let transfer_amount: U128 = 50.into();
let fee: u128 = 30;
let mut msg = U256::from(fee).as_byte_slice().to_vec();
let recipient_address = validate_eth_address(RECIPIENT_ETH_ADDRESS);
msg.append(&mut recipient_address.as_bytes().to_vec());

let relayer_id = "relayer.root";
let message = [relayer_id, hex::encode(msg).as_str()].join(":");

let message = ft_transfer_msg("relayer.root", 30, RECIPIENT_ETH_ADDRESS);
let memo: Option<String> = None;
let res = user_acc
.call(contract.engine_contract.id(), "ft_transfer_call")
Expand All @@ -624,7 +609,9 @@ async fn test_ft_transfer_call_without_relayer() -> anyhow::Result<()> {
transfer_amount.0
);
assert_eq!(
contract.get_eth_balance(&recipient_address).await?,
contract
.get_eth_balance(&validate_eth_address(RECIPIENT_ETH_ADDRESS))
.await?,
transfer_amount.0
);
assert_eq!(contract.total_supply().await?, DEPOSITED_AMOUNT);
Expand All @@ -637,15 +624,7 @@ async fn test_ft_transfer_call_fee_greater_than_amount() -> anyhow::Result<()> {
contract.call_deposit_eth_to_near().await?;

let transfer_amount: U128 = 10.into();
let fee: u128 = 12;
let mut msg = U256::from(fee).as_byte_slice().to_vec();
msg.append(
&mut validate_eth_address(RECIPIENT_ETH_ADDRESS)
.as_bytes()
.to_vec(),
);
let relayer_id = "relayer.root";
let message = [relayer_id, hex::encode(msg).as_str()].join(":");
let message = ft_transfer_msg("relayer.root", 12, RECIPIENT_ETH_ADDRESS);
let memo: Option<String> = None;
let user_acc = contract
.create_sub_account(DEPOSITED_RECIPIENT_NAME)
Expand Down Expand Up @@ -1337,3 +1316,11 @@ async fn test_ft_metadata() -> anyhow::Result<()> {
assert_eq!(metadata.symbol, m.symbol);
Ok(())
}

fn ft_transfer_msg(relayer_id: &str, fee: u128, recipient: &str) -> String {
let mut msg = U256::from(fee).as_byte_slice().to_vec();
let recipient_address = validate_eth_address(recipient);

msg.extend(recipient_address.as_bytes());
[relayer_id, hex::encode(msg).as_str()].join(":")
}
10 changes: 9 additions & 1 deletion engine-tests-connector/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub struct TestContract {
}

impl TestContract {
pub async fn deploy_aurora_contract() -> anyhow::Result<(Contract, Contract, Account)> {
async fn deploy_aurora_contract() -> anyhow::Result<(Contract, Contract, Account)> {
use near_workspaces::{
types::{KeyType, SecretKey},
AccessKey,
Expand Down Expand Up @@ -141,6 +141,14 @@ impl TestContract {
.await?;
assert!(res.is_success());

let result = eth_connector_contract
.call("pa_unpause_feature")
.args_json(json!({ "key": "ALL" }))
.max_gas()
.transact()
.await?;
assert!(result.is_success(), "{result:#?}");

let chain_id = [0u8; 32];
let res = engine_contract
.call("new")
Expand Down
9 changes: 9 additions & 0 deletions engine-tests/src/utils/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ async fn init_eth_connector(aurora: &EngineContract) -> anyhow::Result<()> {
.await?;
assert!(result.is_success());

// By default, the contract is paused. So we need to unpause it.
let result = contract
.call("pa_unpause_feature")
.args_json(json!({ "key": "ALL" }))
.max_gas()
.transact()
.await?;
assert!(result.is_success());

let result = aurora
.set_eth_connector_contract_account(contract_account.id(), WithdrawSerializeType::Borsh)
.transact()
Expand Down

0 comments on commit 5cd8278

Please sign in to comment.