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

Add relayer signer to ER swap #377

Merged
merged 6 commits into from
Feb 4, 2025
Merged
Changes from 1 commit
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: 61 additions & 0 deletions contracts/svm/testing/tests/swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1118,3 +1118,64 @@ fn test_swap_wrong_mint_fee() {
InstructionError::Custom(AnchorErrorCode::ConstraintRaw.into()),
);
}


#[test]
fn test_swap_fail_wrong_relayer_signer() {
danimhr marked this conversation as resolved.
Show resolved Hide resolved
let SwapSetupResult {
mut svm,
user,
searcher,
token_searcher,
token_user,
router_ta_mint_user,
..
} = setup_swap(SwapSetupParams {
platform_fee_bps: 1000,
token_program_searcher: spl_token::ID,
token_decimals_searcher: 6,
token_program_user: spl_token::ID,
token_decimals_user: 6,
});

let express_relay_metadata = get_express_relay_metadata(&mut svm);

// user token fee
let swap_args = SwapArgs {
deadline: svm.get_sysvar::<Clock>().unix_timestamp,
amount_searcher: token_searcher.get_amount_with_decimals(1.),
amount_user: token_user.get_amount_with_decimals(1.),
referral_fee_bps: 1500,
fee_token: FeeToken::User,
};

let wrong_relayer_signer = Keypair::new();
let instructions = build_swap_instructions(
searcher.pubkey(),
user.pubkey(),
None,
None,
router_ta_mint_user,
express_relay_metadata.fee_receiver_relayer,
token_searcher.mint,
token_user.mint,
Some(token_searcher.token_program),
Some(token_user.token_program),
swap_args,
None,
None,
wrong_relayer_signer.pubkey(), // <--- wrong relayer signer
);
let result = submit_transaction(
&mut svm,
&instructions,
&searcher,
&[&searcher, &user, &wrong_relayer_signer],
)
.unwrap_err();
assert_custom_error(
result.err,
4,
InstructionError::Custom(AnchorErrorCode::ConstraintHasOne.into()),
);
}
Loading