chainside / btcpy

A Python3 SegWit-compliant library which provides tools to handle Bitcoin data structures in a simple fashion.
https://www.chainside.net
GNU Lesser General Public License v3.0
271 stars 74 forks source link

Json fixes #48

Open peerchemist opened 6 years ago

peerchemist commented 6 years ago

Fixing to_json() methods to yield sequence as int and value as float, emulating what JSON-RPC interface provides.

Test fails with:

........................................................................................................................E....

ERROR: test_jsonization (tests.unit.TestTransaction)


Traceback (most recent call last): File "/home/cookie/projects/btcpy-upstream/tests/unit.py", line 261, in test_jsonization self.assertEqual(TransactionFactory.from_json(tx), TransactionFactory.unhexlify(tx['hex'])) File "/home/cookie/projects/btcpy-upstream/btcpy/structs/transaction.py", line 1015, in from_json return cls._get_class(segwit=False, mutable=mutable).from_json(tx_json) File "/home/cookie/projects/btcpy-upstream/btcpy/structs/transaction.py", line 487, in from_json tx = super().from_json(tx_json) File "/home/cookie/projects/btcpy-upstream/btcpy/structs/transaction.py", line 461, in from_json outs=[TxOut.from_json(txout_json) for txout_json in tx_json['vout']]) File "/home/cookie/projects/btcpy-upstream/btcpy/structs/transaction.py", line 500, in init raise ValueError('txid {} does not match transaction data {}'.format(txid, self.hexlify())) ValueError: txid 881e5bb59faa99178c291da8043c3ddd037eacf06767d24d4a5c7a6705258c75 does not match transaction data 010000000185701296d47b03f388fd85431c2a9fc817afc9b24870a9a7da850d3a43a8154b0000000049483045022065348e766b145d94b65b76c6ebd142ee11cba71700365d2d5ac62325c67ee51f022100fbfc94490a7f9a66a30e568445d5271c1a72ae8d6ce46a5f8d4d8e75ae9c4d5901ffffffff0bdfda8a00000000000705feffffff8087a0987b0000000000029e91200b200000000000029f91dfd14d0000000000025287201d9a00000000000604ffffff7f9cdfc810000000000002a2915f566c00000000000301649cff73af26010000001976a91443b906f5e0d9371d852c85030a2fbcc7601524d088ac1f145d0000000000024f9c5f4d2f000000000001a2a08f3e00000000000604ffffffff9c00000000


However manual tests with .unhexlify(HEX) method of TransactionFactory yield correct results.

Could the txid in the test be wrong?