How to use the iconservice.icon_constant.Revision function in iconservice

To help you get started, we’ve selected a few iconservice examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github icon-project / icon-service / tests / integrate_test / iiss / decentralized / test_base_transaction_validation.py View on Github external
def _init_decentralized(self):
        # decentralized
        self.update_governance()

        # set Revision REV_IISS
        self.set_revision(Revision.IISS.value)

        total_supply = TOTAL_SUPPLY * ICX_IN_LOOP
        # Minimum_delegate_amount is 0.02 * total_supply
        # In this test delegate 0.03*total_supply because `Issue transaction` exists since REV_IISS
        minimum_delegate_amount_for_decentralization: int = total_supply * 2 // 1000 + 1
        init_balance: int = minimum_delegate_amount_for_decentralization * 2

        # distribute icx PREP_MAIN_PREPS ~ PREP_MAIN_PREPS + PREP_MAIN_PREPS - 1
        self.distribute_icx(accounts=self._accounts[PREP_MAIN_PREPS:PREP_MAIN_AND_SUB_PREPS],
                            init_balance=init_balance)

        # stake PREP_MAIN_PREPS ~ PREP_MAIN_PREPS + PREP_MAIN_PREPS - 1
        stake_amount: int = minimum_delegate_amount_for_decentralization
        tx_list: list = []
        for i in range(PREP_MAIN_PREPS):
            tx: dict = self.create_set_stake_tx(from_=self._accounts[PREP_MAIN_PREPS + i],
github icon-project / icon-service / tests / integrate_test / iiss / decentralized / test_changed_minimum_delegate.py View on Github external
def test_decentralized_minimum_delegation_set_zero(self):
        self.update_governance()
        # set Revision REV_IISS
        self.set_revision(Revision.IISS.value)

        # distribute icx for register PREP_MAIN_PREPS ~ PREP_MAIN_PREPS + PREP_MAIN_PREPS - 1
        self.distribute_icx(accounts=self._accounts[:PREP_MAIN_PREPS],
                            init_balance=3000 * ICX_IN_LOOP)

        # register PRep
        tx_list: list = []
        for i, address in enumerate(self._accounts[:PREP_MAIN_PREPS]):
            tx: dict = self.create_register_prep_tx(address)
            tx_list.append(tx)
        self.process_confirm_block_tx(tx_list)

        # set Revision REV_IISS (decentralization)
        self.set_revision(Revision.DECENTRALIZATION.value)

        self.make_blocks_to_end_calculation()
github icon-project / icon-service / tests / unit_test / iconscore / test_icon_score_api.py View on Github external
def context(settable_inv_container: INVContainer):
    prep_engine = PRepEngine()
    prep_engine.prep_address_converter = mock.Mock()
    inv_engine = INVEngine()
    settable_inv_container.set_inv(StepPrice(10 ** 10))
    settable_inv_container.set_inv(StepCosts(STEP_COSTS))
    settable_inv_container.set_inv(MaxStepLimits({IconScoreContextType.INVOKE: 2_500_000_000}))
    settable_inv_container.set_inv(RevisionCode(Revision.THREE.value))
    inv_engine._inv_container = settable_inv_container

    IconScoreContext.engine = ContextEngine(prep=prep_engine, inv=inv_engine)
    context_factory = IconScoreContextFactory()

    block = Block(block_height=1, block_hash=b"1" * 40, prev_hash=b"0" * 40, timestamp=0)
    context = context_factory.create(IconScoreContextType.INVOKE, block)

    step_limit = 1_000_000_000
    context.set_step_counter(step_limit)

    ContextContainer._push_context(context)
    yield context
    ContextContainer._pop_context()
github icon-project / icon-service / tests / integrate_test / test_integrate_container_db_patch.py View on Github external
def test_array_db_patch(self):
        self.update_governance("0_0_4")
        self.set_revision(Revision.THREE.value)

        expected_status = {
            "code": Revision.THREE.value,
            "name": f"1.1.{Revision.THREE.value}"
        }
        query_request = {
            "version": self._version,
            "from": self._accounts[0],
            "to": GOVERNANCE_SCORE_ADDRESS,
            "dataType": "call",
            "data": {
                "method": "getRevision",
                "params": {}
            }
        }
        response = self._query(query_request)
        self.assertEqual(expected_status, response)

        tx_results: List['TransactionResult'] = self.deploy_score("sample_scores",
github icon-project / icon-service / tests / integrate_test / test_integrate_sending_icx_using_fee.py View on Github external
def test_send_icx_without_data(self):
        step_price = 10 ** 10
        default_step_cost = 100_000
        input_step_cost = 200
        value = 1 * ICX_IN_LOOP

        self.update_governance()

        for revision in range(Revision.TWO.value, Revision.LATEST.value + 1):
            self.set_revision(revision)

            # Create a new to address every block
            balance0: int = self.get_balance(self._admin)
            self.assertTrue(balance0 > 0)

            # Check "to" address balance. It should be 0
            to: 'Address' = create_address()
            to_balance: int = self.get_balance(to)
            self.assertEqual(0, to_balance)

            if revision == Revision.THREE.value:
                # Check backward compatibility on TestNet Database
                # step_used increases by input_step_cost * len(json.dumps(None))
                # because of None parameter handling error on get_input_data_size()
                step_limit = default_step_cost + input_step_cost * len(json.dumps(None))
github icon-project / icon-service / tests / integrate_test / iiss / prevote / test_prep_registration_fee.py View on Github external
actual_burn_signature = reg_tx_result.event_logs[0].indexed[0]

        self.assertEqual("ICXBurned", actual_burn_signature)

        # TEST: When revision is between 'DECENTRALIZATION' and 'FIX_BURN_EVENT_SIGNATURE',
        # burn signature should not have type format
        self._init_decentralized()
        prep = preps[1]

        reg_tx_result: 'TransactionResult' = self.register_prep(from_=prep, value=config_value)[1]
        actual_burn_signature = reg_tx_result.event_logs[0].indexed[0]

        self.assertEqual("ICXBurned", actual_burn_signature)

        # TEST: After 'FIX_BURN_EVENT_SIGNATURE' revision is accepted, burn signature should have type format
        self.set_revision(Revision.FIX_BURN_EVENT_SIGNATURE.value)
        prep = preps[2]

        reg_tx_result: 'TransactionResult' = self.register_prep(from_=prep, value=config_value)[1]
        actual_burn_signature = reg_tx_result.event_logs[0].indexed[0]

        self.assertEqual("ICXBurned(int)", actual_burn_signature)
github icon-project / icon-service / tests / legacy_unittest / prep / test_prep_data_validator.py View on Github external
"invalid email",
        "invalid.com",
        "invalid@",
        "invalid@a",
        "invalid@a.",
        "invalid@.com",
        "invalid.@asdf.com-",
        "email@domain..com",
        "invalid@abcd@abcd.com",
        "john..doe@example.com",
        ".invalid@email.com",
    ]

    for email in invalid_email_list:
        with pytest.raises(InvalidParamsException) as e:
            _validate_email(Revision.DECENTRALIZATION.value, email)
        assert e.value.message == "Invalid email format"

    valid_email_list = ["example@localhost", "user@email.com"]
    for email in valid_email_list:
        try:
            _validate_email(Revision.DECENTRALIZATION.value, email)
        except BaseException:
            pytest.fail("Validating email test failed")
github icon-project / icon-service / tests / unit_test / iiss / test_reward_calc_data_storage.py View on Github external
def expected_rc_data_by_revision(revision: int):
    if revision < Revision.DECENTRALIZATION.value:
        expected_header_revision = 0
        expected_gv_config_main_prep_count = 0
        expected_gv_config_sub_prep_count = 0
        return (RC_DB_VERSION_0,
                expected_header_revision,
                expected_gv_config_main_prep_count,
                expected_gv_config_sub_prep_count)
    else:
        expected_header_revision = revision
        expected_gv_config_main_prep_count = CONFIG_MAIN_PREP_COUNT
        expected_gv_config_sub_prep_count = CONFIG_SUB_PREP_COUNT
        return (RC_DB_VERSION_2,
                expected_header_revision,
                expected_gv_config_main_prep_count,
                expected_gv_config_sub_prep_count)
github icon-project / icon-service / tests / unit_test / iconscore / test_icon_score_step.py View on Github external
    @pytest.mark.parametrize("revision", [r.value for r in Revision if r.value < Revision.THREE.value])
    @pytest.mark.parametrize("input_data, expected_call_data", [(x, [mock.call(x)]) for x in INPUT])
    def test_less_than_revision_three(self,
                                      mock_get_data_size_recursively, mock_get_data_size_using_json_dumps,
                                      revision, input_data, expected_call_data):
        get_input_data_size(revision, input_data)
        mock_get_data_size_recursively.assert_called_once_with(input_data)
        mock_get_data_size_using_json_dumps.assert_not_called()
github icon-project / icon-service / iconservice / iconscore / icon_score_event_log.py View on Github external
def __get_byte_length(context: 'IconScoreContext', data: 'BaseType') -> int:
        if data is None:
            return 0
        elif isinstance(data, int):
            return byte_length_of_int(data)
        elif isinstance(data, Address):
            if context.revision < Revision.THREE.value:
                return ICON_ADDRESS_BODY_SIZE
            else:
                return ICON_ADDRESS_BYTES_SIZE

        return len(EventLogEmitter.__get_bytes_from_base_type(data))