def test_array_db(self, score_db): name = "TEST" test_array = ArrayDB(name, score_db, value_type=int) assert test_array._db != score_db test_array.put(1) test_array.put(3) test_array.put(5) test_array.put(7) assert len(test_array) == 4 assert test_array.pop() == 7 assert test_array.pop() == 5 assert len(test_array) == 2
def test_array_db(self): name = "TEST" testarray = ArrayDB(name, self.db, value_type=int) self.assertNotEqual(testarray._db, self.db) self.assertEqual(testarray._db._prefix, ContainerUtil.create_db_prefix(ArrayDB, name)) testarray.put(1) testarray.put(3) testarray.put(5) testarray.put(7) self.assertEqual(4, len(testarray)) self.assertEqual(7, testarray.pop()) self.assertEqual(5, testarray.pop()) self.assertEqual(2, len(testarray))
def test_array_db(self, score_db): name = "TEST" testarray = ArrayDB(name, score_db, value_type=int) assert testarray._db != score_db assert testarray._db._prefix == ContainerUtil.create_db_prefix( ArrayDB, name) testarray.put(1) testarray.put(3) testarray.put(5) testarray.put(7) assert len(testarray) == 4 assert testarray.pop() == 7 assert testarray.pop() == 5 assert len(testarray) == 2
def test_array_db(self, context, key_value_db, values, value_type): context_db = ContextDatabase(key_value_db, is_shared=False) address = Address(AddressPrefix.CONTRACT, os.urandom(20)) score_db = IconScoreDatabase(address, context_db) self._init_context(context, score_db.address) self._set_revision(context, Revision.USE_RLP.value - 1) name = "array_db" array_db = ArrayDB(name, score_db, value_type) for i in range(2): array_db.put(values[i]) assert len(array_db) == 2 self._set_revision(context, Revision.USE_RLP.value) array_db.put(values[2]) array_db.put(values[3]) assert len(array_db) == 4 for i, value in enumerate(array_db): assert value == values[i] final_key: bytes = _get_final_key(address, ContainerTag.ARRAY, name.encode(), use_rlp=True) assert key_value_db.get(final_key) == int_to_bytes(len(array_db)) for i, use_rlp in enumerate((False, False, True, True)): key = _get_final_key( address.to_bytes(), ContainerTag.ARRAY.value, name.encode(), int_to_bytes(i), use_rlp=use_rlp, ) assert key_value_db.get(key) == ContainerUtil.encode_value(values[i]) for v in reversed(values): assert v == array_db.pop() assert len(array_db) == 0 # 2 values for array_db size still remain # even though all items in array_db have been popped. assert len(key_value_db) == 2