From 1d6d1cac08f2aea932e6c4e71a109ef241249868 Mon Sep 17 00:00:00 2001 From: Andrei Bancioiu Date: Fri, 4 Mar 2022 23:31:59 +0200 Subject: [PATCH] Bit of cleanup (remove deprecated files / functionality) --- erdpy/CLI.md | 107 +----------- erdpy/CLI.md.sh | 6 - erdpy/cli.py | 2 - erdpy/cli_dispatcher.py | 53 ------ erdpy/dispatcher/__init__.py | 0 erdpy/dispatcher/scenario.py | 0 erdpy/dispatcher/scenarios/example.py | 39 ----- erdpy/dispatcher/scenarios/mint.py | 53 ------ erdpy/dispatcher/scenarios/sweepable.py | 50 ------ erdpy/dispatcher/transactions/README.md | 36 ---- erdpy/dispatcher/transactions/__init__.py | 0 erdpy/dispatcher/transactions/queue.py | 163 ------------------ erdpy/projects/project_sol.py | 104 +---------- erdpy/projects/sol_main_ll.txt | 11 -- erdpy/projects/templates.py | 6 - erdpy/tests/README.md | 7 - erdpy/tests/test_dispatcher_transactions.py | 69 -------- erdpy/tests/test_solidity.py | 65 ------- .../testdata/solidity_hello/hello.functions | 1 - erdpy/tests/testdata/solidity_hello/hello.sol | 7 - .../testdata/solidity_soll_001/0-0-1.sol | 39 ----- .../testdata/solidity_soll_002/0-0-2.sol | 123 ------------- .../testdata/solidity_soll_003/0-0-3.sol | 44 ----- 23 files changed, 6 insertions(+), 979 deletions(-) delete mode 100644 erdpy/cli_dispatcher.py delete mode 100644 erdpy/dispatcher/__init__.py delete mode 100644 erdpy/dispatcher/scenario.py delete mode 100644 erdpy/dispatcher/scenarios/example.py delete mode 100644 erdpy/dispatcher/scenarios/mint.py delete mode 100644 erdpy/dispatcher/scenarios/sweepable.py delete mode 100644 erdpy/dispatcher/transactions/README.md delete mode 100644 erdpy/dispatcher/transactions/__init__.py delete mode 100644 erdpy/dispatcher/transactions/queue.py delete mode 100644 erdpy/projects/sol_main_ll.txt delete mode 100644 erdpy/tests/README.md delete mode 100644 erdpy/tests/test_dispatcher_transactions.py delete mode 100644 erdpy/tests/test_solidity.py delete mode 100644 erdpy/tests/testdata/solidity_hello/hello.functions delete mode 100644 erdpy/tests/testdata/solidity_hello/hello.sol delete mode 100644 erdpy/tests/testdata/solidity_soll_001/0-0-1.sol delete mode 100644 erdpy/tests/testdata/solidity_soll_002/0-0-2.sol delete mode 100644 erdpy/tests/testdata/solidity_soll_003/0-0-3.sol diff --git a/erdpy/CLI.md b/erdpy/CLI.md index d5bf7548..6b3435f3 100644 --- a/erdpy/CLI.md +++ b/erdpy/CLI.md @@ -20,7 +20,7 @@ https://docs.elrond.com/sdk-and-tools/erdpy/erdpy. COMMAND GROUPS: - {contract,tx,validator,account,ledger,wallet,network,dispatcher,blockatlas,deps,config,hyperblock,testnet,data,staking-provider,dns} + {contract,tx,validator,account,ledger,wallet,network,blockatlas,deps,config,hyperblock,testnet,data,staking-provider,dns} TOP-LEVEL OPTIONS: -h, --help show this help message and exit @@ -37,7 +37,6 @@ account Get Account data (nonce, balance) from the Networ ledger Get Ledger App addresses and version wallet Create wallet, derive secret key from mnemonic, bech32 address helpers etc. network Get Network parameters, such as number of shards, chain identifier etc. -dispatcher Enqueue transactions, then bulk dispatch them blockatlas Interact with an Block Atlas instance deps Manage dependencies or elrond-sdk modules config Configure elrond-sdk (default values etc.) @@ -1117,110 +1116,6 @@ optional arguments: -h, --help show this help message and exit --proxy PROXY 🔗 the URL of the proxy (default: https://testnet-gateway.elrond.com) -``` -## Group **Dispatcher** - - -``` -$ erdpy dispatcher --help -usage: erdpy dispatcher COMMAND [-h] ... - -Enqueue transactions, then bulk dispatch them - -COMMANDS: - {enqueue,dispatch,dispatch-continuously,clean} - -OPTIONS: - -h, --help show this help message and exit - ----------------- -COMMANDS summary ----------------- -enqueue Enqueue a transaction -dispatch Dispatch queued transactions -dispatch-continuously Continuously dispatch queued transactions -clean Clear queue of transactions - -``` -### Dispatcher.Enqueue - - -``` -$ erdpy dispatcher enqueue --help -usage: erdpy dispatcher enqueue [-h] ... - -Enqueue a transaction - -optional arguments: - -h, --help show this help message and exit - --receiver RECEIVER 🖄 the address of the receiver - --receiver-username RECEIVER_USERNAME 🖄 the username of the receiver - --gas-price GAS_PRICE ⛽ the gas price (default: 1000000000) - --gas-limit GAS_LIMIT ⛽ the gas limit - --value VALUE the value to transfer (default: 0) - --data DATA the payload, or 'memo' of the transaction (default: ) - --chain CHAIN the chain identifier (default: T) - --version VERSION the transaction version (default: 1) - --options OPTIONS the transaction options (default: 0) - -``` -### Dispatcher.Dispatch - - -``` -$ erdpy dispatcher dispatch --help -usage: erdpy dispatcher dispatch [-h] ... - -Dispatch queued transactions - -optional arguments: - -h, --help show this help message and exit - --proxy PROXY 🔗 the URL of the proxy (default: https://testnet-gateway.elrond.com) - --pem PEM 🔑 the PEM file, if keyfile not provided - --pem-index PEM_INDEX 🔑 the index in the PEM file (default: 0) - --keyfile KEYFILE 🔑 a JSON keyfile, if PEM not provided - --passfile PASSFILE 🔑 a file containing keyfile's password, if keyfile provided - --ledger 🔐 bool flag for signing transaction using ledger - --ledger-account-index LEDGER_ACCOUNT_INDEX 🔐 the index of the account when using Ledger - --ledger-address-index LEDGER_ADDRESS_INDEX 🔐 the index of the address when using Ledger - --sender-username SENDER_USERNAME 🖄 the username of the sender - -``` -### Dispatcher.DispatchContinuously - - -``` -$ erdpy dispatcher dispatch-continuously --help -usage: erdpy dispatcher dispatch-continuously [-h] ... - -Continuously dispatch queued transactions - -optional arguments: - -h, --help show this help message and exit - --proxy PROXY 🔗 the URL of the proxy (default: https://testnet-gateway.elrond.com) - --pem PEM 🔑 the PEM file, if keyfile not provided - --pem-index PEM_INDEX 🔑 the index in the PEM file (default: 0) - --keyfile KEYFILE 🔑 a JSON keyfile, if PEM not provided - --passfile PASSFILE 🔑 a file containing keyfile's password, if keyfile provided - --ledger 🔐 bool flag for signing transaction using ledger - --ledger-account-index LEDGER_ACCOUNT_INDEX 🔐 the index of the account when using Ledger - --ledger-address-index LEDGER_ADDRESS_INDEX 🔐 the index of the address when using Ledger - --sender-username SENDER_USERNAME 🖄 the username of the sender - --interval INTERVAL the interval to retrieve transactions from the queue, in seconds - -``` -### Dispatcher.Clean - - -``` -$ erdpy dispatcher clean --help -usage: erdpy dispatcher clean [-h] ... - -Clear queue of transactions - -optional arguments: - -h, --help show this help message and exit - ``` ## Group **BlockAtlas** diff --git a/erdpy/CLI.md.sh b/erdpy/CLI.md.sh index 6adb21ea..13ee53d0 100755 --- a/erdpy/CLI.md.sh +++ b/erdpy/CLI.md.sh @@ -84,12 +84,6 @@ generate() { command "Network.BlockNonce" "network block-nonce" command "Network.Chain" "network chain" - group "Dispatcher" "dispatcher" - command "Dispatcher.Enqueue" "dispatcher enqueue" - command "Dispatcher.Dispatch" "dispatcher dispatch" - command "Dispatcher.DispatchContinuously" "dispatcher dispatch-continuously" - command "Dispatcher.Clean" "dispatcher clean" - group "BlockAtlas" "blockatlas" command "BlockAtlas.CurrentBlockNumber" "blockatlas current-block-number" command "BlockAtlas.BlockByNumber" "blockatlas block-by-number" diff --git a/erdpy/cli.py b/erdpy/cli.py index 72c2987c..97e81037 100644 --- a/erdpy/cli.py +++ b/erdpy/cli.py @@ -11,7 +11,6 @@ import erdpy.cli_contracts import erdpy.cli_data import erdpy.cli_deps -import erdpy.cli_dispatcher import erdpy.cli_ledger import erdpy.cli_network import erdpy.cli_testnet @@ -90,7 +89,6 @@ def setup_parser(args: List[str] = sys.argv[1:]): commands.append(erdpy.cli_ledger.setup_parser(subparsers)) commands.append(erdpy.cli_wallet.setup_parser(args, subparsers)) commands.append(erdpy.cli_network.setup_parser(subparsers)) - commands.append(erdpy.cli_dispatcher.setup_parser(args, subparsers)) commands.append(erdpy.cli_blockatlas.setup_parser(subparsers)) commands.append(erdpy.cli_deps.setup_parser(subparsers)) commands.append(erdpy.cli_config.setup_parser(subparsers)) diff --git a/erdpy/cli_dispatcher.py b/erdpy/cli_dispatcher.py deleted file mode 100644 index bffe7e94..00000000 --- a/erdpy/cli_dispatcher.py +++ /dev/null @@ -1,53 +0,0 @@ -from erdpy.dispatcher.transactions.queue import TransactionQueue -import logging -from typing import Any, List - -from erdpy import cli_shared - -logger = logging.getLogger("cli.dispatcher") - - -def setup_parser(args: List[str], subparsers: Any) -> Any: - parser = cli_shared.add_group_subparser(subparsers, "dispatcher", "Enqueue transactions, then bulk dispatch them") - subparsers = parser.add_subparsers() - - sub = cli_shared.add_command_subparser(subparsers, "dispatcher", "enqueue", "Enqueue a transaction") - cli_shared.add_tx_args(args, sub, with_nonce=False) - sub.set_defaults(func=enqueue_transaction) - - sub = cli_shared.add_command_subparser(subparsers, "dispatcher", "dispatch", "Dispatch queued transactions") - cli_shared.add_proxy_arg(sub) - cli_shared.add_wallet_args(args, sub) - sub.set_defaults(func=dispatch_transactions) - - sub = cli_shared.add_command_subparser(subparsers, "dispatcher", "dispatch-continuously", "Continuously dispatch queued transactions") - cli_shared.add_proxy_arg(sub) - cli_shared.add_wallet_args(args, sub) - sub.add_argument("--interval", required=True, help="the interval to retrieve transactions from the queue, in seconds") - sub.set_defaults(func=dispatch_transactions_continuously) - - sub = cli_shared.add_command_subparser(subparsers, "dispatcher", "clean", "Clear queue of transactions") - sub.set_defaults(func=clean_transactions_queue) - - parser.epilog = cli_shared.build_group_epilog(subparsers) - return subparsers - - -def enqueue_transaction(args: Any): - queue = TransactionQueue() - queue.enqueue_transaction(args) - - -def dispatch_transactions(args: Any): - queue = TransactionQueue() - queue.dispatch_transactions(args) - - -def dispatch_transactions_continuously(args: Any): - queue = TransactionQueue() - queue.dispatch_transactions_continuously(args) - - -def clean_transactions_queue(): - queue = TransactionQueue() - queue.clean_transactions_queue() diff --git a/erdpy/dispatcher/__init__.py b/erdpy/dispatcher/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/erdpy/dispatcher/scenario.py b/erdpy/dispatcher/scenario.py deleted file mode 100644 index e69de29b..00000000 diff --git a/erdpy/dispatcher/scenarios/example.py b/erdpy/dispatcher/scenarios/example.py deleted file mode 100644 index 26bdf94b..00000000 --- a/erdpy/dispatcher/scenarios/example.py +++ /dev/null @@ -1,39 +0,0 @@ -import logging -from pathlib import Path -import sys -from argparse import ArgumentParser - -from erdpy import errors -from erdpy.accounts import AccountsRepository -from erdpy.proxy import ElrondProxy -from erdpy.transactions import BunchOfTransactions - -logger = logging.getLogger("dipatcher.scenarios") - - -def main(): - parser = ArgumentParser() - parser.add_argument("--proxy", required=True) - parser.add_argument("--pem-folder", required=True) - args = parser.parse_args() - - logging.basicConfig(level=logging.DEBUG) - - proxy = ElrondProxy(args.proxy) - pem_folder = Path(args.pem_folder) - accounts_repository = AccountsRepository(pem_folder) - bob = accounts_repository.get_account("bob") - bob.sync_nonce(proxy) - - bunch = BunchOfTransactions() - bunch.add(bob, "erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz", bob.nonce, 10, "", 100000000000000, 50000) - bunch.add(bob, "erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz", bob.nonce + 1, 10, "", 100000000000000, 50000) - bunch.send(proxy) - - -if __name__ == "__main__": - try: - main() - except errors.KnownError as err: - logger.fatal(err) - sys.exit(1) diff --git a/erdpy/dispatcher/scenarios/mint.py b/erdpy/dispatcher/scenarios/mint.py deleted file mode 100644 index 59726970..00000000 --- a/erdpy/dispatcher/scenarios/mint.py +++ /dev/null @@ -1,53 +0,0 @@ -import logging -from pathlib import Path -import sys -from argparse import ArgumentParser - -from erdpy import errors -from erdpy.accounts import Account, AccountsRepository -from erdpy.proxy import ElrondProxy -from erdpy.transactions import BunchOfTransactions - -logger = logging.getLogger("dipatcher.scenarios") - -GAS_PRICE = 100000000000000 -GAS_LIMIT = 50000 -MINTED_VALUE = 10 - - -def main(): - parser = ArgumentParser() - parser.add_argument("--proxy", required=True) - parser.add_argument("--minter", required=True) - parser.add_argument("--minted-value", required=False, type=int, default=MINTED_VALUE) - parser.add_argument("--minted-folder", required=True) - parser.add_argument("--minted-count", required=False, type=int) - args = parser.parse_args() - - logging.basicConfig(level=logging.DEBUG) - - proxy = ElrondProxy(args.proxy) - bunch = BunchOfTransactions() - minter = Account(pem_file=args.minter) - minted_folder = Path(args.minted_folder) - minted_repository = AccountsRepository(minted_folder) - - if args.minted_count: - minted_repository.generate_accounts(args.minted_count) - - minter.sync_nonce(proxy) - nonce = minter.nonce - value = args.minted_value - for minted in minted_repository.get_all(): - bunch.add(minter, minted.address.bech32(), nonce, value, "", GAS_PRICE, GAS_LIMIT) - nonce += 1 - - bunch.send(proxy) - - -if __name__ == "__main__": - try: - main() - except errors.KnownError as err: - logger.fatal(err) - sys.exit(1) diff --git a/erdpy/dispatcher/scenarios/sweepable.py b/erdpy/dispatcher/scenarios/sweepable.py deleted file mode 100644 index 8a07bc67..00000000 --- a/erdpy/dispatcher/scenarios/sweepable.py +++ /dev/null @@ -1,50 +0,0 @@ -# This is an scenario example used to test a particular scenario within our system tests - -import logging -from pathlib import Path -import sys -from argparse import ArgumentParser - -from erdpy import errors -from erdpy.accounts import AccountsRepository -from erdpy.proxy import ElrondProxy -from erdpy.transactions import BunchOfTransactions - -logger = logging.getLogger("dipatcher.scenarios") - -GAS_PRICE = 100000000000000 -GAS_LIMIT = 50000 - - -def main(): - parser = ArgumentParser() - parser.add_argument("--proxy", required=True) - parser.add_argument("--senders-folder", required=True) - args = parser.parse_args() - - logging.basicConfig(level=logging.DEBUG) - - proxy = ElrondProxy(args.proxy) - bunch = BunchOfTransactions() - senders_folder = Path(args.senders_folder) - senders_repository = AccountsRepository(senders_folder) - - for sender in senders_repository.get_all(): - sender.sync_nonce(proxy) - - # Send bad transactions to self - nonce = sender.nonce + 42 - - for i in range(100): - bunch.add(sender, sender.address.bech32(), nonce, 0, "", GAS_PRICE, GAS_LIMIT) - nonce += 1 - - bunch.send(proxy) - - -if __name__ == "__main__": - try: - main() - except errors.KnownError as err: - logger.fatal(err) - sys.exit(1) diff --git a/erdpy/dispatcher/transactions/README.md b/erdpy/dispatcher/transactions/README.md deleted file mode 100644 index 6c6d6c84..00000000 --- a/erdpy/dispatcher/transactions/README.md +++ /dev/null @@ -1,36 +0,0 @@ -# Transaction dispatcher - -## Features - -### Register (enqueue) a transaction to be sent - -``` -erdpy dispatcher enqueue --value="100" --receiver="erd1cux02zersde0l7hhklzhywcxk4u9n4py5tdxyx7vrvhnza2r4gmq4vw35r" --data="foo" --gas-price=200000000000 --gas-limit=50000000 -``` - -### Dispatch registered (enqueued) transactions - -This operation manages the nonce sequence, signs the transactions and sends them to the blockchain. - -``` -erdpy dispatcher dispatch --proxy="https://testnet-api.elrond.com" --pem="alice.pem" -``` - -### Continuously dispatch transactions - -Same as above, but in a continuous, neverending process. The dispatch takes place at the specified time interval (in seconds). - -``` -erdpy dispatcher dispatch-continuously --proxy="https://testnet-api.elrond.com" -pem="./examples/keys/alice.pem" --interval=30 -``` - -### Unregister (clear) all enqueued transactions - -``` -erdpy dispatcher clean -``` - -## Roadmap - -- Use a database as the queue backend -- Implement a mechanism to check which transactions were executed successfully (we need to use API route `transaction/:hash` and `transaction/:hash/status` ) diff --git a/erdpy/dispatcher/transactions/__init__.py b/erdpy/dispatcher/transactions/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/erdpy/dispatcher/transactions/queue.py b/erdpy/dispatcher/transactions/queue.py deleted file mode 100644 index f4c50cd2..00000000 --- a/erdpy/dispatcher/transactions/queue.py +++ /dev/null @@ -1,163 +0,0 @@ -import json -import logging -import os -from pathlib import Path -import time -from collections import OrderedDict -from os import path - -from erdpy import utils -from erdpy.accounts import Account -from erdpy.proxy.core import ElrondProxy -from erdpy.transactions import BunchOfTransactions -from erdpy.workstation import get_tools_folder - -logger = logging.getLogger("queue") - - -def _prepare_tx(args): - ordered_fields = OrderedDict() - ordered_fields["nonce"] = 0 - ordered_fields["value"] = int(args.value) - ordered_fields["receiver"] = args.receiver - ordered_fields["gasPrice"] = int(args.gas_price) - ordered_fields["gasLimit"] = int(args.gas_limit) - ordered_fields["data"] = args.data - ordered_fields["chain"] = args.chain - ordered_fields["version"] = args.version - - return ordered_fields - - -def _wait_to_execute_txs(proxy, owner, expected_nonce): - new_nonce = 0 - old_time = time.time() - timeout = False - while new_nonce < expected_nonce and not timeout: - owner.sync_nonce(proxy) - new_nonce = owner.nonce - # timeout if passed a minute - timeout = time.time() - old_time > 59 - if timeout: - logger.error("Not all transactions were executed") - else: - logger.info(f"Transactions were executed") - - -class TransactionQueue: - _TXS_FILE_NAME = "txs.json" - _TXS_FIELD_NAME = "transactions" - _TXS_INFO_FILE_NAME = "txs_info.txt" - - def __init__(self): - tools_folder = get_tools_folder() - - txs_file_dir = tools_folder / "transactions" - # create transactions directory if not exits - if not txs_file_dir.exists(): - txs_file_dir.mkdir() - - self.txs_file_path = txs_file_dir / self._TXS_FILE_NAME - if not self.txs_file_path.exists(): - # create transactions file if not exits - utils.write_file(self.txs_file_path, '{"' + self._TXS_FIELD_NAME + '":[]}') - - self.txs_info_file_path = txs_file_dir / self._TXS_INFO_FILE_NAME - if not self.txs_info_file_path.exists(): - utils.write_file(self.txs_info_file_path, f"index:{0}") - - def enqueue_transaction(self, args): - prepared = _prepare_tx(args) - data = self._read_json_file() - temp_data = data[self._TXS_FIELD_NAME] - temp_data.append(prepared) - self._write_json_file(data) - - def _read_json_file(self): - with open(self.txs_file_path, "r") as json_file: - try: - data = json.load(json_file) - except Exception: - logger.error("Cannot read transactions file") - return {self._TXS_FIELD_NAME: []} - return data - - def _write_json_file(self, data): - with open(self.txs_file_path, "w") as json_file: - json.dump(data, json_file, indent=1) - - def _remove_all_transactions(self): - self.txs_file_path.unlink() - - def _read_index(self): - info = utils.read_file(self.txs_info_file_path) - info_slit = info.split(":") - return int(info_slit[1]) - - def clean_transactions_queue(self): - os.remove(self.txs_info_file_path) - os.remove(self.txs_file_path) - - def dispatch_transactions_continuously(self, args): - while True: - logger.info("dispatch_transactions_continuously()") - self.dispatch_transactions(args) - time.sleep(int(args.interval)) - - def dispatch_transactions(self, args): - data = self._read_json_file() - txs = data[self._TXS_FIELD_NAME] - txs_index = self._read_index() - - total_txs = len(txs) - txs_index - if total_txs == 0 or len(txs) == 0: - logger.info("No transactions to dispatch") - return - - proxy = ElrondProxy(args.proxy) - # Need to sync nonce - if args.pem: - owner = Account(pem_file=args.pem) - elif args.keyfile and args.passfile: - owner = Account(key_file=args.keyfile, pass_file=args.passfile) - - owner.sync_nonce(proxy) - nonce = owner.nonce - old_nonce = nonce - - print(nonce) - bunch = BunchOfTransactions() - idx = txs_index - while idx < len(txs): - tx = txs[idx] - # TODO CHECK IF BUNCH OF TRANSACTION generate transactions with chain id and version - bunch.add( - owner, - tx.get("receiver"), - nonce, - tx.get("value"), - tx.get("data"), - tx.get("gasPrice"), - tx.get("gasLimit"), - tx.get("chain"), - tx.get("version") - ) - # increment nonce - nonce += 1 - idx += 1 - - logger.info(f"Sending {total_txs} transactions") - try: - num_sent, hashes = bunch.send(proxy) - except Exception: - logger.error("No valid transactions to send") - num_sent = 0 - hashes = [] - - logger.info(f"{num_sent} transactions were accepted by observers") - for key in hashes: - print(f"tx {txs_index+int(key)}: hash => {hashes[key]}") - - utils.write_file(Path(self.txs_info_file_path), f"index:{len(txs)}") - # wait until transactions are executed - _wait_to_execute_txs(proxy, owner, old_nonce + num_sent) diff --git a/erdpy/projects/project_sol.py b/erdpy/projects/project_sol.py index c49053ee..192db58d 100644 --- a/erdpy/projects/project_sol.py +++ b/erdpy/projects/project_sol.py @@ -1,112 +1,18 @@ import logging -import subprocess -from os import path from pathlib import Path +from typing import List -from erdpy import dependencies, errors, myprocess, utils from erdpy.projects.project_base import Project logger = logging.getLogger("ProjectSol") class ProjectSol(Project): - def __init__(self, directory): + def __init__(self, directory: Path): super().__init__(directory) def perform_build(self): - """ - See https://github.com/second-state/SOLL/blob/master/utils/ll2ewasm_sol - """ + pass - self.unit = self.find_file_globally("*.sol") - self.unit_name = self.unit.stem - self.file_ll = self.unit.with_suffix(".ll") - self.file_functions = self.unit.with_suffix(".functions") - self.file_main_ll = self.unit.with_suffix(".main.ll") - self.file_bc = self.unit.with_suffix(".bc") - self.file_o = self.unit.with_suffix(".o") - - try: - self._create_main_ll() - self._emit_LLVM() - self._emit_funcions() - self._do_llvm_link() - self._do_llvm_opt() - self._do_llc() - self._do_wasm_ld() - except subprocess.CalledProcessError as err: - raise errors.BuildError(err.output) - - def _create_main_ll(self): - logger.info("_create_main_ll") - - package_path = Path(__file__).parent - template_path = package_path.joinpath("sol_main_ll.txt") - template = utils.read_file(template_path) - content = template.replace("{{NAME}}", self.unit_name) - utils.write_file(self.file_main_ll, content) - - def _emit_LLVM(self): - logger.info("_emit_LLVM") - - tool = self._get_soll_path() - args = [tool, "-action", "EmitLLVM", str(self.unit)] - output = myprocess.run_process(args) - utils.write_file(self.file_ll, output) - - def _emit_funcions(self): - logger.info("_emit_funcions") - - tool = self._get_soll_path() - args = [tool, "-action", "EmitFuncSig", str(self.unit)] - output = myprocess.run_process(args) - utils.write_file(self.file_functions, output) - - def _do_llvm_link(self): - logger.info("_do_llvm_link") - - tool = path.join(self._get_llvm_path(), "llvm-link") - args = [tool, self.file_ll, self.file_main_ll, "-o", self.file_bc] - myprocess.run_process(args) - - def _do_llvm_opt(self): - logger.info("_do_llvm_opt") - - tool = path.join(self._get_llvm_path(), "opt") - args = [tool, "-std-link-opts", "-Oz", "-polly", self.file_bc, "-o", self.file_bc] - myprocess.run_process(args) - - def _do_llc(self): - logger.info("_do_llc") - - tool = path.join(self._get_llvm_path(), "llc") - args = [tool, "-O3", "-filetype=obj", self.file_bc, "-o", self.file_o] - myprocess.run_process(args) - - def _do_wasm_ld(self): - logger.info("_do_wasm_ld") - - tool = path.join(self._get_llvm_path(), "wasm-ld") - args = [ - tool, - "--entry", - "main", - "--demangle", - "--no-gc-sections", - "--export-all", - "--allow-undefined", - "--verbose", - self.file_o, - "-o", self.get_file_wasm() - ] - myprocess.run_process(args) - - def _get_soll_path(self): - directory = dependencies.get_module_directory("soll") - return path.join(directory, "soll") - - def _get_llvm_path(self): - return dependencies.get_module_directory("llvm") - - def get_dependencies(self): - return ["soll", "llvm"] + def get_dependencies(self) -> List[str]: + return [] diff --git a/erdpy/projects/sol_main_ll.txt b/erdpy/projects/sol_main_ll.txt deleted file mode 100644 index 1e6c327c..00000000 --- a/erdpy/projects/sol_main_ll.txt +++ /dev/null @@ -1,11 +0,0 @@ -source_filename = "{{NAME}}" -target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" -target triple = "wasm32-unknown-unknown-wasm" -; STUB "deploy.data" as "wasm" -@deploy.data = local_unnamed_addr constant [4 x i8] c"\77\61\73\6D", align 1 -@deploy.size = local_unnamed_addr constant i32 4, align 8 -declare void @solidity.main() -define void @main() { - tail call void @solidity.main() - ret void -} diff --git a/erdpy/projects/templates.py b/erdpy/projects/templates.py index 57ee1cc0..d90e2459 100644 --- a/erdpy/projects/templates.py +++ b/erdpy/projects/templates.py @@ -81,8 +81,6 @@ def _copy_template(template: str, destination_path: Path): def _load_as_template(directory: Path): if shared.is_source_clang(directory): return TemplateClang(directory) - if shared.is_source_sol(directory): - return TemplateSol(directory) if shared.is_source_rust(directory): return TemplateRust(directory) @@ -228,10 +226,6 @@ def _replace_in_files(self, files: List[Path], replacements, ignore_missing: boo utils.write_file(file, content) -class TemplateSol(Template): - pass - - def remove_path(dependency: Any) -> None: try: del dependency["path"] diff --git a/erdpy/tests/README.md b/erdpy/tests/README.md deleted file mode 100644 index a45088ca..00000000 --- a/erdpy/tests/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# TESTS - -Some Solidity code from `testdata` is taken from SOLL's documentation: - -https://github.com/second-state/soll/blob/master/doc/examples - -License: https://github.com/second-state/SOLL/blob/master/LICENSE.spdx \ No newline at end of file diff --git a/erdpy/tests/test_dispatcher_transactions.py b/erdpy/tests/test_dispatcher_transactions.py deleted file mode 100644 index 3e9c6322..00000000 --- a/erdpy/tests/test_dispatcher_transactions.py +++ /dev/null @@ -1,69 +0,0 @@ -import _thread -import time -import unittest - -from erdpy.config import DEFAULT_GAS_PRICE -from erdpy.dispatcher.transactions.queue import TransactionQueue - - -def _create_mock_args(): - args = TestArgs() - args.data = "data1" - args.receiver = "erd12cl2dgtjws8vt9yf4v9869vryt0juv3eq8hzzq6mlm9ck935vs3q9lfnqe" - args.gas_price = DEFAULT_GAS_PRICE - args.gas_limit = 50000 - args.value = "100" - args.nonce = 0 - return args - - -def write_in_queue(): - args = _create_mock_args() - queue = TransactionQueue() - - idx = 0 - while idx < 5000: - args.value = str(idx) - queue.enqueue_transaction(args) - time.sleep(0.001) - idx += 1 - - -class DispatcherTestCase(unittest.TestCase): - # this a manual test needs proxy and pem file with funds - @unittest.skip('manual run only') - def test_multi_thread(self): - _thread.start_new_thread(write_in_queue, ()) - - args = TestArgs() - args.proxy = "http://localhost:7950" - args.pem = "./../../../file.pem" - args.interval = 2 - queue = TransactionQueue() - queue.dispatch_transactions_continuously(args) - - self.assertFalse(False) - - @unittest.skip('manual run only') - def test_enqueue_tx(self): - write_in_queue() - self.assertFalse(False) - - @unittest.skip('manual run only') - def test_dispatcher_txs(self): - args = TestArgs() - args.proxy = "http://localhost:7950" - args.pem = "./../../../file.pem" - queue = TransactionQueue() - queue.dispatch_transactions(args) - self.assertFalse(False) - - @unittest.skip('manual run only') - def test_clean(self): - queue = TransactionQueue() - queue.clean_transactions_queue() - self.assertFalse(False) - - -class TestArgs(object): - pass diff --git a/erdpy/tests/test_solidity.py b/erdpy/tests/test_solidity.py deleted file mode 100644 index 663c3981..00000000 --- a/erdpy/tests/test_solidity.py +++ /dev/null @@ -1,65 +0,0 @@ -import base64 -import logging -import unittest -from pathlib import Path - -from erdpy.tests import utils - -logging.basicConfig(level=logging.ERROR) - - -class ProjectSolidityTestCase(utils.ProjectTestCase): - def setUp(self): - super().setUp() - - @unittest.skip('manual run only') - def test_solidity_hello(self): - _, contract = self.build("solidity_hello") - - def myflow(): - self.deploy(contract) - answer = self.query_number(contract, "getValue()") - self.assertEqual(42, answer) - - self.environment.run_flow(myflow) - - @unittest.skip('manual run only') - def test_solidity_soll_001(self): - _, contract = self.build("solidity_soll_001") - - def myflow(): - self.deploy(contract) - answer = add(30, 12) - self.assertEqual(42, answer) - - def add(a, b): - args = [a, b] - return self.query_number(contract, "add(uint256,uint256)", args) - - self.environment.run_flow(myflow) - - @unittest.skip('manual run only') - def test_solidity_soll_003(self): - _, contract = self.build("solidity_soll_003") - - def myflow(): - self.deploy(contract, owner=self.alice) - - transfer(self.alice, self.bob, 1000) - transfer(self.alice, self.carol, 1000) - self.assertEqual(1000, balance_of(self.bob)) - self.assertEqual(1000, balance_of(self.carol)) - transfer(self.bob, self.carol, 200) - transfer(self.carol, self.bob, 400) - self.assertEqual(1200, balance_of(self.bob)) - self.assertEqual(800, balance_of(self.carol)) - - def transfer(sender, recipient, amount): - args = [recipient.address_formatted(), amount] - self.execute(contract, sender, "transfer(address,uint256)", args) - - def balance_of(account): - args = [account.address_formatted()] - return self.query_number(contract, "balanceOf(address)", args) - - self.environment.run_flow(myflow) diff --git a/erdpy/tests/testdata/solidity_hello/hello.functions b/erdpy/tests/testdata/solidity_hello/hello.functions deleted file mode 100644 index aa33ec53..00000000 --- a/erdpy/tests/testdata/solidity_hello/hello.functions +++ /dev/null @@ -1 +0,0 @@ -20965255: getValue() diff --git a/erdpy/tests/testdata/solidity_hello/hello.sol b/erdpy/tests/testdata/solidity_hello/hello.sol deleted file mode 100644 index 221fca6e..00000000 --- a/erdpy/tests/testdata/solidity_hello/hello.sol +++ /dev/null @@ -1,7 +0,0 @@ -pragma solidity ^0.5.0; - -contract UltimateAnswer { - function getValue() public view returns (uint256) { - return uint256(42); - } -} diff --git a/erdpy/tests/testdata/solidity_soll_001/0-0-1.sol b/erdpy/tests/testdata/solidity_soll_001/0-0-1.sol deleted file mode 100644 index a567b2fd..00000000 --- a/erdpy/tests/testdata/solidity_soll_001/0-0-1.sol +++ /dev/null @@ -1,39 +0,0 @@ -pragma solidity ^0.5.0; - -contract SafeMath { - function add(uint256 a, uint256 b) public pure returns (uint256) { - uint256 c = a + b; - require(c >= a, "SafeMath: addition overflow"); - - return c; - } - - function sub(uint256 a, uint256 b) public pure returns (uint256) { - require(b <= a, "SafeMath: subtraction overflow"); - uint256 c = a - b; - - return c; - } - - function mul(uint256 a, uint256 b) public pure returns (uint256) { - if (a == 0) { - return uint256(0); - } - - uint256 c = a * b; - require(c / a == b, "SafeMath: multiplication overflow"); - - return c; - } - - function div(uint256 a, uint256 b) public pure returns (uint256) { - require(b > 0, "SafeMath: division by zero"); - uint256 c = a / b; - return c; - } - - function mod(uint256 a, uint256 b) public pure returns (uint256) { - require(b != 0, "SafeMath: modulo by zero"); - return a % b; - } -} diff --git a/erdpy/tests/testdata/solidity_soll_002/0-0-2.sol b/erdpy/tests/testdata/solidity_soll_002/0-0-2.sol deleted file mode 100644 index 968d579d..00000000 --- a/erdpy/tests/testdata/solidity_soll_002/0-0-2.sol +++ /dev/null @@ -1,123 +0,0 @@ -pragma solidity ^0.5.0; - -contract ERC20 { - // Safemath - function add(uint256 a, uint256 b) internal pure returns (uint256) { - uint256 c = a + b; - require(c >= a, "SafeMath: addition overflow"); - - return c; - } - - function sub(uint256 a, uint256 b) internal pure returns (uint256) { - require(b <= a, "SafeMath: subtraction overflow"); - uint256 c = a - b; - - return c; - } - - function mul(uint256 a, uint256 b) internal pure returns (uint256) { - // Gas optimization: this is cheaper than requiring 'a' not being zero, but the - // benefit is lost if 'b' is also tested. - // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 - if (a == 0) { - return uint256(0); - } - - uint256 c = a * b; - require(c / a == b, "SafeMath: multiplication overflow"); - - return c; - } - - function div(uint256 a, uint256 b) internal pure returns (uint256) { - require(b > 0, "SafeMath: division by zero"); - uint256 c = a / b; - return c; - } - - function mod(uint256 a, uint256 b) internal pure returns (uint256) { - require(b != 0, "SafeMath: modulo by zero"); - return a % b; - } - - // // real contract - mapping (address => uint256) private _balances; - - mapping (address => mapping (address => uint256)) private _allowances; - - uint256 private _totalSupply; - - function totalSupply() public view returns (uint256) { - return _totalSupply; - } - - function balanceOf(address account) public view returns (uint256) { - return _balances[account]; - } - - function _transfer(address _sender, address recipient, uint256 amount) internal { - require(_sender != address(0), "ERC20: transfer from the zero address"); - require(recipient != address(0), "ERC20: transfer to the zero address"); - - _balances[_sender] = sub(_balances[_sender], amount); - _balances[recipient] = add(_balances[recipient], amount); - } - - function transfer(address recipient, uint256 amount) public returns (bool) { - _transfer(msg.sender, recipient, amount); - return true; - } - - function allowance(address owner, address spender) public view returns (uint256) { - return _allowances[owner][spender]; - } - - function _approve(address owner, address spender, uint256 value) internal { - require(owner != address(0), "ERC20: approve from the zero address"); - require(spender != address(0), "ERC20: approve to the zero address"); - - _allowances[owner][spender] = value; - } - - function approve(address spender, uint256 value) public returns (bool) { - _approve(msg.sender, spender, value); - return true; - } - - function transferFrom(address _sender, address recipient, uint256 amount) public returns (bool) { - _transfer(_sender, recipient, amount); - _approve(_sender, msg.sender, sub(_allowances[_sender][msg.sender], amount)); - return true; - } - - function increaseAllowance(address spender, uint256 addedValue) public returns (bool) { - _approve(msg.sender, spender, add(_allowances[msg.sender][spender], addedValue)); - return true; - } - - function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) { - _approve(msg.sender, spender, sub(_allowances[msg.sender][spender], subtractedValue)); - return true; - } - - function _mint(address account, uint256 amount) internal { - require(account != address(0), "ERC20: mint to the zero address"); - - _totalSupply = add(_totalSupply, amount); - _balances[account] = add(_balances[account], amount); - } - - function _burn(address account, uint256 value) internal { - require(account != address(0), "ERC20: burn from the zero address"); - - _balances[account] = sub(_balances[account], value); - _totalSupply = sub(_totalSupply, value); - } - - function _burnFrom(address account, uint256 amount) internal { - _burn(account, amount); - _approve(account, msg.sender, sub(_allowances[account][msg.sender], amount)); - } - -} diff --git a/erdpy/tests/testdata/solidity_soll_003/0-0-3.sol b/erdpy/tests/testdata/solidity_soll_003/0-0-3.sol deleted file mode 100644 index f8e29550..00000000 --- a/erdpy/tests/testdata/solidity_soll_003/0-0-3.sol +++ /dev/null @@ -1,44 +0,0 @@ -pragma solidity ^0.5.0; -contract Token { - uint256 private totalSupply; - string public name; - string public symbol; - mapping(address => uint256) public balances; - - event Transfer(address indexed _from, address indexed _to, uint256 _value); - - // Safemath - function add(uint256 a, uint256 b) internal pure returns (uint256) { - uint256 c = a + b; - require(c >= a, "SafeMath: addition overflow"); - - return c; - } - - function sub(uint256 a, uint256 b) internal pure returns (uint256) { - require(b <= a, "SafeMath: subtraction overflow"); - uint256 c = a - b; - - return c; - } - - constructor() public { - totalSupply = 100000000; - name = "ERC20TokenDemo"; - symbol = "ETD"; - balances[msg.sender] = totalSupply; - } - - function balanceOf(address account) view public returns (uint256) { - return balances[account]; - } - - function transfer(address to, uint256 amount) public returns (bool) { - balances[msg.sender] = sub(balances[msg.sender], amount); - balances[to] = add(balances[to], amount); - emit Transfer(msg.sender, to, amount); - return true; - } - - function () external payable {} -}