Ton

Форк
0
/
legacy_tester.py 
151 строка · 6.8 Кб
1
import os
2
import os.path
3
import subprocess
4
import sys
5
import tempfile
6
import shutil
7

8
add_pragmas = [] #["allow-post-modification", "compute-asm-ltr"];
9

10
tests = [
11
    # note, that deployed version of elector,config and multisig differ since it is compilled with func-0.1.0.
12
    # Newer compillators optimize arithmetic and logic expression that can be calculated at the compile time
13
    ["elector/elector-code.fc", 115226404411715505328583639896096915745686314074575650766750648324043316883483],
14
    ["config/config-code.fc", 10913070768607625342121305745084703121685937915388357634624451844356456145601],
15
    ["eth-bridge-multisig/multisig-code.fc", 101509909129354488841890823627011033360100627957439967918234053299675481277954],
16

17
    ["bsc-bridge-collector/votes-collector.fc", 62190447221288642706570413295807615918589884489514159926097051017036969900417],
18
    ["uni-lock-wallet/uni-lockup-wallet.fc", 61959738324779104851267145467044677651344601417998258530238254441977103654381],
19
    ["nft-collection/nft-collection-editable.fc", 45561997735512210616567774035540357815786262097548276229169737015839077731274],
20
    ["dns-collection/nft-collection.fc", 107999822699841936063083742021519765435859194241091312445235370766165379261859],
21

22

23
    # note, that deployed version of tele-nft-item differs since it is compilled with func-0.3.0.
24
    # After introducing of try/catch construction, c2 register is not always the default one.
25
    # Thus it is necessary to save it upon jumps, differences of deployed and below compilled is that
26
    # "c2 SAVE" is added to the beginning of recv_internal. It does not change behavior.
27
    ["tele-nft-item/nft-item.fc", 69777543125381987786450436977742010705076866061362104025338034583422166453344],
28

29
    ["storage/storage-contract.fc", 91377830060355733016937375216020277778264560226873154627574229667513068328151],
30
    ["storage/storage-provider.fc", 13618336676213331164384407184540461509022654507176709588621016553953760588122],
31
    ["nominator-pool/pool.fc", 69767057279163099864792356875696330339149706521019810113334238732928422055375],
32
    ["jetton-minter/jetton-minter.fc", 9028309926287301331466371999814928201427184114165428257502393474125007156494],
33
    ["gg-marketplace/nft-marketplace-v2.fc", 92199806964112524639740773542356508485601908152150843819273107618799016205930],
34
    ["jetton-wallet/jetton-wallet.fc", 86251125787443633057458168028617933212663498001665054651523310772884328206542],
35
    ["whales-nominators/nominators.fc", 8941364499854379927692172316865293429893094891593442801401542636695127885153],
36

37

38
    ["tact-examples/treasure_Treasure.code.fc", 13962538639825790677138656603323869918938565499584297120566680287245364723897],
39
    ["tact-examples/jetton_SampleJetton.code.fc", 94076762218493729104783735200107713211245710256802265203823917715299139499110],
40
    ["tact-examples/jetton_JettonDefaultWallet.code.fc", 29421313492520031238091587108198906058157443241743283101866538036369069620563],
41
    ["tact-examples/maps_MapTestContract.code.fc", 22556550222249123835909180266811414538971143565993192846012583552876721649744],
42
]
43

44
def getenv(name, default=None):
45
    if name in os.environ:
46
        return os.environ[name]
47
    if default is None:
48
        print("Environment variable", name, "is not set", file=sys.stderr)
49
        exit(1)
50
    return default
51

52
FUNC_EXECUTABLE = getenv("FUNC_EXECUTABLE", "func")
53
FIFT_EXECUTABLE = getenv("FIFT_EXECUTABLE", "fift")
54
TMP_DIR = tempfile.mkdtemp()
55

56
COMPILED_FIF = os.path.join(TMP_DIR, "compiled.fif")
57
RUNNER_FIF = os.path.join(TMP_DIR, "runner.fif")
58

59
TESTS_DIR = "legacy_tests"
60

61
class ExecutionError(Exception):
62
    pass
63

