From fccc66d84427b24a0539767e219d3675cb314e7d Mon Sep 17 00:00:00 2001 From: sasha Date: Wed, 20 Apr 2022 20:53:30 -0700 Subject: [PATCH] Port btest rpc_z_shieldcoinbase_internals to gtest suite WalletRPCTests --- src/wallet/gtest/test_rpc_wallet.cpp | 64 +++++++++++++++++++++++++++- src/wallet/test/rpc_wallet_tests.cpp | 56 ------------------------ 2 files changed, 63 insertions(+), 57 deletions(-) diff --git a/src/wallet/gtest/test_rpc_wallet.cpp b/src/wallet/gtest/test_rpc_wallet.cpp index f46662d0e..6425f4a1d 100644 --- a/src/wallet/gtest/test_rpc_wallet.cpp +++ b/src/wallet/gtest/test_rpc_wallet.cpp @@ -16,4 +16,66 @@ bool find_error(const UniValue& objError, const std::string& expected) { return find_value(objError, "message").get_str().find(expected) != string::npos; -} \ No newline at end of file +} + +TEST(WalletRPCTests,ZShieldCoinbaseInternals) +{ + LoadProofParameters(); + + SelectParams(CBaseChainParams::TESTNET); + const Consensus::Params& consensusParams = Params().GetConsensus(); + + // we need to use pwalletMain because of AsyncRPCOperation_shieldcoinbase + LoadGlobalWallet(); + { + LOCK2(cs_main, pwalletMain->cs_wallet); + + // Mutable tx containing contextual information we need to build tx + // We removed the ability to create pre-Sapling Sprout proofs, so we can + // only create Sapling-onwards transactions. + int nHeight = consensusParams.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight; + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(consensusParams, nHeight + 1); + + // Add keys manually + auto pa = pwalletMain->GenerateNewSproutZKey(); + + // Insufficient funds + { + std::vector inputs = { ShieldCoinbaseUTXO{uint256(),0,0} }; + std::shared_ptr operation(new AsyncRPCOperation_shieldcoinbase(TransactionBuilder(), mtx, inputs, pa) ); + operation->main(); + EXPECT_TRUE(operation->isFailed()); + std::string msg = operation->getErrorMessage(); + EXPECT_TRUE(msg.find("Insufficient coinbase funds") != string::npos); + } + + // Test the perform_joinsplit methods. + { + // Dummy input so the operation object can be instantiated. + std::vector inputs = { ShieldCoinbaseUTXO{uint256(),0,100000} }; + std::shared_ptr operation(new AsyncRPCOperation_shieldcoinbase(TransactionBuilder(), mtx, inputs, pa) ); + std::shared_ptr ptr = std::dynamic_pointer_cast (operation); + TEST_FRIEND_AsyncRPCOperation_shieldcoinbase proxy(ptr); + static_cast(operation.get())->testmode = true; + + ShieldCoinbaseJSInfo info; + info.vjsin.push_back(JSInput()); + info.vjsin.push_back(JSInput()); + info.vjsin.push_back(JSInput()); + try { + proxy.perform_joinsplit(info); + } catch (const std::runtime_error & e) { + EXPECT_TRUE(string(e.what()).find("unsupported joinsplit input")!= string::npos); + } + + info.vjsin.clear(); + try { + proxy.perform_joinsplit(info); + } catch (const std::runtime_error & e) { + EXPECT_TRUE(string(e.what()).find("error verifying joinsplit")!= string::npos); + } + } + + } + UnloadGlobalWallet(); +} diff --git a/src/wallet/test/rpc_wallet_tests.cpp b/src/wallet/test/rpc_wallet_tests.cpp index b10b88bfa..e1eda487e 100644 --- a/src/wallet/test/rpc_wallet_tests.cpp +++ b/src/wallet/test/rpc_wallet_tests.cpp @@ -1661,62 +1661,6 @@ BOOST_AUTO_TEST_CASE(rpc_z_shieldcoinbase_parameters) } } - -BOOST_AUTO_TEST_CASE(rpc_z_shieldcoinbase_internals) -{ - SelectParams(CBaseChainParams::TESTNET); - const Consensus::Params& consensusParams = Params().GetConsensus(); - - LOCK2(cs_main, pwalletMain->cs_wallet); - - // Mutable tx containing contextual information we need to build tx - // We removed the ability to create pre-Sapling Sprout proofs, so we can - // only create Sapling-onwards transactions. - int nHeight = consensusParams.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight; - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(consensusParams, nHeight + 1); - - // Add keys manually - auto pa = pwalletMain->GenerateNewSproutZKey(); - - // Insufficient funds - { - std::vector inputs = { ShieldCoinbaseUTXO{uint256(),0,0} }; - std::shared_ptr operation( new AsyncRPCOperation_shieldcoinbase(TransactionBuilder(), mtx, inputs, pa) ); - operation->main(); - BOOST_CHECK(operation->isFailed()); - std::string msg = operation->getErrorMessage(); - BOOST_CHECK( msg.find("Insufficient coinbase funds") != string::npos); - } - - // Test the perform_joinsplit methods. - { - // Dummy input so the operation object can be instantiated. - std::vector inputs = { ShieldCoinbaseUTXO{uint256(),0,100000} }; - std::shared_ptr operation( new AsyncRPCOperation_shieldcoinbase(TransactionBuilder(), mtx, inputs, pa) ); - std::shared_ptr ptr = std::dynamic_pointer_cast (operation); - TEST_FRIEND_AsyncRPCOperation_shieldcoinbase proxy(ptr); - static_cast(operation.get())->testmode = true; - - ShieldCoinbaseJSInfo info; - info.vjsin.push_back(JSInput()); - info.vjsin.push_back(JSInput()); - info.vjsin.push_back(JSInput()); - try { - proxy.perform_joinsplit(info); - } catch (const std::runtime_error & e) { - BOOST_CHECK( string(e.what()).find("unsupported joinsplit input")!= string::npos); - } - - info.vjsin.clear(); - try { - proxy.perform_joinsplit(info); - } catch (const std::runtime_error & e) { - BOOST_CHECK( string(e.what()).find("error verifying joinsplit")!= string::npos); - } - } - -} - BOOST_AUTO_TEST_CASE(rpc_z_mergetoaddress_parameters) { SelectParams(CBaseChainParams::TESTNET);