Ejemplo n.º 1
0
        internal string Dump()
        {
            return(TreeDumper.DumpCompact(DumpAncestors()));

            TreeDumperNode DumpAncestors()
            {
                TreeDumperNode current = null;

                for (Binder scope = this; scope != null; scope = scope.Next)
                {
                    var(description, snippet, locals) = Print(scope);
                    var sub = new List <TreeDumperNode>();
                    if (!locals.IsEmpty())
                    {
                        sub.Add(new TreeDumperNode("locals", locals, null));
                    }
                    var currentContainer = scope.ContainingMemberOrLambda;
                    if (currentContainer != null && currentContainer != scope.Next?.ContainingMemberOrLambda)
                    {
                        sub.Add(new TreeDumperNode("containing symbol", currentContainer.ToDisplayString(), null));
                    }
                    if (snippet != null)
                    {
                        sub.Add(new TreeDumperNode($"scope", $"{snippet} ({scope.ScopeDesignator.Kind()})", null));
                    }
                    if (current != null)
                    {
                        sub.Add(current);
                    }
                    current = new TreeDumperNode(description, null, sub);
                }

                return(current);
            }

            (string description, string snippet, string locals) Print(Binder scope)
            {
                var    locals  = string.Join(", ", scope.Locals.SelectAsArray(s => s.Name));
                string snippet = null;

                if (scope.ScopeDesignator != null)
                {
                    var lines = scope.ScopeDesignator.ToString().Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                    if (lines.Length == 1)
                    {
                        snippet = lines[0];
                    }
                    else
                    {
                        var first    = lines[0];
                        var last     = lines[lines.Length - 1].Trim();
                        var lastSize = Math.Min(last.Length, 12);
                        snippet = first.Substring(0, Math.Min(first.Length, 12)) + " ... " + last.Substring(last.Length - lastSize, lastSize);
                    }
                    snippet = snippet.IsEmpty() ? null : snippet;
                }

                var description = scope.GetType().Name;

                return(description, snippet, locals);
            }
        }
        public void _Test_storage_failed_case(string historicallyFailingCase)
        {
            string[] lines        = historicallyFailingCase.Split(Environment.NewLine);
            int      storageCount = lines.Length - 2;

            IDb       memDb     = new MemDb();
            TrieStore trieStore = new TrieStore(memDb, LimboLogs.Instance);
            StateTree tree      = new StateTree(trieStore, LimboLogs.Instance);

            Address address      = new Address(Bytes.FromHexString(lines[0]));
            int     accountIndex = int.Parse(lines[1]);

            UInt256[] indexes = new UInt256[storageCount];
            for (int j = 0; j < storageCount; j++)
            {
                indexes[j] = UInt256.Parse(lines[j + 2].Replace("storage: ", string.Empty));
            }

            AddressWithStorage addressWithStorage = new AddressWithStorage();

            addressWithStorage.StorageCells = new StorageCell[storageCount];
            addressWithStorage.Address      = address;

            StorageTree storageTree = new StorageTree(trieStore, Keccak.EmptyTreeHash, LimboLogs.Instance);

            for (int j = 0; j < storageCount; j++)
            {
                UInt256     index       = UInt256.Parse(lines[j + 2].Replace("storage: ", string.Empty));
                StorageCell storageCell = new StorageCell(address, index);
                addressWithStorage.StorageCells[j] = storageCell;
                byte[] rawKey = new byte[32];
                addressWithStorage.StorageCells[j].Index.ToBigEndian(rawKey);
                TestContext.WriteLine($"Set {Keccak.Compute(rawKey).Bytes.ToHexString()}");
                storageTree.Set(addressWithStorage.StorageCells[j].Index, new byte[] { 1 });
                storageTree.UpdateRootHash();
                storageTree.Commit(0);
            }

            Account account = Build.An.Account.WithBalance((UInt256)accountIndex).WithStorageRoot(storageTree.RootHash).TestObject;

            tree.Set(addressWithStorage.Address, account);

            tree.UpdateRootHash();
            tree.Commit(0);

            TreeDumper treeDumper = new TreeDumper();

            tree.Accept(treeDumper, tree.RootHash, true);
            TestContext.WriteLine(treeDumper.ToString());

            AccountProofCollector collector = new AccountProofCollector(address, indexes);

            tree.Accept(collector, tree.RootHash, true);

            AccountProof accountProof = collector.BuildResult();

            accountProof.Address.Should().Be(address);
            accountProof.Balance.Should().Be((UInt256)accountIndex);
            accountProof.Nonce.Should().Be(0);
            accountProof.CodeHash.Should().Be(Keccak.OfAnEmptyString);
            if (accountIndex != 0)
            {
                accountProof.StorageRoot.Should().NotBe(Keccak.EmptyTreeHash);
            }
            accountProof.StorageProofs.Length.Should().Be(accountIndex);

            for (int j = 0; j < accountProof.StorageProofs.Length; j++)
            {
                TrieNode node = new TrieNode(NodeType.Unknown, accountProof.StorageProofs[j].Proof.Last());
                node.ResolveNode(new TrieStore(memDb, NullLogManager.Instance));
                if (node.Value.Length != 1)
                {
                    TestContext.WriteLine($"{j}");
                    // throw new InvalidDataException($"{j}");
                }
            }
        }
Ejemplo n.º 3
0
 internal virtual string Dump()
 {
     return(TreeDumper.DumpCompact(BoundTreeDumperNodeProducer.MakeTree(this)));
 }
Ejemplo n.º 4
0
 public override string GetText(string id)
 {
     return(TreeDumper.ExportToTocXml(Tree.RootNode, "Compiler Error Reference", "In this section:"));
 }
Ejemplo n.º 5
0
 internal string Dump() => TreeDumper.DumpCompact(DumpCore());
Ejemplo n.º 6
0
 public override string GetText(string url)
 {
     return(TreeDumper.ExportToTocXml(Tree.RootNode, "Mono Documentation Library", "Available man pages:"));
 }
Ejemplo n.º 7
0
 public override string GetText(string url)
 {
     return(TreeDumper.ExportToTocXml(Tree.RootNode, "Mono Handbook", string.Empty));
 }