Best Python code snippet using lemoncheesecake
GetContractResult.py
Source:GetContractResult.py  
...70        if check_that("contract_result", contract_result, has_length(2)):71            check_that_in(contract_result, "exec_res", is_dict(), "tr_receipt", is_dict(), quiet=True)72            exec_res = contract_result["exec_res"]73            if check_that("exec_res", exec_res, has_length(6)):74                require_that_in(exec_res, "excepted", equal_to("None"), "code_deposit", equal_to("Success"), quiet=True)75                if not self.type_validator.is_hex(exec_res["new_address"]):76                    lcc.log_error("Wrong format of 'new_address', got: {}".format(exec_res["new_address"]))77                else:78                    lcc.log_info("'new_address' has correct format: hex")79                self.contract_id = self.get_contract_id(response)80                contract_output_in_hex = exec_res["output"]81                if not self.type_validator.is_hex(contract_output_in_hex):82                    lcc.log_error("Wrong format of 'output', got: {}".format(contract_output_in_hex))83                else:84                    lcc.log_info("'output' has correct format: hex")85                contract_output_bytecode_length = len(contract_output_in_hex)86                check_that_in(87                    exec_res,88                    "gas_for_deposit",89                    greater_than(0),90                    "deposit_size",91                    equal_to(contract_output_bytecode_length // 2),92                    quiet=True93                )94            tr_receipt = contract_result["tr_receipt"]95            if check_that("tr_receipt", tr_receipt, has_length(4)):96                check_that_in(97                    tr_receipt,98                    "status_code",99                    equal_to(1),100                    # Note: the value in the field 'gas_used' is checked in the 'GasUsed' scenario101                    "gas_used",102                    greater_than(0),103                    quiet=True104                )105                require_that_in(tr_receipt, "log", equal_to([]), quiet=True)106                self.check_zero_bloom(tr_receipt["bloom"])107        lcc.set_step("Call method 'getPennie'")108        operation = self.echo_ops.get_contract_call_operation(109            echo=self.echo, registrar=self.echo_acc0, bytecode=self.getPennie, callee=self.contract_id110        )111        collected_operation = self.collect_operations(operation, self.__database_api_identifier)112        broadcast_result = self.echo_ops.broadcast(113            echo=self.echo, list_operations=collected_operation, log_broadcast=False114        )115        contract_call_result_id = self.get_operation_results_ids(broadcast_result)116        lcc.log_info(117            "Method 'getPennie' performed successfully, contract call result id: '{}'".format(contract_call_result_id)118        )119        lcc.set_step("Get contract call result of created contract")120        response_id = self.send_request(121            self.get_request("get_contract_result", [contract_call_result_id]), self.__database_api_identifier122        )123        response = self.get_response(response_id)124        contract_call_result = response["result"][1]125        lcc.log_info(126            "Call method 'get_contract_result' with contract_call_result_id='{}' param".format(contract_result_id)127        )128        lcc.set_step("Check contract call result")129        if check_that("contract_call_result", contract_call_result, has_length(2)):130            exec_res = contract_call_result["exec_res"]131            if check_that("exec_res", exec_res, has_length(6)):132                require_that_in(133                    exec_res,134                    "excepted",135                    equal_to("None"),136                    "code_deposit",137                    equal_to("None"),138                    "gas_for_deposit",139                    equal_to(0),140                    "deposit_size",141                    equal_to(0),142                    quiet=True143                )144                check_that_in(exec_res, "output", is_str(), quiet=True)145                tr_receipt = contract_call_result["tr_receipt"]146                if check_that("tr_receipt", tr_receipt, has_length(4)):...GetContracts.py
Source:GetContracts.py  
...58        lcc.set_step("Check simple work of method 'get_contracts'")59        for i, result in enumerate(get_contracts_results):60            lcc.set_step("Checking contract object #{} - '{}'".format(i, params[i]))61            self.object_validator.validate_contract_object(self, result)62            require_that_in(63                result,64                "destroyed",65                is_false(),66                "type",67                equal_to("evm"),68                "supported_asset_id",69                equal_to(self.echo_asset),70                "owner",71                equal_to(self.echo_acc0),72                quiet=True73            )74        lcc.set_step("Get contract object")75        response_id = self.send_request(self.get_request("get_objects", [params]), self.__database_api_identifier)76        get_objects_results = self.get_response(response_id)["result"]77        lcc.log_info("Call method 'get_objects' with params: {}".format(params))78        lcc.set_step("Check length of received objects")79        require_that("'list of received objects'", get_objects_results, has_length(len(params)), quiet=True)80        lcc.set_step("Check the identity of returned results of api-methods: 'get_contracts', 'get_objects'")81        require_that('results', get_objects_results, equal_to(get_contracts_results), quiet=True)82        lcc.set_step("Get contract result object")83        params = [contract_result_id]84        response_id = self.send_request(self.get_request("get_objects", [params]), self.__database_api_identifier)85        get_objects_results = self.get_response(response_id)["result"]86        lcc.log_info("Call method 'get_objects' with param: '{}'".format(contract_id))87        lcc.set_step("Check length of received objects")88        require_that("'list of received objects'", get_objects_results, has_length(len(params)), quiet=True)89        for i, result in enumerate(get_objects_results):90            lcc.set_step("Checking contract result object #{} - '{}'".format(i, params[i]))91            self.object_validator.validate_contract_result_object(self, result)92            require_that_in(93                result,94                "id",95                equal_to(contract_result_id),96                "type",97                equal_to("evm"),98                "contracts_id",99                equal_to([contract_id]),100                quiet=True101            )102@lcc.prop("positive", "type")103@lcc.tags("api", "database_api", "database_api_contracts", "get_contracts")104@lcc.suite("Positive testing of method 'get_contracts'", rank=2)105class PositiveTesting(BaseTest):106    def __init__(self):107        super().__init__()108        self.__database_api_identifier = None109        self.__registration_api_identifier = None110        self.echo_acc0 = None111        self.echo_acc1 = None112        self.contract_1 = self.get_byte_code("piggy", "code")113        self.break_piggy = self.get_byte_code("piggy", "breakPiggy()")114        self.contract_2 = self.get_byte_code("asset_int", "code")115    @staticmethod116    def check_contracts_ids(response, contracts):117        results = response["result"]118        if require_that("contracts info", results, has_length(len(contracts))):119            for i, result in enumerate(results):120                lcc.log_info("Check contract #{}:".format(i))121                require_that_in(122                    result,123                    ["id"],124                    is_str(contracts[i]),125                )126    def setup_suite(self):127        super().setup_suite()128        self._connect_to_echopy_lib()129        lcc.set_step("Setup for {}".format(self.__class__.__name__))130        self.__database_api_identifier = self.get_identifier("database")131        self.__registration_api_identifier = self.get_identifier("registration")132        lcc.log_info(133            "API identifiers are: database='{}', registration='{}'".format(134                self.__database_api_identifier, self.__registration_api_identifier135            )...Transaction.py
Source:Transaction.py  
...31        return payload32    def get_ethrpc_response(self, payload):33        response = requests.post(ETHRPC_URL, json=payload).json()34        if require_that("eth-rpc response", response, has_length(3)):35            require_that_in(response, "id", is_integer(), "jsonrpc", equal_to("2.0"))36            return response37    def transfer(self):38        transfer_operation = self.echo_ops.get_transfer_operation(39            echo=self.echo, from_account_id=self.echo_acc0, to_account_id=self.echo_acc1, amount=140        )41        collected_operation = self.collect_operations(transfer_operation, self.__database_api_identifier)42        signed_tx = self.echo_ops.broadcast(echo=self.echo, list_operations=collected_operation, ethrpc_broadcast=True)43        signatures = signed_tx["signatures"]44        signatures_hex = bytes(signatures).hex()[2:]45        del signed_tx["signatures"]46        signed_tx_hex = bytes(signed_tx).hex()47        params = [signed_tx_hex + "01" + signatures_hex + "00"]48        payload = self.rpc_call("eth_sendRawTransaction", params)49        trx_hash = self.get_ethrpc_response(payload)["result"]50        return trx_hash51    def create_contract(self):52        operation = self.echo_ops.get_contract_create_operation(53            echo=self.echo,54            registrar=self.echo_acc0,55            bytecode=self.contract,56            value_amount=1,57            value_asset_id=self.echo_asset58        )59        collected_operation = self.collect_operations(operation, self.__database_api_identifier)60        broadcast_result = self.echo_ops.broadcast(echo=self.echo, list_operations=collected_operation)61        contract_result = self.get_contract_result(broadcast_result, self.__database_api_identifier)62        contract_id = self.get_contract_id(contract_result)63        contract_address = self.contract_address[:-1] + hex(int(contract_id.split(".")[-1]))[-1]64        lcc.log_info("Created contract address: {}".format(contract_address))65        return contract_address66    def setup_suite(self):67        super().setup_suite()68        self._connect_to_echopy_lib()69        lcc.set_step("Setup for {}".format(self.__class__.__name__))70        self.__database_api_identifier = self.get_identifier("database")71        self.__registration_api_identifier = self.get_identifier("registration")72        lcc.log_info(73            "API identifiers are: database='{}', registration='{}'".format(74                self.__database_api_identifier, self.__registration_api_identifier75            )76        )77        self.echo_acc0 = self.get_account_id(78            self.accounts[0], self.__database_api_identifier, self.__registration_api_identifier79        )80        self.echo_acc1 = self.get_account_id(81            self.accounts[1], self.__database_api_identifier, self.__registration_api_identifier82        )83        lcc.log_info("Echo accounts are: #1='{}', #2='{}'".format(self.echo_acc0, self.echo_acc1))84        self.account_address = "0x0000000000000000000000000000000000000006"85        self.contract_address = "0x0100000000000000000000000000000000000000"86    def teardown_suite(self):87        self._disconnect_to_echopy_lib()88        super().teardown_suite()89    @lcc.test("Check connection to EthPRC interface.")90    def main_check(self):91        message = {92            'code': -32600,93            'message': 'Missing or invalid method'94        }95        payload = self.rpc_call("", "")96        response = requests.post(ETHRPC_URL, json=payload).json()97        if require_that("json-rpc response", response, has_length(3)):98            require_that_in(response, "id", is_none(), "jsonrpc", equal_to("2.0"), "error", equal_to(message))99    @lcc.test("Check method 'eth_getBlockTransactionCountByHash'")100    @lcc.depends_on("EthRPC.Transaction.Transaction.main_check")101    def eth_get_block_transaction_count_by_trx_hash(self):102        self.transfer()103        block_id = self.get_ethrpc_response(self.rpc_call("eth_blockNumber", []))104        block_hash = self.get_ethrpc_response(self.rpc_call("eth_getBlockByNumber",105                                                            [block_id["result"], True]))["result"]["hash"]106        payload = self.rpc_call("eth_getBlockTransactionCountByHash", [block_hash])107        response = self.get_ethrpc_response(payload)108        require_that("'result'", response["result"], equal_to("0x01"))109    @lcc.test("Check method 'eth_getBalance'")110    @lcc.depends_on("EthRPC.Transaction.Transaction.main_check")111    def eth_get_balance(self):112        payload = self.rpc_call("eth_getBalance", [self.account_address, "latest"])...GetAccountDeposits.py
Source:GetAccountDeposits.py  
...176        for i, deposit in enumerate(get_account_deposits_results):177            lcc.set_step("Check account deposit #{}".format(i))178            self.object_validator.validate_deposit_eth_object(self, deposit)179            deposit_ids.append(deposit["id"])180            require_that_in(181                deposit,182                "account",183                is_(new_account),184                "is_approved",185                is_true(),186                "value",187                is_(deposit_values[i]),188                quiet=True189            )190        lcc.set_step("Get deposit by id using 'get_objects'")191        params = deposit_ids192        response_id = self.send_request(self.get_request("get_objects", [params]), self.__database_api_identifier)193        get_objects_results = self.get_response(response_id)["result"]194        lcc.log_info("Call method 'get_objects' with param: {}".format(params))...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
