Пример #1
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, 6);

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

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

        Assert.Equal(ResponseCode.Success, receipt.Status);
        Assert.Equal(txid, receipt.Id);
    }