Skip to content

Commit cf24748

Browse files
committed
fix: update UTxOIdentifier initialization to use TxHash
1 parent 93e3b9b commit cf24748

File tree

4 files changed

+40
-46
lines changed

4 files changed

+40
-46
lines changed

modules/address_state/src/state.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ impl State {
233233
#[cfg(test)]
234234
mod tests {
235235
use super::*;
236-
use acropolis_common::{Address, AddressDelta, UTxOIdentifier, Value};
236+
use acropolis_common::{Address, AddressDelta, TxHash, UTxOIdentifier, Value};
237237
use tempfile::tempdir;
238238

239239
fn dummy_address() -> Address {
@@ -284,7 +284,7 @@ mod tests {
284284
let mut state = setup_state_and_store().await?;
285285

286286
let addr = dummy_address();
287-
let utxo = UTxOIdentifier::new(0, 0, 0);
287+
let utxo = UTxOIdentifier::new(TxHash::default(), 0);
288288
let tx_id = TxIdentifier::new(0, 0);
289289
let deltas = vec![delta(&addr, tx_id, vec![], vec![utxo], 0, 1)];
290290

@@ -295,7 +295,7 @@ mod tests {
295295
let utxos = state.get_address_utxos(&addr).await?;
296296
assert!(utxos.is_some());
297297
assert_eq!(utxos.as_ref().unwrap().len(), 1);
298-
assert_eq!(utxos.as_ref().unwrap()[0], UTxOIdentifier::new(0, 0, 0));
298+
assert_eq!(utxos.as_ref().unwrap()[0], UTxOIdentifier::new(TxHash::default(), 0));
299299

300300
// Drain volatile to immutable
301301
state.volatile.epoch_start_block = 1;
@@ -305,7 +305,7 @@ mod tests {
305305
let utxos = state.get_address_utxos(&addr).await?;
306306
assert!(utxos.is_some());
307307
assert_eq!(utxos.as_ref().unwrap().len(), 1);
308-
assert_eq!(utxos.as_ref().unwrap()[0], UTxOIdentifier::new(0, 0, 0));
308+
assert_eq!(utxos.as_ref().unwrap()[0], UTxOIdentifier::new(TxHash::default(), 0));
309309

310310
// Perisist immutable to disk
311311
state.immutable.persist_epoch(0, &state.config).await?;
@@ -314,7 +314,7 @@ mod tests {
314314
let utxos = state.get_address_utxos(&addr).await?;
315315
assert!(utxos.is_some());
316316
assert_eq!(utxos.as_ref().unwrap().len(), 1);
317-
assert_eq!(utxos.as_ref().unwrap()[0], UTxOIdentifier::new(0, 0, 0));
317+
assert_eq!(utxos.as_ref().unwrap()[0], UTxOIdentifier::new(TxHash::default(), 0));
318318

319319
Ok(())
320320
}
@@ -326,7 +326,7 @@ mod tests {
326326
let mut state = setup_state_and_store().await?;
327327

328328
let addr = dummy_address();
329-
let utxo = UTxOIdentifier::new(0, 0, 0);
329+
let utxo = UTxOIdentifier::new(TxHash::default(), 0);
330330
let tx_id_create = TxIdentifier::new(0, 0);
331331
let tx_id_spend = TxIdentifier::new(1, 0);
332332

@@ -377,8 +377,8 @@ mod tests {
377377
let mut state = setup_state_and_store().await?;
378378

379379
let addr = dummy_address();
380-
let utxo_old = UTxOIdentifier::new(0, 0, 0);
381-
let utxo_new = UTxOIdentifier::new(0, 1, 0);
380+
let utxo_old = UTxOIdentifier::new(TxHash::default(), 0);
381+
let utxo_new = UTxOIdentifier::new(TxHash::default(), 1);
382382
let tx_id_create_old = TxIdentifier::new(0, 0);
383383
let tx_id_spend_old_create_new = TxIdentifier::new(1, 0);
384384

modules/assets_state/src/state.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -688,11 +688,7 @@ mod tests {
688688
asset_registry::{AssetId, AssetRegistry},
689689
state::{AssetsStorageConfig, State, StoreTransactions, CIP67_LABEL_222, CIP68_LABEL_100},
690690
};
691-
use acropolis_common::{
692-
Address, AddressDelta, AssetInfoRecord, AssetMetadata, AssetMetadataStandard, AssetName,
693-
Datum, NativeAsset, NativeAssetDelta, PolicyId, ShelleyAddress, TxIdentifier, TxOutput,
694-
TxUTxODeltas, UTxOIdentifier, Value,
695-
};
691+
use acropolis_common::{Address, AddressDelta, AssetInfoRecord, AssetMetadata, AssetMetadataStandard, AssetName, Datum, NativeAsset, NativeAssetDelta, PolicyId, ShelleyAddress, TxHash, TxIdentifier, TxOutput, TxUTxODeltas, UTxOIdentifier, Value};
696692
use serde_cbor::Value as CborValue;
697693

698694
fn dummy_policy(byte: u8) -> PolicyId {
@@ -845,7 +841,7 @@ mod tests {
845841

846842
fn make_output(policy_id: PolicyId, asset_name: AssetName, datum: Option<Vec<u8>>) -> TxOutput {
847843
TxOutput {
848-
utxo_identifier: UTxOIdentifier::new(0, 0, 0),
844+
utxo_identifier: UTxOIdentifier::new(TxHash::default(), 0),
849845
address: dummy_address(),
850846
value: Value {
851847
lovelace: 0,
@@ -1263,7 +1259,7 @@ mod tests {
12631259
StoreTransactions::None,
12641260
);
12651261

1266-
let input = UTxOIdentifier::new(0, 0, 0);
1262+
let input = UTxOIdentifier::new(TxHash::default(), 0);
12671263
let output = make_output(policy_id, name, None);
12681264

12691265
let tx_deltas = TxUTxODeltas {
@@ -1428,15 +1424,15 @@ mod tests {
14281424
tx_identifier,
14291425
inputs: Vec::new(),
14301426
outputs: vec![TxOutput {
1431-
utxo_identifier: UTxOIdentifier::new(0, 0, 0),
1427+
utxo_identifier: UTxOIdentifier::new(TxHash::default(), 0),
14321428
..output.clone()
14331429
}],
14341430
};
14351431
let tx2 = TxUTxODeltas {
14361432
tx_identifier,
14371433
inputs: Vec::new(),
14381434
outputs: vec![TxOutput {
1439-
utxo_identifier: UTxOIdentifier::new(0, 0, 1),
1435+
utxo_identifier: UTxOIdentifier::new(TxHash::default(), 1),
14401436
..output
14411437
}],
14421438
};
@@ -1470,15 +1466,15 @@ mod tests {
14701466
tx_identifier: TxIdentifier::new(9, 0),
14711467
inputs: Vec::new(),
14721468
outputs: vec![TxOutput {
1473-
utxo_identifier: UTxOIdentifier::new(9, 0, 0),
1469+
utxo_identifier: UTxOIdentifier::new(TxHash::default(), 0),
14741470
..out1
14751471
}],
14761472
};
14771473
let tx2 = TxUTxODeltas {
14781474
tx_identifier: TxIdentifier::new(10, 0),
14791475
inputs: Vec::new(),
14801476
outputs: vec![TxOutput {
1481-
utxo_identifier: UTxOIdentifier::new(10, 0, 0),
1477+
utxo_identifier: UTxOIdentifier::new(TxHash::default(), 0),
14821478
..out2
14831479
}],
14841480
};
@@ -1513,23 +1509,23 @@ mod tests {
15131509
tx_identifier: TxIdentifier::new(9, 0),
15141510
inputs: Vec::new(),
15151511
outputs: vec![TxOutput {
1516-
utxo_identifier: UTxOIdentifier::new(9, 0, 0),
1512+
utxo_identifier: UTxOIdentifier::new(TxHash::default(), 0),
15171513
..base_output.clone()
15181514
}],
15191515
};
15201516
let tx2 = TxUTxODeltas {
15211517
tx_identifier: TxIdentifier::new(8, 0),
15221518
inputs: Vec::new(),
15231519
outputs: vec![TxOutput {
1524-
utxo_identifier: UTxOIdentifier::new(8, 0, 0),
1520+
utxo_identifier: UTxOIdentifier::new(TxHash::default(), 0),
15251521
..base_output.clone()
15261522
}],
15271523
};
15281524
let tx3 = TxUTxODeltas {
15291525
tx_identifier: TxIdentifier::new(7, 0),
15301526
inputs: Vec::new(),
15311527
outputs: vec![TxOutput {
1532-
utxo_identifier: UTxOIdentifier::new(7, 0, 0),
1528+
utxo_identifier: UTxOIdentifier::new(TxHash::default(), 0),
15331529
..base_output
15341530
}],
15351531
};

modules/utxo_state/src/state.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -399,10 +399,7 @@ struct AddressTxMap {
399399
mod tests {
400400
use super::*;
401401
use crate::InMemoryImmutableUTXOStore;
402-
use acropolis_common::{
403-
Address, AssetName, BlockHash, ByronAddress, Datum, Era, NativeAsset, ReferenceScript,
404-
TxUTxODeltas, Value,
405-
};
402+
use acropolis_common::{Address, AssetName, BlockHash, ByronAddress, Datum, Era, NativeAsset, ReferenceScript, TxHash, TxUTxODeltas, Value};
406403
use config::Config;
407404
use tokio::sync::Mutex;
408405

@@ -449,7 +446,7 @@ mod tests {
449446
let reference_script_bytes = vec![0xde, 0xad, 0xbe, 0xef];
450447

451448
let output = TxOutput {
452-
utxo_identifier: UTxOIdentifier::new(0, 0, 0),
449+
utxo_identifier: UTxOIdentifier::new(TxHash::default(), 0),
453450
address: create_address(99),
454451
value: Value::new(
455452
42,
@@ -523,7 +520,7 @@ mod tests {
523520
async fn observe_input_spends_utxo() {
524521
let mut state = new_state();
525522
let output = TxOutput {
526-
utxo_identifier: UTxOIdentifier::new(0, 0, 0),
523+
utxo_identifier: UTxOIdentifier::new(TxHash::default(), 0),
527524
address: create_address(99),
528525
value: Value::new(
529526
42,
@@ -562,7 +559,7 @@ mod tests {
562559
async fn rollback_removes_future_created_utxos() {
563560
let mut state = new_state();
564561
let output = TxOutput {
565-
utxo_identifier: UTxOIdentifier::new(0, 0, 0),
562+
utxo_identifier: UTxOIdentifier::new(TxHash::default(), 0),
566563
address: create_address(99),
567564
value: Value::new(
568565
42,
@@ -603,7 +600,7 @@ mod tests {
603600

604601
// Create the UTXO in block 10
605602
let output = TxOutput {
606-
utxo_identifier: UTxOIdentifier::new(0, 0, 0),
603+
utxo_identifier: UTxOIdentifier::new(TxHash::default(), 0),
607604
address: create_address(99),
608605
value: Value::new(
609606
42,
@@ -653,7 +650,7 @@ mod tests {
653650
async fn prune_shifts_new_utxos_into_immutable() {
654651
let mut state = new_state();
655652
let output = TxOutput {
656-
utxo_identifier: UTxOIdentifier::new(0, 0, 0),
653+
utxo_identifier: UTxOIdentifier::new(TxHash::default(), 0),
657654
address: create_address(99),
658655
value: Value::new(
659656
42,
@@ -701,7 +698,7 @@ mod tests {
701698
async fn prune_deletes_old_spent_utxos() {
702699
let mut state = new_state();
703700
let output = TxOutput {
704-
utxo_identifier: UTxOIdentifier::new(0, 0, 0),
701+
utxo_identifier: UTxOIdentifier::new(TxHash::default(), 0),
705702
address: create_address(99),
706703
value: Value::new(
707704
42,
@@ -820,7 +817,7 @@ mod tests {
820817
state.register_address_delta_observer(observer.clone());
821818

822819
let output = TxOutput {
823-
utxo_identifier: UTxOIdentifier::new(0, 0, 0),
820+
utxo_identifier: UTxOIdentifier::new(TxHash::default(), 0),
824821
address: create_address(99),
825822
value: Value::new(
826823
42,

modules/utxo_state/src/volatile_index.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ impl VolatileIndex {
9797
// -- Tests --
9898
#[cfg(test)]
9999
mod tests {
100+
use acropolis_common::TxHash;
100101
use super::*;
101102

102103
#[test]
@@ -140,47 +141,47 @@ mod tests {
140141
assert_eq!(Some(1), index.first_block);
141142
assert_eq!(2, index.blocks.len());
142143

143-
let utxo = UTxOIdentifier::new(42, 42, 42);
144+
let utxo = UTxOIdentifier::new(TxHash::default(), 422);
144145
index.add_utxo(&utxo);
145146

146147
assert!(index.blocks[0].is_empty());
147148
assert!(!index.blocks[1].is_empty());
148-
assert_eq!(42, index.blocks[1][0].output_index());
149+
assert_eq!(422, index.blocks[1][0].output_index);
149150
}
150151

151152
#[test]
152153
fn prune_before_deletes_and_calls_back_with_utxos() {
153154
let mut index = VolatileIndex::new();
154155
index.add_block(1);
155-
index.add_utxo(&UTxOIdentifier::new(1, 1, 1));
156-
index.add_utxo(&UTxOIdentifier::new(2, 2, 2));
156+
index.add_utxo(&UTxOIdentifier::new(TxHash::default(), 1));
157+
index.add_utxo(&UTxOIdentifier::new(TxHash::default(), 2));
157158
index.add_block(2);
158-
index.add_utxo(&UTxOIdentifier::new(3, 3, 3));
159+
index.add_utxo(&UTxOIdentifier::new(TxHash::default(), 3));
159160

160161
let pruned = index.prune_before(2);
161162
assert_eq!(Some(2), index.first_block);
162163
assert_eq!(1, index.blocks.len());
163164
assert_eq!(2, pruned.len());
164-
assert_eq!(1, pruned[0].output_index());
165-
assert_eq!(2, pruned[1].output_index());
165+
assert_eq!(1, pruned[0].output_index);
166+
assert_eq!(2, pruned[1].output_index);
166167
}
167168

168169
#[test]
169170
fn prune_on_or_after_deletes_and_calls_back_with_utxos() {
170171
let mut index = VolatileIndex::new();
171172
index.add_block(1);
172-
index.add_utxo(&UTxOIdentifier::new(1, 1, 1));
173-
index.add_utxo(&UTxOIdentifier::new(2, 2, 2));
173+
index.add_utxo(&UTxOIdentifier::new(TxHash::default(), 1));
174+
index.add_utxo(&UTxOIdentifier::new(TxHash::default(), 2));
174175
index.add_block(2);
175-
index.add_utxo(&UTxOIdentifier::new(3, 3, 3));
176+
index.add_utxo(&UTxOIdentifier::new(TxHash::default(), 3));
176177
let pruned = index.prune_on_or_after(1);
177178
assert_eq!(Some(1), index.first_block);
178179
assert_eq!(0, index.blocks.len());
179180
assert_eq!(3, pruned.len());
180181

181182
// Note reverse order of blocks
182-
assert_eq!(3, pruned[0].output_index());
183-
assert_eq!(1, pruned[1].output_index());
184-
assert_eq!(2, pruned[2].output_index());
183+
assert_eq!(3, pruned[0].output_index);
184+
assert_eq!(1, pruned[1].output_index);
185+
assert_eq!(2, pruned[2].output_index);
185186
}
186187
}

0 commit comments

Comments
 (0)