def test_serialize_pubkey_outpoint(self): pubkey_outpoint = PubKeyOutpoint(PublicKey.from_hexstr( "022af4cc9ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f" ), is_pubkey_hash=True) serialized = PubKeyOutpointSerializer.serialize(pubkey_outpoint) self.assertEquals( hexstr(serialized), "022af4cc9ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f" )
def test_deserialize_pubkey_outpoint(self): serialized_data = decodehexstr( "022af4cc9ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f" ) pubkey_outpoint = PubKeyOutpointSerializer.deserialize( serialized_data, outpoint_type=OutpointIndex.PUBKEY) self.assertEquals( pubkey_outpoint, PubKeyOutpoint(PublicKey.from_hexstr( "022af4cc9ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f" ), is_pubkey_hash=False))
def test_WalletFile_1(self): io = IoHandle.using_stringio() wallet = WalletFile.new(io) wallet.start_tx() wallet.outpoints[1] = OutpointIndex( 12, Uint256.from_hexstr( "2af4cc9ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f" ), 3, OutpointIndex.PUBKEY_HASH, 4, PubKeyOutpoint(PublicKey.from_hexstr( "022af4cc9ec3358354345c91691031a1fcdbe9a9064197521814e8a20fe018eb5f" ), is_pubkey_hash=True)) wallet.end_tx() wallet.commit() wallet.start_tx() wallet.outpoints[1] = OutpointIndex( 12, Uint256.from_hexstr( "2af4cc9ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f" ), 3, OutpointIndex.PUBKEY_HASH, 4, PubKeyOutpoint(PublicKey.from_hexstr( "022af4cc9ec3358354345c91691031a1fcdbe9a9064197521814e8a20fe018eb5f" ), is_pubkey_hash=True)) wallet.end_tx() wallet.commit() #with open(r"c:\local\tmp\wallet-test.wlt", "wb") as wlt: # wlt.write(io.iohandle.getvalue()) io.seek(0, SEEK_SET) wallet2 = WalletFile.load(io, len(io.iohandle.getvalue())) print wallet2.fileheader print wallet2.outpoints
def test_serialize_outpoint_index(self): outpoint = OutpointIndex( 12, Uint256.from_hexstr( "2af4cc9ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f" ), 3, OutpointIndex.PUBKEY_HASH, 4, PubKeyOutpoint(PublicKey.from_hexstr( "022af4cc9ec3358354345c91691031a1fcdbe9a9064197521814e8a20fe018eb5f" ), is_pubkey_hash=True)) serialized = OutpointIndexSerializer.serialize(outpoint) self.assertEquals( hexstr(serialized), "0000000c2af4cc9ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f030200000004022af4cc9ec3358354345c91691031a1fcdbe9a9064197521814e8a20fe018eb5f" )
import unittest import mock from coinpy.lib.wallet.formats.btc.wallet_model import BtcWallet, PrivateKey,\ PubKeyOutpoint, PublicKey, ItemSet TEST_PRIVATEKEY = PrivateKey(0, private_key_data="\x01\x02\x03\x04" * 8) TEST_OUTPOINT = PubKeyOutpoint(PublicKey.from_hexstr("01" * 33)) class TestItemSet(unittest.TestCase): def test_ItemSet_setAndCommit_getReturnsValue(self): items = ItemSet() items.begin_transaction() items.set("key1", 1) items.commit_transaction() self.assertEquals(items.get("key1"), 1) def test_ItemSet_setWithoutCommit_getThrowsKeyError(self): items = ItemSet() items.begin_transaction() items.set("key1", 1) with self.assertRaises(KeyError): print items.get("key1") def test_ItemSet_delete_itemIsStillPresent(self): items = ItemSet({"key1": 1}) items.begin_transaction() items.delete("key1")
def deserialize(data, outpoint_type): is_pubkey_hash = (outpoint_type == OutpointIndex.PUBKEY_HASH) return PubKeyOutpoint(PublicKey.from_bytestr(data), is_pubkey_hash=is_pubkey_hash)