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

feat!: add assert_ne and revert_with_log revert signals #27

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Changes from all commits
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
16 changes: 16 additions & 0 deletions src/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ pub const FAILED_ASSERT_EQ_SIGNAL: u64 = 0xffff_ffff_ffff_0003;
/// Revert with this value for a failing call to `std::assert::assert`.
pub const FAILED_ASSERT_SIGNAL: u64 = 0xffff_ffff_ffff_0004;

/// Revert with this value for a failing call to `std::assert::assert_ne`.
pub const FAILED_ASSERT_NE_SIGNAL: u64 = 0xffff_ffff_ffff_0005;

/// Revert with this value for a failing call to `std::revert::revert_with_log`.
pub const REVERT_WITH_LOG_SIGNAL: u64 = 0xffff_ffff_ffff_0006;

#[derive(Error, Debug)]
pub enum ErrorSignal {
#[error("Failing call to `std::revert::require`")]
Expand All @@ -27,6 +33,10 @@ pub enum ErrorSignal {
AssertEq,
#[error("Failing call to `std::assert::assert`")]
Assert,
#[error("Failing call to `std::assert::assert_ne`")]
AssertNe,
#[error("Failing call to `std::revert::revert_with_log`")]
RevertWithLog,
}

#[derive(Error, Debug)]
Expand All @@ -48,6 +58,10 @@ impl ErrorSignal {
Ok(Self::AssertEq)
} else if revert_code == FAILED_ASSERT_SIGNAL {
Ok(Self::Assert)
} else if revert_code == FAILED_ASSERT_NE_SIGNAL {
Ok(Self::AssertNe)
} else if revert_code == REVERT_WITH_LOG_SIGNAL {
Ok(Self::RevertWithLog)
} else {
Err(Error::UnknownRevertCode(revert_code))
}
Expand All @@ -62,6 +76,8 @@ impl ErrorSignal {
ErrorSignal::SendMessage => FAILED_SEND_MESSAGE_SIGNAL,
ErrorSignal::AssertEq => FAILED_ASSERT_EQ_SIGNAL,
ErrorSignal::Assert => FAILED_ASSERT_SIGNAL,
ErrorSignal::AssertNe => FAILED_ASSERT_NE_SIGNAL,
ErrorSignal::RevertWithLog => REVERT_WITH_LOG_SIGNAL,
}
}
}
Loading