def test_convert_tx_to_jsonrpc_request_for_deploy_transaction(self): # Update SCORE deploy_transaction = DeployTransactionBuilder() \ .from_(self.setting["from"]) \ .to(self.setting["to"]) \ .step_limit(self.setting["step_limit"]) \ .nid(self.setting["nid"]) \ .content_type(self.setting["content_type"]) \ .content(self.setting["content_update"]) \ .build() tx_dict = SignedTransaction.convert_tx_to_jsonrpc_request( deploy_transaction) self.assertTrue(is_deploy_transaction(tx_dict)) # Install SCORE deploy_transaction = DeployTransactionBuilder() \ .from_(self.setting["from"]) \ .to(self.setting["to_install"]) \ .step_limit(self.setting["step_limit"]) \ .nid(self.setting["nid"]) \ .nonce(self.setting["nonce"]) \ .content_type(self.setting["content_type"]) \ .content(self.setting["content_install"]) \ .params(self.setting["params_install"]) \ .build() tx_dict = SignedTransaction.convert_tx_to_jsonrpc_request( deploy_transaction) self.assertTrue(is_deploy_transaction(tx_dict))
def test_to_dict(self): # Transfer # When having an optional property, nonce icx_transaction = TransactionBuilder().from_(self.setting["from"]).to(self.setting["to"]) \ .value(self.setting["value"]).step_limit(self.setting["step_limit"]).nid(self.setting["nid"]) \ .nonce(self.setting["nonce"]).build() tx_dict = SignedTransaction.convert_tx_to_jsonrpc_request( icx_transaction) self.assertTrue(is_icx_transaction(tx_dict)) # When not having an optional property, nonce icx_transaction = TransactionBuilder().from_(self.setting["from"]).to(self.setting["to"]) \ .value(self.setting["value"]).step_limit(self.setting["step_limit"]).nid(self.setting["nid"]).build() tx_dict = SignedTransaction.convert_tx_to_jsonrpc_request( icx_transaction) self.assertTrue(is_icx_transaction(tx_dict)) # When not having an required property, value icx_transaction = TransactionBuilder().from_(self.setting["from"]).to(self.setting["to"]) \ .step_limit(self.setting["step_limit"]).nid(self.setting["nid"]).build() tx_dict = SignedTransaction.convert_tx_to_jsonrpc_request( icx_transaction) self.assertFalse(is_icx_transaction(tx_dict)) # Update SCORE deploy_transaction = DeployTransactionBuilder().from_(self.setting["from"]).to(self.setting["to"]) \ .step_limit(self.setting["step_limit"]).nid(self.setting["nid"]).content_type(self.setting["content_type"]) \ .content(self.setting["content_update"]).build() tx_dict = SignedTransaction.convert_tx_to_jsonrpc_request( deploy_transaction) self.assertTrue(is_deploy_transaction(tx_dict)) # Install SCORE deploy_transaction = DeployTransactionBuilder().from_(self.setting["from"]).to(self.setting["to_install"]) \ .step_limit(self.setting["step_limit"]).nid(self.setting["nid"]).nonce(self.setting["nonce"]) \ .content_type(self.setting["content_type"]).content(self.setting["content_install"]) \ .params(self.setting["params_install"]).build() tx_dict = SignedTransaction.convert_tx_to_jsonrpc_request( deploy_transaction) self.assertTrue(is_deploy_transaction(tx_dict)) # SCORE method call call_transaction = CallTransactionBuilder().from_(self.setting["from"]).to(self.setting["to"]) \ .step_limit(self.setting["step_limit"]).nid(self.setting["nid"]).nonce(self.setting["nonce"]) \ .method(self.setting["method"]).params(self.setting["params_call"]).build() tx_dict = SignedTransaction.convert_tx_to_jsonrpc_request( call_transaction) self.assertTrue(is_call_transaction(tx_dict)) # Message send msg_transaction = MessageTransactionBuilder().from_(self.setting["from"]).to(self.setting["to"]) \ .step_limit(self.setting["step_limit"]).nid(self.setting["nid"]).data(self.setting["data"]).build() tx_dict = SignedTransaction.convert_tx_to_jsonrpc_request( msg_transaction) self.assertTrue(is_message_transaction(tx_dict))
def test_installing_score_validation(self): # Test install SCORE : When not having an optional property, nonce deploy_transaction = DeployTransactionBuilder().from_(self.setting["from"]).to(self.setting["to_install"]) \ .step_limit(self.setting["step_limit"]).nid(self.setting["nid"]) \ .content_type(self.setting["content_type"]).content(self.setting["content_install"]) \ .build() signed_transaction_dict = SignedTransaction(deploy_transaction, self.wallet) result = self.icon_service.send_transaction(signed_transaction_dict) self.assertTrue(is_T_HASH(result)) # Test install SCORE : When not having a required property, nid deploy_transaction = DeployTransactionBuilder().from_(self.setting["from"]).to(self.setting["to_install"]) \ .step_limit(self.setting["step_limit"]).content_type(self.setting["content_type"])\ .content(self.setting["content_install"]).build() signed_transaction_dict = SignedTransaction(deploy_transaction, self.wallet) self.assertRaises(JSONRPCException, self.icon_service.send_transaction, signed_transaction_dict) # Test install SCORE : When not having a required property - contentType deploy_transaction = DeployTransactionBuilder().from_(self.setting["from"]).to(self.setting["to_install"]) \ .step_limit(self.setting["step_limit"]).nid(self.setting["nid"]) \ .content(self.setting["content_install"]).build() signed_transaction_dict = SignedTransaction(deploy_transaction, self.wallet) self.assertRaises(JSONRPCException, self.icon_service.send_transaction, signed_transaction_dict) # Test install SCORE : When data type of the address is wrong wrong_address = "hx4873b94352c8c1f3b2f09aaeccea31ce9e90" deploy_transaction = DeployTransactionBuilder().from_(wrong_address).to(self.setting["to_install"]) \ .step_limit(self.setting["step_limit"]).nid(self.setting["nid"]) \ .content_type(self.setting["content_type"]).content(self.setting["content_install"]) \ .build() signed_transaction_dict = SignedTransaction(deploy_transaction, self.wallet) self.assertRaises(JSONRPCException, self.icon_service.send_transaction, signed_transaction_dict) # Test install SCORE : When a sending address is wrong - not the wallet's address wrong_address = "hx5bfdb090f43a808005ffc27c25b213145e80b7cd" deploy_transaction = DeployTransactionBuilder().from_(wrong_address).to(self.setting["to_install"]) \ .step_limit(self.setting["step_limit"]).nid(self.setting["nid"]) \ .content_type(self.setting["content_type"]).content(self.setting["content_install"]) \ .build() signed_transaction_dict = SignedTransaction(deploy_transaction, self.wallet) self.assertRaises(JSONRPCException, self.icon_service.send_transaction, signed_transaction_dict)
def _deploy_score(self, to: str = SCORE_INSTALL_ADDRESS) -> dict: dir_path = os.path.abspath(os.path.dirname(__file__)) score_project = os.path.abspath(os.path.join(dir_path, '..')) score_content_bytes = gen_deploy_data_content(score_project) # Generates an instance of transaction for deploying SCORE. transaction = DeployTransactionBuilder() \ .from_(self._wallet.get_address()) \ .to(to) \ .nid(3) \ .step_limit(10000000000) \ .nonce(100) \ .content_type("application/zip") \ .content(score_content_bytes) \ .params({}) \ .build() # Returns the signed transaction object having a signature signed_transaction = SignedTransaction(transaction, self._wallet) # process the transaction in local tx_result = self.process_transaction(signed_transaction, self._icon_service) self.assertEqual(True, tx_result['status'], msg=pp.pformat(tx_result)) self.assertTrue('scoreAddress' in tx_result, msg=pp.pformat(tx_result)) return tx_result
def _deploy_cps_score(self, to: str = SCORE_INSTALL_ADDRESS, params=None) -> dict: if params is None: params = {} transaction = DeployTransactionBuilder() \ .from_(self._test1.get_address()) \ .to(to) \ .step_limit(100_000_000_000) \ .nid(3) \ .nonce(100) \ .content_type("application/zip") \ .content(gen_deploy_data_content(self.CPS_SCORE_PROJECT)) \ .params(params) \ .build() signed_transaction = SignedTransaction(transaction, self._test1) # process the transaction in local tx_result = self.process_transaction(signed_transaction, self.icon_service) self.assertEqual(True, tx_result['status']) self.assertTrue('scoreAddress' in tx_result) pprint(tx_result) return tx_result
def test_send_deploy(self, _make_id): deploy_transaction = DeployTransactionBuilder() \ .from_(self.setting["from"]) \ .to(self.setting["to_install"]) \ .step_limit(self.setting["step_limit"]) \ .nid(self.setting["nid"]) \ .nonce(self.setting["nonce"]) \ .content_type(self.setting["content_type"]) \ .content(self.setting["content_install"]) \ .params(self.setting["params_install"]) \ .build() signed_transaction = SignedTransaction(deploy_transaction, self.wallet) with requests_mock.Mocker() as m: response_json = { "jsonrpc": "2.0", "id": 1234, "result": "0x4bf74e6aeeb43bde5dc8d5b62537a33ac8eb7605ebbdb51b015c1881b45b3aed" } m.post(self.matcher, json=response_json) result_dict = self.icon_service.send_transaction( signed_transaction, full_response=True) actual_request = json.loads(m._adapter.last_request.text) result_content = result_dict['result'] self.assertEqual(result_success_v3.keys(), result_dict.keys()) self.assertTrue(is_T_HASH(result_content))
def _deploy(self, _installContentBytes: bytes, _params: object) -> str: transaction = DeployTransactionBuilder()\ .from_(self._walletOfUc.get_address())\ .to('cx0000000000000000000000000000000000000000')\ .step_limit(1000000000)\ .nid(3)\ .nonce(100)\ .content_type('application/zip')\ .content(_installContentBytes)\ .params(_params)\ .build() signedTransaction = SignedTransaction(transaction, self._walletOfUc) txHash = self._iconService.send_transaction(signedTransaction) scoreAddr = '' for i in range(1, 11): sleep(1) try: txResult = self._iconService.get_transaction_result(txHash) except: continue else: break self.assertNotEqual(txResult, None) scoreAddr = txResult['scoreAddress'] self.assertNotEqual(scoreAddr, '') return scoreAddr
def _deploy_score( self, to: str = SCORE_INSTALL_ADDRESS ) -> dict: #SCORE 배포를위한 트랜잭션 인스턴스를 생성합니다. transaction = DeployTransactionBuilder() \ .from_(self._test1.get_address()) \ .to(to) \ .step_limit(100_000_000_000) \ .nid(3) \ .nonce(100) \ .content_type("application/zip") \ .content(gen_deploy_data_content(self.SCORE_PROJECT)) \ .build() signed_transaction = SignedTransaction( transaction, self._test1) # 서명이있는 서명 된 트랜잭션 객체를 반환합니다. # 로컬에서 거래 처리 tx_result = self.process_transaction(signed_transaction, self.icon_service) self.assertTrue('status' in tx_result) self.assertEqual(1, tx_result['status']) self.assertTrue('scoreAddress' in tx_result) return tx_result
def _deploy_score(self, to: str = SCORE_INSTALL_ADDRESS, params: dict = None) -> dict: # Generates an instance of transaction for deploying SCORE. transaction = DeployTransactionBuilder() \ .from_(self._test1.get_address()) \ .to(to) \ .step_limit(100_000_000_000) \ .nid(3) \ .nonce(100) \ .content_type("application/zip") \ .content(gen_deploy_data_content(self.SCORE_PROJECT)) \ .params(params) \ .build() # Returns the signed transaction object having a signature signed_transaction = SignedTransaction(transaction, self._test1) # process the transaction tx_result = self.process_transaction(signed_transaction, self.icon_service) self.assertTrue('status' in tx_result) self.assertEqual(1, tx_result['status']) self.assertTrue('scoreAddress' in tx_result) return tx_result
def _deploy_smart_wallet(wallet, token_type, contract_addr, sendLimit, dids): deploy_contract = gen_deploy_data_content("../smart_wallet") print(deploy_contract) account = { "tokenType": token_type, "contractAddr": contract_addr, "balance": 0, "totalUsed": 0, "sendLimit": int(sendLimit), "lastUsedDate": "2018-11-12", "dids": dids } transaction = DeployTransactionBuilder() \ .from_(wallet.get_address()) \ .to("cx0000000000000000000000000000000000000000") \ .step_limit(2000000000000) \ .nid(3) \ .nonce(100) \ .content_type("application/zip") \ .content(deploy_contract) \ .params({"account": json.dumps(account)}) \ .build() result = _send_transaction(transaction, wallet, 10) IconServiceContainer.contract_addr = result['scoreAddress']
def _deploy_irc2(self, project, to: str = SCORE_INSTALL_ADDRESS) -> dict: # Generates an instance of transaction for deploying SCORE. transaction = DeployTransactionBuilder() \ .params({ "_initialSupply": 0x100000000000, "_decimals": 18, "_name": 'StandardToken', "_symbol": 'ST', }) \ .from_(self._operator.get_address()) \ .to(to) \ .step_limit(100_000_000_000) \ .nid(3) \ .nonce(100) \ .content_type("application/zip") \ .content(gen_deploy_data_content(project)) \ .build() # Returns the signed transaction object having a signature signed_transaction = SignedTransaction(transaction, self._operator) # process the transaction in local result = self.process_transaction(signed_transaction, self.icon_service) self.assertTrue('status' in result) self.assertEqual(1, result['status']) self.assertTrue('scoreAddress' in result) return result
def test_deploy_wrong_address(self, _make_id): wrong_address = "hx5bfdb090f43a808005ffc27c25b213145e8" deploy_transaction = DeployTransactionBuilder() \ .from_(self.setting["from"]) \ .to(wrong_address) \ .step_limit(self.setting["step_limit"]) \ .nid(self.setting["nid"]) \ .nonce(self.setting["nonce"]) \ .content_type(self.setting["content_type"]) \ .content(self.setting["content_install"]) \ .params(self.setting["params_install"]) \ .build() signed_transaction = SignedTransaction(deploy_transaction, self.wallet) with requests_mock.Mocker() as m: response_json = { 'jsonrpc': '2.0', 'id': 1234, 'error': { "code": -32600, "message": f'Not a system SCORE {wrong_address}' } } m.post(self.matcher, json=response_json, status_code=400) result_dict = self.icon_service.send_transaction( signed_transaction, full_response=True) self.assertEqual(result_error_v3.keys(), result_dict.keys())
def _deploy_score(self, to: str = SCORE_INSTALL_ADDRESS) -> dict: # publish token score contract transaction = DeployTransactionBuilder() \ .from_(self._test1.get_address()) \ .to(to) \ .step_limit(100_000_000_000) \ .nid(3) \ .nonce(100).params(self.TOKEN_SCORE_PARAM) \ .content_type("application/zip") \ .content(gen_deploy_data_content(self.TOKEN_SCORE_PROJECT)) \ .build() signed_transaction = SignedTransaction(transaction, self._test1) tx_result = self.process_transaction(signed_transaction, self.icon_service) self.assertTrue('status' in tx_result) self.assertEqual(1, tx_result['status']) self.assertTrue('scoreAddress' in tx_result) # publish crowdsale score contract self.CROWDSALE_PARAM['_tokenScore'] = tx_result['scoreAddress'] transaction = DeployTransactionBuilder() \ .from_(self._test1.get_address()) \ .to(to) \ .step_limit(100_000_000_000) \ .nid(3) \ .nonce(100).params(self.CROWDSALE_PARAM) \ .content_type("application/zip") \ .content(gen_deploy_data_content(self.CROWDSALE_SCORE_PROJECT)) \ .build() signed_transaction = SignedTransaction(transaction, self._test1) tx_result = self.process_transaction(signed_transaction, self.icon_service) self.assertTrue('status' in tx_result) self.assertEqual(1, tx_result['status']) self.assertTrue('scoreAddress' in tx_result) return { 'crowdsale_score_address': tx_result['scoreAddress'], 'token_score_address': self.CROWDSALE_PARAM['_tokenScore'] }
def _deploy(self, wallet, to, content, params, limit): transaction = DeployTransactionBuilder() \ .from_(wallet.get_address()) \ .to(to) \ .nid(self._nid) \ .content_type("application/zip") \ .content(content) \ .params(params) \ .build() return self._send_transaction(transaction, wallet, limit)
def test_estimate_step_with_deploy_transaction(self, _make_id): param = {"init_supply": 10000} deploy_transaction = DeployTransactionBuilder() \ .from_(self.setting["from"]) \ .to(self.setting["to_install"]) \ .step_limit(self.setting["step_limit"]) \ .nid(self.setting["nid"]) \ .nonce(self.setting["nonce"]) \ .timestamp(self.setting["timestamp"]) \ .content_type(self.setting["content_type"]) \ .content(self.setting["content_install"]) \ .params(param) \ .version(3) \ .build() with requests_mock.Mocker() as m: expected_step = 1_042_767_600 expected_request = { 'jsonrpc': '2.0', 'method': 'debug_estimateStep', 'id': 1234, 'params': { 'from': self.setting["from"], 'nid': hex(self.setting["nid"]), 'nonce': hex(self.setting["nonce"]), 'timestamp': hex(self.setting["timestamp"]), 'to': self.setting["to_install"], 'version': hex(self.version), 'data': { 'contentType': self.setting["content_type"], 'content': f'0x{self.setting["content_install"].hex()}', 'params': { 'init_supply': hex(param["init_supply"]) } }, 'dataType': 'deploy' } } response_json = { 'jsonrpc': '2.0', 'result': hex(expected_step), 'id': 1234 } m.post(self.matcher, json=response_json) result = self.icon_service.estimate_step(deploy_transaction) actual_request = json.loads(m._adapter.last_request.text) self.assertEqual(expected_request, actual_request) self.assertEqual(expected_step, result)
def _deploy(self, wallet, to, content, params, limit, nid=1): transaction = DeployTransactionBuilder() \ .from_(wallet.get_address()) \ .to(to) \ .step_limit(limit) \ .version(3) \ .nid(nid) \ .content_type("application/zip") \ .content(content) \ .params(params) \ .build() return self._icon_service.send_transaction( SignedTransaction(transaction, wallet))
def test_estimate_step_with_deploy_transaction(self): param = {"init_supply": 10000} deploy_transaction = DeployTransactionBuilder() \ .from_(self.setting["from"]) \ .to(self.setting["to_install"]) \ .step_limit(self.setting["step_limit"]) \ .nid(self.setting["nid"]) \ .nonce(self.setting["nonce"]) \ .content_type(self.setting["content_type"]) \ .content(self.setting["content_install"]) \ .params(param) \ .version(3) \ .build() self.assertEqual(1042767600, self.icon_service.estimate_step(deploy_transaction))
def test_signed_transaction_with_deploy_transaction_without_step_limit( self): deploy_transaction_without_step_limit = DeployTransactionBuilder() \ .from_(self.setting["from"]) \ .to(self.setting["to_install"]) \ .nid(self.setting["nid"]) \ .nonce(self.setting["nonce"]) \ .content_type(self.setting["content_type"]) \ .content(self.setting["content_install"]) \ .params(self.setting["params_install"]) \ .build() # fail without step limit self.assertRaises(DataTypeException, SignedTransaction, deploy_transaction_without_step_limit, self.wallet)
def _deploy_score(self, to: str = SCORE_INSTALL_ADDRESS) -> dict: transaction = DeployTransactionBuilder() \ .from_(self._test1.get_address()) \ .to(to) \ .step_limit(100_000_000_000) \ .nid(3) \ .nonce(100) \ .content_type("application/zip") \ .content(gen_deploy_data_content(self.SCORE_PROJECT)) \ .build() signed_transaction = SignedTransaction(transaction, self._test1) tx_result = self.process_transaction(signed_transaction) return tx_result
def _deploy(self, owner, to, content, params, step_limit) -> Transaction: logging.debug("TxBuildHelper._deploy() start") transaction = DeployTransactionBuilder() \ .from_(owner.get_address()) \ .to(to) \ .step_limit(step_limit) \ .version(3) \ .nid(self._nid) \ .content_type("application/zip") \ .content(content) \ .params(params) \ .build() logging.debug("TxBuildHelper._deploy() end") return transaction
def create_deploy_score_tx( score_path: str, from_: 'KeyWallet', to: str = SCORE_INSTALL_ADDRESS) -> 'SignedTransaction': transaction = DeployTransactionBuilder() \ .from_(from_.get_address()) \ .to(to) \ .step_limit(100_000_000_000) \ .nid(DEFAULT_NID) \ .nonce(0) \ .content_type("application/zip") \ .content(gen_deploy_data_content(score_path)) \ .build() # Returns the signed transaction object having a signature signed_transaction = SignedTransaction(transaction, from_) return signed_transaction
def get_transaction(conf: dict, params: dict): data_type = params.get('dataType') params_data = params.get('data', {}) try: transaction_params = { "from_": params['from'], "to": params['to'], "nid": convert_hex_str_to_int(conf['nid']), "value": convert_hex_str_to_int(params.get('value', "0x0")) } if data_type is None: transaction_builder = TransactionBuilder(**transaction_params) elif data_type == "call": transaction_params['method'] = params_data.get('method') transaction_params['params'] = params_data.get('params') transaction_builder = CallTransactionBuilder( **transaction_params) elif data_type == "deploy": transaction_params['content'] = params_data.get('content') transaction_params['content_type'] = params_data.get( 'contentType') transaction_params['params'] = params_data.get('params') transaction_builder = DeployTransactionBuilder(**params) elif data_type == "message": transaction_params['data'] = params_data transaction_builder = MessageTransactionBuilder( **transaction_params) elif data_type == "deposit": transaction_params['action'] = params_data.get('action') transaction_params['id'] = params_data.get('id') transaction_builder = DepositTransactionBuilder( **transaction_params) else: raise JsonContentsException("Invalid dataType") transaction = transaction_builder.build() except KeyError: raise JsonContentsException( "Invalid json content. check json contents") except TypeError: raise JsonContentsException("Invalid json content. check keys") except DataTypeException: raise JsonContentsException("Invalid json content. check values") else: return transaction
def test_update_scores(self): score_list = ['cps_score', 'cpf_treasury', 'cps_treasury'] transaction = DeployTransactionBuilder() \ .from_(self._test1.get_address()) \ .to(self.contracts[score_list[0]]) \ .step_limit(100_000_000_000) \ .nid(3) \ .nonce(100) \ .content_type("application/zip") \ .content(gen_deploy_data_content(self.CPS_SCORE_PROJECT)) \ .build() signed_transaction = SignedTransaction(transaction, self._test1) tx_hash = self.process_transaction(signed_transaction, self.icon_service) pprint(tx_hash)
def test_signed_transaction_with_deploy_transaction_without_step_limit( self): deploy_transaction_without_step_limit = DeployTransactionBuilder().from_(self.setting["from"]).to( self.setting["to_install"]) \ .nid(self.setting["nid"]).nonce(self.setting["nonce"]) \ .content_type(self.setting["content_type"]).content(self.setting["content_install"]) \ .params(self.setting["params_install"]).build() # fail without step limit self.assertRaises(DataTypeException, SignedTransaction, deploy_transaction_without_step_limit, self.wallet) # success with param of step limit signed_transaction_dict = SignedTransaction( deploy_transaction_without_step_limit, self.wallet, self.setting["step_limit"]) result = self.icon_service.send_transaction(signed_transaction_dict) self.assertTrue(is_T_HASH(result))
def _deploy_std_basic(self, to: str = SCORE_INSTALL_ADDRESS) -> dict: # Generates an instance of transaction for deploying SCORE. transaction = (DeployTransactionBuilder().from_( self._test1.get_address()).to(to).step_limit(100_000_000_000).nid( 3).nonce(100).content_type("application/zip").content( gen_deploy_data_content(self.STD_BASIC_PROJECT)).build()) # Returns the signed transaction object having a signature signed_transaction = SignedTransaction(transaction, self._test1) # process the transaction in local tx_result = self.process_transaction(signed_transaction, self.icon_service) self.assertEqual(True, tx_result["status"]) self.assertTrue("scoreAddress" in tx_result) return tx_result
def update_contracts(self, contract_path: str, contract_address: str): transaction = DeployTransactionBuilder() \ .from_(self._test1.get_address()) \ .to(contract_address) \ .step_limit(100_000_000_000) \ .nid(3) \ .nonce(100) \ .content_type("application/zip") \ .content(gen_deploy_data_content(contract_path)) \ .build() signed_transaction = SignedTransaction(transaction, self._test1) # process the transaction in local tx_result = self.process_transaction(signed_transaction, self.icon_service) self.assertEqual(True, tx_result['status']) self.assertTrue('scoreAddress' in tx_result) return tx_result
def test_estimate_step_with_call_transaction(self): param = {"init_supply": 10000} deploy_transaction = DeployTransactionBuilder() \ .from_(self.setting["from"]) \ .to(self.setting["to_install"]) \ .step_limit(self.setting["step_limit"]) \ .nid(self.setting["nid"]) \ .nonce(self.setting["nonce"]) \ .content_type(self.setting["content_type"]) \ .content(self.setting["content_install"]) \ .params(param) \ .version(3) \ .build() signed_transaction_dict = SignedTransaction(deploy_transaction, self.wallet) result_install = self.icon_service.send_transaction(signed_transaction_dict) sleep(2) installed_score_address = self.icon_service.get_transaction_result(result_install)["scoreAddress"] # Sends a call transaction calling a method `acceptScore` to make the SCORE active params = {"txHash": result_install} call_transaction = CallTransactionBuilder() \ .from_(self.setting["from"]) \ .to(self.setting["to_governance"]) \ .step_limit(self.setting["step_limit"]) \ .nid(self.setting["nid"]) \ .nonce(self.setting["nonce"]) \ .method("acceptScore") \ .params(params) \ .build() signed_transaction_dict = SignedTransaction(call_transaction, self.wallet) self.icon_service.send_transaction(signed_transaction_dict) params = {"addr_to": self.setting["to"], "value": 1000000} call_transaction = CallTransactionBuilder() \ .from_(self.setting["from"]) \ .to(installed_score_address) \ .nid(self.setting["nid"]) \ .nonce(self.setting["nonce"]) \ .method("transfer") \ .params(params) \ .build() self.assertEqual(155160, self.icon_service.estimate_step(call_transaction))
def test_deploy_sICX_score(self, to=SCORE_INSTALL_ADDRESS): params = {'_admin': self.contracts['staking_score']} transaction = DeployTransactionBuilder() \ .from_(self._test1.get_address()) \ .to(to) \ .step_limit(100_000_000_000) \ .nid(3) \ .nonce(100) \ .content_type("application/zip") \ .content(gen_deploy_data_content(self.sICX_SCORE)) \ .params(params) \ .build() signed_transaction = SignedTransaction(transaction, self._test1) # process the transaction in local tx_result = self.process_transaction(signed_transaction, self.icon_service) self.assertEqual(True, tx_result['status']) self.assertTrue('scoreAddress' in tx_result) pprint(tx_result) return tx_result
def _deploy_score(self, score_path: str, params: dict) -> dict: # Make zipfile of a score # score_content = gen_deploy_data_content(score_path) shutil.make_archive("./tmp", "zip", score_path) with open("./tmp.zip", "rb") as z: score_content = z.read() os.remove("./tmp.zip") transaction = DeployTransactionBuilder() \ .from_(self._wallet.get_address()) \ .to("cx0000000000000000000000000000000000000000") \ .step_limit(STEP_LIMIT) \ .nid(self._nid) \ .nonce(NONCE) \ .content_type("application/zip") \ .content(score_content) \ .params(params) \ .build() return self._send_transaction(transaction)
def _deploy_score( self, key_wallet: 'KeyWallet', path: str, score_address: str = SYSTEM_ADDRESS, ) -> dict: # Generates an instance of transaction for deploying SCORE. transaction = DeployTransactionBuilder() \ .from_(key_wallet.get_address()) \ .to(score_address) \ .step_limit(100_000_000_000) \ .nid(3) \ .nonce(100) \ .content_type("application/zip") \ .content(gen_deploy_data_content(path)) \ .build() # Returns the signed transaction object having a signature signed_transaction = SignedTransaction(transaction, key_wallet) # send transaction return self.icon_service.send_transaction(signed_transaction)