Ejemplo n.º 1
0
def test_unlockhashcondition_binary(ulh):
    """
    Tests the generation of binary encoded version of unlockhashcondition object
    """
    expected_output = bytearray(b'\x01!\x00\x00\x00\x00\x00\x00\x00\x012M\xcf\x02}\xd4\xa3\n\x93,D\x1f6Z%\xe8k\x17=\xef\xa4\xb8\xe5\x89H%4q\xb8\x1br\xcf')
    ulhc = UnlockHashCondition(unlockhash=ulh)
    assert ulhc.binary == expected_output, "Failed to generate the expected binary value of unlockhashcondition"
Ejemplo n.º 2
0
def test_coinoutput_binary(ulh):
    """
    Tests the binary output of a CoinOuput
    """
    expected_output = bytearray(
        b'\x02\x00\x00\x00\x00\x00\x00\x00\x01\xf4\x01!\x00\x00\x00\x00\x00\x00\x00\x012M\xcf\x02}\xd4\xa3\n\x93,D\x1f6Z%\xe8k\x17=\xef\xa4\xb8\xe5\x89H%4q\xb8\x1br\xcf'
    )
    ulhc = UnlockHashCondition(unlockhash=ulh)
    co = CoinOutput(value=500, condition=ulhc)
    assert co.binary == expected_output
Ejemplo n.º 3
0
def test_unlockhashcondition_json(ulh):
    """
    Tests the generation of json encoded version of the unlockhashcondition object
    """
    expected_output = {'type': 1,
                       'data': {
                                'unlockhash': '01324dcf027dd4a30a932c441f365a25e86b173defa4b8e58948253471b81b72cf57a828ea336a'
                                }
                        }
    ulhc = UnlockHashCondition(unlockhash=ulh)
    assert ulhc.json == expected_output, "Failed to generate the expected json value of unlockhashcondition"
Ejemplo n.º 4
0
    def add_coin_output(self, value, recipient, locktime=None):
        """
        Add a new coin output to the transaction

        @param value: Amout of coins
        @param recipient: The recipient address
        @param locktime: If provided then a locktimecondition will be created for this output
        """
        unlockhash = UnlockHash.from_string(recipient)
        condition = UnlockHashCondition(unlockhash=unlockhash)
        if locktime is not None:
            condition = LockTimeCondition(condition=condition,
                                          locktime=locktime)
        self._coins_outputs.append(CoinOutput(value=value,
                                              condition=condition))
Ejemplo n.º 5
0
def test_coinoutput_json(ulh):
    """
    Tests the json output of a CoinOuput
    """
    expected_output = {
        'value': '500',
        'condition': {
            'type': 1,
            'data': {
                'unlockhash':
                '01324dcf027dd4a30a932c441f365a25e86b173defa4b8e58948253471b81b72cf57a828ea336a'
            }
        }
    }
    ulhc = UnlockHashCondition(unlockhash=ulh)
    co = CoinOutput(value=500, condition=ulhc)
    assert co.json == expected_output
Ejemplo n.º 6
0
def test_locktimecondition_json(ulh):
    """
    Tests the generation of json encoded version of the LockTimeCondition object
    """
    expected_output = {'type': 3,
                       'data': {
                            'locktime': 10,
                            'condition': {
                                'type': 1,
                                'data': {
                                    'unlockhash': '01324dcf027dd4a30a932c441f365a25e86b173defa4b8e58948253471b81b72cf57a828ea336a'
                                    }
                                }
                            }
                        }

    ulhc = UnlockHashCondition(unlockhash=ulh)
    ltc = LockTimeCondition(condition=ulhc, locktime=10)
    assert ltc.json == expected_output, "Failed to generate the expected json value of locktimecondition"