Пример #1
0
        protected override async Task ProcessParameters(TransactionOperation transaction, JsonElement param)
        {
            var(rawEp, rawParam) = (param.RequiredString("entrypoint"), Micheline.FromJson(param.Required("value")));

            if (transaction.Target is Contract contract)
            {
                var schema = contract.Kind > ContractKind.DelegatorContract
                    ? (await Cache.Schemas.GetAsync(contract))
                    : Script.ManagerTz;

                try
                {
                    var(normEp, normParam) = schema.NormalizeParameter(rawEp, rawParam);

                    transaction.Entrypoint     = normEp;
                    transaction.RawParameters  = normParam.ToBytes();
                    transaction.JsonParameters = schema.HumanizeParameter(normEp, normParam);
                }
                catch (Exception ex)
                {
                    transaction.Entrypoint ??= rawEp;
                    transaction.RawParameters ??= rawParam.ToBytes();

                    if (transaction.Status == OperationStatus.Applied)
                    {
                        Logger.LogError($"Failed to humanize tx {transaction.OpHash} parameters: {ex.Message}");
                    }
                }
            }
            else
            {
                transaction.Entrypoint    = rawEp;
                transaction.RawParameters = rawParam.ToBytes();
            }
        }
Пример #2
0
        public void Operations_are_executed_in_a_transaction()
        {
            var operation = new TransactionOperation();
            var sut       = new AtomicBehavior().AttachTo(operation);

            sut.Execute();

            Assert.True(operation.ExecutedInTransaction);
        }
Пример #3
0
        public void Transactions_are_not_committed_for_failed_operations()
        {
            var operation = new TransactionOperation { ThrowOnExecute = new Exception() };
            var sut = new AtomicBehavior().AttachTo(operation);

            ExecuteIgnoringErrors(sut.Execute);

            Assert.False(operation.TransactionCommitted);
        }
Пример #4
0
        public void Transactions_are_committed_for_successful_operations()
        {
            var operation = new TransactionOperation();
            var sut = new AtomicBehavior().AttachTo(operation);

            sut.Execute();

            Assert.True(operation.TransactionCommitted);
        }
Пример #5
0
        public void Operations_are_executed_in_a_transaction()
        {
            var operation = new TransactionOperation();
            var sut = new AtomicBehavior().AttachTo(operation);

            sut.Execute();

            Assert.True(operation.ExecutedInTransaction);
        }
Пример #6
0
        public void Transactions_are_committed_for_successful_operations()
        {
            var operation = new TransactionOperation();
            var sut       = new AtomicBehavior().AttachTo(operation);

            sut.Execute();

            Assert.True(operation.TransactionCommitted);
        }
Пример #7
0
        public void Transactions_are_not_committed_for_failed_operations()
        {
            var operation = new TransactionOperation {
                ThrowOnExecute = new Exception()
            };
            var sut = new AtomicBehavior().AttachTo(operation);

            ExecuteIgnoringErrors(sut.Execute);

            Assert.False(operation.TransactionCommitted);
        }
Пример #8
0
        public void InitUserObject()
        {
            transaction = new List <TransactionLogs>()
            {
                new TransactionLogs()
                {
                    Amount   = 200,
                    IsIncome = true,
                    UserId   = 1
                },
                new TransactionLogs()
                {
                    Amount   = 100,
                    IsIncome = false,
                    UserId   = 2
                }
            }.AsQueryable();
            users = new List <User>()
            {
                new User()
                {
                    Login    = "******",
                    Password = "******",
                    UserId   = 1
                },
                new User()
                {
                    Login    = "******",
                    Password = "******",
                    UserId   = 2
                }
            }.AsQueryable();

            mockSetUser = Substitute.For <DbSet <User>, IQueryable <User> >();
            ((IQueryable <User>)mockSetUser).Provider.Returns(users.Provider);
            ((IQueryable <User>)mockSetUser).Expression.Returns(users.Expression);
            ((IQueryable <User>)mockSetUser).ElementType.Returns(users.ElementType);
            ((IQueryable <User>)mockSetUser).GetEnumerator().Returns(users.GetEnumerator());
            mockSetTransaction = Substitute.For <DbSet <TransactionLogs>, IQueryable <TransactionLogs> >();
            ((IQueryable <TransactionLogs>)mockSetTransaction).Provider.Returns(transaction.Provider);
            ((IQueryable <TransactionLogs>)mockSetTransaction).Expression.Returns(transaction.Expression);
            ((IQueryable <TransactionLogs>)mockSetTransaction).ElementType.Returns(transaction.ElementType);

            db = Substitute.For <IEFDbContext>();
            db.transactionLogs.Returns(mockSetTransaction);
            db.users.Returns(mockSetUser);
            transactionOperations = new TransactionOperation(db);
        }
