rename: encrypt_attachments() -> encrypt_payload_items() + test gen_wallet_decrypted_attachments -> gen_wallet_decrypted_payload_items improved (tx_comment put in extra)
This commit is contained in:
parent
1b0f64176d
commit
46eab64834
6 changed files with 35 additions and 36 deletions
|
|
@ -1784,7 +1784,7 @@ namespace currency
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
void encrypt_attachments(transaction& tx, const account_keys& sender_keys, const account_public_address& destination_addr, const keypair& tx_random_key, crypto::key_derivation& derivation)
|
||||
void encrypt_payload_items(transaction& tx, const account_keys& sender_keys, const account_public_address& destination_addr, const keypair& tx_random_key, crypto::key_derivation& derivation)
|
||||
{
|
||||
bool r = crypto::generate_key_derivation(destination_addr.view_public_key, tx_random_key.sec, derivation);
|
||||
CHECK_AND_ASSERT_MES(r, void(), "failed to generate_key_derivation");
|
||||
|
|
@ -1816,10 +1816,10 @@ namespace currency
|
|||
}
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
void encrypt_attachments(transaction& tx, const account_keys& sender_keys, const account_public_address& destination_addr, const keypair& tx_random_key)
|
||||
void encrypt_payload_items(transaction& tx, const account_keys& sender_keys, const account_public_address& destination_addr, const keypair& tx_random_key)
|
||||
{
|
||||
crypto::key_derivation derivation = AUTO_VAL_INIT(derivation);
|
||||
return encrypt_attachments(tx, sender_keys, destination_addr, tx_random_key, derivation);
|
||||
return encrypt_payload_items(tx, sender_keys, destination_addr, tx_random_key, derivation);
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
void load_wallet_transfer_info_flags(tools::wallet_public::wallet_transfer_info& x)
|
||||
|
|
@ -2582,7 +2582,7 @@ namespace currency
|
|||
|
||||
//include offers if need
|
||||
tx.attachment = attachments;
|
||||
encrypt_attachments(tx, sender_account_keys, crypt_destination_addr, gen_context.tx_key, result.derivation);
|
||||
encrypt_payload_items(tx, sender_account_keys, crypt_destination_addr, gen_context.tx_key, result.derivation);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -396,8 +396,8 @@ namespace currency
|
|||
bool is_tx_spendtime_unlocked(uint64_t unlock_time, uint64_t current_blockchain_size, uint64_t current_time);
|
||||
crypto::key_derivation get_encryption_key_derivation(bool is_income, const transaction& tx, const account_keys& acc_keys);
|
||||
bool decrypt_payload_items(bool is_income, const transaction& tx, const account_keys& acc_keys, std::vector<payload_items_v>& decrypted_items);
|
||||
void encrypt_attachments(transaction& tx, const account_keys& sender_keys, const account_public_address& destination_addr, const keypair& tx_random_key, crypto::key_derivation& derivation);
|
||||
void encrypt_attachments(transaction& tx, const account_keys& sender_keys, const account_public_address& destination_addr, const keypair& tx_random_key);
|
||||
void encrypt_payload_items(transaction& tx, const account_keys& sender_keys, const account_public_address& destination_addr, const keypair& tx_random_key, crypto::key_derivation& derivation);
|
||||
void encrypt_payload_items(transaction& tx, const account_keys& sender_keys, const account_public_address& destination_addr, const keypair& tx_random_key);
|
||||
bool is_derivation_used_to_encrypt(const transaction& tx, const crypto::key_derivation& derivation);
|
||||
bool is_address_like_wrapped(const std::string& addr);
|
||||
void load_wallet_transfer_info_flags(tools::wallet_public::wallet_transfer_info& x);
|
||||
|
|
|
|||
|
|
@ -1356,12 +1356,14 @@ void append_vector_by_another_vector(U& dst, const V& src)
|
|||
|
||||
#define MAKE_TX_LIST_START_WITH_ATTACHS(VEC_EVENTS, SET_NAME, FROM, TO, AMOUNT, HEAD, ATTACHS) MAKE_TX_LIST_START_MIX_ATTR(VEC_EVENTS, SET_NAME, FROM, TO, AMOUNT, HEAD, CURRENCY_TO_KEY_OUT_RELAXED, ATTACHS)
|
||||
|
||||
#define MAKE_TX_ATTACH_FEE(EVENTS, TX_VAR, FROM, TO, AMOUNT, FEE, HEAD, ATTACH) \
|
||||
PRINT_EVENT_N(EVENTS); \
|
||||
currency::transaction TX_VAR = AUTO_VAL_INIT(TX_VAR); \
|
||||
CHECK_AND_ASSERT_MES(construct_tx_to_key(generator.get_hardforks(), EVENTS, TX_VAR, HEAD, FROM, TO, AMOUNT, FEE, 0, generator.last_tx_generated_secret_key, CURRENCY_TO_KEY_OUT_RELAXED, empty_extra, ATTACH), false, "construct_tx_to_key failed"); \
|
||||
#define MAKE_TX_EXTRA_ATTACH_FEE(EVENTS, TX_VAR, FROM, TO, AMOUNT, FEE, HEAD, EXTRA, ATTACH) \
|
||||
PRINT_EVENT_N(EVENTS); \
|
||||
currency::transaction TX_VAR{}; \
|
||||
CHECK_AND_ASSERT_MES(construct_tx_to_key(generator.get_hardforks(), EVENTS, TX_VAR, HEAD, FROM, TO, AMOUNT, FEE, 0, generator.last_tx_generated_secret_key, CURRENCY_TO_KEY_OUT_RELAXED, EXTRA, ATTACH), false, "construct_tx_to_key failed"); \
|
||||
EVENTS.push_back(TX_VAR)
|
||||
|
||||
#define MAKE_TX_ATTACH_FEE(EVENTS, TX_VAR, FROM, TO, AMOUNT, FEE, HEAD, ATTACH) MAKE_TX_EXTRA_ATTACH_FEE(EVENTS, TX_VAR, FROM, TO, AMOUNT, FEE, HEAD, empty_extra, ATTACH)
|
||||
|
||||
#define MAKE_TX_ATTACH(EVENTS, TX_VAR, FROM, TO, AMOUNT, HEAD, ATTACH) MAKE_TX_ATTACH_FEE(EVENTS, TX_VAR, FROM, TO, AMOUNT, TESTS_DEFAULT_FEE, HEAD, ATTACH)
|
||||
|
||||
#define MAKE_MINER_TX_AND_KEY_MANUALLY(TX, PREV_BLOCK, P_KEYPAIR) \
|
||||
|
|
@ -1417,30 +1419,25 @@ void append_vector_by_another_vector(U& dst, const V& src)
|
|||
|
||||
#define MAKE_TEST_WALLET_TX(EVENTS_VEC, TX_VAR, WLT_WAR, MONEY, DEST_ACC) \
|
||||
PRINT_EVENT_N(EVENTS_VEC); \
|
||||
transaction TX_VAR = AUTO_VAL_INIT(TX_VAR); \
|
||||
transaction TX_VAR{}; \
|
||||
{ \
|
||||
std::vector<tx_destination_entry> destinations(1, tx_destination_entry(MONEY, DEST_ACC.get_public_address())); \
|
||||
WLT_WAR->transfer(destinations, 0, 0, TESTS_DEFAULT_FEE, std::vector<extra_v>(), std::vector<attachment_v>(), TX_VAR); \
|
||||
} \
|
||||
EVENTS_VEC.push_back(TX_VAR)
|
||||
|
||||
#define MAKE_TEST_WALLET_TX_ATTACH(EVENTS_VEC, TX_VAR, WLT_WAR, MONEY, DEST_ACC, ATTACH) \
|
||||
#define MAKE_TEST_WALLET_TX_EXTRA_ATTACH(EVENTS_VEC, TX_VAR, WLT_WAR, MONEY, DEST_ACC, EXTRA, ATTACH) \
|
||||
PRINT_EVENT_N(EVENTS_VEC); \
|
||||
transaction TX_VAR = AUTO_VAL_INIT(TX_VAR); \
|
||||
transaction TX_VAR{}; \
|
||||
{ \
|
||||
std::vector<tx_destination_entry> destinations(1, tx_destination_entry(MONEY, DEST_ACC.get_public_address())); \
|
||||
WLT_WAR->transfer(destinations, 0, 0, TESTS_DEFAULT_FEE, std::vector<extra_v>(), ATTACH, TX_VAR); \
|
||||
WLT_WAR->transfer(destinations, 0, 0, TESTS_DEFAULT_FEE, EXTRA, ATTACH, TX_VAR); \
|
||||
} \
|
||||
EVENTS_VEC.push_back(TX_VAR)
|
||||
|
||||
#define MAKE_TEST_WALLET_TX_EXTRA(EVENTS_VEC, TX_VAR, WLT_WAR, MONEY, DEST_ACC, EXTRA) \
|
||||
PRINT_EVENT_N(EVENTS_VEC); \
|
||||
transaction TX_VAR = AUTO_VAL_INIT(TX_VAR); \
|
||||
{ \
|
||||
std::vector<tx_destination_entry> destinations(1, tx_destination_entry(MONEY, DEST_ACC.get_public_address())); \
|
||||
WLT_WAR->transfer(destinations, 0, 0, TESTS_DEFAULT_FEE, EXTRA, std::vector<attachment_v>(), TX_VAR); \
|
||||
} \
|
||||
EVENTS_VEC.push_back(TX_VAR)
|
||||
#define MAKE_TEST_WALLET_TX_ATTACH(EVENTS_VEC, TX_VAR, WLT_WAR, MONEY, DEST_ACC, ATTACH) MAKE_TEST_WALLET_TX_EXTRA_ATTACH(EVENTS_VEC, TX_VAR, WLT_WAR, MONEY, DEST_ACC, empty_extra, ATTACH)
|
||||
|
||||
#define MAKE_TEST_WALLET_TX_EXTRA(EVENTS_VEC, TX_VAR, WLT_WAR, MONEY, DEST_ACC, EXTRA) MAKE_TEST_WALLET_TX_EXTRA_ATTACH(EVENTS_VEC, TX_VAR, WLT_WAR, MONEY, DEST_ACC, EXTRA, empty_attachment)
|
||||
|
||||
#define CHECK_TEST_WALLET_BALANCE_AT_GEN_TIME(WLT_WAR, TOTAL_BALANCE) \
|
||||
if (!check_balance_via_wallet(*WLT_WAR.get(), #WLT_WAR, TOTAL_BALANCE)) \
|
||||
|
|
|
|||
|
|
@ -1077,7 +1077,7 @@ int main(int argc, char* argv[])
|
|||
GENERATE_AND_PLAY(gen_wallet_oversized_payment_id);
|
||||
GENERATE_AND_PLAY(gen_wallet_transfers_and_outdated_unconfirmed_txs);
|
||||
GENERATE_AND_PLAY(gen_wallet_transfers_and_chain_switch);
|
||||
GENERATE_AND_PLAY(gen_wallet_decrypted_attachments);
|
||||
GENERATE_AND_PLAY(gen_wallet_decrypted_payload_items);
|
||||
GENERATE_AND_PLAY_HF(gen_wallet_alias_and_unconfirmed_txs, "3-*");
|
||||
GENERATE_AND_PLAY_HF(gen_wallet_alias_via_special_wallet_funcs, "3-*");
|
||||
GENERATE_AND_PLAY(gen_wallet_fake_outputs_randomness);
|
||||
|
|
|
|||
|
|
@ -1443,14 +1443,14 @@ bool gen_wallet_transfers_and_chain_switch::generate(std::vector<test_event_entr
|
|||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
gen_wallet_decrypted_attachments::gen_wallet_decrypted_attachments()
|
||||
gen_wallet_decrypted_payload_items::gen_wallet_decrypted_payload_items()
|
||||
: m_on_transfer2_called(false)
|
||||
{
|
||||
m_hardforks.set_hardfork_height(1, 0);
|
||||
m_hardforks.set_hardfork_height(2, 0); // tx_payer requires HF2
|
||||
}
|
||||
|
||||
bool gen_wallet_decrypted_attachments::generate(std::vector<test_event_entry>& events) const
|
||||
bool gen_wallet_decrypted_payload_items::generate(std::vector<test_event_entry>& events) const
|
||||
{
|
||||
// Test outline
|
||||
// NOTE: All transactions are sending with same attachments: tx_payer, tx_comment and tx_message
|
||||
|
|
@ -1508,16 +1508,18 @@ bool gen_wallet_decrypted_attachments::generate(std::vector<test_event_entry>& e
|
|||
// that feeling when you are a bit paranoid
|
||||
std::vector<currency::payload_items_v> decrypted_attachments;
|
||||
currency::keypair k = currency::keypair::generate();
|
||||
transaction t = AUTO_VAL_INIT(t);
|
||||
t.attachment = std::vector<currency::attachment_v>({ a_tx_payer, a_tx_comment, a_tx_message });
|
||||
transaction t{};
|
||||
t.attachment.push_back(a_tx_payer);
|
||||
t.attachment.push_back(a_tx_message);
|
||||
t.extra.push_back(a_tx_comment);
|
||||
add_tx_pub_key_to_extra(t, k.pub);
|
||||
add_attachments_info_to_extra(t.extra, t.attachment);
|
||||
currency::encrypt_attachments(t, miner_acc.get_keys(), alice_acc.get_public_address(), k);
|
||||
currency::encrypt_payload_items(t, miner_acc.get_keys(), alice_acc.get_public_address(), k);
|
||||
bool r = currency::decrypt_payload_items(true, t, alice_acc.get_keys(), decrypted_attachments);
|
||||
CHECK_AND_ASSERT_MES(r, false, "encrypt_attachments + decrypt_attachments failed to work together");
|
||||
CHECK_AND_ASSERT_MES(r, false, "encrypt_payload_items + decrypt_attachments failed to work together");
|
||||
}
|
||||
|
||||
MAKE_TX_ATTACH(events, tx_0, miner_acc, alice_acc, MK_TEST_COINS(10000), blk_0r, std::vector<currency::attachment_v>({ a_tx_payer, a_tx_comment, a_tx_message }));
|
||||
MAKE_TX_EXTRA_ATTACH_FEE(events, tx_0, miner_acc, alice_acc, MK_TEST_COINS(10000), TESTS_DEFAULT_FEE, blk_0r, std::vector<currency::payload_items_v>({ a_tx_comment }), std::vector<currency::payload_items_v>({ a_tx_payer, a_tx_message }));
|
||||
MAKE_NEXT_BLOCK(events, blk_1, blk_0r, miner_acc); // don't put tx_0 into this block, the block is only necessary to trigger tx_pool scan on in wallet2::refresh()
|
||||
|
||||
// wallet callback must be passed as shared_ptr, so to avoid deleting "this" construct shared_ptr with custom null-deleter
|
||||
|
|
@ -1540,7 +1542,7 @@ bool gen_wallet_decrypted_attachments::generate(std::vector<test_event_entry>& e
|
|||
// Do the same in opposite direction: alice -> miner. Unlock money, received by Alice first.
|
||||
REWIND_BLOCKS_N(events, blk_2r, blk_2, miner_acc, WALLET_DEFAULT_TX_SPENDABLE_AGE);
|
||||
|
||||
MAKE_TX_ATTACH(events, tx_1, alice_acc, miner_acc, MK_TEST_COINS(100), blk_2r, std::vector<currency::attachment_v>({ a_tx_payer, a_tx_comment, a_tx_message }));
|
||||
MAKE_TX_EXTRA_ATTACH_FEE(events, tx_1, alice_acc, miner_acc, MK_TEST_COINS(100), TESTS_DEFAULT_FEE, blk_2r, std::vector<currency::payload_items_v>({ a_tx_comment }), std::vector<currency::payload_items_v>({ a_tx_payer, a_tx_message }));
|
||||
MAKE_NEXT_BLOCK(events, blk_3, blk_2r, miner_acc); // don't put tx_1 into this block, the block is only necessary to trigger tx_pool scan on in wallet2::refresh()
|
||||
|
||||
// Spend tx was not sent via Alice wallet instance, so wallet can't obtain destination address and pass it to callback (although, it decrypts attachments & extra)
|
||||
|
|
@ -1573,7 +1575,7 @@ bool gen_wallet_decrypted_attachments::generate(std::vector<test_event_entry>& e
|
|||
m_comment_to_be_checked = a_tx_comment.comment;
|
||||
m_address_to_be_checked = get_account_address_as_str(bob_acc.get_public_address()); // note, that a_tx_payer is NOT refering to Bob's account, but in the callback we should get correct sender addr
|
||||
m_on_transfer2_called = false;
|
||||
MAKE_TEST_WALLET_TX_ATTACH(events, tx_2, alice_wlt, MK_TEST_COINS(2000), bob_acc, std::vector<currency::attachment_v>({ a_tx_payer, a_tx_comment, a_tx_message }));
|
||||
MAKE_TEST_WALLET_TX_EXTRA_ATTACH(events, tx_2, alice_wlt, MK_TEST_COINS(2000), bob_acc, std::vector<currency::extra_v>({ a_tx_comment }), std::vector<currency::attachment_v>({ a_tx_payer, a_tx_message }));
|
||||
CHECK_AND_ASSERT_MES(m_on_transfer2_called, false, "on_transfer2() was not called (5)");
|
||||
|
||||
MAKE_NEXT_BLOCK(events, blk_5, blk_4r, miner_acc); // don't put tx_2 into this block, the block is only necessary to trigger tx_pool scan on in wallet2::refresh()
|
||||
|
|
@ -1595,7 +1597,7 @@ bool gen_wallet_decrypted_attachments::generate(std::vector<test_event_entry>& e
|
|||
REFRESH_TEST_WALLET_AT_GEN_TIME(events, bob_wlt, blk_6r, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 2 + WALLET_DEFAULT_TX_SPENDABLE_AGE + 2 + WALLET_DEFAULT_TX_SPENDABLE_AGE + 2 + WALLET_DEFAULT_TX_SPENDABLE_AGE);
|
||||
|
||||
a_tx_payer.acc_addr = bob_acc.get_public_address(); // here we specify correct payer address, as it will not be masked by wallet
|
||||
MAKE_TEST_WALLET_TX_ATTACH(events, tx_3, bob_wlt, MK_TEST_COINS(200), alice_acc, std::vector<currency::attachment_v>({ a_tx_payer, a_tx_comment, a_tx_message }));
|
||||
MAKE_TEST_WALLET_TX_EXTRA_ATTACH(events, tx_3, bob_wlt, MK_TEST_COINS(200), alice_acc, std::vector<currency::extra_v>({ a_tx_comment }), std::vector<currency::attachment_v>({ a_tx_payer, a_tx_message }));
|
||||
|
||||
MAKE_NEXT_BLOCK(events, blk_7, blk_6r, miner_acc); // don't put tx_3 into this block, the block is only necessary to trigger tx_pool scan on in wallet2::refresh()
|
||||
|
||||
|
|
@ -1612,7 +1614,7 @@ bool gen_wallet_decrypted_attachments::generate(std::vector<test_event_entry>& e
|
|||
return true;
|
||||
}
|
||||
|
||||
void gen_wallet_decrypted_attachments::on_transfer2(const tools::wallet_public::wallet_transfer_info& wti, const std::list<tools::wallet_public::asset_balance_entry>& balances, uint64_t total_mined)
|
||||
void gen_wallet_decrypted_payload_items::on_transfer2(const tools::wallet_public::wallet_transfer_info& wti, const std::list<tools::wallet_public::asset_balance_entry>& balances, uint64_t total_mined)
|
||||
{
|
||||
m_on_transfer2_called = true;
|
||||
//try {
|
||||
|
|
|
|||
|
|
@ -104,9 +104,9 @@ struct gen_wallet_transfers_and_chain_switch : public wallet_test
|
|||
bool generate(std::vector<test_event_entry>& events) const;
|
||||
};
|
||||
|
||||
struct gen_wallet_decrypted_attachments : public wallet_test, virtual public tools::i_wallet2_callback
|
||||
struct gen_wallet_decrypted_payload_items : public wallet_test, virtual public tools::i_wallet2_callback
|
||||
{
|
||||
gen_wallet_decrypted_attachments();
|
||||
gen_wallet_decrypted_payload_items();
|
||||
bool generate(std::vector<test_event_entry>& events) const;
|
||||
|
||||
// intrface tools::i_wallet2_callback
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue