public List <object> RunSequence(string sequenceName)
        {
            var resultList   = new List <object>();
            var testSequence = _tests.sequences[sequenceName];
            var debugParams  = new DebugParameters();

            foreach (var testItem in testSequence.Items)
            {
                //TODO: Refactoring required
                debugParams.PrivateKey = testItem.TestPrivateKey;
                var keyPair = DebuggerUtils.GetKeyFromString(debugParams.PrivateKey);
                if (keyPair != null)
                {
                    Runtime.invokerKeys = keyPair;
                }
                debugParams.WitnessMode = CheckWitnessMode.Default;
                var testCase = _tests.cases[testItem.TestName];
                debugParams.ArgList     = testCase.args;
                debugParams.TriggerType = TriggerType.Application;
                SetDebugParameters(debugParams);
                Run();
                var result = _emulator.GetOutput();
                resultList.Add(result);
            }
            return(resultList);
        }
        public bool SetDebugParameters(DebugParameters debugParams)
        {
            //Save all the params for settings later
            _settings.lastPrivateKey = debugParams.PrivateKey;
            _settings.lastParams.Clear();
            foreach (var param in debugParams.DefaultParams)
            {
                _settings.lastParams.Add(param.Key, param.Value);
            }
            _settings.Save();

            //Set the emulator context
            _emulator.checkWitnessMode = debugParams.WitnessMode;
            _emulator.currentTrigger   = debugParams.TriggerType;
            _emulator.timestamp        = debugParams.Timestamp;
            if (debugParams.Transaction.Count > 0)
            {
                var transaction = debugParams.Transaction.First();
                _emulator.SetTransaction(transaction.Key, transaction.Value);
            }

            try
            {
                _emulator.Reset(debugParams.ArgList, this.ABI);
            }
            catch
            {
                return(false);
            }

            Reset();
            return(true);
        }
Exemple #3
0
 public int GetCooldownRemaining()
 {
     if (DebugParameters.Get() != null && DebugParameters.Get().GetParameterAsBool("NoCooldowns"))
     {
         return(0);
     }
     return(m_cooldownRemaining);
 }
Exemple #4
0
        public bool DisableAllBrush()
        {
//            if (SinglePlayerManager.Get() != null && !SinglePlayerManager.Get().EnableBrush())
//                return true;
            if (DebugParameters.Get() != null)
            {
                return(DebugParameters.Get().GetParameterAsBool("DisableBrush"));
            }
            return(false);
        }
Exemple #5
0
        public bool SetDebugParameters(DebugParameters debugParams)
        {
            //Save all the params for settings later
            Settings.lastPrivateKey = debugParams.PrivateKey;
            Settings.lastParams.Clear();
            foreach (var param in debugParams.DefaultParams)
            {
                Settings.lastParams.Add(param.Key, param.Value);
            }
            Settings.Save();

            //Set the emulator context
            _emulator.checkWitnessMode = debugParams.WitnessMode;
            _emulator.currentTrigger   = debugParams.TriggerType;
            _emulator.timestamp        = debugParams.Timestamp;
            if (debugParams.Transaction.Count > 0)
            {
                var transaction = debugParams.Transaction.First();
                _emulator.SetTransaction(transaction.Key, transaction.Value);
            }

            try
            {
                var    inputs       = debugParams.ArgList;
                byte[] loaderScript = debugParams.RawScript;


                if (loaderScript == null)
                {
                    loaderScript = _emulator.GenerateLoaderScriptFromInputs(inputs, this.ABI);
                }

                var methodName = inputs != null && inputs.ChildCount > 0 ? inputs[0].Value : null;

                _emulator.Reset(loaderScript, this.ABI, methodName);
            }
            catch (Exception e)
            {
                return(false);
            }

            Reset();
            return(true);
        }
