From 429d7874a03a8923f8bb2c84e263b0ab85ad099c Mon Sep 17 00:00:00 2001 From: Mariano Sorgente <3069354+mariano54@users.noreply.github.com> Date: Sun, 30 Aug 2020 19:40:59 +0900 Subject: [PATCH] Fix lint, and catch harvester drive access failure --- src/plotting/plot_tools.py | 17 ++++++++------- src/wallet/cc_wallet/cc_wallet.py | 21 ++++++++++--------- src/wallet/cc_wallet/cc_wallet_puzzles.py | 4 +++- src/wallet/cc_wallet/test_cc.py | 4 +++- .../p2_delegated_puzzle_or_hidden_puzzle.py | 4 +++- .../puzzles/p2_m_of_n_delegate_direct.py | 4 +++- src/wallet/trade_manager.py | 6 ++++-- src/wallet/util/cc_utils.py | 4 +++- tests/rl_wallet/test_rl_rpc.py | 19 ++++++++++------- 9 files changed, 52 insertions(+), 31 deletions(-) diff --git a/src/plotting/plot_tools.py b/src/plotting/plot_tools.py index b5fc7207..94056cc5 100644 --- a/src/plotting/plot_tools.py +++ b/src/plotting/plot_tools.py @@ -30,13 +30,16 @@ def _get_filenames(directory: Path) -> List[Path]: log.warning(f"Directory: {directory} does not exist.") return [] all_files: List[Path] = [] - for child in directory.iterdir(): - if not child.is_dir(): - # If it is a file ending in .plot, add it - if child.suffix == ".plot": - all_files.append(child) - else: - log.info(f"Not checking subdirectory {child}") + try: + for child in directory.iterdir(): + if not child.is_dir(): + # If it is a file ending in .plot, add it + if child.suffix == ".plot": + all_files.append(child) + else: + log.info(f"Not checking subdirectory {child}") + except Exception as e: + log.info(f"Error reading directory {directory} {e}") return all_files diff --git a/src/wallet/cc_wallet/cc_wallet.py b/src/wallet/cc_wallet/cc_wallet.py index 6b13d532..942d2e45 100644 --- a/src/wallet/cc_wallet/cc_wallet.py +++ b/src/wallet/cc_wallet/cc_wallet.py @@ -337,7 +337,9 @@ class CCWallet: if coin is not None: if cc_wallet_puzzles.check_is_cc_puzzle(puzzle_program): - inner_puzzle_hash = get_inner_puzzle_hash_from_puzzle(puzzle_program) + inner_puzzle_hash = get_inner_puzzle_hash_from_puzzle( + puzzle_program + ) self.log.info( f"parent: {coin_name} inner_puzzle for parent is {inner_puzzle_hash.hex()}" @@ -393,9 +395,7 @@ class CCWallet: return new def puzzle_for_pk(self, pubkey) -> Program: - inner_puzzle = self.standard_wallet.puzzle_for_pk( - bytes(pubkey) - ) + inner_puzzle = self.standard_wallet.puzzle_for_pk(bytes(pubkey)) inner_puzzle_hash = inner_puzzle.get_tree_hash() cc_puzzle: Program = self.cc_info.puzzle_for_inner_puzzle(inner_puzzle) self.base_puzzle_program = bytes(cc_puzzle) @@ -440,7 +440,9 @@ class CCWallet: eve_spend = cc_generate_eve_spend(eve_coin, cc_inner_puzzle, genesis_id) full_spend = SpendBundle.aggregate([tx.spend_bundle, eve_spend]) - future_parent = CCParent(eve_coin.parent_coin_info, cc_inner_puzzle_hash, eve_coin.amount) + future_parent = CCParent( + eve_coin.parent_coin_info, cc_inner_puzzle_hash, eve_coin.amount + ) eve_parent = CCParent( origin.parent_coin_info, origin.puzzle_hash, origin.amount ) @@ -794,7 +796,9 @@ class CCWallet: await self.save_info(cc_info) cc_inner_puzzle = await self.get_new_inner_puzzle() - cc_puzzle = cc_wallet_puzzles.puzzle_for_inner_puzzle(cc_inner_puzzle, origin_id) + cc_puzzle = cc_wallet_puzzles.puzzle_for_inner_puzzle( + cc_inner_puzzle, origin_id + ) cc_puzzle_hash = cc_puzzle.get_tree_hash() tx_record: Optional[ @@ -867,10 +871,7 @@ class CCWallet: CoinSolution( coin, Program.to( - [ - self.cc_info.puzzle_for_inner_puzzle(innerpuz), - solution, - ] + [self.cc_info.puzzle_for_inner_puzzle(innerpuz), solution] ), ) ) diff --git a/src/wallet/cc_wallet/cc_wallet_puzzles.py b/src/wallet/cc_wallet/cc_wallet_puzzles.py index 77aba346..871a115e 100644 --- a/src/wallet/cc_wallet/cc_wallet_puzzles.py +++ b/src/wallet/cc_wallet/cc_wallet_puzzles.py @@ -74,7 +74,9 @@ def cc_make_solution( aggees_program = Program.to([] if auditees is None else [list(_) for _ in auditees]) - solution = Program.to([parent, amount, inner_solution, auditor_list, aggees_program]) + solution = Program.to( + [parent, amount, inner_solution, auditor_list, aggees_program] + ) return solution diff --git a/src/wallet/cc_wallet/test_cc.py b/src/wallet/cc_wallet/test_cc.py index f183ab71..7dfb9034 100644 --- a/src/wallet/cc_wallet/test_cc.py +++ b/src/wallet/cc_wallet/test_cc.py @@ -34,7 +34,9 @@ CC_MOD = load_clvm("cc.clvm", package_or_requirement=__name__) ZERO_GENESIS_MOD = load_clvm("zero-genesis.clvm", package_or_requirement=__name__) -PUZZLE_TABLE: Dict[bytes32, Program] = dict((_.get_tree_hash(), _) for _ in [ANYONE_CAN_SPEND_PUZZLE]) +PUZZLE_TABLE: Dict[bytes32, Program] = dict( + (_.get_tree_hash(), _) for _ in [ANYONE_CAN_SPEND_PUZZLE] +) def hash_to_puzzle_f(puzzle_hash: bytes32) -> Optional[Program]: diff --git a/src/wallet/puzzles/p2_delegated_puzzle_or_hidden_puzzle.py b/src/wallet/puzzles/p2_delegated_puzzle_or_hidden_puzzle.py index 871fdd1a..62f79d09 100644 --- a/src/wallet/puzzles/p2_delegated_puzzle_or_hidden_puzzle.py +++ b/src/wallet/puzzles/p2_delegated_puzzle_or_hidden_puzzle.py @@ -50,7 +50,9 @@ def puzzle_for_public_key_and_hidden_puzzle( return puzzle_for_synthetic_public_key(synthetic_public_key) -def solution_with_delegated_puzzle(synthetic_public_key, delegated_puzzle, solution) -> Program: +def solution_with_delegated_puzzle( + synthetic_public_key, delegated_puzzle, solution +) -> Program: puzzle = puzzle_for_synthetic_public_key(synthetic_public_key) return Program.to([puzzle, [[], delegated_puzzle, solution]]) diff --git a/src/wallet/puzzles/p2_m_of_n_delegate_direct.py b/src/wallet/puzzles/p2_m_of_n_delegate_direct.py index 90ffa0fa..c12b8d66 100644 --- a/src/wallet/puzzles/p2_m_of_n_delegate_direct.py +++ b/src/wallet/puzzles/p2_m_of_n_delegate_direct.py @@ -17,6 +17,8 @@ def puzzle_for_m_of_public_key_list(m, public_key_list) -> Program: return MOD.curry(m, public_key_list) -def solution_for_delegated_puzzle(m, public_key_list, selectors, puzzle, solution) -> Program: +def solution_for_delegated_puzzle( + m, public_key_list, selectors, puzzle, solution +) -> Program: puzzle_reveal = puzzle_for_m_of_public_key_list(m, public_key_list) return Program.to([puzzle_reveal, [selectors, puzzle, solution]]) diff --git a/src/wallet/trade_manager.py b/src/wallet/trade_manager.py index 262442ff..04c50b4c 100644 --- a/src/wallet/trade_manager.py +++ b/src/wallet/trade_manager.py @@ -424,7 +424,9 @@ class TradeManager: ) if coinsol.coin in [record.coin for record in unspent]: return False, None, "can't respond to own offer" - innerpuzzlereveal = cc_wallet_puzzles.get_inner_puzzle_from_puzzle(puzzle) + innerpuzzlereveal = cc_wallet_puzzles.get_inner_puzzle_from_puzzle( + puzzle + ) innersol = cc_wallet_puzzles.inner_puzzle_solution(solution) out_amount = cc_wallet_puzzles.get_output_amount_for_puzzle_and_solution( innerpuzzlereveal, innersol @@ -661,7 +663,7 @@ class TradeManager: cc_wallet_puzzles.puzzle_for_inner_puzzle( auditor_inner_puzzle, bytes.fromhex(colour), ), - solution + solution, ] ), ) diff --git a/src/wallet/util/cc_utils.py b/src/wallet/util/cc_utils.py index b1c0afe4..b6b0187f 100644 --- a/src/wallet/util/cc_utils.py +++ b/src/wallet/util/cc_utils.py @@ -53,7 +53,9 @@ def get_discrepancies_for_spend_bundle( if not cc_wallet_puzzles.is_ephemeral_solution(solution): colour = cc_wallet_puzzles.get_genesis_from_puzzle(puzzle).hex() # get puzzle and solution - innerpuzzlereveal = cc_wallet_puzzles.get_inner_puzzle_from_puzzle(puzzle) + innerpuzzlereveal = cc_wallet_puzzles.get_inner_puzzle_from_puzzle( + puzzle + ) innersol = cc_wallet_puzzles.inner_puzzle_solution(solution) # Get output amounts by running innerpuzzle and solution out_amount = cc_wallet_puzzles.get_output_amount_for_puzzle_and_solution( diff --git a/tests/rl_wallet/test_rl_rpc.py b/tests/rl_wallet/test_rl_rpc.py index bc3673b3..3e7f2190 100644 --- a/tests/rl_wallet/test_rl_rpc.py +++ b/tests/rl_wallet/test_rl_rpc.py @@ -77,7 +77,7 @@ class TestCCWallet: assert val["type"] == WalletType.RATE_LIMITED.value assert val["origin"] assert val["pubkey"] - admin_wallet_id = val['id'] + admin_wallet_id = val["id"] admin_pubkey = val["pubkey"] origin: Coin = val["origin"] @@ -96,9 +96,9 @@ class TestCCWallet: ) assert val["success"] - assert (await api_user.get_wallet_balance({"wallet_id": user_wallet_id}))["wallet_balance"][ - "confirmed_wallet_balance" - ] == 0 + assert (await api_user.get_wallet_balance({"wallet_id": user_wallet_id}))[ + "wallet_balance" + ]["confirmed_wallet_balance"] == 0 for i in range(0, 2 * num_blocks): await full_node.farm_new_block(FarmNewBlockProtocol(32 * b"\0")) @@ -112,7 +112,12 @@ class TestCCWallet: puzzle_hash = encode_puzzle_hash(await receiving_wallet.get_new_puzzlehash()) assert await receiving_wallet.get_spendable_balance() == 0 val = await api_user.send_transaction( - {"wallet_id": user_wallet_id, "amount": 3, "fee": 0, "puzzle_hash": puzzle_hash} + { + "wallet_id": user_wallet_id, + "amount": 3, + "fee": 0, + "puzzle_hash": puzzle_hash, + } ) assert val["status"] == "SUCCESS" @@ -121,8 +126,8 @@ class TestCCWallet: await time_out_assert(15, check_balance, 97, api_user, user_wallet_id) await time_out_assert(15, receiving_wallet.get_spendable_balance, 3) - val = await api_admin.send_clawback_transaction({'wallet_id': admin_wallet_id}) - assert val['status'] == 'SUCCESS' + val = await api_admin.send_clawback_transaction({"wallet_id": admin_wallet_id}) + assert val["status"] == "SUCCESS" for i in range(0, num_blocks): await full_node.farm_new_block(FarmNewBlockProtocol(32 * b"\0")) await time_out_assert(15, check_balance, 0, api_admin, admin_wallet_id)