mirror of
				https://github.com/ton-blockchain/ton
				synced 2025-03-09 15:40:10 +00:00 
			
		
		
		
	[FunC] Enrich and refactor testing framework, add negative tests
* fully refactor run_tests.py, make it extensible for the future * an ability to write @compilation_should_fail tests * an ability to launch run_tests.py for a single .fc file * keep run_tests.js in sync with run_tests.py * extract legacy_tests names/hashes to a separate file shared between legacy_tester.py and legacy_tester.js
This commit is contained in:
		
							parent
							
								
									0bc6305f96
								
							
						
					
					
						commit
						a5d2a1003f
					
				
					 9 changed files with 615 additions and 203 deletions
				
			
		|  | @ -1,27 +1,68 @@ | |||
| const fs = require('fs/promises'); | ||||
| // Usage: `node legacy_tests.js` from current dir, providing some env (see getenv() calls).
 | ||||
| // This is a JS version of legacy_tester.py to test FunC compiled to WASM.
 | ||||
| 
 | ||||
| const fs = require('fs'); | ||||
| const path = require('path') | ||||
| const process = require('process'); | ||||
| const { compileWasm, compileFile } = require('./wasm_tests_common'); | ||||
| 
 | ||||
| 
 | ||||
| /** @return {string} */ | ||||
| function getenv(name, def = null) { | ||||
|     if (name in process.env) | ||||
|         return process.env[name] | ||||
|     if (def === null) { | ||||
|         console.log(`Environment variable ${name} is not set`) | ||||
|         process.exit(1) | ||||
|     } | ||||
|     return def | ||||
| } | ||||
| 
 | ||||
| const FUNCFIFTLIB_MODULE = getenv('FUNCFIFTLIB_MODULE') | ||||
| const FUNCFIFTLIB_WASM = getenv('FUNCFIFTLIB_WASM') | ||||
| const TESTS_DIR = "legacy_tests" | ||||
| 
 | ||||
| /** | ||||
|  * @return {{filename: string, code_hash: BigInt}[]} | ||||
|  */ | ||||
| function load_legacy_tests_list(jsonl_filename) { | ||||
|     let contents = fs.readFileSync(jsonl_filename) | ||||
|     let results = [...contents.toString().matchAll(/^\[\s*"(.*?)"\s*,\s*(.*?)\s*]/gms)] | ||||
|     return results.map((line) => ({ | ||||
|         filename: line[1].trim(), | ||||
|         code_hash: BigInt(line[2]), | ||||
|     })) | ||||
| } | ||||
| 
 | ||||
| async function main() { | ||||
|     const tests = JSON.parse((await fs.readFile('../legacy_tests.json')).toString('utf-8')) | ||||
|     const tests = load_legacy_tests_list('legacy_tests.jsonl') | ||||
| 
 | ||||
|     for (const [filename, hashstr] of tests) { | ||||
|         if (filename.includes('storage-provider')) continue; | ||||
|     for (let ti = 0; ti < tests.length; ++ti) { | ||||
|         const {filename: filename_rel, code_hash} = tests[ti] | ||||
|         const filename = path.join(TESTS_DIR, filename_rel) | ||||
|         console.log(`Running test ${ti + 1}/${tests.length}: ${filename_rel}`) | ||||
| 
 | ||||
|         const mod = await compileWasm() | ||||
|         if (filename.includes('storage-provider')) { | ||||
|             console.log("  Skip"); | ||||
|             continue; | ||||
|         } | ||||
| 
 | ||||
|         const response = await compileFile(mod, filename); | ||||
|         const wasmModule = await compileWasm(FUNCFIFTLIB_MODULE, FUNCFIFTLIB_WASM) | ||||
|         const response = compileFile(wasmModule, filename); | ||||
| 
 | ||||
|         if (response.status !== 'ok') { | ||||
|             console.error(response); | ||||
|             throw new Error('Could not compile ' + filename); | ||||
|             throw new Error(`Could not compile ${filename}`); | ||||
|         } | ||||
| 
 | ||||
|         if (BigInt('0x' + response.codeHashHex) !== BigInt(hashstr)) { | ||||
|             throw new Error('Compilation result is different for ' + filename); | ||||
|         if (BigInt('0x' + response.codeHashHex) !== code_hash) { | ||||
|             throw new Error(`Code hash is different for ${filename}`); | ||||
|         } | ||||
| 
 | ||||
|         console.log(filename, 'ok'); | ||||
|         console.log('  OK  '); | ||||
|     } | ||||
| 
 | ||||
|     console.log(`Done ${tests.length}`) | ||||
| } | ||||
| 
 | ||||
| main() | ||||
| main().catch(console.error) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue