예제 #1
0
    def test_call_welcome(self):
        call = CallBuilder().from_(self._test1.get_address()) \
            .to(self._score_address) \
            .method("welcome") \
            .build()

        response = self.process_call(call, self.icon_service)

        # 조회
        print(response)
        # Hello가 들어있는지 확인
        self.assertTrue('Hello' in response)
예제 #2
0
    def test_score_update(self):
        # Generates a call instance using the CallBuilder
        call = CallBuilder().from_(self._test1.get_address()) \
            .to(self._score_address) \
            .method("hello") \
            .build()
        # update SCORE
        tx_result = self._deploy_score(self._score_address)
        self.assertEqual(self._score_address, tx_result['scoreAddress'])

        # Sends the call request
        response = self.process_call(call, self.icon_service)
예제 #3
0
    def _call(self,
              to: str,
              method: str,
              params: dict = {}) -> Union[dict, str]:
        call = CallBuilder() \
            .from_(self.key_wallet.get_address()) \
            .to(to) \
            .method(method) \
            .params(params) \
            .build()

        return self.icon_service.call(call)
예제 #4
0
    def _get_user_status(self, _from: KeyWallet):
        params = {"_userId": _from.get_address()}

        call = CallBuilder().from_(_from.get_address()) \
            .to(self._sample_game_score_address) \
            .method("getUserStatus") \
            .params(params) \
            .build()

        # Sends the call request
        response = self.process_call(call, self.icon_service)
        return response
예제 #5
0
    def test_call_owner_name(self):
        call = CallBuilder().from_(self._test1.get_address()) \
            .to(self._score_address) \
            .method("getOwnerName") \
            .build()
        response = self.process_call(call, self.icon_service)
        print(response)

        call = CallBuilder().from_(self._test1.get_address()) \
            .to(self._score_address) \
            .method("getOwnerNameInterface") \
            .build()
        response = self.process_call(call, self.icon_service)
        print(response)

        call = CallBuilder().from_(self._test1.get_address()) \
            .to(self._score_address) \
            .method("getOwnerNameInnerFunc") \
            .build()
        response = self.process_call(call, self.icon_service)
        print(response)
    def test_call_totalSupply(self):
        # Generates a call instance using the CallBuilder
        call = CallBuilder().from_(self._test1.get_address()) \
            .to(self._score_address) \
            .method("totalSupply") \
            .build()

        # Sends the call request
        response = self.process_call(call, self.icon_service)

        self.assertEqual(hex(self.initial_supply * 10**self.decimals),
                         response)
예제 #7
0
    def _call_balance(self, addr: str) -> str:
        params = {'_owner': addr}
        # Generates a call instance using the CallBuilder
        call = CallBuilder().from_(addr) \
            .to(self._score_address) \
            .method('balanceOf') \
            .params(params) \
            .build()

        # Sends the call request
        request = self.process_call(call, self.icon_service)
        return request
예제 #8
0
    def test_005_propose(self):
        transaction = CallTransactionBuilder()\
            .from_(self._walletOfCustomer.get_address())\
            .to(self._scoreAddrOfOrderAgentProxy)\
            .step_limit(100000000)\
            .nid(3)\
            .nonce(100)\
            .method('propose')\
            .params({'_itemId': '0x0', '_value': '0x1000000000000000000'})\
            .build()

        txResult = self._sendTransaction(transaction, self._walletOfCustomer)

        call = CallBuilder().from_(self._walletOfCustomer.get_address())\
            .to(self._scoreAddrOfOrderAgentProxy)\
            .method('getCount')\
            .build()

        callResult = self._sendCall(call)
        self.assertEqual(callResult, '0x1')

        call = CallBuilder().from_(self._walletOfCustomer.get_address())\
            .to(self._scoreAddrOfOrderAgentProxy)\
            .method('get')\
            .params({'_index': '0x0'})\
            .build()

        callResult = self._sendCall(call)
        self.assertEqual(json.loads(callResult)['state'], 'proposed')
        self.assertEqual(
            json.loads(callResult)['value'], 0x1000000000000000000)

        call = CallBuilder().from_(self._walletOfCustomer.get_address())\
            .to(self._scoreAddrOfOrderAgentProxy)\
            .method('balanceOf')\
            .params({'_owner': self._walletOfCustomer.get_address()})\
            .build()

        callResult = self._sendCall(call)
        self.assertEqual(callResult, '0x0')
