public void TestSymbol() { var inputs = DataNode.CreateArray(); inputs.AddValue("symbol"); inputs.AddValue(null); emulator.Reset(inputs); emulator.Run(); var result = emulator.GetOutput(); Assert.NotNull(result); var symbol = result.GetString(); Assert.IsTrue(symbol.Equals("DEMO")); }
public void PutSomething() { var inputs = MakeParameters("xx"); emulator.Reset(inputs); emulator.Run(); // obtain the smart contract output var result = emulator.GetOutput(); // validate output var symbol = result.GetString(); Debug.WriteLine(symbol); }
private bool InitInvoke() { var key = paramsList.Text; var f = abi.functions[key]; var argList = "\"" + key + "\""; if (f.inputs != null) { argList += ", ["; int index = 0; foreach (var p in f.inputs) { var temp = (key + "_" + f.name).ToLower(); var val = inputGrid.Rows[index].Cells[1].Value; if (index > 0) { argList += ","; } switch (p.type.ToLower()) { case "string": val = "\"" + val + "\""; break; } argList += val; index++; } argList += "]"; } else { argList += ", [null]"; } string json = "{\"params\": [" + argList + "]}"; if (string.IsNullOrEmpty(json)) { MessageBox.Show("Invalid input!"); return(false); } DataNode node; try { node = JSONReader.ReadFromString(json); } catch { MessageBox.Show("Error parsing input!"); return(false); } var items = node.GetNode("params"); if (assetListBox.SelectedIndex > 0) { foreach (var entry in Asset.Entries) { if (entry.name == assetListBox.SelectedItem.ToString()) { BigInteger ammount; BigInteger.TryParse(assetAmmount.Text, out ammount); if (ammount > 0) { emulator.SetTransaction(entry.id, ammount); } else { MessageBox.Show(entry.name + " ammount must be greater than zero"); return(false); } break; } } } emulator.Reset(items); return(true); }
private bool InitInvoke() { var key = paramsList.Text; var f = abi.functions[key]; var ws = witnessComboBox.SelectedItem.ToString().Replace(" ", ""); if (!Enum.TryParse <CheckWitnessMode>(ws, out emulator.checkWitnessMode)) { return(false); } var ts = triggerComboBox.SelectedItem.ToString().Replace(" ", ""); if (!Enum.TryParse <TriggerType>(ts, out emulator.currentTrigger)) { return(false); } 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(); mainForm.settings.lastParams[param_key] = val.ToString(); } if (index > 0) { argList += ","; } if (p.type.Contains("Array")) { var s = val.ToString(); if (s.StartsWith("[") && s.EndsWith("]")) { val = s; } else if (IsHex(s)) { var bytes = s.HexToBytes(); s = BytesToString(bytes); } else if (IsValidWallet(s)) { var bytes = s.Base58CheckDecode(); var scriptHash = Crypto.Default.ToScriptHash(bytes); bytes = scriptHash.ToArray(); s = BytesToString(bytes); } else { ShowArgumentError(f, index, val); return(false); } } else { switch (p.type.ToLower()) { case "string": { var s = val.ToString(); if (!s.StartsWith("\"") || !s.EndsWith("\"")) { ShowArgumentError(f, index, val); return(false); } break; } case "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 "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.Length == 0) { argList = "[null]"; } var operation = Char.ToLowerInvariant(key[0]) + key.Substring(1); argList = $"\"{operation}\", {argList}"; } string json = "{\"params\": [" + argList + "]}"; if (string.IsNullOrEmpty(json)) { MessageBox.Show("Invalid input!"); return(false); } DataNode node; try { node = JSONReader.ReadFromString(json); } catch { MessageBox.Show("Error parsing input!"); ResetTabs(); return(false); } var items = node.GetNode("params"); if (assetComboBox.SelectedIndex > 0) { foreach (var entry in Asset.Entries) { if (entry.name == assetComboBox.SelectedItem.ToString()) { BigInteger ammount; BigInteger.TryParse(assetAmount.Text, out ammount); if (ammount > 0) { emulator.SetTransaction(entry.id, ammount); } else { MessageBox.Show(entry.name + " amount must be greater than zero"); return(false); } break; } } } emulator.Reset(items); mainForm.settings.Save(); return(true); }