Exemple #6
0
        public List <object> RunSequence(string sequenceName)
        {
            var resultList   = new List <object>();
            var testSequence = _tests.sequences[sequenceName];
            var debugParams  = new DebugParameters();

            foreach (var testItem in testSequence.Items)
            {
                debugParams.PrivateKey  = testItem.TestPrivateKey;
                debugParams.WitnessMode = CheckWitnessMode.Default;
                var testCase = _tests.cases[testItem.TestName];
                debugParams.ArgList     = testCase.args;
                debugParams.TriggerType = TriggerType.Application;
                SetDebugParameters(debugParams);
                Run();
                var result = _emulator.GetOutput();
                resultList.Add(result);
            }
            return(resultList);
        }
        public DeveloperLogEvent Clone()
        {
            var clone = (DeveloperLogEvent)MemberwiseClone();

            clone.GrpcErrorDetails               = GrpcErrorDetails?.Clone();
            clone.ExternalToolError              = ExternalToolError?.Clone();
            clone.CommandData                    = CommandData?.Clone();
            clone.GameletData                    = GameletData?.Clone();
            clone.GrpcCallDetails                = GrpcCallDetails?.Select(x => x.Clone()).ToList();
            clone.LoadSymbolData                 = LoadSymbolData?.Clone();
            clone.DebugPreflightCheckData        = DebugPreflightCheckData?.Clone();
            clone.DebugSessionEndData            = DebugSessionEndData?.Clone();
            clone.DebugEventBatch                = DebugEventBatch?.Clone();
            clone.DebugParameters                = DebugParameters?.Clone();
            clone.CopyExecutable                 = CopyExecutable?.Clone();
            clone.CopyLldbServer                 = CopyLldbServer?.Clone();
            clone.CustomCommand                  = CustomCommand?.Clone();
            clone.ExceptionsData                 = ExceptionsData?.Select(x => x.Clone()).ToList();
            clone.BoundBreakpointsData           = BoundBreakpointsData?.Clone();
            clone.GameLaunchData                 = GameLaunchData?.Clone();
            clone.DebugExpressionEvaluationBatch = DebugExpressionEvaluationBatch?.Clone();
            return(clone);
        }
