From 0d2b730ebf37f35d990f7d175ba850cb2a94586e Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sat, 23 Apr 2022 14:36:09 +0000 Subject: [PATCH] unit_tests.py dep: add solc (Solidity compiler) test --- test/include/common.py | 21 +++++++++++++++++++++ test/test_py_d/ts_ethdev.py | 21 ++------------------- test/unit_tests_d/ut_dep.py | 27 ++++++++++++++++++++++++++- 3 files changed, 49 insertions(+), 20 deletions(-) diff --git a/test/include/common.py b/test/include/common.py index b4e87c5e..a46f7e95 100755 --- a/test/include/common.py +++ b/test/include/common.py @@ -24,6 +24,7 @@ class TestSuiteException(Exception): pass class TestSuiteFatalException(Exception): pass import os +from subprocess import run,PIPE from mmgen.common import * from mmgen.devtools import * from mmgen.fileutil import write_data_to_file,get_data_from_file @@ -231,3 +232,23 @@ def test_daemons_ops(*network_ids,op,remove_datadir=False): d.remove_datadir() ret = d.cmd(op,silent=silent) return ret + +tested_solc_ver = '0.8.7' + +def check_solc_ver(): + cmd = 'python3 scripts/create-token.py --check-solc-version' + try: + cp = run(cmd.split(),check=False,stdout=PIPE) + except Exception as e: + die(4,f'Unable to execute {cmd!r}: {e}') + res = cp.stdout.decode().strip() + if cp.returncode == 0: + omsg( + orange(f'Found supported solc version {res}') if res == tested_solc_ver else + yellow(f'WARNING: solc version ({res}) does not match tested version ({tested_solc_ver})') + ) + return True + else: + omsg(yellow('Warning: Solidity compiler (solc) could not be executed or has unsupported version')) + omsg(res) + return False diff --git a/test/test_py_d/ts_ethdev.py b/test/test_py_d/ts_ethdev.py index 76849973..d86c3578 100755 --- a/test/test_py_d/ts_ethdev.py +++ b/test/test_py_d/ts_ethdev.py @@ -51,25 +51,6 @@ amt2 = '888.111122223333444455' parity_devkey_fn = 'parity.devkey' erigon_devkey_fn = 'erigon.devkey' -tested_solc_ver = '0.8.7' - -def check_solc_ver(): - cmd = 'python3 scripts/create-token.py --check-solc-version' - try: - cp = run(cmd.split(),check=False,stdout=PIPE) - except Exception as e: - die(4,f'Unable to execute {cmd!r}: {e}') - res = cp.stdout.decode().strip() - if cp.returncode == 0: - omsg( - orange(f'Found supported solc version {res}') if res == tested_solc_ver else - yellow(f'WARNING: solc version ({res}) does not match tested version ({tested_solc_ver})') - ) - return True - else: - omsg(yellow(res + '\nUsing precompiled contract data')) - return False - vbal1 = '1.2288409' vbal9 = '1.22626295' vbal2 = '99.997088755' @@ -327,6 +308,8 @@ class TestSuiteEthdev(TestSuiteBase,TestSuiteShared): from mmgen.daemon import CoinDaemon self.rpc_port = CoinDaemon(proto=self.proto,test_suite=True).rpc_port self.using_solc = check_solc_ver() + if not self.using_solc: + omsg(yellow('Using precompiled contract data')) write_to_file( joinpath(self.tmpdir,parity_devkey_fn), diff --git a/test/unit_tests_d/ut_dep.py b/test/unit_tests_d/ut_dep.py index 6f185fe4..3d0a42b8 100755 --- a/test/unit_tests_d/ut_dep.py +++ b/test/unit_tests_d/ut_dep.py @@ -6,12 +6,15 @@ test.unit_tests_d.ut_dep: dependency unit tests for the MMGen suite No data verification is performed. """ +from subprocess import run,PIPE + from mmgen.common import * from mmgen.exception import NoLEDSupport +from ..include.common import check_solc_ver class unit_tests: - altcoin_deps = ('pysha3','py_ecc') + altcoin_deps = ('pysha3','py_ecc','solc') win_skip = ('aiohttp','pysha3','led') def led(self,name,ut): @@ -99,3 +102,25 @@ class unit_tests: scrypt(password=passwd,salt=salt,n=2**N,r=r,p=p,maxmem=0,dklen=buflen) return True + + def solc(self,name,ut): + from mmgen.protocol import init_proto + solc_ok = check_solc_ver() + if solc_ok: + cmd = [ + 'python3', + 'scripts/create-token.py', + '--coin=ETH', + '--name=My Fake Token', + '--symbol=FAKE', + '--supply=100000000000000000000000000', + '--decimals=18', + '--stdout', + init_proto('eth').checksummed_addr('deadbeef'*5), + ] + cp = run(cmd,stdout=PIPE,stderr=PIPE) + vmsg(cp.stderr.decode()) + if cp.returncode: + msg(cp.stderr.decode()) + return False + return True