コード例 #1
0
        public void Roundtrip()
        {
            NewBlockHashesMessage message = new NewBlockHashesMessage((Keccak.Compute("1"), 1), (Keccak.Compute("2"), 2));
            var serializer = new NewBlockHashesMessageSerializer();

            SerializerTester.TestZero(serializer, message);
        }
コード例 #2
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;
            NewBlockMessage message = new NewBlockMessage();

            message.Block = block;

            NewBlockMessageSerializer serializer = new NewBlockMessageSerializer();

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

//            TestContext.Out.WriteLine(bytes.ToHexString());
//            TestContext.Out.WriteLine(bytes.Length);
            Assert.AreEqual(expectedBytes.ToHexString(), bytes.ToHexString(), "bytes");

            NewBlockMessage deserializedBlock = serializer.Deserialize(bytes);

            Assert.AreEqual(6, deserializedBlock.Block.Transactions.Length, "length tx");

            SerializerTester.Test(serializer, message);
            SerializerTester.TestZero(serializer, message);
        }
コード例 #3
0
        public void Can_handle_empty()
        {
            TransactionsMessageSerializer serializer = new TransactionsMessageSerializer();
            TransactionsMessage           message    = new TransactionsMessage();

            SerializerTester.TestZero(serializer, message);
        }
コード例 #4
0
        public void Roundtrip_zero()
        {
            GetBlockHeadersMessage message = new GetBlockHeadersMessage();

            message.MaxHeaders          = 1;
            message.Skip                = 2;
            message.Reverse             = 0;
            message.StartingBlockNumber = 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.StartingBlockNumber, deserialized.StartingBlockNumber, $"{nameof(message.StartingBlockNumber)}");
            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.Test(serializer, message);
            SerializerTester.TestZero(serializer, message);
        }
コード例 #5
0
        public void Roundtrip_hash()
        {
            GetBlockHeadersMessage message = new GetBlockHeadersMessage();

            message.MaxHeaders        = 1;
            message.Skip              = 2;
            message.Reverse           = 1;
            message.StartingBlockHash = 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.StartingBlockHash, deserialized.StartingBlockHash, $"{nameof(message.StartingBlockHash)}");
            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.Test(serializer, message);
            SerializerTester.TestZero(serializer, message);
        }
コード例 #6
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");
        }
コード例 #7
0
        public void Roundtrip_with_nulls()
        {
            BlockBodiesMessage message = new BlockBodiesMessage {
                Bodies = new BlockBody[1] {
                    null
                }
            };
            var serializer = new BlockBodiesMessageSerializer();

            SerializerTester.TestZero(serializer, message);
        }
コード例 #8
0
        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(RopstenSpecProvider.Instance, NullLogManager.Instance), TestItem.PrivateKeyA, 1).TestObject;
            BlockBodiesMessage message = new BlockBodiesMessage();

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

            var serializer = new BlockBodiesMessageSerializer();

            SerializerTester.TestZero(serializer, message);
        }
コード例 #9
0
        public void Hobbit()
        {
            StatusMessage message = new StatusMessage();

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

            StatusMessageSerializer serializer = new StatusMessageSerializer();

            SerializerTester.TestZero(serializer, message);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        public void Roundtrip()
        {
            TransactionsMessageSerializer serializer = new TransactionsMessageSerializer();
            Transaction transaction = new Transaction();

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

            TransactionsMessage message = new TransactionsMessage(transaction, transaction);

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

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

            TransactionsMessage deserialized = serializer.Deserialize(bytes);

            Assert.AreEqual(message.Transactions.Length, deserialized.Transactions.Length, "length");
            // TODO: Chain IDs need to be handled properly
//            Assert.AreEqual(message.Transactions[0].ChainId, deserialized.Transactions[0].ChainId, $"{nameof(Transaction.ChainId)}");
            Assert.AreEqual(message.Transactions[0].Data, deserialized.Transactions[0].Data, $"{nameof(Transaction.Data)}");
            Assert.AreEqual(message.Transactions[0].GasLimit, deserialized.Transactions[0].GasLimit, $"{nameof(Transaction.GasLimit)}");
            Assert.AreEqual(message.Transactions[0].GasPrice, deserialized.Transactions[0].GasPrice, $"{nameof(Transaction.GasPrice)}");
            Assert.AreEqual(message.Transactions[0].Hash, deserialized.Transactions[0].Hash, $"{nameof(Transaction.Hash)}");
            // TODO: cannot test Init and Data at once with one transaction only
//            Assert.AreEqual(message.Transactions[0].Init, deserialized.Transactions[0].Init, $"{nameof(Transaction.Init)}");
            Assert.AreEqual(message.Transactions[0].Nonce, deserialized.Transactions[0].Nonce, $"{nameof(Transaction.Nonce)}");
            Assert.AreEqual(message.Transactions[0].Signature, deserialized.Transactions[0].Signature, $"{nameof(Transaction.Signature)}");
            Assert.AreEqual(message.Transactions[0].To, deserialized.Transactions[0].To, $"{nameof(Transaction.To)}");
            Assert.AreEqual(message.Transactions[0].Value, deserialized.Transactions[0].Value, $"{nameof(Transaction.Value)}");

            SerializerTester.Test(serializer, message);
            SerializerTester.TestZero(serializer, message);
        }