Exemplo n.º 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);
                    }
        }
Exemplo n.º 2
0
        public void Constructor_WithValidArguments_ShouldSuccess()
        {
            var tx = new SimpleSendV0(this.sender, this.receiver, this.property, this.amount);

            Assert.Equal(SimpleSendV0.StaticId, tx.Id);
            Assert.Equal(0, tx.Version);
            Assert.Equal(this.sender, tx.Sender);
            Assert.Equal(this.receiver, tx.Receiver);
            Assert.Equal(this.property, tx.Property);
            Assert.Equal(this.amount, tx.Amount);
        }
Exemplo n.º 3
0
        public void Constructor_WhenSuccess_ShouldInitializeProperties()
        {
            var tx = new SimpleSendV0(TestAddress.Regtest1, TestAddress.Regtest2, this.property, this.amount);

            Assert.Equal(SimpleSendV0.StaticId, tx.Id);
            Assert.Equal(0, tx.Version);
            Assert.Equal(TestAddress.Regtest1, tx.Sender);
            Assert.Equal(TestAddress.Regtest2, tx.Receiver);
            Assert.Equal(this.property, tx.Property);
            Assert.Equal(this.amount, tx.Amount);
        }
Exemplo n.º 4
0
        public void SetAndGetExodusTransaction_WithValidTransaction_ShouldRetreiveSameTx()
        {
            // Arrange.
            var address    = TestAddress.Regtest1;
            var propertyId = new PropertyId(3);
            var amount     = new PropertyAmount(10);

            var exodusTx = new SimpleSendV0(address, address, propertyId, amount);

            // Act.
            #pragma warning disable CS0618
            this.subject.SetExodusTransaction(exodusTx);
            #pragma warning restore CS0618
            var retrieved = this.subject.GetExodusTransaction();

            // Assert.
            Assert.Same(exodusTx, retrieved);
        }
Exemplo n.º 5
0
        public async Task GetBalanceChangesAsync_WithSimepleSend_ShouldReturnBalanceChanges()
        {
            // Arrange.
            var sender   = TestAddress.Regtest1;
            var receiver = TestAddress.Regtest2;
            var property = new PropertyId(2);
            var amount   = new PropertyAmount(100);

            var tx = new SimpleSendV0(sender, receiver, property, amount);

            // Act.
            var changes = await this.subject.GetBalanceChangesAsync(tx, CancellationToken.None);

            // Assert.
            Assert.NotNull(changes);
            Assert.Equal(2, changes.Count());
            Assert.Contains(new BalanceChange(sender, PropertyAmount.Negate(amount), property), changes);
            Assert.Contains(new BalanceChange(receiver, amount, property), changes);
        }
Exemplo n.º 6
0
        public async Task AddAsync_WithExodusTransaction_ShouldSuccessAndCallEncode()
        {
            // Arrange.
            var network = ZcoinNetworks.Instance.Regtest;
            var block   = Block.CreateBlock(network);
            var tx      = Transaction.Create(network);

            var sender   = TestAddress.Regtest1;
            var receiver = TestAddress.Regtest2;

            var exodusTx = new SimpleSendV0(sender, receiver, new PropertyId(2), new PropertyAmount(10));

            #pragma warning disable CS0618
            tx.SetExodusTransaction(exodusTx);
            #pragma warning restore CS0618

            block.Transactions.Add(tx);

            // Payload
            var rawPayload = new byte[] { 0x00, 0x01, 0x02, 0x03 };
            this.exodusEncoder.Setup(e => e.Encode(exodusTx)).Returns(rawPayload).Verifiable();

            // Act.
            await this.subject.AddAsync(block, 100, CancellationToken.None);

            // Assert.
            this.exodusEncoder.Verify();
            using (var db = this.dbFactory.CreateDbContext())
            {
                var payload = await db.ExodusPayloads.FirstOrDefaultAsync(CancellationToken.None);

                Assert.NotNull(payload);

                Assert.Equal(tx.GetHash(), payload.TransactionHash);
                Assert.Equal(receiver.ToString(), payload.Receiver);
                Assert.Equal(sender.ToString(), payload.Sender);
                Assert.Equal(rawPayload, payload.Data);
            }
        }
Exemplo n.º 7
0
        async Task TestExodusTransactionRetrieving(Func <ExodusRetrievingTestingInfo, Task> actAndAssert)
        {
            var network = ZcoinNetworks.Instance.Regtest;
            var block   = ZcoinNetworks.Instance.Regtest.GetGenesis().CreateNextBlockWithCoinbase(TestAddress.Regtest1, 1);
            var tx      = Transaction.Create(network);

            var sender   = TestAddress.Regtest1;
            var receiver = TestAddress.Regtest2;

            var exodusTx = new SimpleSendV0(sender, receiver, new PropertyId(2), new PropertyAmount(10));

            #pragma warning disable CS0618
            tx.SetExodusTransaction(exodusTx);
            #pragma warning restore CS0618

            block.Transactions.Add(tx);

            // Payload
            var payload = new byte[] { 0x00, 0x01, 0x02, 0x03 };
            this.exodusEncoder.Setup(e => e.Encode(exodusTx)).Returns(payload);
            this.exodusEncoder.Setup(e => e.Decode(sender, receiver, payload)).Returns(exodusTx);

            var genesis = ZcoinNetworks.Instance.Regtest.GetGenesis();
            await this.subject.AddAsync(genesis, 0, CancellationToken.None);

            await this.subject.AddAsync(block, 1, CancellationToken.None);

            await actAndAssert(new ExodusRetrievingTestingInfo
            {
                Block             = block,
                BlockHeight       = 1,
                ExodusTransaction = exodusTx,
                Transaction       = tx,
                Sender            = sender,
                Receiver          = receiver,
                Payload           = payload,
            });
        }