Skip to content

Commit 32a27b4

Browse files
authored
chore: update ErrorCode and add require macro (#300)
* chore: update ErrorCode and add require macro * update scripts * bump litesvm version * update benchmark --------- Co-authored-by: Aursen <[email protected]>
1 parent d7391f6 commit 32a27b4

File tree

15 files changed

+40
-21
lines changed

15 files changed

+40
-21
lines changed

benches/program-bench/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ name = "bench"
99
harness = false
1010

1111
[dependencies]
12-
litesvm = "0.8"
12+
litesvm = "0.8.2"
1313
serde = "1.0"
1414
solana-hash = "3.0"
1515
solana-instruction = "3.0"

crates/errors/src/error_code.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use pinocchio::program_error::{ProgramError, ToStr};
22

33
#[derive(Debug, PartialEq, Eq)]
44
pub enum ErrorCode {
5-
InvalidProgramExecutable = 100,
5+
UnknownInstruction = 100,
66
AccountNotSigner,
77
AccountDiscriminatorMismatch,
88
HasOneConstraint,
@@ -12,7 +12,6 @@ pub enum ErrorCode {
1212
TokenConstraintViolated,
1313
BufferFull,
1414
InvalidReturnData,
15-
UnknownInstruction,
1615
InvalidDataLength,
1716
InvalidDataAlignment,
1817
}
@@ -22,7 +21,7 @@ impl TryFrom<u32> for ErrorCode {
2221

2322
fn try_from(value: u32) -> Result<Self, Self::Error> {
2423
match value {
25-
100 => Ok(ErrorCode::InvalidProgramExecutable),
24+
100 => Ok(ErrorCode::UnknownInstruction),
2625
101 => Ok(ErrorCode::AccountNotSigner),
2726
102 => Ok(ErrorCode::AccountDiscriminatorMismatch),
2827
103 => Ok(ErrorCode::HasOneConstraint),
@@ -32,9 +31,8 @@ impl TryFrom<u32> for ErrorCode {
3231
107 => Ok(ErrorCode::TokenConstraintViolated),
3332
108 => Ok(ErrorCode::BufferFull),
3433
109 => Ok(ErrorCode::InvalidReturnData),
35-
110 => Ok(ErrorCode::UnknownInstruction),
36-
111 => Ok(ErrorCode::InvalidDataLength),
37-
112 => Ok(ErrorCode::InvalidDataAlignment),
34+
110 => Ok(ErrorCode::InvalidDataLength),
35+
111 => Ok(ErrorCode::InvalidDataAlignment),
3836
_ => Err(ProgramError::InvalidArgument),
3937
}
4038
}
@@ -52,7 +50,7 @@ impl ToStr for ErrorCode {
5250
E: 'static + ToStr + TryFrom<u32>,
5351
{
5452
match self {
55-
ErrorCode::InvalidProgramExecutable => "Error: Program is not executable",
53+
ErrorCode::UnknownInstruction => "Error: Unknown instruction",
5654
ErrorCode::AccountNotSigner => "Error: Account is not a signer",
5755
ErrorCode::AccountDiscriminatorMismatch => {
5856
"Error: Discriminator did not match what was expected"
@@ -66,7 +64,6 @@ impl ToStr for ErrorCode {
6664
ErrorCode::TokenConstraintViolated => "Error: Token constraint was violated",
6765
ErrorCode::BufferFull => "Error: Buffer is full",
6866
ErrorCode::InvalidReturnData => "Error: The return data is invalid",
69-
ErrorCode::UnknownInstruction => "Error: Unknown instruction",
7067
ErrorCode::InvalidDataLength => "Error: Invalid data length",
7168
ErrorCode::InvalidDataAlignment => "Error: Invalid data alignment",
7269
}

crates/errors/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,12 @@ macro_rules! impl_error_logger {
8989
}
9090
};
9191
}
92+
93+
#[macro_export]
94+
macro_rules! require {
95+
( $constraint:expr, $error:expr ) => {
96+
if !$constraint {
97+
return Err($error.into());
98+
}
99+
};
100+
}

examples/anchor-cpi/tests/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ publish = false
66

77
[dev-dependencies]
88
bytemuck = "1.23"
9-
litesvm = "0.8"
9+
litesvm = "0.8.2"
1010
typhoon = { path = "../../../crates/lib" }
1111
solana-instruction = "3.0"
1212
solana-keypair = "3.0"

examples/counter/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ typhoon = { path = "../../crates/lib" }
2424
typhoon-idl-generator = { path = "../../crates/idl-generator" }
2525

2626
[dev-dependencies]
27-
litesvm = "0.8"
27+
litesvm = "0.8.2"
2828
solana-instruction = "3.0"
2929
solana-keypair = "3.0"
3030
solana-native-token = "3.0"

examples/cpi/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ unexpected_cfgs = { level = "warn", check-cfg = [
1515
bytemuck = "1.23"
1616
hand-interface = { path = "interfaces/hand" }
1717
lever-interface = { path = "interfaces/lever" }
18-
litesvm = "0.8"
18+
litesvm = "0.8.2"
1919
typhoon = { path = "../../crates/lib" }
2020
typhoon-instruction-builder = { path = "../../crates/instruction-builder" }
2121
solana-pubkey = "3.0"

examples/escrow/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ unexpected_cfgs = { level = "warn", check-cfg = [
1515
[workspace.dependencies]
1616
bytemuck = "1.23"
1717
escrow-interface = { path = "interfaces/escrow" }
18-
litesvm = "0.8"
18+
litesvm = "0.8.2"
1919
typhoon = { path = "../../crates/lib" }
2020
typhoon-token = { path = "../../crates/token" }
2121
typhoon-instruction-builder = { path = "../../crates/instruction-builder" }

examples/hello-world/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ unexpected_cfgs = { level = "warn", check-cfg = [
1919
typhoon = { path = "../../crates/lib" }
2020

2121
[dev-dependencies]
22-
litesvm = "0.8"
22+
litesvm = "0.8.2"
2323
solana-instruction = "3.0"
2424
solana-keypair = "3.0"
2525
solana-native-token = "3.0"

examples/instruction-data/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ bytemuck = { version = "1.21.0", features = ["derive"] }
2020
typhoon = { path = "../../crates/lib" }
2121

2222
[dev-dependencies]
23-
litesvm = "0.8"
23+
litesvm = "0.8.2"
2424
solana-instruction = "3.0"
2525
solana-keypair = "3.0"
2626
solana-native-token = "3.0"

examples/misc/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ solana-keypair = "3.0"
1818
misc-interface = { path = "interface" }
1919
typhoon = { path = "../../crates/lib" }
2020
typhoon-instruction-builder = { path = "../../crates/instruction-builder" }
21-
litesvm = "0.8"
21+
litesvm = "0.8.2"

0 commit comments

Comments
 (0)