mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-01-03 05:43:08 +00:00
fix increase nonce and add test
This commit is contained in:
parent
e9b11af986
commit
c6fb383adf
@ -98,10 +98,18 @@ impl SequencerAccountsStore {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn increase_nonce(&mut self, account_addr: &AccountAddress) -> Option<u64> {
|
||||
let acc_data = self.accounts.get_mut(account_addr)?;
|
||||
acc_data.nonce += 1;
|
||||
Some(acc_data.nonce)
|
||||
///Update `account_addr` nonce,
|
||||
///
|
||||
/// Returns previous nonce
|
||||
pub fn increase_nonce(&mut self, account_addr: &AccountAddress) -> u64 {
|
||||
if let Some(acc_data) = self.accounts.get_mut(account_addr) {
|
||||
let old_nonce = acc_data.nonce;
|
||||
acc_data.nonce += 1;
|
||||
old_nonce
|
||||
} else {
|
||||
self.register_account(*account_addr);
|
||||
self.increase_nonce(account_addr)
|
||||
}
|
||||
}
|
||||
|
||||
///Remove account from storage
|
||||
@ -289,4 +297,14 @@ mod tests {
|
||||
assert!(seq_acc_store.contains_account(&[1; 32]));
|
||||
assert_eq!(seq_acc_store.get_account_balance(&[1; 32]), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_increase_nonce() {
|
||||
let mut account_store = SequencerAccountsStore::default();
|
||||
let address = [1; 32];
|
||||
let first_nonce = account_store.increase_nonce(&address);
|
||||
assert_eq!(first_nonce, 0);
|
||||
let second_nonce = account_store.increase_nonce(&address);
|
||||
assert_eq!(second_nonce, 1);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user