Skip to content

Commit aaab8b6

Browse files
committed
Added tests for the failover
Signed-off-by: Aditya Arya <arya050411@gmail.com>
1 parent 2363a93 commit aaab8b6

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

src/sdk/main/include/TransactionResponse.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class TransactionResponse
4545
TransactionResponse(AccountId nodeId,
4646
TransactionId transactionId,
4747
std::vector<std::byte> hash,
48-
std::vector<AccountId> transactionNodeAccountIds);
48+
std::vector<AccountId> transactionNodeAccountIds = {});
4949

5050
/**
5151
* Get a TransactionReceipt for this TransactionResponse's corresponding Transaction.

src/sdk/tests/unit/TransactionResponseUnitTests.cc

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
// SPDX-License-Identifier: Apache-2.0
2+
#include "AccountId.h"
3+
#include "Client.h"
4+
#include "TransactionReceiptQuery.h"
5+
#include "TransactionRecordQuery.h"
26
#include "TransactionResponse.h"
37

48
#include <gtest/gtest.h>
@@ -29,3 +33,50 @@ TEST_F(TransactionResponseUnitTests, ContructTransactionResponse)
2933
EXPECT_EQ(transactionResponse.mTransactionId, transactionId);
3034
EXPECT_EQ(transactionResponse.mTransactionNodeAccountIds, nodeAccountIds);
3135
}
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

Comments
 (0)