Ejemplo 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 = TestSwapTransaction.create_tx_struct(100)
        tx_struct.payload.sender = ''.join(['X' for _ in range(64)])
        tx = SwapTransaction.from_data(tx_struct, validate=False)
        self.assertRaises(Exception, tx.validate_payload)

        # Test invalid length
        tx_struct = TestSwapTransaction.create_tx_struct(100)
        tx_struct.payload.sender = ''.join(['a' for _ in range(50)])
        tx = SwapTransaction.from_data(tx_struct, validate=False)
        self.assertRaises(Exception, tx.validate_payload)
Ejemplo n.º 2
0
 def test_validation(self):
     """
     Tests that all validation passes with a correct struct
     """
     tx_struct = TestSwapTransaction.create_tx_struct(333)
     tx = SwapTransaction.from_data(tx_struct, validate=True)
     self.assertTrue(True)
Ejemplo n.º 3
0
 def test_from_data(self):
     """
     Tests from_data with a valid capnp struct (no validation)
     """
     tx_struct = TestSwapTransaction.create_tx_struct(250)
     tx = SwapTransaction.from_data(tx_struct, validate=False)
     self.__assert_struct_equal_object(tx_struct, tx)
Ejemplo n.º 4
0
 def test_serialization(self):
     """
     Tests that serialize and from_bytes are inverse operations
     """
     tx_struct = TestSwapTransaction.create_tx_struct(100)
     struct_binary = tx_struct.to_bytes_packed()
     tx = SwapTransaction.from_data(tx_struct, validate=False)
Ejemplo n.º 5
0
 def test_invalid_expiration(self):
     """
     Tests that an exception is thrown when given an invalid expiration. Expirations have to exist in the future
     """
     # Test amount is 0
     tx_struct = TestSwapTransaction.create_tx_struct(1, None, int(time.time())-1)
     tx = SwapTransaction.from_data(tx_struct, validate=False)
     self.assertRaises(Exception, tx.validate_payload)
Ejemplo n.º 6
0
 def test_invalid_hashlock(self):
     """
     Tests that an exception is thrown when given an invalid hashlock. Hashlocks are at maximum 64 bytes long
     """
     # Test amount is 0
     tx_struct = TestSwapTransaction.create_tx_struct(1, secrets.token_bytes(128))
     tx = SwapTransaction.from_data(tx_struct, validate=False)
     self.assertRaises(Exception, tx.validate_payload)
Ejemplo n.º 7
0
 def test_invalid_payload_amount(self):
     """
     Tests that an exception is thrown when given an invalid amount. Note we don't have to check if amount is negative
     explicity because amount is stored as a 64 bit unsigned integer, and trying to assign it to a negative signed
     integer value will throw an exception.
     """
     # Test amount is 0
     tx_struct = TestSwapTransaction.create_tx_struct(0)
     tx = SwapTransaction.from_data(tx_struct, validate=False)
     self.assertRaises(Exception, tx.validate_payload)
Ejemplo n.º 8
0
    def test_invalid_signature(self):
        """
        Tests that an exception is thrown when given an invalid signature
        """
        # Test invalid type (non hex)
        tx_struct = TestSwapTransaction.create_tx_struct(100)
        tx_struct.metadata.signature = ''.join(['X' for _ in range(128)])
        tx = SwapTransaction.from_data(tx_struct, validate=False)
        self.assertRaises(Exception, tx.validate_signature)

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

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

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

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