Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteNacked committed Sep 23, 2024
1 parent e5f7ef2 commit 3befc2b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ use gtest::{Program, System};
use sails_rs::prelude::*;

mod utils;
use utils::{BridgingPayment, Token, VftTreasury, ADMIN_ID, FEE, TOKEN_ID};
use utils::{
BridgingPayment, GearBridgeBuiltinMock, Token, VftTreasury, ADMIN_ID, BRIDGE_BUILTIN_ID, FEE,
TOKEN_ID,
};

#[test]
fn deposit_to_treasury_success() {
let system = System::new();
system.init_logger();

let vft = Program::token(&system, TOKEN_ID);
let bridge_built_in = Program::mock_with_id(&system, BRIDGE_BUILTIN_ID, GearBridgeBuiltinMock);
// Init bridge builtin
assert!(!bridge_built_in.send_bytes(ADMIN_ID, vec![]).main_failed());

let vft_treasury = Program::vft_treasury(&system);
let bridging_payment = Program::bridge_payment(&system);
Expand All @@ -19,7 +25,7 @@ fn deposit_to_treasury_success() {

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

system.mint_to(account_id, FEE);
bridging_payment.request_transaction(account_id, amount, [1; 20].into(), vft.id(), false);
Expand Down
47 changes: 31 additions & 16 deletions gear-programs/bridging-payment-vara-supply/src/wasm/tests/utils.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use bridging_payment_vara_supply::services::{Config, InitConfig};
use extended_vft_wasm::WASM_BINARY as TOKEN_WASM_BINARY;
use gtest::{Program, System, WasmProgram};
use sails_rs::prelude::*;
use vft_treasury_wasm::WASM_BINARY as VFT_TREASURY_WASM_BINARY;

use sails_rs::prelude::*;
pub const ADMIN_ID: u64 = 1000;
pub const FEE: u128 = 10_000_000_000_000;
pub const VFT_TREASURY_ID: u64 = 100;
pub const TOKEN_ID: u64 = 200;
pub const ETH_CLIENT_ID: u64 = 500;
pub const BRIDGE_BUILTIN_ID: u64 = 300;

// macros
macro_rules! create_function {
Expand Down Expand Up @@ -108,7 +110,7 @@ macro_rules! implement_token_query {
};
}

macro_rules! create_ft_mock {
macro_rules! create_mock {
($name:ident, $handle_result:expr) => {
#[derive(Debug)]
pub struct $name;
Expand Down Expand Up @@ -137,18 +139,19 @@ macro_rules! create_ft_mock {
};
}

create_ft_mock!(FTMockError, Err("Error"));
create_ft_mock!(FTMockWrongReply, Ok(None));
create_ft_mock!(
FTMockReturnsFalse,
Ok(Some(
["Vft".encode(), "TransferFrom".encode(), false.encode()].concat()
))
);
create_ft_mock!(
FTMockReturnsTrue,
#[derive(Encode, Decode, Clone, Debug, PartialEq, Eq)]
pub enum Response {
MessageSent { nonce: U256, hash: H256 },
}

create_mock!(
GearBridgeBuiltinMock,
Ok(Some(
["Vft".encode(), "TransferFrom".encode(), true.encode()].concat()
Response::MessageSent {
nonce: U256::from(1),
hash: [1; 32].into(),
}
.encode(),
))
);

Expand Down Expand Up @@ -196,18 +199,30 @@ impl Token for Program<'_> {

pub trait VftTreasury {
fn vft_treasury(system: &System) -> Program<'_>;
create_function!(_map_vara_to_eth_address, "MapVaraToEthAddress", vara_token_id: ActorId, eth_token_id: H160);
create_function!(map_vara_to_eth_address, "MapVaraToEthAddress", eth_token_id: H160, vara_token_id: ActorId);
}

impl VftTreasury for Program<'_> {
fn vft_treasury(system: &System) -> Program<'_> {
let program =
Program::from_binary_with_id(system, VFT_TREASURY_ID, VFT_TREASURY_WASM_BINARY);
let init_config = vft_treasury_app::services::InitConfig::new(1010.into());
let init_config = vft_treasury_app::services::InitConfig::new(
[1; 20].into(),
BRIDGE_BUILTIN_ID.into(),
ETH_CLIENT_ID.into(),
vft_treasury_app::services::Config::new(
15_000_000_000,
15_000_000_000,
15_000_000_000,
100,
15_000_000_000,
),
);

let payload = ["New".encode(), init_config.encode()].concat();
let result = program.send_bytes(ADMIN_ID, payload);
assert!(!result.main_failed());
program
}
implement_function!(_map_vara_to_eth_address, "VftTreasury", "MapVaraToEthAddress", vara_token_id: ActorId, eth_token_id: H160; false);
implement_function!(map_vara_to_eth_address, "VftTreasury", "MapVaraToEthAddress", eth_token_id: H160, vara_token_id: ActorId; false);
}

0 comments on commit 3befc2b

Please sign in to comment.