def test_proof_serialization(self): proof1 = TxProof(position=10, branch=[os.urandom(32) for i in range(10)]) raw = self.store._pack_proof(proof1) proof2 = self.store._unpack_proof(raw) self.assertEqual(proof1.position, proof2.position) self.assertEqual(proof1.branch, proof2.branch)
def test_proof(self): bytedata = os.urandom(10) tx_hash = bitcoinx.double_sha256(bytedata) metadata = TxData(height=1, fee=2, position=None, date_added=1, date_updated=1) with SynchronousWriter() as writer: self.store.create([(tx_hash, metadata, bytedata, 0, None)], completion_callback=writer.get_callback()) assert writer.succeeded() position1 = 10 merkle_branch1 = [os.urandom(32) for i in range(10)] proof = TxProof(position1, merkle_branch1) date_updated = 1 with SynchronousWriter() as writer: self.store.update_proof([(tx_hash, proof, date_updated)], completion_callback=writer.get_callback()) assert writer.succeeded() rows = self.store.read_proof([self.tx_hash]) assert len(rows) == 0 db_tx_hash, (tx_position2, merkle_branch2) = self.store.read_proof([tx_hash])[0] assert db_tx_hash == tx_hash assert position1 == tx_position2 assert merkle_branch1 == merkle_branch2
def test_proof(self): bytedata = os.urandom(10) tx_hash_bytes = bitcoinx.double_sha256(bytedata) tx_id = bitcoinx.hash_to_hex_str(tx_hash_bytes) metadata = TxData(height=1, fee=2, position=None, timestamp=None) self.store.add(tx_id, metadata, bytedata) position1 = 10 merkle_branch1 = [os.urandom(32) for i in range(10)] proof = TxProof(position1, merkle_branch1) self.store.update_proof(tx_id, proof) with self.assertRaises(wallet_database.MissingRowError): self.store.get_proof(self.tx_id) position2, merkle_branch2 = self.store.get_proof(tx_id) self.assertEqual(position1, position2) self.assertEqual(merkle_branch1, merkle_branch2)