Exemple #1
0
        public void TestDeserialize()
        {
            ISerializable newContract = new ContractState();

            using (MemoryStream ms = new MemoryStream(1024))
                using (BinaryWriter writer = new BinaryWriter(ms))
                    using (BinaryReader reader = new BinaryReader(ms))
                    {
                        ((ISerializable)contract).Serialize(writer);
                        ms.Seek(0, SeekOrigin.Begin);
                        newContract.Deserialize(reader);
                    }
            ((ContractState)newContract).Manifest.ToJson().ToString().Should().Be(contract.Manifest.ToJson().ToString());
            ((ContractState)newContract).Script.Should().BeEquivalentTo(contract.Script);
        }
Exemple #2
0
        public void Deserialize()
        {
            FunctionCode code;
            bool         hasStorage;
            string       name;
            string       codeVersion;
            string       author;
            string       email;
            string       description;

            setupContractStateWithValues(new ContractState(), out code, out hasStorage, out name, out codeVersion, out author, out email, out description);

            byte[] data  = new byte[] { 0, 32, 66, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 1, 0, 0, 1, 7, 110, 97, 109, 101, 83, 116, 114, 14, 99, 111, 100, 101, 86, 101, 114, 115, 105, 111, 110, 83, 116, 114, 9, 97, 117, 116, 104, 111, 114, 83, 116, 114, 8, 101, 109, 97, 105, 108, 83, 116, 114, 14, 100, 101, 115, 99, 114, 105, 112, 116, 105, 111, 110, 83, 116, 114 };
            int    index = 0;

            using (MemoryStream ms = new MemoryStream(data, index, data.Length - index, false))
            {
                using (BinaryReader reader = new BinaryReader(ms))
                {
                    uut.Deserialize(reader);
                }
            }
            uut.Code.ParameterList.Length.Should().Be(code.ParameterList.Length);
            for (int i = 0; i < uut.Code.ParameterList.Length; i++)
            {
                uut.Code.ParameterList[i].Should().Be(code.ParameterList[i]);
            }
            uut.Code.Script.Length.Should().Be(code.Script.Length);
            for (int i = 0; i < uut.Code.Script.Length; i++)
            {
                uut.Code.Script[i].Should().Be(code.Script[i]);
            }
            uut.Code.ReturnType.Should().Be(code.ReturnType);
            uut.HasStorage.Should().Be(hasStorage);
            uut.CodeVersion.Should().Be(codeVersion);
            uut.Author.Should().Be(author);
            uut.Email.Should().Be(email);
            uut.Description.Should().Be(description);
        }