Exemplo n.º 1
0
        public void Can_handle_empty()
        {
            TransactionsMessageSerializer serializer = new TransactionsMessageSerializer();
            TransactionsMessage           message    = new TransactionsMessage(new Transaction[] { });

            SerializerTester.TestZero(serializer, message);
        }
        public void Roundtrip_empty_status()
        {
            StatusMessage           statusMessage = new();
            StatusMessageSerializer serializer    = new();

            SerializerTester.TestZero(serializer, statusMessage);
        }
Exemplo n.º 3
0
        public void Roundtrip()
        {
            NewBlockHashesMessage message = new NewBlockHashesMessage((Keccak.Compute("1"), 1), (Keccak.Compute("2"), 2));
            var serializer = new NewBlockHashesMessageSerializer();

            SerializerTester.TestZero(serializer, message);
        }
        public void Roundtrip_with_nulls()
        {
            BlockBodiesMessage message = new() { Bodies = new BlockBody[1] {
                                                     null
                                                 } };
            var serializer = new BlockBodiesMessageSerializer();

            SerializerTester.TestZero(serializer, message);
        }
    }
Exemplo n.º 5
0
        public void Roundtrip()
        {
            NewBlockMessage message = new NewBlockMessage();

            message.TotalDifficulty = 131200;
            message.Block           = Build.A.Block.Genesis.TestObject;
            NewBlockMessageSerializer serializer = new NewBlockMessageSerializer();

            SerializerTester.TestZero(serializer, message, "f90205f901fef901f9a00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000830f424080833d090080830f424083010203a000000000000000000000000000000000000000000000000000000000000000008800000000000003e8c0c083020080");
        }
        public void Roundtrip()
        {
            StatusMessage statusMessage = new();

            statusMessage.ProtocolVersion = 63;
            statusMessage.BestHash        = Keccak.Compute("1");
            statusMessage.GenesisHash     = Keccak.Compute("0");
            statusMessage.TotalDifficulty = 131200;
            statusMessage.ChainId         = 1;

            StatusMessageSerializer serializer = new();

            SerializerTester.TestZero(serializer, statusMessage, "f8483f0183020080a0c89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6a0044852b2a670ade5407e78fb2863c51de9fcb96542a07186fe3aeda6bb8a116d");
        }
        public void Roundtrip_with_fork_id_next_is_max()
        {
            StatusMessage statusMessage = new();

            statusMessage.ProtocolVersion = 63;
            statusMessage.BestHash        = Keccak.Compute("1");
            statusMessage.GenesisHash     = Keccak.Compute("0");
            statusMessage.TotalDifficulty = 131200;
            statusMessage.ChainId         = 1;
            statusMessage.ForkId          = new ForkId(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }, long.MaxValue);

            StatusMessageSerializer serializer = new();

            SerializerTester.TestZero(serializer, statusMessage);
        }
        public void Roundtrip()
        {
            BlockHeader header = Build.A.BlockHeader.TestObject;
            Address     to     = Build.An.Address.FromNumber(1).TestObject;
            Transaction tx     = Build.A.Transaction.WithTo(to).SignedAndResolved(new EthereumEcdsa(ChainId.Ropsten, LimboLogs.Instance), TestItem.PrivateKeyA).TestObject;

            tx.SenderAddress = null;
            BlockBodiesMessage message = new();

            message.Bodies = new [] { new BlockBody(new [] { tx }, new [] { header }) };

            var serializer = new BlockBodiesMessageSerializer();

            SerializerTester.TestZero(serializer, message);
        }
        public void Roundtrip_nulls()
        {
            BlockHeadersMessage message = new BlockHeadersMessage();

            message.BlockHeaders = new[] { Build.A.BlockHeader.TestObject, null };

            BlockHeadersMessageSerializer serializer = new BlockHeadersMessageSerializer();

            byte[] bytes = serializer.Serialize(message);

            BlockHeadersMessage deserialized = serializer.Deserialize(bytes);

            Assert.AreEqual(message.BlockHeaders.Length, deserialized.BlockHeaders.Length, "length");
            Assert.AreEqual(message.BlockHeaders[0].Hash, deserialized.BlockHeaders[0].Hash, "hash");
            Assert.Null(message.BlockHeaders[1]);

            SerializerTester.TestZero(serializer, message);
        }
        public void Roundtrip_call()
        {
            TransactionsMessageSerializer serializer = new TransactionsMessageSerializer();
            Transaction transaction = new Transaction();

            transaction.Data          = new byte[] { 1, 2, 3 };
            transaction.GasLimit      = 10;
            transaction.GasPrice      = 100;
            transaction.Nonce         = 1000;
            transaction.Signature     = new Signature(1, 2, 27);
            transaction.To            = TestItem.AddressA;
            transaction.Value         = 10000;
            transaction.Hash          = transaction.CalculateHash();
            transaction.SenderAddress = null;

            TransactionsMessage message = new TransactionsMessage(new[] { transaction, transaction });

            SerializerTester.TestZero(serializer, message, "f84ae48203e8640a94b7705ae4c6f81b66cdb323c65f4e8133690fc099822710830102031b0102e48203e8640a94b7705ae4c6f81b66cdb323c65f4e8133690fc099822710830102031b0102");
        }
        public void Roundtrip_init()
        {
            TransactionsMessageSerializer serializer = new TransactionsMessageSerializer();
            Transaction transaction = new Transaction();

            transaction.GasLimit      = 10;
            transaction.GasPrice      = 100;
            transaction.Data          = new byte[] { 4, 5, 6 };
            transaction.Nonce         = 1000;
            transaction.Signature     = new Signature(1, 2, 27);
            transaction.To            = null;
            transaction.Value         = 10000;
            transaction.Hash          = transaction.CalculateHash();
            transaction.SenderAddress = null;

            TransactionsMessage message = new TransactionsMessage(new[] { transaction, transaction });

            SerializerTester.TestZero(serializer, message, "e2d08203e8640a80822710830405061b0102d08203e8640a80822710830405061b0102");
        }
        public void Roundtrip()
        {
            BlockHeadersMessage message = new BlockHeadersMessage();

            message.BlockHeaders = new[] { Build.A.BlockHeader.TestObject };

            BlockHeadersMessageSerializer serializer = new BlockHeadersMessageSerializer();

            byte[] bytes         = serializer.Serialize(message);
            byte[] expectedBytes = Bytes.FromHexString("f901fcf901f9a0ff483e972a04a9a62bb4b7d04ae403c615604e4090521ecc5bb7af67f71be09ca01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000830f424080833d090080830f424083010203a02ba5557a4c62a513c7e56d1bf13373e0da6bec016755483e91589fe1c6d212e28800000000000003e8");

            Assert.AreEqual(bytes.ToHexString(), expectedBytes.ToHexString(), "bytes");

            BlockHeadersMessage deserialized = serializer.Deserialize(bytes);

            Assert.AreEqual(message.BlockHeaders.Length, deserialized.BlockHeaders.Length, "length");
            Assert.AreEqual(message.BlockHeaders[0].Hash, deserialized.BlockHeaders[0].Hash, "hash");

            SerializerTester.TestZero(serializer, message);
        }
        public void Roundtrip()
        {
            GetBlockBodiesMessageSerializer serializer = new GetBlockBodiesMessageSerializer();
            GetBlockBodiesMessage           message    = new GetBlockBodiesMessage(Keccak.OfAnEmptySequenceRlp, Keccak.Zero, Keccak.EmptyTreeHash);

            byte[] bytes         = serializer.Serialize(message);
            byte[] expectedBytes = Bytes.FromHexString("f863a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347a00000000000000000000000000000000000000000000000000000000000000000a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421");

            Assert.True(Bytes.AreEqual(bytes, expectedBytes), "bytes");

            GetBlockBodiesMessage deserialized = serializer.Deserialize(bytes);

            Assert.AreEqual(message.BlockHashes.Count, deserialized.BlockHashes.Count, $"count");
            for (int i = 0; i < message.BlockHashes.Count; i++)
            {
                Assert.AreEqual(message.BlockHashes[i], deserialized.BlockHashes[i], $"hash {i}");
            }

            SerializerTester.TestZero(serializer, message);
        }
