Skip to content

Commit

Permalink
Migration from Purple_Fenix upgrade to v5_dummy
Browse files Browse the repository at this point in the history
  • Loading branch information
furszy committed Oct 14, 2020
1 parent 7c8480c commit 6d49e6b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/test/librust/sapling_rpc_wallet_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ BOOST_AUTO_TEST_CASE(rpc_shielded_sendmany_taddr_to_sapling)
CScript scriptPubKey = CScript() << OP_DUP << OP_HASH160 << ToByteVector(tAddrKeyID) << OP_EQUALVERIFY << OP_CHECKSIG;
mtx.vout.push_back(CTxOut(5 * COIN, scriptPubKey));
CWalletTx wtx(pwalletMain, mtx);
pwalletMain->AddToWallet(wtx, true, nullptr);
pwalletMain->LoadToWallet(wtx);

// Fake-mine the transaction
BOOST_CHECK_EQUAL(0, chainActive.Height());
Expand All @@ -450,7 +450,7 @@ BOOST_AUTO_TEST_CASE(rpc_shielded_sendmany_taddr_to_sapling)
BOOST_CHECK(chainActive.Contains(&fakeIndex));
BOOST_CHECK_EQUAL(1, chainActive.Height());
wtx.SetMerkleBranch(block);
pwalletMain->AddToWallet(wtx, true, nullptr);
pwalletMain->LoadToWallet(wtx);

// Context that shielded_sendmany requires
auto builder = TransactionBuilder(consensusParams, nextBlockHeight, pwalletMain);
Expand Down
34 changes: 17 additions & 17 deletions src/test/librust/sapling_wallet_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ SaplingOutPoint CreateValidBlock(CWallet& wallet,
wallet, sk, 0, true);

auto saplingNotes = SetSaplingNoteData(wtx);
wallet.AddToWallet(wtx, true);
wallet.LoadToWallet(wtx);

