Skip to content

Commit

Permalink
feat!: add assert_ne and revert_with_log revert signals (#27)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: 
- `ErrorSignal` has two new variants: `AssertNe` and `RevertWithLog`
  • Loading branch information
hal3e authored Dec 2, 2024
1 parent d75780a commit 47f1289
Showing 1 changed file with 16 additions and 0 deletions.
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,
}
}
}

0 comments on commit 47f1289

Please sign in to comment.