未验证 提交 b97f979b 编写于 作者: K Kevin Heifner 提交者: GitHub

Merge pull request #1887 from EOSIO/verify-unspecified-transaction-expiration-throws-1867

 GH #1867 Test to verify unspecified transaction expiration throws.
......@@ -352,7 +352,7 @@ namespace eosio { namespace chain {
template<typename T>
void validate_transaction(const T& trx) const {
try {
EOS_ASSERT(trx.actions.size() > 0, transaction_exception, "A transaction must have at least one message");
EOS_ASSERT(trx.actions.size() > 0, transaction_exception, "A transaction must have at least one action");
validate_expiration(trx);
validate_uniqueness(trx);
......
......@@ -104,6 +104,55 @@ BOOST_AUTO_TEST_CASE(trx_variant ) {
}
}
BOOST_AUTO_TEST_CASE(trx_uniqueness) {
tester chain;
signed_transaction trx;
name new_account_name = name("alice");
authority owner_auth = authority(chain.get_public_key( new_account_name, "owner"));
trx.actions.emplace_back(vector<permission_level>{{config::system_account_name, config::active_name}},
contracts::newaccount{
.creator = config::system_account_name,
.name = new_account_name,
.owner = owner_auth,
.active = authority(chain.get_public_key(new_account_name, "active")),
.recovery = authority(chain.get_public_key(new_account_name, "recovery)),"))
});
trx.expiration = time_point_sec(chain.control->head_block_time()) + 90;
trx.ref_block_num = static_cast<uint16_t>(chain.control->head_block_num());
trx.ref_block_prefix = static_cast<uint32_t>(chain.control->head_block_id()._hash[1]);
trx.sign(chain.get_private_key(config::system_account_name, "active"), chain_id_type());
chain.push_transaction(trx);
BOOST_CHECK_THROW(chain.push_transaction(trx), tx_duplicate);
}
BOOST_AUTO_TEST_CASE(invalid_expiration) {
tester chain;
signed_transaction trx;
name new_account_name = name("alice");
authority owner_auth = authority(chain.get_public_key( new_account_name, "owner"));
trx.actions.emplace_back(vector<permission_level>{{config::system_account_name, config::active_name}},
contracts::newaccount{
.creator = config::system_account_name,
.name = new_account_name,
.owner = owner_auth,
.active = authority(chain.get_public_key(new_account_name, "active")),
.recovery = authority(chain.get_public_key(new_account_name, "recovery)),"))
});
trx.ref_block_num = static_cast<uint16_t>(chain.control->head_block_num());
trx.ref_block_prefix = static_cast<uint32_t>(chain.control->head_block_id()._hash[1]);
trx.sign(chain.get_private_key(config::system_account_name, "active"), chain_id_type());
// Unset expiration should throw
BOOST_CHECK_THROW(chain.push_transaction(trx), transaction_exception);
memset(&trx.expiration, 0, sizeof(trx.expiration)); // currently redundant, as default is all zeros, but may not always be.
trx.sign(chain.get_private_key(config::system_account_name, "active"), chain_id_type());
// Expired transaction (January 1970) should throw
BOOST_CHECK_THROW(chain.push_transaction(trx), transaction_exception);
}
BOOST_AUTO_TEST_CASE(irrelevant_auth) {
try {
tester chain;
......
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <boost/test/unit_test.hpp>
#pragma GCC diagnostic pop
#include <boost/algorithm/string/predicate.hpp>
#include <eosio/testing/tester.hpp>
#include <eosio/chain/contracts/abi_serializer.hpp>
......@@ -100,6 +103,29 @@ BOOST_FIXTURE_TEST_CASE( test_transfer, currency_tester ) try {
}
} FC_LOG_AND_RETHROW() /// test_transfer
BOOST_FIXTURE_TEST_CASE( test_duplicate_transfer, currency_tester ) {
create_accounts( {N(alice)} );
auto trace = push_action(N(currency), N(transfer), mutable_variant_object()
("from", "currency")
("to", "alice")
("quantity", "100.0000 CUR")
("memo", "fund Alice")
);
BOOST_CHECK_THROW(push_action(N(currency), N(transfer), mutable_variant_object()
("from", "currency")
("to", "alice")
("quantity", "100.0000 CUR")
("memo", "fund Alice")),
tx_duplicate);
produce_block();
BOOST_CHECK_EQUAL(true, chain_has_transaction(trace.id));
BOOST_CHECK_EQUAL(get_balance(N(alice)), asset::from_string( "100.0000 CUR" ) );
}
BOOST_FIXTURE_TEST_CASE( test_addtransfer, currency_tester ) try {
create_accounts( {N(alice)} );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册