Fix flake8 - clean up tests and add to flake8 - lint src upload to pypi

This commit is contained in:
Gene Hoffman 2020-06-29 11:46:27 -07:00 committed by Gene Hoffman
parent 981756c45c
commit 2e25ca131c
25 changed files with 72 additions and 99 deletions

View File

@ -94,7 +94,7 @@ jobs:
- name: Lint source with flake8
run: |
./venv/bin/flake8 src
./venv/bin/flake8 src tests
- name: Lint source with mypy
run: |

View File

@ -76,7 +76,7 @@ jobs:
- name: Lint source with flake8
run: |
./venv/bin/flake8 src
./venv/bin/flake8 src tests
- name: Lint source with mypy
run: |

View File

@ -34,9 +34,22 @@ jobs:
env:
SECRET: "${{ secrets.test_pypi_password }}"
- name: Build source distribution
- name: Install developer requirements
run: |
python -m pip install --upgrade pip
. ./activate
venv/bin/python -m pip install -r requirements-dev.txt
- name: Lint source with flake8
run: |
./venv/bin/flake8 src tests
- name: Lint source with mypy
run: |
./venv/bin/mypy src tests
- name: Build source distribution
run: |
pip install pep517
python -m pep517.build --source --out-dir dist .

View File

@ -23,10 +23,10 @@ def help_message():
print("usage: chia keys command")
print(f"command can be any of {command_list}")
print("")
print(f"chia keys generate (generates and adds a key to keychain)")
print(f"chia keys generate_and_print (generates but does NOT add to keychain)")
print(f"chia keys show (displays all the keys in keychain)")
print(f"chia keys add -m [24 words] (add a private key through the mnemonic)")
print("chia keys generate (generates and adds a key to keychain)")
print("chia keys generate_and_print (generates but does NOT add to keychain)")
print("chia keys show (displays all the keys in keychain)")
print("chia keys add -m [24 words] (add a private key through the mnemonic)")
print(
"chia keys delete -f [fingerprint] (delete a key by it's pk fingerprint in hex form)"
)

View File

@ -3,32 +3,28 @@ import sys
import time
import random
import tempfile
from bitstring import BitArray
from pathlib import Path
from typing import Any, Dict, List, Tuple, Optional
from typing import Dict, List, Tuple, Optional
from blspy import (
PrependSignature,
PrivateKey,
PublicKey,
ExtendedPublicKey,
InsecureSignature,
Util,
)
from chiavdf import prove
from chiabip158 import PyBIP158
from chiapos import DiskPlotter, DiskProver
from src import __version__
from chiapos import DiskPlotter
from src.consensus.coinbase import create_puzzlehash_for_pk
from src.consensus.constants import ConsensusConstants
from src.cmds.init import create_default_chia_config, initialize_ssl
from src.types.BLSSignature import BLSPublicKey
from src.consensus import block_rewards, pot_iterations
from src.consensus.pot_iterations import calculate_min_iters_from_iterations
from src.consensus.block_rewards import calculate_base_fee, calculate_block_reward
from src.consensus.pot_iterations import calculate_iterations
from src.consensus.block_rewards import calculate_block_reward
from src.consensus.coinbase import create_coinbase_coin, create_fees_coin
from src.types.challenge import Challenge
from src.types.classgroup import ClassgroupElement
@ -48,8 +44,8 @@ from src.util.hash import std_hash
from src.util.path import mkdir
from src.util.significant_bits import truncate_to_significant_bits
from src.util.mempool_check_conditions import get_name_puzzle_conditions
from src.util.config import load_config, load_config_cli, save_config
from src.util.plot_tools import load_plots, PlotInfo, stream_plot_info
from src.util.config import load_config, save_config
from src.util.plot_tools import load_plots, stream_plot_info
from src.util.logging import initialize_logging
from tests.wallet_tools import WalletTool
@ -582,7 +578,7 @@ class BlockTools:
fee_reward = uint64(block_rewards.calculate_base_fee(height) + fees)
parent_coin_name = std_hash(std_hash(height))
std_hash(std_hash(height))
# Create filter
byte_array_tx: List[bytes32] = []

View File

