Ejemplo n.º 1
0
        public void TransferFundsBlockSerializerTests()
        {
            ulong tagId           = 113;
            ulong syncBlockHeight = 1;
            uint  nonce           = 4;

            byte[] powHash     = BinaryBuilder.GetPowHash(1234);
            ushort version     = 1;
            ulong  blockHeight = 9;

            byte[] prevHash = BinaryBuilder.GetDefaultHash(1234);
            byte[] body;

            ulong uptodateFunds = 10001;

            byte[] targetHash = BinaryBuilder.GetDefaultHash(1235);

            using (MemoryStream ms = new MemoryStream())
            {
                using (BinaryWriter bw = new BinaryWriter(ms))
                {
                    bw.Write(tagId);
                    bw.Write(uptodateFunds);
                    bw.Write((uint)0);
                    bw.Write(targetHash);
                }

                body = ms.ToArray();
            }

            byte[] expectedPacket = BinaryBuilder.GetSignedPacket(PacketType.Transactional, syncBlockHeight, nonce, powHash, version,
                                                                  BlockTypes.Transaction_TransferFunds, blockHeight, prevHash, body, _privateKey, out byte[] expectedSignature);

            TransferFundsBlock block = new TransferFundsBlock
            {
                SyncBlockHeight    = syncBlockHeight,
                Nonce              = nonce,
                PowHash            = powHash,
                BlockHeight        = blockHeight,
                HashPrev           = prevHash,
                TagId              = tagId,
                UptodateFunds      = uptodateFunds,
                TargetOriginalHash = targetHash
            };

            TransferFundsBlockSerializer serializer = new TransferFundsBlockSerializer(_cryptoService, _identityKeyProvidersRegistry, _hashCalculationRepository);

            serializer.Initialize(block);

            byte[] actualPacket = serializer.GetBytes();

            Assert.Equal(expectedPacket, actualPacket);
        }
Ejemplo n.º 2
0
        public void TransferFundsBlockSerializerTests()
        {
            ulong syncBlockHeight = 1;
            uint  nonce           = 4;

            byte[] powHash     = BinaryHelper.GetPowHash(1234);
            ushort version     = 1;
            ulong  blockHeight = 9;

            byte[] body;

            ulong uptodateFunds = 10001;

            byte[] targetHash = BinaryHelper.GetDefaultHash(1235);

            using (MemoryStream ms = new MemoryStream())
            {
                using (BinaryWriter bw = new BinaryWriter(ms))
                {
                    bw.Write(uptodateFunds);
                    bw.Write(targetHash);
                }

                body = ms.ToArray();
            }

            byte[] expectedPacket = BinaryHelper.GetSignedPacket(PacketType.Transactional, syncBlockHeight, nonce, powHash, version,
                                                                 BlockTypes.Transaction_TransferFunds, blockHeight, null, body, _privateKey, out byte[] expectedSignature);

            TransferFundsBlock block = new TransferFundsBlock
            {
                SyncBlockHeight    = syncBlockHeight,
                Nonce              = nonce,
                PowHash            = powHash,
                BlockHeight        = blockHeight,
                UptodateFunds      = uptodateFunds,
                TargetOriginalHash = targetHash
            };

            TransferFundsBlockSerializer serializer = new TransferFundsBlockSerializer();

            serializer.Initialize(block);
            serializer.SerializeBody();
            _signingService.Sign(block);

            byte[] actualPacket = serializer.GetBytes();

            Assert.Equal(expectedPacket, actualPacket);
        }