Basic receivable_processor completion.
This commit is contained in:
parent
f0e35d8af2
commit
8a5fa4b9e1
4 changed files with 88 additions and 4 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -19,3 +19,4 @@
|
|||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
*.DS_Store
|
||||
|
|
|
@ -19,8 +19,6 @@ include_directories (${CRYPTOPP_INCLUDE_DIR})
|
|||
|
||||
find_package (Qt5 REQUIRED COMPONENTS Core Gui Widgets)
|
||||
|
||||
include_directories (${CMAKE_SOURCE_DIR}/libb64-1.2/include)
|
||||
|
||||
add_library (mu_coin
|
||||
mu_coin/mu_coin.hpp
|
||||
mu_coin/mu_coin.cpp
|
||||
|
|
|
@ -1571,13 +1571,17 @@ void receivable_message_processor::process_authorizations (mu_coin::block_hash c
|
|||
for (auto i (send.outputs.begin ()), j (send.outputs.end ()); i != j; ++i)
|
||||
{
|
||||
mu_coin::private_key prv;
|
||||
mu_coin::secret_key key;
|
||||
mu_coin::secret_key key (0);
|
||||
if (!processor.client.wallet.fetch (i->destination, key, prv))
|
||||
{
|
||||
if (!processor.client.ledger.store.pending_get (i->destination, hash))
|
||||
{
|
||||
mu_coin::block_hash previous;
|
||||
processor.client.ledger.store.latest_get (i->destination, previous);
|
||||
auto new_address (processor.client.ledger.store.latest_get (i->destination, previous));
|
||||
if (new_address)
|
||||
{
|
||||
previous = i->destination;
|
||||
}
|
||||
auto receive (new mu_coin::receive_block);
|
||||
receive->previous = previous;
|
||||
receive->source = hash;
|
||||
|
|
|
@ -191,4 +191,85 @@ TEST (receivable_processor, confirm_insufficient_pos)
|
|||
std::copy (stream.data, stream.data + stream.size, client1.network.buffer.begin ());
|
||||
client1.network.receive_action (boost::system::error_code {}, stream.size);
|
||||
ASSERT_EQ (1, receivable->acknowledged);
|
||||
ASSERT_FALSE (receivable->complete);
|
||||
// Shared_from_this, local, timeout, callback
|
||||
ASSERT_EQ (4, receivable.use_count ());
|
||||
}
|
||||
|
||||
TEST (receivable_processor, confirm_sufficient_pos)
|
||||
{
|
||||
boost::asio::io_service io_service;
|
||||
mu_coin::processor_service processor;
|
||||
mu_coin::client client1 (io_service, 24001, processor);
|
||||
mu_coin::keypair key1;
|
||||
client1.ledger.store.genesis_put (key1.pub, std::numeric_limits<mu_coin::uint256_t>::max ());
|
||||
auto block1 (new mu_coin::send_block ());
|
||||
auto receivable (std::make_shared <mu_coin::receivable_processor> (std::unique_ptr <mu_coin::publish_req> {new mu_coin::publish_req {std::unique_ptr <mu_coin::block> {block1}}}, client1));
|
||||
receivable->run ();
|
||||
ASSERT_EQ (1, client1.network.publish_listener_size ());
|
||||
mu_coin::publish_con con1 {block1->hash ()};
|
||||
mu_coin::authorization auth1;
|
||||
auth1.address = key1.pub;
|
||||
mu_coin::sign_message (key1.prv, key1.pub, con1.block, auth1.signature);
|
||||
con1.authorizations.push_back (auth1);
|
||||
mu_coin::byte_write_stream stream;
|
||||
con1.serialize (stream);
|
||||
ASSERT_LE (stream.size, client1.network.buffer.size ());
|
||||
std::copy (stream.data, stream.data + stream.size, client1.network.buffer.begin ());
|
||||
client1.network.receive_action (boost::system::error_code {}, stream.size);
|
||||
ASSERT_EQ (std::numeric_limits<mu_coin::uint256_t>::max (), receivable->acknowledged);
|
||||
ASSERT_TRUE (receivable->complete);
|
||||
ASSERT_EQ (3, receivable.use_count ());
|
||||
}
|
||||
|
||||
TEST (receivable_processor, send_with_receive)
|
||||
{
|
||||
boost::asio::io_service io_service;
|
||||
mu_coin::processor_service processor;
|
||||
mu_coin::client client1 (io_service, 24001, processor);
|
||||
mu_coin::client client2 (io_service, 24002, processor);
|
||||
mu_coin::keypair key1;
|
||||
client1.wallet.insert (key1.pub, key1.prv, 0);
|
||||
mu_coin::keypair key2;
|
||||
client2.wallet.insert (key2.pub, key2.prv, 0);
|
||||
auto amount (std::numeric_limits <mu_coin::uint256_t>::max ());
|
||||
client1.ledger.store.genesis_put (key1.pub, amount);
|
||||
client2.ledger.store.genesis_put (key1.pub, amount);
|
||||
auto block1 (new mu_coin::send_block ());
|
||||
mu_coin::block_hash previous;
|
||||
ASSERT_FALSE (client1.ledger.store.latest_get (key1.pub, previous));
|
||||
block1->inputs.push_back (mu_coin::send_input (key1.pub, previous, amount - 100));
|
||||
block1->outputs.push_back (mu_coin::send_output (key2.pub, 99));
|
||||
block1->signatures.push_back (mu_coin::uint512_union {});
|
||||
mu_coin::sign_message (key1.prv, key1.pub, block1->hash (), block1->signatures.back ());
|
||||
ASSERT_EQ (amount, client1.ledger.balance (key1.pub));
|
||||
ASSERT_EQ (0, client1.ledger.balance (key2.pub));
|
||||
ASSERT_EQ (amount, client2.ledger.balance (key1.pub));
|
||||
ASSERT_EQ (0, client2.ledger.balance (key2.pub));
|
||||
ASSERT_EQ (mu_coin::process_result::progress, client1.ledger.process (*block1));
|
||||
ASSERT_EQ (mu_coin::process_result::progress, client2.ledger.process (*block1));
|
||||
ASSERT_EQ (amount - 100, client1.ledger.balance (key1.pub));
|
||||
ASSERT_EQ (0, client1.ledger.balance (key2.pub));
|
||||
ASSERT_EQ (amount - 100, client2.ledger.balance (key1.pub));
|
||||
ASSERT_EQ (0, client2.ledger.balance (key2.pub));
|
||||
auto receivable (std::make_shared <mu_coin::receivable_processor> (std::unique_ptr <mu_coin::publish_req> {new mu_coin::publish_req {std::unique_ptr <mu_coin::block> {block1}}}, client2));
|
||||
receivable->run ();
|
||||
ASSERT_EQ (1, client2.network.publish_listener_size ());
|
||||
mu_coin::publish_con con1 {block1->hash ()};
|
||||
mu_coin::authorization auth1;
|
||||
auth1.address = key1.pub;
|
||||
mu_coin::sign_message (key1.prv, key1.pub, con1.block, auth1.signature);
|
||||
con1.authorizations.push_back (auth1);
|
||||
mu_coin::byte_write_stream stream;
|
||||
con1.serialize (stream);
|
||||
ASSERT_LE (stream.size, client2.network.buffer.size ());
|
||||
std::copy (stream.data, stream.data + stream.size, client2.network.buffer.begin ());
|
||||
client2.network.receive_action (boost::system::error_code {}, stream.size);
|
||||
ASSERT_EQ (amount - 100, client1.ledger.balance (key1.pub));
|
||||
ASSERT_EQ (0, client1.ledger.balance (key2.pub));
|
||||
ASSERT_EQ (amount - 100, client2.ledger.balance (key1.pub));
|
||||
ASSERT_EQ (99, client2.ledger.balance (key2.pub));
|
||||
ASSERT_EQ (amount - 100, receivable->acknowledged);
|
||||
ASSERT_TRUE (receivable->complete);
|
||||
ASSERT_EQ (3, receivable.use_count ());
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue