Пример #1
0
        public async Task BroadcastTransaction_ThrowNetworkException_Test()
        {
            _testContext.MockedPeers[0]
            .Setup(p => p.EnqueueTransaction(It.IsAny <Transaction>(), It.IsAny <Action <NetworkException> >()))
            .Callback <Transaction, Action <NetworkException> >((block, action) =>
                                                                action.Invoke(new NetworkException()));
            _testContext.MockedPeers[1]
            .Setup(p => p.EnqueueTransaction(It.IsAny <Transaction>(), It.IsAny <Action <NetworkException> >()))
            .Callback <Transaction, Action <NetworkException> >((block, action) =>
                                                                action.Invoke(new NetworkException("Unrecoverable", NetworkExceptionType.Unrecoverable)));
            _testContext.MockedPeers[2]
            .Setup(p => p.EnqueueTransaction(It.IsAny <Transaction>(), It.IsAny <Action <NetworkException> >()))
            .Callback <Transaction, Action <NetworkException> >((block, action) =>
                                                                action.Invoke(new NetworkException("PeerUnstable", NetworkExceptionType.PeerUnstable)));

            var transaction = OsCoreTestHelper.CreateFakeTransaction();

            await _networkService.BroadcastTransactionAsync(transaction);

            foreach (var peer in _testContext.MockedPeers)
            {
                peer.Verify(p => p.EnqueueTransaction(It.Is <Transaction>(tx => tx.GetHash() == transaction.GetHash()),
                                                      It.IsAny <Action <NetworkException> >()), Times.Once());
            }

            _testContext.MockAElfNetworkServer.Verify(s => s.TrySchedulePeerReconnectionAsync(It.IsAny <IPeer>()),
                                                      Times.Once());
        }
Пример #2
0
        public async Task BroadcastTransaction_OnePeerKnowsTransaction_Test()
        {
            var transaction = OsCoreTestHelper.CreateFakeTransaction();

            _peerPool.FindPeerByPublicKey("Pubkey0").TryAddKnownTransaction(transaction.GetHash());

            await _networkService.BroadcastTransactionAsync(transaction);

            _testContext.MockedPeers[0].Verify(p => p.EnqueueTransaction(It.Is <Transaction>(tx => tx.GetHash() == transaction.GetHash()),
                                                                         It.IsAny <Action <NetworkException> >()), Times.Never);
            _testContext.MockedPeers[1].Verify(p => p.EnqueueTransaction(It.Is <Transaction>(tx => tx.GetHash() == transaction.GetHash()),
                                                                         It.IsAny <Action <NetworkException> >()), Times.Once());
            _testContext.MockedPeers[2].Verify(p => p.EnqueueTransaction(It.Is <Transaction>(tx => tx.GetHash() == transaction.GetHash()),
                                                                         It.IsAny <Action <NetworkException> >()), Times.Once());
        }
Пример #3
0
        public async Task BroadcastTransaction_PeerNotReady_Test()
        {
            _testContext.MockedPeers[0]
            .Setup(p => p.EnqueueTransaction(It.IsAny <Transaction>(), It.IsAny <Action <NetworkException> >()))
            .Throws <NetworkException>();

            var transaction = OsCoreTestHelper.CreateFakeTransaction();

            await _networkService.BroadcastTransactionAsync(transaction);

            foreach (var peer in _testContext.MockedPeers)
            {
                peer.Verify(p => p.EnqueueTransaction(It.Is <Transaction>(tx => tx.GetHash() == transaction.GetHash()),
                                                      It.IsAny <Action <NetworkException> >()), Times.Once());
            }
        }
Пример #4
0
        public async Task BroadcastTransaction_Test()
        {
            var transaction = OsCoreTestHelper.CreateFakeTransaction();

            await _networkService.BroadcastTransactionAsync(transaction);

            foreach (var peer in _testContext.MockedPeers)
            {
                peer.Object.TryAddKnownTransaction(transaction.GetHash());
            }

            await _networkService.BroadcastTransactionAsync(transaction);

            foreach (var peer in _testContext.MockedPeers)
            {
                peer.Verify(p => p.EnqueueTransaction(It.Is <Transaction>(tx => tx.GetHash() == transaction.GetHash()),
                                                      It.IsAny <Action <NetworkException> >()), Times.Once());
            }
        }