Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LouiseMedova committed Aug 26, 2024
1 parent 00778e1 commit e8aaf38
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ fn transfer_tokens_success() {
let bridging_payment = Program::bridge_payment(&system);

let account_id: u64 = 10000;
let amount = U256::from(10_000_000_000 as u64);
let amount = U256::from(10_000_000_000_u64);

vft.mint(ADMIN_ID, account_id.into(), amount, false);
vft.approve(account_id, bridging_payment.id().into(), amount, false);
vft.approve(account_id, bridging_payment.id(), amount, false);
vft.grant_burner_role(ADMIN_ID, vft_gateway.id(), false);
vft_gateway.map_vara_to_eth_address(ADMIN_ID, vft.id(), [2; 20].into(), false);

Expand Down
2 changes: 1 addition & 1 deletion gear-programs/bridging-payment/src/wasm/tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ pub trait BridgingPayment {

impl BridgingPayment for Program<'_> {
fn bridge_payment(system: &System) -> Program<'_> {
let program = Program::current(&system);
let program = Program::current(system);
let init_config = InitConfig::new(
ADMIN_ID.into(),
VFT_GATEWAY_ID.into(),
Expand Down
6 changes: 3 additions & 3 deletions gear-programs/vft-gateway/src/wasm/tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ impl VftGateway for Program<'_> {
let result = self.send_bytes_with_gas(from, payload, with_gas, 0);
if panic {
assert!(result.main_failed());
return Err(Error::MessageFailed);
Err(Error::MessageFailed)
} else {
let log_entry = result
.log()
Expand All @@ -202,7 +202,7 @@ impl VftGateway for Program<'_> {
<(String, String, Result<(U256, H160), Error>)>::decode(&mut log_entry.payload())
.expect("Unable to decode reply"); // Panic if decoding fails

return reply.2;
reply.2
}
}

Expand Down Expand Up @@ -245,6 +245,6 @@ impl VftGateway for Program<'_> {
<(String, String, Vec<(MessageId, MessageInfo)>)>::decode(&mut log_entry.payload())
.expect("Unable to decode reply"); // Panic if decoding fails

return reply.2;
reply.2
}
}
27 changes: 14 additions & 13 deletions gear-programs/vft-gateway/src/wasm/tests/vft_gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn test_successful_transfer_vara_to_eth() {
let vft_gateway = Program::vft_gateway(&system);

let account_id: u64 = 10000;
let amount = U256::from(10_000_000_000 as u64);
let amount = U256::from(10_000_000_000_u64);
let gas = 100_000_000_000;

vft.mint(ADMIN_ID, account_id.into(), amount);
Expand Down Expand Up @@ -59,13 +59,13 @@ async fn test_transfer_fails_due_to_token_panic() {
let vft_gateway = Program::vft_gateway(&system);

let account_id: u64 = 10000;
let amount = U256::from(10_000_000_000 as u64);
let amount = U256::from(10_000_000_000_u64);
let gas = 100_000_000_000;

vft_gateway.map_vara_to_eth_address(ADMIN_ID, vft.id(), [2; 20].into());
let reply =
vft_gateway.transfer_vara_to_eth(account_id, vft.id(), amount, [3; 20].into(), gas, false);
assert_eq!(reply, Err(Error::ReplyError));
assert_eq!(reply, Err(Error::ReplyFailure));

let msg_tracker = vft_gateway.get_msg_tracker_state();
assert!(msg_tracker.is_empty());
Expand All @@ -87,7 +87,7 @@ async fn test_transfer_fails_due_to_token_rejecting_request() {
let vft_gateway = Program::vft_gateway(&system);

let account_id: u64 = 10000;
let amount = U256::from(10_000_000_000 as u64);
let amount = U256::from(10_000_000_000_u64);
let gas = 100_000_000_000;

vft_gateway.map_vara_to_eth_address(ADMIN_ID, vft.id(), [2; 20].into());
Expand All @@ -114,7 +114,7 @@ async fn test_bridge_builtin_panic_with_token_mint() {
let vft_gateway = Program::vft_gateway(&system);

let account_id: u64 = 10000;
let amount = U256::from(10_000_000_000 as u64);
let amount = U256::from(10_000_000_000_u64);
let gas = 100_000_000_000;

vft.mint(ADMIN_ID, account_id.into(), amount);
Expand All @@ -123,7 +123,7 @@ async fn test_bridge_builtin_panic_with_token_mint() {
vft_gateway.map_vara_to_eth_address(ADMIN_ID, vft.id(), [2; 20].into());
let reply =
vft_gateway.transfer_vara_to_eth(account_id, vft.id(), amount, [3; 20].into(), gas, false);
assert_eq!(reply, Err(Error::ReplyError));
assert_eq!(reply, Err(Error::ReplyFailure));

let msg_tracker = vft_gateway.get_msg_tracker_state();
assert_eq!(msg_tracker[0].1.status, MessageStatus::MintTokensStep);
Expand All @@ -132,7 +132,7 @@ async fn test_bridge_builtin_panic_with_token_mint() {
vft.grant_minter_role(ADMIN_ID, vft_gateway.id());

let reply = vft_gateway.handle_interrupted_transfer(account_id, msg_tracker[0].0);
assert_eq!(reply, Err(Error::TokensRefundedError));
assert_eq!(reply, Err(Error::TokensRefunded));
}

#[tokio::test]
Expand All @@ -147,8 +147,8 @@ async fn test_multiple_transfers() {

let account_id1: u64 = 10001;
let account_id2: u64 = 10002;
let amount1 = U256::from(10_000_000_000 as u64);
let amount2 = U256::from(5_000_000_000 as u64);
let amount1 = U256::from(10_000_000_000_u64);
let amount2 = U256::from(5_000_000_000_u64);
let gas = 100_000_000_000;

vft.mint(ADMIN_ID, account_id1.into(), amount1);
Expand Down Expand Up @@ -194,8 +194,8 @@ fn test_transfer_vara_to_eth_insufficient_balance() {
let vft_gateway = Program::vft_gateway(&system);

let account_id: u64 = 10000;
let amount = U256::from(10_000_000_000 as u64);
let excessive_amount = U256::from(20_000_000_000 as u64); // More than the available balance
let amount = U256::from(10_000_000_000_u64);
let excessive_amount = U256::from(20_000_000_000_u64); // More than the available balance
let gas = 100_000_000_000;

vft.mint(ADMIN_ID, account_id.into(), amount);
Expand All @@ -211,12 +211,13 @@ fn test_transfer_vara_to_eth_insufficient_balance() {
gas,
false,
);
assert_eq!(reply, Err(Error::ReplyError));
assert_eq!(reply, Err(Error::ReplyFailure));

let balance = vft.balance_of(account_id.into());
assert_eq!(balance, amount); // Balance should remain unchanged
}

#[ignore]
#[tokio::test]
async fn test_transfer_fails_due_to_gas_depletion_after_bridge_reply() {
let system = System::new();
Expand All @@ -228,7 +229,7 @@ async fn test_transfer_fails_due_to_gas_depletion_after_bridge_reply() {
let vft_gateway = Program::vft_gateway(&system);

let account_id: u64 = 10001;
let amount = U256::from(10_000_000_000 as u64);
let amount = U256::from(10_000_000_000_u64);
let gas = 50_000_000_000;

vft.mint(ADMIN_ID, account_id.into(), amount);
Expand Down

0 comments on commit e8aaf38

Please sign in to comment.