@ -1,12 +1,10 @@
import asyncio
import time
from pathlib import Path
from secrets import token_bytes
import pytest
from src.protocols import full_node_protocol
from src.simulator.simulator_protocol import FarmNewBlockProtocol, ReorgProtocol
from src.simulator.simulator_protocol import FarmNewBlockProtocol
from src.types.peer_info import PeerInfo
from src.util.ints import uint16, uint32, uint64
from src.wallet.trade_manager import TradeManager

View File

@ -1,19 +1,14 @@
import asyncio
from secrets import token_bytes
from pathlib import Path
from typing import Any, Dict
import sqlite3
import random
import aiosqlite
import pytest
from src.consensus.constants import constants as consensus_constants
from src.full_node.block_store import BlockStore
from src.full_node.coin_store import CoinStore
from src.full_node.blockchain import Blockchain
from src.types.full_block import FullBlock
from src.types.sized_bytes import bytes32
from src.util.ints import uint32, uint64
from tests.setup_nodes import test_constants, bt
@ -41,11 +36,11 @@ class TestBlockStore:
db_filename_3.unlink()
connection = await aiosqlite.connect(db_filename)
connection_2 = await aiosqlite.connect(db_filename_2)
# connection_2 = await aiosqlite.connect(db_filename_2)
connection_3 = await aiosqlite.connect(db_filename_3)
db = await BlockStore.create(connection)
db_2 = await BlockStore.create(connection_2)
# db_2 = await BlockStore.create(connection_2)
db_3 = await BlockStore.create(connection_3)
try:
genesis = FullBlock.from_bytes(test_constants["GENESIS_BLOCK"])
@ -89,7 +84,7 @@ class TestBlockStore:
except Exception:
await connection.close()
await connection_2.close()
# await connection_2.close()
await connection_3.close()
db_filename.unlink()
db_filename_2.unlink()
@ -98,7 +93,7 @@ class TestBlockStore:
raise
await connection.close()
await connection_2.close()
# await connection_2.close()
await connection_3.close()
db_filename.unlink()
db_filename_2.unlink()

View File

@ -1,6 +1,5 @@
import asyncio
import time
from typing import Any, Dict
from pathlib import Path
import aiosqlite
@ -12,7 +11,8 @@ from src.types.full_block import FullBlock
from src.types.header import Header, HeaderData
from src.types.proof_of_space import ProofOfSpace
from src.util.ints import uint8, uint64, uint32
from src.consensus.constants import constants as consensus_constants
from src.consensus.constants import ConsensusConstants
from tests.block_tools import BlockTools
from src.util.errors import Err
from src.types.sized_bytes import bytes32
from src.types.pool_target import PoolTarget
@ -20,6 +20,7 @@ from src.types.BLSSignature import BLSSignature
from src.full_node.block_store import BlockStore
from src.full_node.coin_store import CoinStore
from src.consensus.find_fork_point import find_fork_point_in_chain
from tests.make_test_constants import make_test_constants_with_genesis
from tests.setup_nodes import bt
@ -546,7 +547,7 @@ class TestBlockValidation:
diff_6 = b.get_next_difficulty(blocks[5].header)
diff_7 = b.get_next_difficulty(blocks[6].header)
diff_8 = b.get_next_difficulty(blocks[7].header)
diff_9 = b.get_next_difficulty(blocks[8].header)
# diff_9 = b.get_next_difficulty(blocks[8].header)
assert diff_6 == diff_7
assert diff_8 > diff_7

View File

@ -1,5 +1,4 @@
import asyncio
from typing import Any, Dict
from pathlib import Path
import aiosqlite
@ -8,7 +7,6 @@ import pytest
from src.full_node.blockchain import Blockchain, ReceiveBlockResult
from src.full_node.coin_store import CoinStore
from src.full_node.block_store import BlockStore
from src.consensus.constants import constants as consensus_constants
from tests.setup_nodes import test_constants, bt
test_constants_dict = test_constants.copy()

View File

@ -1,15 +1,11 @@
import asyncio
from secrets import token_bytes
from pathlib import Path
from typing import Any, Dict
import sqlite3
import random
import aiosqlite
import pytest
from src.full_node.full_node_store import FullNodeStore
from src.full_node.blockchain import Blockchain
from src.types.full_block import FullBlock
from src.types.sized_bytes import bytes32
from src.util.ints import uint32, uint64
from tests.setup_nodes import test_constants, bt
@ -26,7 +22,7 @@ class TestFullNodeStore:
async def test_basic_store(self):
assert sqlite3.threadsafety == 1
blocks = bt.get_consecutive_blocks(test_constants, 9, [], 9, b"0")
blocks_alt = bt.get_consecutive_blocks(test_constants, 3, [], 9, b"1")
# blocks_alt = bt.get_consecutive_blocks(test_constants, 3, [], 9, b"1")
db_filename = Path("blockchain_test.db")
db_filename_2 = Path("blockchain_test_2.db")
db_filename_3 = Path("blockchain_test_3.db")

