def test_offer_puzzle(self):
     coin_spend = CoinSpend(
         COIN,
         OFFER_MOD,
         SOLUTION,
     )
     compressed = compress_object_with_puzzles(bytes(coin_spend),
                                               LATEST_VERSION)
     assert len(bytes(coin_spend)) > len(compressed)
     assert coin_spend == CoinSpend.from_bytes(
         decompress_object_with_puzzles(compressed))
     self.compression_factors["offer_puzzle"] = len(
         bytes(compressed)) / len(bytes(coin_spend))
 def test_standard_puzzle(self):
     coin_spend = CoinSpend(
         COIN,
         puzzle_for_pk(G1Element()),
         SOLUTION,
     )
     compressed = compress_object_with_puzzles(bytes(coin_spend),
                                               LATEST_VERSION)
     assert len(bytes(coin_spend)) > len(compressed)
     assert coin_spend == CoinSpend.from_bytes(
         decompress_object_with_puzzles(compressed))
     self.compression_factors["standard_puzzle"] = len(
         bytes(compressed)) / len(bytes(coin_spend))
 def _row_to_farmer_record(row) -> FarmerRecord:
     return FarmerRecord(
         bytes.fromhex(row[0]),
         bytes.fromhex(row[1]),
         row[2],
         bytes.fromhex(row[3]),
         G1Element.from_bytes(bytes.fromhex(row[4])),
         CoinSpend.from_bytes(row[5]),
         PoolState.from_bytes(row[6]),
         row[7],
         row[8],
         row[9],
         True if row[10] == 1 else False,
     )
 def test_unknown_wrapper(self):
     unknown = Program.to([2, 2, []])  # (a 2 ())
     coin_spend = CoinSpend(
         COIN,
         unknown.curry(puzzle_for_pk(G1Element())),
         SOLUTION,
     )
     compressed = compress_object_with_puzzles(bytes(coin_spend),
                                               LATEST_VERSION)
     assert len(bytes(coin_spend)) > len(compressed)
     assert coin_spend == CoinSpend.from_bytes(
         decompress_object_with_puzzles(compressed))
     self.compression_factors["unknown_and_standard"] = len(
         bytes(compressed)) / len(bytes(coin_spend))
 def test_nesting_puzzles(self):
     coin_spend = CoinSpend(
         COIN,
         construct_cat_puzzle(CAT_MOD,
                              Program.to([]).get_tree_hash(),
                              puzzle_for_pk(G1Element())),
         SOLUTION,
     )
     compressed = compress_object_with_puzzles(bytes(coin_spend),
                                               LATEST_VERSION)
     assert len(bytes(coin_spend)) > len(compressed)
     assert coin_spend == CoinSpend.from_bytes(
         decompress_object_with_puzzles(compressed))
     self.compression_factors["cat_w_standard_puzzle"] = len(
         bytes(compressed)) / len(bytes(coin_spend))
Esempio n. 6
0
 async def rebuild_cache(self) -> None:
     """
     This resets the cache, and loads all entries from the DB. Any entries in the cache that were not committed
     are removed. This can happen if a state transition in wallet_blockchain fails.
     """
     cursor = await self.db_connection.execute("SELECT * FROM pool_state_transitions ORDER BY transition_index")
     rows = await cursor.fetchall()
     await cursor.close()
     self._state_transitions_cache = {}
     for row in rows:
         _, wallet_id, height, coin_spend_bytes = row
         coin_spend: CoinSpend = CoinSpend.from_bytes(coin_spend_bytes)
         if wallet_id not in self._state_transitions_cache:
             self._state_transitions_cache[wallet_id] = []
         self._state_transitions_cache[wallet_id].append((height, coin_spend))