Exemple #1
0
    def test_msgpack_for_db_loads_dumps(self):
        int_table = [-1, 0, 1, 10**30]
        bytes_table = [b'hello', b'', ZERO_SCORE_ADDRESS.to_bytes()]
        str_table = ["hello", ""]
        address_table = [create_address(), create_address(1)]
        dict_table = {"1": 1, "2": 2, "3": 3}
        list_table = [1, 2, 3, 4, 5]
        bool_table = [True, False]
        None_table = [None]

        expected_struct: list = [
            int_table, bytes_table, str_table, address_table, dict_table,
            list_table, bool_table, None_table
        ]

        data: bytes = MsgPackForDB.dumps(expected_struct)
        struct: list = MsgPackForDB.loads(data)
        self.assertEqual(expected_struct, struct)
    def run(self, args):
        db_path: str = args.db

        state_reader = StateDatabaseReader()
        state_reader.open(db_path)

        picked_number = self.get_list_idx()

        value = state_reader.get_by_key(self.COMMAND_LIST[picked_number].key)

        if value is not None:
            pprint(
                self.COMMAND_LIST[picked_number].from_func(MsgPackForDB.loads(value))
            )
        else:
            print(f"value is not exist, key = {self.COMMAND_LIST[picked_number].key}")

        state_reader.close()
Exemple #3
0
    def test_putting_i_score_data_on_current_db(self):
        # success case: If there is no prev_calc_period_issued_i_score, should return None
        actual_i_score, _, _ = self.rc_data_storage.get_calc_response_from_rc()
        assert actual_i_score == -1

        # success case: put i score and get i score from the db
        expected_i_score = 10_000
        expected_version = 1
        expected_block_height = 0
        expected_state_hash: bytes = sha3_256(b"state_hash")
        assert isinstance(expected_state_hash, bytes)
        assert len(expected_state_hash) == 32

        self.rc_data_storage.put_calc_response_from_rc(expected_i_score, expected_block_height, expected_state_hash)
        i_score_db_data = MsgPackForDB.loads(self.rc_data_storage._db.get(self.rc_data_storage.KEY_FOR_CALC_RESPONSE_FROM_RC))
        assert i_score_db_data[0] == expected_version
        assert i_score_db_data[1] == expected_i_score
        assert i_score_db_data[2] == expected_block_height
        assert i_score_db_data[3] == expected_state_hash

        actual_i_score, _, _ = self.rc_data_storage.get_calc_response_from_rc()
        assert actual_i_score == expected_i_score
Exemple #4
0
 def _prt_length_info(self, tag: str, data_list: list):
     data: bytes = MsgPackForDB.dumps(data_list)
     print(f"{tag} data: {data_list}")
     print(f"{tag} length: {len(data)}")
 def _convert_calc_period(cls, key: bytes, value: bytes):
     converted_key: str = f"Calc Period (key: {key})"
     converted_value: str = str(MsgPackForDB.loads(value))
     return converted_key, converted_value
 def _convert_calc_end_block_height(cls, key: bytes, value: bytes):
     converted_key: str = f"Calc End BH (key: {key})"
     converted_value: str = str(MsgPackForDB.loads(value))
     return converted_key, converted_value
 def _convert_total_stake(cls, key: bytes, value: bytes):
     converted_key: str = f"Total Stake (key: {key})"
     converted_value: str = str(MsgPackForDB.loads(value))
     return converted_key, converted_value
 def _convert_prep_registration_fee(cls, key, value):
     data = MsgPackForDB.loads(value)
     return f"Prep registration fee (bytes: {key})", str(data)
 def _convert_term(cls, key, value):
     data = MsgPackForDB.loads(value)
     return f"Term (bytes: {key})", str(data)
Exemple #10
0
 def _convert_last_term_info(cls, key: bytes, value: bytes):
     converted_value: list = MsgPackForDB.loads(value)
     return key.decode(), str(converted_value)
Exemple #11
0
 def _convert_last_main_preps(cls, key: bytes, value: bytes):
     data: list = MsgPackForDB.loads(value)
     _version = data[0]
     return key.decode(), str(data)