Пример #1
0
        public void TestSerialize()
        {
            byte[] result1 = BinarySerializer.Serialize(new byte[5], MaxItemSize);
            byte[] expectedArray1 = new byte[] {
                        0x28, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00
                    };
            Assert.AreEqual(Encoding.Default.GetString(expectedArray1), Encoding.Default.GetString(result1));

            byte[] result2 = BinarySerializer.Serialize(true, MaxItemSize);
            byte[] expectedArray2 = new byte[] {
                        0x20, 0x01
                    };
            Assert.AreEqual(Encoding.Default.GetString(expectedArray2), Encoding.Default.GetString(result2));

            byte[] result3 = BinarySerializer.Serialize(1, MaxItemSize);
            byte[] expectedArray3 = new byte[] {
                        0x21, 0x01, 0x01
                    };
            Assert.AreEqual(Encoding.Default.GetString(expectedArray3), Encoding.Default.GetString(result3));

            StackItem stackItem4 = new InteropInterface(new object());
            Action action4 = () => BinarySerializer.Serialize(stackItem4, MaxItemSize);
            action4.Should().Throw<NotSupportedException>();

            List<StackItem> list6 = new List<StackItem> { 1 };
            StackItem stackItem62 = new VM.Types.Array(list6);
            byte[] result6 = BinarySerializer.Serialize(stackItem62, MaxItemSize);
            byte[] expectedArray6 = new byte[] {
                        0x40,0x01,0x21,0x01,0x01
                    };
            Assert.AreEqual(Encoding.Default.GetString(expectedArray6), Encoding.Default.GetString(result6));

            List<StackItem> list7 = new List<StackItem> { 1 };
            StackItem stackItem72 = new Struct(list7);
            byte[] result7 = BinarySerializer.Serialize(stackItem72, MaxItemSize);
            byte[] expectedArray7 = new byte[] {
                        0x41,0x01,0x21,0x01,0x01
                    };
            Assert.AreEqual(Encoding.Default.GetString(expectedArray7), Encoding.Default.GetString(result7));

            StackItem stackItem82 = new Map { [2] = 1 };
            byte[] result8 = BinarySerializer.Serialize(stackItem82, MaxItemSize);
            byte[] expectedArray8 = new byte[] {
                        0x48,0x01,0x21,0x01,0x02,0x21,0x01,0x01
                    };
            Assert.AreEqual(Encoding.Default.GetString(expectedArray8), Encoding.Default.GetString(result8));

            Map stackItem91 = new Map();
            stackItem91[1] = stackItem91;
            Action action9 = () => BinarySerializer.Serialize(stackItem91, MaxItemSize);
            action9.Should().Throw<NotSupportedException>();

            VM.Types.Array stackItem10 = new VM.Types.Array();
            stackItem10.Add(stackItem10);
            Action action10 = () => BinarySerializer.Serialize(stackItem10, MaxItemSize);
            action10.Should().Throw<NotSupportedException>();
        }
Пример #2
0
        public void TestSerialize()
        {
            byte[] result1        = StackItemSerializer.Serialize(new byte[5]);
            byte[] expectedArray1 = new byte[] {
                0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00
            };
            Assert.AreEqual(Encoding.Default.GetString(expectedArray1), Encoding.Default.GetString(result1));

            byte[] result2        = StackItemSerializer.Serialize(true);
            byte[] expectedArray2 = new byte[] {
                0x01, 0x01
            };
            Assert.AreEqual(Encoding.Default.GetString(expectedArray2), Encoding.Default.GetString(result2));

            byte[] result3        = StackItemSerializer.Serialize(1);
            byte[] expectedArray3 = new byte[] {
                0x02, 0x01, 0x01
            };
            Assert.AreEqual(Encoding.Default.GetString(expectedArray3), Encoding.Default.GetString(result3));

            StackItem stackItem4 = new InteropInterface <object>(new object());
            Action    action4    = () => StackItemSerializer.Serialize(stackItem4);

            action4.Should().Throw <NotSupportedException>();

            byte[] result5        = StackItemSerializer.Serialize(1);
            byte[] expectedArray5 = new byte[] {
                0x02, 0x01, 0x01
            };
            Assert.AreEqual(Encoding.Default.GetString(expectedArray5), Encoding.Default.GetString(result5));


            List <StackItem> list6 = new List <StackItem> {
                1
            };
            StackItem stackItem62 = new VM.Types.Array(list6);

            byte[] result6        = StackItemSerializer.Serialize(stackItem62);
            byte[] expectedArray6 = new byte[] {
                0x80, 0x01, 0x02, 0x01, 0x01
            };
            Assert.AreEqual(Encoding.Default.GetString(expectedArray6), Encoding.Default.GetString(result6));

            List <StackItem> list7 = new List <StackItem> {
                1
            };
            StackItem stackItem72 = new Struct(list7);

            byte[] result7        = StackItemSerializer.Serialize(stackItem72);
            byte[] expectedArray7 = new byte[] {
                0x81, 0x01, 0x02, 0x01, 0x01
            };
            Assert.AreEqual(Encoding.Default.GetString(expectedArray7), Encoding.Default.GetString(result7));

            Dictionary <PrimitiveType, StackItem> list8 = new Dictionary <PrimitiveType, StackItem> {
                [2] = 1
            };
            StackItem stackItem82 = new Map(list8);

            byte[] result8        = StackItemSerializer.Serialize(stackItem82);
            byte[] expectedArray8 = new byte[] {
                0x82, 0x01, 0x02, 0x01, 0x02, 0x02, 0x01, 0x01
            };
            Assert.AreEqual(Encoding.Default.GetString(expectedArray8), Encoding.Default.GetString(result8));

            Map stackItem91 = new Map();

            stackItem91.Add(1, stackItem91);
            Action action9 = () => StackItemSerializer.Serialize(stackItem91);

            action9.Should().Throw <NotSupportedException>();

            VM.Types.Array stackItem10 = new VM.Types.Array();
            stackItem10.Add(stackItem10);
            Action action10 = () => StackItemSerializer.Serialize(stackItem10);

            action10.Should().Throw <NotSupportedException>();
        }
