mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2024-09-21 00:24:37 +03:00
e5bc89e5b6
* updated wallet name * deprecated series * swap to cat2 * updating .gitmodule to point to defender-gui * Remove break (its preventing other sockets from getting data when earlier ones have an error) (#12241) * Convert DID Wallet to use the new coin selection algorithm that the normal wallet and the CAT wallet already use (#12063) * small type change * use coin_selection.py with DID Wallet use more efficient coin selection methods. * Add special DID edgecase + fix int type * Ms.fix coin selection (#12261) * Fix coin selection bug * Fix properly * Fallback in cases of too many coins selected * Also check for num coins * Lint issues. * Add another test * No sorting, and faster knapsack * Lint fix * Remove comment and useless check * Lint line * Tx submission idempotance, and prioritize wallet (#12282) * Tx submission idempotance, and prioritize wallet * TODO comment * Updating gui modules * extend min_coin to rpc calls & cli for coin selection (#12274) * add tests to test if min_coin is working they are passing, but no harm in being safe * expand min coin amount across wallet.py * extend to trade_manager * add new options to rpc's almost done lol. * add min_coin_amount to wallet send * make param non optional alleviate None errors * add cat wallet changes, rpc and all + fix a bug i accidentally made oops * Fix offer compression backwards compatibility * bumping gui pin to head of release/1.5.0 * Calculate NFT royalty amount * Create NFT wallet after the DID created (#12175) * Bumping gui * Show total amount to be paid for NFT offers * Fix for NFT0 and NFT+Royalty detection suggested by quex * Linter fix and formatting change * Add RPCs for getting/extending the current derivation path index (#12472) * Sleep to allow neworking layer to execute (#12463) * Sleep to allow neworking layer to execute * Add comment * Added param to indicate how many additional phs create_more_puzzle_hashes should create. (#12493) Account for range() not including last_index when `up_to_index` is provided. * Fixed the wallet db rename from v2/v1 to v2_r1. Removed vestigial code for dealing with the lite wallet db now that we're syncing v2_r1 from scratch. * When extending the derivation index, make sure we don't mark previously (#12513) unused indices as used. This helps minimize gaps in the address space. * Updating SBX asset ID * Adding 1.5.0 changelog (#56) * Adding 1.5.0 changelog * Adding CVE fix * Updating gitmodules (#57) * Updating gitmodules * Pinning gui * black fixes * mypy fixes * xfail some run_block tests that need CAT2 update * fix test * Fix test based on series<->edition changes * Drop EOL impish and hirsute (#12559) (cherry picked from commit189790ced2
) * Expand select_coins rpc (#12360) * change type to uint64, 128 is too big anyway * add new options to select_coins endpoint * oops * add tests and finalize * oops (cherry picked from commitd5bf4d8b59
) * .resolve() for wallet db path tests in windows * followup to actually fix the wallet db path tests * Update .gitmodules * Update wallet_node.py * Update trade_manager.py Co-authored-by: Sebastjan <trepca@gmail.com> Co-authored-by: matt <matt@chia.net> Co-authored-by: William Allen <wallentx@users.noreply.github.com> Co-authored-by: wallentx <william.allentx@gmail.com> Co-authored-by: Chris Marslender <chrismarslender@gmail.com> Co-authored-by: Jack Nelson <jack@jacknelson.xyz> Co-authored-by: Mariano Sorgente <3069354+mariano54@users.noreply.github.com> Co-authored-by: Matt Hauff <quexington@gmail.com> Co-authored-by: Jeff Cruikshank <jeff@chia.net> Co-authored-by: Kronus91 <t.yu@chia.net> Co-authored-by: Justin England <justin@chia.net> Co-authored-by: Earle Lowe <e.lowe@chia.net> Co-authored-by: Earle Lowe <30607889+emlowe@users.noreply.github.com>
183 lines
7.6 KiB
Python
183 lines
7.6 KiB
Python
from os import remove
|
|
from pathlib import Path
|
|
from tempfile import NamedTemporaryFile
|
|
from unittest import TestCase
|
|
|
|
from clvm_tools.clvmc import compile_clvm
|
|
|
|
from chia.types.blockchain_format.program import Program, SerializedProgram
|
|
|
|
wallet_program_files = set(
|
|
[
|
|
"chia/wallet/puzzles/calculate_synthetic_public_key.clvm",
|
|
"chia/wallet/puzzles/cat_v2.clvm",
|
|
"chia/wallet/puzzles/chialisp_deserialisation.clvm",
|
|
"chia/wallet/puzzles/rom_bootstrap_generator.clvm",
|
|
"chia/wallet/puzzles/generator_for_single_coin.clvm",
|
|
"chia/wallet/puzzles/lock.inner.puzzle.clvm",
|
|
"chia/wallet/puzzles/p2_conditions.clvm",
|
|
"chia/wallet/puzzles/p2_delegated_conditions.clvm",
|
|
"chia/wallet/puzzles/p2_delegated_puzzle.clvm",
|
|
"chia/wallet/puzzles/p2_delegated_puzzle_or_hidden_puzzle.clvm",
|
|
"chia/wallet/puzzles/p2_m_of_n_delegate_direct.clvm",
|
|
"chia/wallet/puzzles/p2_puzzle_hash.clvm",
|
|
"chia/wallet/puzzles/rl_aggregation.clvm",
|
|
"chia/wallet/puzzles/rl.clvm",
|
|
"chia/wallet/puzzles/sha256tree_module.clvm",
|
|
"chia/wallet/puzzles/singleton_top_layer.clvm",
|
|
"chia/wallet/puzzles/did_innerpuz.clvm",
|
|
"chia/wallet/puzzles/decompress_puzzle.clvm",
|
|
"chia/wallet/puzzles/decompress_coin_spend_entry_with_prefix.clvm",
|
|
"chia/wallet/puzzles/decompress_coin_spend_entry.clvm",
|
|
"chia/wallet/puzzles/block_program_zero.clvm",
|
|
"chia/wallet/puzzles/test_generator_deserialize.clvm",
|
|
"chia/wallet/puzzles/test_multiple_generator_input_arguments.clvm",
|
|
"chia/wallet/puzzles/p2_singleton.clvm",
|
|
"chia/wallet/puzzles/pool_waitingroom_innerpuz.clvm",
|
|
"chia/wallet/puzzles/pool_member_innerpuz.clvm",
|
|
"chia/wallet/puzzles/singleton_launcher.clvm",
|
|
"chia/wallet/puzzles/p2_singleton_or_delayed_puzhash.clvm",
|
|
"chia/wallet/puzzles/genesis_by_puzzle_hash.clvm",
|
|
"chia/wallet/puzzles/everything_with_signature.clvm",
|
|
"chia/wallet/puzzles/delegated_tail.clvm",
|
|
"chia/wallet/puzzles/settlement_payments.clvm",
|
|
"chia/wallet/puzzles/genesis_by_coin_id.clvm",
|
|
"chia/wallet/puzzles/singleton_top_layer_v1_1.clvm",
|
|
"chia/wallet/puzzles/nft_metadata_updater_default.clvm",
|
|
"chia/wallet/puzzles/nft_metadata_updater_updateable.clvm",
|
|
"chia/wallet/puzzles/nft_state_layer.clvm",
|
|
"chia/wallet/puzzles/nft_ownership_layer.clvm",
|
|
"chia/wallet/puzzles/nft_ownership_transfer_program_one_way_claim_with_royalties.clvm",
|
|
"chia/wallet/puzzles/decompress_block_spends.clvm",
|
|
]
|
|
)
|
|
|
|
clvm_include_files = set(
|
|
["chia/wallet/puzzles/create-lock-puzzlehash.clvm", "chia/wallet/puzzles/condition_codes.clvm"]
|
|
)
|
|
|
|
CLVM_PROGRAM_ROOT = "chia/wallet/puzzles"
|
|
|
|
|
|
def list_files(dir, glob):
|
|
dir = Path(dir)
|
|
entries = dir.glob(glob)
|
|
files = [f for f in entries if f.is_file()]
|
|
return files
|
|
|
|
|
|
def read_file(path):
|
|
with open(path) as f:
|
|
return f.read()
|
|
|
|
|
|
def path_with_ext(path, ext):
|
|
return Path(str(path) + ext)
|
|
|
|
|
|
class TestClvmCompilation(TestCase):
|
|
"""
|
|
These are tests, and not just build scripts to regenerate the bytecode, because
|
|
the developer must be aware if the compiled output changes, for any reason.
|
|
"""
|
|
|
|
def test_all_programs_listed(self):
|
|
"""
|
|
Checks to see if a new .clvm file was added to chia/wallet/puzzles, but not added to `wallet_program_files`
|
|
"""
|
|
existing_files = list_files(CLVM_PROGRAM_ROOT, "*.clvm")
|
|
existing_file_paths = set([Path(x).relative_to(CLVM_PROGRAM_ROOT) for x in existing_files])
|
|
|
|
expected_files = set(clvm_include_files).union(set(wallet_program_files))
|
|
expected_file_paths = set([Path(x).relative_to(CLVM_PROGRAM_ROOT) for x in expected_files])
|
|
|
|
self.assertEqual(
|
|
expected_file_paths,
|
|
existing_file_paths,
|
|
msg="Please add your new program to `wallet_program_files` or `clvm_include_files.values`",
|
|
)
|
|
|
|
def test_include_and_source_files_separate(self):
|
|
self.assertEqual(clvm_include_files.intersection(wallet_program_files), set())
|
|
|
|
# TODO: Test recompilation with all available compiler configurations & implementations
|
|
def test_all_programs_are_compiled(self):
|
|
"""Checks to see if a new .clvm file was added without its .hex file"""
|
|
all_compiled = True
|
|
msg = "Please compile your program with:\n"
|
|
|
|
# Note that we cannot test all existing .clvm files - some are not
|
|
# meant to be run as a "module" with load_clvm; some are include files
|
|
# We test for inclusion in `test_all_programs_listed`
|
|
for prog_path in wallet_program_files:
|
|
try:
|
|
output_path = path_with_ext(prog_path, ".hex")
|
|
hex = output_path.read_text()
|
|
self.assertTrue(len(hex) > 0)
|
|
except Exception as ex:
|
|
all_compiled = False
|
|
msg += f" run -i {prog_path.parent} -d {prog_path} > {prog_path}.hex\n"
|
|
print(ex)
|
|
msg += "and check it in"
|
|
self.assertTrue(all_compiled, msg=msg)
|
|
|
|
def test_recompilation_matches(self):
|
|
self.maxDiff = None
|
|
for f in wallet_program_files:
|
|
f = Path(f)
|
|
compile_clvm(f, path_with_ext(f, ".recompiled"), search_paths=[f.parent])
|
|
orig_hex = path_with_ext(f, ".hex").read_text().strip()
|
|
new_hex = path_with_ext(f, ".recompiled").read_text().strip()
|
|
self.assertEqual(orig_hex, new_hex, msg=f"Compilation of {f} does not match {f}.hex")
|
|
pass
|
|
|
|
def test_all_compiled_programs_are_hashed(self):
|
|
"""Checks to see if a .hex file is missing its .sha256tree file"""
|
|
all_hashed = True
|
|
msg = "Please hash your program with:\n"
|
|
for prog_path in wallet_program_files:
|
|
try:
|
|
hex = path_with_ext(prog_path, ".hex.sha256tree").read_text()
|
|
self.assertTrue(len(hex) > 0)
|
|
except Exception as ex:
|
|
print(ex)
|
|
all_hashed = False
|
|
msg += f" opd -H {prog_path}.hex | head -1 > {prog_path}.hex.sha256tree\n"
|
|
msg += "and check it in"
|
|
self.assertTrue(all_hashed, msg)
|
|
|
|
# TODO: Test all available shatree implementations on all progams
|
|
def test_shatrees_match(self):
|
|
"""Checks to see that all .sha256tree files match their .hex files"""
|
|
for prog_path in wallet_program_files:
|
|
# load the .hex file as a program
|
|
hex_filename = path_with_ext(prog_path, ".hex")
|
|
clvm_hex = hex_filename.read_text() # .decode("utf8")
|
|
clvm_blob = bytes.fromhex(clvm_hex)
|
|
s = SerializedProgram.from_bytes(clvm_blob)
|
|
p = Program.from_bytes(clvm_blob)
|
|
|
|
# load the checked-in shatree
|
|
existing_sha = path_with_ext(prog_path, ".hex.sha256tree").read_text().strip()
|
|
|
|
self.assertEqual(
|
|
s.get_tree_hash().hex(),
|
|
existing_sha,
|
|
msg=f"Checked-in shatree hash file does not match hash of loaded SerializedProgram: {prog_path}",
|
|
)
|
|
self.assertEqual(
|
|
p.get_tree_hash().hex(),
|
|
existing_sha,
|
|
msg=f"Checked-in shatree hash file does not match shatree hash of loaded Program: {prog_path}",
|
|
)
|
|
|
|
def test_017_encoding_bug_fixed(self):
|
|
with NamedTemporaryFile(delete=False) as tf:
|
|
tf.write(b"10000000")
|
|
hexname = tf.name + ".hex"
|
|
compile_clvm(tf.name, hexname, [])
|
|
with open(hexname) as f:
|
|
self.assertEqual(f.read().strip(), "8400989680")
|
|
remove(tf.name)
|
|
remove(hexname)
|