def test_invalid_symbols(): INVALID_CHARS = '0!@#$%^' res = Base58Field().validate( b58_by_len(10)[slice(0, -len(INVALID_CHARS))] + INVALID_CHARS) assert res assert (res == 'should not contain the following chars {}' .format(sorted(set(INVALID_CHARS))[:10]))
def test_invalid_symbols_truncated_output(): INVALID_CHARS = '\x00\xAA0!@#$%^&*()' res = Base58Field().validate( b58_by_len(20)[slice(0, -len(INVALID_CHARS))] + INVALID_CHARS) assert res assert (res == 'should not contain the following chars ' '{} (truncated)'.format(sorted(set(INVALID_CHARS))[:10]))
def test_identifiers(): for byte_len in range(1, 33): val = b58_by_len(byte_len) if byte_len in (16, 32): assert not validator.validate(val) else: assert validator.validate(val)
def test_valid_request_id(): for byte_len in range(1, 33): val = b58_by_len(byte_len) if byte_len in (16, 32): assert not validator.validate((val, 11111)) else: assert validator.validate(val)
def test_non_empty_merkle_roots(): for byte_len in range(1, 33): val = b58_by_len(byte_len) if byte_len == 32: assert not validator.validate(val) else: assert validator.validate(val)
def test_non_empty_base58(): for byte_len in range(1, 33): val = b58_by_len(byte_len) assert not Base58Field().validate(val) # no decoded length constraints assert not Base58Field( byte_lengths=(byte_len,)).validate(val) assert Base58Field( byte_lengths=(byte_len - 1,)).validate(val)
def test_multiple_constraints(): choices = (1, 7, 18) validator = Base58Field(byte_lengths=choices) for byte_len in range(1, 33): val = b58_by_len(byte_len) if byte_len in choices: assert not validator.validate(val) else: assert validator.validate(val)
def test_short_length_verkeys(): assert not op_nym.validate({ TXN_TYPE: NYM, TARGET_NYM: TEST_TARGET_NYM, VERKEY: TEST_VERKEY_ABBREVIATED }) with pytest.raises(TypeError) as ex_info: op_nym.validate({ TXN_TYPE: NYM, TARGET_NYM: TEST_TARGET_NYM, VERKEY: b58_by_len(16) }) ex_info.match(r'b58 decoded value length 16 should be one of \[32\]') with pytest.raises(TypeError) as ex_info: op_nym.validate({ TXN_TYPE: NYM, TARGET_NYM: TEST_TARGET_NYM, VERKEY: '~' + b58_by_len(32) }) ex_info.match(r'b58 decoded value length 32 should be one of \[16\]')
def test_non_empty_verkeys(): for byte_len in range(1, 33): val = b58_by_len(byte_len) as_long = validator.validate(val) as_short = validator.validate('~' + val) if byte_len == 16: assert as_long.startswith(err) assert not as_short elif byte_len == 32: assert not as_long assert as_short.startswith(err) else: assert as_long.startswith(err) assert as_short.startswith(err)
def test_non_empty_verkeys(): for byte_len in range(1, 33): val = b58_by_len(byte_len) as_long = validator.validate(val) as_short = validator.validate('~' + val) if byte_len == 16: assert (as_long == 'b58 decoded value length 16 should be one of [32]') assert not as_short elif byte_len == 32: assert not as_long assert (as_short == 'b58 decoded value length 32 should be one of [16]') else: assert (as_long == 'b58 decoded value length {} should be one of [32]' .format(byte_len)) assert (as_short == 'b58 decoded value length {} should be one of [16]' .format(byte_len))
def test_invalid_symbol(): res = validator.validate(b58_by_len(32)[:-1] + '0') assert res assert (res == "should not contain the following chars {}".format( sorted(set('0'))))
def test_invalid_txn_root_hash(): assert validator.validate((ledger_id, state_root_hash, pool_state_root_hash, b58_by_len(31), timestamp))
from plenum.common.messages.fields import BlsMultiSignatureField, TimestampField from plenum.common.util import get_utc_epoch from plenum.test.input_validation.utils import b58_by_len validator = BlsMultiSignatureField() state_root_hash = b58_by_len(32) pool_state_root_hash = b58_by_len(32) txn_root_hash = b58_by_len(32) ledger_id = 1 timestamp = get_utc_epoch() value = (ledger_id, state_root_hash, pool_state_root_hash, txn_root_hash, timestamp) invalid_value1 = (-1, state_root_hash, pool_state_root_hash, txn_root_hash, timestamp) invalid_value2 = (ledger_id, b58_by_len(31), pool_state_root_hash, txn_root_hash, timestamp) invalid_value3 = (ledger_id, state_root_hash, pool_state_root_hash, txn_root_hash,
from plenum.common.messages.fields import BlsMultiSignatureField, TimestampField from plenum.common.util import get_utc_epoch from plenum.test.input_validation.utils import b58_by_len validator = BlsMultiSignatureField() state_root_hash = b58_by_len(32) pool_state_root_hash = b58_by_len(32) txn_root_hash = b58_by_len(32) ledger_id = 1 timestamp = get_utc_epoch() value = (ledger_id, state_root_hash, pool_state_root_hash, txn_root_hash, timestamp) invalid_value1 = (-1, state_root_hash, pool_state_root_hash, txn_root_hash, timestamp) invalid_value2 = (ledger_id, b58_by_len(31), pool_state_root_hash, txn_root_hash, timestamp) invalid_value3 = (ledger_id, state_root_hash, pool_state_root_hash, txn_root_hash, TimestampField._oldest_time - 1) participants = ["Node1", "Node2", "Node3"] signature = "somefakesignaturesomefakesignaturesomefakesignature" def test_valid(): assert not validator.validate((signature, participants, value)) assert not validator.validate(('1' * 512, participants, value)) def test_invalid_participants():
def test_invalid_char(): res = validator.validate(b58_by_len(16)[:-1] + '+') assert res assert (res == "should not contain the following chars {}". format(sorted(set('+'))))
from plenum.common.constants import DOMAIN_LEDGER_ID from plenum.common.messages.fields import BlsMultiSignatureValueField, TimestampField from plenum.common.util import get_utc_epoch from plenum.test.input_validation.utils import b58_by_len validator = BlsMultiSignatureValueField() state_root_hash = b58_by_len(32) pool_state_root_hash = b58_by_len(32) txn_root_hash = b58_by_len(32) ledger_id = DOMAIN_LEDGER_ID timestamp = get_utc_epoch() def test_valid(): assert not validator.validate( (ledger_id, state_root_hash, pool_state_root_hash, txn_root_hash, timestamp)) def test_invalid_ledger_id(): assert validator.validate( (100, state_root_hash, pool_state_root_hash, txn_root_hash, timestamp)) def test_invalid_state_root_hash(): assert validator.validate((ledger_id, b58_by_len(31), pool_state_root_hash, txn_root_hash, timestamp)) def test_invalid_pool_state_root_hash(): assert validator.validate(
def test_invalid_txn_root_hash(): assert validator.validate( (ledger_id, state_root_hash, pool_state_root_hash, b58_by_len(31), timestamp))