<commit_before>#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>

#include <tic_tac_toe/tic_tac_toe.wast.hpp>
#include <tic_tac_toe/tic_tac_toe.abi.hpp>
#include <eosio.system/eosio.system.wast.hpp>
#include <eosio.system/eosio.system.abi.hpp>

#include <proxy/proxy.wast.hpp>
#include <proxy/proxy.abi.hpp>

#include <Runtime/Runtime.h>

#include <fc/variant_object.hpp>
#include <fc/io/json.hpp>

#ifdef NON_VALIDATING_TEST
#define TESTER tester
#else
#define TESTER validating_tester
#endif

using namespace eosio;
using namespace eosio::chain;
using namespace eosio::chain::contracts;
using namespace eosio::testing;
using namespace fc;

struct movement {
   uint32_t    row;
   uint32_t    column;

   template<typename DataStream>
   friend DataStream& operator << ( DataStream& ds, const movement& t ){ \
      return ds << t.row << t.column;
   }
   template<typename DataStream>
   friend DataStream& operator >> ( DataStream& ds, movement& t ){
      return ds >> t.row >> t.column;
   }
};

BOOST_AUTO_TEST_SUITE(tic_tac_toe_tests)

BOOST_AUTO_TEST_CASE( tic_tac_toe_game ) try {
   TESTER chain;
   abi_serializer abi_ser = json::from_string(tic_tac_toe_abi).as<abi_def>();

   chain.set_code(config::system_account_name, eosio_system_wast);
   chain.set_abi(config::system_account_name, eosio_system_abi);

   chain.produce_blocks();
   chain.create_account(N(tic.tac.toe));
   chain.produce_blocks(10);

   chain.set_code(N(tic.tac.toe), tic_tac_toe_wast);
   chain.set_abi(N(tic.tac.toe), tic_tac_toe_abi);

   chain.produce_blocks();
   chain.create_account(N(player1));
   chain.create_account(N(player2));
   chain.produce_blocks(10);

   chain.push_action(N(tic.tac.toe), N(create), N(player1), mutable_variant_object()
           ("challenger", "player2")
           ("host", "player1")
   );

   chain.produce_blocks();

   auto mvt = mutable_variant_object()
           ("row", 1)
           ("column", 1);
   chain.push_action(N(tic.tac.toe), N(move), N(player1), mutable_variant_object()
           ("challenger", "player2")
           ("host", "player1")
           ("by", "player1")
           ("mvt", mvt)
   );

   mvt = mutable_variant_object()
           ("row", 0)
           ("column", 1);
   BOOST_CHECK_EXCEPTION(chain.push_action(N(tic.tac.toe), N(move), N(player1), mutable_variant_object()
         ("challenger", "player2")
         ("host", "player1")
         ("by", "player1")
         ("mvt", mvt)
      ), transaction_exception, assert_message_contains("not your turn"));

   mvt = mutable_variant_object()
           ("row", 1)
           ("column", 1);
   BOOST_CHECK_EXCEPTION(chain.push_action(N(tic.tac.toe), N(move), N(player2), mutable_variant_object()
         ("challenger", "player2")
         ("host", "player1")
         ("by", "player2")
         ("mvt", mvt)
      ), transaction_exception, assert_message_contains("not a valid movement"));

   mvt = mutable_variant_object()
           ("row", 0)
           ("column", 1);
   chain.push_action(N(tic.tac.toe), N(move), N(player2), mutable_variant_object()
           ("challenger", "player2")
           ("host", "player1")
           ("by", "player2")
           ("mvt", mvt)
   );

   mvt = mutable_variant_object()
           ("row", 0)
           ("column", 0 );
   chain.push_action(N(tic.tac.toe), N(move), N(player1), mutable_variant_object()
           ("challenger", "player2")
           ("host", "player1")
           ("by", "player1")
           ("mvt", mvt)
   );

   mvt = mutable_variant_object()
           ("row", 0)
           ("column", 2);
   chain.push_action(N(tic.tac.toe), N(move), N(player2), mutable_variant_object()
           ("challenger", "player2")
           ("host", "player1")
           ("by", "player2")
           ("mvt", mvt)
   );

   mvt = mutable_variant_object()
           ("row", 2)
           ("column", 2);
   chain.push_action(N(tic.tac.toe), N(move), N(player1), mutable_variant_object()
           ("challenger", "player2")
           ("host", "player1")
           ("by", "player1")
           ("mvt", mvt)
   );

   mvt = mutable_variant_object()
           ("row", 2)
           ("column", 0);
   BOOST_CHECK_EXCEPTION(chain.push_action(N(tic.tac.toe), N(move), N(player2), mutable_variant_object()
         ("challenger", "player2")
         ("host", "player1")
         ("by", "player2")
         ("mvt", mvt)
      ), transaction_exception, assert_message_contains("the game has ended"));

   chain.push_action(N(tic.tac.toe), N(close), N(player1), mutable_variant_object()
           ("challenger", "player2")
           ("host", "player1")
   );

   mvt = mutable_variant_object()
           ("row", 2)
           ("column", 0);
   BOOST_CHECK_EXCEPTION(chain.push_action(N(tic.tac.toe), N(move), N(player2), mutable_variant_object()
         ("challenger", "player2")
         ("host", "player1")
         ("by", "player2")
         ("mvt", mvt)
      ), transaction_exception, assert_message_contains("game doesn't exists"));

   BOOST_CHECK_EXCEPTION(chain.push_action(N(tic.tac.toe), N(restart), N(player2), mutable_variant_object()
         ("challenger", "player2")
         ("host", "player1")
         ("by", "player2")
      ), transaction_exception, assert_message_contains("game doesn't exists"));

   chain.push_action(N(tic.tac.toe), N(create), N(player2), mutable_variant_object()
           ("challenger", "player1")
           ("host", "player2")
   );
<commit_msg>Fixes for peer review and extra cleanup. GH #2214<commit_after>#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>

#include <tic_tac_toe/tic_tac_toe.wast.hpp>
#include <tic_tac_toe/tic_tac_toe.abi.hpp>
#include <eosio.system/eosio.system.wast.hpp>
#include <eosio.system/eosio.system.abi.hpp>

#include <proxy/proxy.wast.hpp>
#include <proxy/proxy.abi.hpp>

#include <Runtime/Runtime.h>

#include <fc/variant_object.hpp>
#include <fc/io/json.hpp>

#ifdef NON_VALIDATING_TEST
#define TESTER tester
#else
#define TESTER validating_tester
#endif

using namespace eosio;
using namespace eosio::chain;
using namespace eosio::chain::contracts;
using namespace eosio::testing;
using namespace fc;

const static uint32_t board_len = 9;
struct game {
   account_name     challenger;
   account_name     host;
   account_name     turn; // = account name of host/ challenger
   account_name     winner = N(none); // = none/ draw/ account name of host/ challenger
   uint8_t          board[board_len];
};
FC_REFLECT(game, (challenger)(host)(turn)(winner)(board));


struct movement {
   uint32_t    row;
   uint32_t    column;
};
FC_REFLECT(movement, (row)(column));

struct ttt_tester : TESTER {
   void get_game(game& game, account_name scope, account_name key) {
      auto* maybe_tid = find_table(N(tic.tac.toe), scope, N(games));
      if(maybe_tid == nullptr)
         BOOST_FAIL("table for code=\"tic.tac.toe\" scope=\"" + scope.to_string() + "\" table=\"games\" does not exist");

      auto* o = control->get_database().find<contracts::key_value_object, contracts::by_scope_primary>(boost::make_tuple(maybe_tid->id, key));
      if(o == nullptr)
         BOOST_FAIL("game for  does not exist for challenger=\"" + key.to_string() + "\"");

      fc::raw::unpack(o->value.data(), o->value.size(), game);
   }
};

BOOST_AUTO_TEST_SUITE(tic_tac_toe_tests)

BOOST_AUTO_TEST_CASE( tic_tac_toe_game ) try {
   TESTER chain;
   abi_serializer abi_ser = json::from_string(tic_tac_toe_abi).as<abi_def>();
   chain.create_account(N(tic.tac.toe));
   chain.produce_blocks(10);

   chain.set_code(N(tic.tac.toe), tic_tac_toe_wast);
   chain.set_abi(N(tic.tac.toe), tic_tac_toe_abi);

   chain.produce_blocks();
   chain.create_account(N(player1));
   chain.create_account(N(player2));
   chain.produce_blocks(10);

   chain.push_action(N(tic.tac.toe), N(create), N(player1), mutable_variant_object()
           ("challenger", "player2")
           ("host", "player1")
   );

   chain.produce_blocks();

   auto mvt = mutable_variant_object()
           ("row", 1)
           ("column", 1);
   chain.push_action(N(tic.tac.toe), N(move), N(player1), mutable_variant_object()
           ("challenger", "player2")
           ("host", "player1")
           ("by", "player1")
           ("mvt", mvt)
   );

   mvt = mutable_variant_object()
           ("row", 0)
           ("column", 1);
   BOOST_CHECK_EXCEPTION(chain.push_action(N(tic.tac.toe), N(move), N(player1), mutable_variant_object()
         ("challenger", "player2")
         ("host", "player1")
         ("by", "player1")
         ("mvt", mvt)
      ), transaction_exception, assert_message_contains("not your turn"));

   mvt = mutable_variant_object()
           ("row", 1)
           ("column", 1);
   BOOST_CHECK_EXCEPTION(chain.push_action(N(tic.tac.toe), N(move), N(player2), mutable_variant_object()
         ("challenger", "player2")
         ("host", "player1")
         ("by", "player2")
         ("mvt", mvt)
      ), transaction_exception, assert_message_contains("not a valid movement"));

   mvt = mutable_variant_object()
           ("row", 0)
           ("column", 1);
   chain.push_action(N(tic.tac.toe), N(move), N(player2), mutable_variant_object()
           ("challenger", "player2")
           ("host", "player1")
           ("by", "player2")
           ("mvt", mvt)
   );

   mvt = mutable_variant_object()
           ("row", 0)
           ("column", 0 );
   chain.push_action(N(tic.tac.toe), N(move), N(player1), mutable_variant_object()
           ("challenger", "player2")
           ("host", "player1")
           ("by", "player1")
           ("mvt", mvt)
   );

   mvt = mutable_variant_object()
           ("row", 0)
           ("column", 2);
   chain.push_action(N(tic.tac.toe), N(move), N(player2), mutable_variant_object()
           ("challenger", "player2")
           ("host", "player1")
           ("by", "player2")
           ("mvt", mvt)
   );

   mvt = mutable_variant_object()
           ("row", 2)
           ("column", 2);
   chain.push_action(N(tic.tac.toe), N(move), N(player1), mutable_variant_object()
           ("challenger", "player2")
           ("host", "player1")
           ("by", "player1")
           ("mvt", mvt)
   );

   mvt = mutable_variant_object()
           ("row", 2)
           ("column", 0);
   BOOST_CHECK_EXCEPTION(chain.push_action(N(tic.tac.toe), N(move), N(player2), mutable_variant_object()
         ("challenger", "player2")
         ("host", "player1")
         ("by", "player2")
         ("mvt", mvt)
      ), transaction_exception, assert_message_contains("the game has ended"));

   game current;
   chain.get_table_entry(current, N(tic.tac.toe), N(player1), N(games), N(player2));
   BOOST_REQUIRE_EQUAL("player1", account_name(current.winner).to_string());

   chain.push_action(N(tic.tac.toe), N(close), N(player1), mutable_variant_object()
           ("challenger", "player2")
           ("host", "player1")
   );

   mvt = mutable_variant_object()
           ("row", 2)
           ("column", 0);
   BOOST_CHECK_EXCEPTION(chain.push_action(N(tic.tac.toe), N(move), N(player2), mutable_variant_object()
         ("challenger", "player2")
         ("host", "player1")
         ("by", "player2")
         ("mvt", mvt)
      ), transaction_exception, assert_message_contains("game doesn't exists"));

   BOOST_CHECK_EXCEPTION(chain.push_action(N(tic.tac.toe), N(restart), N(player2), mutable_variant_object()
         ("challenger", "player2")
         ("host", "player1")
         ("by", "player2")
      ), transaction_exception, assert_message_contains("game doesn't exists"));

   chain.push_action(N(tic.tac.toe), N(create), N(player2), mutable_variant_object()
           ("challenger", "player1")
           ("host", "player2")
   );

{'fraction_non_alphanumeric': 0.16471943393121605, 'fraction_numerical': 0.013575777521803521, 'mean_word_length': 3.1583989052343484, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2874271', 'n_tokens_mistral': 4421, 'n_tokens_neox': 4243, 'n_words': 745}