message: add test cases for max_net_usage test (2084)
diff: #include <eosio/chain/contracts/abi_serializer.hpp>
  #include <eosio/chain/wasm_eosio_constraints.hpp>
  #include <eosio/chain/exceptions.hpp>
  +#include <eosio/chain/wast_to_wasm.hpp>
  #include <asserter/asserter.wast.hpp>
  #include <asserter/asserter.abi.hpp>
  @@ -1238,4 +1239,54 @@ BOOST_FIXTURE_TEST_CASE( protect_injected, TESTER ) try {
  produce_blocks(1);
  } FC_LOG_AND_RETHROW()
  +BOOST_FIXTURE_TEST_CASE(net_usage_tests, tester ) try {
  + int count = 0;
  + auto check = [&](int coderepeat, int max_net_usage)-> bool {
  + account_name account = N(f_tests) + (count++) * 16;
  + create_accounts({account});
  +
  + std::string code = R"=====(
  + (module
  + (import "env" "require_auth" (func $require_auth (param i64)))
  + (import "env" "eosio_assert" (func $eosio_assert (param i32 i32)))
  + (table 0 anyfunc)
  + (memory $0 1)
  + (export "apply" (func $apply))
  + (func $i64_trunc_u_f64 (param $0 f64) (result i64) (i64.trunc_u/f64 (get_local $0)))
  + (func $test (param $0 i64))
  + (func $apply (param $0 i64)(param $1 i64)(param $2 i64)
  + )=====";
  + for (int i = 0; i < coderepeat; ++i) {
  + code += "(call $test (call $i64_trunc_u_f64 (f64.const 1)))\n";
  + }
  + code += "))";
  + produce_blocks(1);
  + signed_transaction trx;
  + auto wasm = ::eosio::chain::wast_to_wasm(code);
  + trx.actions.emplace_back( vector<permission_level>{{account,config::active_name}},
  + contracts::setcode{
  + .account = account,
  + .vmtype = 0,
  + .vmversion = 0,
  + .code = bytes(wasm.begin(), wasm.end())
  + });
  + set_transaction_headers(trx);
  + if (max_net_usage) trx.max_net_usage_words = max_net_usage;
  + trx.sign( get_private_key( account, "active" ), chain_id_type() );
  + try {
  + push_transaction(trx);
  + produce_blocks(1);
  + return true;
  + } catch (tx_resource_exhausted &) {
  + return false;
  + } catch (transaction_exception &) {
  + return false;
  + }
  + };
  + BOOST_REQUIRE_EQUAL(true, check(1024, 0)); // default behavior
  + BOOST_REQUIRE_EQUAL(false, check(1024, 1000)); // transaction max_net_usage too small
  + BOOST_REQUIRE_EQUAL(false, check(10240, 0)); // larger than global maximum
  +
  +} FC_LOG_AND_RETHROW()
  +
  BOOST_AUTO_TEST_SUITE_END()
  