public void Extension_can_accept_visitors() { ITreeVisitor visitor = Substitute.For <ITreeVisitor>(); TrieVisitContext context = new(); TrieNode ignore = TrieNodeFactory.CreateLeaf(HexPrefix.Leaf("ccc"), Array.Empty <byte>()); TrieNode node = TrieNodeFactory.CreateExtension(HexPrefix.Extension("aa"), ignore); node.Accept(visitor, NullTrieNodeResolver.Instance, context); visitor.Received().VisitExtension(node, context); }
public void Leaf_with_contract_without_storage_and_empty_code_can_accept_visitors() { ITreeVisitor visitor = Substitute.For <ITreeVisitor>(); TrieVisitContext context = new(); Account account = new(1, 100, Keccak.EmptyTreeHash, Keccak.OfAnEmptyString); AccountDecoder decoder = new(); TrieNode node = TrieNodeFactory.CreateLeaf(HexPrefix.Leaf("aa"), decoder.Encode(account).Bytes); node.Accept(visitor, NullTrieNodeResolver.Instance, context); visitor.Received().VisitLeaf(node, context, node.Value); }
public void Leaf_with_simple_account_can_accept_visitors() { ITreeVisitor visitor = Substitute.For <ITreeVisitor>(); TrieVisitContext context = new(); Account account = new(100); AccountDecoder decoder = new(); TrieNode node = TrieNodeFactory.CreateLeaf(HexPrefix.Leaf("aa"), decoder.Encode(account).Bytes); node.Accept(visitor, NullTrieNodeResolver.Instance, context); visitor.Received().VisitLeaf(node, context, node.Value); }
public Context() { TiniestLeaf = new TrieNode(NodeType.Leaf); TiniestLeaf.Key = new HexPrefix(true, 5); TiniestLeaf.Value = new byte[] { 10 }; HeavyLeaf = new TrieNode(NodeType.Leaf); HeavyLeaf.Key = new HexPrefix(true, new byte[20]); HeavyLeaf.Value = Keccak.EmptyTreeHash.Bytes.Concat(Keccak.EmptyTreeHash.Bytes).ToArray(); Account account = new(100); AccountDecoder decoder = new(); AccountLeaf = TrieNodeFactory.CreateLeaf( HexPrefix.Leaf("bbb"), decoder.Encode(account).Bytes); }
public void Small_child_unresolve() { TrieNode child = new(NodeType.Leaf); child.Value = Bytes.FromHexString("a"); child.Key = HexPrefix.Leaf("b"); child.ResolveKey(NullTrieStore.Instance, false); child.IsPersisted = true; TrieNode trieNode = new(NodeType.Extension); trieNode.SetChild(0, child); trieNode.Key = HexPrefix.Extension("abcd"); trieNode.ResolveKey(NullTrieStore.Instance, false); trieNode.PrunePersistedRecursively(2); trieNode.GetChild(NullTrieStore.Instance, 0).Should().Be(child); }
public void Batch_not_db_regression() { TrieNode child = new(NodeType.Leaf); child.Key = HexPrefix.Leaf("abc"); child.Value = new byte[200]; child.Seal(); TrieNode trieNode = new(NodeType.Extension); trieNode.SetChild(0, child); trieNode.Seal(); ITrieNodeResolver trieStore = Substitute.For <ITrieNodeResolver>(); trieStore.LoadRlp(Arg.Any <Keccak>()).Throws(new TrieException()); child.ResolveKey(trieStore, false); child.IsPersisted = true; trieStore.FindCachedOrUnknown(Arg.Any <Keccak>()).Returns(new TrieNode(NodeType.Unknown, child.Keccak !)); trieNode.GetChild(trieStore, 0); Assert.Throws <TrieException>(() => trieNode.GetChild(trieStore, 0).ResolveNode(trieStore)); }