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
                    }
                }.AsTxId();
                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
 internal Hashgraph.TransactionReceipt ToTransactionReceipt(TransactionID transactionId)
 {
     if (AccountID != null)
     {
         return(FillProperties(transactionId, new CreateAccountReceipt()));
     }
     else if (FileID != null)
     {
         return(FillProperties(transactionId, new FileReceipt()));
     }
     else if (TopicID != null)
     {
         return(FillProperties(transactionId, new CreateTopicReceipt()));
     }
     else if (ContractID != null)
     {
         return(FillProperties(transactionId, new CreateContractReceipt()));
     }
     else if (TokenID != null)
     {
         return(FillProperties(transactionId, new CreateTokenReceipt()));
     }
     else if (NewTotalSupply != 0)
     {
         return(FillProperties(transactionId, new TokenReceipt()));
     }
     else if (!TopicRunningHash.IsEmpty)
     {
         return(FillProperties(transactionId, new SubmitMessageReceipt()));
     }
     else
     {
         return(FillProperties(transactionId, new Hashgraph.TransactionReceipt()));
     }
 }
Exemplo n.º 3
0
 internal SubmitMessageReceipt FillProperties(TransactionID transactionId, SubmitMessageReceipt receipt)
 {
     FillCommonProperties(transactionId, receipt);
     receipt.RunningHash        = TopicRunningHash?.ToByteArray();
     receipt.RunningHashVersion = TopicRunningHashVersion;
     receipt.SequenceNumber     = TopicSequenceNumber;
     return(receipt);
 }
Exemplo n.º 4
0
 internal TransactionBody(GossipContextStack context, TransactionID transactionId)
 {
     OnConstruction();
     TransactionID = transactionId;
     NodeAccountID = new AccountID(RequireInContext.Gateway(context));
     TransactionFee = (ulong)context.FeeLimit;
     TransactionValidDuration = new Proto.Duration(context.TransactionDuration);
     Memo = context.Memo ?? "";
 }
Exemplo n.º 5
0
 private void FillCommonProperties(TransactionID transactionId, Hashgraph.TransactionReceipt result)
 {
     result.Id     = transactionId.ToTxId();
     result.Status = (ResponseCode)Status;
     if (ExchangeRate != null)
     {
         result.CurrentExchangeRate = ExchangeRate.CurrentRate?.ToExchangeRate();
         result.NextExchangeRate    = ExchangeRate.NextRate?.ToExchangeRate();
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// Internal constructor for cases where a NetworkResult has not
 /// yet been constructed, for example when the receipt can no
 /// longer be found.
 /// </summary>
 internal TransactionException(string message, Proto.TransactionID transactionId, Proto.ResponseCodeEnum responseCode) : base(message)
 {
     Receipt = new NetworkResult
     {
         TransactionID = transactionId,
         Receipt       = new Proto.TransactionReceipt
         {
             Status = responseCode
         }
     }.ToReceipt();
 }
Exemplo n.º 7
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);
    }
Exemplo n.º 8
0
    public async Task RunTest()
    {
        await using var client = _network.NewClient();

        // 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()
        };

        using (new ConsoleRedirector(_network.Output))
        {
            var arg0 = _network.Gateway.Url;
            var arg1 = _network.Gateway.AccountNum.ToString();
            var arg2 = _network.Payer.AccountNum.ToString();
            var arg3 = Hex.FromBytes(_network.PrivateKey);
            var arg4 = Hex.FromBytes(transaction.ToByteArray());
            await Main(new string[] { arg0, arg1, arg2, arg3, arg4 });
        }
    }
}
Exemplo n.º 9
0
 private void FillCommonProperties(Hashgraph.TransactionRecord record)
 {
     record.Id             = TransactionID.ToTxId();
     record.Status         = (ResponseCode)Receipt.Status;
     record.Hash           = TransactionHash?.ToByteArray();
     record.Concensus      = ConsensusTimestamp?.ToDateTime();
     record.Memo           = Memo;
     record.Fee            = TransactionFee;
     record.Transfers      = TransferList.ToTransfers();
     record.TokenTransfers = TokenTransferLists.ToTransfers();
     if (Receipt.ExchangeRate != null)
     {
         record.CurrentExchangeRate = Receipt.ExchangeRate.CurrentRate?.ToExchangeRate();
         record.NextExchangeRate    = Receipt.ExchangeRate.NextRate?.ToExchangeRate();
     }
 }
Exemplo n.º 10
0
 internal CreateContractReceipt FillProperties(TransactionID transactionId, CreateContractReceipt receipt)
 {
     FillCommonProperties(transactionId, receipt);
     receipt.Contract = ContractID.ToAddress();
     return(receipt);
 }
Exemplo n.º 11
0
 internal TransactionGetRecordQuery(TransactionID transactionRecordId, bool includeDuplicates)
 {
     TransactionID     = transactionRecordId;
     IncludeDuplicates = includeDuplicates;
 }
Exemplo n.º 12
0
 internal Hashgraph.TransactionReceipt FillProperties(TransactionID transactionId, Hashgraph.TransactionReceipt result)
 {
     FillCommonProperties(transactionId, result);
     return(result);
 }
Exemplo n.º 13
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, 6);

        await(_network.Signatory as ISignatory).SignAsync(invoice);
        var transaction = new Proto.Transaction
        {
            SignedTransactionBytes = invoice.GenerateSignedTransactionFromSignatures().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]);
    }
}
Exemplo n.º 14
0
 internal TokenReceipt FillProperties(TransactionID transactionId, TokenReceipt receipt)
 {
     FillCommonProperties(transactionId, receipt);
     receipt.Circulation = NewTotalSupply;
     return(receipt);
 }
Exemplo n.º 15
0
 internal CreateTokenReceipt FillProperties(TransactionID transactionId, CreateTokenReceipt receipt)
 {
     FillCommonProperties(transactionId, receipt);
     receipt.Token = TokenID.ToAddress();
     return(receipt);
 }
Exemplo n.º 16
0
 internal FileReceipt FillProperties(TransactionID transactionId, FileReceipt receipt)
 {
     FillCommonProperties(transactionId, receipt);
     receipt.File = FileID.ToAddress();
     return(receipt);
 }
Exemplo n.º 17
0
        internal static ReadOnlyCollection <Hashgraph.TransactionReceipt> ToTransactionReceiptList(this RepeatedField <TransactionReceipt> list, TransactionReceipt first, TransactionID transactionId)
        {
            var count = (first != null ? 1 : 0) + (list != null ? list.Count : 0);

            if (count > 0)
            {
                var result = new List <Hashgraph.TransactionReceipt>(count);
                if (first != null)
                {
                    result.Add(first.ToTransactionReceipt(transactionId));
                }
                if (list != null && list.Count > 0)
                {
                    foreach (var entry in list)
                    {
                        result.Add(entry.ToTransactionReceipt(transactionId));
                    }
                }
                return(result.AsReadOnly());
            }
            return(EMPTY_RESULT);
        }
 internal TransactionGetReceiptQuery(TransactionID transactionId, bool includeDuplicates = false) : this()
 {
     TransactionID     = transactionId;
     IncludeDuplicates = includeDuplicates;
 }
Exemplo n.º 19
0
 internal CreateAccountReceipt FillProperties(TransactionID transactionId, CreateAccountReceipt receipt)
 {
     FillCommonProperties(transactionId, receipt);
     receipt.Address = AccountID.ToAddress();
     return(receipt);
 }