Skip to content

Commit c81e695

Browse files
committed
Add more tests
1 parent 3748c7a commit c81e695

File tree

4 files changed

+676
-8
lines changed

4 files changed

+676
-8
lines changed

Diff for: Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: p-token/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ spl-token-interface = { version = "^0", path = "../interface" }
2222

2323
[dev-dependencies]
2424
assert_matches = "1.5.0"
25+
num-traits = "0.2"
2526
solana-program-test = "2.1"
2627
solana-sdk = "2.1"
2728
spl-token = { version="^4", features=["no-entrypoint"] }

Diff for: p-token/tests/setup/mod.rs

+43
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,46 @@ pub mod account;
66
pub mod mint;
77

88
pub const TOKEN_PROGRAM_ID: Pubkey = Pubkey::new_from_array(spl_token_interface::program::ID);
9+
10+
#[macro_export]
11+
macro_rules! assert_instruction_error {
12+
( $error:expr, $matcher:pat ) => {
13+
match $error {
14+
solana_program_test::BanksClientError::TransactionError(
15+
solana_sdk::transaction::TransactionError::InstructionError(_, $matcher),
16+
) => {
17+
assert!(true)
18+
}
19+
err => assert!(false, "Expected instruction error but got '{:#?}'", err),
20+
};
21+
};
22+
}
23+
24+
#[macro_export]
25+
macro_rules! assert_custom_error {
26+
( $error:expr, $matcher:pat ) => {
27+
match $error {
28+
solana_program_test::BanksClientError::TransactionError(
29+
solana_sdk::transaction::TransactionError::InstructionError(
30+
_,
31+
solana_sdk::instruction::InstructionError::Custom(x),
32+
),
33+
) => match num_traits::FromPrimitive::from_i32(x as i32) {
34+
Some($matcher) => assert!(true),
35+
Some(other) => {
36+
assert!(
37+
false,
38+
"Expected another custom instruction error than '{:#?}'",
39+
other
40+
)
41+
}
42+
None => assert!(false, "Expected custom instruction error"),
43+
},
44+
err => assert!(
45+
false,
46+
"Expected custom instruction error but got '{:#?}'",
47+
err
48+
),
49+
};
50+
};
51+
}

0 commit comments

Comments
 (0)