예제 #9
0
    def test_call_transfer_success(self):
        value = 100
        recipient = f"hx{'0'*40}"

        # publish transfer calling transactions
        transaction = CallTransactionBuilder() \
            .from_(self._test1.get_address()) \
            .to(self._score_address).method({}) \
            .step_limit(2000000) \
            .method("transfer") \
            .params({"_to": recipient, "_value": value}) \
            .build()

        signed_transaction = SignedTransaction(transaction, self._test1)
        tx_result = self.process_transaction(signed_transaction)

        self.assertEqual(tx_result['status'], 1)
        self.assertNotEqual(len(tx_result['eventLogs']), 0)
        print(f"eventLogs: {tx_result['eventLogs']}")

        # check the balances of recipient
        call = CallBuilder().from_(self._test1.get_address()) \
            .to(self._score_address) \
            .method("balanceOf") \
            .params({"_owner": recipient}) \
            .build()

        response = self.process_call(call, self.icon_service)
        self.assertEqual(hex(value), response)

        # check the balances of owner
        call = CallBuilder().from_(self._test1.get_address()) \
            .to(self._score_address) \
            .method("balanceOf") \
            .params({"_owner": self._test1.get_address()}) \
            .build()

        response = self.process_call(call, self.icon_service)
        self.assertEqual(hex(1000 * 10**10 - value), response)
예제 #10
0
    def test_call_transfer_fail(self):
        value = 1000 * 10**10 + 1
        recipient = f"hx{'0'*40}"

        # publish transfer calling transactions
        transaction = CallTransactionBuilder() \
            .from_(self._test1.get_address()) \
            .to(self._score_address).method({}) \
            .step_limit(2000000) \
            .method("transfer") \
            .params({"_to": recipient, "_value": value}) \
            .build()

        signed_transaction = SignedTransaction(transaction, self._test1)
        tx_result = self.process_transaction(signed_transaction)

        self.assertNotEqual(tx_result['status'], 1)
        self.assertEqual(tx_result['failure']['message'],
                         "balance is insufficient")

        # check the balances of recipient
        call = CallBuilder().from_(self._test1.get_address()) \
            .to(self._score_address) \
            .method("balanceOf") \
            .params({"_owner": recipient}) \
            .build()

        response = self.process_call(call, self.icon_service)
        self.assertEqual(hex(0), response)

        # check the balances of owner
        call = CallBuilder().from_(self._test1.get_address()) \
            .to(self._score_address) \
            .method("balanceOf") \
            .params({"_owner": self._test1.get_address()}) \
            .build()

        response = self.process_call(call, self.icon_service)
        self.assertEqual(hex(1000 * 10**10), response)
예제 #11
0
def votingResults(walletName) -> dict:
    params = {}
    call = CallBuilder().from_(wallets.get(walletName).get_address()) \
        .to(default_score) \
        .method("get_vote_talley") \
        .params(params) \
        .build()
    result = icon_service.call(call)

    votesResult = {}
    votesResult['yes'] = convert_hex_str_to_int(result['yes'])
    votesResult['no'] = convert_hex_str_to_int(result['no'])
    return json.dumps(votesResult)
예제 #12
0
    def test_call_hello(self):
        # Generates a call instance using the CallBuilder
        call = CallBuilder().from_(self._test1.get_address()) \
            .to(self._score_address) \
            .method("hello") \
            .build()

        # Sends the call request
        response = self.process_call(call, self.icon_service)

        self.assertEqual(
            "Life4honor : Owner, [('Jin', 'Developer'), ('nanaones', 'Developer'), ('ICON', 'Blockchain'), ('SCORE', 'Smart Contract')]",
            response)
    def test_getTodayRate(self):
        print('======================================================================')
        print('Test getTodayRate')
        print('----------------------------------------------------------------------')

        _call = CallBuilder().from_(self._test1.get_address()) \
            .to(self.contracts['staking1']) \
            .method("getTodayRate") \
            .build()

        response = self.get_tx_result(_call)
        # check call result
        print (response)
