Exemplo n.º 1
0
        public async Task TwoJobsTest()
        {
            var balances = new List <int>()
            {
                100,
                0
            };
            var addresses = Enumerable.Range(0, balances.Count).Select(x => Address.FromRawBytes(Hash.Generate().ToByteArray())).ToList();

            foreach (var addbal in addresses.Zip(balances, Tuple.Create))
            {
                _mock.Initialize1(addbal.Item1, (ulong)addbal.Item2);
            }

            var txs = new List <Transaction>()
            {
                _mock.GetTransferTxn1(addresses[0], addresses[1], 10),
            };
            var txsHashes = txs.Select(y => y.GetHash()).ToList();

            var finalBalances = new List <int>
            {
                90,
                10
            };

            var service = new ParallelTransactionExecutingService(_mock.ActorEnvironment,
                                                                  new Grouper(_mock.ServicePack.ResourceDetectionService), _mock.ServicePack);

            var traces = await service.ExecuteAsync(txs, _mock.ChainId1, CancellationToken.None);

            foreach (var txTrace in txs.Zip(traces, Tuple.Create))
            {
                Assert.Equal(txTrace.Item1.GetHash(), txTrace.Item2.TransactionId);
                if (!string.IsNullOrEmpty(txTrace.Item2.StdErr))
                {
                    Assert.Null(txTrace.Item2.StdErr);
                }
            }

            foreach (var addFinbal in addresses.Zip(finalBalances, Tuple.Create))
            {
                Assert.Equal((ulong)addFinbal.Item2, _mock.GetBalance1(addFinbal.Item1));
            }
        }