1
0
Fork 0
forked from lthn/blockchain

added more test cases for emmit into multiassets_basic_test

This commit is contained in:
cryptozoidberg 2023-08-16 23:04:29 +02:00
parent ed3b5e5e81
commit 4c666aa6a4
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
8 changed files with 79 additions and 33 deletions

View file

@ -749,7 +749,7 @@ namespace currency
crypto::public_key owner = currency::null_pkey; // consider premultipling by 1/8
bool hidden_supply = false;
BEGIN_VERSIONED_SERIALIZE()
BEGIN_VERSIONED_SERIALIZE(0)
FIELD(total_max_supply)
FIELD(current_supply)
FIELD(decimal_point)
@ -816,8 +816,7 @@ namespace currency
boost::optional<crypto::signature> opt_proof; // operation proof - for update/emit
boost::optional<crypto::public_key> opt_asset_id; // target asset_id - for update/emit
BEGIN_VERSIONED_SERIALIZE()
CURRENT_VERSION(1)
BEGIN_VERSIONED_SERIALIZE(1)
FIELD(operation_type)
FIELD(descriptor)
FIELD(opt_amount_commitment)
@ -842,7 +841,7 @@ namespace currency
boost::optional<crypto::linear_composition_proof_s> opt_amount_commitment_composition_proof; // for hidden supply
boost::optional<crypto::signature> opt_amount_commitment_g_proof; // for non-hidden supply, proofs that amount_commitment - supply * asset_id = lin(G)
BEGIN_VERSIONED_SERIALIZE()
BEGIN_VERSIONED_SERIALIZE(0)
FIELD(opt_amount_commitment_composition_proof)
FIELD(opt_amount_commitment_g_proof)
END_SERIALIZE()

View file

@ -299,8 +299,7 @@ namespace currency
// solely for consolidated txs, asset opration fields are not serialized
BEGIN_SERIALIZE_OBJECT()
VERSION()
CURRENT_VERSION(0)
VERSION(0)
FIELD(asset_ids)
FIELD(blinded_asset_ids)
FIELD(amount_commitments)

View file

@ -98,28 +98,31 @@ do { \
if (!_ser_ar.stream().good()) return false; \
} while (0);
#define VERSION() \
#define VERSION(ver) \
do { \
_ser_ar.tag("VERSION"); \
if (!_ser_ar.stream().good()){break;} \
s_version = s_current_version = ver; \
_ser_ar.serialize_varint(s_version); \
if (!_ser_ar.stream().good()) return false; \
if(s_version > s_current_version) return false; \
} while (0);
/*
#define CURRENT_VERSION(v) \
do { \
s_current_version = v; \
if (_ser_ar.is_saving_arch()) { s_version = v; } \
} while (0);
*/
#define END_VERSION_UNDER(x) \
if(s_version < x ) {return true;}
#define BEGIN_VERSIONED_SERIALIZE() \
#define BEGIN_VERSIONED_SERIALIZE(ver) \
BEGIN_SERIALIZE() \
VERSION()
VERSION(ver)
#define DEFINE_SERIALIZATION_VERSION(v) inline static uint32_t get_serialization_version() { return v; }

View file