예제 #14
0
def get_my_values(method, address, output):
    call = CallBuilder().from_(tester_address) \
        .to('cx0000000000000000000000000000000000000000') \
        .params({"address": address}) \
        .method(method) \
        .build()
    result = icon_service.call(call)
    try:
        temp_output = loop_to_icx(int(result[output], 0))
    except:
        temp_output = float("NAN")
    df = {'address': address, output: temp_output}
    return (df)
    def test_call_welcome(self):
        print("----------------[test call]------------------------")
        # Generates a call instance using the CallBuilder
        call = CallBuilder().from_(self._test1.get_address()) \
            .to(self._score_address) \
            .method("welcome") \
            .build()

        # Sends the call request
        response = self.process_call(call, self.icon_service)
        self.assertEqual(response, f"Hello, {self._test1.get_address()} !!! Welcome to ICON Workshop 2019!!!")

        print(response)
    def test_lifeTime(self):
        print('======================================================================')
        print('getLifetimeReward')
        print('----------------------------------------------------------------------')

        _call = CallBuilder().from_(self._test1.get_address()) \
            .to(self.contracts['staking1']) \
            .method("getLifetimeReward") \
            .build()

        response = self.get_tx_result(_call)
        # check call result
        print (response)
예제 #17
0
def get_token_name(token_address: str):
    """
    Gets the token name

    If not have the external method `name` to get the score name,
    it will raise JSONRPCException.
    """
    call = CallBuilder()\
        .from_(wallet.get_address())\
        .to(token_address)\
        .method("name")\
        .build()
    return icon_service.call(call)
    def test_std_reference_proxy_set_std_basic(self):
        call = (CallBuilder().from_(self._test1.get_address()).to(
            self._std_reference_proxy).method("get_ref").build())
        response = self.process_call(call, self.icon_service)
        self.assertEqual(self._std_basic, response)

        transaction = (CallTransactionBuilder().from_(
            self._test1.get_address()).to(
                self._std_reference_proxy).step_limit(100_000_000_000).nid(
                    3).nonce(100).method("set_ref").params({
                        "_ref":
                        self._test1.get_address()
                    }).build())
        signed_transaction = SignedTransaction(transaction, self._test1)
        tx_result = self.process_transaction(signed_transaction,
                                             self.icon_service)
        self.assertEqual(True, tx_result["status"])

        call = (CallBuilder().from_(self._test1.get_address()).to(
            self._std_reference_proxy).method("get_ref").build())
        response = self.process_call(call, self.icon_service)
        self.assertEqual(self._test1.get_address(), response)
예제 #19
0
    def test_call_hello(self):
        # Generates a call instance using the CallBuilder
        call = CallBuilder().from_(self._test1.get_address()) \
            .to(self._score_address) \
            .method("diceRoll") \
            .params({
                "name": "abcd"
            }) \
            .build()

        # Sends the call request
        response = self.process_call(call, self.icon_service)
        print(response)
    def test_call_decimals(self):
        # Generates a call instance using the CallBuilder
        call = CallBuilder().from_(self._test1.get_address()) \
            .to(self._score_address) \
            .method("decimals") \
            .build()

        # Sends the call request
        response = self.process_call(call, self.icon_service)
        # print('Decimals in HEX:', response)
        decimals = int(response, 0)
        print('Decimals in DEC:', decimals)
        self.assertEqual(hex(self.decimals), response)
예제 #21
0
    def test_createCard(self):
        call = CallBuilder() \
            .from_("hx08711b77e894c3509c78efbf9b62a85a4354c8df") \
            .to(self._score_address) \
            .method("getMyCard") \
            .build()

        response = self.process_call(call, self.icon_service)
        print("getMyCard : ", response)

        params = {"_tokenId": 0}
        call = CallBuilder() \
            .from_(self._test1.get_address()) \
            .to(self._score_address) \
            .method("getApproved") \
            .params(params) \
            .build()

        response = self.process_call(call, self.icon_service)
        print("getApproved : ", response)

        #
        params = {"_playerId": 1, "_price": 5}
        transaction = CallTransactionBuilder() \
            .from_("hx79e7f88e6186e72d86a1b3f1c4e29bd4ae00ff53") \
            .to(self._score_address) \
            .step_limit(10_000_000) \
            .nid(3) \
            .nonce(100) \
            .method("auctionBuy") \
            .params(params) \
            .build()

        # Returns the signed transaction object having a signature
        signed_transaction = SignedTransaction(transaction, self._test1)
        # print("signed_transaction: ", signed_transaction)
        response = self.process_transaction(signed_transaction,
                                            self.icon_service)
        print("response: ", response)