block.vtx.emplace_back(MakeTransactionRef(wtx));
wallet.IncrementNoteWitnesses(&index, &block, saplingTree);
Expand Down Expand Up @@ -224,7 +224,7 @@ BOOST_AUTO_TEST_CASE(GetConflictedSaplingNotes) {
BOOST_CHECK(saplingNoteData.size() > 0);
wtx.SetSaplingNoteData(saplingNoteData);
wtx.SetMerkleBranch(mapBlockIndex[blockHash], 0);
BOOST_CHECK(wallet.AddToWallet(wtx, true));
BOOST_CHECK(wallet.LoadToWallet(wtx));

// Simulate receiving new block and ChainTip signal
wallet.IncrementNoteWitnesses(&fakeIndex, &block, saplingTree);
Expand Down Expand Up @@ -276,11 +276,11 @@ BOOST_AUTO_TEST_CASE(GetConflictedSaplingNotes) {
BOOST_CHECK_EQUAL(0, wallet.GetConflicts(hash3).size());

// No conflicts for one spend
BOOST_CHECK(wallet.AddToWallet(wtx2, true));
BOOST_CHECK(wallet.LoadToWallet(wtx2));
BOOST_CHECK_EQUAL(0, wallet.GetConflicts(hash2).size());

// Conflicts for two spends
BOOST_CHECK(wallet.AddToWallet(wtx3, true));
BOOST_CHECK(wallet.LoadToWallet(wtx3));
auto c3 = wallet.GetConflicts(hash2);
BOOST_CHECK_EQUAL(2, c3.size());
BOOST_CHECK(std::set<uint256>({hash2, hash3}) == c3);
Expand Down Expand Up @@ -340,7 +340,7 @@ BOOST_AUTO_TEST_CASE(SaplingNullifierIsSpent) {
BOOST_CHECK_EQUAL(0, chainActive.Height());

wtx.SetMerkleBranch(mapBlockIndex[blockHash], 0);
wallet.AddToWallet(wtx, true);
wallet.LoadToWallet(wtx);

// Verify note has been spent
BOOST_CHECK(wallet.GetSaplingScriptPubKeyMan()->IsSaplingSpent(nullifier));
Expand Down Expand Up @@ -404,7 +404,7 @@ BOOST_AUTO_TEST_CASE(NavigateFromSaplingNullifierToNote) {
auto saplingNoteData = wallet.GetSaplingScriptPubKeyMan()->FindMySaplingNotes(wtx).first;
BOOST_CHECK(saplingNoteData.size() > 0);
wtx.SetSaplingNoteData(saplingNoteData);
wallet.AddToWallet(wtx, true);
wallet.LoadToWallet(wtx);

// Verify dummy note is now spent, as AddToWallet invokes AddToSpends()
BOOST_CHECK(wallet.GetSaplingScriptPubKeyMan()->IsSaplingSpent(nullifier));
Expand Down Expand Up @@ -497,7 +497,7 @@ BOOST_AUTO_TEST_CASE(SpentSaplingNoteIsFromMe) {
BOOST_CHECK(saplingNoteData.size() > 0);
wtx.SetSaplingNoteData(saplingNoteData);
wtx.SetMerkleBranch(mapBlockIndex[blockHash], 0);
wallet.AddToWallet(wtx, true, NULL);
wallet.LoadToWallet(wtx);

// Simulate receiving new block and ChainTip signal.
// This triggers calculation of nullifiers for notes belonging to this wallet
Expand Down Expand Up @@ -571,7 +571,7 @@ BOOST_AUTO_TEST_CASE(SpentSaplingNoteIsFromMe) {
BOOST_CHECK(saplingNoteData2.size() > 0);
wtx2.SetSaplingNoteData(saplingNoteData2);
wtx2.SetMerkleBranch(mapBlockIndex[blockHash2], 0);
wallet.AddToWallet(wtx2, true, NULL);
wallet.LoadToWallet(wtx2);

// Verify note B is spent. AddToWallet invokes AddToSpends which updates mapTxSaplingNullifiers
BOOST_CHECK(wallet.GetSaplingScriptPubKeyMan()->IsSaplingSpent(nullifier2));
Expand Down Expand Up @@ -606,7 +606,7 @@ BOOST_AUTO_TEST_CASE(CachedWitnessesEmptyChain) {

BOOST_CHECK(!(bool) saplingWitnesses[0]);

wallet.AddToWallet(wtx, true, NULL);
wallet.LoadToWallet(wtx);

::GetWitnessesAndAnchors(wallet, saplingNotes, saplingWitnesses);

Expand Down Expand Up @@ -663,7 +663,7 @@ BOOST_AUTO_TEST_CASE(CachedWitnessesChainTip) {
wallet, sk, 50, true);

std::vector<SaplingOutPoint> saplingNotes = SetSaplingNoteData(wtx);
wallet.AddToWallet(wtx, true, NULL);
wallet.LoadToWallet(wtx);

std::vector<boost::optional<SaplingWitness>> saplingWitnesses;
GetWitnessesAndAnchors(wallet , saplingNotes, saplingWitnesses);
Expand Down Expand Up @@ -747,7 +747,7 @@ BOOST_AUTO_TEST_CASE(CachedWitnessesDecrementFirst) {
CWalletTx wtx = GetValidSaplingReceive(Params().GetConsensus(),
wallet, sk, 20, true);
std::vector<SaplingOutPoint> saplingNotes = SetSaplingNoteData(wtx);
wallet.AddToWallet(wtx, true, NULL);
wallet.LoadToWallet(wtx);

std::vector<boost::optional<SaplingWitness>> saplingWitnesses;

Expand Down Expand Up @@ -871,7 +871,7 @@ BOOST_AUTO_TEST_CASE(ClearNoteWitnessCache) {
wtx.mapSaplingNoteData[saplingNotes[0]].witnessHeight = 1;
wallet.GetSaplingScriptPubKeyMan()->nWitnessCacheSize = 1;

wallet.AddToWallet(wtx, true, NULL);
wallet.LoadToWallet(wtx);

// SetSaplingNoteData() only created a single Sapling output
// which is in the wallet, so we add a second SaplingOutPoint here to
Expand Down Expand Up @@ -949,7 +949,7 @@ BOOST_AUTO_TEST_CASE(UpdatedSaplingNoteData) {
BOOST_CHECK(saplingNoteData.size() == 1); // wallet only has key for change output
wtx.SetSaplingNoteData(saplingNoteData);
wtx.SetMerkleBranch(mapBlockIndex[blockHash], 0);
wallet.AddToWallet(wtx, true, NULL);
wallet.LoadToWallet(wtx);

// Simulate receiving new block and ChainTip signal
wallet.IncrementNoteWitnesses(&fakeIndex, &block, testNote.tree);
Expand Down Expand Up @@ -1063,7 +1063,7 @@ BOOST_AUTO_TEST_CASE(MarkAffectedSaplingTransactionsDirty) {
BOOST_CHECK(saplingNoteData.size() > 0);
wtx.SetSaplingNoteData(saplingNoteData);
wtx.SetMerkleBranch(mapBlockIndex[blockHash], 0);
wallet.AddToWallet(wtx, true, NULL);
wallet.LoadToWallet(wtx);

// Simulate receiving new block and ChainTip signal
wallet.IncrementNoteWitnesses(&fakeIndex, &block, saplingTree);
Expand Down Expand Up @@ -1103,12 +1103,12 @@ BOOST_AUTO_TEST_CASE(MarkAffectedSaplingTransactionsDirty) {

// After getting a cached value, the first tx should be clean
wallet.mapWallet[hash].GetDebit(ISMINE_ALL);
BOOST_CHECK(wallet.mapWallet[hash].fDebitCached);
BOOST_CHECK(wallet.mapWallet[hash].GetDebit(ISMINE_SPENDABLE));

// After adding the note spend, the first tx should be dirty
wallet.AddToWallet(wtx2, true, NULL);
wallet.LoadToWallet(wtx2);
wallet.MarkAffectedTransactionsDirty(wtx2);
BOOST_CHECK(!wallet.mapWallet[hash].fDebitCached);
BOOST_CHECK(!wallet.mapWallet[hash].GetDebit(ISMINE_SPENDABLE));

// Tear down
chainActive.SetTip(NULL);
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ void CWallet::SetBestChainInternal(CWalletDB& walletdb, const CBlockLocator& loc
return;
}

if (!walletdb.WriteTx(wtxItem.first, wtx)) {
if (!walletdb.WriteTx(wtx)) {
LogPrintf("SetBestChain(): Failed to write CWalletTx, aborting atomic write\n");
walletdb.TxnAbort();
return;
Expand Down

0 comments on commit 6d49e6b

Please sign in to comment.