From a97cfd241d2ec542bf8b7148495f9d3e552ee1c3 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Fri, 10 Sep 2021 21:54:52 +0100 Subject: [PATCH] test: Implement CInv.__eq__() for mininode to simplify RPC test --- qa/rpc-tests/feature_zip239.py | 12 ++---------- qa/rpc-tests/test_framework/mininode.py | 6 ++++++ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/qa/rpc-tests/feature_zip239.py b/qa/rpc-tests/feature_zip239.py index 2d1ee7c49..62fbc14f1 100755 --- a/qa/rpc-tests/feature_zip239.py +++ b/qa/rpc-tests/feature_zip239.py @@ -70,10 +70,7 @@ class Zip239Test(BitcoinTestFramework): actual_invs = sorted(msg.inv, key=lambda inv: (inv.type, inv.hash, inv.hash_aux)) for (expected, actual) in zip(expected_invs, actual_invs): - fail_msg = "%r != %r" % (actual, expected) - assert_equal(actual.type, expected.type, fail_msg) - assert_equal(actual.hash, expected.hash, fail_msg) - assert_equal(actual.hash_aux, expected.hash_aux, fail_msg) + assert_equal(expected, actual) def send_data_message(self, testnode, txid, authDigest=None): # Send p2p message "getdata" to verify tx gets sent in "tx" message @@ -105,12 +102,7 @@ class Zip239Test(BitcoinTestFramework): assert_true(testnode.last_tx is None, "'%r' is not None" % testnode.last_tx) assert_false(testnode.last_notfound is None, "notfound not received") assert_equal(len(testnode.last_notfound.inv), 1) - actual = testnode.last_notfound.inv[0] - expected = self.cinv_for(txid, authDigest) - fail_msg = "%r != %r" % (actual, expected) - assert_equal(actual.type, expected.type, fail_msg) - assert_equal(actual.hash, expected.hash, fail_msg) - assert_equal(actual.hash_aux, expected.hash_aux, fail_msg) + assert_equal(testnode.last_notfound.inv[0], self.cinv_for(txid, authDigest)) def verify_disconnected(self, testnode, timeout=30): sleep_time = 0.05 diff --git a/qa/rpc-tests/test_framework/mininode.py b/qa/rpc-tests/test_framework/mininode.py index 90fc26e25..074ebc9cd 100755 --- a/qa/rpc-tests/test_framework/mininode.py +++ b/qa/rpc-tests/test_framework/mininode.py @@ -363,6 +363,12 @@ class CInv(object): r += ser_uint256(self.hash_aux) return r + def __eq__(self, other): + return ( + (type(self) == type(other)) and + (self.type, self.hash, self.hash_aux) == (other.type, other.hash, other.hash_aux) + ) + def __repr__(self): return "CInv(type=%s hash=%064x hash_aux=%064x)" \ % (self.typemap[self.type], self.hash, self.hash_aux)