def test_process_pre_prepare_with_incorrect_audit_txn_root(orderer_with_requests, state_roots, txn_roots, multi_sig, fake_requests): if not orderer_with_requests.is_master: return handler = Mock() orderer_with_requests._bus.subscribe(RaisedSuspicion, handler) pre_prepare_params = create_pre_prepare_params(state_root=state_roots[DOMAIN_LEDGER_ID], ledger_id=DOMAIN_LEDGER_ID, txn_root=txn_roots[DOMAIN_LEDGER_ID], bls_multi_sig=multi_sig, view_no=orderer_with_requests.view_no, inst_id=0, pool_state_root=state_roots[POOL_LEDGER_ID], # INVALID! audit_txn_root="HSai3sMHKeAva4gWMabDrm1yNhezvPHfXnGyHf2ex1L4", reqs=fake_requests, pp_seq_no=1) pre_prepare = PrePrepare(*pre_prepare_params) _register_pp_ts(orderer_with_requests, pre_prepare, orderer_with_requests.primary_name) orderer_with_requests.process_preprepare(pre_prepare, orderer_with_requests.primary_name) check_suspicious(handler, RaisedSuspicion(inst_id=orderer_with_requests._data.inst_id, ex=SuspiciousNode(orderer_with_requests.primary_name, Suspicions.PPR_AUDIT_TXN_ROOT_HASH_WRONG, pre_prepare)))
def test_suspicious_on_wrong_list_of_primaries(orderer_with_requests, state_roots, txn_roots, multi_sig, fake_requests): if not orderer_with_requests.is_master: return handler = Mock() orderer_with_requests._bus.subscribe(RaisedSuspicion, handler) pre_prepare_params = create_pre_prepare_params(state_root=state_roots[DOMAIN_LEDGER_ID], ledger_id=DOMAIN_LEDGER_ID, txn_root=txn_roots[DOMAIN_LEDGER_ID], bls_multi_sig=multi_sig, view_no=orderer_with_requests.view_no, inst_id=0, pool_state_root=state_roots[POOL_LEDGER_ID], audit_txn_root=state_roots[AUDIT_LEDGER_ID], reqs=fake_requests, pp_seq_no=1, primaries=["Some", "Other", "Primaries"]) pre_prepare = PrePrepare(*pre_prepare_params) _register_pp_ts(orderer_with_requests, pre_prepare, orderer_with_requests.primary_name) orderer_with_requests.process_preprepare(pre_prepare, orderer_with_requests.primary_name) check_suspicious(handler, RaisedSuspicion(inst_id=orderer_with_requests._data.inst_id, ex=SuspiciousNode(orderer_with_requests.primary_name, Suspicions.PPR_WITH_WRONG_PRIMARIES, pre_prepare)))
def test_validate_prepare_from_primary(o, prepare): handler = Mock() o._bus.subscribe(RaisedSuspicion, handler) o._validate_prepare(prepare, PRIMARY_NAME) check_suspicious( handler, RaisedSuspicion(inst_id=o._data.inst_id, ex=SuspiciousNode(PRIMARY_NAME, Suspicions.PR_FRM_PRIMARY, prepare)))
def test_validate_prepare_wrong_state_root(o, pre_prepare, prepare): handler = Mock() o._bus.subscribe(RaisedSuspicion, handler) o.process_preprepare(pre_prepare, PRIMARY_NAME) prepare = updateNamedTuple(prepare, stateRootHash=generate_state_root()) o._validate_prepare(prepare, NON_PRIMARY_NAME) check_suspicious( handler, RaisedSuspicion(inst_id=o._data.inst_id, ex=SuspiciousNode(NON_PRIMARY_NAME, Suspicions.PR_STATE_WRONG, prepare)))
def test_validate_prepare_wrong_digest(o, pre_prepare, prepare): handler = Mock() o._bus.subscribe(RaisedSuspicion, handler) o.process_preprepare(pre_prepare, PRIMARY_NAME) prepare = updateNamedTuple(prepare, digest='fake_digest') o._validate_prepare(prepare, NON_PRIMARY_NAME) check_suspicious( handler, RaisedSuspicion(inst_id=o._data.inst_id, ex=SuspiciousNode(NON_PRIMARY_NAME, Suspicions.PR_DIGEST_WRONG, prepare)))
def test_validate_duplicate_prepare(o, pre_prepare, prepare): handler = Mock() o._bus.subscribe(RaisedSuspicion, handler) o.process_preprepare(pre_prepare, PRIMARY_NAME) o.process_prepare(prepare, NON_PRIMARY_NAME) o._validate_prepare(prepare, NON_PRIMARY_NAME) check_suspicious( handler, RaisedSuspicion(inst_id=o._data.inst_id, ex=SuspiciousNode(NON_PRIMARY_NAME, Suspicions.DUPLICATE_PR_SENT, prepare)))
def test_validate_prepare_no_preprepare(o, prepare): # must sent PrePrepare before processing the Prepare if o.name == PRIMARY_NAME: handler = Mock() o._bus.subscribe(RaisedSuspicion, handler) o._validate_prepare(prepare, NON_PRIMARY_NAME) check_suspicious( handler, RaisedSuspicion(inst_id=o._data.inst_id, ex=SuspiciousNode(NON_PRIMARY_NAME, Suspicions.UNKNOWN_PR_SENT, prepare))) # PrePrepare can be delayed, so just enqueue else: o._validate_prepare(prepare, NON_PRIMARY_NAME) assert (prepare, NON_PRIMARY_NAME ) in o.preparesWaitingForPrePrepare[prepare.viewNo, prepare.ppSeqNo]
def test_process_pre_prepare_with_ordered_request(orderer, pre_prepare): handler = Mock() orderer._bus.subscribe(RaisedSuspicion, handler) orderer.db_manager.stores[SEQ_NO_DB_LABEL] = FakeSomething(get_by_full_digest=lambda req: 'sample', get_by_payload_digest=lambda req: (1, 1)) orderer._non_finalised_reqs = lambda a: pre_prepare.reqIdr def request_propagates(reqs): assert False, "Requested propagates for: {}".format(reqs) orderer._bus.subscribe(RequestPropagates, request_propagates) orderer.process_preprepare(pre_prepare, orderer.primary_name) check_suspicious(handler, RaisedSuspicion(inst_id=orderer._data.inst_id, ex=SuspiciousNode(orderer.primary_name, Suspicions.PPR_WITH_ORDERED_REQUEST, pre_prepare)))