64
def pre_process_func(f):
65
    shutil.copyfile(f, f+"_backup")
66
    with open(f, "r") as src:
67
        sources = src.read()
68
    with open(f, "w") as src:
69
        for pragma in add_pragmas:
70
            src.write("#pragma %s;\n"%pragma)
71
        src.write(sources)
72

73
def post_process_func(f):
74
    shutil.move(f+"_backup", f)
75

76
def compile_func(f):
77
    res = None
78
    try:
79
        pre_process_func(f)
80
        if "storage-provider.fc" in f :
81
            # This contract requires building of storage-contract to include it as ref
82
            with open(f, "r") as src:
83
                sources = src.read()
84
                COMPILED_ST_BOC = os.path.join(TMP_DIR, "storage-contract-code.boc")
85
                sources = sources.replace("storage-contract-code.boc", COMPILED_ST_BOC)
86
            with open(f, "w") as src:
87
                src.write(sources)
88
            COMPILED_ST_FIF = os.path.join(TMP_DIR, "storage-contract.fif")
89
            COMPILED_ST_BOC = os.path.join(TMP_DIR, "storage-contract-code.boc")
90
            COMPILED_BUILD_BOC = os.path.join(TMP_DIR, "build-boc.fif")
91
            res = subprocess.run([FUNC_EXECUTABLE, "-o", COMPILED_ST_FIF, "-SPA", f.replace("storage-provider.fc","storage-contract.fc")], capture_output=False, timeout=10)
92
            with open(COMPILED_BUILD_BOC, "w") as scr:
93
                scr.write("\"%s\" include boc>B \"%s\" B>file "%(COMPILED_ST_FIF, COMPILED_ST_BOC))
94
            res = subprocess.run([FIFT_EXECUTABLE, COMPILED_BUILD_BOC ], capture_output=True, timeout=10)
95

96

97
        res = subprocess.run([FUNC_EXECUTABLE, "-o", COMPILED_FIF, "-SPA", f], capture_output=True, timeout=10)
98
    except Exception as e:
99
        post_process_func(f)
100
        raise e
101
    else:
102
        post_process_func(f)
103
    if res.returncode != 0:
104
        raise ExecutionError(str(res.stderr, "utf-8"))
105

106
def run_runner():
107
    res = subprocess.run([FIFT_EXECUTABLE, RUNNER_FIF], capture_output=True, timeout=10)
108
    if res.returncode != 0:
109
        raise ExecutionError(str(res.stderr, "utf-8"))
110
    s = str(res.stdout, "utf-8")
111
    s = s.strip()
112
    return int(s)
113

114
def get_version():
115
    res = subprocess.run([FUNC_EXECUTABLE, "-s"], capture_output=True, timeout=10)
116
    if res.returncode != 0:
117
        raise ExecutionError(str(res.stderr, "utf-8"))
118
    s = str(res.stdout, "utf-8")
119
    return s.strip()
120

121
success = 0
122
for ti, t in enumerate(tests):
123
    tf, th = t
124
    print("  Running test %d/%d: %s" % (ti + 1, len(tests), tf), file=sys.stderr)
125
    tf = os.path.join(TESTS_DIR, tf)
126
    try:
127
        compile_func(tf)
128
    except ExecutionError as e:
129
        print(file=sys.stderr)
130
        print("Compilation error", file=sys.stderr)
131
        print(e, file=sys.stderr)
132
        exit(2)
133

134
    with open(RUNNER_FIF, "w") as f:
135
        print("\"%s\" include hash .s" % COMPILED_FIF , file=f)
136

137
    try:
138
        func_out = run_runner()
139
        if func_out != th:
140
            raise ExecutionError("Error : expected '%d', found '%d'" % (th, func_out))
141
        success += 1
142
    except ExecutionError as e:
143
        print(e, file=sys.stderr)
144
        print("Compiled:", file=sys.stderr)
145
        with open(COMPILED_FIF, "r") as f:
146
            print(f.read(), file=sys.stderr)
147
        exit(2)
148
    print("  OK  ", file=sys.stderr)
149

150
print(get_version())
151
print("Done: Success %d, Error: %d"%(success, len(tests)-success), file=sys.stderr)

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.