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

        # Test invalid length
        tx_struct = TestStandardTransaction.create_tx_struct(100)
        tx_struct.payload.sender = ''.join(['a' for _ in range(50)])
        tx = StandardTransaction.from_data(tx_struct, validate=False)
        self.assertRaises(Exception, tx.validate_payload)
示例#2
0
 def test_validation(self):
     """
     Tests that all validation passes with a correct struct
     """
     tx_struct = TestStandardTransaction.create_tx_struct(333)
     tx = StandardTransaction.from_data(tx_struct, validate=True)
     self.assertTrue(True)
示例#3
0
 def test_from_data(self):
     """
     Tests from_data with a valid capnp struct (no validation)
     """
     tx_struct = TestStandardTransaction.create_tx_struct(250)
     tx = StandardTransaction.from_data(tx_struct, validate=False)
     self.__assert_struct_equal_object(tx_struct, tx)
示例#4
0
 def test_from_bytes(self):
     """
     Tests from_bytes with a valid serialized capnp struct (no validation)
     """
     tx_struct = TestStandardTransaction.create_tx_struct(314)
     tx = StandardTransaction.from_bytes(tx_struct.to_bytes_packed(),
                                         validate=False)
     self.__assert_struct_equal_object(tx_struct, tx)
示例#5
0
    def test_builder_serializiation(self):
        """
        Tests serialization/deserialization using the StandardTransactionBuilder object
        """
        tx = StandardTransactionBuilder.random_tx()
        clone = StandardTransaction.from_bytes(tx.serialize())

        self.assertTrue(True)
示例#6
0
    def test_serialization(self):
        """
        Tests that serialize and from_bytes are inverse operations
        """
        tx_struct = TestStandardTransaction.create_tx_struct(100)
        struct_binary = tx_struct.to_bytes_packed()
        tx = StandardTransaction.from_data(tx_struct, validate=False)

        self.assertTrue(True)
示例#7
0
    def test_builder_reserialization(self):
        """
        Tests that a transaction object can be loaded from binary created using StandardTransactionBuilder, and then
        properly serialized again
        """
        tx = StandardTransactionBuilder.random_tx()
        clone = StandardTransaction.from_bytes(tx.serialize())
        clone.serialize()

        self.assertTrue(True)
示例#8
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 = TestStandardTransaction.create_tx_struct(0)
     tx = StandardTransaction.from_data(tx_struct, validate=False)
     self.assertRaises(Exception, tx.validate_payload)
示例#9
0
    def test_invalid_signature(self):
        """
        Tests that an exception is thrown when given an invalid signature
        """
        # Test invalid type (non hex)
        tx_struct = TestStandardTransaction.create_tx_struct(100)
        tx_struct.metadata.signature = ''.join(['X' for _ in range(128)])
        tx = StandardTransaction.from_data(tx_struct, validate=False)
        self.assertRaises(Exception, tx.validate_signature)

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

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

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

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