Exemplo n.º 1
0
        public async Task InvalidTransactionIdThrowsErrorNetVersion070Regression()
        {
            // The following unit test used to throw a precheck exception because
            // the COST_ANSWER would error out if the record did not exist, will
            // this be restored or is this the new (wasteful) behavior?  For now
            // mark this test as a regression and we will wait and see if it changes
            // in the next version.  If not, we will need to look into changing
            // the behavior of the library in an attempt to not waste client hBars.
            var testFailException = (await Assert.ThrowsAsync <Xunit.Sdk.ThrowsException>(InvalidTransactionIdThrowsError));

            Assert.StartsWith("Assert.Throws() Failure", testFailException.Message);

            // [Fact(DisplayName = "Get Record: Invalid Transaction ID throws error.")]
            async Task InvalidTransactionIdThrowsError()
            {
                await using var client = _network.NewClient();
                var txId = new Proto.TransactionID {
                    AccountID = new Proto.AccountID(_network.Payer), TransactionValidStart = new Proto.Timestamp {
                        Seconds = 500, Nanos = 100
                    }
                }.ToTxId();
                var pex = await Assert.ThrowsAsync <PrecheckException>(async() =>
                {
                    await client.GetTransactionRecordAsync(txId);
                });

                Assert.Equal(ResponseCode.RecordNotFound, pex.Status);
                Assert.StartsWith("Transaction Failed Pre-Check: RecordNotFound", pex.Message);
            }
        }
Exemplo n.º 2
0
        public async Task SubmitUnsafeTransaction()
        {
            await using var client = _network.NewClient();
            var systemAddress = await _network.GetSystemAccountAddress();

            if (systemAddress is null)
            {
                _network.Output?.WriteLine("TEST SKIPPED: No access to System Administrator Account.");
                return;
            }
            // Ok, lets build a TX from Scratch, Including a Signature
            var txid      = client.CreateNewTxId();
            var transfers = new Proto.TransferList();

            transfers.AccountAmounts.Add(new Proto.AccountAmount
            {
                AccountID = new Proto.AccountID(_network.Payer),
                Amount    = -1
            });
            transfers.AccountAmounts.Add(new Proto.AccountAmount
            {
                AccountID = new Proto.AccountID(_network.Gateway),
                Amount    = 1
            });
            var body = new Proto.TransactionBody
            {
                TransactionID            = new Proto.TransactionID(txid),
                NodeAccountID            = new Proto.AccountID(_network.Gateway),
                TransactionFee           = 30_00_000_000,
                TransactionValidDuration = new Proto.Duration {
                    Seconds = 180
                },
                Memo           = "Unsafe Test",
                CryptoTransfer = new Proto.CryptoTransferTransactionBody {
                    Transfers = transfers
                }
            };
            var invoice = new Invoice(body);

            await(_network.Signatory as ISignatory).SignAsync(invoice);
            var transaction = new Proto.Transaction
            {
                SignedTransactionBytes = invoice.GenerateSignedTransactionFromSignatures(6).ToByteString()
            };

            var receipt = await client.SubmitUnsafeTransactionAsync(transaction.ToByteArray(), ctx => ctx.Payer = systemAddress);

            Assert.Equal(ResponseCode.Success, receipt.Status);
            Assert.Equal(txid, receipt.Id);
        }
Exemplo n.º 3
0
        public async Task SubmitUnsafeTransactionWithRecord()
        {
            await using var client = _network.NewClient();
            var systemAddress = await _network.GetSystemAccountAddress();

            if (systemAddress is null)
            {
                _network.Output?.WriteLine("TEST SKIPPED: No access to System Administrator Account.");
                return;
            }
            // Ok, lets build a TX from Scratch, Including a Signature
            var txid      = client.CreateNewTxId();
            var transfers = new Proto.TransferList();

            transfers.AccountAmounts.Add(new Proto.AccountAmount
            {
                AccountID = new Proto.AccountID(_network.Payer),
                Amount    = -1
            });
            transfers.AccountAmounts.Add(new Proto.AccountAmount
            {
                AccountID = new Proto.AccountID(_network.Gateway),
                Amount    = 1
            });
            var body = new Proto.TransactionBody
            {
                TransactionID            = new Proto.TransactionID(txid),
                NodeAccountID            = new Proto.AccountID(_network.Gateway),
                TransactionFee           = 30_00_000_000,
                TransactionValidDuration = new Proto.Duration {
                    Seconds = 180
                },
                Memo           = "Unsafe Test",
                CryptoTransfer = new Proto.CryptoTransferTransactionBody {
                    Transfers = transfers
                }
            };
            var invoice = new Invoice(body);

            await(_network.Signatory as ISignatory).SignAsync(invoice);
            var transaction = new Proto.Transaction
            {
                SignedTransactionBytes = invoice.GenerateSignedTransactionFromSignatures(6).ToByteString()
            };

            var record = await client.SubmitUnsafeTransactionWithRecordAsync(transaction.ToByteArray(), ctx => ctx.Payer = systemAddress);

            Assert.Equal(ResponseCode.Success, record.Status);
            Assert.Equal(txid, record.Id);
            Assert.False(record.Hash.IsEmpty);
            Assert.NotNull(record.Concensus);
            Assert.NotNull(record.CurrentExchangeRate);
            Assert.NotNull(record.NextExchangeRate);
            Assert.NotEmpty(record.Hash.ToArray());
            Assert.Equal("Unsafe Test", record.Memo);
            Assert.InRange(record.Fee, 0UL, ulong.MaxValue);
            Assert.Equal(_network.Payer, record.Id.Address);
            Assert.Equal(3, record.Transfers.Count);
            Assert.Equal(-1 - (long)record.Fee, record.Transfers[_network.Payer]);
        }
    }