示例#1
0
    def test_transaction(self):
        priv, pub = generate_keypair()
        inputs = [TxIn(1, "aaa", Decimal(200), pub)]
        outputs = [TxOut(Decimal(100), "aaa"), TxOut(Decimal(99), "bbb")]

        for ti in inputs:
            ti.sign(priv)

        tx = Transaction(TX_REGULAR, inputs, outputs)
        self.assertSerializable(Transaction, tx, globals())

        self.assertTrue(tx.has_enough_balance)
        self.assertEqual(tx.fee, Decimal(1))
        self.assertTrue(tx.valid)

        tx1 = Transaction(
            TX_REGULAR,
            [inputs[0], TxIn(1, "bbb", Decimal(200), pub)], outputs)
        tx2 = Transaction(TX_REGULAR, [TxIn(1, "bbb", Decimal(200), pub)],
                          outputs)
        self.assertTrue(tx.has_same_inputs(tx1))
        self.assertFalse(tx.has_same_inputs(tx2))

        mempool = get_mempool()
        self.assertSerializable(Mempool, mempool, globals())

        self.assertIs(mempool, get_mempool())
        self.assertEqual(mempool, get_mempool())
        self.assertTrue(mempool.add(tx))
        self.assertFalse(mempool.add(tx))

        self.assertTrue(mempool.is_double_spent(tx))
        self.assertTrue(mempool.is_double_spent(tx1))
        self.assertFalse(mempool.is_double_spent(tx2))
示例#2
0
    def test_txout(self):
        priv, pub = generate_keypair()
        to = TxOut(Decimal(100), "aaa")
        self.assertSerializable(TxOut, to, globals())

        to = TxOut(Decimal(100000000000000000000), "aaa")
        self.assertSerializable(TxOut, to, globals())
示例#3
0
    def test_txin(self):
        priv, pub = generate_keypair()
        ti = TxIn(1, "aaa", Decimal(100), pub)
        self.assertFalse(ti.valid)

        # sign with wrong key
        ti.sign(priv.replace("a", "1").replace("1", "b"))
        self.assertFalse(ti.valid)

        # sign with invalid key
        with self.assertRaises(binascii.Error):
            ti.sign("aaa")

        # stil screaming with error
        with self.assertRaises(ValueError):
            ti.verify()

        # sign with right key
        ti.sign(priv)
        self.assertTrue(ti.valid)

        self.assertSerializable(TxIn, ti, globals())
示例#4
0
 def __init__(self, password=None):
     self._key_pair = elliptic.generate_keypair()
     self._password = password
 def test_elliptic(self):
     prv, pub = generate_keypair()
     msg = "0" * 1024 * 1024 * 100  # assuming 100 MB block data
     self.assertTrue(verify(pub, sign(prv, msg), msg))