Example #1
0
    def test_confirm_input(self):
        # create a fake Spendable
        COIN_VALUE = 100000000
        spendables = [
            Spendable(COIN_VALUE, script_for_address(BITCOIN_ADDRESSES[0]),
                      FAKE_HASH, 0)
        ]

        tx_1 = create_signed_tx(spendables,
                                BITCOIN_ADDRESSES[1:2],
                                wifs=WIFS[:1])

        spendables = tx_1.tx_outs_as_spendable()

        tx_db = dict((tx.hash(), tx) for tx in [tx_1])

        tx_2 = create_signed_tx(spendables,
                                BITCOIN_ADDRESSES[2:3],
                                wifs=WIFS[:3])
        tx_2.validate_unspents(tx_db)

        tx_2 = create_signed_tx([s.as_dict() for s in spendables],
                                BITCOIN_ADDRESSES[2:3],
                                wifs=WIFS[:3])
        tx_2.validate_unspents(tx_db)

        tx_2 = create_signed_tx([s.as_text() for s in spendables],
                                BITCOIN_ADDRESSES[2:3],
                                wifs=WIFS[:3])
        tx_2.validate_unspents(tx_db)
Example #2
0
    def test_confirm_input_raises(self):
        # create a fake Spendable
        COIN_VALUE = 100000000
        spendables = [Spendable(COIN_VALUE, script_for_address(BITCOIN_ADDRESSES[0]), FAKE_HASH, 0)]

        tx_1 = create_signed_tx(spendables, BITCOIN_ADDRESSES[1:2], wifs=WIFS[:1])
        spendables = tx_1.tx_outs_as_spendable()
        spendables[0].coin_value += 100

        tx_db = dict((tx.hash(), tx) for tx in [tx_1])
        tx_2 = create_signed_tx(spendables, BITCOIN_ADDRESSES[2:3], wifs=WIFS[:3])

        self.assertRaises(BadSpendableError, tx_2.validate_unspents, tx_db)
