Skip to content

Commit

Permalink
Paymaster: Add wegld test
Browse files Browse the repository at this point in the history
  • Loading branch information
CostinCarabas committed Oct 10, 2023
1 parent fa1eecd commit 5c3d321
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion contracts/paymaster/src/forward_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub trait ForwardCall {

let mut err_result = MultiValueEncoded::new();
err_result.push(ManagedBuffer::new_from_bytes(ERR_CALLBACK_MSG));
err_result.push(err.err_msg.clone());
err_result.push(err.err_msg);

err_result
}
Expand Down
48 changes: 47 additions & 1 deletion contracts/paymaster/tests/paymaster_blackbox_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,19 @@ impl PaymasterTestState {

self
}
fn check_egld_balance(
&mut self,
address_expr: &str,
balance_expr: &str,
) -> &mut Self {
self.world
.check_state_step(CheckStateStep::new().put_account(
address_expr,
CheckAccount::new().balance(balance_expr),
));

self
}
}

#[test]
Expand Down Expand Up @@ -304,7 +317,40 @@ fn test_forward_call_sc_adder_multiple_payments() {
}

#[test]
fn test_forward_call_fails_wegld() {
fn test_forward_call_wegld() {
let mut state = PaymasterTestState::new();
state.deploy_paymaster_contract();
state.deploy_adder_contract();

state.check_esdt_balance(CALLER_ADDRESS_EXPR, FEE_TOKEN_ID_EXPR, BALANCE);
state.check_esdt_balance(CALLER_ADDRESS_EXPR, WEGLD_TOKEN_ID_EXPR, BALANCE);

// Call fails because unwrap amount is 0
state.world.sc_call(
ScCallStep::new()
.from(CALLER_ADDRESS_EXPR)
.esdt_transfer(FEE_TOKEN_ID_EXPR, 0, FEE_AMOUNT)
.esdt_transfer(WEGLD_TOKEN_ID_EXPR, 0, BALANCE)
.call(state.paymaster_contract.forward_execution(
state.relayer_address.clone(),
state.callee_sc_wegld_address.to_address(),
UNWRAP_ENDPOINT_NAME,
MultiValueEncoded::new(),
))
);

// Fee is kept by the relayer
let new_fee_amount: &str = "99980000";
state.check_esdt_balance(RELAYER_ADDRESS_EXPR, FEE_TOKEN_ID_EXPR, FEE_AMOUNT);
state.check_esdt_balance(CALLER_ADDRESS_EXPR, FEE_TOKEN_ID_EXPR, new_fee_amount);

// Caller has the original balance
state.check_egld_balance(CALLER_ADDRESS_EXPR, BALANCE);
}


#[test]
fn test_forward_call_fails_wegld_0_amount() {
let mut state = PaymasterTestState::new();
state.deploy_paymaster_contract();
state.deploy_adder_contract();
Expand Down

0 comments on commit 5c3d321

Please sign in to comment.