Exemplo n.º 1
0
    def test_invalid_payload_receiver(self):
        """
        Tests that an exception is thrown when given an invalid receiver
        """
        # Test invalid type (non hex)
        tx_struct = TestRedeemTransaction.create_tx_struct()
        tx_struct.payload.sender = ''.join(['X' for _ in range(64)])
        tx = RedeemTransaction.from_data(tx_struct, validate=False)
        self.assertRaises(Exception, tx.validate_payload)

        # Test invalid length
        tx_struct = TestRedeemTransaction.create_tx_struct()
        tx_struct.payload.sender = ''.join(['a' for _ in range(50)])
        tx = RedeemTransaction.from_data(tx_struct, validate=False)
        self.assertRaises(Exception, tx.validate_payload)
Exemplo n.º 2
0
 def test_validation(self):
     """
     Tests that all validation passes with a correct struct
     """
     tx_struct = TestRedeemTransaction.create_tx_struct()
     tx = RedeemTransaction.from_data(tx_struct, validate=True)
     self.assertTrue(True)
Exemplo n.º 3
0
 def test_from_data(self):
     """
     Tests from_data with a valid capnp struct (no validation)
     """
     tx_struct = TestRedeemTransaction.create_tx_struct()
     tx = RedeemTransaction.from_data(tx_struct, validate=False)
     self.__assert_struct_equal_object(tx_struct, tx)
Exemplo n.º 4
0
 def test_serialization(self):
     """
     Tests that serialize and from_bytes are inverse operations
     """
     tx_struct = TestRedeemTransaction.create_tx_struct()
     struct_binary = tx_struct.to_bytes_packed()
     tx = RedeemTransaction.from_data(tx_struct, validate=False)
Exemplo n.º 5
0
 def test_from_bytes(self):
     """
     Tests from_bytes with a valid serialized capnp struct (no validation)
     """
     tx_struct = TestRedeemTransaction.create_tx_struct()
     tx = RedeemTransaction.from_bytes(tx_struct.to_bytes_packed(),
                                       validate=False)
     self.__assert_struct_equal_object(tx_struct, tx)
Exemplo n.º 6
0
    def test_invalid_signature(self):
        """
        Tests that an exception is thrown when given an invalid signature
        """
        # Test invalid type (non hex)
        tx_struct = TestRedeemTransaction.create_tx_struct()
        tx_struct.metadata.signature = ''.join(['X' for _ in range(128)])
        tx = RedeemTransaction.from_data(tx_struct, validate=False)
        self.assertRaises(Exception, tx.validate_signature)

        # Test invalid length
        tx_struct = TestRedeemTransaction.create_tx_struct()
        tx_struct.metadata.signature = ''.join(['X' for _ in range(44)])
        tx = RedeemTransaction.from_data(tx_struct, validate=False)
        self.assertRaises(Exception, tx.validate_signature)

        # Test invalid signature
        tx_struct = TestRedeemTransaction.create_tx_struct()
        tx_struct.metadata.signature = ''.join(['a' for _ in range(128)])
        tx = RedeemTransaction.from_data(tx_struct, validate=False)
        self.assertRaises(Exception, tx.validate_signature)
Exemplo n.º 7
0
    def test_invalid_pow(self):
        """
        Tests that an exception is thrown when given an invalid proof
        """
        # Test invalid type (non hex)
        tx_struct = TestRedeemTransaction.create_tx_struct()
        tx_struct.metadata.proof = ''.join(['X' for _ in range(32)])
        tx = RedeemTransaction.from_data(tx_struct, validate=False)
        self.assertRaises(Exception, tx.validate_pow)

        # Test invalid length
        tx_struct = TestRedeemTransaction.create_tx_struct()
        tx_struct.metadata.proof = ''.join(['a' for _ in range(30)])
        tx = RedeemTransaction.from_data(tx_struct, validate=False)
        self.assertRaises(Exception, tx.validate_pow)

        # Test invalid proof
        tx_struct = TestRedeemTransaction.create_tx_struct()
        tx_struct.metadata.proof = ''.join(['a' for _ in range(32)])
        tx = RedeemTransaction.from_data(tx_struct, validate=False)
        self.assertRaises(Exception, tx.validate_pow)