示例#1
0
    def test_tx(self):
        self.set_tx(Address.from_string(f"hx{'1234' * 10}"))
        self.score2.t_tx()  # On the upper line, set the tx property to pass the assert statement so that no exception is raised.

        self.set_tx(Address.from_string(f"hx{'12' * 20}"))
        self.assertRaises(AssertionError,
                          self.score2.t_tx)  # On the upper line, set the tx property not to pass the assert statement, and raise an exception.
 def setUp(self):
     super().setUp()
     self.mock_score = Address.from_string(f"cx{'abcd' * 10}")
     self.dividends = self.get_score_instance(Dividends, self.test_account1)
     self.wallet_array = [KeyWallet.load(v) for v in TEST_ACCOUNTS]
     account_info = {
         Address.from_string(wallet.get_address()): 10**21
         for wallet in self.wallet_array
     }
     self.initialize_accounts(account_info)
    def setUp(self):
        super().setUp()
        self.mock_score_address = Address.from_string(f"cx{'1234' * 10}")
        self.score2 = self.get_score_instance(
            SimpleScore2,
            self.test_account1,
            on_install_params={'score_address': self.mock_score_address})

        self.test_account3 = Address.from_string(f"hx{'12345' * 8}")
        self.test_account4 = Address.from_string(f"hx{'1234' * 10}")
        account_info = {self.test_account3: 10**21, self.test_account4: 10**21}
        self.initialize_accounts(account_info)
    def test_default_parameters(self):
        tx1 = self._make_deploy_tx("test_scores",
                                   "test_db_returns_default_value",
                                   self._addr_array[0],
                                   ZERO_SCORE_ADDRESS,
                                   deploy_params={})
        prev_block, tx_results = self._make_and_req_block([tx1])
        self._write_precommit_state(prev_block)
        self.assertEqual(tx_results[0].status, int(True))
        score_addr1 = tx_results[0].score_address

        val1 = 3
        val2 = "string"
        val3 = b'bytestring'
        val4 = Address.from_string(f"hx{'0'*40}")
        val5 = False
        val6 = Address.from_string(f"hx{'abcd1234'*5}")

        query_request = {
            "from": self._admin,
            "to": score_addr1,
            "dataType": "call",
            "data": {
                "method": "get_value1",
                "params": {}
            }
        }
        response = self._query(query_request)
        self.assertEqual(response, val1)

        query_request['data']['method'] = 'get_value2'
        response = self._query(query_request)
        self.assertEqual(response, val2)

        query_request['data']['method'] = 'get_value3'
        response = self._query(query_request)
        self.assertEqual(response, val3)

        query_request['data']['method'] = 'get_value4'
        response = self._query(query_request)
        self.assertEqual(response, val4)

        query_request['data']['method'] = 'get_value5'
        response = self._query(query_request)
        self.assertEqual(response, val5)

        query_request['data']['method'] = 'get_value6'
        response = self._query(query_request)
        self.assertEqual(response, val6)
    def test_default_parameters(self):
        tx_results: List['TransactionResult'] = self.deploy_score(
            score_root="sample_scores",
            score_name="sample_db_returns_default_value",
            from_=self._accounts[0],
            deploy_params={})
        score_address: 'Address' = tx_results[0].score_address

        val1 = 3
        val2 = "string"
        val3 = b'bytestring'
        val4 = Address.from_string(f"hx{'0' * 40}")
        val5 = False
        val6 = Address.from_string(f"hx{'abcd1234' * 5}")

        query_request = {
            "from": self._admin,
            "to": score_address,
            "dataType": "call",
            "data": {
                "method": "get_value1",
                "params": {}
            }
        }
        response = self._query(query_request)
        self.assertEqual(response, val1)

        query_request['data']['method'] = 'get_value2'
        response = self._query(query_request)
        self.assertEqual(response, val2)

        query_request['data']['method'] = 'get_value3'
        response = self._query(query_request)
        self.assertEqual(response, val3)

        query_request['data']['method'] = 'get_value4'
        response = self._query(query_request)
        self.assertEqual(response, val4)

        query_request['data']['method'] = 'get_value5'
        response = self._query(query_request)
        self.assertEqual(response, val5)

        query_request['data']['method'] = 'get_value6'
        response = self._query(query_request)
        self.assertEqual(response, val6)
    def setUp(self):
        super().setUp()
        self.name = "IconHouseToken"
        self.symbol = "IHT"
        self.decimals = 18
        self.initial_supply = 0
        #self.controllable = 1

        params = {
            'name': self.name,
            'symbol': self.symbol,
            'decimals': self.decimals,
            'initial_supply': self.initial_supply,
            # 'controllable': self.controllable,
        }
        self.score = self.get_score_instance(SampleIRC16, self.test_account1,
                                             params)
        self.set_msg(self.test_account1)

        # self.test_account1 = hxe48913df85da204d99ac22e0180e017c82a5dc9b
        # self.test_account2 = hx541441378726178b4bce6d411765ee0b51bd7a03
        self.test_account3 = Address.from_string(f"hx{'12345'*8}")
        self.test_account4 = Address.from_string(f"hx{'1234'*10}")
        self.test_account5 = Address.from_string(f"hx{'4321'*10}")
