Skip to content

Commit

Permalink
fix: make confirmed_and_unconfirmed_balance deterministic
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-da committed Oct 16, 2024
1 parent 1979842 commit 793aa63
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
15 changes: 10 additions & 5 deletions src/models/state/wallet/wallet_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1526,10 +1526,9 @@ mod tests {
#[traced_test]
#[tokio::test]
async fn confirmed_and_unconfirmed_balance() -> Result<()> {
let mut rng = thread_rng();
let network = Network::RegTest;
let network = Network::Main;
let mut global_state_lock =
mock_genesis_global_state(network, 0, WalletSecret::new_random()).await;
mock_genesis_global_state(network, 0, WalletSecret::devnet_wallet()).await;
let change_key = global_state_lock
.lock_guard_mut()
.await
Expand Down Expand Up @@ -1560,24 +1559,30 @@ mod tests {

// generate an output that our wallet cannot claim.
let outputs = vec![(
ReceivingAddress::from(GenerationReceivingAddress::derive_from_seed(rng.gen())),
ReceivingAddress::from(GenerationReceivingAddress::derive_from_seed(
tip_digest,
)),
send_amt,
)];

let tx_outputs = gs.generate_tx_outputs(outputs, UtxoNotificationMedium::OnChain);
let timestamp = gs.chain.light_state().header().timestamp + Timestamp::minutes(1);

info!("START transaction generation!");
let (tx, _change_output) = gs
.create_transaction(
tx_outputs,
change_key,
UtxoNotificationMedium::OnChain,
NeptuneCoins::zero(),
Timestamp::now(),
timestamp,
)
.await?;
tx
};

info!("transaction generation DONE!");

// add the tx to the mempool.
// note that the wallet should be notified of these changes.
global_state_lock
Expand Down
6 changes: 4 additions & 2 deletions src/tests/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,9 @@ pub async fn add_block_to_archival_state(
/// For now we use databases on disk. In-memory databases would be nicer.
pub fn unit_test_data_directory(network: Network) -> Result<DataDirectory> {
let mut rng = rand::thread_rng();
let user = env::var("USER").unwrap_or_else(|_| "default".to_string());
let tmp_root: PathBuf = env::temp_dir()
.join("neptune-unit-tests")
.join(format!("neptune-unit-tests-{}", user))
.join(Path::new(&Alphanumeric.sample_string(&mut rng, 16)));

DataDirectory::get(Some(tmp_root), network)
Expand Down Expand Up @@ -811,7 +812,8 @@ pub async fn mine_block_to_wallet(global_state_lock: &mut GlobalStateLock) -> Re
let state = global_state_lock.lock_guard().await;
let tip_block = state.chain.light_state();

let timestamp = Timestamp::now();
// we use a deterministic timestamp so we can use cached proofs.
let timestamp = tip_block.kernel.header.timestamp + Timestamp::millis(TARGET_BLOCK_INTERVAL);
let (transaction, coinbase_expected_utxo) =
crate::mine_loop::create_block_transaction(tip_block, &state, timestamp).await?;

Expand Down

0 comments on commit 793aa63

Please sign in to comment.