def test_fill_ts_store_after_catchup(txnPoolNodeSet, looper, sdk_pool_handle, sdk_wallet_steward, tconf, tdir, allPluginsPath): sdk_send_random_and_check(looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_steward, 5) node_to_disconnect = txnPoolNodeSet[-1] disconnect_node_and_ensure_disconnected(looper, txnPoolNodeSet, node_to_disconnect) looper.removeProdable(name=node_to_disconnect.name) sdk_replies = sdk_send_random_and_check(looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_steward, 2) node_to_disconnect = start_stopped_node(node_to_disconnect, looper, tconf, tdir, allPluginsPath) txnPoolNodeSet[-1] = node_to_disconnect looper.run(checkNodesConnected(txnPoolNodeSet)) waitNodeDataEquality(looper, node_to_disconnect, *txnPoolNodeSet, exclude_from_check=['check_last_ordered_3pc_backup']) req_handler = node_to_disconnect.read_manager.request_handlers[GET_BUY] for reply in sdk_replies: key = BuyHandler.prepare_buy_key(get_from(reply[1]['result']), get_req_id(reply[1]['result'])) root_hash = req_handler.database_manager.ts_store.get_equal_or_prev( get_txn_time(reply[1]['result'])) assert root_hash from_state = req_handler.state.get_for_root_hash(root_hash=root_hash, key=key) assert domain_state_serializer.deserialize(from_state)['amount'] == \ get_payload_data(reply[1]['result'])['amount']
def test_get_state_value_and_proof(looper, sdk_wallet_steward, sdk_pool_handle, txnPoolNodeSet): node = txnPoolNodeSet[0] req_handler = node.read_manager.request_handlers[GET_BUY] req1, _ = sdk_send_random_and_check(looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_steward, 1)[0] # Save headHash after first request head1 = req_handler.state.headHash sdk_send_random_and_check(looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_steward, 1) # Save headHash after second request head2 = req_handler.state.headHash # Build path to first request path1 = BuyHandler.prepare_buy_key(req1[f.IDENTIFIER.nm], req1[f.REQ_ID.nm]) # Check that if parameter "head_hash" is None, then we make proof for commitedHeadHash (by default) val, proof = req_handler._get_value_from_state(path1, with_proof=True) assert b58encode(head2).decode() == proof[ROOT_HASH] assert val == req_handler.state.get(path1) # Check that if parameter "head_hash" is not None, then we make proof for given headHash val, proof = req_handler._get_value_from_state(path1, head_hash=head1, with_proof=True) assert b58encode(head1).decode() == proof[ROOT_HASH] assert val == req_handler.state.get_for_root_hash(head1, path1) # Get value without proof val, proof = req_handler._get_value_from_state(path1, with_proof=False) assert proof is None assert val == req_handler.state.get(path1)
def prepare_for_state_read(req: Request): if req.txn_type == "buy": txn = reqToTxn(req) key = BuyHandler.prepare_buy_key(req.identifier, req.reqId) value = domain_state_serializer.serialize( {"amount": get_payload_data(txn)['amount']}) return key, value
def get_result(self, request: Request): identifier, req_id, operation = get_request_data(request) buy_key = BuyHandler.prepare_buy_key(identifier, req_id) result = self.state.get(buy_key) res = {f.IDENTIFIER.nm: identifier, f.REQ_ID.nm: req_id, "buy": result} return Reply(res)
def prepare_buy_for_state(txn): identifier = get_from(txn) req_id = get_req_id(txn) value = domain_state_serializer.serialize( {"amount": get_payload_data(txn)['amount']}) key = BuyHandler.prepare_buy_key(identifier, req_id) return key, value
def test_make_proof_bls_disabled(looper, txnPoolNodeSet, sdk_wallet_client): req = json.loads( sdk_signed_random_requests(looper, sdk_wallet_client, 1)[0]) for node in txnPoolNodeSet: req_handler = node.read_manager.request_handlers[GET_BUY] key = BuyHandler.prepare_buy_key(req['identifier'], req['reqId']) _, _, _, proof = req_handler.lookup(key, with_proof=True) assert not proof
def test_make_result_bls_disabled(looper, txnPoolNodeSet, sdk_wallet_client): req = json.loads( sdk_signed_random_requests(looper, sdk_wallet_client, 1)[0]) for node in txnPoolNodeSet: req_handler = node.read_manager.request_handlers[GET_BUY] key = BuyHandler.prepare_buy_key(req['identifier'], req['reqId']) _, _, _, proof = req_handler.lookup(key, with_proof=True) result = req_handler.make_result(sdk_json_to_request_object(req), {TXN_TYPE: "buy"}, 2, get_utc_epoch(), proof) assert STATE_PROOF not in result
def test_make_proof_committed_head_used(looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_client): req_dict, _ = sdk_send_random_requests(looper, sdk_pool_handle, sdk_wallet_client, 1)[0] req = sdk_json_to_request_object(req_dict) wait_for_requests_ordered(looper, txnPoolNodeSet, [req]) key = BuyHandler.prepare_buy_key(req.identifier, req.reqId) for node in txnPoolNodeSet: node.states[DOMAIN_LEDGER_ID].set(key, b'somevalue') check_result(txnPoolNodeSet, req, True)
def check_result(txnPoolNodeSet, req, should_have_proof): for node in txnPoolNodeSet: req_handler = node.read_manager.request_handlers[GET_BUY] key = BuyHandler.prepare_buy_key(req.identifier, req.reqId) _, _, _, proof = req_handler.lookup(key, with_proof=True) txn_time = get_utc_epoch() result = req_handler.make_result(req, {TXN_TYPE: "buy"}, 2, txn_time, proof) assert result assert result[DATA] == {TXN_TYPE: "buy"} assert result[f.IDENTIFIER.nm] == req.identifier assert result[f.REQ_ID.nm] == req.reqId assert result[f.SEQ_NO.nm] == 2 assert result[TXN_TIME] == txn_time if should_have_proof: assert result[STATE_PROOF] == proof assert validate_proof_for_read(result, req) else: assert STATE_PROOF not in result
def test_make_proof_bls_enabled(looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_client): reqs = sdk_json_couples_to_request_list( sdk_send_random_requests(looper, sdk_pool_handle, sdk_wallet_client, 1)) wait_for_requests_ordered(looper, txnPoolNodeSet, reqs) req = reqs[0] for node in txnPoolNodeSet: req_handler = node.read_manager.request_handlers[GET_BUY] key = BuyHandler.prepare_buy_key(req.identifier, req.reqId) _, _, _, proof = req_handler.lookup(key, with_proof=True) assert proof assert ROOT_HASH in proof assert MULTI_SIGNATURE in proof assert PROOF_NODES in proof multi_sig = proof[MULTI_SIGNATURE] assert MULTI_SIGNATURE_SIGNATURE in multi_sig assert MULTI_SIGNATURE_PARTICIPANTS in multi_sig assert MULTI_SIGNATURE_VALUE in multi_sig multi_sig_value = multi_sig[MULTI_SIGNATURE_VALUE] assert MULTI_SIGNATURE_VALUE_LEDGER_ID in multi_sig_value assert MULTI_SIGNATURE_VALUE_STATE_ROOT in multi_sig_value assert MULTI_SIGNATURE_VALUE_TXN_ROOT in multi_sig_value assert MULTI_SIGNATURE_VALUE_POOL_STATE_ROOT in multi_sig_value assert MULTI_SIGNATURE_VALUE_TIMESTAMP in multi_sig_value # check that multi sig values are in order value_keys = list(multi_sig_value.keys()) assert [ MULTI_SIGNATURE_VALUE_LEDGER_ID, MULTI_SIGNATURE_VALUE_POOL_STATE_ROOT, MULTI_SIGNATURE_VALUE_STATE_ROOT, MULTI_SIGNATURE_VALUE_TIMESTAMP, MULTI_SIGNATURE_VALUE_TXN_ROOT ] == value_keys assert validate_multi_signature(proof, txnPoolNodeSet)