Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove eth-connector fee logic #882

Merged
merged 4 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 59 additions & 2 deletions engine-tests-connector/src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,64 @@ async fn test_ft_transfer_call_eth() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
async fn test_ft_transfer_call_without_fee() -> anyhow::Result<()> {
let contract = TestContract::new().await?;
contract.call_deposit_eth_to_near().await?;

let user_acc = contract
.create_sub_account(DEPOSITED_RECIPIENT_NAME)
.await?;
assert_eq!(
contract.get_eth_on_near_balance(user_acc.id()).await?.0,
DEPOSITED_AMOUNT,
);
assert_eq!(
contract
.get_eth_on_near_balance(contract.engine_contract.id())
.await?
.0,
0,
);

let transfer_amount: U128 = 50.into();
let message = RECIPIENT_ETH_ADDRESS;
let memo: Option<String> = None;
let res = user_acc
.call(contract.engine_contract.id(), "ft_transfer_call")
.args_json(json!({
"receiver_id": contract.engine_contract.id(),
"amount": transfer_amount,
"memo": memo,
"msg": message,
}))
.gas(DEFAULT_GAS)
.deposit(ONE_YOCTO)
.transact()
.await?;
assert!(res.is_success());

assert_eq!(
contract.get_eth_on_near_balance(user_acc.id()).await?.0,
DEPOSITED_AMOUNT - transfer_amount.0,
);
assert_eq!(
contract
.get_eth_on_near_balance(contract.engine_contract.id())
.await?
.0,
transfer_amount.0,
);
assert_eq!(
contract
.get_eth_balance(&validate_eth_address(RECIPIENT_ETH_ADDRESS),)
.await?,
transfer_amount.0,
);
assert_eq!(contract.total_supply().await?, DEPOSITED_AMOUNT);
Ok(())
}

#[tokio::test]
async fn test_ft_transfer_call_without_message() -> anyhow::Result<()> {
let contract = TestContract::new().await?;
Expand Down Expand Up @@ -438,8 +496,7 @@ async fn test_deposit_with_0x_prefix() -> anyhow::Result<()> {
let message = [CONTRACT_ACC, ":", "0x", &recipient_address_encoded].concat();
let fee: Fee = Fee::new(NEP141Wei::new(0));
let token_message_data =
TokenMessageData::parse_event_message_and_prepare_token_message_data(&message, fee)
.unwrap();
TokenMessageData::parse_event_message_and_prepare_token_message_data(&message).unwrap();

let deposit_event = DepositedEvent {
eth_custodian_address,
Expand Down
3 changes: 1 addition & 2 deletions engine-tests/src/tests/erc20_connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1020,8 +1020,7 @@ pub mod workspace {
let message = recipient_id.to_string();
let fee: Fee = Fee::new(NEP141Wei::new(0));
let token_message_data =
TokenMessageData::parse_event_message_and_prepare_token_message_data(&message, fee)
.unwrap();
TokenMessageData::parse_event_message_and_prepare_token_message_data(&message).unwrap();

let deposit_event = DepositedEvent {
eth_custodian_address,
Expand Down
3 changes: 1 addition & 2 deletions engine-tests/src/tests/standalone/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,7 @@ fn mock_proof(recipient_address: Address, deposit_amount: Wei) -> aurora_engine:
let fee = Fee::new(NEP141Wei::new(0));
let message = ["aurora", ":", recipient_address.encode().as_str()].concat();
let token_message_data: TokenMessageData =
TokenMessageData::parse_event_message_and_prepare_token_message_data(&message, fee)
.unwrap();
TokenMessageData::parse_event_message_and_prepare_token_message_data(&message).unwrap();

let deposit_event = DepositedEvent {
eth_custodian_address,
Expand Down
14 changes: 3 additions & 11 deletions engine-tests/src/utils/standalone/mocks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use aurora_engine::engine;
use aurora_engine::engine::Engine;
#[cfg(not(feature = "ext-connector"))]
use aurora_engine::parameters::InitCallArgs;
#[cfg(not(feature = "ext-connector"))]
use aurora_engine_modexp::ModExpAlgorithm;
use aurora_engine_sdk::env::{Env, DEFAULT_PREPAID_GAS};
use aurora_engine_sdk::io::IO;
#[cfg(not(feature = "ext-connector"))]
Expand Down Expand Up @@ -114,19 +112,13 @@ pub fn mint_evm_account<I: IO + Copy, E: Env>(
};

#[cfg(not(feature = "ext-connector"))]
deposit(io, &engine, &env.current_account_id(), address, balance);
deposit(io, &env.current_account_id(), address, balance);

engine.apply(std::iter::once(state_change), std::iter::empty(), false);
}

#[cfg(not(feature = "ext-connector"))]
fn deposit<I: IO + Copy, E: Env, M: ModExpAlgorithm>(
mut io: I,
engine: &Engine<I, E, M>,
aurora_account_id: &AccountId,
address: Address,
balance: Wei,
) {
fn deposit<I: IO + Copy>(mut io: I, aurora_account_id: &AccountId, address: Address, balance: Wei) {
const DEFAULT_GAS: u64 = 300_000_000_000_000;
let deposit_args = aurora_engine_types::parameters::connector::FinishDepositCallArgs {
new_owner_id: aurora_account_id.clone(),
Expand Down Expand Up @@ -165,7 +157,7 @@ fn deposit<I: IO + Copy, E: Env, M: ModExpAlgorithm>(
hex::encode(address.as_bytes())
),
};
connector.ft_on_transfer(engine, &transfer_args).unwrap();
connector.ft_on_transfer(&transfer_args).unwrap();
}

#[cfg(not(feature = "ext-connector"))]
Expand Down
Loading
Loading