Re-generates examples for doc/schema/lightning-*.json files
(node_factory, bitcoind, executor)
| 2053 | |
| 2054 | @unittest.skipIf(not GENERATE_EXAMPLES, 'Generates examples for doc/schema/lightning-*.json files.') |
| 2055 | def test_generate_examples(node_factory, bitcoind, executor): |
| 2056 | """Re-generates examples for doc/schema/lightning-*.json files""" |
| 2057 | try: |
| 2058 | global ALL_RPC_EXAMPLES, REGENERATING_RPCS |
| 2059 | |
| 2060 | def list_all_examples(): |
| 2061 | """list all methods used in 'update_example' calls to ensure that all methods are covered""" |
| 2062 | try: |
| 2063 | methods = [] |
| 2064 | file_path = os.path.abspath(__file__) |
| 2065 | |
| 2066 | # Parse and traverse this file's content to list all methods & file names |
| 2067 | with open(file_path, "r") as file: |
| 2068 | file_content = file.read() |
| 2069 | tree = ast.parse(file_content) |
| 2070 | for node in ast.walk(tree): |
| 2071 | if isinstance(node, ast.Call) and isinstance(node.func, ast.Name) and node.func.id == 'update_example': |
| 2072 | for keyword in node.keywords: |
| 2073 | if (keyword.arg == 'method' and isinstance(keyword.value, ast.Constant)): |
| 2074 | if keyword.value.value not in methods: |
| 2075 | methods.append(keyword.value.value) |
| 2076 | return methods |
| 2077 | except Exception as e: |
| 2078 | logger.error(f'Error in listing all examples: {e}') |
| 2079 | raise |
| 2080 | |
| 2081 | def list_missing_examples(): |
| 2082 | """Checks for missing example & log an error if missing.""" |
| 2083 | try: |
| 2084 | missing_examples = '' |
| 2085 | for file_name in os.listdir('doc/schemas'): |
| 2086 | if not file_name.endswith('.json'): |
| 2087 | continue |
| 2088 | file_name_str = str(file_name).replace('.json', '') |
| 2089 | # Log an error if the method is not in the list |
| 2090 | if file_name_str not in ALL_RPC_EXAMPLES and file_name_str not in IGNORE_RPCS_LIST: |
| 2091 | missing_examples = missing_examples + f"'{file_name_str}', " |
| 2092 | if missing_examples != '': |
| 2093 | raise MissingExampleError(f"Missing {missing_examples.count(', ')} Examples For: [{missing_examples.rstrip(', ')}]") |
| 2094 | except MissingExampleError: |
| 2095 | raise |
| 2096 | except Exception as e: |
| 2097 | logger.error(f'Error in listing missing examples: {e}') |
| 2098 | raise |
| 2099 | |
| 2100 | ALL_RPC_EXAMPLES = list_all_examples() |
| 2101 | logger.info(f'This test can reproduce examples for {len(ALL_RPC_EXAMPLES)} methods: {ALL_RPC_EXAMPLES}') |
| 2102 | logger.warning(f'This test ignores {len(IGNORE_RPCS_LIST)} rpc methods: {IGNORE_RPCS_LIST}') |
| 2103 | REGENERATING_RPCS = [rpc.strip() for rpc in os.getenv("REGENERATE").split(', ')] if os.getenv("REGENERATE") else ALL_RPC_EXAMPLES |
| 2104 | list_missing_examples() |
| 2105 | l1, l2, l3, l4, l5, l6, c12, c23, c25 = setup_test_nodes(node_factory, bitcoind) |
| 2106 | c23_2, c23res2, c34_2, inv_l11, inv_l21, inv_l22, inv_l31, inv_l32, inv_l34 = generate_transactions_examples(l1, l2, l3, l4, l5, c25, bitcoind) |
| 2107 | rune_l21 = generate_runes_examples(l1, l2, l3) |
| 2108 | generate_datastore_examples(l2) |
| 2109 | generate_coinmvt_examples(l2) |
| 2110 | generate_bookkeeper_examples(l2, l3, c23res2['channel_id']) |
| 2111 | offer_l23, inv_req_l1_l22 = generate_offers_renepay_examples(l1, l2, inv_l21, inv_l34) |
| 2112 | generate_askrene_examples(l1, l2, l3, c12, c23_2) |
nothing calls this directly
no test coverage detected