Пример #3
0
        public void TestSerialize()
        {
            StackItem stackItem1 = new ByteArray(new byte[5]);

            byte[] result1        = Neo.SmartContract.Helper.Serialize(stackItem1);
            byte[] expectedArray1 = new byte[] {
                0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00
            };
            Assert.AreEqual(Encoding.Default.GetString(expectedArray1), Encoding.Default.GetString(result1));

            StackItem stackItem2 = new VM.Types.Boolean(true);

            byte[] result2        = Neo.SmartContract.Helper.Serialize(stackItem2);
            byte[] expectedArray2 = new byte[] {
                0x01, 0x01
            };
            Assert.AreEqual(Encoding.Default.GetString(expectedArray2), Encoding.Default.GetString(result2));

            StackItem stackItem3 = new VM.Types.Integer(1);

            byte[] result3        = Neo.SmartContract.Helper.Serialize(stackItem3);
            byte[] expectedArray3 = new byte[] {
                0x02, 0x01, 0x01
            };
            Assert.AreEqual(Encoding.Default.GetString(expectedArray3), Encoding.Default.GetString(result3));

            StackItem stackItem4 = new InteropInterface <object>(new object());
            Action    action4    = () => Neo.SmartContract.Helper.Serialize(stackItem4);

            action4.Should().Throw <NotSupportedException>();

            StackItem stackItem5 = new VM.Types.Integer(1);

            byte[] result5        = Neo.SmartContract.Helper.Serialize(stackItem5);
            byte[] expectedArray5 = new byte[] {
                0x02, 0x01, 0x01
            };
            Assert.AreEqual(Encoding.Default.GetString(expectedArray5), Encoding.Default.GetString(result5));


            StackItem        stackItem61 = new VM.Types.Integer(1);
            List <StackItem> list6       = new List <StackItem>
            {
                stackItem61
            };
            StackItem stackItem62 = new VM.Types.Array(list6);

            byte[] result6        = Neo.SmartContract.Helper.Serialize(stackItem62);
            byte[] expectedArray6 = new byte[] {
                0x80, 0x01, 0x02, 0x01, 0x01
            };
            Assert.AreEqual(Encoding.Default.GetString(expectedArray6), Encoding.Default.GetString(result6));

            StackItem        stackItem71 = new VM.Types.Integer(1);
            List <StackItem> list7       = new List <StackItem>
            {
                stackItem71
            };
            StackItem stackItem72 = new VM.Types.Struct(list7);

            byte[] result7        = Neo.SmartContract.Helper.Serialize(stackItem72);
            byte[] expectedArray7 = new byte[] {
                0x81, 0x01, 0x02, 0x01, 0x01
            };
            Assert.AreEqual(Encoding.Default.GetString(expectedArray7), Encoding.Default.GetString(result7));

            StackItem stackItem81 = new VM.Types.Integer(1);
            Dictionary <PrimitiveType, StackItem> list8 = new Dictionary <PrimitiveType, StackItem>
            {
                { new VM.Types.Integer(2), stackItem81 }
            };
            StackItem stackItem82 = new VM.Types.Map(list8);

            byte[] result8        = Neo.SmartContract.Helper.Serialize(stackItem82);
            byte[] expectedArray8 = new byte[] {
                0x82, 0x01, 0x02, 0x01, 0x02, 0x02, 0x01, 0x01
            };
            Assert.AreEqual(Encoding.Default.GetString(expectedArray8), Encoding.Default.GetString(result8));

            Integer stackItem9  = new VM.Types.Integer(1);
            Map     stackItem91 = new VM.Types.Map();

            stackItem91.Add(stackItem9, stackItem91);
            Action action9 = () => Neo.SmartContract.Helper.Serialize(stackItem91);

            action9.Should().Throw <NotSupportedException>();

            VM.Types.Array stackItem10 = new VM.Types.Array();
            stackItem10.Add(stackItem10);
            Action action10 = () => Neo.SmartContract.Helper.Serialize(stackItem10);

            action10.Should().Throw <NotSupportedException>();
        }