2016-01-18 15:33:29 +00:00
|
|
|
// Copyright (c) 2011-2016 The Cryptonote developers
|
2015-04-23 16:07:22 +00:00
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2015-04-06 16:13:07 +00:00
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
#include "RandomOuts.h"
|
2015-04-06 16:13:07 +00:00
|
|
|
#include "TestGenerator.h"
|
2015-07-30 15:22:07 +00:00
|
|
|
#include "Rpc/CoreRpcServerCommandsDefinitions.h"
|
2015-04-06 16:13:07 +00:00
|
|
|
|
|
|
|
GetRandomOutputs::GetRandomOutputs() {
|
|
|
|
REGISTER_CALLBACK_METHOD(GetRandomOutputs, checkHalfUnlocked);
|
|
|
|
REGISTER_CALLBACK_METHOD(GetRandomOutputs, checkFullyUnlocked);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GetRandomOutputs::generate(std::vector<test_event_entry>& events) const {
|
|
|
|
TestGenerator generator(m_currency, events);
|
|
|
|
|
|
|
|
generator.generateBlocks();
|
|
|
|
|
|
|
|
uint64_t sendAmount = MK_COINS(1);
|
|
|
|
|
|
|
|
auto builder = generator.createTxBuilder(
|
|
|
|
generator.minerAccount, generator.minerAccount, sendAmount, m_currency.minimumFee());
|
|
|
|
|
|
|
|
for (int i = 0; i < 10; ++i) {
|
|
|
|
auto builder = generator.createTxBuilder(
|
|
|
|
generator.minerAccount, generator.minerAccount, sendAmount, m_currency.minimumFee());
|
|
|
|
|
|
|
|
auto tx = builder.build();
|
|
|
|
generator.addEvent(tx);
|
|
|
|
generator.makeNextBlock(tx);
|
|
|
|
}
|
|
|
|
|
|
|
|
// unlock half of the money
|
|
|
|
generator.generateBlocks(m_currency.minedMoneyUnlockWindow() / 2);
|
|
|
|
generator.addCallback("checkHalfUnlocked");
|
|
|
|
|
|
|
|
// unlock the remaining part
|
|
|
|
generator.generateBlocks(m_currency.minedMoneyUnlockWindow() / 2);
|
|
|
|
generator.addCallback("checkFullyUnlocked");
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-05-27 12:08:46 +00:00
|
|
|
bool GetRandomOutputs::request(CryptoNote::core& c, uint64_t amount, size_t mixin, CryptoNote::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS_response& resp) {
|
|
|
|
CryptoNote::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS_request req;
|
2015-04-06 16:13:07 +00:00
|
|
|
|
|
|
|
req.amounts.push_back(amount);
|
|
|
|
req.outs_count = mixin;
|
|
|
|
|
2015-05-27 12:08:46 +00:00
|
|
|
resp = boost::value_initialized<CryptoNote::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS_response>();
|
2015-04-06 16:13:07 +00:00
|
|
|
|
|
|
|
return c.get_random_outs_for_amounts(req, resp);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CHECK(cond) if((cond) == false) { LOG_ERROR("Condition "#cond" failed"); return false; }
|
|
|
|
|
2015-05-27 12:08:46 +00:00
|
|
|
bool GetRandomOutputs::checkHalfUnlocked(CryptoNote::core& c, size_t ev_index, const std::vector<test_event_entry>& events) {
|
|
|
|
CryptoNote::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS_response resp;
|
2015-04-06 16:13:07 +00:00
|
|
|
|
|
|
|
auto amount = MK_COINS(1);
|
|
|
|
auto unlocked = m_currency.minedMoneyUnlockWindow() / 2 + 1;
|
|
|
|
|
|
|
|
CHECK(request(c, amount, 0, resp));
|
|
|
|
CHECK(resp.outs.size() == 1);
|
|
|
|
CHECK(resp.outs[0].amount == amount);
|
|
|
|
CHECK(resp.outs[0].outs.size() == 0);
|
|
|
|
|
|
|
|
CHECK(request(c, amount, unlocked, resp));
|
|
|
|
CHECK(resp.outs.size() == 1);
|
|
|
|
CHECK(resp.outs[0].amount == amount);
|
|
|
|
CHECK(resp.outs[0].outs.size() == unlocked);
|
|
|
|
|
|
|
|
CHECK(request(c, amount, unlocked * 2, resp));
|
|
|
|
CHECK(resp.outs.size() == 1);
|
|
|
|
CHECK(resp.outs[0].amount == amount);
|
|
|
|
CHECK(resp.outs[0].outs.size() == unlocked);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-05-27 12:08:46 +00:00
|
|
|
bool GetRandomOutputs::checkFullyUnlocked(CryptoNote::core& c, size_t ev_index, const std::vector<test_event_entry>& events) {
|
|
|
|
CryptoNote::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS_response resp;
|
2015-04-06 16:13:07 +00:00
|
|
|
|
|
|
|
auto amount = MK_COINS(1);
|
|
|
|
auto unlocked = m_currency.minedMoneyUnlockWindow() + 1;
|
|
|
|
|
|
|
|
CHECK(request(c, amount, unlocked, resp));
|
|
|
|
CHECK(resp.outs.size() == 1);
|
|
|
|
CHECK(resp.outs[0].amount == amount);
|
|
|
|
CHECK(resp.outs[0].outs.size() == unlocked);
|
|
|
|
|
|
|
|
CHECK(request(c, amount, unlocked * 2, resp));
|
|
|
|
CHECK(resp.outs.size() == 1);
|
|
|
|
CHECK(resp.outs[0].amount == amount);
|
|
|
|
CHECK(resp.outs[0].outs.size() == unlocked);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|