Coverage for tests / integration / test_user_wallet_api.py: 0%

59 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-18 23:20 -0400

1import unittest 

2from graphqler import __main__ 

3from graphqler import config 

4from tests.integration.utils.stats import get_percent_query_mutation_success 

5from tests.integration.utils.run_api import run_node_project, wait_for_server 

6import os 

7import shutil 

8 

9 

10 

11class TestUserWalletApi(unittest.TestCase): 

12 PORT = 4001 

13 URL = f"http://localhost:{PORT}/graphql" 

14 PATH = "ci-test-user-wallet-api/" 

15 API_PATH = "tests/test-apis/user-wallet-api" 

16 CONFIG_PATH = "tests/test-apis/test_configs/user_wallet_api_config.toml" 

17 process = None 

18 process_pid = None 

19 

20 @classmethod 

21 def setUpClass(cls): 

22 # Start the GrapQL server 

23 cls.process = run_node_project(cls.API_PATH, [], str(cls.PORT)) 

24 cls.process_pid = cls.process.pid 

25 

26 # Parse the config 

27 config = __main__.parse_config(cls.CONFIG_PATH) 

28 __main__.set_config(config) 

29 

30 # Wait for the server to to respond 

31 wait_for_server(cls.URL, timeout=30) 

32 

33 @classmethod 

34 def tearDownClass(cls): 

35 if cls.process and cls.process.pid == cls.process_pid: 

36 cls.process.kill() 

37 cls.process.wait() 

38 if os.path.exists(cls.PATH): 

39 try: 

40 shutil.rmtree(cls.PATH) 

41 except Exception as e: 

42 print(f"Error removing directory {cls.PATH}: {e}") 

43 

44 def test_run_compile_mode_generates_valid_introspection_file(self): 

45 print(self.PATH, self.URL) 

46 __main__.run_compile_mode(self.PATH, self.URL) 

47 introspection_path = os.path.join(self.PATH, config.INTROSPECTION_RESULT_FILE_NAME) 

48 self.assertTrue(os.path.exists(introspection_path)) 

49 self.assertGreater(os.path.getsize(introspection_path), 0) 

50 

51 def test_run_fuzz_mode_generates_valid_stats_file(self): 

52 print(self.PATH, self.URL) 

53 __main__.run_compile_mode(self.PATH, self.URL) 

54 __main__.run_fuzz_mode(self.PATH, self.URL) 

55 stats_path = os.path.join(self.PATH, config.STATS_FILE_NAME) 

56 self.assertTrue(os.path.exists(stats_path)) 

57 self.assertGreater(os.path.getsize(stats_path), 0) 

58 

59 def test_run_single_mode_generates_valid_stats_file(self): 

60 print(self.PATH, self.URL) 

61 __main__.run_compile_mode(self.PATH, self.URL) 

62 __main__.run_single_mode(self.PATH, self.URL, "getCurrentRate") 

63 stats_path = os.path.join(self.PATH, config.STATS_FILE_NAME) 

64 self.assertTrue(os.path.exists(stats_path)) 

65 self.assertGreater(os.path.getsize(stats_path), 0) 

66 

67 def test_run_fuzz_mode_has_success_over_ninety_percent(self): 

68 print(self.PATH, self.URL) 

69 __main__.run_compile_mode(self.PATH, self.URL) 

70 __main__.run_fuzz_mode(self.PATH, self.URL) 

71 stats_path = os.path.join(self.PATH, config.STATS_FILE_NAME) 

72 percentage = get_percent_query_mutation_success(stats_path) 

73 self.assertTrue(percentage >= 80)