Exemple #8
0
 /// <summary>
 /// Constructs a new Debug object in the operation mode it is set to
 /// </summary>
 /// <param name="operationMode">DebugParameters constant, determines
 /// if the messages are sent to the console, to a file, to both or to
 /// none</param>
 public Debug(DebugParameters operationMode)
 {
     this.operationMode = operationMode;
 }
        private bool InitInvoke()
        {
            var key = paramsList.Text;
            var f   = _abi.functions[key];

            _debugParameters = new DebugParameters();

            //Get the private key used
            _debugParameters.PrivateKey = privateKeyInput.Text;

            //Get the witness mode
            CheckWitnessMode witnessMode;
            var ws = witnessComboBox.SelectedItem.ToString().Replace(" ", "");

            if (!Enum.TryParse <CheckWitnessMode>(ws, out witnessMode))
            {
                return(false);
            }
            _debugParameters.WitnessMode = witnessMode;

            //Get the trigger type
            TriggerType type;
            var         ts = triggerComboBox.SelectedItem.ToString().Replace(" ", "");

            if (!Enum.TryParse <TriggerType>(ts, out type))
            {
                return(false);
            }
            _debugParameters.TriggerType = type;

            //Get the arguments list
            var argList = "";

            if (f.inputs != null)
            {
                int index = 0;
                foreach (var p in f.inputs)
                {
                    var temp = ($"{key}_{f.name}").ToLower();
                    var name = inputGrid.Rows[index].Cells[0].Value;

                    object val;

                    // detect placeholder
                    if (inputGrid.Rows[index].Cells[1].Style.ForeColor == Color.Gray)
                    {
                        val = "";
                    }
                    else
                    {
                        val = ReadCellVal(index, 1);
                    }

                    if (val == null)
                    {
                        val = ""; // temporary hack, necessary to avoid VM crash
                    }

                    if (val != null && !val.Equals(""))
                    {
                        var param_key = (currentContractName + "_" + f.name + "_" + p.name).ToLower();
                        //Add our default running parameters for next time
                        _debugParameters.DefaultParams[param_key] = val.ToString();
                    }

                    if (index > 0)
                    {
                        argList += ",";
                    }

                    if (p.type == Emulator.Type.Array || p.type == Emulator.Type.ByteArray)
                    {
                        var s = val.ToString();

                        if (s.StartsWith("[") && s.EndsWith("]"))
                        {
                            val = s;
                        }
                        else
                        if (s.StartsWith("\"") && s.EndsWith("\""))
                        {
                            s = s.Substring(1, s.Length - 2);
                            if (DebuggerUtils.IsHex(s))
                            {
                                var bytes = s.HexToBytes();
                                s = DebuggerUtils.BytesToString(bytes);
                            }
                            else if (DebuggerUtils.IsValidWallet(s))
                            {
                                var scriptHash = Emulation.Helper.AddressToScriptHash(s);
                                s = DebuggerUtils.BytesToString(scriptHash);
                            }
                            else
                            {
                                ShowArgumentError(f, index, val);
                                return(false);
                            }

                            val = $"[{s}]";
                        }
                        else
                        {
                            ShowArgumentError(f, index, val);
                            return(false);
                        }
                    }
                    else
                    {
                        switch (p.type)
                        {
                        case Emulator.Type.String:
                        {
                            var s = val.ToString();
                            if (!s.StartsWith("\"") || !s.EndsWith("\""))
                            {
                                ShowArgumentError(f, index, val);
                                return(false);
                            }

                            break;
                        }

                        case Emulator.Type.Integer:
                        {
                            BigInteger n;
                            var        s = val.ToString();
                            if (string.IsNullOrEmpty(s) || !BigInteger.TryParse(s, out n))
                            {
                                ShowArgumentError(f, index, val);
                                ResetTabs();
                                return(false);
                            }
                            break;
                        }

                        case Emulator.Type.Boolean:
                        {
                            switch (val.ToString().ToLower())
                            {
                            case "true": val = true; break;

                            case "false": val = false; break;

                            default:
                            {
                                ShowArgumentError(f, index, val);
                                ResetTabs();
                                return(false);
                            }
                            }
                            break;
                        }
                        }
                    }

                    argList += val;
                    index++;
                }
            }
            if (key != _abi.entryPoint.name)
            {
                if (f.inputs == null || f.inputs.Count == 0)
                {
                    argList = "[null]";
                }
                var operation = Char.ToLowerInvariant(key[0]) + key.Substring(1);
                argList = $"\"{operation}\", {argList}";
            }

            //Set the arguments list
            try
            {
                _debugParameters.ArgList = DebuggerUtils.GetArgsListAsNode(argList);
            }
            catch
            {
                MessageBox.Show("Error parsing input!");
                ResetTabs();
                return(false);
            }

            if (assetComboBox.SelectedIndex > 0)
            {
                foreach (var entry in Asset.Entries)
                {
                    if (entry.name == assetComboBox.SelectedItem.ToString())
                    {
                        BigInteger amount;
                        BigInteger.TryParse(assetAmount.Text, out amount);
                        if (amount > 0)
                        {
                            amount *= Asset.Decimals; // fix decimals

                            //Add the transaction info
                            _debugParameters.Transaction.Add(entry.id, amount);
                        }
                        else
                        {
                            MessageBox.Show(entry.name + " amount must be greater than zero");
                            return(false);
                        }

                        break;
                    }
                }
            }

            uint timestamp;

            if (!uint.TryParse(timestampBox.Text, out timestamp))
            {
                MessageBox.Show("Invalid timestamp");
                return(false);
            }
            else
            {
                _debugParameters.Timestamp = timestamp;
            }

            return(true);
        }
        public void MergeFrom(DeveloperLogEvent other)
        {
            if (other == null)
            {
                return;
            }

            if (other.ApiEndpoint.HasValue)
            {
                ApiEndpoint = other.ApiEndpoint;
            }

            if (other.BinaryType.HasValue)
            {
                BinaryType = other.BinaryType;
            }

            if (other.OrganizationId != null)
            {
                OrganizationId = other.OrganizationId;
            }

            if (other.ProjectId != null)
            {
                ProjectId = other.ProjectId;
            }

            if (other.VisualStudioVersion != null)
            {
                VisualStudioVersion = other.VisualStudioVersion;
            }

            if (other.SdkVersion != null)
            {
                SdkVersion = other.SdkVersion;
            }

            if (other.VsExtensionVersion != null)
            {
                VsExtensionVersion = other.VsExtensionVersion;
            }

            if (other.VsSessionIdStr != null)
            {
                VsSessionIdStr = other.VsSessionIdStr;
            }

            if (other.DebugSessionIdStr != null)
            {
                DebugSessionIdStr = other.DebugSessionIdStr;
            }

            if (other.StatusCode.HasValue)
            {
                StatusCode = other.StatusCode;
            }

            if (other.GrpcErrorDetails != null)
            {
                if (GrpcErrorDetails == null)
                {
                    GrpcErrorDetails = new GrpcServiceCallDetails();
                }

                GrpcErrorDetails.MergeFrom(other.GrpcErrorDetails);
            }

            if (other.ExternalToolError != null)
            {
                if (ExternalToolError == null)
                {
                    ExternalToolError = new Types.ExternalToolError();
                }

                ExternalToolError.MergeFrom(other.ExternalToolError);
            }

            if (other.LatencyMilliseconds.HasValue)
            {
                LatencyMilliseconds = other.LatencyMilliseconds;
            }

            if (other.LatencyType.HasValue)
            {
                LatencyType = other.LatencyType;
            }

            if (other.CommandData != null)
            {
                if (CommandData == null)
                {
                    CommandData = new Types.CommandData();
                }

                CommandData.MergeFrom(other.CommandData);
            }

            if (other.GameletData != null)
            {
                if (GameletData == null)
                {
                    GameletData = new Types.GameletData();
                }

                GameletData.MergeFrom(other.GameletData);
            }

            if (other.GrpcCallDetails != null)
            {
                if (GrpcCallDetails == null)
                {
                    GrpcCallDetails = new List <GrpcServiceCallDetails>();
                }

                GrpcCallDetails.AddRange(other.GrpcCallDetails);
            }

            if (other.LoadSymbolData != null)
            {
                if (LoadSymbolData == null)
                {
                    LoadSymbolData = new Types.LoadSymbolData();
                }

                LoadSymbolData.MergeFrom(other.LoadSymbolData);
            }

            if (other.DebugPreflightCheckData != null)
            {
                if (DebugPreflightCheckData == null)
                {
                    DebugPreflightCheckData = new DebugPreflightCheckData();
                }

                DebugPreflightCheckData.MergeFrom(other.DebugPreflightCheckData);
            }

            if (other.DebugSessionEndData != null)
            {
                if (DebugSessionEndData == null)
                {
                    DebugSessionEndData = new DebugSessionEndData();
                }

                DebugSessionEndData.MergeFrom(other.DebugSessionEndData);
            }

            if (other.DebugEventBatch != null)
            {
                if (DebugEventBatch == null)
                {
                    DebugEventBatch = new VSIDebugEventBatch();
                }

                DebugEventBatch.MergeFrom(other.DebugEventBatch);
            }

            if (other.DebugParameters != null)
            {
                if (DebugParameters == null)
                {
                    DebugParameters = new VSIDebugParameters();
                }

                DebugParameters.MergeFrom(other.DebugParameters);
            }

            if (other.CopyExecutable != null)
            {
                if (CopyExecutable == null)
                {
                    CopyExecutable = new CopyBinaryData();
                }

                CopyExecutable.MergeFrom(other.CopyExecutable);
            }

            if (other.CopyLldbServer != null)
            {
                if (CopyLldbServer == null)
                {
                    CopyLldbServer = new CopyBinaryData();
                }

                CopyLldbServer.MergeFrom(other.CopyLldbServer);
            }

            if (other.CustomCommand != null)
            {
                if (CustomCommand == null)
                {
                    CustomCommand = new CustomCommandData();
                }

                CustomCommand.MergeFrom(other.CustomCommand);
            }

            if (other.ExceptionsData != null)
            {
                if (ExceptionsData == null)
                {
                    ExceptionsData = new List <VSIExceptionData>();
                }

                ExceptionsData.AddRange(other.ExceptionsData);
            }

            if (other.BoundBreakpointsData != null)
            {
                if (BoundBreakpointsData == null)
                {
                    BoundBreakpointsData = new VSIBoundBreakpointsData();
                }

                BoundBreakpointsData.MergeFrom(other.BoundBreakpointsData);
            }

            if (other.GameLaunchData != null)
            {
                if (GameLaunchData == null)
                {
                    GameLaunchData = new GameLaunchData();
                }

                GameLaunchData.MergeFrom(other.GameLaunchData);
            }

            if (other.DebugExpressionEvaluationBatch != null)
            {
                if (DebugExpressionEvaluationBatch == null)
                {
                    DebugExpressionEvaluationBatch = new VSIDebugExpressionEvaluationBatch();
                }

                DebugExpressionEvaluationBatch.MergeFrom(other.DebugExpressionEvaluationBatch);
            }
        }