Esempio n. 1
0
        public void Encode_WhenInputIsSingleByteAndLessThanOrEqualTo127()
        {
            var result = RLP.Encode(new byte[] { 127 });

            Assert.IsTrue(result.Length == 1);
            Assert.IsTrue(result[0] == 127);
        }
        public void Encode_WhenSingleByteIsLessThanOrEqualTo127ReturnByte()
        {
            var result = RLP.Encode(127);

            Assert.IsTrue(result.GetType() == typeof(byte[]));
            Assert.IsTrue(result.Length == 1);
            Assert.IsTrue(result[0] == 127);
        }
        public void Decode_WhenEncodedDataIsGreaterThan55BytesReturnCorrectValue()
        {
            var bytes = RLP.Encode("This is a sentence. A sentence that is longer than 55 bytes.");

            var result = RLP.Decode(bytes);

            Assert.IsTrue(result.Count == 1);
            Assert.IsTrue(result[0] == "This is a sentence. A sentence that is longer than 55 bytes.");
        }
        public void Decode_WhenEncodedDataIs0To55BytesReturnCorrectValue()
        {
            var bytes = RLP.Encode("cheese on toast");

            var result = RLP.Decode(bytes);

            Assert.IsTrue(result.Count == 1);
            Assert.IsTrue(result[0] == "cheese on toast");
        }
        public void Decode_WhenDataIsSingleByteAndLessThanOrEqualTo127ReturnValue()
        {
            var bytes = RLP.Encode(10);

            var result = RLP.Decode(bytes);

            Assert.IsTrue(result.Count == 1);
            Assert.IsTrue(result[0] == "10");
        }
Esempio n. 6
0
        public void Decode_WhenEncodedLengthIs56To255Bytes()
        {
            var input = RLP.Encode("This is a sentence. A sentence that is longer than 55 bytes.".ToBytes());

            var result = RLP.Decode(input);

            Assert.IsTrue(result.Count == 1);
            Assert.IsTrue(result[0].IsCollection == false);
            Assert.AreEqual("This is a sentence. A sentence that is longer than 55 bytes.", System.Text.Encoding.ASCII.GetString(result[0].String));
        }
Esempio n. 7
0
        public void Decode_WhenEncodedIsSingleByteAndLessThanOrEqualTo127()
        {
            var item = RLP.Encode(127.ToBytes());

            var result = RLP.Decode(item);

            Assert.IsTrue(result.Count == 1);
            Assert.IsTrue(result[0].IsCollection == false);
            Assert.IsTrue(result[0].String[0] == 127);
        }
Esempio n. 8
0
        public void Decode_WhenEncodedLengthIs0To55Bytes()
        {
            var input = RLP.Encode("cheese on toast".ToBytes());

            var result = RLP.Decode(input);

            Assert.IsTrue(result.Count == 1);
            Assert.IsTrue(result[0].IsCollection == false);
            Assert.AreEqual("cheese on toast", System.Text.Encoding.ASCII.GetString(result[0].String));
        }
        public void Encode_WhenEncodedStringIsGreaterThan55BytesReturnCorrectBytes()
        {
            var result = RLP.Encode("This is a sentence. A sentence that is longer than 55 bytes.");

            Assert.IsTrue(result.GetType() == typeof(byte[]));
            Assert.IsTrue(result.Length == 62);
            Assert.IsTrue(result[0] == 184);
            Assert.IsTrue(result[1] == 60);
            Assert.IsTrue(result[2] == 84);
            Assert.IsTrue(result[61] == 46);
        }
Esempio n. 10
0
        public void Encode_WhenEncodedStringIs0To55BytesReturnCorrectBytes()
        {
            var result = RLP.Encode("dog");

            Assert.IsTrue(result.GetType() == typeof(byte[]));
            Assert.IsTrue(result.Length == 4);
            Assert.IsTrue(result[0] == 131);
            Assert.IsTrue(result[1] == 100);
            Assert.IsTrue(result[2] == 111);
            Assert.IsTrue(result[3] == 103);
        }
Esempio n. 11
0
        public void Encode_WhenEncodedCollectionIs0To55BytesReturnCorrectBytes()
        {
            var result = RLP.Encode(new List <string> {
                "cat", "dog"
            });

            Assert.IsTrue(result.GetType() == typeof(byte[]));
            Assert.IsTrue(result.Length == 9);
            Assert.IsTrue(result[0] == 200);
            Assert.IsTrue(result[1] == 131);
            Assert.IsTrue(result[5] == 131);
        }
Esempio n. 12
0
        public void Decode_WhenEncodedCollectionIs0To55BytesReturnCorrectValues()
        {
            var bytes = RLP.Encode(new List <string> {
                "cat", "dog"
            });

            var result = RLP.Decode(bytes);

            Assert.IsTrue(result.Count == 2);
            Assert.IsTrue(result[0] == "cat");
            Assert.IsTrue(result[1] == "dog");
        }
