Skip to content

Commit 643e48a

Browse files
committed
carrot+fcmp: fix tx builder paramaters to multi-sweep functions and test multi-sweep
1 parent 0174cff commit 643e48a

File tree

2 files changed

+96
-2
lines changed

2 files changed

+96
-2
lines changed

src/wallet/tx_builder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ std::vector<carrot::CarrotTransactionProposalV1> make_carrot_transaction_proposa
528528
std::vector<carrot::InputCandidate> input_candidates = collect_carrot_input_candidate_list(transfers,
529529
subaddr_account,
530530
subaddr_indices,
531-
only_below,
531+
only_below ? only_below : MONEY_SUPPLY,
532532
0,
533533
top_block_index);
534534
std::vector<carrot::CarrotSelectedInput> selected_inputs;
@@ -552,7 +552,7 @@ std::vector<carrot::CarrotTransactionProposalV1> make_carrot_transaction_proposa
552552
std::move(selected_inputs),
553553
change_address_spend_pubkey,
554554
change_address_index,
555-
/*ignore_dust=*/false,
555+
/*ignore_dust=*/true,
556556
tx_proposals);
557557
return tx_proposals;
558558
}

tests/unit_tests/carrot_impl.cpp

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "carrot_core/output_set_finalization.h"
3535
#include "carrot_core/payment_proposal.h"
3636
#include "carrot_impl/format_utils.h"
37+
#include "carrot_impl/multi_tx_proposal_utils.h"
3738
#include "carrot_impl/tx_builder_outputs.h"
3839
#include "carrot_impl/tx_proposal_utils.h"
3940
#include "carrot_impl/input_selection.h"
@@ -1529,3 +1530,96 @@ TEST(carrot_impl, make_single_transfer_input_selector_greedy_aging_3)
15291530
ASSERT_EQ(std::set<size_t>({0, 1, 2, 4}), selected_input_indices);
15301531
}
15311532
//----------------------------------------------------------------------------------------------------------------------
1533+
TEST(carrot_impl, make_multiple_carrot_transaction_proposals_sweep_1)
1534+
{
1535+
// Taken from real function test
1536+
const rct::xmr_amount input_enote_amounts[] = {
1537+
35183466129983, 35183399022847, 35183331915839, 35183197702207, 35183130595583, 35183063489087,
1538+
35182996382719, 35182929276479, 35182862170367, 35182795064383, 35182727958527, 35182660852799,
1539+
35182593747199, 35182526641727, 35182459536383, 35182392431167, 35182325326078, 35182258221118,
1540+
35182191116286, 35182124011582, 35182056907006, 35181989802558, 35181922698238, 35181855594046,
1541+
35181788489981, 35181721386045, 35181654282237, 35181587178557, 35181520075005, 35181452971580,
1542+
35181385868284, 35181318765116, 35181251662076, 35181184559163, 35181117456379, 35181050353723,
1543+
35180983251195, 35180916148794, 35180849046522, 35180781944378, 35180714842361, 35180647740473,
1544+
35180580638713, 35180513537080, 35180446435576, 35180379334199, 35180312232951, 35180245131830,
1545+
35180178030838, 35180110929974, 35180043829237, 35179976728629, 35179909628148, 35179842527796,
1546+
35179775427571, 35179708327474, 35179641227506, 35179574127665, 35179507027953, 35179439928368,
1547+
35179372828911, 35179305729583, 35179238630382, 35179171531309, 35179104432365, 35179037333548,
1548+
35178970234859, 35178903136298, 35178836037865, 35178768939561, 35178701841384, 35178634743335,
1549+
35178567645414, 35178500547621, 35178433449956, 35178366352419, 35178299255010, 35178232157729,
1550+
35178165060576, 35178097963551, 35178030866654, 35177963769885, 35177896673244, 35177829576731,
1551+
35177762480346, 35177695384089, 35192149487959, 1000000000000, 69354088760000, 35192082391958,
1552+
69353820325310, 35192984896085, 1000000000000, 67052582291646, 35177427000340, 35191881104722,
1553+
69353283459006, 35177292809233, 35177225713872, 35177158618638, 35177091523533,
1554+
};
1555+
static constexpr std::size_t n_input_enote_amounts = sizeof(input_enote_amounts) / sizeof(input_enote_amounts[0]);
1556+
1557+
std::vector<carrot::CarrotSelectedInput> selected_inputs;
1558+
selected_inputs.reserve(n_input_enote_amounts);
1559+
for (std::size_t i = 0; i < n_input_enote_amounts; ++i)
1560+
{
1561+
selected_inputs.push_back(carrot::CarrotSelectedInput{
1562+
.amount = input_enote_amounts[i],
1563+
.input = gen_output_opening_hint()
1564+
});
1565+
}
1566+
1567+
std::unordered_map<crypto::public_key, std::size_t> expected_otas;
1568+
for (std::size_t i = 0; i < n_input_enote_amounts; ++i)
1569+
{
1570+
const carrot::CarrotSelectedInput &selected_input = selected_inputs.at(i);
1571+
expected_otas.emplace(onetime_address_ref(selected_input.input), i);
1572+
}
1573+
1574+
const carrot::CarrotPaymentProposalV1 normal_payment_proposal{
1575+
.destination = carrot::gen_carrot_main_address_v1(),
1576+
.amount = 0,
1577+
.randomness = carrot::gen_janus_anchor()
1578+
};
1579+
1580+
for (int ignore_dust = 0; ignore_dust <= 1; ++ignore_dust)
1581+
{
1582+
MDEBUG(typeid(*this).name() << ": ignore_dust=" << ignore_dust);
1583+
1584+
std::vector<carrot::CarrotTransactionProposalV1> tx_proposals;
1585+
make_multiple_carrot_transaction_proposals_sweep({normal_payment_proposal},
1586+
/*selfsend_payment_proposals=*/{},
1587+
/*fee_per_weight=*/20000,
1588+
/*extra=*/{},
1589+
std::vector<carrot::CarrotSelectedInput>(selected_inputs),
1590+
/*change_address_spend_pubkey=*/carrot::mock::gen_public_key(),
1591+
/*change_address_index=*/{},
1592+
ignore_dust,
1593+
tx_proposals);
1594+
1595+
const std::size_t n_expected_tx_proposals = (n_input_enote_amounts + FCMP_PLUS_PLUS_MAX_INPUTS - 1)
1596+
/ FCMP_PLUS_PLUS_MAX_INPUTS;
1597+
ASSERT_EQ(n_expected_tx_proposals, tx_proposals.size());
1598+
1599+
std::unordered_set<crypto::public_key> seen_ota;
1600+
for (const carrot::CarrotTransactionProposalV1 &tx_proposal : tx_proposals)
1601+
{
1602+
ASSERT_EQ(1, tx_proposal.normal_payment_proposals.size());
1603+
ASSERT_EQ(1, tx_proposal.selfsend_payment_proposals.size());
1604+
ASSERT_TRUE(tx_proposal.extra.empty());
1605+
1606+
carrot::CarrotPaymentProposalV1 modified_normal_payment_proposal = normal_payment_proposal;
1607+
modified_normal_payment_proposal.amount = tx_proposal.normal_payment_proposals.at(0).amount;
1608+
ASSERT_EQ(modified_normal_payment_proposal, tx_proposal.normal_payment_proposals.at(0));
1609+
1610+
boost::multiprecision::uint128_t input_amount_sum = 0;
1611+
for (const carrot::InputProposalV1 &input_proposal : tx_proposal.input_proposals)
1612+
{
1613+
const crypto::public_key ota = onetime_address_ref(input_proposal);
1614+
ASSERT_TRUE(expected_otas.count(ota));
1615+
ASSERT_FALSE(seen_ota.count(ota));
1616+
seen_ota.insert(ota);
1617+
input_amount_sum += input_enote_amounts[expected_otas.at(ota)];
1618+
}
1619+
1620+
ASSERT_EQ(input_amount_sum, tx_proposal.normal_payment_proposals.at(0).amount + tx_proposal.fee);
1621+
}
1622+
EXPECT_EQ(n_input_enote_amounts, seen_ota.size());
1623+
}
1624+
}
1625+
//----------------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)