public async void should_ignore_invalid_incoming_transaction()
        {
            //arrange
            A.CallTo(() => _blockVerifier.VerifyTransaction(A <Transaction> .Ignored, A <ICollection <Transaction> > .Ignored))
            .Returns(-1);

            //act
            var result = await _subject.RecieveTransaction(new Transaction()
            {
                TransactionId = new byte[0]
            });

            //assert
            A.CallTo(() => _blockVerifier.VerifyTransaction(A <Transaction> .Ignored, A <ICollection <Transaction> > .Ignored))
            .MustHaveHappened();

            A.CallTo(() => _unconfirmedTransactionPool.Add(A <Transaction> .Ignored))
            .MustNotHaveHappened();

            result.Should().Be(PeerDataResult.Ignore);
        }
Esempio n. 2
0
        public async Task <PeerDataResult> RecieveTransaction(Transaction transaction)
        {
            _logger.LogDebug($"Recv txn {BitConverter.ToString(transaction.TransactionId)}");
            var txnResult = await _blockVerifier.VerifyTransaction(transaction, _unconfirmedTransactionPool.Get);

            if (txnResult == 0)
            {
                if (_unconfirmedTransactionPool.Add(transaction))
                {
                    _logger.LogDebug($"Accepted txn {BitConverter.ToString(transaction.TransactionId)}");
                    return(PeerDataResult.Relay);
                }

                return(PeerDataResult.Ignore);
            }
            _logger.LogDebug($"Rejected txn {BitConverter.ToString(transaction.TransactionId)} code: {txnResult}");
            return(PeerDataResult.Ignore);
        }