Skip to content

Commit

Permalink
Unit tests fix
Browse files Browse the repository at this point in the history
  • Loading branch information
psolstice committed Oct 6, 2021
1 parent 3747c46 commit d68f433
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 70 deletions.
6 changes: 0 additions & 6 deletions src/test/lelantus_mintspend_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ BOOST_AUTO_TEST_CASE(lelantus_mintspend_test)
{GetScriptForDestination(randomAddr.Get()), 30 * COIN, true},
};

// Add 1 more blocks and verify that Mint can not be spent until 2blocks verification
{
CWalletTx wtx;
BOOST_CHECK_THROW(pwalletMain->JoinSplitLelantus(recipients, {}, wtx), WalletError); //this must throw as it has to have at least two mint coins with at least 2 confirmation
}

GenerateBlock({});

BOOST_CHECK_MESSAGE(previousHeight + 1 == chainActive.Height(), "Block not added to chain");
Expand Down
8 changes: 6 additions & 2 deletions src/test/sigma_lelantus_transition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ BOOST_AUTO_TEST_CASE(sigma_lelantus_transition_test)
BOOST_CHECK_MESSAGE(mempool.size() == 0, "Mints were not removed from mempool");
GenerateBlocks(6);
recipients = {
{GetScriptForDestination(randomAddr.Get()), 100 * COIN, true},
{GetScriptForDestination(randomAddr.Get()), 105 * COIN, true},
};
wtx.Init(NULL);
BOOST_CHECK_NO_THROW(pwalletMain->JoinSplitLelantus(recipients, {}, wtx));
Expand All @@ -121,6 +121,7 @@ BOOST_AUTO_TEST_CASE(sigma_lelantus_transition_test)
GenerateBlock({CMutableTransaction(*wtx.tx)});
BOOST_CHECK_MESSAGE(previousHeight + 1 == chainActive.Height(), "Block not added to chain");
BOOST_CHECK_MESSAGE(mempool.size() == 0, "JoinSplit is not removed from mempool");
int joinSplitHeight = chainActive.Height();

coins = pwalletMain->GetAvailableCoins(nullptr, false);
BOOST_CHECK_MESSAGE(coins.size() == 0, "All sigma coins should be marked used, but something went wrong");
Expand All @@ -132,7 +133,10 @@ BOOST_AUTO_TEST_CASE(sigma_lelantus_transition_test)
GenerateBlocks(6);

auto currentLelantusCoins = pwalletMain->GetAvailableLelantusCoins(nullptr, false);
BOOST_CHECK_MESSAGE(currentLelantusCoins.size() > lelantusCoins.size(), "Newly created jmint should be marked as spendable, but something went wrong");
// There should be a mint with height equal to join split height in list of available lelantus coins
BOOST_CHECK_MESSAGE(std::find_if(currentLelantusCoins.begin(), currentLelantusCoins.end(),
[=](const CLelantusEntry &coin) { return coin.nHeight == joinSplitHeight; }) != currentLelantusCoins.end(),
"Newly created jmint should be marked as spendable, but something went wrong");

mempool.clear();
sigma::CSigmaState::GetState()->Reset();
Expand Down
3 changes: 0 additions & 3 deletions src/test/sigma_manymintspend_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@ BOOST_AUTO_TEST_CASE(sigma_mintspend_many)


previousHeight = chainActive.Height();
//Add 1 more blocks and verify that Mint can not be spent until 2 blocks verification
wtx.Init(NULL);
BOOST_CHECK_THROW(pwalletMain->SpendSigma(recipients, wtx), WalletError); //this must throw as 2 blocks have not passed yet,

b = CreateAndProcessBlock(scriptPubKey);
wtx.Init(NULL);
Expand Down
5 changes: 0 additions & 5 deletions src/test/sigma_mintspend_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,6 @@ BOOST_AUTO_TEST_CASE(sigma_mintspend_test)


previousHeight = chainActive.Height();
//Add 1 more blocks and verify that Mint can not be spent until 2 blocks verification
{
CWalletTx wtx;
BOOST_CHECK_THROW(pwalletMain->SpendSigma(recipients, wtx), WalletError); //this must throw as 2 blocks have not passed yet,
}
b = CreateAndProcessBlock(scriptPubKey);

BOOST_CHECK_MESSAGE(previousHeight + 1 == chainActive.Height(), "Block not added to chain");
Expand Down
54 changes: 0 additions & 54 deletions src/wallet/test/sigma_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,25 +324,6 @@ BOOST_AUTO_TEST_CASE(get_coin_not_enough)
sigmaState->Reset();
}

BOOST_AUTO_TEST_CASE(get_coin_cannot_spend_unconfirmed_coins)
{
AddOneCoinForEachGroup();
std::vector<std::pair<sigma::CoinDenomination, int>> newCoins;
GetCoinSetByDenominationAmount(newCoins, 1, 1, 1, 1, 1, 1, 1);
GenerateBlockWithCoins(newCoins);
// Intentionally do not create 5 more blocks after this one, so coins can not be spent.
// GenerateEmptyBlocks(5);

CAmount require(11150 * CENT); // 111.5

std::vector<CSigmaEntry> coins;
std::vector<sigma::CoinDenomination> coinsToMint;
std::list<CSigmaEntry> availableCoins = pwalletMain->GetAvailableCoins();

BOOST_CHECK_THROW(pwalletMain->GetCoinsToSpend(require, coins, coinsToMint, availableCoins), InsufficientFunds);
sigmaState->Reset();
}

BOOST_AUTO_TEST_CASE(get_coin_minimize_coins_spend_fit_amount)
{
std::vector<std::pair<sigma::CoinDenomination, int>> newCoins;
Expand Down Expand Up @@ -477,41 +458,6 @@ BOOST_AUTO_TEST_CASE(create_spend_with_insufficient_coins)
sigmaState->Reset();
}

BOOST_AUTO_TEST_CASE(create_spend_with_confirmation_less_than_6)
{
CAmount fee;
std::vector<CSigmaEntry> selected;
std::vector<CHDMint> changes;
std::vector<CRecipient> recipients;

GenerateBlockWithCoins({ std::make_pair(sigma::CoinDenomination::SIGMA_DENOM_10, 2) });

recipients.push_back(CRecipient{
.scriptPubKey = GetScriptForDestination(randomAddr1.Get()),
.nAmount = 5 * COIN,
.fSubtractFeeFromAmount = false
});

recipients.push_back(CRecipient{
.scriptPubKey = GetScriptForDestination(randomAddr2.Get()),
.nAmount = 5 * COIN,
.fSubtractFeeFromAmount = false
});

recipients.push_back(CRecipient{
.scriptPubKey = GetScriptForDestination(randomAddr3.Get()),
.nAmount = 1 * COIN,
.fSubtractFeeFromAmount = false
});

bool fChangeAddedToFee;
BOOST_CHECK_EXCEPTION(
pwalletMain->CreateSigmaSpendTransaction(recipients, fee, selected, changes, fChangeAddedToFee),
InsufficientFunds,
[](const InsufficientFunds& e) { return e.what() == std::string("Insufficient funds"); });
sigmaState->Reset();
}

BOOST_AUTO_TEST_CASE(create_spend_with_coins_less_than_2)
{
CAmount fee;
Expand Down

0 comments on commit d68f433

Please sign in to comment.