예제 #1
0
        public void DecodeEndodedListWithOneLongElement()
        {
            byte[][] bytes = new byte[1][];

            byte[] data = new byte[256 * 256];

            for (int j = 0; j < data.Length; j++)
            {
                data[j] = (byte)(j);
            }

            bytes[0] = Rlp.Encode(data);

            byte[] list = Rlp.EncodeList(bytes);

            var result = Rlp.DecodeList(list);

            Assert.IsNotNull(result);
            Assert.AreEqual(bytes.Length, result.Count);

            for (int k = 0; k < bytes.Length; k++)
            {
                Assert.IsTrue(bytes[k].SequenceEqual(result[k]));
            }
        }
예제 #2
0
        public void DecodeEncodeEmptyList()
        {
            var result = Rlp.DecodeList(Rlp.EncodeList(new byte[0]));

            Assert.IsNotNull(result);
            Assert.AreEqual(0, result.Count);
        }
예제 #3
0
        public void EncodeListWithOnlyOneShortEntry()
        {
            var result = Rlp.EncodeList(new byte[] { 0x01 });

            Assert.IsNotNull(result);
            Assert.AreEqual(2, result.Length);
            Assert.AreEqual(192 + 1, result[0]);
            Assert.AreEqual(0x01, result[1]);
        }
예제 #4
0
        public void DecodeSimpleListWithOneElement()
        {
            var result = Rlp.DecodeList(Rlp.EncodeList(new byte[] { 0x01 }));

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count);

            var elem = result[0];

            Assert.IsNotNull(elem);
            Assert.AreEqual(1, elem.Length);
            Assert.AreEqual(0x01, elem[0]);
        }
예제 #5
0
        public void DecodeEndodedListWithTwoElements()
        {
            byte[] bytes1 = Rlp.Encode(new byte[] { 0x01 });
            byte[] bytes2 = Rlp.Encode(new byte[] { 0x02 });

            byte[] list = Rlp.EncodeList(bytes1, bytes2);

            var result = Rlp.DecodeList(list);

            Assert.IsNotNull(result);
            Assert.AreEqual(2, result.Count);

            Assert.IsTrue(bytes1.SequenceEqual(result[0]));
            Assert.IsTrue(bytes2.SequenceEqual(result[1]));
        }
예제 #6
0
        public void EncodeListWithMoreThan55Bytes()
        {
            byte[] bytes1 = new byte[30];
            bytes1[0] = 0x01;
            byte[] bytes2 = new byte[30];
            bytes2[0] = 0x02;

            var result = Rlp.EncodeList(bytes1, bytes2);

            Assert.IsNotNull(result);
            Assert.AreEqual(62, result.Length);
            Assert.AreEqual(247 + 1, result[0]);
            Assert.AreEqual(60, result[1]);
            Assert.AreEqual(0x01, result[2]);
            Assert.AreEqual(0x0, result[3]);
            Assert.AreEqual(0x02, result[32]);
            Assert.AreEqual(0x0, result[33]);
        }