Skip to content

Commit b8d4a76

Browse files
CopilotSteake
andcommitted
Add integration test for blockchain persistence
- Add test_blockchain_with_persistent_storage test - Add tempfile as dev dependency for bitcell-node - Verify accounts persist correctly across blockchain restarts Co-authored-by: Steake <530040+Steake@users.noreply.github.com>
1 parent 145749e commit b8d4a76

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

crates/bitcell-node/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ base64 = "0.21"
3939

4040
[dev-dependencies]
4141
proptest.workspace = true
42+
tempfile = "3.23.0"

crates/bitcell-node/src/blockchain.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,4 +566,38 @@ mod tests {
566566
// Test reward becomes 0 after 64 halvings
567567
assert_eq!(Blockchain::calculate_block_reward(HALVING_INTERVAL * 64), 0);
568568
}
569+
570+
#[test]
571+
fn test_blockchain_with_persistent_storage() {
572+
use tempfile::TempDir;
573+
574+
let temp_dir = TempDir::new().unwrap();
575+
let data_path = temp_dir.path();
576+
let sk = Arc::new(SecretKey::generate());
577+
let pubkey = [1u8; 33];
578+
579+
// Create blockchain with storage and modify state
580+
{
581+
let metrics = MetricsRegistry::new();
582+
let blockchain = Blockchain::with_storage(sk.clone(), metrics, data_path).unwrap();
583+
584+
// Add an account to state
585+
let mut state = blockchain.state.write().unwrap();
586+
state.update_account(pubkey, bitcell_state::Account {
587+
balance: 1000,
588+
nonce: 5,
589+
});
590+
}
591+
592+
// Recreate blockchain from same storage and verify persistence
593+
{
594+
let metrics = MetricsRegistry::new();
595+
let blockchain = Blockchain::with_storage(sk, metrics, data_path).unwrap();
596+
597+
let state = blockchain.state.read().unwrap();
598+
let account = state.get_account_owned(&pubkey).expect("Account should persist");
599+
assert_eq!(account.balance, 1000);
600+
assert_eq!(account.nonce, 5);
601+
}
602+
}
569603
}

0 commit comments

Comments
 (0)