Skip to content

Commit

Permalink
Fix claim fee
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteNacked committed Sep 23, 2024
1 parent 2f7fa7d commit da86292
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gear-programs/bridging-payment-vara-supply/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct Program;
#[program]
impl Program {
pub fn new(init_config: InitConfig) -> Self {
BridgingPayment::<GStdExecContext>::seed(init_config, GStdExecContext::new());
BridgingPayment::<GStdExecContext>::seed(init_config);
Self
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ impl<T> BridgingPayment<T>
where
T: ExecContext,
{
pub fn seed(config: InitConfig, exec_context: T) {
pub fn seed(config: InitConfig) {
unsafe {
DATA = Some(BridgingPaymentData {
admin_address: exec_context.actor_id(),
admin_address: config.admin_address,
vft_treasury_address: config.vft_treasury_address,
});
CONFIG = Some(config.config);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use gtest::{Program, System};
use gtest::{Log, Program, System};
use sails_rs::prelude::*;

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

#[test]
Expand All @@ -30,4 +30,13 @@ fn deposit_to_treasury_success() {
system.mint_to(account_id, FEE);
bridging_payment.request_transaction(account_id, amount, [1; 20].into(), vft.id(), false);
assert_eq!(vft.balance_of(account_id.into()), U256::zero());
assert_eq!(vft.balance_of(VFT_TREASURY_ID.into()), amount);

// Claim fee
bridging_payment.reclaim_fee(ADMIN_ID, false);
system
.get_mailbox(ADMIN_ID)
.claim_value(Log::builder().dest(ADMIN_ID))
.unwrap();
assert_eq!(system.balance_of(ADMIN_ID), FEE);
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ create_mock!(
pub trait BridgingPayment {
fn bridge_payment(system: &System) -> Program<'_>;
create_function!(request_transaction, "RequestToGateway", amount: U256, receiver: H160, vara_token_id: ActorId);
create_function!(reclaim_fee, "ReclaimFee");
}

impl BridgingPayment for Program<'_> {
Expand All @@ -170,11 +171,12 @@ impl BridgingPayment for Program<'_> {
Config::new(FEE, 15_000_000_000, 100_000_000_000, 1000, 50_000_000_000),
);
let payload = ["New".encode(), init_config.encode()].concat();
let result = program.send_bytes(10, payload);
let result = program.send_bytes(ADMIN_ID, payload);
assert!(!result.main_failed());
program
}
implement_function!(request_transaction, "BridgingPayment", "RequestTransaction", amount: U256, receiver: H160, vara_token_id: ActorId; true);
implement_function!(reclaim_fee, "BridgingPayment", "ReclaimFee");
}

pub trait Token {
Expand Down

0 comments on commit da86292

Please sign in to comment.