Skip to content

Commit 3361418

Browse files
committed
fix: signer state test logic
1 parent fe7cfac commit 3361418

File tree

1 file changed

+20
-65
lines changed

1 file changed

+20
-65
lines changed

libsigner/src/tests/signer_state.rs

Lines changed: 20 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ struct SignerStateTest {
4141
tx_a: StacksTransaction,
4242
tx_b: StacksTransaction,
4343
tx_c: StacksTransaction,
44+
tx_d: StacksTransaction,
4445
}
4546

4647
impl SignerStateTest {
@@ -66,48 +67,26 @@ impl SignerStateTest {
6667
let pk1 = StacksPrivateKey::random();
6768
let pk2 = StacksPrivateKey::random();
6869
let pk3 = StacksPrivateKey::random();
70+
let pk4 = StacksPrivateKey::random();
6971

70-
let tx_a = StacksTransaction {
72+
let make_tx = |pk: &StacksPrivateKey, memo: [u8; 34]| StacksTransaction {
7173
version: TransactionVersion::Testnet,
7274
chain_id: 0x80000000,
73-
auth: TransactionAuth::from_p2pkh(&pk1).unwrap(),
75+
auth: TransactionAuth::from_p2pkh(pk).unwrap(),
7476
anchor_mode: TransactionAnchorMode::Any,
7577
post_condition_mode: TransactionPostConditionMode::Allow,
7678
post_conditions: vec![],
7779
payload: TransactionPayload::TokenTransfer(
7880
local_address.clone().into(),
7981
100,
80-
TokenTransferMemo([1u8; 34]),
82+
TokenTransferMemo(memo),
8183
),
8284
};
8385

84-
let tx_b = StacksTransaction {
85-
version: TransactionVersion::Testnet,
86-
chain_id: 0x80000000,
87-
auth: TransactionAuth::from_p2pkh(&pk2).unwrap(),
88-
anchor_mode: TransactionAnchorMode::Any,
89-
post_condition_mode: TransactionPostConditionMode::Allow,
90-
post_conditions: vec![],
91-
payload: TransactionPayload::TokenTransfer(
92-
local_address.clone().into(),
93-
200,
94-
TokenTransferMemo([2u8; 34]),
95-
),
96-
};
97-
98-
let tx_c = StacksTransaction {
99-
version: TransactionVersion::Testnet,
100-
chain_id: 0x80000000,
101-
auth: TransactionAuth::from_p2pkh(&pk3).unwrap(),
102-
anchor_mode: TransactionAnchorMode::Any,
103-
post_condition_mode: TransactionPostConditionMode::Allow,
104-
post_conditions: vec![],
105-
payload: TransactionPayload::TokenTransfer(
106-
local_address.clone().into(),
107-
300,
108-
TokenTransferMemo([3u8; 34]),
109-
),
110-
};
86+
let tx_a = make_tx(&pk1, [1u8; 34]);
87+
let tx_b = make_tx(&pk2, [2u8; 34]);
88+
let tx_c = make_tx(&pk3, [3u8; 34]);
89+
let tx_d = make_tx(&pk4, [4u8; 34]);
11190

11291
Self {
11392
global_eval,
@@ -120,6 +99,7 @@ impl SignerStateTest {
12099
tx_a,
121100
tx_b,
122101
tx_c,
102+
tx_d,
123103
}
124104
}
125105

@@ -551,35 +531,6 @@ fn determine_global_states_with_tx_replay_set() {
551531

552532
#[test]
553533
/// Case: One signer has [A,B,C], another has [A,B] - should find common prefix [A,B]
554-
fn test_replay_set_common_prefix_coalescing_demo() {
555-
let mut state_test = SignerStateTest::new(5);
556-
557-
// Signers 0, 1: [A,B,C] (40% weight)
558-
state_test.update_signers(
559-
&[0, 1],
560-
vec![
561-
state_test.tx_a.clone(),
562-
state_test.tx_b.clone(),
563-
state_test.tx_c.clone(),
564-
],
565-
);
566-
567-
// Signers 2, 3, 4: [A,B] (60% weight - should win)
568-
state_test.update_signers(
569-
&[2, 3, 4],
570-
vec![state_test.tx_a.clone(), state_test.tx_b.clone()],
571-
);
572-
573-
let transactions = state_test.get_global_replay_set();
574-
575-
// Should find common prefix [A,B] since it's the longest prefix with majority support
576-
assert_eq!(transactions.len(), 2);
577-
assert_eq!(transactions[0], state_test.tx_a); // Order matters!
578-
assert_eq!(transactions[1], state_test.tx_b);
579-
assert!(!transactions.contains(&state_test.tx_c));
580-
}
581-
582-
#[test]
583534
fn test_replay_set_common_prefix_coalescing() {
584535
let mut state_test = SignerStateTest::new(5);
585536

@@ -698,22 +649,26 @@ fn test_replay_set_order_matters_no_common_prefix() {
698649
#[test]
699650
/// Case: [A,B,C] vs [A,B,D] should find common prefix [A,B]
700651
fn test_replay_set_partial_prefix_match() {
701-
let mut state_test = SignerStateTest::new(4);
652+
let mut state_test = SignerStateTest::new(5);
702653

703-
// Signer 0: [A,B,C] (25% weight - not enough alone)
654+
// Signer 0, 1: [A,B,C] (40% weight)
704655
state_test.update_signers(
705-
&[0],
656+
&[0, 1],
706657
vec![
707658
state_test.tx_a.clone(),
708659
state_test.tx_b.clone(),
709660
state_test.tx_c.clone(),
710661
],
711662
);
712663

713-
// Signers 1, 2, 3: [A,B] only (75% weight - above threshold)
664+
// Signers 2, 3, 4: [A,B,D] (60% weight)
714665
state_test.update_signers(
715-
&[1, 2, 3],
716-
vec![state_test.tx_a.clone(), state_test.tx_b.clone()],
666+
&[2, 3, 4],
667+
vec![
668+
state_test.tx_a.clone(),
669+
state_test.tx_b.clone(),
670+
state_test.tx_d.clone(),
671+
],
717672
);
718673

719674
let transactions = state_test.get_global_replay_set();

0 commit comments

Comments
 (0)