def test_getTotalToken(self): call = CallBuilder() \ .from_(self._test1.get_address()) \ .to(self._score_address) \ .method("getName") \ .build() response = self.process_call(call, self.icon_service) print("getName : ", response) call = CallBuilder() \ .from_(self._test1.get_address()) \ .to(self._score_address) \ .method("getSymbol") \ .build() response = self.process_call(call, self.icon_service) print("getSymbol : ", response) call = CallBuilder() \ .from_(self._test1.get_address()) \ .to(self._score_address) \ .method("getTotalToken") \ .build() response = self.process_call(call, self.icon_service) print("getTotalToken : ", response)
def test_scenario1(self): call = CallBuilder().from_(self.test1_wallet.get_address()) \ .to(self._sample_game_score_address) \ .method("showGameRoomList") \ .build() # Sends the call request response = self.process_call(call, self.icon_service) print(response) tx_result_create_room = self._create_room(self.test1_wallet) self.assertTrue('status' in tx_result_create_room) self.assertEqual(1, tx_result_create_room['status']) tx_result_create_room = self._create_room(self.test2_wallet) self.assertTrue('status' in tx_result_create_room) self.assertEqual(1, tx_result_create_room['status']) tx_result_create_room = self._create_room(self.test1_wallet) self.assertTrue('status' in tx_result_create_room) self.assertEqual(0, tx_result_create_room['status']) call = CallBuilder().from_(self.test1_wallet.get_address()) \ .to(self._sample_game_score_address) \ .method("showGameRoomList") \ .build() # Sends the call request response = self.process_call(call, self.icon_service) print(response)
def test_008_upgrade(self): transaction = CallTransactionBuilder()\ .from_(self._walletOfUc.get_address())\ .to(self._scoreAddrOfContractRegistry)\ .step_limit(100000000)\ .nid(3)\ .nonce(100)\ .method('upgrade')\ .params({'_contractAddress': self._scoreAddrOfStoreAgent2})\ .build() txResult = self._sendTransaction(transaction, self._walletOfUc) call = CallBuilder().from_(self._walletOfUc.get_address())\ .to(self._scoreAddrOfContractRegistry)\ .method('getCount')\ .build() callResult = self._sendCall(call) self.assertEqual(callResult, '0x1') call = CallBuilder().from_(self._walletOfUc.get_address())\ .to(self._scoreAddrOfContractRegistry)\ .method('getAddressByName')\ .params({'_contractName': 'StoreAgent'})\ .build() callResult = self._sendCall(call) self.assertEqual(callResult, self._scoreAddrOfStoreAgent2) call = CallBuilder().from_(self._walletOfUc.get_address())\ .to(self._scoreAddrOfContractRegistry)\ .method('getAddressByName')\ .params({'_contractName': 'StoreAgent', '_version': '0x1'})\ .build() callResult = self._sendCall(call) self.assertEqual(callResult, self._scoreAddrOfStoreAgent) call = CallBuilder().from_(self._walletOfUc.get_address())\ .to(self._scoreAddrOfContractRegistry)\ .method('get')\ .params({'_index': '0x0'})\ .build() callResult = self._sendCall(call) self.assertEqual( json.loads(callResult)['address'], self._scoreAddrOfStoreAgent2) self.assertEqual(json.loads(callResult)['version'], 2) call = CallBuilder().from_(self._walletOfUc.get_address())\ .to(self._scoreAddrOfContractRegistry)\ .method('get')\ .params({'_index': '0x0', '_version': '0x1'})\ .build() callResult = self._sendCall(call) self.assertEqual( json.loads(callResult)['address'], self._scoreAddrOfStoreAgent) self.assertEqual(json.loads(callResult)['version'], 1)
def test_integrate_after_unit_tests(self): call = CallBuilder().from_(self._test1.get_address()).to( self._score_address).method("getSCOREValue").build() response = self.process_call(call, self.icon_service) self.assertEqual(response, "") new_value = "new_value" call_tx = CallTransactionBuilder().from_(self._test1.get_address()).to(self._score_address).\ method("setSCOREValue").params({"value": new_value}).step_limit(10000000).build() signed_tx = SignedTransaction(call_tx, self._test1) tx_result = self.process_transaction(signed_tx, self.icon_service) self.assertTrue(tx_result['status']) call = CallBuilder().from_(self._test1.get_address()).to( self._score_address).method("getSCOREValue").build() response = self.process_call(call, self.icon_service) self.assertEqual(new_value, response) call = CallBuilder().from_(self._test1.get_address()).to( self._score_address).method("get_owner").build() response = self.process_call(call, self.icon_service) self.assertEqual(self._test1.get_address(), response) call = CallBuilder().from_(self._test1.get_address()).to(self._score_address).method("get_balance").\ params({"address": self._test1.get_address()}).build() response = self.process_call(call, self.icon_service) self.assertEqual(hex(10**24), response) call = CallBuilder().from_(self._test1.get_address()).to(self._score_address).method("simple_json_dumps")\ .build() response = self.process_call(call, self.icon_service) expected = json.dumps({"simple": "value"}) self.assertEqual(expected, response)
def test_006_accept(self): transaction = CallTransactionBuilder()\ .from_(self._walletOfProvider.get_address())\ .to(self._scoreAddrOfOrderAgentProxy)\ .step_limit(100000000)\ .nid(3)\ .nonce(100)\ .method('accept')\ .params({'_index': '0x0', '_value': '0x1000000000000000000'})\ .build() txResult = self._sendTransaction(transaction, self._walletOfProvider) call = CallBuilder().from_(self._walletOfProvider.get_address())\ .to(self._scoreAddrOfOrderAgentProxy)\ .method('get')\ .params({'_index': '0x0'})\ .build() callResult = self._sendCall(call) self.assertEqual(json.loads(callResult)['state'], 'accepted') call = CallBuilder().from_(self._walletOfProvider.get_address())\ .to(self._scoreAddrOfOrderAgentProxy)\ .method('balanceOf')\ .params({'_owner': self._walletOfProvider.get_address()})\ .build() callResult = self._sendCall(call) self.assertEqual(callResult, '0x0')
def test_token_fallback(self): call = CallBuilder().from_(self._test1.get_address()) \ .to(self.crowdsale_score_address) \ .method("isCrowdsaleClosed") \ .build() response = self.process_call(call, self.icon_service) self.assertEqual(hex(True), response) transaction = CallTransactionBuilder() \ .from_(self._test1.get_address()) \ .to(self.token_score_address).method({}) \ .step_limit(2000000) \ .method("transfer") \ .params({"_to": self.crowdsale_score_address, "_value": 100}) \ .build() signed_transaction = SignedTransaction(transaction, self._test1) _ = self.process_transaction(signed_transaction) # Generates a call instance using the CallBuilder call = CallBuilder().from_(self._test1.get_address()) \ .to(self.crowdsale_score_address) \ .method("isCrowdsaleClosed") \ .build() # Sends the call request response = self.process_call(call, self.icon_service) self.assertEqual(hex(False), response)
def test_003_register(self): transaction = CallTransactionBuilder()\ .from_(self._walletOfProvider.get_address())\ .to(self._scoreAddrOfStoreAgentProxy)\ .step_limit(100000000)\ .nid(3)\ .nonce(100)\ .method('register')\ .params({'_itemName': 'A Used Bycicle', '_itemDetails': 'It\'s been used for 3 years'})\ .build() txResult = self._sendTransaction(transaction, self._walletOfProvider) call = CallBuilder().from_(self._walletOfProvider.get_address())\ .to(self._scoreAddrOfStoreAgentProxy)\ .method('getCount')\ .build() callResult = self._sendCall(call) self.assertEqual(callResult, '0x1') call = CallBuilder().from_(self._walletOfProvider.get_address())\ .to(self._scoreAddrOfStoreAgentProxy)\ .method('get')\ .params({'_index': '0x0'})\ .build() callResult = self._sendCall(call) self.assertEqual(json.loads(callResult)['state'], 'ready') self.assertEqual(json.loads(callResult)['owner'], self._walletOfProvider.get_address())
def test_call(self): test_call = CallBuilder().from_(self.address).to(self.to).method("getStepCosts").params("").build() result = self.icon_service.call(test_call) self.assertTrue(result) test_call = CallBuilder().from_(self.address).to(self.to).method("getStepCosts").build() result = self.icon_service.call(test_call) self.assertTrue(result)
def _call(self, method, params=None): call = CallBuilder() \ .from_(self._from) \ .to(GOVERNANCE_ADDRESS) \ .method(method) \ .params(params) \ .build() self.on_send_request(call.to_dict()) return self._icon_service.call(call)
def test_safe_withdraw(self): donation = 10 transaction = CallTransactionBuilder() \ .from_(self._test1.get_address()) \ .to(self.token_score_address).method({}) \ .step_limit(2000000) \ .method("transfer") \ .params({"_to": self.crowdsale_score_address, "_value": 1000}) \ .build() signed_transaction = SignedTransaction(transaction, self._test1) tx_result = self.process_transaction(signed_transaction) self.assertTrue('status' in tx_result) self.assertEqual(1, tx_result['status']) transaction = TransactionBuilder()\ .from_(self._test1.get_address())\ .to(self.crowdsale_score_address)\ .step_limit(2000000)\ .value(donation)\ .build() signed_transaction = SignedTransaction(transaction, self._test1) tx_result = self.process_transaction(signed_transaction) self.assertTrue('status' in tx_result) self.assertEqual(1, tx_result['status']) call = CallBuilder().from_(self._test1.get_address()) \ .to(self.crowdsale_score_address) \ .method("getBalance") \ .build() response = self.process_call(call, self.icon_service) self.assertEqual(hex(donation), response) transaction = CallTransactionBuilder() \ .from_(self._test1.get_address()) \ .to(self.crowdsale_score_address).method({}) \ .step_limit(2000000) \ .method("safeWithdraw") \ .build() signed_transaction = SignedTransaction(transaction, self._test1) tx_result = self.process_transaction(signed_transaction) self.assertTrue('status' in tx_result) self.assertEqual(1, tx_result['status']) call = CallBuilder().from_(self._test1.get_address()) \ .to(self.crowdsale_score_address) \ .method("getBalance") \ .build() response = self.process_call(call, self.icon_service) self.assertEqual(hex(0), response)
def _call(self, method, params=None, to: str = ZERO_ADDRESS) -> dict: call = CallBuilder() \ .from_(self._from) \ .to(to) \ .method(method) \ .params(params) \ .build() self.on_send_request(call.to_dict()) return self._icon_service.call(call, True)
def test_check_goal_reached(self): donation = 10 transaction = CallTransactionBuilder() \ .from_(self._test1.get_address()) \ .to(self.token_score_address).method({}) \ .step_limit(2000000) \ .method("transfer") \ .params({"_to": self.crowdsale_score_address, "_value": 1000}) \ .build() signed_transaction = SignedTransaction(transaction, self._test1) tx_result = self.process_transaction(signed_transaction) self.assertTrue('status' in tx_result) self.assertEqual(1, tx_result['status']) transaction = TransactionBuilder()\ .from_(self._test1.get_address())\ .to(self.crowdsale_score_address)\ .step_limit(2000000)\ .value(donation)\ .build() signed_transaction = SignedTransaction(transaction, self._test1) tx_result = self.process_transaction(signed_transaction) self.assertTrue('status' in tx_result) self.assertEqual(1, tx_result['status']) transaction = CallTransactionBuilder() \ .from_(self._test1.get_address()) \ .to(self.crowdsale_score_address).method({}) \ .step_limit(2000000) \ .method("checkGoalReached") \ .build() signed_transaction = SignedTransaction(transaction, self._test1) tx_result = self.process_transaction(signed_transaction) self.assertTrue('status' in tx_result) self.assertEqual(1, tx_result['status']) call = CallBuilder().from_(self._test1.get_address()) \ .to(self.crowdsale_score_address) \ .method("isCrowdsaleClosed") \ .build() response = self.process_call(call, self.icon_service) self.assertEqual(hex(True), response) call = CallBuilder().from_(self._test1.get_address()) \ .to(self.crowdsale_score_address) \ .method("isFundingGoalReached") \ .build() response = self.process_call(call, self.icon_service) self.assertEqual(hex(True), response)
def test_make_call_builder_from_dict_to_dict(self): """Testing for from dict and to dict method.""" call_1 = CallBuilder() \ .to("1_TO") \ .method("1_METHOD") \ .params({"test": 123}) \ .build() call_1_as_dict = call_1.to_dict() call_2 = CallBuilder.from_dict(call_1_as_dict).build() call_2_as_dict = call_2.to_dict() self.assertEqual(call_1_as_dict, call_2_as_dict)
def test_call(self): # with from test_call = CallBuilder().from_(self.address).to(self.to).method("getStepCosts").params("").build() result = self.icon_service.call(test_call) self.assertEqual(type(result), dict) test_call = CallBuilder().from_(self.address).to(self.to).method("getStepCosts").build() result = self.icon_service.call(test_call) self.assertTrue(type(result), dict) # without from test_call = CallBuilder().to(self.to).method("getStepCosts").params("").build() result = self.icon_service.call(test_call) self.assertEqual(type(result), dict)
def getQuotePriceInBase(id) -> int: call = CallBuilder().from_("hx0000000000000000000000000000000000000001")\ .to(DEX_CONTRACT)\ .method("getQuotePriceInBase")\ .params({"_id": id})\ .build() return int(icon_service.call(call), 0)
def getPriceByName(pair) -> int: call = CallBuilder().from_("hx0000000000000000000000000000000000000001")\ .to(DEX_CONTRACT)\ .method("getPriceByName")\ .params({"_name": pair})\ .build() return int(icon_service.call(call), 0)
def getAPY(pair) -> int: call = CallBuilder().from_("hx0000000000000000000000000000000000000001")\ .to(REWARDS_CONTRACT)\ .method("getAPY")\ .params({"_name": pair})\ .build() return int(icon_service.call(call), 0)
def latest_transactions(): params = {} call = CallBuilder().from_(wallets['wallet1'].get_address()) \ .to(default_score) \ .method("get_results") \ .params(params) \ .build() result = icon_service.call(call) transaction_list = [] for resultVal in result['result']: transaction_list.append(ast.literal_eval(resultVal)) score_balance = icon_service.get_balance(default_score) account_balance = icon_service.get_balance( wallets['wallet1'].get_address()) decending_ordered_transaction = sorted( transaction_list, key=lambda val: int(val['timestamp']), reverse=True) latest_transaction = decending_ordered_transaction[0] if len( decending_ordered_transaction) > 0 else [] response = { 'transaction_list': decending_ordered_transaction, 'score_balance': score_balance, 'account_balance': account_balance, 'latest_transaction': latest_transaction } return jsonify(response)
def test_modify_status(self): params = {"_scoreName": "Modified SCORE Name", "_introduction": "Modified Introduction"} transaction = CallTransactionBuilder() \ .method("modifyScoreStatus") \ .params(params) \ .step_limit(10000000000) \ .to(self._score_address) \ .build() signed_transaction = SignedTransaction(transaction, self._test1) tx_result = self.process_transaction(signed_transaction) self.assertEqual(1, tx_result['status']) print(tx_result['eventLogs']) call = CallBuilder().from_(self._test1.get_address()) \ .to(self._score_address) \ .method("getScoreStatus") \ .build() # Sends the call request response = self.process_call(call, self.icon_service) response_list = response.split("\n") self.assertEqual("SCORE_NAME : Modified SCORE Name", response_list[0]) self.assertEqual("INTRODUCTION : Modified Introduction", response_list[1]) self.test_time_recording()
def test_send_token_to_ca(self): call = CallBuilder().from_(self.tester_addr)\ .to(token_address)\ .method("balanceOf")\ .params({"_owner": hello_world_address})\ .build() balance_before = self.icon_service.call(call) token_value = "0x1" transaction = CallTransactionBuilder()\ .from_(self.tester_addr)\ .to(token_address)\ .step_limit(2000000)\ .nid(network_id)\ .method("transfer")\ .params({"_to":hello_world_address, "_value":token_value})\ .build() signed_transaction = SignedTransaction(transaction, self.wallet) tx_hash = self.icon_service.send_transaction(signed_transaction) sleep(10) result = self.icon_service.get_transaction_result(tx_hash) self.assertEqual(result['status'], 1) self.assertFalse(result['eventLogs'] is None) balance_after = self.icon_service.call(call) self.assertEqual(int(balance_before,0)+int(token_value,0), int(balance_after,0))
def test_008_withdraw(self): transaction = CallTransactionBuilder()\ .from_(self._walletOfProvider.get_address())\ .to(self._scoreAddrOfOrderAgentProxy)\ .step_limit(100000000)\ .nid(3)\ .nonce(100)\ .method('withdraw')\ .params({'_value': '0x2000000000000000000'})\ .build() txResult = self._sendTransaction(transaction, self._walletOfProvider) balance = self._getBalance(self._walletOfProvider.get_address()) self.assertEqual(balance, 0x2000000000000000000) balance = self._getBalance(self._walletOfCustomer.get_address()) self.assertEqual(balance, 0x0) call = CallBuilder().from_(self._walletOfProvider.get_address())\ .to(self._scoreAddrOfOrderAgentProxy)\ .method('balanceOf')\ .params({'_owner': self._walletOfProvider.get_address()})\ .build() callResult = self._sendCall(call) self.assertEqual(callResult, '0x0')
def call(self, to, method, params=None): _call = CallBuilder() \ .to(to) \ .method(method) \ .params(params) \ .build() return self._icon_service.call(_call)
def icx_call(icon_integrate_test_base: IconIntegrateTestBase, from_: str, to_: str, method: str, params: dict = None, icon_service: IconService = None) -> any: """Calls SCORE's external function which is read-only by using SDK and returns the response :param icon_integrate_test_base: IconIntegrateTestBase :param from_: Message sender's address :param to_: SCORE address that will handle the message :param method: name of an external function :param params: parameters as dict to be passed to the function (optional) :param icon_service: IconService :return: response as dict returned by the executed SCORE function """ # Generates a call instance using the CallBuilder call = CallBuilder().from_(from_) \ .to(to_) \ .method(method) \ .params(params) \ .build() # Sends the call request response = icon_integrate_test_base.process_call(call, icon_service) return response
def getPoolStats(id) -> dict: call = CallBuilder().from_("hx0000000000000000000000000000000000000001")\ .to(DEX_CONTRACT)\ .method("getPoolStats")\ .params({"_id": id})\ .build() return icon_service.call(call)
def test_token_fallback(self): input_params = {"initialSupply": 1000, "decimals": 1} token_deploy_result = self._deploy_score(scorepath=self.SAMPLE_TOKEN, _params=input_params) score_address = token_deploy_result['scoreAddress'] transaction = CallTransactionBuilder().from_(self._test1.get_address()) \ .to(score_address) \ .step_limit(10000000000) \ .nid(3) \ .method("transfer") \ .params({"_to": self._score_address, "_value": 10}) \ .build() signed_transaction = SignedTransaction(transaction, self._test1) tx_result = self.process_transaction(signed_transaction, self.icon_service) self.assertEqual(1, tx_result['status']) call = CallBuilder().from_(self._test1.get_address()) \ .to(score_address) \ .method("balanceOf") \ .params({"_owner": self._score_address}) \ .build() response = self.process_call(call, self.icon_service) self.assertEqual('0xa', response)
def readonly(fn_name: str, params=None): call = CallBuilder().from_(RANDOM_ADDRESS)\ .to(SCORE_ADDRESS)\ .method(fn_name)\ .params(params)\ .build() print(icon_service.call(call))
def get_my_logo(method, address): call = CallBuilder().from_(tester_address) \ .to('cx0000000000000000000000000000000000000000') \ .params({"address": address}) \ .method(method) \ .build() result = icon_service.call(call) json_details = extract_values(result, 'details')[0] page = Request(json_details, headers={'User-Agent': 'Mozilla/5.0'}) jpage = json.load(urlopen(page)) try: logo_link_256 = extract_values(jpage, 'logo_256')[0] logo_link_1024 = extract_values(jpage, 'logo_1024')[0] logo_link_svg = extract_values(jpage, 'logo_svg')[0] except: print(json_details + ': Perhaps No logo uploaded by the P-Rep') print(address + ' is done.') ## add ranking logic to choose one maybe? if logo_link_svg is not None: logo_link = logo_link_svg elif logo_link_1024 is not None: logo_link = logo_link_1024 else: logo_link = logo_link_256 return logo_link
def call(conf): """Request icx_call :param conf: call command configuration. :return: response of icx_call """ uri, version = uri_parser(conf['uri']) icon_service = IconService(HTTPProvider(uri, version)) with open(conf['json_file'], 'r') as jf: payload = json.load(jf) call = CallBuilder()\ .from_(conf['from'])\ .to(payload['params']['to'])\ .method(payload['params']['data']['method'])\ .params(payload['params']['data'].get('params', None))\ .build() response = call_with_logger(icon_service, call, uri) if 'error' in response: print(json.dumps(response, indent=4)) else: print(f'response : {json.dumps(response, indent=4)}') return response
def test_hello(self): call = CallBuilder().from_(self.tester_addr)\ .to(hello_world_address)\ .method("hello")\ .build() result = self.icon_service.call(call) self.assertEqual(result, 'Hello')
def test_balanceOf(self): ################### TEST_TOKEN ADD ################### transaction = CallTransactionBuilder() \ .from_(self._test1.get_address()) \ .to(self._score_address) \ .step_limit(10_000_000) \ .nid(3) \ .nonce(100) \ .method("init_add") \ .build() # Returns the signed transaction object having a signature signed_transaction = SignedTransaction(transaction, self._test1) # print("signed_transaction: ", signed_transaction) self.process_transaction(signed_transaction, self.icon_service) ################### _test1 / balanceOf ################### params = { # "_owner" : "hx08711b77e894c3509c78efbf9b62a85a4354c8df", "_owner": "hx08711b77e894c3509c78efbf9b62a85a4354c8df", # hxe7af5fcfd8dfc67530a01a0e403882687528dfcb } call_balanceOf = CallBuilder() \ .from_(self._test1.get_address()) \ .to(self._score_address) \ .method("balanceOf") \ .params(params)\ .build() response = self.process_call(call_balanceOf, self.icon_service) print("balanceOf : ", response)