예제 #1
0
        public void Encode_WithValidExodusTransaction_ShouldSuccess(long property, long amount)
        {
            using (var payloadStream = new MemoryStream())
                using (var stream = new MemoryStream())
                    using (var writer = new BinaryWriter(stream))
                    {
                        // Arrange.
                        RawTransaction.WritePropertyId(payloadStream, property);
                        RawTransaction.WritePropertyAmount(payloadStream, new PropertyAmount(amount));

                        var payload = payloadStream.ToArray();

                        var transaction = new SimpleSendV0(
                            TestAddress.Regtest1,
                            TestAddress.Regtest2,
                            new PropertyId(property),
                            new PropertyAmount(amount)
                            );

                        // Act.
                        this.subject.Encode(writer, transaction);

                        // Assert.
                        var result = stream.ToArray();
                        Assert.Equal(payload, result);
                    }
        }
        public void Decode_V0WithInvalidAmount_ShouldThrow(long amount)
        {
            // Arrange.
            using (var stream = new MemoryStream())
                using (var reader = new BinaryReader(stream))
                {
                    RawTransaction.WritePropertyId(stream, PropertyId.MaxValue);
                    RawTransaction.WritePropertyAmount(stream, new PropertyAmount(amount));

                    stream.Seek(0, SeekOrigin.Begin);

                    // Act.
                    var ex = Assert.Throws <TransactionFieldException>(
                        () => this.subject.Decode(TestAddress.Regtest1, TestAddress.Regtest2, reader, 0)
                        );

                    // Assert.
                    Assert.Equal("amount", ex.Field);
                }
        }
        public void Decode_V0WithValidData_ShouldSuccess(long property, long amount)
        {
            // Arrange.
            using (var stream = new MemoryStream())
                using (var reader = new BinaryReader(stream))
                {
                    RawTransaction.WritePropertyId(stream, property);
                    RawTransaction.WritePropertyAmount(stream, new PropertyAmount(amount));

                    stream.Seek(0, SeekOrigin.Begin);

                    // Act.
                    var tx = (SimpleSendV0)this.subject.Decode(TestAddress.Regtest1, TestAddress.Regtest2, reader, 0);

                    // Assert.
                    Assert.IsType <SimpleSendV0>(tx); // We want to be the exact V0.
                    Assert.Equal(this.subject.Type, tx.Id);
                    Assert.Equal(0, tx.Version);
                    Assert.Same(TestAddress.Regtest1, tx.Sender);
                    Assert.Same(TestAddress.Regtest2, tx.Receiver);
                    Assert.Equal(property, tx.Property.Value);
                    Assert.Equal(amount, tx.Amount.Indivisible);
                }
        }