Exemplo n.º 14
0
        public void Roundtrip2()
        {
            Transaction a     = Build.A.Transaction.SignedAndResolved().TestObject;
            Transaction b     = Build.A.Transaction.SignedAndResolved().TestObject;
            Transaction c     = Build.A.Transaction.SignedAndResolved().TestObject;
            Transaction d     = Build.A.Transaction.SignedAndResolved().TestObject;
            Transaction e     = Build.A.Transaction.SignedAndResolved().TestObject;
            Transaction f     = Build.A.Transaction.SignedAndResolved().TestObject;
            Block       block = Build.A.Block.WithTransactions(a, b, c, d, e, f).TestObject;

            foreach (Transaction transaction in block.Transactions)
            {
                transaction.SenderAddress = null;
            }

            NewBlockMessage message = new NewBlockMessage();

            message.Block = block;

            NewBlockMessageSerializer serializer = new NewBlockMessageSerializer();

            SerializerTester.TestZero(serializer, message, "f9044af90446f901f9a0ff483e972a04a9a62bb4b7d04ae403c615604e4090521ecc5bb7af67f71be09ca01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0b8fe3489c99b3cfe741222974963cab3c8b74190d31e61876b12cc056ec9c816a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000830f424080833d090080830f424083010203a02ba5557a4c62a513c7e56d1bf13373e0da6bec016755483e91589fe1c6d212e28800000000000003e8f90246f85f8001825208940000000000000000000000000000000000000000018025a0ac46223b1f2bb2c1a0397d2e44e0cf82b78a766b3035f6c34be06395db18a8e4a0379b8a0437094d9e1d0ae5c2511d1a4b2cb65be7974d6cbccd5370e14f2df3a5f85f8001825208940000000000000000000000000000000000000000018025a0ac46223b1f2bb2c1a0397d2e44e0cf82b78a766b3035f6c34be06395db18a8e4a0379b8a0437094d9e1d0ae5c2511d1a4b2cb65be7974d6cbccd5370e14f2df3a5f85f8001825208940000000000000000000000000000000000000000018025a0ac46223b1f2bb2c1a0397d2e44e0cf82b78a766b3035f6c34be06395db18a8e4a0379b8a0437094d9e1d0ae5c2511d1a4b2cb65be7974d6cbccd5370e14f2df3a5f85f8001825208940000000000000000000000000000000000000000018025a0ac46223b1f2bb2c1a0397d2e44e0cf82b78a766b3035f6c34be06395db18a8e4a0379b8a0437094d9e1d0ae5c2511d1a4b2cb65be7974d6cbccd5370e14f2df3a5f85f8001825208940000000000000000000000000000000000000000018025a0ac46223b1f2bb2c1a0397d2e44e0cf82b78a766b3035f6c34be06395db18a8e4a0379b8a0437094d9e1d0ae5c2511d1a4b2cb65be7974d6cbccd5370e14f2df3a5f85f8001825208940000000000000000000000000000000000000000018025a0ac46223b1f2bb2c1a0397d2e44e0cf82b78a766b3035f6c34be06395db18a8e4a0379b8a0437094d9e1d0ae5c2511d1a4b2cb65be7974d6cbccd5370e14f2df3a5c080");
        }
