def test_invalid_payload_sender(self): """ Tests that an exception is thrown when given an invalid sender """ # Test invalid type (non hex) tx_struct = TestVoteTransaction.create_tx_struct() tx_struct.payload.sender = ''.join(['X' for _ in range(64)]) tx = VoteTransaction.from_data(tx_struct, validate=False) self.assertRaises(Exception, tx.validate_payload) # Test invalid length tx_struct = TestVoteTransaction.create_tx_struct() tx_struct.payload.sender = ''.join(['a' for _ in range(50)]) tx = VoteTransaction.from_data(tx_struct, validate=False) self.assertRaises(Exception, tx.validate_payload)
def test_validation(self): """ Tests that all validation passes with a correct struct """ tx_struct = TestVoteTransaction.create_tx_struct() tx = VoteTransaction.from_data(tx_struct, validate=True) self.assertTrue(True)
def test_from_data(self): """ Tests from_data with a valid capnp struct (no validation) """ tx_struct = TestVoteTransaction.create_tx_struct() tx = VoteTransaction.from_data(tx_struct, validate=False) self.__assert_struct_equal_object(tx_struct, tx)
def test_serialization(self): """ Tests that serialize and from_bytes are inverse operations """ tx_struct = TestVoteTransaction.create_tx_struct() struct_binary = tx_struct.to_bytes_packed() tx = VoteTransaction.from_data(tx_struct, validate=False)
def test_from_bytes(self): """ Tests from_bytes with a valid serialized capnp struct (no validation) """ tx_struct = TestVoteTransaction.create_tx_struct() tx = VoteTransaction.from_bytes(tx_struct.to_bytes_packed(), validate=False) self.__assert_struct_equal_object(tx_struct, tx)
def test_invalid_signature(self): """ Tests that an exception is thrown when given an invalid signature """ # Test invalid type (non hex) tx_struct = TestVoteTransaction.create_tx_struct() tx_struct.metadata.signature = ''.join(['X' for _ in range(128)]) tx = VoteTransaction.from_data(tx_struct, validate=False) self.assertRaises(Exception, tx.validate_signature) # Test invalid length tx_struct = TestVoteTransaction.create_tx_struct() tx_struct.metadata.signature = ''.join(['X' for _ in range(44)]) tx = VoteTransaction.from_data(tx_struct, validate=False) self.assertRaises(Exception, tx.validate_signature) # Test invalid signature tx_struct = TestVoteTransaction.create_tx_struct() tx_struct.metadata.signature = ''.join(['a' for _ in range(128)]) tx = VoteTransaction.from_data(tx_struct, validate=False) self.assertRaises(Exception, tx.validate_signature)
def test_invalid_pow(self): """ Tests that an exception is thrown when given an invalid proof """ # Test invalid type (non hex) tx_struct = TestVoteTransaction.create_tx_struct() tx_struct.metadata.proof = ''.join(['X' for _ in range(32)]) tx = VoteTransaction.from_data(tx_struct, validate=False) self.assertRaises(Exception, tx.validate_pow) # Test invalid length tx_struct = TestVoteTransaction.create_tx_struct() tx_struct.metadata.proof = ''.join(['a' for _ in range(30)]) tx = VoteTransaction.from_data(tx_struct, validate=False) self.assertRaises(Exception, tx.validate_pow) # Test invalid proof tx_struct = TestVoteTransaction.create_tx_struct() tx_struct.metadata.proof = ''.join(['a' for _ in range(32)]) tx = VoteTransaction.from_data(tx_struct, validate=False) self.assertRaises(Exception, tx.validate_pow)