Example #3
0
    def test_simple_spend(self):

        FEE = 10000

        # create a fake Spendable
        COIN_VALUE = 100000000
        spendables = [Spendable(COIN_VALUE, script_for_address(BITCOIN_ADDRESSES[0]), FAKE_HASH, 0)]

        EXPECTED_IDS = [
            "d28bff6c4a8a0f9e7d5b7df0670d07b43c5613d8c9b14e84707b1e2c0154a978",
            "7afbe63b00171b18f806ebd48190ebc1c68cadf286a85489c06ebe43d146489e",
            "2b90c150ba1d080a0816952f5d9c2642d408989cbc4d4c540591c8c9241294bd",
            "17b0b5b22887081595c1a9ad153e903f63bb8682ae59d6082df018dc617e5e67",
            "dff1b34c243becb096ad2a2d6119973067a8137cc8bf95615e742bbf6f0944c1",
            "206bbfbb759a8f91901d86b62390d7587f6097a32994ece7752d143fc8a02cee",
            "7841412716ad35cbc9954e547ba85be89e5ed0b34ed5fb8d7594517318dc10d6",
            "8b7e643bf47db46ada7a75b8498990b111fe20917b5610ca6759b8b0078ccd5e",
            "5756f0a6d5a2bbb93a07f0729d3773aaafd21393ede3ec0e20b0b5219ca45548",
            "32dcbb34965ea72d2caa59eb1e907aa28bac2afea43214c1809f5d8ed360f30e",
        ]

        for count in range(1, 11):
            tx = create_signed_tx(spendables, BITCOIN_ADDRESSES[1:count+1], wifs=WIFS[:1])
            self.assertEqual(tx.bad_signature_count(), 0)
            self.assertEqual(tx.fee(), FEE)
            self.assertEqual(tx.id(), EXPECTED_IDS[count-1])
            for idx in range(1, count+1):
                script = tx.txs_out[idx-1].puzzle_script()
                address = BitcoinMainnet.ui.address_for_script(script)
                self.assertEqual(address, BITCOIN_ADDRESSES[idx])
            # TODO: add check that s + s < generator for each signature
            for i in range(count):
                extra = (1 if i < ((COIN_VALUE - FEE) % count) else 0)
                self.assertEqual(tx.txs_out[i].coin_value, (COIN_VALUE - FEE) // count + extra)
Example #4
0
    def test_confirm_input(self):
        # create a fake Spendable
        COIN_VALUE = 100000000
        spendables = [Spendable(COIN_VALUE, script_for_address(BITCOIN_ADDRESSES[0]), FAKE_HASH, 0)]

        tx_1 = create_signed_tx(spendables, BITCOIN_ADDRESSES[1:2], wifs=WIFS[:1])

        spendables = tx_1.tx_outs_as_spendable()

        tx_db = dict((tx.hash(), tx) for tx in [tx_1])

        tx_2 = create_signed_tx(spendables, BITCOIN_ADDRESSES[2:3], wifs=WIFS[:3])
        tx_2.validate_unspents(tx_db)

        tx_2 = create_signed_tx([s.as_dict() for s in spendables], BITCOIN_ADDRESSES[2:3], wifs=WIFS[:3])
        tx_2.validate_unspents(tx_db)

        tx_2 = create_signed_tx([s.as_text() for s in spendables], BITCOIN_ADDRESSES[2:3], wifs=WIFS[:3])
        tx_2.validate_unspents(tx_db)
Example #5
0
    def test_confirm_input_raises(self):
        # create a fake Spendable
        COIN_VALUE = 100000000
        spendables = [
            Spendable(COIN_VALUE, script_for_address(BITCOIN_ADDRESSES[0]),
                      FAKE_HASH, 0)
        ]

        tx_1 = create_signed_tx(spendables,
                                BITCOIN_ADDRESSES[1:2],
                                wifs=WIFS[:1])
        spendables = tx_1.tx_outs_as_spendable()
        spendables[0].coin_value += 100

        tx_db = dict((tx.hash(), tx) for tx in [tx_1])
        tx_2 = create_signed_tx(spendables,
                                BITCOIN_ADDRESSES[2:3],
                                wifs=WIFS[:3])

        self.assertRaises(BadSpendableError, tx_2.validate_unspents, tx_db)
Example #6
0
    def _make_tx(self, input_script, other_scripts=[]):
        from pycoin.coins.tx_utils import create_signed_tx
        from pycoin.solve.utils import build_p2sh_lookup

        cv = int(50*1e8)

        key = self._key
        sec = key.sec()
        wif = key.wif()
        address = key.address()
        p2sh_lookup = build_p2sh_lookup(other_scripts)

        coinbase_tx = Tx.coinbase_tx(public_key_sec=sec, coin_value=cv)
        coinbase_tx.txs_out[0].script = input_script
        spendable = coinbase_tx.tx_outs_as_spendable()[0]
        payables = [(address, cv)]
        tx = create_signed_tx(spendables=[spendable], payables=payables, wifs=[wif], p2sh_lookup=p2sh_lookup)
        tx.unspents = [spendable]
        print(tx.as_hex(include_unspents=True))
        return tx
Example #7
0
    def test_simple_spend(self):

        FEE = 10000

        # create a fake Spendable
        COIN_VALUE = 100000000
        spendables = [
            Spendable(COIN_VALUE, script_for_address(BITCOIN_ADDRESSES[0]),
                      FAKE_HASH, 0)
        ]

        EXPECTED_IDS = [
            "d28bff6c4a8a0f9e7d5b7df0670d07b43c5613d8c9b14e84707b1e2c0154a978",
            "7afbe63b00171b18f806ebd48190ebc1c68cadf286a85489c06ebe43d146489e",
            "2b90c150ba1d080a0816952f5d9c2642d408989cbc4d4c540591c8c9241294bd",
            "17b0b5b22887081595c1a9ad153e903f63bb8682ae59d6082df018dc617e5e67",
            "dff1b34c243becb096ad2a2d6119973067a8137cc8bf95615e742bbf6f0944c1",
            "206bbfbb759a8f91901d86b62390d7587f6097a32994ece7752d143fc8a02cee",
            "7841412716ad35cbc9954e547ba85be89e5ed0b34ed5fb8d7594517318dc10d6",
            "8b7e643bf47db46ada7a75b8498990b111fe20917b5610ca6759b8b0078ccd5e",
            "5756f0a6d5a2bbb93a07f0729d3773aaafd21393ede3ec0e20b0b5219ca45548",
            "32dcbb34965ea72d2caa59eb1e907aa28bac2afea43214c1809f5d8ed360f30e",
        ]

        for count in range(1, 11):
            tx = create_signed_tx(spendables,
                                  BITCOIN_ADDRESSES[1:count + 1],
                                  wifs=WIFS[:1])
            self.assertEqual(tx.bad_solution_count(), 0)
            self.assertEqual(tx.fee(), FEE)
            self.assertEqual(tx.id(), EXPECTED_IDS[count - 1])
            for idx in range(1, count + 1):
                script = tx.txs_out[idx - 1].puzzle_script()
                address = network.ui.address_for_script(script)
                self.assertEqual(address, BITCOIN_ADDRESSES[idx])
            # TODO: add check that s + s < generator for each signature
            for i in range(count):
                extra = (1 if i < ((COIN_VALUE - FEE) % count) else 0)
                self.assertEqual(tx.txs_out[i].coin_value,
                                 (COIN_VALUE - FEE) // count + extra)
Example #8
0
    def _make_tx(self, input_script, other_scripts=[]):
        from pycoin.coins.tx_utils import create_signed_tx
        from pycoin.solve.utils import build_p2sh_lookup

        cv = int(50 * 1e8)

        key = self._key
        sec = key.sec()
        wif = key.wif()
        address = key.address()
        p2sh_lookup = build_p2sh_lookup(other_scripts)

        coinbase_tx = Tx.coinbase_tx(public_key_sec=sec, coin_value=cv)
        coinbase_tx.txs_out[0].script = input_script
        spendable = coinbase_tx.tx_outs_as_spendable()[0]
        payables = [(address, cv)]
        tx = create_signed_tx(spendables=[spendable],
                              payables=payables,
                              wifs=[wif],
                              p2sh_lookup=p2sh_lookup)
        tx.unspents = [spendable]
        print(tx.as_hex(include_unspents=True))
        return tx
Example #9
0
 def my_create_signed_tx(*args, **kwargs):
     return create_signed_tx(network, *args, **kwargs)