Пример #1
0
class Ordered(MessageBase):
    typename = ORDERED
    schema = (
        (f.INST_ID.nm, NonNegativeNumberField()),
        (f.VIEW_NO.nm, NonNegativeNumberField()),
        (f.REQ_IDR.nm, IterableField(RequestIdentifierField())),
        (f.PP_SEQ_NO.nm, NonNegativeNumberField()),
        (f.PP_TIME.nm, TimestampField()),
        (f.LEDGER_ID.nm, LedgerIdField()),
        (f.STATE_ROOT.nm, MerkleRootField(nullable=True)),
        (f.TXN_ROOT.nm, MerkleRootField(nullable=True)),
    )
Пример #2
0
class PrePrepare(MessageBase):
    typename = PREPREPARE
    schema = (
        (f.INST_ID.nm, NonNegativeNumberField()),
        (f.VIEW_NO.nm, NonNegativeNumberField()),
        (f.PP_SEQ_NO.nm, NonNegativeNumberField()),
        (f.PP_TIME.nm, TimestampField()),
        (f.REQ_IDR.nm, IterableField(RequestIdentifierField())),
        (f.DISCARDED.nm, NonNegativeNumberField()),
        (f.DIGEST.nm, LimitedLengthStringField(max_length=DIGEST_FIELD_LIMIT)),
        (f.LEDGER_ID.nm, LedgerIdField()),
        (f.STATE_ROOT.nm, MerkleRootField(nullable=True)),
        (f.TXN_ROOT.nm, MerkleRootField(nullable=True)),
    )
Пример #3
0
class PrePrepare(MessageBase):
    typename = PREPREPARE
    schema = (
        (f.INST_ID.nm, NonNegativeNumberField()),
        (f.VIEW_NO.nm, NonNegativeNumberField()),
        (f.PP_SEQ_NO.nm, NonNegativeNumberField()),
        (f.PP_TIME.nm, TimestampField()),
        (f.REQ_IDR.nm, IterableField(RequestIdentifierField())),
        (f.DISCARDED.nm, NonNegativeNumberField()),
        (f.DIGEST.nm, LimitedLengthStringField(max_length=DIGEST_FIELD_LIMIT)),
        (f.LEDGER_ID.nm, LedgerIdField()),
        (f.STATE_ROOT.nm, MerkleRootField(nullable=True)),
        (f.TXN_ROOT.nm, MerkleRootField(nullable=True)),
        # TODO: support multiple multi-sigs for multiple previous batches
        (f.BLS_MULTI_SIG.nm,
         BlsMultiSignatureField(optional=True, nullable=True)))
Пример #4
0
 def _validate_requested_propagate(self, **kwargs):
     if not (RequestIdentifierField().validate(
         (kwargs['identifier'], kwargs['req_id']))):
         if 'propagate' in kwargs:
             try:
                 # the input is expected as a dict (serialization with ujson==1.33)
                 ppg = Propagate(**kwargs['propagate'])
                 if ppg.request[f.IDENTIFIER.nm] != kwargs['identifier'] or \
                                 ppg.request[f.REQ_ID.nm] != kwargs['req_id']:
                     logger.warning('{} found PROPAGATE {} not '
                                    'satisfying query criteria'.format(
                                        self, *kwargs['ppg']))
                     return
                 return ppg
             except TypeError as ex:
                 logger.warning(
                     '{} could not create PROPAGATE out of {}'.format(
                         self, **kwargs['propagate']))
         else:
             return True
import pytest

from plenum.common.messages.fields import RequestIdentifierField
from plenum.test.input_validation.constants import \
    TEST_IDENTIFIER_SHORT, TEST_IDENTIFIER_LONG

from plenum.test.input_validation.utils import b58_by_len

validator = RequestIdentifierField()

# Request id consists of client identifier (base56 string 16/32 long) and
# some number (for now it is current timestamp, but can be any number)
valid_request_id = (TEST_IDENTIFIER_LONG, 11111)


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_invalid_order():
    s, t = valid_request_id
    assert validator.validate((t, s))


def test_empty_client_id():
    assert validator.validate(("", valid_request_id[1]))
 def validate(self, **kwargs) -> bool:
     return not (RequestIdentifierField().validate((kwargs['identifier'],
                 kwargs['req_id'])))