public void Leaf_with_contract_without_storage_and_with_code_can_accept_visitors() { ITreeVisitor visitor = Substitute.For <ITreeVisitor>(); visitor.ShouldVisit(Arg.Any <Keccak>()).Returns(true); TrieVisitContext context = new(); Account account = new(1, 100, Keccak.EmptyTreeHash, Keccak.Zero); 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 Branch_can_accept_visitors() { ITreeVisitor visitor = Substitute.For <ITreeVisitor>(); TrieVisitContext context = new TrieVisitContext(); PatriciaTree tree = new PatriciaTree(); TrieNode node = new TrieNode(NodeType.Branch); for (int i = 0; i < 16; i++) { node.SetChild(i, null); } node.Accept(visitor, tree, context); visitor.Received().VisitBranch(node, context); }
public void Extension_with_leaf_can_be_visited() { ITreeVisitor visitor = Substitute.For <ITreeVisitor>(); visitor.ShouldVisit(Arg.Any <Keccak>()).Returns(true); TrieVisitContext context = new TrieVisitContext(); PatriciaTree tree = new PatriciaTree(); TrieNode node = new TrieNode(NodeType.Extension); node.SetChild(0, _accountLeaf); node.Accept(visitor, tree, context); visitor.Received().VisitExtension(node, context); visitor.Received().VisitLeaf(_accountLeaf, context, _accountLeaf.Value); }
public void Leaf_with_contract_with_storage_and_without_code_can_accept_visitors() { ITreeVisitor visitor = Substitute.For <ITreeVisitor>(); visitor.ShouldVisit(Arg.Any <Keccak>()).Returns(true); TrieVisitContext context = new TrieVisitContext(); PatriciaTree tree = new PatriciaTree(); Account account = new Account(1, 100, Keccak.Zero, Keccak.OfAnEmptyString); AccountDecoder decoder = new AccountDecoder(); TrieNode node = new TrieNode(NodeType.Leaf); node.Value = decoder.Encode(account).Bytes; node.Accept(visitor, tree, context); visitor.Received().VisitLeaf(node, context, node.Value); }
public void Branch_with_children_can_be_visited() { ITreeVisitor visitor = Substitute.For <ITreeVisitor>(); visitor.ShouldVisit(Arg.Any <Keccak>()).Returns(true); TrieVisitContext context = new TrieVisitContext(); PatriciaTree tree = new PatriciaTree(); TrieNode node = new TrieNode(NodeType.Branch); for (int i = 0; i < 16; i++) { node.SetChild(i, _accountLeaf); } node.Accept(visitor, tree, context); visitor.Received().VisitBranch(node, context); visitor.Received(16).VisitLeaf(_accountLeaf, context, _accountLeaf.Value); }
public void Branch_with_children_can_be_visited() { Context ctx = new Context(); ITreeVisitor visitor = Substitute.For <ITreeVisitor>(); visitor.ShouldVisit(Arg.Any <Keccak>()).Returns(true); TrieVisitContext context = new TrieVisitContext(); TrieNode node = new TrieNode(NodeType.Branch); for (int i = 0; i < 16; i++) { node.SetChild(i, ctx.AccountLeaf); } node.Accept(visitor, NullTrieNodeResolver.Instance, context); visitor.Received().VisitBranch(node, context); visitor.Received(16).VisitLeaf(ctx.AccountLeaf, context, ctx.AccountLeaf.Value); }