Skip to content

Commit c839343

Browse files
committed
test(lander): keep linkage of other tx when assigning new nonce
1 parent 646b1b0 commit c839343

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

  • rust/main/lander/src/adapter/chains/ethereum/nonce/state/assign/tests

rust/main/lander/src/adapter/chains/ethereum/nonce/state/assign/tests/tests_assign.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,40 @@ fn create_tx(uuid: TransactionUuid, status: TransactionStatus) -> Transaction {
1515
make_tx(uuid, status, None, None)
1616
}
1717

18+
#[tokio::test]
19+
async fn test_assign_next_nonce_and_keep_old_linkage() {
20+
let (_, tx_db, nonce_db) = tmp_dbs();
21+
let address = Address::random();
22+
let metrics = EthereumAdapterMetrics::dummy_instance();
23+
let state = Arc::new(NonceManagerState::new(nonce_db, tx_db, address, metrics));
24+
25+
let other_tx_uuid = TransactionUuid::random();
26+
27+
// Assign nonce and build linkage for other tx
28+
let nonce = state
29+
.assign_next_nonce(&other_tx_uuid, &None)
30+
.await
31+
.unwrap();
32+
state
33+
.set_tracked_tx_uuid(&nonce, &other_tx_uuid)
34+
.await
35+
.unwrap();
36+
37+
let tx_uuid = TransactionUuid::random();
38+
// Now assign a new nonce to a new tx but with an old nonce of the other tx
39+
let new_nonce = state
40+
.assign_next_nonce(&tx_uuid, &Some(nonce))
41+
.await
42+
.unwrap();
43+
44+
let tracked_tx_uuid = state.get_tracked_tx_uuid(&nonce).await.unwrap();
45+
let tracked_nonce = state.get_tx_nonce(&other_tx_uuid).await.unwrap();
46+
// Assert that linkage of the old tx id & nonce was not removed
47+
assert_eq!(tracked_tx_uuid, other_tx_uuid);
48+
assert_eq!(tracked_nonce, Some(nonce));
49+
assert_eq!(nonce + 1, new_nonce);
50+
}
51+
1852
#[tokio::test]
1953
async fn test_assign_next_nonce_no_previous_nonce() {
2054
let (_, tx_db, nonce_db) = tmp_dbs();

0 commit comments

Comments
 (0)