示例#7
0
 def from_string(s: str) -> 'Validators':
     if not isinstance(s, str) or len(s) < 1:
         return None
     splitted = s.split(",")
     addresses = []
     for a in splitted:
         try:
             addresses.append(Address.from_string(a).to_bytes())
         except BaseException as e:
             if len(splitted) == 1:
                 return Validators(base64.urlsafe_b64decode(s))
             else:
                 raise e
     b = rlp.rlp_encode(addresses)
     return Validators(b)
示例#8
0
    def test_handleRelayMessage(self):
        # ================================================
        #  test_block_update
        # ================================================

        block_updates = []
        _block_header = Dummy.block_header(1, self._validators.hash)
        _votes = Dummy.votes(_block_header, self._validators_with_key)
        _next_validators = None
        block_update = rlp.rlp_encode([_block_header._bytes, _votes._bytes, _next_validators])
        block_updates.append(block_update)
        block_proof = None
        receipt_proofs = []
        _msgs = rlp.rlp_encode([block_updates, block_proof, receipt_proofs])
        self.set_msg(Address.from_string(self._btp_bmc.contract))
        btp_msgs = self.score.handleRelayMessage(str(self._btp_bmc), str(self._btp_bmc), 1, base64.urlsafe_b64encode(_msgs))
        print(btp_msgs)
