Esempio n. 1
0
    def create_set_revision_tx(from_: 'KeyWallet',
                               revision: int) -> 'SignedTransaction':
        # set revision
        transaction = CallTransactionBuilder() \
            .from_(from_.get_address()) \
            .to(GOVERNANCE_ADDRESS) \
            .step_limit(10_000_000) \
            .nid(3) \
            .nonce(100) \
            .method("setRevision") \
            .params({"code": revision, "name": f"1.4.{revision}"}) \
            .build()

        # Returns the signed transaction object having a signature
        signed_transaction = SignedTransaction(transaction, from_)
        return signed_transaction
Esempio n. 2
0
    def test_remove_user(self):
        send = CallTransactionBuilder().from_(self.tester_addr) \
            .version(3) \
            .step_limit(3000000000000000000000) \
            .timestamp(0x573117f1d6568) \
            .nid(0x3) \
            .to(vote_dao_address) \
            .method("remove_user") \
            .params({"contents": "hx8d29ac2645805452a6e921c888b23c58be862cf0"}) \
            .build()
        signed_transaction = SignedTransaction(send, self.wallet)
        tx_hash = self.icon_service.send_transaction(signed_transaction)

        sleep(10)
        result = self.icon_service.get_transaction_result(tx_hash)
        assert result['status'] == 0 or 1
Esempio n. 3
0
    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
