public async Task SendTx_ShouldPublishEvent_Test() { TransactionsReceivedEvent received = null; _eventBus.Subscribe <TransactionsReceivedEvent>(t => { received = t; return(Task.CompletedTask); }); var tx = new Transaction { From = SampleAddress.AddressList[0], To = SampleAddress.AddressList[1], RefBlockNumber = 1, MethodName = "Hello" }; var pubKey = "SomePubKey"; Metadata metadata = new Metadata { { GrpcConstants.PubkeyMetadataKey, pubKey } }; var reqBlockCtxt = BuildServerCallContext(metadata); _peerPool.TryAddPeer(GrpcTestPeerHelpers.CreateBasicPeer("127.0.0.1:1245", pubKey)); await _serverService.SendTransaction(tx, reqBlockCtxt); received.Transactions.ShouldNotBeNull(); received.Transactions.Count().ShouldBe(1); received.Transactions.First().From.ShouldBe(tx.From); }
public async Task HandleTransactionsReceivedAsync(TransactionsReceivedEvent eventData) { foreach (var transaction in eventData.Transactions) { _allTransactions.Add(transaction.GetHash(), transaction); await _transactionManager.AddTransactionAsync(transaction); } }
public async Task BroadcastTransactions(IEnumerable <Transaction> transactions) { var transactionsReceivedEvent = new TransactionsReceivedEvent { Transactions = transactions }; await _txHub.HandleTransactionsReceivedAsync(transactionsReceivedEvent); }
public async Task HandleTransactionsReceivedAsync(TransactionsReceivedEvent eventData) { foreach (var transaction in eventData.Transactions) { _allTransactions.Add(transaction.GetHash(), transaction); } await _blockchainService.AddTransactionsAsync(eventData.Transactions); }
public async Task HandleTransactionsReceivedAsync(TransactionsReceivedEvent eventData) { foreach (var transaction in eventData.Transactions) { if (_allTransactions.ContainsKey(transaction.GetHash())) { continue; } _allTransactions.Add(transaction.GetHash(), transaction); await _transactionManager.AddTransactionAsync(transaction); } }
public async Task SendTransactionAsync_Success() { TransactionsReceivedEvent received = null; _eventBus.Subscribe <TransactionsReceivedEvent>(t => { received = t; return(Task.CompletedTask); }); var transactions = await _osTestHelper.GenerateTransferTransactions(1); await _grpcPeer.SendTransactionAsync(transactions.First()); received.ShouldNotBeNull(); received.Transactions.Count().ShouldBe(1); received.Transactions.First().From.ShouldBe(transactions.First().From); }
public async Task SendTx_ShouldPublishEvent() { TransactionsReceivedEvent received = null; _eventBus.Subscribe <TransactionsReceivedEvent>(t => { received = t; return(Task.CompletedTask); }); Transaction tx = new Transaction(); tx.From = SampleAddress.AddressList[0]; tx.To = SampleAddress.AddressList[1]; await _service.SendTransaction(tx, BuildServerCallContext()); received?.Transactions.ShouldNotBeNull(); received.Transactions.Count().ShouldBe(1); received.Transactions.First().From.ShouldBe(tx.From); }
public async Task SendTx_WithHighTxRef_ShouldNotPublishEvent_Test() { TransactionsReceivedEvent received = null; _eventBus.Subscribe <TransactionsReceivedEvent>(t => { received = t; return(Task.CompletedTask); }); Transaction tx = new Transaction(); tx.From = SampleAddress.AddressList[0]; tx.To = SampleAddress.AddressList[1]; var chain = await _blockchainService.GetChainAsync(); tx.RefBlockNumber = chain.BestChainHeight + NetworkConstants.DefaultInitialSyncOffset + 1; await _serverService.SendTransaction(tx, BuildServerCallContext()); received.ShouldBeNull(); }