From 78928883799f13885369356bb67bc86923e7f676 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Mon, 28 Mar 2022 19:45:13 +0000 Subject: [PATCH] test: Improve gtest handling of `TransactionBuilderResult::GetTxOrThrow` We can't directly use `EXPECT_NO_THROW` on a function that returns a result; instead we manually call `GTEST_FAIL` if the builder result is an error. --- src/wallet/gtest/test_wallet.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/wallet/gtest/test_wallet.cpp b/src/wallet/gtest/test_wallet.cpp index d12e77595..d0c3fd997 100644 --- a/src/wallet/gtest/test_wallet.cpp +++ b/src/wallet/gtest/test_wallet.cpp @@ -834,7 +834,13 @@ TEST(WalletTests, GetConflictedOrchardNotes) { auto builder = TransactionBuilder(consensusParams, 1, orchardAnchor, &keystore); builder.AddTransparentInput(COutPoint(), scriptPubKey, 50000); builder.AddOrchardOutput(std::nullopt, recipient, 40000, {}); - auto tx = builder.Build().GetTxOrThrow(); + auto maybeTx = builder.Build(); + EXPECT_TRUE(maybeTx.IsTx()); + if (maybeTx.IsError()) { + std::cerr << "Failed to build transaction: " << maybeTx.GetError() << std::endl; + GTEST_FAIL(); + } + auto tx = maybeTx.GetTxOrThrow(); CWalletTx wtx {&wallet, tx}; // Fake-mine the transaction @@ -883,14 +889,26 @@ TEST(WalletTests, GetConflictedOrchardNotes) { auto noteToSpend = std::move(wallet.GetOrchardSpendInfo(orchardEntries)[0]); auto builder2 = TransactionBuilder(consensusParams, 2, orchardTree.root()); builder2.AddOrchardSpend(std::move(noteToSpend.first), std::move(noteToSpend.second)); - auto tx2 = builder2.Build().GetTxOrThrow(); + auto maybeTx2 = builder2.Build(); + EXPECT_TRUE(maybeTx2.IsTx()); + if (maybeTx2.IsError()) { + std::cerr << "Failed to build transaction: " << maybeTx2.GetError() << std::endl; + GTEST_FAIL(); + } + auto tx2 = maybeTx2.GetTxOrThrow(); CWalletTx wtx2 {&wallet, tx2}; // Generate conflicting tx to spend note A auto noteToSpend2 = std::move(wallet.GetOrchardSpendInfo(orchardEntries)[0]); auto builder3 = TransactionBuilder(consensusParams, 2, orchardTree.root()); builder3.AddOrchardSpend(std::move(noteToSpend2.first), std::move(noteToSpend2.second)); - auto tx3 = builder3.Build().GetTxOrThrow(); + auto maybeTx3 = builder3.Build(); + EXPECT_TRUE(maybeTx3.IsTx()); + if (maybeTx3.IsError()) { + std::cerr << "Failed to build transaction: " << maybeTx3.GetError() << std::endl; + GTEST_FAIL(); + } + auto tx3 = maybeTx3.GetTxOrThrow(); CWalletTx wtx3 {&wallet, tx3}; auto hash2 = wtx2.GetHash();