public void DeserializeString_DataIsNotString_ShouldThrow(params byte[] data)
        {
            var ex = Assert.Throws <TransactionSerializationException>(
                () =>
            {
                var reader = SerializationTesting.CreateReader(data);
                Serializer.DeserializeString(ref reader);
            });

            Assert.Equal("Invalid string.", ex.Message);
        }
Exemplo n.º 2
0
        public void Deserialize_NotEnoughData_ShouldThrow(int length)
        {
            var data = new byte[length];

            Assert.Throws <TransactionSerializationException>(
                () =>
            {
                var reader = SerializationTesting.CreateReader(data);
                this.subject.Deserialize(null, null, ref reader);
            });
        }
Exemplo n.º 3
0
        public void Deserialize_WithUpsupportedTransaction_ShouldThrow()
        {
            // Arrange.
            var writer = SerializationTesting.CreateWriter(2, 0);

            // Act.
            var ex = Assert.Throws <TransactionSerializationException>(
                () =>
            {
                var reader = SerializationTesting.CreateReader(writer);
                this.subject.Deserialize(null, null, ref reader);
            });

            // Assert.
            Assert.Equal("Unknow transaction.", ex.Message);
        }
Exemplo n.º 4
0
        public void Deserialize_WithSupportedTransaction_ShouldInvokePayloadSerializer(int id, params byte[] payload)
        {
            // Arrange.
            var tx = new FakeTransaction(
                TestAddress.Regtest1,
                TestAddress.Regtest2,
                id,
                Elysium.Transaction.MaxVersion);
            var writer = SerializationTesting.CreateWriter(tx.Id, tx.Version);

            var(selected, other) = tx.Id switch
            {
                0 => (this.payload1, this.payload2),
                1 => (this.payload2, this.payload1),
                _ => throw new NotImplementedException()
            };

            writer.Write(payload);

            selected.StubbedDeserialize
            .Setup(f => f(tx.Sender, tx.Receiver, payload, tx.Version))
            .Returns(tx);

            // Act.
            var reader = SerializationTesting.CreateReader(writer);
            var result = this.subject.Deserialize(tx.Sender, tx.Receiver, ref reader);

            // Assert.
            Assert.Same(tx, result);
            Assert.Equal(0, reader.Remaining);

            selected.StubbedDeserialize.Verify(
                f => f(tx.Sender, tx.Receiver, payload, tx.Version),
                Times.Once());

            other.StubbedDeserialize.Verify(
                f => f(It.IsAny <BitcoinAddress?>(), It.IsAny <BitcoinAddress?>(), It.IsAny <byte[]>(), It.IsAny <int>()),
                Times.Never());
        }
Exemplo n.º 5
0
        public void Deserialize_WithUnsupportedVersion_ShouldThrow()
        {
            // Arrange.
            var writer = SerializationTesting.CreateWriter(0, 1);

            this.payload1.StubbedDeserialize
            .Setup(f => f(It.IsAny <BitcoinAddress?>(), It.IsAny <BitcoinAddress?>(), It.IsAny <byte[]>(), 1))
            .Throws(new ArgumentOutOfRangeException("version"));

            // Act.
            var ex = Assert.Throws <TransactionSerializationException>(
                () =>
            {
                var reader = SerializationTesting.CreateReader(writer);
                this.subject.Deserialize(null, null, ref reader);
            });

            // Assert.
            Assert.Equal("Unknow version.", ex.Message);

            this.payload1.StubbedDeserialize.Verify(
                f => f(null, null, new byte[0], 1),
                Times.Once());
        }