Skip to content

Commit 854a0c9

Browse files
committed
fix: unit test rework
Signed-off-by: gsstoykov <[email protected]>
1 parent 9c374fa commit 854a0c9

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

src/sdk/tests/unit/ScheduleCreateTransactionUnitTests.cc

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -234,24 +234,33 @@ TEST_F(ScheduleCreateTransactionTests, GetSetWaitForExpiryFrozen)
234234
//-----
235235
TEST_F(ScheduleCreateTransactionTests, ToFromSchedulableTransactionBodyWithCustomFeeLimits)
236236
{
237-
// Create a TopicMessageSubmitTransaction with custom fee limits
238-
const TopicId topicId = TopicId::fromString("0.0.123");
239-
const std::string message = "test message";
240-
const AccountId payerId = AccountId::fromString("0.0.456");
237+
// Create an AccountAllowanceApproveTransaction which works properly with scheduling
238+
const AccountId ownerId = AccountId::fromString("0.0.123");
239+
const AccountId spenderId = AccountId::fromString("0.0.456");
240+
const Hbar amount = Hbar(50LL);
241+
const AccountId payerId = AccountId::fromString("0.0.789");
241242
const Hbar feeAmount = Hbar(10LL);
242243

243-
auto topicMessageTx = TopicMessageSubmitTransaction().setTopicId(topicId).setMessage(message);
244+
auto allowanceTx = AccountAllowanceApproveTransaction().approveHbarAllowance(ownerId, spenderId, amount);
244245

245-
// Add custom fee limit
246+
// Wrap the transaction to get access to protobuf methods
247+
WrappedTransaction tempWrappedTx(allowanceTx);
248+
249+
// Get the transaction body protobuf and manually add custom fee limits
250+
auto txBodyPtr = tempWrappedTx.toProtobuf();
251+
auto txBody = *txBodyPtr;
252+
253+
// Add custom fee limit manually to the transaction body
246254
CustomFeeLimit customFeeLimit;
247255
customFeeLimit.setPayerId(payerId);
248256
CustomFixedFee customFee;
249257
customFee.setAmount(static_cast<uint64_t>(feeAmount.toTinybars()));
250258
customFeeLimit.addCustomFee(customFee);
251-
topicMessageTx.addCustomFeeLimit(customFeeLimit);
259+
260+
txBody.mutable_max_custom_fees()->AddAllocated(customFeeLimit.toProtobuf().release());
252261

253-
// Wrap the transaction
254-
WrappedTransaction wrappedTx(topicMessageTx);
262+
// Create a new wrapped transaction from the modified transaction body
263+
WrappedTransaction wrappedTx = WrappedTransaction::fromProtobuf(txBody);
255264

256265
// Convert to SchedulableTransactionBody
257266
auto schedulableProto = wrappedTx.toSchedulableProtobuf();
@@ -261,13 +270,7 @@ TEST_F(ScheduleCreateTransactionTests, ToFromSchedulableTransactionBodyWithCusto
261270
EXPECT_TRUE(schedulableProto->max_custom_fees(0).has_account_id());
262271
EXPECT_EQ(schedulableProto->max_custom_fees(0).fees_size(), 1);
263272

264-
// For TopicMessageSubmitTransaction with our current implementation,
265-
// the fromProtobuf reconstruction may not work with source transaction bodies
266-
// that don't have the consensus submit message portion properly set.
267-
// This is expected behavior with our fix that prevents custom fee limit duplication.
268-
// A follow up PR will address this issue.
269-
270-
// Instead, verify that the schedulable protobuf itself contains the correct information
273+
// Verify that the schedulable protobuf contains the correct information
271274
const auto& feeLimit = schedulableProto->max_custom_fees(0);
272275
EXPECT_TRUE(feeLimit.has_account_id());
273276
EXPECT_EQ(AccountId::fromProtobuf(feeLimit.account_id()), payerId);
@@ -276,4 +279,7 @@ TEST_F(ScheduleCreateTransactionTests, ToFromSchedulableTransactionBodyWithCusto
276279
const auto& fee = feeLimit.fees(0);
277280
EXPECT_EQ(fee.amount(), static_cast<uint64_t>(feeAmount.toTinybars()));
278281
EXPECT_FALSE(fee.has_denominating_token_id()); // Should be HBAR (no token ID)
282+
283+
// Verify the transaction type is correct
284+
EXPECT_EQ(wrappedTx.getTransactionType(), TransactionType::ACCOUNT_ALLOWANCE_APPROVE_TRANSACTION);
279285
}

0 commit comments

Comments
 (0)