File size: 533 Bytes
5fe2042
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env python
# -*- coding: utf-8 -*-


import os
import subprocess


def evaluate_solution(task_id: str, solution: str):
    initial_dir = os.getcwd()
    task_dir = task_id.replace('/', '_')
    task_path = 'tasks/' + task_dir
    os.chdir(task_path)

    with open('contracts/Task.sol', 'w') as f:
        f.write(solution)
    try:
        subprocess.run(['npx', 'hardhat', 'test'], check=True)
        return True
    except subprocess.CalledProcessError:
        return False
    finally:
        os.chdir(initial_dir)