示例#9
0
 def raw_to_object(self, raw):
     return self.new_relayer(Address.from_string(raw))
    def test_address_type_parameters_methods(self):
        tx1 = self._make_deploy_tx("test_scores",
                                   "test_db_returns",
                                   self._addr_array[0],
                                   ZERO_SCORE_ADDRESS,
                                   deploy_params={
                                       "value": str(self._addr_array[1]),
                                       "value1": str(self._addr_array[1])
                                   })

        prev_block, tx_results = self._make_and_req_block([tx1])
        self._write_precommit_state(prev_block)
        self.assertEqual(tx_results[0].status, int(True))
        score_addr1 = tx_results[0].score_address
        query_request = {
            "from": self._admin,
            "to": score_addr1,
            "dataType": "call",
            "data": {
                "method": "get_value4",
                "params": {}
            }
        }
        response = self._query(query_request)
        self.assertEqual(response,
                         self._addr_array[1])  # original value: 0(int)

        # set value to '1' -> fail
        tx = self._make_score_call_tx(self._addr_array[0],
                                      score_addr1,
                                      'set_value4', {"value": ONE},
                                      pre_validation_enabled=False)
        prev_block, tx_results = self._make_and_req_block([tx])
        self._write_precommit_state(prev_block)
        self.assertEqual(tx_results[0].status, int(False))

        # set value to '0' -> fail
        tx = self._make_score_call_tx(self._addr_array[0],
                                      score_addr1,
                                      'set_value4', {"value": ZERO},
                                      pre_validation_enabled=False)
        prev_block, tx_results = self._make_and_req_block([tx])
        self._write_precommit_state(prev_block)
        self.assertEqual(tx_results[0].status, int(False))

        # set value to '' fail
        tx = self._make_score_call_tx(self._addr_array[0],
                                      score_addr1,
                                      'set_value4', {"value": EMPTY_STR},
                                      pre_validation_enabled=False)
        prev_block, tx_results = self._make_and_req_block([tx])
        self._write_precommit_state(prev_block)
        self.assertEqual(tx_results[0].status, int(False))

        # set value to b'' fail
        tx = self._make_score_call_tx(self._addr_array[0],
                                      score_addr1,
                                      'set_value4', {"value": EMPTY_BYTE},
                                      pre_validation_enabled=False)
        prev_block, tx_results = self._make_and_req_block([tx])
        self._write_precommit_state(prev_block)
        self.assertEqual(tx_results[0].status, int(False))

        # set value to None -> fail

        tx = self._make_score_call_tx(self._addr_array[0],
                                      score_addr1,
                                      'set_value4', {"value": None},
                                      pre_validation_enabled=False)
        prev_block, tx_results = self._make_and_req_block([tx])
        self._write_precommit_state(prev_block)
        self.assertEqual(tx_results[0].status, int(False))

        # set value to 1 -> fail
        tx = self._make_score_call_tx(self._addr_array[0],
                                      score_addr1,
                                      'set_value4', {"value": NUM1},
                                      pre_validation_enabled=False)
        prev_block, tx_results = self._make_and_req_block([tx])
        self._write_precommit_state(prev_block)
        self.assertEqual(tx_results[0].status, int(False))

        # set value to 0 -> fail
        tx = self._make_score_call_tx(self._addr_array[0],
                                      score_addr1,
                                      'set_value4', {"value": NUM0},
                                      pre_validation_enabled=False)
        prev_block, tx_results = self._make_and_req_block([tx])
        self._write_precommit_state(prev_block)
        self.assertEqual(tx_results[0].status, int(False))

        # set value to '0x14'
        tx = self._make_score_call_tx(self._addr_array[0],
                                      score_addr1,
                                      'set_value4', {"value": INT_VAL},
                                      pre_validation_enabled=False)
        prev_block, tx_results = self._make_and_req_block([tx])
        self._write_precommit_state(prev_block)
        self.assertEqual(tx_results[0].status, int(False))

        # set value to 'string value''
        tx = self._make_score_call_tx(self._addr_array[0],
                                      score_addr1,
                                      'set_value4', {"value": STRING_VAL},
                                      pre_validation_enabled=False)
        prev_block, tx_results = self._make_and_req_block([tx])
        self._write_precommit_state(prev_block)
        self.assertEqual(tx_results[0].status, int(False))

        # set value to b'byte value'
        tx = self._make_score_call_tx(self._addr_array[0],
                                      score_addr1,
                                      'set_value4', {"value": BYTE_VAL},
                                      pre_validation_enabled=False)
        prev_block, tx_results = self._make_and_req_block([tx])
        self._write_precommit_state(prev_block)
        self.assertEqual(tx_results[0].status, int(False))

        # set value to address value
        tx = self._make_score_call_tx(self._addr_array[0],
                                      score_addr1,
                                      'set_value4', {"value": ADDRESS_VAL},
                                      pre_validation_enabled=False)
        prev_block, tx_results = self._make_and_req_block([tx])
        self._write_precommit_state(prev_block)
        self.assertEqual(tx_results[0].status, int(True))
        response = self._query(query_request)
        self.assertEqual(response, Address.from_string(ADDRESS_VAL))

        # set value to False
        tx = self._make_score_call_tx(self._addr_array[0],
                                      score_addr1,
                                      'set_value4', {"value": BOOL_VAL},
                                      pre_validation_enabled=False)
        prev_block, tx_results = self._make_and_req_block([tx])
        self._write_precommit_state(prev_block)
        self.assertEqual(tx_results[0].status, int(False))
