def test_mix_ops(self): """Test mixin insert/update/delete operations""" storage = MemoryBalanceStorage() insert = {str(a): a for a in range(5000)} storage.update(insert=insert, height=77) for a in range(5000): self.assertEqual(storage.get(str(a)), a) # Mixed op insert = {str(a): a for a in range(10000, 15000)} update = {str(a): 66 for a in range(1000)} delete = [str(a) for a in range(1000, 3000)] storage.update(insert=insert, update=update, delete=delete, height=99) for a in range(10000, 15000): self.assertEqual(storage.get(str(a)), a) for a in range(3000, 5000): self.assertEqual(storage.get(str(a)), a) for a in range(1000): self.assertEqual(storage.get(str(a)), 66) for a in range(1000, 3000): with self.assertRaises(KeyError): storage.get(str(a)) self.assertEqual(storage.height, 99)
def test_insert_balance(self): storage = MemoryBalanceStorage() insert = {str(a): a for a in range(10000)} storage.update(insert=insert, height=66) for a in range(10000): self.assertEqual(storage.get(str(a)), a) self.assertEqual(storage.height, 66)
def test_delete_balance(self): storage = MemoryBalanceStorage() insert = {str(a): a for a in range(10000)} storage.update(insert=insert) for a in range(10000): self.assertEqual(storage.get(str(a)), a) delete = set([str(a) for a in range(5000)]) storage.update(delete=delete, height=44) for a in range(5000): with self.assertRaises(KeyError): storage.get(str(a)) self.assertEqual(storage.height, 44)
def test_update_balance(self): storage = MemoryBalanceStorage() insert = {str(a): a for a in range(10000)} storage.update(insert=insert) for a in range(10000): self.assertEqual(storage.get(str(a)), a) update = {str(a): 10 for a in range(5000)} storage.update(update=update, height=88) for a in range(5000): self.assertEqual(storage.get(str(a)), 10) self.assertEqual(storage.height, 88)
def test_get_balance(self): storage = MemoryBalanceStorage() storage.update(insert={"addr1": 1, "addr2": 2}, height=33) self.assertEqual(storage.height, 33) self.assertEqual(storage.get("addr1", 1), 1) self.assertEqual(storage.get("addr2", 2), 2) # Missing address raise exception with self.assertRaises(KeyError): storage.get("addr3") # Check default keyword self.assertEqual(storage.get("addr3", 77), 77) self.assertEqual(storage.get("addr1", 77), 1) self.assertEqual(storage.get("addr2", 77), 2)
def test_get_bulk_balance(self): """ """ storage = MemoryBalanceStorage() insert = { "addr1": 1, "addr2": 2, "addr3": 3, } storage.update(insert=insert) result = dict(storage.get_bulk(set(["addr1", "addr2", "addr4"]))) self.assertEqual(len(result), 2) self.assertTrue('addr1' in result) self.assertTrue('addr2' in result) result = dict(storage.get_bulk({"addr4": 55})) self.assertEqual(len(result), 0)