Пример #9
0
        protected override IEnumerable <BigMapDiff> ParseBigMapDiffs(TransactionOperation transaction, JsonElement result)
        {
            if (!result.TryGetProperty("big_map_diff", out var diffs))
            {
                return(null);
            }

            return(diffs.RequiredArray().EnumerateArray().Select(x => new UpdateDiff
            {
                Ptr = transaction.Target.Id,
                KeyHash = x.RequiredString("key_hash"),
                Key = Micheline.FromJson(x.Required("key")),
                Value = x.TryGetProperty("value", out var value)
                    ? Micheline.FromJson(value)
                    : null,
            }));
Пример #10
0
        public static void Execute(Executor executor, OpenTransactionCommand openTransactionCommand)
        {
            var containsTransaction = executor.ProcessContext.Connection.ContainsItemInBag(BagNames.TRANSACTION);

            if (containsTransaction)
            {
                executor.HandleExecuteError(new Exception("Invalid open transaction!"));
            }

            var transaction = new TransactionOperation
            {
            };

            executor.ProcessContext.Connection.SetItemInBag(BagNames.TRANSACTION, transaction);

            executor.ExecuteNextCommand();
        }
Пример #11
0
        public Operation CreateOperation(Guid logGuid, TransactionOperation transactionOperation, IOperationProvider operationProvider)
        {
            Operation operation = null;

            if (operationProvider != null)
            {
                OperationProvider = operationProvider;
            }
            else
            {
                throw new ArgumentException("Provider cann't be null");
            }
            switch (transactionOperation)
            {
            case TransactionOperation.CheckPayment:
                operation = new CheckOperation(logGuid, OperationProvider);
                break;

            case TransactionOperation.IPayment:
                operation = new IPaymentOperation(logGuid, OperationProvider);
                break;

            case TransactionOperation.ICommit:
                operation = new ICommitOperation(logGuid, OperationProvider);
                break;

            case TransactionOperation.Cancel:
                operation = new CancelOperation(logGuid, OperationProvider);
                break;

            default:
                string msg = $"TransactionOperation {OperationProvider} not supported";
                Logger.WriteLoggerError(msg);
                throw new ArgumentOutOfRangeException(msg);
            }
            return(operation);
        }
Пример #12
0
 protected override Task ResetGracePeriod(TransactionOperation transaction) => Task.CompletedTask;
 public TransactionInformation(System.Deployment.Internal.Isolation.StoreTransactionOperation[] storeOperations, uint[] rgDispositions, int[] rgResults, DateTime time) : base(null, time)
 {
     this._operations = new ArrayList();
     int num = Math.Min(Math.Min(storeOperations.Length, rgDispositions.Length), rgResults.Length);
     int index = 0;
     for (index = 0; index < num; index++)
     {
         TransactionOperation operation = new TransactionOperation(storeOperations[index], rgDispositions[index], rgResults[index]);
         this._operations.Add(operation);
         if (operation.Failed)
         {
             this._failed = true;
         }
     }
 }
Пример #14
0
 public void cleanUpTest()
 {
     transaction           = null;
     transactionOperations = null;
     mockSetTransaction    = null;
 }
Пример #15
0
 protected override IEnumerable <BigMapDiff> ParseBigMapDiffs(TransactionOperation transaction, JsonElement result)
 {
     return(result.TryGetProperty("big_map_diff", out var diffs)
         ? diffs.RequiredArray().EnumerateArray().Select(BigMapDiff.Parse)
         : null);
 }
Пример #16
0
 protected override IMicheline NormalizeStorage(TransactionOperation transaction, IMicheline storage, Netezos.Contracts.ContractScript schema)
 {
     return(storage);
 }
Пример #17
0
        public TransactionType AddRule(PositionType positionType, TransactionOperation operation)
        {
            TransactionRules.Add(new TransactionRuleType(positionType, operation));

            return(this);
        }
Пример #18
0
 public TransactionRuleType(PositionType posititonType, TransactionOperation operation)
 {
     PositionTypeName     = posititonType.PropertyName;
     TransactionOperation = operation;
 }