Esempio n. 13
0
        public void Encode_WhenInputLengthIs0To55Bytes()
        {
            var input = "dog".ToBytes();

            var result = RLP.Encode(input);

            Assert.IsTrue(result.Length == 4);
            Assert.IsTrue(result[0] == 131);
            Assert.IsTrue(result[1] == 100);
            Assert.IsTrue(result[2] == 111);
            Assert.IsTrue(result[3] == 103);
        }
Esempio n. 14
0
        public void Encode_WhenInputLengthIs56To255Bytes()
        {
            var input = "This is a sentence. A sentence that is longer than 55 bytes.".ToBytes();

            var result = RLP.Encode(input);

            Assert.IsTrue(result.Length == 62);
            Assert.IsTrue(result[0] == 184);
            Assert.IsTrue(result[1] == 60);
            Assert.IsTrue(result[2] == 84);
            Assert.IsTrue(result[61] == 46);
        }
Esempio n. 15
0
        public void Decode_WhenEncodedCollectionIs0To55Bytes()
        {
            var input = RLP.Encode(new List <byte[]> {
                "cat".ToBytes(), "dog".ToBytes()
            });

            var result = RLP.Decode(input);

            Assert.IsTrue(result.Count == 2);
            Assert.IsTrue(result.All(x => x.IsCollection == false));
            Assert.AreEqual("cat", System.Text.Encoding.ASCII.GetString(result[0].String));
            Assert.AreEqual("dog", System.Text.Encoding.ASCII.GetString(result[1].String));
        }
Esempio n. 16
0
        public void Encode_WhenInputIsCollectionAndTotalLengthOfItemsIs0To55Bytes()
        {
            var input = new List <byte[]> {
                "cat".ToBytes(), "dog".ToBytes()
            };

            var result = RLP.Encode(input);

            Assert.IsTrue(result.Length == 9);
            Assert.IsTrue(result[0] == 200);
            Assert.IsTrue(result[1] == 131);
            Assert.IsTrue(result[5] == 131);
        }
Esempio n. 17
0
        public void Encode_WhenEncodedCollectionIsGreaterThan55BytesReturnCorrectBytes()
        {
            var result = RLP.Encode(new List <string>
            {
                "this is a collection",
                "that when encoded",
                "will be greater than 55 bytes",
            });

            Assert.IsTrue(result.GetType() == typeof(byte[]));
            Assert.IsTrue(result.Length == 71);
            Assert.IsTrue(result[0] == 248);
            Assert.IsTrue(result[1] == 69);
            Assert.IsTrue(result[2] == 148);
            Assert.IsTrue(result[70] == 115);
        }
Esempio n. 18
0
        public void Encode_WhenInputIsCollectionAndTotalLengthOfItemsIs56To255Bytes()
        {
            var input = new List <byte[]>
            {
                "this is a collection".ToBytes(),
                "that when encoded".ToBytes(),
                "will be greater than 55 bytes".ToBytes(),
            };

            var result = RLP.Encode(input);

            Assert.IsTrue(result.Length == 71);
            Assert.IsTrue(result[0] == 248);
            Assert.IsTrue(result[1] == 69);
            Assert.IsTrue(result[2] == 148);
            Assert.IsTrue(result[70] == 115);
        }
Esempio n. 19
0
        public void Decode_WhenDecodedCollectionIsGreaterThan55BytesReturnCorrectValues()
        {
            var bytes = RLP.Encode(new List <string>
            {
                "cat",
                "dog",
                "this is a collection",
                "that when encoded",
                "will be greater than 55 bytes",
                "127"
            });

            var result = RLP.Decode(bytes);

            Assert.IsTrue(result.Count == 6);
            Assert.IsTrue(result[0] == "cat");
            Assert.IsTrue(result[1] == "dog");
            Assert.IsTrue(result[2] == "this is a collection");
            Assert.IsTrue(result[3] == "that when encoded");
            Assert.IsTrue(result[4] == "will be greater than 55 bytes");
            Assert.IsTrue(result[5] == "127");
        }
Esempio n. 20
0
        public void Decode_WhenEncodedCollectionIs56To255Bytes()
        {
            var input = RLP.Encode(new List <byte[]>
            {
                "cat".ToBytes(),
                "dog".ToBytes(),
                "this is a collection".ToBytes(),
                "that when encoded".ToBytes(),
                "will be greater than 55 bytes".ToBytes(),
                127.ToBytes(),
            });

            var result = RLP.Decode(input);

            Assert.IsTrue(result.Count == 6);
            Assert.IsTrue(result.All(x => x.IsCollection == false));
            Assert.AreEqual("cat", System.Text.Encoding.ASCII.GetString(result[0].String));
            Assert.AreEqual("dog", System.Text.Encoding.ASCII.GetString(result[1].String));
            Assert.AreEqual("this is a collection", System.Text.Encoding.ASCII.GetString(result[2].String));
            Assert.AreEqual("that when encoded", System.Text.Encoding.ASCII.GetString(result[3].String));
            Assert.AreEqual("will be greater than 55 bytes", System.Text.Encoding.ASCII.GetString(result[4].String));
            Assert.AreEqual(127, result[5].String[0]);
        }