@ -3335,6 +3335,20 @@ uint64_t wallet2::balance(uint64_t& unlocked, uint64_t& awaiting_in, uint64_t& a
return total;
}
//----------------------------------------------------------------------------------------------------
uint64_t wallet2::balance(crypto::public_key asset_id, uint64_t& unlocked) const
{
std::unordered_map<crypto::public_key, wallet_public::asset_balance_entry_base> balances;
uint64_t dummy;
balance(balances, dummy);
auto it = balances.find(asset_id);
if (it == balances.end())
{
return 0;
}
unlocked = it->second.unlocked;
return it->second.total;
}
//----------------------------------------------------------------------------------------------------
bool wallet2::balance(std::unordered_map<crypto::public_key, wallet_public::asset_balance_entry_base>& balances, uint64_t& mined) const
{
mined = 0;

View file

@ -703,6 +703,7 @@ namespace tools
uint64_t balance(uint64_t& unloked, uint64_t& awaiting_in, uint64_t& awaiting_out, uint64_t& mined, const crypto::public_key& asset_id = currency::native_coin_asset_id) const;
bool balance(std::unordered_map<crypto::public_key, wallet_public::asset_balance_entry_base>& balances, uint64_t& mined) const;
bool balance(std::list<wallet_public::asset_balance_entry>& balances, uint64_t& mined) const;
uint64_t balance(crypto::public_key asset_id, uint64_t& unloked) const;
uint64_t balance(uint64_t& unloked) const;

View file

@ -1347,8 +1347,7 @@ namespace wallet_public
crypto::secret_key one_time_skey;
BEGIN_SERIALIZE_OBJECT()
VERSION()
CURRENT_VERSION(0)
VERSION(0)
FIELD(gen_context)
FIELD(one_time_skey)
END_SERIALIZE()
@ -1361,8 +1360,7 @@ namespace wallet_public
BEGIN_SERIALIZE_OBJECT()
VERSION()
CURRENT_VERSION(0)
VERSION(0)
FIELD(tx_template)
FIELD(encrypted_context)
END_SERIALIZE()

View file

@ -115,23 +115,27 @@ bool multiassets_basic_test::c1(currency::core& c, size_t ev_index, const std::v
CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed");
alice_wlt->refresh();
balances.clear();
alice_wlt->balance(balances, mined);
uint64_t last_alice_balances = alice_wlt->balance(asset_id, mined);
CHECK_AND_ASSERT_MES(last_alice_balances == AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC + AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC/2, false, "Failed to find needed asset in result balances");
it_asset = balances.find(asset_id);
CHECK_AND_ASSERT_MES(it_asset != balances.end(), false, "Failed to find needed asset in result balances");
CHECK_AND_ASSERT_MES(it_asset->second.total == AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC + AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC/2, false, "Failed to find needed asset in result balances");
miner_wlt->refresh();
uint64_t last_miner_balance = miner_wlt->balance(asset_id, mined);
try {
miner_wlt->transfer(AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC / 2, alice_wlt->get_account().get_public_address(), asset_id);
//pass over hardfork
CHECK_AND_ASSERT_MES(false, false, "Transfer with 0 Zano worked(fail)");
}
catch (...)
{
return true;
try {
miner_wlt->transfer(AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC / 2, alice_wlt->get_account().get_public_address(), asset_id);
//pass over hardfork
CHECK_AND_ASSERT_MES(false, false, "Transfer with 0 Zano worked(fail)");
}
catch (...)
{
LOG_PRINT_L0("Transfer failed as planned");
//return true;
}
}
asset_descriptor_base asset_info = AUTO_VAL_INIT(asset_info);
@ -141,10 +145,39 @@ bool multiassets_basic_test::c1(currency::core& c, size_t ev_index, const std::v
adb.ticker = "TCT";
adb.decimal_point = 12
*/
bool r = c.get_blockchain_storage().get_asset_info(asset_id);
r = c.get_blockchain_storage().get_asset_info(asset_id, asset_info);
CHECK_AND_ASSERT_MES(r, false, "Failed to get_asset_info");
CHECK_AND_ASSERT_MES(asset_info.current_supply = AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC*2, false, "Failed to find needed asset in result balances");
CHECK_AND_ASSERT_MES(asset_info.current_supply == AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC*2, false, "Failed to find needed asset in result balances");
//test update function
asset_info.meta_info = "{\"some\": \"info\"}";
miner_wlt->update_asset(asset_id, asset_info, tx);
r = mine_next_pow_blocks_in_playtime(miner_wlt->get_account().get_public_address(), c, 2);
CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed");
asset_descriptor_base asset_info2 = AUTO_VAL_INIT(asset_info2);
r = c.get_blockchain_storage().get_asset_info(asset_id, asset_info2);
CHECK_AND_ASSERT_MES(r, false, "Failed to get_asset_info");
CHECK_AND_ASSERT_MES(asset_info2.meta_info == asset_info.meta_info, false, "Failed to find needed asset in result balances");
//test emmit function
//use same destinations as we used before
miner_wlt->emmit_asset(asset_id, destinations, tx);
r = mine_next_pow_blocks_in_playtime(miner_wlt->get_account().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();
alice_wlt->refresh();
CHECK_AND_ASSERT_MES(miner_wlt->balance(asset_id, mined) == last_miner_balance + destinations[0].amount, false, "Miner balance wrong");
CHECK_AND_ASSERT_MES(alice_wlt->balance(asset_id, mined) == last_alice_balances + destinations[1].amount, false, "Alice balance wrong");
asset_descriptor_base asset_info3 = AUTO_VAL_INIT(asset_info3);
r = c.get_blockchain_storage().get_asset_info(asset_id, asset_info3);
CHECK_AND_ASSERT_MES(r, false, "Failed to get_asset_info");
CHECK_AND_ASSERT_MES(asset_info3.current_supply == asset_info2.current_supply + destinations[1].amount + destinations[0].amount, false, "Failed to find needed asset in result balances");
return true;
}

View file

@ -760,11 +760,10 @@ struct A_v1 : public A
BEGIN_SERIALIZE()
CURRENT_VERSION(1)
FIELD(one)
FIELD(two)
FIELD(vector_one)
VERSION()
VERSION(1)
if (s_version < 1) return true;
FIELD(vector_two)
END_SERIALIZE()
@ -777,11 +776,11 @@ struct A_v2 : public A_v1
BEGIN_SERIALIZE()
CURRENT_VERSION(2)
//CURRENT_VERSION(2)
FIELD(one)
FIELD(two)
FIELD(vector_one)
VERSION()
VERSION(2)
if (s_version < 1) return true;
FIELD(vector_two)
if (s_version < 2) return true;
@ -795,11 +794,11 @@ struct A_v3 : public A_v2
std::vector<std::string> vector_5;
BEGIN_SERIALIZE()
CURRENT_VERSION(3)
//CURRENT_VERSION(3)
FIELD(one)
FIELD(two)
FIELD(vector_one)
VERSION()
VERSION(3)
if (s_version < 1) return true;
FIELD(vector_two)
if (s_version < 2) return true;