Пример #1
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);
            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)}");
        }
Пример #2
0
        public void Can_handle_empty()
        {
            TransactionsMessageSerializer serializer = new TransactionsMessageSerializer();
            TransactionsMessage           message    = new TransactionsMessage(new Transaction[] { });

            SerializerTester.TestZero(serializer, message);
        }
        public void Can_handle_empty()
        {
            TransactionsMessageSerializer serializer = new TransactionsMessageSerializer();
            TransactionsMessage           message    = new TransactionsMessage();

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

            Assert.AreEqual(message.Transactions.Length, deserialized.Transactions.Length);
        }
        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");
        }
Пример #6
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);
        }