Exemplo n.º 15
0
        public void Roundtrip_zero()
        {
            GetBlockHeadersMessage message = new GetBlockHeadersMessage();

            message.MaxHeaders       = 1;
            message.Skip             = 2;
            message.Reverse          = 0;
            message.StartBlockNumber = 100;
            GetBlockHeadersMessageSerializer serializer = new GetBlockHeadersMessageSerializer();

            byte[] bytes         = serializer.Serialize(message);
            byte[] expectedBytes = Bytes.FromHexString("c464010280");

            Assert.AreEqual(expectedBytes, bytes, "bytes");

            GetBlockHeadersMessage deserialized = serializer.Deserialize(bytes);

            Assert.AreEqual(message.StartBlockNumber, deserialized.StartBlockNumber, $"{nameof(message.StartBlockNumber)}");
            Assert.AreEqual(message.MaxHeaders, deserialized.MaxHeaders, $"{nameof(message.MaxHeaders)}");
            Assert.AreEqual(message.Reverse, deserialized.Reverse, $"{nameof(message.Reverse)}");
            Assert.AreEqual(message.Skip, deserialized.Skip, $"{nameof(message.Skip)}");

            SerializerTester.TestZero(serializer, message);
        }
Exemplo n.º 16
0
        public void Roundtrip_hash()
        {
            GetBlockHeadersMessage message = new GetBlockHeadersMessage();

            message.MaxHeaders     = 1;
            message.Skip           = 2;
            message.Reverse        = 1;
            message.StartBlockHash = Keccak.OfAnEmptyString;
            GetBlockHeadersMessageSerializer serializer = new GetBlockHeadersMessageSerializer();

            byte[] bytes         = serializer.Serialize(message);
            byte[] expectedBytes = Bytes.FromHexString("e4a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470010201");

            Assert.True(Bytes.AreEqual(bytes, expectedBytes), "bytes");

            GetBlockHeadersMessage deserialized = serializer.Deserialize(bytes);

            Assert.AreEqual(message.StartBlockHash, deserialized.StartBlockHash, $"{nameof(message.StartBlockHash)}");
            Assert.AreEqual(message.MaxHeaders, deserialized.MaxHeaders, $"{nameof(message.MaxHeaders)}");
            Assert.AreEqual(message.Reverse, deserialized.Reverse, $"{nameof(message.Reverse)}");
            Assert.AreEqual(message.Skip, deserialized.Skip, $"{nameof(message.Skip)}");

            SerializerTester.TestZero(serializer, message);
        }