private bool ResetDebugger() { if (string.IsNullOrEmpty(targetAVMPath)) { MessageBox.Show("Please load an .avm file first!"); return(false); } if (this.debugger == null) { this.debugger = new NeoEmulator(blockchain); var address = blockchain.FindAddressByName(this.contractName); if (address == null) { address = blockchain.DeployContract(this.contractName, this.contractBytecode); SendLogToPanel($"Deployed contract {contractName} on virtual blockchain."); } else { if (!address.byteCode.SequenceEqual(this.contractBytecode)) { address.byteCode = this.contractBytecode; SendLogToPanel($"Updated contract {contractName} bytecode."); } } this.debugger.SetExecutingAddress(address); } runForm.emulator = this.debugger; runForm.abi = abi; var result = runForm.ShowDialog(); if (result != DialogResult.OK) { return(false); } RemoveCurrentHighlight(); /*currentLine = ResolveLine(0); * if (currentLine > 0 ) * { * TextArea.Lines[currentLine].MarkerAdd(STEP_BG); * }*/ currentLine = -1; shouldReset = false; logView.Clear(); stackPanel.Clear(); UpdateGasCost(); return(true); }
public void Setup() { //var path = TestContext.CurrentContext.TestDirectory.Replace("ICO-Unit-Tests", "ICO-Template"); string avmPath = @"C:\OguzhanE\projects\NepLend\NepLend\bin\Debug\NepLend.avm"; var avmBytes = File.ReadAllBytes(avmPath); emulator = new NeoEmulator(avmBytes); }
public SmartContractEmulator(byte[] bytecodes) { Blockchain = new Blockchain(); Emulator = new NeoEmulator(Blockchain) { checkWitnessMode = CheckWitnessMode.AlwaysTrue }; ContractAddress = Blockchain.DeployContract(string.Empty, bytecodes); Emulator.SetExecutingAddress(ContractAddress); }
public Shell() { this.blockchain = new Blockchain(); this.debugger = new NeoEmulator(blockchain); AddCommand(new HelpCommand()); AddCommand(new ExitCommand()); AddCommand(new LoadCommand()); AddCommand(new DeployCommand()); AddCommand(new CallCommand()); AddCommand(new StorageCommand()); }
public TestEnviroment(int buyers_count) { debugger = new DebugClient(); // this is the key for the NEO "issuer" in the virtual chain used for testing owner_keys = KeyPair.GenerateAddress(); this.api = new NeoEmulator(owner_keys); this.api.SetLogger(x => { if (api.Chain.HasDebugger) { debugger.WriteLine(x); } Debug.WriteLine(x); }); // create a random key for the team team_keys = KeyPair.GenerateAddress(); // since the real team address is hardcoded in the contract, use BypassKey to give same permissions to this key this.api.Chain.BypassKey(new UInt160(PhantasmaContract.Team_Address), new UInt160(team_keys.address.AddressToScriptHash())); api.Chain.AttachDebugger(debugger); Transaction tx; tx = api.SendAsset(owner_keys, team_keys.address, "GAS", 800); Assert.IsNotNull(tx); var balances = api.GetAssetBalancesOf(team_keys.address); Assert.IsTrue(balances.ContainsKey("GAS")); Assert.IsTrue(balances["GAS"] == 800); tx = api.DeployContract(team_keys, ContractTests.contract_script_bytes, "0710".HexToBytes(), 5, ContractPropertyState.HasStorage, "Phantasma", "1.0", "phantasma.io", "*****@*****.**", "Phantasma Smart Contract"); Assert.IsNotNull(tx); if (buyers_count > 0) { whitelisted_buyerKeys = new KeyPair[buyers_count]; for (int i = 0; i < whitelisted_buyerKeys.Length; i++) { whitelisted_buyerKeys[i] = KeyPair.GenerateAddress(); api.SendAsset(owner_keys, whitelisted_buyerKeys[i].address, "NEO", 100); api.CallContract(team_keys, ContractTests.contract_script_hash, "whitelistAdd", new object[] { whitelisted_buyerKeys[i].address.AddressToScriptHash() }); } } this.token = new NEP5(api, ContractTests.contract_script_hash); }
public void Setup() { var path = TestContext.CurrentContext.TestDirectory.Replace("ICO-Unit-Tests", "ICO-Template"); Directory.SetCurrentDirectory(path); var avmBytes = File.ReadAllBytes("ICOContract.avm"); var chain = new Blockchain(); emulator = new NeoEmulator(chain); var address = chain.DeployContract("test", avmBytes); emulator.SetExecutingAddress(address); }
public bool LoadEmulator() { //Create load the emulator Blockchain blockchain = new Blockchain(); blockchain.Load(_blockchainFilePath); _emulator = new NeoEmulator(blockchain); if (_debugContent.Keys.Contains(DebugMode.Source) && !String.IsNullOrEmpty(_debugContent[DebugMode.Source])) { _emulator.SetProfilerFilenameSource(_srcFileName, _debugContent[DebugMode.Source]); } return(true); }
public StorageForm(NeoEmulator debugger) { InitializeComponent(); _debugger = debugger; dataGridView1.Columns.Add("Key", "Key"); dataGridView1.Columns.Add("Values", "Content"); dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; dataGridView1.RowHeadersVisible = false; dataGridView1.Columns[0].ReadOnly = true; dataGridView1.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridView1.Columns[0].FillWeight = 3; dataGridView1.Columns[1].ReadOnly = true; dataGridView1.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridView1.Columns[1].FillWeight = 4; }
public void LoadDataFromFile(string path) { if (string.IsNullOrEmpty(path)) { return; } if (!File.Exists(path)) { MessageBox.Show("Can't find '" + (String.IsNullOrEmpty(path) ? "(null)" : path + "'"), this.Text + " - " + Environment.CurrentDirectory); } else { MainForm.targetAVMPath = path; this.contractName = Path.GetFileNameWithoutExtension(path); this.contractBytecode = File.ReadAllBytes(path); var oldMapFileName = path.Replace(".avm", ".neomap"); var newMapFileName = path.Replace(".avm", ".debug.json"); debugMode = DebugMode.Assembly; sourceLanguage = SourceLanguageKind.Other; if (File.Exists(newMapFileName)) { map = new NeoMapFile(); map.LoadFromFile(newMapFileName, contractBytecode); this.contractName = map.contractName; } else { if (File.Exists(oldMapFileName)) { MessageBox.Show("Warning: The file format of debug map changed. Please recompile your AVM with the latest compiler."); } map = null; } string abiFilename = path.Replace(".avm", ".abi.json"); if (File.Exists(abiFilename)) { abi = new ABI(abiFilename); } else { MessageBox.Show($"Error: {abiFilename} was not found. Please recompile your AVM with the latest compiler."); return; } this.debugger = null; this.avm_asm = NeoDisassembler.Disassemble(contractBytecode); if (map != null && map.Entries.Any()) { var srcFile = map.Entries.FirstOrDefault().url; if (string.IsNullOrEmpty(srcFile)) { MessageBox.Show("Error: Could not load the debug map correct, no file entries."); return; } if (!File.Exists(srcFile)) { MessageBox.Show("Error: Could not load the source code, check that this file exists:" + srcFile); return; } FileName.Text = srcFile; sourceLanguage = LanguageSupport.DetectLanguage(srcFile); debugMode = DebugMode.Source; debugContent[DebugMode.Source] = File.ReadAllText(srcFile); } debugContent[DebugMode.Assembly] = avm_asm.ToString(); FileName.Text = Path.GetFileName(path); ReloadTextArea(); BlockchainLoad(); UpdateSourceViewMenus(); shouldReset = true; settings.lastOpenedFile = path; settings.Save(); } }