示例#1
0
        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);
        }
示例#2
0
 public async Task HandleTransactionsReceivedAsync(TransactionsReceivedEvent eventData)
 {
     foreach (var transaction in eventData.Transactions)
     {
         _allTransactions.Add(transaction.GetHash(), transaction);
         await _transactionManager.AddTransactionAsync(transaction);
     }
 }
示例#3
0
        public async Task BroadcastTransactions(IEnumerable <Transaction> transactions)
        {
            var transactionsReceivedEvent = new TransactionsReceivedEvent
            {
                Transactions = transactions
            };

            await _txHub.HandleTransactionsReceivedAsync(transactionsReceivedEvent);
        }
示例#4
0
文件: MockTxHub.cs 项目: zhxymh/AElf
        public async Task HandleTransactionsReceivedAsync(TransactionsReceivedEvent eventData)
        {
            foreach (var transaction in eventData.Transactions)
            {
                _allTransactions.Add(transaction.GetHash(), transaction);
            }

            await _blockchainService.AddTransactionsAsync(eventData.Transactions);
        }
示例#5
0
 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);
     }
 }
示例#6
0
        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);
        }
示例#7
0
        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);
        }
示例#8
0
        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();
        }