Esempio n. 4
0
def writeTransaction(self, method: str, params: []) -> {}:
    transaction = CallTransactionBuilder()\
                  .from_(self._test1.get_address())\
                  .to(self._score_address)\
                  .step_limit(100000000)\
                  .nid(3)\
                  .nonce(100)\
                  .method(method)\
                  .params(params)\
                  .build()
    signed_transaction = SignedTransaction(transaction, self._test1)
    tx_result = self.process_transaction(signed_transaction, self.icon_service)

    assert 'status' in tx_result
    assert 1 == tx_result['status']

    return tx_result
    def _use_scrooge_(self, _to: Address, _ratio: int):
        transaction_use_scrooge = CallTransactionBuilder() \
            .from_(self._test1.get_address()) \
            .to(self._score_address) \
            .step_limit(10_000_000) \
            .nid(3) \
            .nonce(100) \
            .method("scrooge") \
            .params({
            "_to":_to,
            "_ratio":_ratio
        }) \
            .build()

        signed_transaction = SignedTransaction(transaction_use_scrooge, self._test1)
        tx_result = self.process_transaction(signed_transaction, self.icon_service)
        return tx_result
    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.to_dict(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.to_dict(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.to_dict(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.to_dict(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.to_dict(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.to_dict(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.to_dict(msg_transaction)
        self.assertTrue(is_message_transaction(tx_dict))
    def test_stake(self):
        # use pre-defined account
        # account = self._wallet_array[0]
        # make new account
        account = self._make_account()
        stake_value: int = 0x64

        # Generates a 'setStake' instance of transaction
        transaction = CallTransactionBuilder() \
            .from_(account.get_address()) \
            .to(self.SYSTEM_ADDRESS) \
            .step_limit(10_000_000) \
            .nid(3) \
            .nonce(100) \
            .method("setStake") \
            .params({"value": stake_value}) \
            .build()

        # Returns the signed transaction object having a signature
        signed_transaction = SignedTransaction(transaction, account)

        # 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'])

        # Generates a 'getStake' call instance using the CallBuilder
        call = CallBuilder().from_(account.get_address()) \
            .to(self.SYSTEM_ADDRESS) \
            .method("getStake") \
            .params({"address": account.get_address()}) \
            .build()

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

        expect_result = {
            "stake": hex(stake_value),
            "unstake": "0x0",
            "unstakedBlockHeight": "0x0"
        }

        self.assertEqual(expect_result, response)
Esempio n. 8
0
    def test_token_transfer(self):
        # Make params of transfer method
        to = self._wallet_array[0].get_address()
        value = 100
        params = {
            '_to': to,
            '_value': value,
        }

        # Generates an instance of transaction for calling method in SCORE.
        transaction = CallTransactionBuilder() \
            .from_(self._test1.get_address()) \
            .to(self._score_address) \
            .step_limit(10_000_000) \
            .nid(3) \
            .nonce(100) \
            .method("transfer") \
            .params(params) \
            .build()

        # Returns the signed transaction object having a signature
        signed_transaction = SignedTransaction(transaction, self._test1)

        # Sends the transaction to the network
        tx_result = self.process_transaction(signed_transaction, self.icon_service)

        self.assertTrue('status' in tx_result)
        self.assertEqual(1, tx_result['status'])

        # Make params of balanceOf method
        params = {
            '_owner': to
        }
        # 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)

        # check balance of receiver
        self.assertEqual(hex(value), response)
Esempio n. 9
0
def dice_fast_bets(bet_amount, params_bet, loop_times):
    signed_tx = []
    for _ in range(loop_times):
        transaction = CallTransactionBuilder() \
            .from_(wallet.get_address()) \
            .to(daoDice_contract) \
            .step_limit(40000000) \
            .value(bet_amount) \
            .nid(nid) \
            .nonce(50) \
            .method("call_bet") \
            .params(params_bet) \
            .build()
        # Signs and sends the tx to the contract
        signed_transaction = SignedTransaction(transaction, wallet)
        signed_tx.append(signed_transaction)

    return signed_tx
Esempio n. 10
0
def cancel_my_swap(swap_id):
    """Cancels my swap by id, Returning the txhash """
    swap_id = hex(swap_id)
    params = {"swap_id": swap_id}
    transaction = CallTransactionBuilder() \
        .from_(address) \
        .to(iconswap_score) \
        .value(0) \
        .method("cancel_swap") \
        .params(params) \
        .step_limit(40000000) \
        .nid(nid) \
        .nonce(50) \
        .build()

    signed_transaction = SignedTransaction(transaction, my_wallet)
    tx_hash = icon_service.send_transaction(signed_transaction)
    return tx_hash
 def set_refs_by_using_relay(self, _symbols, _rates, _resolve_times,
                             _request_ids):
     transaction = (CallTransactionBuilder().from_(
         self._test1.get_address()).to(self._std_basic).step_limit(
             100_000_000_000).nid(3).nonce(100).method("relay").params({
                 "_symbols":
                 json.dumps(_symbols),
                 "_rates":
                 json.dumps(_rates),
                 "_resolve_times":
                 json.dumps(_resolve_times),
                 "_request_ids":
                 json.dumps(_request_ids),
             }).build())
     signed_transaction = SignedTransaction(transaction, self._test1)
     tx_result = self.process_transaction(signed_transaction,
                                          self.icon_service)
     self.assertEqual(True, tx_result["status"])
Esempio n. 12
0
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('address', type=str)
        parser.add_argument('amount', type=int)
        args = parser.parse_args();

        transaction = CallTransactionBuilder()\
            .from_(admin_addr)\
            .to(contract_address)\
            .step_limit(100000000)\
            .nid(3)\
            .nonce(100)\
            .method("set")\
            .params({"_to":args['address'], "_amount":args['amount']})\
            .build()

        signed_transaction = SignedTransaction(transaction, wallet)
        tx_hash = icon_service.send_transaction(signed_transaction)
Esempio n. 13
0
def create_transaction(multiplier=1):
    transaction = (
        CallTransactionBuilder()
        .from_(player_wallet.get_address())
        .to(CASINO_SCORE_ADDRESS)
        .method("play")
        .value(BET_AMOUNT * multiplier)
        .step_limit(2000000)
        .nid(3)
        .nonce(100)
        .params({})
        .build()
    )

    signed_transaction = SignedTransaction(transaction, player_wallet)
    signed_transaction_hash = icon_service.send_transaction(signed_transaction)
    print('Transaction hash: {} '.format(signed_transaction_hash))
    return signed_transaction_hash
Esempio n. 14
0
    def create_claim_iscore_tx(key_wallet: 'KeyWallet',
                               value: int = 0,
                               step_limit: int = DEFAULT_STEP_LIMIT,
                               nid: int = DEFAULT_NID,
                               nonce: int = 0) -> 'SignedTransaction':

        transaction = CallTransactionBuilder(). \
            from_(key_wallet.get_address()). \
            to(SYSTEM_ADDRESS). \
            value(value). \
            step_limit(step_limit). \
            nid(nid). \
            nonce(nonce). \
            method("claimIScore"). \
            build()

        signed_transaction = SignedTransaction(transaction, key_wallet)

        return signed_transaction
Esempio n. 15
0
    def _exchange(self, _from: KeyWallet, amount: int):
        params = {
            'amount': amount
        }

        transaction_exchange = CallTransactionBuilder() \
            .from_(_from.get_address()) \
            .to(self._sample_game_score_address) \
            .step_limit(10_000_000) \
            .nid(3) \
            .nonce(100) \
            .method("exchange") \
            .params(params) \
            .build()

        signed_transaction_exchange = SignedTransaction(transaction_exchange, _from)

        tx_result_exchange = self.process_transaction(signed_transaction_exchange, self.icon_service)
        return tx_result_exchange
Esempio n. 16
0
    def write_data(self, contract_address, action_name, wallet_key, params):
        wallet = KeyWallet.load(bytes.fromhex(wallet_key))

        call_transaction = CallTransactionBuilder() \
          .from_(wallet.get_address()) \
          .to(contract_address) \
          .step_limit(self.get_max_step_limit(wallet.get_address())) \
          .nid(self.network_id) \
          .nonce(self.network_id) \
          .method(action_name) \
          .params(params) \
          .build()

        signed_transaction = SignedTransaction(call_transaction, wallet)
        tx_hash = self.icon_service.send_transaction(signed_transaction)
        # print('tx_hash:', tx_hash)

        tx_result = self.get_transaction_result(tx_hash)
        return tx_result
Esempio n. 17
0
    def setMethod(self, _method: dict, type: str) -> dict:
        result = {}
        if type == "DIR":
            contract_address = self.id_contract_address
        elif type == "PTM":
            contract_address = self.ptm_contract_address
        elif type == "PGM":
            contract_address = self.pgm_contract_address
        else:
            print("Not supported contract type")
            result["status"] = "failure"
            result["message"] = ""
            return result

        if not _method.__contains__("params"):
            _method["params"] = ""

        transaction = CallTransactionBuilder() \
            .from_(self.key_wallet.get_address()) \
            .to(contract_address) \
            .step_limit(10000000) \
            .nid(self.nid) \
            .method(_method["name"]) \
            .params(_method["params"]) \
            .build()

        # sign the transaction with key wallet
        signed_tx = SignedTransaction(transaction, self.key_wallet)
        # commit(send) the signed transaction to the service endpoint
        tx_hash = self.service_endpoint.send_transaction(signed_tx)
        sleep(3)  # wait a second for the transaction to be finalized
        tx_result = self.service_endpoint.get_transaction_result(tx_hash)
        print(tx_result)

        if "failure" in tx_result:
            result["status"] = "failure"
            result["message"] = tx_result["failure"]
        else:
            result["status"] = "success"
            result["message"] = tx_result["eventLogs"][0]["data"]

        return result
Esempio n. 18
0
    def _build_transaction(self, type_="write", **kwargs):
        if type_ not in ("transfer", "write", "read"):
            raise ValueError("Wrong type value")

        from_ = self._wallet.get_address(
        ) if "from_" not in kwargs else kwargs["from_"]
        to_ = self._score_address if "to" not in kwargs else kwargs["to"]
        margin_ = 2500000 if "margin" not in kwargs else kwargs["margin"]
        value_ = 0 if "value" not in kwargs else kwargs["value"]
        method_ = None if "method" not in kwargs else kwargs["method"]
        params_ = {} if "params" not in kwargs else kwargs["params"]

        tx = None
        if type_ == "write":
            steps_ = self._estimate_steps(margin_)
            tx = CallTransactionBuilder() \
                .from_(from_) \
                .to(to_) \
                .value(value_) \
                .nid(3) \
                .step_limit(steps_) \
                .nonce(100) \
                .method(method_) \
                .params(params_) \
                .build()
        elif type_ == "read":
            tx = CallBuilder() \
                .from_(from_) \
                .to(to_) \
                .method(method_) \
                .params(params_) \
                .build()
        elif type_ == "transfer":
            steps_ = self._estimate_steps(margin_)
            tx = TransactionBuilder() \
                .from_(from_) \
                .to(to_) \
                .value(value_) \
                .step_limit(steps_) \
                .nid(3) \
                .build()
        return tx
Esempio n. 19
0
    def test_009_downgrade(self):
        call = CallBuilder().from_(self._walletOfUc.get_address())\
            .to(self._scoreAddrOfContractRegistry)\
            .method('getLatestVersion')\
            .params({'_index': '0x0'})\
            .build()

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

        transaction = CallTransactionBuilder()\
            .from_(self._walletOfUc.get_address())\
            .to(self._scoreAddrOfContractRegistry)\
            .step_limit(100000000)\
            .nid(3)\
            .nonce(100)\
            .method('downgrade')\
            .params({'_index': '0x0', '_version': '0x1'})\
            .build()

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

        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._scoreAddrOfStoreAgent)
        self.assertEqual(json.loads(callResult)['version'], 1)

        call = CallBuilder().from_(self._walletOfUc.get_address())\
            .to(self._scoreAddrOfContractRegistry)\
            .method('getLatestVersion')\
            .params({'_index': '0x0'})\
            .build()

        callResult = self._sendCall(call)
        self.assertEqual(callResult, '0x2')
Esempio n. 20
0
def transaction_call(icon_integrate_test_base: IconIntegrateTestBase,
                     from_: KeyWallet,
                     to_: str,
                     method: str,
                     params: dict = None,
                     value: int = 0,
                     icon_service: IconService = None) -> dict:
    """Sends the call transaction by using SDK

    :param icon_integrate_test_base: IconIntegrateTestBase
    :param from_: wallet address making a transaction
    :param to_: wallet address to receive coin or SCORE address to receive a transaction
    :param method: name of an external function
    :param params: parameters as dict passed on the SCORE methods (optional)
    :param value: amount of ICX to be sent (Optional)
    :param icon_service: IconService
    :return: transaction result as dict
    """
    # Generates an instance of transaction for calling method in SCORE.
    transaction = CallTransactionBuilder() \
        .from_(from_.get_address()) \
        .to(to_) \
        .step_limit(10_000_000) \
        .nid(3) \
        .nonce(100) \
        .method(method) \
        .params(params) \
        .value(value) \
        .build()

    # Returns the signed transaction object having a signature
    signed_transaction = SignedTransaction(transaction, from_)

    # Sends the transaction to the network
    tx_result = icon_integrate_test_base.process_transaction(
        signed_transaction, icon_service)

    assert 'status' in tx_result
    assert 1 == tx_result['status']

    return tx_result
Esempio n. 21
0
    def test_004_open(self):
        transaction = CallTransactionBuilder()\
            .from_(self._walletOfProvider.get_address())\
            .to(self._scoreAddrOfStoreAgentProxy)\
            .step_limit(100000000)\
            .nid(3)\
            .nonce(100)\
            .method('open')\
            .params({'_index': '0x0'})\
            .build()

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

        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')
Esempio n. 22
0
    def test_game(self):
        #CallBuildern을 사용하여호출 인스턴스 생성
        params = {"_choice": 1, "_time": 1}

        transaction = CallTransactionBuilder() \
            .from_(self._test1.get_address()) \
            .to(self._score_address) \
            .step_limit(10_000_000) \
            .nid(3) \
            .nonce(100) \
            .value(2000000000000000000)\
            .method("game_start") \
            .params(params) \
            .build()

        # 서명이있는 서명 된 트랜잭션 객체를 반환합니다.
        signed_transaction = SignedTransaction(transaction, self._test1)
        # print("signed_transaction: ", signed_transaction)
        txresult = self.process_transaction(signed_transaction,
                                            self.icon_service)
        print("txresult: ", txresult)
Esempio n. 23
0
def sell_tap_fill_swap(tap_amount, swap_id):
    """ It will fill someone's sell order if you provide the tap_amount and the swap_id. Returns tx hash """
    swap_id = hex(swap_id)
    tap_amount = int_to_bighexa(tap_amount)
    pre_data = {'action': 'fill_irc2_order', 'swap_id': swap_id}
    aft_data = json.dumps(pre_data, separators=(',', ':')).encode('utf-8')
    data = convert_bytes_to_hex_str(aft_data)
    # c = convert_hex_str_to_bytes(" put has here")
    params = {"_to": iconswap_score, "_value": tap_amount, "_data": data}
    transaction = CallTransactionBuilder() \
        .from_(address) \
        .to(tap_score) \
        .step_limit(40000000) \
        .nid(nid) \
        .nonce(50) \
        .method("transfer") \
        .params(params) \
        .build()
    signed_transaction = SignedTransaction(transaction, my_wallet)
    tx_hash = icon_service.send_transaction(signed_transaction)
    return tx_hash
    def test_createCard(self):
        params = {
            "_grade": 1,
        }

        transaction = CallTransactionBuilder() \
            .from_(self._test1.get_address()) \
            .to(self._score_address) \
            .step_limit(10_000_000) \
            .nid(3) \
            .nonce(100) \
            .value(1000000000000000000) \
            .method("createCard") \
            .params(params) \
            .build()

        # Returns the signed transaction object having a signature
        signed_transaction = SignedTransaction(transaction, self._test1)
        # print("signed_transaction: ", signed_transaction)
        txresult = self.process_transaction(signed_transaction,
                                            self.icon_service)
Esempio n. 25
0
def call_transaction(_score_address, _fromWallet, _method, _params):
    transaction = CallTransactionBuilder()\
        .from_(_fromWallet.get_address())\
        .to(_score_address)\
        .step_limit(1000000000)\
        .nid(3)\
        .nonce(100)\
        .method(_method)\
        .params(_params)\
        .build()

    signed_transaction = SignedTransaction(transaction, _fromWallet)
    txhash = TestACT.icon_service.send_transaction(signed_transaction)

    #print('txhash = [{}] {}'.format(type(txhash), txhash))
    time.sleep(10)

    txresult = TestACT.icon_service.get_transaction_result(txhash)
    #print('txresult = [{}] {}'.format(type(txresult), txresult))

    return txresult
 def build_transaction(self,
                       from_: KeyWallet,
                       to: str,
                       value: int = 0,
                       method: str = None,
                       params: dict = None) -> dict:
     call_transaction = CallTransactionBuilder() \
         .from_(from_.get_address()) \
         .to(to) \
         .value(value) \
         .nid(3) \
         .nonce(100) \
         .method(method) \
         .params(params) \
         .build()
     signed_transaction = SignedTransaction(call_transaction, from_,
                                            10000000)
     tx_result = self.process_transaction(signed_transaction,
                                          self.icon_service)
     self.assertEqual(tx_result['status'], 1)
     return tx_result
Esempio n. 27
0
    def create_set_stake_tx(key_wallet: KeyWallet,
                            stake: int,
                            value: int = 0,
                            step_limit: int = DEFAULT_STEP_LIMIT,
                            nid: int = DEFAULT_NID,
                            nonce: int = 0) -> 'SignedTransaction':

        transaction = CallTransactionBuilder(). \
            from_(key_wallet.get_address()). \
            to(SYSTEM_ADDRESS). \
            value(value). \
            step_limit(step_limit). \
            nid(nid). \
            nonce(nonce). \
            method("setStake"). \
            params({"value": hex(stake)}). \
            build()

        signed_transaction = SignedTransaction(transaction, key_wallet)

        return signed_transaction
Esempio n. 28
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')
    def _transaction_call(self, from_: KeyWallet, to_: str, method: str, params: dict = None) -> dict:
        # Generates an instance of transaction for calling method in SCORE.
        transaction = CallTransactionBuilder() \
            .from_(from_.get_address()) \
            .to(to_) \
            .step_limit(10_000_000) \
            .nid(3) \
            .nonce(100) \
            .method(method) \
            .params(params) \
            .build()

        # Returns the signed transaction object having a signature
        signed_transaction = SignedTransaction(transaction, from_)

        # Sends the transaction to the network
        tx_result = self.process_transaction(signed_transaction, self.icon_service)

        self.assertTrue('status' in tx_result)
        self.assertEqual(1, tx_result['status'])

        return tx_result
    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)