public void should_return_valid_pending_and_queued_transactions() { uint nonce = 3; _stateReader.GetAccount(_address).Returns(Account.TotallyEmpty.WithChangedNonce(nonce)); var transactions = GetTransactions(); _txPool.GetPendingTransactionsBySender() .Returns(new Dictionary <Address, Transaction[]> { { _address, transactions } }); var info = _infoProvider.GetInfo(); info.Pending.Count.Should().Be(1); info.Queued.Count.Should().Be(1); var pending = info.Pending.First(); pending.Key.Should().Be(_address); pending.Value.Count.Should().Be(3); VerifyNonceAndTransactions(pending.Value, 3); VerifyNonceAndTransactions(pending.Value, 4); VerifyNonceAndTransactions(pending.Value, 5); var queued = info.Queued.First(); queued.Key.Should().Be(_address); queued.Value.Count.Should().Be(4); VerifyNonceAndTransactions(queued.Value, 1); VerifyNonceAndTransactions(queued.Value, 2); VerifyNonceAndTransactions(queued.Value, 8); VerifyNonceAndTransactions(queued.Value, 9); }
public TxPoolInfo GetInfo() { var groupedTransactions = _txPool.GetPendingTransactionsBySender(); var pendingTransactions = new Dictionary <Address, IDictionary <ulong, Transaction> >(); var queuedTransactions = new Dictionary <Address, IDictionary <ulong, Transaction> >(); foreach (KeyValuePair <Address, Transaction[]> group in groupedTransactions) { Address address = group.Key; var accountNonce = _stateReader.GetAccount(address).Nonce; var expectedNonce = accountNonce; var pending = new Dictionary <ulong, Transaction>(); var queued = new Dictionary <ulong, Transaction>(); var transactionsOrderedByNonce = group.Value.OrderBy(t => t.Nonce); foreach (var transaction in transactionsOrderedByNonce) { ulong transactionNonce = (ulong)transaction.Nonce; if (transaction.Nonce == expectedNonce) { pending.Add(transactionNonce, transaction); expectedNonce = transaction.Nonce + 1; } else { queued.Add(transactionNonce, transaction); } } if (pending.Any()) { pendingTransactions[address] = pending; } if (queued.Any()) { queuedTransactions[address] = queued; } } return(new TxPoolInfo(pendingTransactions, queuedTransactions)); }
public static bool HasCode(this IAccountStateProvider stateProvider, Address address) => stateProvider.GetAccount(address).HasCode;