feat(DbTx): add get_by_encoded_key (#13171)

This commit is contained in:
Hai | RISE
2024-12-06 20:58:17 +07:00
committed by GitHub
parent 634db30b6b
commit fdff4f18f2
6 changed files with 88 additions and 7 deletions

View File

@ -219,9 +219,12 @@ impl Account {
///
/// In case of a mismatch, `Err(Error::Assertion)` is returned.
pub fn assert_db(&self, address: Address, tx: &impl DbTx) -> Result<(), Error> {
let account = tx.get::<tables::PlainAccountState>(address)?.ok_or_else(|| {
Error::Assertion(format!("Expected account ({address}) is missing from DB: {self:?}"))
})?;
let account =
tx.get_by_encoded_key::<tables::PlainAccountState>(&address)?.ok_or_else(|| {
Error::Assertion(format!(
"Expected account ({address}) is missing from DB: {self:?}"
))
})?;
assert_equal(self.balance, account.balance, "Balance does not match")?;
assert_equal(self.nonce.to(), account.nonce, "Nonce does not match")?;