public void Can_Save_Increased_Peer() { var pid = PeerIdHelper.GetPeerId("some_peer"); var savedPeer = SavePeerInRepo(pid); var peerReputationChange = Substitute.For <IPeerReputationChange>(); peerReputationChange.PeerId.Returns(pid); peerReputationChange.ReputationEvent.Returns(Substitute.For <IReputationEvents>()); peerReputationChange.ReputationEvent.Amount.Returns(100); _reputationManager.OnNext(peerReputationChange); var updatedSubbedPeer = _reputationManager.PeerRepository.Get(savedPeer.DocumentId); updatedSubbedPeer.Reputation.Should().Be(200); }
public void OnNext(FavouriteDeltaBroadcast candidate) { _logger.Verbose("Favourite candidate delta received {favourite}", candidate); try { Guard.Argument(candidate, nameof(candidate)).NotNull().Require(f => f.IsValid()); var cid = candidate.Candidate.PreviousDeltaDfsHash.ToByteArray().ToCid(); if (!_deltaProducersProvider .GetDeltaProducersFromPreviousDelta(cid) .Any(p => p.Equals(candidate.VoterId))) { var reputationChange = new ReputationChange(candidate.VoterId, ReputationEventType.VoterIsNotProducer); _reputationManager.OnNext(reputationChange); _logger.Debug( "Voter {voter} is not a producer for this cycle succeeding {deltaHash} and its vote has been discarded.", candidate.VoterId, candidate.Candidate.PreviousDeltaDfsHash); return; } var candidateListKey = GetCandidateListCacheKey(candidate); if (_candidatesCache.TryGetValue(candidateListKey, out ConcurrentDictionary <FavouriteDeltaBroadcast, bool> retrieved)) { retrieved.TryAdd(candidate, default); return; } _candidatesCache.Set(candidateListKey, new ConcurrentDictionary <FavouriteDeltaBroadcast, bool>( new[] { new KeyValuePair <FavouriteDeltaBroadcast, bool>(candidate, false) }, FavouriteByHashAndVoterComparer.Default), _cacheEntryOptions()); } catch (Exception e) { _logger.Error(e, "Failed to process favourite delta {0}", candidate); } }