예제 #22
0
    def test_make_call_builder_changed(self):
        """Testing for making a call builder changed, it should not work."""

        call_1 = CallBuilder()       \
            .from_("1_FROM")         \
            .to("1_TO")              \
            .method("1_METHOD")      \
            .params("1_PARAMS")      \
            .build()

        def test_set_call_builder():
            call_1.from_ = "1_NEW_PROM"

        self.assertRaises(AttributeError, test_set_call_builder)
예제 #23
0
    def test_symbol(self):
        call_symbol = CallBuilder()\
            .from_(self._test1.get_address())\
            .to(self._score_address)\
            .method("symbol")\
            .build()

        response = self.process_call(call_symbol, self.icon_service)

        print("symbol: ", response)

        params = {"_owner": self._test1.get_address()}
        print("params: ", params)

        call_balance = CallBuilder()\
            .from_(self._test1.get_address())\
            .to(self._score_address)\
            .method("balanceOf")\
            .build()

        response = self.process_call(call_balance, self.icon_service)

        print("call_balance: ", response)
예제 #24
0
    def test_make_call_builder(self):
        """Testing for making a couple of call builders successfully"""

        call_1 = CallBuilder()          \
            .from_("1_FROM")            \
            .to("1_TO")                 \
            .method("1_METHOD")         \
            .params({"test": 123})      \
            .build()

        call_2 = CallBuilder().from_("2_FROM").to("2_TO").method(
            "2_METHOD").params({
                "test": 123
            }).build()

        properties = ["from_", "to", "method", "params"]
        values_call_1 = ["1_FROM", "1_TO", "1_METHOD", {'test': '0x7b'}]
        values_call_2 = ["2_FROM", "2_TO", "2_METHOD", {'test': '0x7b'}]

        # Checks all of property is collect.
        for idx, property in enumerate(properties):
            self.assertEqual(getattr(call_1, property), values_call_1[idx])
            self.assertEqual(getattr(call_2, property), values_call_2[idx])
예제 #25
0
def getCurrentTermBounds() -> dict:
    """
    :return: Term start/end-block height
    """

    call = CallBuilder() \
        .to(SCORE_INSTALL_ADDRESS) \
        .method("getPRepTerm") \
        .build()
    prep_term = ICX_SERVICE.call(call)
    return {
        "start": int(prep_term["startBlockHeight"], 16),
        "end": int(prep_term["endBlockHeight"], 16)
    }
예제 #26
0
def is_token_minted(tweet_id):
		params = {
			"_id": tweet_id
		}
		call = CallBuilder()\
			.from_(wallet.get_address())\
			.to(irc31_contract_address)\
			.method("tokenURI")\
			.params(params)\
			.build()
		result = icon_service.call(call)
		if len(result) > 0:
			return True
		else:
			return False
예제 #27
0
 def get_prep_list(self,
                   start_index: Optional[int] = None,
                   end_index: Optional[int] = None) -> dict:
     params = {}
     if start_index is not None:
         params['startRanking'] = hex(start_index)
     if end_index is not None:
         params['endRanking'] = hex(end_index)
     call = CallBuilder() \
         .from_(self._test1.get_address()) \
         .to(SYSTEM_ADDRESS) \
         .method("getPRepList") \
         .params(params) \
         .build()
     response = self.process_call(call, self.icon_service)
     return response
예제 #28
0
    def _icx_call(self,
                  from_: str,
                  to_: str,
                  method: str,
                  params: dict = None):
        # Generates a call instance using the CallBuilder
        call = CallBuilder().from_(from_) \
            .to(to_) \
            .method(method) \
            .params(params) \
            .build()

        # Sends the call request
        response = self.process_call(call, self.icon_service)

        return response
예제 #29
0
def get_transactions():
    call = (
        CallBuilder()
        .from_(player_wallet.get_address())
        .to(CASINO_SCORE_ADDRESS)
        .method("get_results")
        .params({})
        .build()
    )
    result = icon_service.call(call)

    transaction_list = []
    for resultVal in result["result"]:
        transaction_list.append(ast.literal_eval(resultVal))

    return transaction_list
예제 #30
0
    def test_call_balanceOf(self):
        # Make params of balanceOf method
        params = {
            # token owner
            '_owner': self._test1.get_address()
        }
        # Generates a call instance using the CallBuilder
        call = CallBuilder().from_(self._test1.get_address()) \
            .to(self._score_address) \
            .method("balanceOf") \
            .params(params) \
            .build()

        # Sends the call request
        response = self.process_call(call, self.icon_service)

        self.assertEqual(hex(self.initial_supply * 10 ** self.decimals), response)