def __test__(self, version, height, items, string, **kwargs): utx1 = UnspentTransaction.deserialize(BytesIO(string)) utx2 = UnspentTransaction.deserialize(BytesIO(string)) self.assertTrue(utx1 == utx2) self.assertFalse(utx1 != utx2) self.assertEqual(utx1.serialize(), utx2.serialize()) utx2.version = version - 1 self.assertFalse(utx1 == utx2) self.assertTrue(utx1 != utx2) self.assertNotEqual(utx1.serialize(), utx2.serialize()) utx2.version = version self.assertTrue(utx1 == utx2) self.assertEqual(utx1.serialize(), utx2.serialize()) utx2.height = height + 1 self.assertFalse(utx1 == utx2) self.assertTrue(utx1 != utx2) self.assertNotEqual(utx1.serialize(), utx2.serialize()) utx2.height = height if version in (2, ): utx2.reference_height = height - 1 self.assertFalse(utx1 == utx2) self.assertTrue(utx1 != utx2) self.assertNotEqual(utx1.serialize(), utx2.serialize()) utx2.reference_height = utx1.reference_height self.assertTrue(utx1 == utx2) self.assertEqual(utx1.serialize(), utx2.serialize()) del utx2[next(six.iterkeys(utx2))] if utx2: self.assertFalse(utx1 == utx2) self.assertTrue(utx1 != utx2) self.assertNotEqual(utx1.serialize(), utx2.serialize())
def __test__(self, script, string): file_ = BytesIO(string) pickler = ScriptPickler(file_) self.assertEqual(pickler.load(), script) file_ = BytesIO(string) pickler = ScriptPickler() self.assertEqual(pickler.load(file=file_), script) self.assertEqual(pickler.loads(string), script)
def __test__(self, value, children, str_, composable, patricia): pn = MemoryComposableAuthTree.deserialize(BytesIO(str_)) self.assertEqual(pn.value, value) self.assertEqual(list((child.prefix, child.node) for child in pn.children), children) self.assertEqual(pn.hash, composable) pn2 = MemoryPatriciaAuthTree.deserialize(BytesIO(str_)) self.assertEqual(pn2.value, value) self.assertEqual(list((child.prefix, child.node) for child in pn2.children), children) self.assertEqual(pn2.hash, patricia)
def __test__(self, script, string): file_ = BytesIO() pickler = ScriptPickler(file_) pickler.dump(script) self.assertEqual(file_.getvalue(), string) file_ = BytesIO() pickler = ScriptPickler() pickler.dump(script, file=file_) self.assertEqual(file_.getvalue(), string) self.assertEqual(pickler.dumps(script), string)
def __test__(self, list_, compressor, result): file_ = BytesIO(result) self.assertEqual( list( deserialize_iterator(file_, lambda f: compressor.deserialize(f))), list_)
def __test__(self, version, height, items, string, **kwargs): utx = UnspentTransaction.deserialize(BytesIO(string)) self.assertEqual(utx.version, version) self.assertEqual(utx.height, height) if 'reference_height' in kwargs: self.assertEqual(utx.reference_height, kwargs['reference_height']) for idx, output in items: self.assertIn(idx, utx) self.assertEqual(utx[idx], output) self.assertEqual(utx.serialize(), string)
def __test__(self, size, result): file_ = BytesIO(result) self.assertEqual(BigCompactSize.deserialize(file_), size)
def __test__(self, invalid, deserializer): file_ = BytesIO(invalid) self.assertRaises(EOFError, lambda f, d: list(deserialize_iterator(f, d)), file_, deserializer)
def __test__(self, list_, result): file_ = BytesIO(result) self.assertEqual( list(deserialize_iterator(file_, LittleCompactSize.deserialize)), list_)
def __test__(self, len_, invalid): file_ = BytesIO(invalid[::-1]) self.assertRaises(EOFError, LittleInteger.deserialize, file_, len_)
def __test__(self, hash_, len_, result): result = result[::-1] file_ = BytesIO(result) self.assertEqual(LittleInteger.deserialize(file_, len_), hash_)
def __test__(self, hash_, len_, result): file_ = BytesIO(result) self.assertEqual(BigInteger.deserialize(file_, len_), hash_)
def __test__(self, data): self.assertEqual(FlatData.deserialize(BytesIO(data), len(data)), data)
def __test__(self, invalid): file_ = BytesIO(invalid) self.assertRaises(EOFError, BigCompactSize.deserialize, file_) self.assertRaises(EOFError, LittleCompactSize.deserialize, file_)
from scenariotest import ScenarioMeta, ScenarioTest from bitcoin.destination import * from bitcoin.crypto import VerifyingKey from bitcoin.script import * from bitcoin.tools import BytesIO import bitcoin.base58 import codecs # ===----------------------------------------------------------------------=== PUBKEY = [ dict(verifying_key=VerifyingKey.deserialize( BytesIO( codecs.decode('muqdFiyLkdVygf59nrWJFwJMHCBhdYdU2tXs8AUz7iWD', 'base58'))), script=Script().join([ ScriptOp(data=bytes.fromhex( '029b4b68495bb7cdc737fada24b80adff2b7a08d77424368' 'e7ae56f5f14980b282')), ScriptOp(OP_CHECKSIG) ])), dict(verifying_key=VerifyingKey.deserialize( BytesIO( codecs.decode('28kSUszMTVjiXUNNjN8aFMzj4Ztfp36ktAtoPgqUW1Fy7', 'base58'))), script=Script().join([ ScriptOp(data=bytes.fromhex( '03d0e86fa3d42ebcd38019e976dd66d32d4339060f705b8f' '70f407647aa6ff52de')),