예제 #1
0
    def test_digest(self):
        block_batch = self.block_batch

        tx_batch = TransactionBatch(create_hash_256())
        key0 = create_hash_256()
        tx_batch[key0] = TransactionBatchValue(b'value0', True)
        key1 = create_hash_256()
        tx_batch[key1] = TransactionBatchValue(b'value1', True)
        key2 = create_hash_256()
        tx_batch[key2] = TransactionBatchValue(b'value2', True)

        block_batch.update(tx_batch)
        data = [key0, b'value0', key1, b'value1', key2, b'value2']
        expected = sha3_256(b'|'.join(data))
        ret = block_batch.digest()
        self.assertEqual(expected, ret)

        tx_batch[key2] = TransactionBatchValue(None, True)
        block_batch.update(tx_batch)
        hash1 = block_batch.digest()

        tx_batch[key2] = TransactionBatchValue(b'', True)
        block_batch.update(tx_batch)
        hash2 = block_batch.digest()
        self.assertNotEqual(hash1, hash2)
예제 #2
0
    def test_digest_with_excluded_data(self):
        block_batch = self.block_batch

        tx_batch = TransactionBatch(create_hash_256())
        include_key1 = create_hash_256()
        tx_batch[include_key1] = TransactionBatchValue(b'value0', True)
        include_key2 = create_hash_256()
        tx_batch[include_key2] = TransactionBatchValue(b'value1', True)
        include_key3 = create_hash_256()
        tx_batch[include_key3] = TransactionBatchValue(b'', True)
        include_key4 = create_hash_256()
        tx_batch[include_key4] = TransactionBatchValue(None, True)

        exclude_key1 = create_hash_256()
        tx_batch[exclude_key1] = TransactionBatchValue(b'value2', False)
        exclude_key2 = create_hash_256()
        tx_batch[exclude_key2] = TransactionBatchValue(b'value3', False)

        block_batch.update(tx_batch)
        data = [
            include_key1, b'value0', include_key2, b'value1', include_key3,
            b'', include_key4
        ]
        expected = sha3_256(b'|'.join(data))
        ret = block_batch.digest()
        self.assertEqual(expected, ret)
예제 #3
0
    def test_digest(self):
        block_batch = self.block_batch

        key0 = create_hash_256()
        block_batch[key0] = b'value0'
        key1 = create_hash_256()
        block_batch[key1] = b'value1'
        key2 = create_hash_256()
        block_batch[key2] = b'value2'

        data = [key0, b'value0', key1, b'value1', key2, b'value2']
        expected = sha3_256(b'|'.join(data))
        ret = block_batch.digest()
        self.assertEqual(expected, ret)

        block_batch[key2] = None
        hash1 = block_batch.digest()
        block_batch[key2] = b''
        hash2 = block_batch.digest()
        self.assertNotEqual(hash1, hash2)
예제 #4
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
예제 #5
0
def hash_db_key(address: 'Address', key: bytes) -> bytes:
    data = [address.to_bytes(), key]
    return sha3_256(b'|'.join(data))