Skip to content

Commit 22abef0

Browse files
authored
Fix relay tx request matching in tests (#5212)
1 parent 38fe86e commit 22abef0

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

test/src/util/transaction.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,27 @@ pub fn send_tx(net: &Net, node: &Node, tx: TransactionView, cycles: u64) {
6868
}
6969

7070
pub fn relay_tx(net: &Net, node: &Node, tx: TransactionView, cycles: u64) {
71+
let tx_hash = tx.hash();
7172
let tx_hashes_msg = packed::RelayMessage::new_builder()
7273
.set(
7374
packed::RelayTransactionHashes::new_builder()
74-
.tx_hashes(vec![tx.hash()])
75+
.tx_hashes(vec![tx_hash.clone()])
7576
.build(),
7677
)
7778
.build();
7879
net.send(node, SupportProtocols::RelayV3, tx_hashes_msg.as_bytes());
7980

80-
let ret = net.should_receive(node, |data: &Bytes| {
81-
packed::RelayMessage::from_slice(data)
82-
.map(|message| message.to_enum().item_name() == packed::GetRelayTransactions::NAME)
83-
.unwrap_or(false)
84-
});
85-
assert!(ret, "node should ask for tx");
81+
let ret = net.should_receive(
82+
node,
83+
|data: &Bytes| match packed::RelayMessage::from_slice(data).map(|message| message.to_enum())
84+
{
85+
Ok(packed::RelayMessageUnion::GetRelayTransactions(get_txs)) => {
86+
get_txs.tx_hashes().into_iter().any(|hash| hash == tx_hash)
87+
}
88+
_ => false,
89+
},
90+
);
91+
assert!(ret, "node should ask for tx {tx_hash}");
8692

8793
let relay_tx = packed::RelayTransaction::new_builder()
8894
.cycles(cycles)

0 commit comments

Comments
 (0)