Пример #1
0
 public static Transaction GetTransactionContainingResources(TransactionResourceInfo resourceInfo)
 {
     return(new Transaction
     {
         Params = resourceInfo.ToByteString()
     });
 }
        private (ExecutionReturnSet, Transaction) GetFakePairs(Address destination, int[] expectedKeys,
                                                               int[] actualKeys = null)
        {
            var tri = new TransactionResourceInfo
            {
                Paths =
                {
                    expectedKeys.Select(GetPath)
                }
            };
            var txn = new Transaction
            {
                From       = SampleAddress.AddressList[7],
                To         = destination,
                MethodName = "Dummy",
                Params     = tri.ToByteString(),
                Signature  = ByteString.CopyFromUtf8("SignaturePlaceholder")
            };
            var rs = new ExecutionReturnSet {
                TransactionId = txn.GetHash()
            };

            actualKeys = actualKeys ?? expectedKeys;
            foreach (var key in actualKeys.Select(GetPath).Select(p => p.ToStateKey()))
            {
                rs.StateAccesses[key] = true;
            }

            return(rs, txn);
        }
Пример #3
0
 public TransactionResourceCache(TransactionResourceInfo resourceInfo, Address address,
                                 long resourceUsedBlockHeight)
 {
     ResourceUsedBlockHeight = resourceUsedBlockHeight;
     ResourceInfo            = resourceInfo;
     Address = address;
 }
        public async Task GetResourcesAsync_WithNonParallelCode_Test()
        {
            var txn = GetNonParallelCodeTransaction(new ResourceInfo());
            await Service.HandleTransactionAcceptedEvent(new TransactionAcceptedEvent
            {
                Transaction = txn
            });

            var resourceInfos =
                (await Service.GetResourcesAsync(new Mock <IChainContext>().Object, new[] { txn }, CancellationToken.None))
                .ToList();

            resourceInfos.Count.ShouldBe(1);
            var testContractFile = typeof(SmartContractExecution.Parallel.Tests.TestContract.TestContract).Assembly
                                   .Location;
            var code = File.ReadAllBytes(testContractFile);
            var transactionResourceInfo = new TransactionResourceInfo
            {
                TransactionId             = txn.GetHash(),
                ParallelType              = ParallelType.NonParallelizable,
                IsNonparallelContractCode = true,
                ContractHash              = HashHelper.ComputeFrom(code)
            };

            resourceInfos.First().TransactionResourceInfo.ShouldBe(transactionResourceInfo);
        }
Пример #5
0
        private (ExecutionReturnSet, Transaction) GetFakePairs(Address destination, int[] expectedKeys,
                                                               int[] actualKeys = null, int[] readExpectedKeys = null, int[] readOnlyActualKeys = null)
        {
            var tri = new TransactionResourceInfo
            {
                WritePaths =
                {
                    expectedKeys.Select(GetPath)
                }
            };

            if (readExpectedKeys != null)
            {
                tri.ReadPaths.AddRange(readExpectedKeys.Select(GetPath));
            }
            var txn = new Transaction
            {
                From       = SampleAddress.AddressList[7],
                To         = destination,
                MethodName = "Dummy",
                Params     = tri.ToByteString(),
                Signature  = ByteString.CopyFromUtf8(KernelConstants.SignaturePlaceholder)
            };
            var rs = new ExecutionReturnSet {
                TransactionId = txn.GetHash()
            };

            actualKeys ??= expectedKeys;
            var readOnlyStateKeys = readOnlyActualKeys?.Select(GetPath).Select(p => p.ToStateKey()).ToList();

            foreach (var key in actualKeys.Select(GetPath).Select(p => p.ToStateKey()))
            {
                rs.StateAccesses[key] = true;
                if (readOnlyActualKeys != null && readOnlyStateKeys.Contains(key))
                {
                    continue;
                }
                rs.StateChanges[key] = ByteString.Empty;
            }

            return(rs, txn);
        }
        public async Task GetResourcesAsync_WithCache_Test()
        {
            var txn = GetNonAcs2Transaction(new ResourceInfo());
            await Service.HandleTransactionAcceptedEvent(new TransactionAcceptedEvent
            {
                Transaction = txn
            });

            var otherTxn      = GetNonAcs2Transaction(new ResourceInfo());
            var resourceInfos =
                (await Service.GetResourcesAsync(new Mock <IChainContext>().Object, new[] { txn, otherTxn }, CancellationToken.None))
                .ToList();

            resourceInfos.Count.ShouldBe(2);
            var transactionResourceInfo = new TransactionResourceInfo
            {
                TransactionId = txn.GetHash(),
                ParallelType  = ParallelType.NonParallelizable
            };

            resourceInfos.First().TransactionResourceInfo.ShouldBe(transactionResourceInfo);
            resourceInfos[1].TransactionResourceInfo.ShouldBe(transactionResourceInfo);
        }
Пример #7
0
 public TransactionResourceCache(long refBlockNumber, TransactionResourceInfo resourceInfo, Address address)
 {
     RefBlockNumber = refBlockNumber;
     ResourceInfo   = resourceInfo;
     Address        = address;
 }
Пример #8
0
 public TransactionResourceCache(TransactionResourceInfo resourceInfo, Address address)
 {
     ResourceUsedBlockHeight = long.MaxValue;
     ResourceInfo            = resourceInfo;
     Address = address;
 }