View File

@ -1,5 +1,4 @@
import asyncio
import time
import pytest

View File

@ -2,10 +2,8 @@ import asyncio
from time import time
from typing import List, Tuple
import clvm
import pytest
from clvm.casts import int_to_bytes
from clvm_tools import binutils
from src.server.outbound_message import OutboundMessage
from src.protocols import full_node_protocol
@ -675,7 +673,7 @@ class TestMempool:
if msg.message.function == "new_transaction":
new_transaction = True
assert new_transaction == True
assert new_transaction
mempool_bundle = full_node_1.mempool_manager.get_spendbundle(
spend_bundle1.name()
@ -723,7 +721,7 @@ class TestMempool:
if msg.message.function == "new_transaction":
new_transaction = True
assert new_transaction == False
assert new_transaction is False
mempool_bundle = full_node_1.mempool_manager.get_spendbundle(
spend_bundle1.name()
@ -786,7 +784,7 @@ class TestMempool:
if msg.message.function == "new_transaction":
new_transaction = True
assert new_transaction == False
assert new_transaction is False
mempool_bundle = full_node_1.mempool_manager.get_spendbundle(
spend_bundle1.name()

View File

@ -1,17 +1,9 @@
import asyncio
from secrets import token_bytes
from pathlib import Path
from typing import Any, Dict
import sqlite3
import random
import aiosqlite
import pytest
from src.full_node.sync_store import SyncStore
from src.full_node.blockchain import Blockchain
from src.types.full_block import FullBlock
from src.types.sized_bytes import bytes32
from src.util.ints import uint32, uint64
from tests.setup_nodes import test_constants, bt
@ -26,15 +18,15 @@ class TestStore:
async def test_basic_store(self):
assert sqlite3.threadsafety == 1
blocks = bt.get_consecutive_blocks(test_constants, 9, [], 9, b"0")
blocks_alt = bt.get_consecutive_blocks(test_constants, 3, [], 9, b"1")
# blocks_alt = bt.get_consecutive_blocks(test_constants, 3, [], 9, b"1")
db = await SyncStore.create()
db_2 = await SyncStore.create()
# db_2 = await SyncStore.create()
# Save/get sync
for sync_mode in (False, True):
db.set_sync_mode(sync_mode)
assert sync_mode == db.get_sync_mode()
genesis = FullBlock.from_bytes(test_constants["GENESIS_BLOCK"])
FullBlock.from_bytes(test_constants["GENESIS_BLOCK"])
# clear sync info
await db.clear_sync_info()

View File

@ -1,5 +1,4 @@
import asyncio
import time
from secrets import token_bytes
import pytest

View File

@ -5,7 +5,6 @@ import pytest
from secrets import token_bytes
from blspy import PrivateKey
from chiapos import DiskPlotter
from src.types.proof_of_space import ProofOfSpace
from src.rpc.farmer_rpc_client import FarmerRpcClient
from src.rpc.harvester_rpc_client import HarvesterRpcClient
from src.rpc.rpc_server import start_rpc_server
@ -77,7 +76,7 @@ class TestRpc:
await time_out_assert(5, have_connections, True)
challenges = await client.get_latest_challenges()
await client.get_latest_challenges()
async def have_challenges():
return len(await client.get_latest_challenges()) > 0

View File

@ -2,7 +2,6 @@ import asyncio
from typing import List
import pytest
from blspy import ExtendedPrivateKey
from chiabip158 import PyBIP158
from tests.setup_nodes import test_constants, setup_simulators_and_wallets, bt
@ -28,7 +27,7 @@ class TestFilter:
wallet = wallet_node.wallet_state_manager.main_wallet
num_blocks = 2
ph = await wallet.get_new_puzzlehash()
await wallet.get_new_puzzlehash()
blocks = bt.get_consecutive_blocks(test_constants, num_blocks, [], 10)
for i in range(1, num_blocks):

View File

@ -16,7 +16,7 @@ def event_loop():
class TestMerkleSet:
@pytest.mark.asyncio
async def test_basics(self):
wallet_tool = WalletTool()
WalletTool()
num_blocks = 10
blocks = bt.get_consecutive_blocks(test_constants, num_blocks, [], 10,)

View File

@ -1,9 +1,7 @@
import asyncio
import pytest
import time
from typing import Dict, Any, List
from tests.setup_nodes import setup_full_system, bt
from src.consensus.constants import constants as consensus_constants
from typing import List
from tests.setup_nodes import setup_full_system
from src.util.ints import uint32
from src.types.full_block import FullBlock
from tests.make_test_constants import make_test_constants_with_genesis

View File

@ -17,7 +17,7 @@ def test_1():
conditions = [
make_create_coin_condition(std_hash(bytes(pp)), amount)
for pp, amount in [(puzzle_program_1, 1000), (puzzle_program_2, 2000),]
for pp, amount in [(puzzle_program_1, 1000), (puzzle_program_2, 2000), ]
]
assert conditions is not None
@ -33,7 +33,7 @@ def test_1():
output_conditions_dict = conditions_by_opcode(output_conditions)
pprint(output_conditions_dict)
input_coin_info_hash = bytes([0] * 32)
additions = created_outputs_for_conditions_dict(
created_outputs_for_conditions_dict(
output_conditions_dict, input_coin_info_hash
)
aggsigs = aggsig_in_conditions_dict(output_conditions_dict)

View File

@ -1,7 +1,6 @@
import time
from secrets import token_bytes
import clvm
from blspy import ExtendedPrivateKey
from clvm import run_program
from clvm_tools import binutils
@ -10,7 +9,6 @@ from src.types.condition_opcodes import ConditionOpcode
from src.types.condition_var_pair import ConditionVarPair
from src.types.BLSSignature import BLSSignature
from src.types.program import Program
from src.util.condition_tools import parse_sexp_to_conditions
from src.wallet.BLSPrivateKey import BLSPrivateKey
from src.wallet.puzzles.p2_delegated_puzzle import puzzle_for_pk
from tests.wallet_tools import WalletTool
@ -36,7 +34,10 @@ def float_to_str(f):
def run_and_return_cost_time(chialisp):
start = time.time()
clvm_loop = f"((c (q ((c (f (a)) (c (f (a)) (c (f (r (a))) (c (f (r (r (a)))) (q ()))))))) (c (q ((c (i (f (r (a))) (q (i (q 1) ((c (f (a)) (c (f (a)) (c (- (f (r (a))) (q 1)) (c (f (r (r (a)))) (q ())))))) ((c (f (r (r (a)))) (q ()))))) (q (q ()))) (a)))) (a))))"
clvm_loop = "((c (q ((c (f (a)) (c (f (a)) (c (f (r (a))) (c (f (r (r (a))))"
" (q ()))))))) (c (q ((c (i (f (r (a))) (q (i (q 1) ((c (f (a)) (c (f (a))"
" (c (- (f (r (a))) (q 1)) (c (f (r (r (a)))) (q ()))))))"
" ((c (f (r (r (a)))) (q ()))))) (q (q ()))) (a)))) (a))))"
loop_program = Program(binutils.assemble(clvm_loop))
clvm_loop_solution = f"(1000 {chialisp})"
solution_program = Program(binutils.assemble(clvm_loop_solution))
@ -62,7 +63,9 @@ def benchmark_all_operators():
if_clvm = "(i (= (q 1000000000) (q 1000000000)) (q 1000000000) (q 1000000000))"
sha256tree = "(sha256 (q 1000000000))"
pubkey_for_exp = "(pubkey_for_exp (q 1))"
point_add = "(point_add (q 0x17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb) (q 0x17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb))"
point_add = "(point_add"
" (q 0x17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb)"
" (q 0x17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb))"
point_add_cost, point_add_time = run_and_return_cost_time(point_add)
addition_cost, addition_time = run_and_return_cost_time(addition)
substraction_cost, substraction_time = run_and_return_cost_time(substraction)

View File

@ -1,6 +1,6 @@
import unittest
from dataclasses import dataclass
from typing import List, Optional, Dict, Any
from typing import List, Optional
from src.util.ints import uint32
from src.types.coin import Coin

View File

@ -1,15 +1,10 @@
import asyncio
from secrets import token_bytes
from pathlib import Path
from typing import Any, Dict
import sqlite3
import random
import pytest
import aiosqlite
from blspy import PrivateKey
from src.types.full_block import FullBlock
from src.types.sized_bytes import bytes32
from src.util.ints import uint32, uint64
from src.util.ints import uint32
from src.wallet.wallet_puzzle_store import WalletPuzzleStore
from src.wallet.derivation_record import DerivationRecord
from src.wallet.util.wallet_types import WalletType
@ -33,7 +28,7 @@ class TestPuzzleStore:
db = await WalletPuzzleStore.create(con)
try:
derivation_recs = []
wallet_types = [t for t in WalletType]
# wallet_types = [t for t in WalletType]
for i in range(1000):
derivation_recs.append(
@ -54,23 +49,23 @@ class TestPuzzleStore:
uint32(2),
)
)
assert await db.puzzle_hash_exists(derivation_recs[0].puzzle_hash) == False
assert await db.index_for_pubkey(derivation_recs[0].pubkey) == None
assert await db.puzzle_hash_exists(derivation_recs[0].puzzle_hash) is False
assert await db.index_for_pubkey(derivation_recs[0].pubkey) is None
assert (
await db.index_for_puzzle_hash(derivation_recs[2].puzzle_hash) == None
await db.index_for_puzzle_hash(derivation_recs[2].puzzle_hash) is None
)
assert (
await db.wallet_info_for_puzzle_hash(derivation_recs[2].puzzle_hash)
== None
is None
)
assert len((await db.get_all_puzzle_hashes())) == 0
assert await db.get_last_derivation_path() == None
assert await db.get_unused_derivation_path() == None
assert await db.get_derivation_record(0, 2) == None
assert await db.get_last_derivation_path() is None
assert await db.get_unused_derivation_path() is None
assert await db.get_derivation_record(0, 2) is None
await db.add_derivation_paths(derivation_recs)
assert await db.puzzle_hash_exists(derivation_recs[0].puzzle_hash) == True
assert await db.puzzle_hash_exists(derivation_recs[0].puzzle_hash) is True
assert await db.index_for_pubkey(derivation_recs[4].pubkey) == 2
assert await db.index_for_puzzle_hash(derivation_recs[2].puzzle_hash) == 1
assert await db.wallet_info_for_puzzle_hash(

View File

@ -288,9 +288,9 @@ class TestWalletSimulator:
for i in range(0, 4):
await full_node_0.farm_new_block(FarmNewBlockProtocol(token_bytes()))
confirmed_balance = await wallet_0.get_confirmed_balance()
unconfirmed_balance = await wallet_0.get_unconfirmed_balance()
wallet_2_confirmed_balance = await wallet_1.get_confirmed_balance()
await wallet_0.get_confirmed_balance()
await wallet_0.get_unconfirmed_balance()
await wallet_1.get_confirmed_balance()
await time_out_assert(5, wallet_0.get_confirmed_balance, new_funds - 5)
await time_out_assert(5, wallet_0.get_unconfirmed_balance, new_funds - 5)

View File

@ -1,14 +1,9 @@
import asyncio
from secrets import token_bytes
from pathlib import Path
from typing import Any, Dict
from secrets import token_bytes
import aiosqlite
import random
import pytest
from src.types.full_block import FullBlock
from src.types.sized_bytes import bytes32
from src.util.ints import uint32, uint64, uint128
from src.wallet.wallet_store import WalletStore
from src.wallet.wallet_coin_record import WalletCoinRecord
@ -246,7 +241,7 @@ class TestWalletStore:
assert len(await store.get_unspent_coins_at_height(3)) == 1
assert len(await store.get_unspent_coins_at_height(4)) == 1
except:
except "db connection error":
await db_connection.close()
raise
await db_connection.close()

View File

@ -1,12 +1,11 @@
import asyncio
import time
import pytest
from src.types.peer_info import PeerInfo
from src.protocols import full_node_protocol
from src.util.ints import uint16, uint64, uint32
from tests.setup_nodes import setup_two_nodes, setup_node_and_wallet, test_constants, bt
from tests.setup_nodes import setup_node_and_wallet, test_constants, bt
from src.types.spend_bundle import SpendBundle
from src.util.bundle_tools import best_solution_program
from tests.wallet_tools import WalletTool