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_V0WithTooShortData_ShouldThrow(int length) { // Arrange. var payload = new byte[length]; using (var stream = new MemoryStream(payload)) using (var reader = new BinaryReader(stream)) { if (payload.Length >= 4) { RawTransaction.WritePropertyId(stream, PropertyId.MinValue); } stream.Seek(0, SeekOrigin.Begin); // Act. var ex = Assert.ThrowsAny <TransactionTooShortException>( () => this.subject.Decode(TestAddress.Regtest1, TestAddress.Regtest2, reader, 0) ); // Assert. Assert.Equal(16, ex.RequiredSize); } }
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); } }