|
1 | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | +#include "AccountId.h" |
| 3 | +#include "Client.h" |
| 4 | +#include "TransactionReceiptQuery.h" |
| 5 | +#include "TransactionRecordQuery.h" |
2 | 6 | #include "TransactionResponse.h" |
3 | 7 |
|
4 | 8 | #include <gtest/gtest.h> |
@@ -29,3 +33,50 @@ TEST_F(TransactionResponseUnitTests, ContructTransactionResponse) |
29 | 33 | EXPECT_EQ(transactionResponse.mTransactionId, transactionId); |
30 | 34 | EXPECT_EQ(transactionResponse.mTransactionNodeAccountIds, nodeAccountIds); |
31 | 35 | } |
| 36 | + |
| 37 | +//----- |
| 38 | +TEST_F(TransactionResponseUnitTests, GetReceiptQueryNullClientPinsToSubmittingNode) |
| 39 | +{ |
| 40 | + // Given |
| 41 | + const AccountId submittingNode(0ULL, 0ULL, 3ULL); |
| 42 | + const TransactionId txId = TransactionId::withValidStart(AccountId(1ULL), std::chrono::system_clock::now()); |
| 43 | + const TransactionResponse response(submittingNode, txId, {}, { submittingNode, AccountId(0ULL, 0ULL, 4ULL) }); |
| 44 | + |
| 45 | + // When / Then: no client → pinned to submitting node only |
| 46 | + EXPECT_EQ(response.getReceiptQuery(nullptr).getNodeAccountIds(), (std::vector<AccountId>{ submittingNode })); |
| 47 | +} |
| 48 | + |
| 49 | +//----- |
| 50 | +TEST_F(TransactionResponseUnitTests, GetReceiptQueryFailoverBuildsNodeListFromTransactionNodes) |
| 51 | +{ |
| 52 | + // Given: transaction nodes 3, 5, 4 (unsorted); submitting node is 3 |
| 53 | + const AccountId submittingNode(0ULL, 0ULL, 3ULL); |
| 54 | + const AccountId node4(0ULL, 0ULL, 4ULL); |
| 55 | + const AccountId node5(0ULL, 0ULL, 5ULL); |
| 56 | + const TransactionId txId = TransactionId::withValidStart(AccountId(1ULL), std::chrono::system_clock::now()); |
| 57 | + const TransactionResponse response(submittingNode, txId, {}, { submittingNode, node5, node4 }); |
| 58 | + |
| 59 | + Client client; |
| 60 | + client.setAllowReceiptNodeFailover(true); |
| 61 | + |
| 62 | + // When / Then: submitting node first, remaining sorted by account number ascending |
| 63 | + const std::vector<AccountId> expected = { submittingNode, node4, node5 }; |
| 64 | + EXPECT_EQ(response.getReceiptQuery(&client).getNodeAccountIds(), expected); |
| 65 | +} |
| 66 | + |
| 67 | +//----- |
| 68 | +TEST_F(TransactionResponseUnitTests, SingleFlagGovernsReceiptAndRecordQueryNodeList) |
| 69 | +{ |
| 70 | + // Given |
| 71 | + const AccountId submittingNode(0ULL, 0ULL, 3ULL); |
| 72 | + const AccountId node4(0ULL, 0ULL, 4ULL); |
| 73 | + const TransactionId txId = TransactionId::withValidStart(AccountId(1ULL), std::chrono::system_clock::now()); |
| 74 | + const TransactionResponse response(submittingNode, txId, {}, { submittingNode, node4 }); |
| 75 | + |
| 76 | + Client client; |
| 77 | + client.setAllowReceiptNodeFailover(true); |
| 78 | + |
| 79 | + // When / Then: same flag, same node list for both query types |
| 80 | + EXPECT_EQ(response.getReceiptQuery(&client).getNodeAccountIds(), |
| 81 | + response.getRecordQuery(&client).getNodeAccountIds()); |
| 82 | +} |
0 commit comments