peerplays_migrated/tests/tests/sidechain_addresses_test.cpp
sierra19XX b436b790fb
SON Weighted Multi Signature Signing (#349)
* Bring in the bitcoin utils code into plugin
* Add tx creation, signing and tests
* tx deserialization fix
* add 10-of-14 multisig address test
* Add signing and verification tests and sign_transaction_standalone
* Add send_transaction_standalone function
* Debug logs and additional tests
* Fix for son deletion in the middle
* Extend script_builder
* Witness script for weighted wallet
* btc_weighted_multisig_address implementation
* Fix for bad-txns-nonstandard-inputs
* Weighted multisignature address test
* Create test tx with weighted multisig wallet
* Fix the issues with tx signing
* End to End test weighted multi sig
* 1 or m-of-n deposit address support
* Move network_type enum to the base class
* btc_one_or_weighted_multisig_address implementation
* Simplify redeem script
* Fix error in redeem_script
* btc_one_or_weighted_multisig_address tests
* Refactor sidechain address mapping
* CLANG code format
* CLANG code format sidechain tests
* Integration of deposit and rest of weighted wallets, withdrawal fee fix, whole code refactoring
* Move util functions to Utils file
* Add proper checks for withdraw fee
* Deposit address creation, import deposit/withdraw addresses, some code cleanup

Co-authored-by: satyakoneru <15652887+satyakoneru@users.noreply.github.com>
Co-authored-by: gladcow <s.gladkov@pbsa.info>
Co-authored-by: Srdjan Obucina <obucinac@gmail.com>
2020-04-18 22:18:04 +02:00

150 lines
5.2 KiB
C++

#include <boost/test/unit_test.hpp>
#include "../common/database_fixture.hpp"
#include <graphene/chain/hardfork.hpp>
#include <graphene/chain/sidechain_address_object.hpp>
#include <graphene/chain/sidechain_defs.hpp>
using namespace graphene::chain;
using namespace graphene::chain::test;
BOOST_FIXTURE_TEST_SUITE( sidechain_addresses_tests, database_fixture )
BOOST_AUTO_TEST_CASE( sidechain_address_add_test ) {
BOOST_TEST_MESSAGE("sidechain_address_add_test");
generate_block();
set_expiration(db, trx);
ACTORS((alice));
generate_block();
set_expiration(db, trx);
{
BOOST_TEST_MESSAGE("Send sidechain_address_add_operation");
sidechain_address_add_operation op;
op.payer = alice_id;
op.sidechain_address_account = alice_id;
op.sidechain = sidechain_type::bitcoin;
op.deposit_public_key = "deposit_public_key";
op.deposit_address = "deposit_address";
op.withdraw_public_key = "withdraw_public_key";
op.withdraw_address = "withdraw_address";
trx.operations.push_back(op);
sign(trx, alice_private_key);
PUSH_TX(db, trx, ~0);
}
generate_block();
BOOST_TEST_MESSAGE("Check sidechain_address_add_operation results");
const auto& idx = db.get_index_type<sidechain_address_index>().indices().get<by_account_and_sidechain>();
BOOST_REQUIRE( idx.size() == 1 );
auto obj = idx.find( boost::make_tuple( alice_id, sidechain_type::bitcoin ) );
BOOST_REQUIRE( obj != idx.end() );
BOOST_CHECK( obj->sidechain_address_account == alice_id );
BOOST_CHECK( obj->sidechain == sidechain_type::bitcoin );
BOOST_CHECK( obj->deposit_public_key == "deposit_public_key" );
BOOST_CHECK( obj->deposit_address == "deposit_address" );
BOOST_CHECK( obj->withdraw_public_key == "withdraw_public_key" );
BOOST_CHECK( obj->withdraw_address == "withdraw_address" );
}
BOOST_AUTO_TEST_CASE( sidechain_address_update_test ) {
BOOST_TEST_MESSAGE("sidechain_address_update_test");
INVOKE(sidechain_address_add_test);
GET_ACTOR(alice);
const auto& idx = db.get_index_type<sidechain_address_index>().indices().get<by_account_and_sidechain>();
BOOST_REQUIRE( idx.size() == 1 );
auto obj = idx.find( boost::make_tuple( alice_id, sidechain_type::bitcoin ) );
BOOST_REQUIRE( obj != idx.end() );
std::string new_deposit_public_key = "new_deposit_public_key";
std::string new_deposit_address = "new_deposit_address";
std::string new_withdraw_public_key = "new_withdraw_public_key";
std::string new_withdraw_address = "new_withdraw_address";
{
BOOST_TEST_MESSAGE("Send sidechain_address_update_operation");
sidechain_address_update_operation op;
op.payer = alice_id;
op.sidechain_address_id = sidechain_address_id_type(0);
op.sidechain_address_account = obj->sidechain_address_account;
op.sidechain = obj->sidechain;
op.deposit_public_key = new_deposit_public_key;
op.deposit_address = new_deposit_address;
op.withdraw_public_key = new_withdraw_public_key;
op.withdraw_address = new_withdraw_address;
trx.operations.push_back(op);
sign(trx, alice_private_key);
PUSH_TX(db, trx, ~0);
}
generate_block();
{
BOOST_TEST_MESSAGE("Check sidechain_address_update_operation results");
const auto& idx = db.get_index_type<sidechain_address_index>().indices().get<by_account_and_sidechain>();
BOOST_REQUIRE( idx.size() == 1 );
auto obj = idx.find( boost::make_tuple( alice_id, sidechain_type::bitcoin ) );
BOOST_REQUIRE( obj != idx.end() );
BOOST_CHECK( obj->sidechain_address_account == obj->sidechain_address_account );
BOOST_CHECK( obj->sidechain == obj->sidechain );
BOOST_CHECK( obj->deposit_public_key == new_deposit_public_key );
BOOST_CHECK( obj->deposit_address == new_deposit_address );
BOOST_CHECK( obj->withdraw_public_key == new_withdraw_public_key );
BOOST_CHECK( obj->withdraw_address == new_withdraw_address );
}
}
BOOST_AUTO_TEST_CASE( sidechain_address_delete_test ) {
BOOST_TEST_MESSAGE("sidechain_address_delete_test");
INVOKE(sidechain_address_add_test);
GET_ACTOR(alice);
const auto& idx = db.get_index_type<sidechain_address_index>().indices().get<by_account_and_sidechain>();
BOOST_REQUIRE( idx.size() == 1 );
auto obj = idx.find( boost::make_tuple( alice_id, sidechain_type::bitcoin ) );
BOOST_REQUIRE( obj != idx.end() );
{
BOOST_TEST_MESSAGE("Send sidechain_address_delete_operation");
sidechain_address_delete_operation op;
op.payer = alice_id;
op.sidechain_address_id = sidechain_address_id_type(0);
op.sidechain_address_account = alice_id;
op.sidechain = obj->sidechain;
trx.operations.push_back(op);
sign(trx, alice_private_key);
PUSH_TX(db, trx, ~0);
}
generate_block();
{
BOOST_TEST_MESSAGE("Check sidechain_address_delete_operation results");
const auto& idx = db.get_index_type<sidechain_address_index>().indices().get<by_account_and_sidechain>();
BOOST_REQUIRE( idx.size() == 0 );
auto obj = idx.find( boost::make_tuple( alice_id, sidechain_type::bitcoin ) );
BOOST_REQUIRE( obj == idx.end() );
}
}
BOOST_AUTO_TEST_SUITE_END()