Пример #1
0
        public void ReadAndWriteStreamAllUncommitted()
        {
            AddValidBlocksWithForkAllUncommitted();
            var stream = new MemoryStream();
            var writer = new BinaryWriter(stream);
            var reader = new BinaryReader(stream);

            BlockchainSerializer.WriteTo(writer, _chain);
            stream.Seek(0, 0);
            SimpleBlockchain newChain = BlockchainSerializer.ReadFrom(reader);

            Assert.Equal(_1, newChain.RetrieveAlias(_tmpId1));
            Assert.Equal(_2, newChain.RetrieveAlias(_tmpId2));
            Assert.Equal(_3, newChain.RetrieveAlias(_tmpId3));
            Assert.Equal(_4, newChain.RetrieveAlias(_tmpId4));

            Assert.True(newChain.RetrieveUncommittedBlock(_1, out var oneBlock));
            Assert.True(newChain.RetrieveUncommittedBlock(_2, out var twoBlock));
            Assert.True(newChain.RetrieveUncommittedBlock(_3, out var threeBlock));
            Assert.True(newChain.RetrieveUncommittedBlock(_4, out var fourBlock));

            Assert.Equal(_tmpId1, oneBlock.BlockId);
            Assert.Equal(_tmpId2, twoBlock.BlockId);
            Assert.Equal(_tmpId3, threeBlock.BlockId);
            Assert.Equal(_tmpId4, fourBlock.BlockId);

            Assert.Equal(2, _chain.BlockchainHeight);
        }
Пример #2
0
        public void ReadAndWriteStreamAllCommitted()
        {
            AddValidBlocksWithFork();
            var stream = new MemoryStream();
            var writer = new BinaryWriter(stream);
            var reader = new BinaryReader(stream);

            BlockchainSerializer.WriteTo(writer, _chain);
            stream.Seek(0, 0);
            var newChain = BlockchainSerializer.ReadFrom(reader);

            Assert.Equal(_1, newChain.RetrieveAlias(BlockId.Genesis));
            Assert.Equal(_2, newChain.RetrieveAlias(_hash1));
            Assert.Equal(_3, newChain.RetrieveAlias(_hash2));
            Assert.Equal(_4, newChain.RetrieveAlias(_hash3));

            Assert.True(newChain.RetrieveCommittedBlock(_1, out var oneBlock));
            Assert.True(newChain.RetrieveCommittedBlock(_2, out var twoBlock));
            Assert.True(newChain.RetrieveCommittedBlock(_3, out var threeBlock));
            Assert.True(newChain.RetrieveCommittedBlock(_4, out var fourBlock));

            Assert.Equal(BlockId.Genesis, oneBlock.BlockId);
            Assert.Equal(_hash1, twoBlock.BlockId);
            Assert.Equal(_hash2, threeBlock.BlockId);
            Assert.Equal(_hash3, fourBlock.BlockId);

            Assert.Equal(2, _chain.BlockchainHeight);
        }