From 66a0c55322800925aead845e42a19ea996f31ccd Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 23 Oct 2017 07:02:10 +1030 Subject: [PATCH] test_lightning.py: fix float insanity with values. When is 0.01 != 0.01? When there are floats involved! Jenkins hit an error once, I have no idea why. This works around the following intermittant error: ERROR: test_closing_negotiation_reconnect (__main__.LightningDTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "tests/test_lightningd.py", line 1601, in test_closing_negotiation_reconnect self.fund_channel(l1, l2, 10**6) File "tests/test_lightningd.py", line 241, in fund_channel raise ValueError("Can't find {} payment in {}".format(amount, tx)) ValueError: Can't find 1000000 payment in 02000000000101b0b27be92916faee59f197c263e1ae7b44c0e59acdf2c385c55b5b04670ac026010000001716001401fad90abcd66697e2592164722de4a95ebee165ffffffff02651d0f0000000000160014c2ccab171c2a5be9dab52ec41b825863024c546640420f00000000002200205b8cd3b914cf67cdd8fa6273c930353dd36476734fbd962102c2df53b90880cd02473044022017bd19a0ee85532f67a280c71ed02d1321f08975334bd281527478022265225702202ec448bf9c0890a31a26f0ef4f03d298c8ec16b277faff09a70ddd335df44b6e012103d745445c9362665f22e0d96e9e766f273f3260dea39c8a76bfa05dd2684ddccf00000000 For testing, that tx decodes to: { "txid": "0165e92be762b352b665b76b9872d5189e1b2a8faf4918ab3cca7cd5d4b6a5fa", "hash": "8af9a36c79ee5243468c5cbed1c80f10238fba405f0ad957a0c2cfc46fb632f5", "version": 2, "size": 257, "vsize": 176, "locktime": 0, "vin": [ { "txid": "26c00a67045b5bc585c3f2cd9ae5c0447baee163c297f159eefa1629e97bb2b0", "vout": 1, "scriptSig": { "asm": "001401fad90abcd66697e2592164722de4a95ebee165", "hex": "16001401fad90abcd66697e2592164722de4a95ebee165" }, "txinwitness": [ "3044022017bd19a0ee85532f67a280c71ed02d1321f08975334bd281527478022265225702202ec448bf9c0890a31a26f0ef4f03d298c8ec16b277faff09a70ddd335df44b6e01", "03d745445c9362665f22e0d96e9e766f273f3260dea39c8a76bfa05dd2684ddccf" ], "sequence": 4294967295 } ], "vout": [ { "value": 0.00990565, "n": 0, "scriptPubKey": { "asm": "0 c2ccab171c2a5be9dab52ec41b825863024c5466", "hex": "0014c2ccab171c2a5be9dab52ec41b825863024c5466", "type": "witness_v0_keyhash" } }, { "value": 0.01000000, "n": 1, "scriptPubKey": { "asm": "0 5b8cd3b914cf67cdd8fa6273c930353dd36476734fbd962102c2df53b90880cd", "hex": "00205b8cd3b914cf67cdd8fa6273c930353dd36476734fbd962102c2df53b90880cd", "type": "witness_v0_scripthash" } } ] } Signed-off-by: Rusty Russell --- tests/test_lightningd.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_lightningd.py b/tests/test_lightningd.py index 57f74df6f..ec13486d8 100644 --- a/tests/test_lightningd.py +++ b/tests/test_lightningd.py @@ -236,8 +236,10 @@ class LightningDTests(BaseLightningDTests): # Hacky way to find our output. for out in bitcoind.rpc.decoderawtransaction(tx)['vout']: - if out['scriptPubKey']['type'] == 'witness_v0_scripthash' and out['value'] == Decimal(amount) / 10**8: - return "{}:1:{}".format(bitcoind.rpc.getblockcount(), out['n']) + # Sometimes a float? Sometimes a decimal? WTF Python?! + if out['scriptPubKey']['type'] == 'witness_v0_scripthash': + if out['value'] == Decimal(amount) / 10**8 or out['value'] * 10**8 == amount: + return "{}:1:{}".format(bitcoind.rpc.getblockcount(), out['n']) raise ValueError("Can't find {} payment in {}".format(amount, tx)) def pay(self, lsrc, ldst, amt, label=None, async=False):