# See the License for the specific language governing permissions and
# limitations under the License.

from iconservice import ZERO_SCORE_ADDRESS, Address
from tests.integrate_test.test_integrate_base import TestIntegrateBase

ONE = '1'
ZERO = '0'
EMPTY_STR = ""
EMPTY_BYTE = bytes.hex(b"")
NUM1 = 1
NUM0 = 0
INT_VAL = '0x14'
STRING_VAL = 'string value'
BYTE_VAL = bytes.hex(b'byte string')
ADDRESS_VAL = str(Address.from_string(f"hx{'abcd1234' * 5}"))
BOOL_VAL = hex(False)


class TestIntegrateMethodParamters(TestIntegrateBase):
    def test_int_type_parameters_methods(self):
        tx1 = self._make_deploy_tx("test_scores",
                                   "test_db_returns",
                                   self._addr_array[0],
                                   ZERO_SCORE_ADDRESS,
                                   deploy_params={
                                       "value": str(self._addr_array[1]),
                                       "value1": str(self._addr_array[1])
                                   })

        prev_block, tx_results = self._make_and_req_block([tx1])
示例#12
0
 def __init__(self):
     self.test_account3 = Address.from_string(f"hx{'1238' * 10}")
示例#13
0
    def setUp(self):
        super().setUp()
        self.test_admin_account = Address.from_string(f"hx{'1574' * 10}")
        self.test_account3 = Address.from_string(f"hx{'1238' * 10}")
        self.test_account4 = Address.from_string(f"hx{'1237' * 10}")
        self.test_account5 = Address.from_string(f"hx{'1236' * 10}")
        self.test_account6 = Address.from_string(f"hx{'2365' * 10}")
        self.test_account7 = Address.from_string(f"hx{'6964' * 10}")
        self.initialize_accounts({self.test_account1: 100000 * 10**18})

        self.cps_score_address = Address.from_string(f"cx{'1234' * 10}")
        self.cps_treasury_score = Address.from_string(f"cx{'3456' * 10}")
        self.cpf_treasury_score = Address.from_string(f"cx{'5678' * 10}")
        self.bnUSD_score = Address.from_string(f"cx{'7890' * 10}")
        self.sICX_score = Address.from_string(f"cx{'1985' * 10}")
        self.dex_score = Address.from_string(f"cx{'2000' * 10}")
        self.staking_score = Address.from_string(f"cx{'2001' * 10}")

        self.initialize_accounts({self.cpf_treasury_score: 100000 * 10**18})

        self.test_contract_1 = Address.from_string(f"cx{'6789' * 10}")
        self.set_msg(self.test_account1)
        self.set_tx(self.test_account1)
        self.cpf_score = self.get_score_instance(
            CPF_TREASURY,
            self.test_account1,
            on_install_params={},
            score_address=self.cpf_treasury_score)
示例#14
0
# limitations under the License.
import copy
from unittest.mock import PropertyMock

import pytest

from iconservice import Address
from iconservice.base.block import Block
from iconservice.icon_constant import Revision, IconScoreContextType
from iconservice.iconscore.context.context import ContextContainer
from iconservice.iconscore.icon_score_context import IconScoreContext
from iconservice.icx.coin_part import CoinPart, CoinPartFlag, CoinPartType
from iconservice.icx.icx_account import Account
from iconservice.icx.stake_part import StakePart

ADDRESS = Address.from_string(f"hx{'1234'*10}")
UNSTAKE_LOCK_PERIOD = 20
WITHDRAWAL_AMOUNT = 10


@pytest.fixture(scope="function")
def context():
    ctx = IconScoreContext(IconScoreContextType.DIRECT)
    block = Block(0, None, 0, None, 0)
    ctx.block = block
    ContextContainer._push_context(ctx)
    yield ctx
    ContextContainer._pop_context()


class TestAccount: