Exemplo n.º 1
0
        public void DecodeValidExtensionNode()
        {
            var list = new List(new IValue[]
            {
                (Binary)ByteUtil.ParseHex("beef").ToArray(),
                (Binary)default(HashDigest <SHA256>).ToByteArray(),
            });

            INode node = NodeDecoder.Decode(list);

            Assert.IsType <ShortNode>(node);
            var shortNode = (ShortNode)node;

            Assert.IsType <HashNode>(shortNode.Value);
            Assert.Equal(new HashNode(default), shortNode.Value);
Exemplo n.º 2
0
        public void DecodeValidValueNode()
        {
            var list = new List(new IValue[]
            {
                (Binary)ByteUtil.ParseHex("beef").ToArray(),
                new List(new IValue[] { default(Null), (Text)"beef", }),
            });

            INode node = NodeDecoder.Decode(list);

            Assert.IsType <ShortNode>(node);
            var shortNode = (ShortNode)node;

            Assert.IsType <ValueNode>(shortNode.Value);
            Assert.Equal(ByteUtil.ParseHex("beef"), shortNode.Key);
            Assert.Equal(new ValueNode((Text)"beef"), shortNode.Value);
        }
Exemplo n.º 3
0
        public void DecodeValidFullNode()
        {
            var hashA = HashDigest <SHA256> .DeriveFrom(TestUtils.GetRandomBytes(128));

            var hashB = HashDigest <SHA256> .DeriveFrom(TestUtils.GetRandomBytes(128));

            var list = new List(new IValue[]
            {
                (Binary)hashA.ToByteArray(),
                Null.Value,
                Null.Value,
                Null.Value,
                Null.Value,
                Null.Value,
                Null.Value,
                Null.Value,
                Null.Value,
                Null.Value,
                Null.Value,
                Null.Value,
                Null.Value,
                Null.Value,
                Null.Value,
                Null.Value,
                (Binary)hashB.ToByteArray(),
            });

            Assert.Equal(17, list.Count);

            INode node = NodeDecoder.Decode(list);

            Assert.IsType <FullNode>(node);
            var fullNode = (FullNode)node;

            Assert.Equal(new HashNode(hashB), fullNode.Value);
            Assert.Equal(new HashNode(hashA), fullNode.Children[0]);
            for (int i = 1; i < 16; ++i)
            {
                Assert.Null(fullNode.Children[i]);
            }
        }
Exemplo n.º 4
0
 private INode?GetNode(HashDigest <SHA256> nodeHash)
 {
     return(NodeDecoder.Decode(
                _codec.Decode(KeyValueStore.Get(nodeHash.ToByteArray()))));
 }
Exemplo n.º 5
0
        public void DecodeInvalidFullNodeThrowsException(int listCount)
        {
            var list = new List(Enumerable.Repeat((IValue)default(Null), listCount));

            Assert.Throws <InvalidTrieNodeException>(() => NodeDecoder.Decode(list));
        }