1
0
Fork 0
forked from lthn/blockchain

added test isolate_auditable_and_proof

This commit is contained in:
cryptozoidberg 2021-06-24 23:24:38 +02:00
parent faa956a959
commit 479f2029a0
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
7 changed files with 145 additions and 7 deletions

View file

@ -793,7 +793,7 @@ namespace currency
}
void operator()(tx_service_attachment& sa)
{
const std::string orignal_body = sa.body;
const std::string original_body = sa.body;
if (sa.flags&TX_SERVICE_ATTACHMENT_DEFLATE_BODY)
{
zlib_helper::pack(sa.body);
@ -818,7 +818,7 @@ namespace currency
{
//take hash from derivation and use it as a salt
crypto::hash derivation_hash = crypto::cn_fast_hash(&derivation_local, sizeof(derivation_local));
std::string salted_body = orignal_body;
std::string salted_body = original_body;
string_tools::apped_pod_to_strbuff(salted_body, derivation_hash);
crypto::hash proof_hash = crypto::cn_fast_hash(salted_body.data(), salted_body.size());
sa.security.push_back(*(crypto::public_key*)&proof_hash);
@ -2950,7 +2950,7 @@ namespace currency
return tools::base58::encode_addr(CURRENCY_PUBLIC_ADDRESS_BASE58_PREFIX, t_serializable_object_to_blob(addr)); // new format Zano address (normal)
}
//-----------------------------------------------------------------------
bool is_address_looks_like_wrapped(const std::string& addr)
bool is_address_like_wrapped(const std::string& addr)
{
if (addr.length() == 42 && addr.substr(0, 2) == "0x")
return true;

View file

@ -289,7 +289,7 @@ namespace currency
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);
bool is_derivation_used_to_encrypt(const transaction& tx, const crypto::key_derivation& derivation);
bool is_address_looks_like_wrapped(const std::string& addr);
bool is_address_like_wrapped(const std::string& addr);
void load_wallet_transfer_info_flags(tools::wallet_public::wallet_transfer_info& x);
uint64_t get_tx_type(const transaction& tx);
uint64_t get_tx_type_ex(const transaction& tx, tx_out& htlc_out, txin_htlc& htlc_in);

View file

@ -1218,7 +1218,7 @@ bool simple_wallet::transfer(const std::vector<std::string> &args_)
currency::tx_destination_entry de;
de.addr.resize(1);
//check if address looks like wrapped address
if (is_address_looks_like_wrapped(local_args[i]))
if (is_address_like_wrapped(local_args[i]))
{
success_msg_writer(true) << "Address " << local_args[i] << " recognized as wrapped address, creating wrapping transaction...";
//put into service attachment specially encrypted entry which will contain wrap address and network

View file

@ -718,7 +718,10 @@ void wallet2::prepare_wti_decrypted_attachments(wallet_public::wallet_transfer_i
for (const auto& item : decrypted_att)
{
wti.service_entries.push_back(item);
if (item.type() == typeid(currency::tx_service_attachment))
{
wti.service_entries.push_back(tools::wallet_public::tx_service_attachment_kv(boost::get<currency::tx_service_attachment>(item)));
}
}
}
else

View file

@ -87,7 +87,7 @@ namespace wallet_public
#define WALLET_TRANSFER_INFO_FLAGS_HTLC_DEPOSIT static_cast<uint16_t>(1 << 0)
struct tx_service_attachment_kv: public tx_service_attachment
struct tx_service_attachment_kv: public currency::tx_service_attachment
{
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(service_id)

View file

@ -0,0 +1,116 @@
// Copyright (c) 2014-2021 Zano Project
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "chaingen.h"
#include "escrow_wallet_tests.h"
#include "random_helper.h"
#include "chaingen_helpers.h"
#include "atomic_tests.h"
using namespace epee;
using namespace crypto;
using namespace currency;
isolate_auditable_and_proof::isolate_auditable_and_proof()
{
REGISTER_CALLBACK_METHOD(isolate_auditable_and_proof, c1);
REGISTER_CALLBACK_METHOD(isolate_auditable_and_proof, configure_core);
}
bool isolate_auditable_and_proof::generate(std::vector<test_event_entry>& events) const
{
random_state_test_restorer::reset_random(0); // to make the test deterministic
m_genesis_timestamp = 1450000000;
test_core_time::adjust(m_genesis_timestamp);
epee::debug::get_set_enable_assert(true, true);
currency::account_base genesis_acc;
genesis_acc.generate();
m_mining_accunt.generate();
m_mining_accunt.set_createtime(m_genesis_timestamp);
block blk_0 = AUTO_VAL_INIT(blk_0);
generator.construct_genesis_block(blk_0, genesis_acc, test_core_time::get_time());
events.push_back(blk_0);
DO_CALLBACK(events, "configure_core");
REWIND_BLOCKS_N(events, blk_0r, blk_0, m_mining_accunt, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 5);
DO_CALLBACK(events, "c1");
epee::debug::get_set_enable_assert(true, false);
return true;
}
bool isolate_auditable_and_proof::configure_core(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
{
return true;
}
/************************************************************************/
/* */
/************************************************************************/
bool isolate_auditable_and_proof::c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
{
epee::debug::get_set_enable_assert(true, true);
misc_utils::auto_scope_leave_caller scope_exit_handler = misc_utils::create_scope_leave_handler([&](){epee::debug::get_set_enable_assert(true, false); });
LOG_PRINT_MAGENTA("Mining Address: " << currency::get_account_address_as_str(m_mining_accunt.get_public_address()), LOG_LEVEL_0);
currency::account_base auditable_test;
auditable_test.generate(true);
auditable_test.set_createtime(m_genesis_timestamp);
LOG_PRINT_MAGENTA(": " << currency::get_account_address_as_str(auditable_test.get_public_address()), LOG_LEVEL_0);
std::shared_ptr<tools::wallet2> auditable_test_instance = init_playtime_test_wallet(events, c, auditable_test);
#define AMOUNT_TO_TRANSFER_LOCAL (TESTS_DEFAULT_FEE*10)
std::shared_ptr<tools::wallet2> miner_wlt = init_playtime_test_wallet(events, c, m_mining_accunt);
miner_wlt->refresh();
//create transaction that use TX_SERVICE_ATTACHMENT_ENCRYPT_BODY and TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE
{
std::vector<extra_v> extra;
std::vector<currency::attachment_v> attachments;
vector<currency::tx_destination_entry> dsts;
currency::tx_destination_entry de;
de.addr.resize(1);
//put into service attachment specially encrypted entry which will contain wrap address and network
tx_service_attachment sa = AUTO_VAL_INIT(sa);
sa.service_id = BC_WRAP_SERVICE_ID;
sa.instruction = BC_WRAP_SERVICE_INSTRUCTION_ERC20;
sa.flags = TX_SERVICE_ATTACHMENT_ENCRYPT_BODY | TX_SERVICE_ATTACHMENT_ENCRYPT_BODY_ISOLATE_AUDITABLE;
sa.body = "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B";
extra.push_back(sa);
currency::account_public_address acc = AUTO_VAL_INIT(acc);
de.addr.front() = auditable_test.get_public_address();
currency::transaction tx;
miner_wlt->transfer(dsts, 0, 0, miner_wlt->get_core_runtime_config().tx_default_fee, extra, attachments, tx);
}
bool r = mine_next_pow_blocks_in_playtime(m_mining_accunt.get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW);
CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed");
miner_wlt->refresh();
auditable_test_instance->refresh();
epee::json_rpc::error je;
tools::wallet_rpc_server::connection_context ctx;
tools::wallet_rpc_server miner_wlt_rpc(*auditable_test_instance);
wallet_public::COMMAND_RPC_GET_RECENT_TXS_AND_INFO::request req = AUTO_VAL_INIT();
wallet_public::COMMAND_RPC_GET_RECENT_TXS_AND_INFO::request res = AUTO_VAL_INIT();
req.count = 100;
req.offset = 0;
miner_wlt_rpc->on_get_recent_txs_and_info(req, res, je, ctx);
std::string ps = epee::serialization::store_t_to_json(res);
return r;
}

View file

@ -0,0 +1,19 @@
// Copyright (c) 2014-2021 Zano Project
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#pragma once
#include "chaingen.h"
#include "wallet_tests_basic.h"
struct isolate_auditable_and_proof : public wallet_test
{
isolate_auditable_and_proof();
bool generate(std::vector<test_event_entry>& events) const;
virtual bool c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)=0;
virtual bool configure_core(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
protected:
mutable uint64_t m_genesis_timestamp;
mutable currency::account_base m_mining_accunt;
};