Пример #1
0
    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
Пример #2
0
    def test_serialize_multisig_outpoint(self):
        outpoint = MultiSigOutpoint(2, 3,
                                    [PublicKey.from_hexstr("022af4cc9ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f"), 
                                     PublicKey.from_hexstr("022dc45c9ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f"), 
                                     PublicKey.from_hexstr("029ce0129ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f")])
        
        serialized = MultiSigOutpointSerializer.serialize(outpoint)

        self.assertEquals(hexstr(serialized), 
                          "0000000200000003022af4cc9ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f022dc45c9ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f029ce0129ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f")
Пример #3
0
    def test_deserialize_multisig_outpoint(self):
        serialized_data = decodehexstr("0000000200000003022af4cc9ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f022dc45c9ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f029ce0129ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f")
        
        outpoint = MultiSigOutpointSerializer.deserialize(serialized_data)

        self.assertEquals(outpoint, 
                          MultiSigOutpoint(2, 3,
                                    [PublicKey.from_hexstr("022af4cc9ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f"), 
                                     PublicKey.from_hexstr("022dc45c9ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f"), 
                                     PublicKey.from_hexstr("029ce0129ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f")])
                          )
Пример #4
0
    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")
Пример #5
0
    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))
Пример #6
0
    def test_serialize_multisig_outpoint(self):
        outpoint = MultiSigOutpoint(2, 3, [
            PublicKey.from_hexstr(
                "022af4cc9ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f"
            ),
            PublicKey.from_hexstr(
                "022dc45c9ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f"
            ),
            PublicKey.from_hexstr(
                "029ce0129ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f"
            )
        ])

        serialized = MultiSigOutpointSerializer.serialize(outpoint)

        self.assertEquals(
            hexstr(serialized),
            "0000000200000003022af4cc9ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f022dc45c9ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f029ce0129ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f"
        )
Пример #7
0
    def test_deserialize_multisig_outpoint(self):
        serialized_data = decodehexstr(
            "0000000200000003022af4cc9ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f022dc45c9ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f029ce0129ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f"
        )

        outpoint = MultiSigOutpointSerializer.deserialize(serialized_data)

        self.assertEquals(
            outpoint,
            MultiSigOutpoint(2, 3, [
                PublicKey.from_hexstr(
                    "022af4cc9ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f"
                ),
                PublicKey.from_hexstr(
                    "022dc45c9ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f"
                ),
                PublicKey.from_hexstr(
                    "029ce0129ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f"
                )
            ]))
Пример #8
0
    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"
        )
Пример #9
0
    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")
Пример #10
0
    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))
Пример #11
0
    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
Пример #12
0
    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"
        )
Пример #13
0
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")
Пример #14
0
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")