Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

Commit

Permalink
add unit tests for eosio.msig::approve with proposal_hash specified #87
Browse files Browse the repository at this point in the history
  • Loading branch information
arhag committed Nov 7, 2018
1 parent 2b533f0 commit a3cc6e6
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions tests/eosio.msig_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -861,4 +861,90 @@ BOOST_FIXTURE_TEST_CASE( approve_by_two_old, eosio_msig_tester ) try {

} FC_LOG_AND_RETHROW()

BOOST_FIXTURE_TEST_CASE( approve_with_hash, eosio_msig_tester ) try {
auto trx = reqauth("alice", {permission_level{N(alice), config::active_name}}, abi_serializer_max_time );
auto trx_hash = fc::sha256::hash( trx );
auto not_trx_hash = fc::sha256::hash( trx_hash );

push_action( N(alice), N(propose), mvo()
("proposer", "alice")
("proposal_name", "first")
("trx", trx)
("requested", vector<permission_level>{{ N(alice), config::active_name }})
);

//fail to approve with incorrect hash
BOOST_REQUIRE_EXCEPTION( push_action( N(alice), N(approve), mvo()
("proposer", "alice")
("proposal_name", "first")
("level", permission_level{ N(alice), config::active_name })
("proposal_hash", not_trx_hash)
),
eosio::chain::crypto_api_exception,
fc_exception_message_is("hash mismatch")
);

//approve and execute
push_action( N(alice), N(approve), mvo()
("proposer", "alice")
("proposal_name", "first")
("level", permission_level{ N(alice), config::active_name })
("proposal_hash", trx_hash)
);

transaction_trace_ptr trace;
control->applied_transaction.connect([&]( const transaction_trace_ptr& t) { if (t->scheduled) { trace = t; } } );
push_action( N(alice), N(exec), mvo()
("proposer", "alice")
("proposal_name", "first")
("executer", "alice")
);

BOOST_REQUIRE( bool(trace) );
BOOST_REQUIRE_EQUAL( 1, trace->action_traces.size() );
BOOST_REQUIRE_EQUAL( transaction_receipt::executed, trace->receipt->status );
} FC_LOG_AND_RETHROW()

BOOST_FIXTURE_TEST_CASE( switch_proposal_and_fail_approve_with_hash, eosio_msig_tester ) try {
auto trx1 = reqauth("alice", {permission_level{N(alice), config::active_name}}, abi_serializer_max_time );
auto trx1_hash = fc::sha256::hash( trx1 );

push_action( N(alice), N(propose), mvo()
("proposer", "alice")
("proposal_name", "first")
("trx", trx1)
("requested", vector<permission_level>{{ N(alice), config::active_name }})
);

auto trx2 = reqauth("alice",
{ permission_level{N(alice), config::active_name},
permission_level{N(alice), config::owner_name} },
abi_serializer_max_time );

push_action( N(alice), N(cancel), mvo()
("proposer", "alice")
("proposal_name", "first")
("canceler", "alice")
);

push_action( N(alice), N(propose), mvo()
("proposer", "alice")
("proposal_name", "first")
("trx", trx2)
("requested", vector<permission_level>{ { N(alice), config::active_name },
{ N(alice), config::owner_name } })
);

//fail to approve with hash meant for old proposal
BOOST_REQUIRE_EXCEPTION( push_action( N(alice), N(approve), mvo()
("proposer", "alice")
("proposal_name", "first")
("level", permission_level{ N(alice), config::active_name })
("proposal_hash", trx1_hash)
),
eosio::chain::crypto_api_exception,
fc_exception_message_is("hash mismatch")
);
} FC_LOG_AND_RETHROW()

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit a3cc6e6

Please sign in to comment.