diff --git a/.github/workflows/build-linux-arm64-installer.yml b/.github/workflows/build-linux-arm64-installer.yml index 29cc8872211b..930a20ede20f 100644 --- a/.github/workflows/build-linux-arm64-installer.yml +++ b/.github/workflows/build-linux-arm64-installer.yml @@ -44,16 +44,6 @@ jobs: echo "::set-output name=CHIA_INSTALLER_VERSION::$(python3 ./build_scripts/installer-version.py)" deactivate - - name: Test for secrets access - id: check_secrets - shell: bash - run: | - unset HAS_SECRET - if [ -n "$SECRET" ]; then HAS_SECRET='true' ; fi - echo ::set-output name=HAS_SECRET::${HAS_SECRET} - env: - SECRET: "${{ secrets.test_pypi_password }}" - - name: Build ARM64 Installer run: | podman run --rm=true \ @@ -92,12 +82,10 @@ jobs: path: ${{ github.workspace }}/build_scripts/final_installer/ - name: Install AWS CLI - if: steps.check_secrets.outputs.HAS_SECRET run: | sudo apt-get install -y awscli - name: Configure AWS Credentials - if: steps.check_secrets.outputs.HAS_SECRET uses: aws-actions/configure-aws-credentials@v1 with: aws-access-key-id: ${{ secrets.INSTALLER_UPLOAD_KEY }} @@ -105,7 +93,6 @@ jobs: aws-region: us-west-2 - name: Upload to s3 - if: steps.check_secrets.outputs.HAS_SECRET run: | aws s3 cp ${{ github.workspace }}/build_scripts/final_installer/*.deb s3://download-chia-net/builds/ @@ -118,25 +105,13 @@ jobs: sha256sum ${{ github.workspace }}/build_scripts/final_installer/chia-blockchain_${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}_arm64.deb > ${{ github.workspace }}/build_scripts/final_installer/chia-blockchain_${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}_arm64.deb.sha256 ls ${{ github.workspace }}/build_scripts/final_installer/ - - name: Install py3createtorrent - if: startsWith(github.ref, 'refs/tags/') - run: | - pip3 install py3createtorrent - - - name: Create torrent - if: startsWith(github.ref, 'refs/tags/') - run: | - py3createtorrent -f -t udp://tracker.opentrackr.org:1337/announce ${{ github.workspace }}/build_scripts/final_installer/chia-blockchain_${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}_arm64.deb -o ${{ github.workspace }}/build_scripts/final_installer/chia-blockchain_${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}_arm64.deb.torrent --webseed https://download-chia-net.s3.us-west-2.amazonaws.com/install/chia-blockchain_${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}_arm64.deb - ls ${{ github.workspace }}/build_scripts/final_installer/ - - name: Upload Release Files - if: steps.check_secrets.outputs.HAS_SECRET && startsWith(github.ref, 'refs/tags/') + if: startsWith(github.ref, 'refs/tags/') run: | ls ${{ github.workspace }}/build_scripts/final_installer/ aws s3 cp ${{ github.workspace }}/build_scripts/final_installer/*.deb s3://download-chia-net/install/ aws s3 cp ${{ github.workspace }}/build_scripts/final_installer/*.sha256 s3://download-chia-net/install/ - aws s3 cp ${{ github.workspace }}/build_scripts/final_installer/chia-blockchain_${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}_arm64.deb.torrent s3://download-chia-net/torrents/ - name: Clean up on self hosted runner run: | - sudo rm -rf build_scripts/final_installer \ No newline at end of file + sudo rm -rf build_scrpits/final_installer diff --git a/.github/workflows/build-linux-installer.yml b/.github/workflows/build-linux-installer.yml index c22116559f97..600c3242e9d0 100644 --- a/.github/workflows/build-linux-installer.yml +++ b/.github/workflows/build-linux-installer.yml @@ -78,16 +78,6 @@ jobs: echo "::set-output name=CHIA_INSTALLER_VERSION::$(python3 ./build_scripts/installer-version.py)" deactivate - - name: Test for secrets access - id: check_secrets - shell: bash - run: | - unset HAS_SECRET - if [ -n "$SECRET" ]; then HAS_SECRET='true' ; fi - echo ::set-output name=HAS_SECRET::${HAS_SECRET} - env: - SECRET: "${{ secrets.test_pypi_password }}" - - name: Run install script env: INSTALL_PYTHON_VERSION: ${{ matrix.python-version }} @@ -117,7 +107,6 @@ jobs: path: ${{ github.workspace }}/build_scripts/final_installer/ - name: Configure AWS Credentials - if: steps.check_secrets.outputs.HAS_SECRET uses: aws-actions/configure-aws-credentials@v1 with: aws-access-key-id: ${{ secrets.INSTALLER_UPLOAD_KEY }} @@ -125,7 +114,6 @@ jobs: aws-region: us-west-2 - name: Upload to s3 - if: steps.check_secrets.outputs.HAS_SECRET env: CHIA_INSTALLER_VERSION: ${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }} run: | @@ -144,29 +132,10 @@ jobs: sha256sum ${{ github.workspace }}/build_scripts/final_installer/chia-blockchain_${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}_amd64.deb > ${{ github.workspace }}/build_scripts/final_installer/chia-blockchain_${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}_amd64.deb.sha256 ls ${{ github.workspace }}/build_scripts/final_installer/ - - name: Install py3createtorrent - if: startsWith(github.ref, 'refs/tags/') - run: | - pip3 install py3createtorrent - - - name: Create .rpm torrent - if: startsWith(github.ref, 'refs/tags/') - run: | - py3createtorrent -f -t udp://tracker.opentrackr.org:1337/announce ${{ github.workspace }}/build_scripts/final_installer/chia-blockchain-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}-1.x86_64.rpm -o ${{ github.workspace }}/build_scripts/final_installer/chia-blockchain-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}-1.x86_64.rpm.torrent --webseed https://download-chia-net.s3.us-west-2.amazonaws.com/install/chia-blockchain-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}-1.x86_64.rpm - ls - - - name: Create .deb torrent - if: startsWith(github.ref, 'refs/tags/') - run: | - py3createtorrent -f -t udp://tracker.opentrackr.org:1337/announce ${{ github.workspace }}/build_scripts/final_installer/chia-blockchain_${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}_amd64.deb -o ${{ github.workspace }}/build_scripts/final_installer/chia-blockchain_${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}_amd64.deb.torrent --webseed https://download-chia-net.s3.us-west-2.amazonaws.com/install/chia-blockchain_${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}_amd64.deb - ls - - name: Upload Release Files - if: steps.check_secrets.outputs.HAS_SECRET && startsWith(github.ref, 'refs/tags/') + if: startsWith(github.ref, 'refs/tags/') run: | aws s3 cp ${{ github.workspace }}/build_scripts/final_installer/chia-blockchain_${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}_amd64.deb s3://download-chia-net/install/ aws s3 cp ${{ github.workspace }}/build_scripts/final_installer/chia-blockchain_${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}_amd64.deb.sha256 s3://download-chia-net/install/ - aws s3 cp ${{ github.workspace }}/build_scripts/final_installer/chia-blockchain_${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}_amd64.deb.torrent s3://download-chia-net/torrents/ aws s3 cp ${{ github.workspace }}/build_scripts/final_installer/chia-blockchain-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}-1.x86_64.rpm s3://download-chia-net/install/ aws s3 cp ${{ github.workspace }}/build_scripts/final_installer/chia-blockchain-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}-1.x86_64.rpm.sha256 s3://download-chia-net/install/ - aws s3 cp ${{ github.workspace }}/build_scripts/final_installer/chia-blockchain-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}-1.x86_64.rpm.torrent s3://download-chia-net/torrents/ diff --git a/.github/workflows/build-macos-installer.yml b/.github/workflows/build-macos-installer.yml index 6f0ad748da58..751ccc7902d2 100644 --- a/.github/workflows/build-macos-installer.yml +++ b/.github/workflows/build-macos-installer.yml @@ -146,20 +146,9 @@ jobs: run: | aws s3 cp ${{ github.workspace }}/build_scripts/final_installer/Chia-Catalina-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}.dmg s3://download-chia-net/builds/ - - name: Install py3createtorrent - if: startsWith(github.ref, 'refs/tags/') - run: | - pip3 install py3createtorrent - - - name: Create torrent - if: startsWith(github.ref, 'refs/tags/') - run: | - py3createtorrent -t torrent.chia.net ${{ github.workspace }}/build_scripts/final_installer/Chia-Catalina-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}.dmg ${{ github.workspace }}/build_scripts/final_installer/Chia-Catalina-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}.dmg.torrent - #Temporarily disable release uploads # - name: Upload Release Files # if: startsWith(github.ref, 'refs/tags/') # run: | # aws s3 cp ${{ github.workspace }}/build_scripts/final_installer/Chia-Catalina-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}.dmg s3://download-chia-net/install/ # aws s3 cp ${{ github.workspace }}/build_scripts/final_installer/Chia-Catalina-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}.dmg.sha256 s3://download-chia-net/install/ -# aws s3 cp ${{ github.workspace }}/build_scripts/final_installer/Chia-Catalina-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}.dmg.torrent s3://download-chia-net/install/ \ No newline at end of file diff --git a/.github/workflows/build-windows-installer.yml b/.github/workflows/build-windows-installer.yml index 631929f84044..3a7ea7e70924 100644 --- a/.github/workflows/build-windows-installer.yml +++ b/.github/workflows/build-windows-installer.yml @@ -113,12 +113,10 @@ jobs: - name: Install AWS CLI - if: steps.check_secrets.outputs.HAS_SECRET run: | msiexec.exe /i https://awscli.amazonaws.com/AWSCLIV2.msi - name: Configure AWS Credentials - if: steps.check_secrets.outputs.HAS_SECRET uses: aws-actions/configure-aws-credentials@v1 with: aws-access-key-id: ${{ secrets.INSTALLER_UPLOAD_KEY }} @@ -126,7 +124,6 @@ jobs: aws-region: us-west-2 - name: Upload to s3 - if: steps.check_secrets.outputs.HAS_SECRET env: CHIA_INSTALLER_VERSION: ${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }} run: | @@ -141,23 +138,11 @@ jobs: certutil.exe -hashfile ${{ github.workspace }}\chia-blockchain-gui\release-builds\windows-installer\ChiaSetup-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}.exe SHA256 > ${{ github.workspace }}\chia-blockchain-gui\release-builds\windows-installer\ChiaSetup-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}.exe.checksum ls ${{ github.workspace }}\chia-blockchain-gui\release-builds\windows-installer\ - - name: Install py3createtorrent - if: startsWith(github.ref, 'refs/tags/') - run: | - pip3 install py3createtorrent - - - name: Create torrent - if: startsWith(github.ref, 'refs/tags/') - run: | - py3createtorrent -f -t udp://tracker.opentrackr.org:1337/announce ${{ github.workspace }}\chia-blockchain-gui\release-builds\windows-installer\ChiaSetup-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}.exe -o ${{ github.workspace }}\chia-blockchain-gui\release-builds\windows-installer\ChiaSetup-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}.exe.torrent --webseed https://download-chia-net.s3.us-west-2.amazonaws.com/install/ChiaSetup-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}.exe - ls - - name: Upload Release Files - if: steps.check_secrets.outputs.HAS_SECRET && startsWith(github.ref, 'refs/tags/') + if: startsWith(github.ref, 'refs/tags/') env: AWS_ACCESS_KEY_ID: ${{ secrets.INSTALLER_UPLOAD_KEY }} AWS_SECRET_ACCESS_KEY: ${{ secrets.INSTALLER_UPLOAD_SECRET }} run: | aws s3 cp ${{ github.workspace }}\chia-blockchain-gui\release-builds\windows-installer\ChiaSetup-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}.exe s3://download-chia-net/install/ aws s3 cp ${{ github.workspace }}\chia-blockchain-gui\release-builds\windows-installer\ChiaSetup-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}.exe.checksum s3://download-chia-net/install/ - aws s3 cp ${{ github.workspace }}\chia-blockchain-gui\release-builds\windows-installer\ChiaSetup-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}.exe.torrent s3://download-chia-net/torrents/ diff --git a/azure-pipelines.yml b/azure-pipelines.yml index eeaf7248668b..3f9d46d78785 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -111,19 +111,11 @@ steps: aws s3 cp $(System.DefaultWorkingDirectory)/build_scripts/final_installer/*.dmg s3://download-chia-net/builds/ displayName: "Upload to S3" - - bash: | - pip3 install py3createtorrent - py3createtorrent -f -t udp://tracker.opentrackr.org:1337/announce $(System.DefaultWorkingDirectory)/build_scripts/final_installer/$CHIA_VERSION.dmg -o $(System.DefaultWorkingDirectory)/build_scripts/final_installer/$CHIA_VERSION.dmg.torrent --webseed https://download-chia-net.s3.us-west-2.amazonaws.com/install/$CHIA_VERSION.dmg - ls - displayName: "Create torrent file" - condition: contains(variables['build.sourceBranch'], 'refs/tags/') - - bash: | export AWS_ACCESS_KEY_ID=$(AccessKey) export AWS_SECRET_ACCESS_KEY=$(SecretKey) export AWS_DEFAULT_REGION=us-west-2 aws s3 cp $(System.DefaultWorkingDirectory)/build_scripts/final_installer/$CHIA_VERSION.dmg s3://download-chia-net/install/ aws s3 cp $(System.DefaultWorkingDirectory)/build_scripts/final_installer/$CHIA_VERSION.dmg.sha256 s3://download-chia-net/install/ - aws s3 cp $(System.DefaultWorkingDirectory)/build_scripts/final_installer/$CHIA_VERSION.dmg.torrent s3://download-chia-net/torrents/ displayName: "Upload Release Files" - condition: contains(variables['build.sourceBranch'], 'refs/tags/') \ No newline at end of file + condition: contains(variables['build.sourceBranch'], 'refs/tags/') diff --git a/chia-blockchain-gui b/chia-blockchain-gui index 444c6966fe50..725071236eff 160000 --- a/chia-blockchain-gui +++ b/chia-blockchain-gui @@ -1 +1 @@ -Subproject commit 444c6966fe50183c8d72cbc972c5403db341739c +Subproject commit 725071236eff8c81d5b267dc8eb69d7e03f3df8c diff --git a/chia/full_node/full_node.py b/chia/full_node/full_node.py index e934640332b9..2e3b814f5c2e 100644 --- a/chia/full_node/full_node.py +++ b/chia/full_node/full_node.py @@ -1761,10 +1761,9 @@ class FullNode: vdf_proof: VDFProof, height: uint32, field_vdf: CompressibleVDFField, - ) -> bool: + ): full_blocks = await self.block_store.get_full_blocks_at([height]) assert len(full_blocks) > 0 - replaced = False for block in full_blocks: new_block = None block_record = await self.blockchain.get_block_record_from_db(self.blockchain.height_to_hash(height)) @@ -1799,12 +1798,11 @@ class FullNode: if block.reward_chain_block.challenge_chain_ip_vdf == vdf_info: new_block = dataclasses.replace(block, challenge_chain_ip_proof=vdf_proof) if new_block is None: - continue + self.log.debug("did not replace any proof, vdf does not match") + return async with self.db_wrapper.lock: await self.block_store.add_full_block(new_block.header_hash, new_block, block_record) await self.block_store.db_wrapper.commit_transaction() - replaced = True - return replaced async def respond_compact_proof_of_time(self, request: timelord_protocol.RespondCompactProofOfTime): field_vdf = CompressibleVDFField(int(request.field_vdf)) @@ -1813,10 +1811,7 @@ class FullNode: ): return None async with self.blockchain.compact_proof_lock: - replaced = await self._replace_proof(request.vdf_info, request.vdf_proof, request.height, field_vdf) - if not replaced: - self.log.error(f"Could not replace compact proof: {request.height}") - return None + await self._replace_proof(request.vdf_info, request.vdf_proof, request.height, field_vdf) msg = make_msg( ProtocolMessageTypes.new_compact_vdf, full_node_protocol.NewCompactVDF(request.height, request.header_hash, request.field_vdf, request.vdf_info), @@ -1895,10 +1890,7 @@ class FullNode: async with self.blockchain.compact_proof_lock: if self.blockchain.seen_compact_proofs(request.vdf_info, request.height): return None - replaced = await self._replace_proof(request.vdf_info, request.vdf_proof, request.height, field_vdf) - if not replaced: - self.log.error(f"Could not replace compact proof: {request.height}") - return None + await self._replace_proof(request.vdf_info, request.vdf_proof, request.height, field_vdf) msg = make_msg( ProtocolMessageTypes.new_compact_vdf, full_node_protocol.NewCompactVDF(request.height, request.header_hash, request.field_vdf, request.vdf_info), diff --git a/chia/rpc/wallet_rpc_api.py b/chia/rpc/wallet_rpc_api.py index 578375f4905b..033b736493ae 100644 --- a/chia/rpc/wallet_rpc_api.py +++ b/chia/rpc/wallet_rpc_api.py @@ -25,7 +25,6 @@ from chia.util.ws_message import WsRpcMessage, create_payload_dict from chia.wallet.cc_wallet.cc_wallet import CCWallet from chia.wallet.derive_keys import master_sk_to_singleton_owner_sk from chia.wallet.rl_wallet.rl_wallet import RLWallet -from chia.wallet.derive_keys import master_sk_to_farmer_sk, master_sk_to_pool_sk from chia.wallet.did_wallet.did_wallet import DIDWallet from chia.wallet.trade_record import TradeRecord from chia.wallet.transaction_record import TransactionRecord @@ -212,8 +211,6 @@ class WalletRpcApi: "fingerprint": fingerprint, "sk": bytes(sk).hex(), "pk": bytes(sk.get_g1()).hex(), - "farmer_pk": bytes(master_sk_to_farmer_sk(sk).get_g1()).hex(), - "pool_pk": bytes(master_sk_to_pool_sk(sk).get_g1()).hex(), "seed": s, }, } diff --git a/chia/server/start_wallet.py b/chia/server/start_wallet.py index 20cf96b2c37a..ac602f74a5cd 100644 --- a/chia/server/start_wallet.py +++ b/chia/server/start_wallet.py @@ -8,6 +8,7 @@ from chia.rpc.wallet_rpc_api import WalletRpcApi from chia.server.outbound_message import NodeType from chia.server.start_service import run_service from chia.types.peer_info import PeerInfo +from chia.util.block_tools import test_constants from chia.util.config import load_config_cli, load_config from chia.util.default_root import DEFAULT_ROOT_PATH from chia.util.keychain import Keychain @@ -80,8 +81,6 @@ def main() -> None: # This is simulator local_test = config["testing"] if local_test is True: - from tests.block_tools import test_constants - constants = test_constants current = config["database_path"] config["database_path"] = f"{current}_simulation" diff --git a/chia/simulator/simulator_constants.py b/chia/simulator/simulator_constants.py index f3d8ff6463e2..d77a47a98635 100644 --- a/chia/simulator/simulator_constants.py +++ b/chia/simulator/simulator_constants.py @@ -1,5 +1,5 @@ if __name__ == "__main__": - from tests.block_tools import BlockTools, test_constants + from chia.util.block_tools import BlockTools, test_constants from chia.util.default_root import DEFAULT_ROOT_PATH # TODO: mariano: fix this with new consensus diff --git a/chia/simulator/start_simulator.py b/chia/simulator/start_simulator.py index 509fe11760fc..286865a25435 100644 --- a/chia/simulator/start_simulator.py +++ b/chia/simulator/start_simulator.py @@ -6,7 +6,7 @@ from chia.full_node.full_node import FullNode from chia.rpc.full_node_rpc_api import FullNodeRpcApi from chia.server.outbound_message import NodeType from chia.server.start_service import run_service -from tests.block_tools import BlockTools, test_constants +from chia.util.block_tools import BlockTools, test_constants from chia.util.config import load_config_cli from chia.util.default_root import DEFAULT_ROOT_PATH from chia.util.path import mkdir, path_from_root diff --git a/tests/block_tools.py b/chia/util/block_tools.py similarity index 99% rename from tests/block_tools.py rename to chia/util/block_tools.py index 712efebb27e2..9c4f51c67e56 100644 --- a/tests/block_tools.py +++ b/chia/util/block_tools.py @@ -65,7 +65,7 @@ from chia.util.ints import uint8, uint32, uint64, uint128 from chia.util.keychain import Keychain, bytes_to_mnemonic from chia.util.path import mkdir from chia.util.vdf_prover import get_vdf_info_and_proof -from tests.wallet_tools import WalletTool +from chia.util.wallet_tools import WalletTool from chia.wallet.derive_keys import ( master_sk_to_farmer_sk, master_sk_to_local_sk, diff --git a/chia/util/initial-config.yaml b/chia/util/initial-config.yaml index 1f4a348d9d1f..1cb0167f2d91 100644 --- a/chia/util/initial-config.yaml +++ b/chia/util/initial-config.yaml @@ -115,7 +115,7 @@ logging: &logging log_maxfilesrotation: 7 # Max files in rotation. Default value 7 if the key is not set log_syslog: False # If True, outputs to SysLog host and port specified log_syslog_host: "localhost" # Send logging messages to a remote or local Unix syslog - log_syslog_port: 514 # UDP port of the remote or local Unix syslog + log_syslog_port: 514 # UDP port of the remote or local Unix syslog harvester: # The harvester server (if run) will run on this port diff --git a/tests/wallet_tools.py b/chia/util/wallet_tools.py similarity index 100% rename from tests/wallet_tools.py rename to chia/util/wallet_tools.py diff --git a/tests/blockchain/test_blockchain.py b/tests/blockchain/test_blockchain.py index a46225aa8020..de6d2d3f8181 100644 --- a/tests/blockchain/test_blockchain.py +++ b/tests/blockchain/test_blockchain.py @@ -28,13 +28,13 @@ from chia.types.end_of_slot_bundle import EndOfSubSlotBundle from chia.types.full_block import FullBlock from chia.types.spend_bundle import SpendBundle from chia.types.unfinished_block import UnfinishedBlock -from tests.block_tools import BlockTools, get_vdf_info_and_proof +from chia.util.block_tools import BlockTools, get_vdf_info_and_proof from chia.util.errors import Err from chia.util.hash import std_hash from chia.util.ints import uint8, uint64, uint32 from chia.util.merkle_set import MerkleSet from chia.util.recursive_replace import recursive_replace -from tests.wallet_tools import WalletTool +from chia.util.wallet_tools import WalletTool from tests.core.fixtures import default_400_blocks # noqa: F401; noqa: F401 from tests.core.fixtures import default_1000_blocks # noqa: F401 from tests.core.fixtures import default_10000_blocks # noqa: F401 diff --git a/tests/blockchain/test_blockchain_transactions.py b/tests/blockchain/test_blockchain_transactions.py index 1cda186263c9..4d30306a94ea 100644 --- a/tests/blockchain/test_blockchain_transactions.py +++ b/tests/blockchain/test_blockchain_transactions.py @@ -12,7 +12,7 @@ from chia.types.condition_with_args import ConditionWithArgs from chia.types.spend_bundle import SpendBundle from chia.util.errors import ConsensusError, Err from chia.util.ints import uint64 -from tests.wallet_tools import WalletTool +from chia.util.wallet_tools import WalletTool from tests.core.full_node.test_full_node import connect_and_get_peer from tests.setup_nodes import bt, setup_two_nodes, test_constants from tests.util.generator_tools_testing import run_and_get_removals_and_additions diff --git a/tests/core/daemon/test_daemon.py b/tests/core/daemon/test_daemon.py index cef16709c9ae..b5b0b7cde4c2 100644 --- a/tests/core/daemon/test_daemon.py +++ b/tests/core/daemon/test_daemon.py @@ -6,7 +6,7 @@ import pytest from chia.server.outbound_message import NodeType from chia.server.server import ssl_context_for_server from chia.types.peer_info import PeerInfo -from tests.block_tools import BlockTools +from chia.util.block_tools import BlockTools from chia.util.ints import uint16 from chia.util.ws_message import create_payload from tests.core.node_height import node_height_at_least diff --git a/tests/core/full_node/full_sync/test_full_sync.py b/tests/core/full_node/full_sync/test_full_sync.py index e950ecc3af80..137b367e8153 100644 --- a/tests/core/full_node/full_sync/test_full_sync.py +++ b/tests/core/full_node/full_sync/test_full_sync.py @@ -370,5 +370,5 @@ class TestFullSync: s.new_sub_slot_iters * 2, ) await full_node_2.full_node.sync_from_fork_point(0, 500, peak1.header_hash, summaries2) - log.info(f"full node height {full_node_2.full_node.blockchain.get_peak().height}") - assert node_height_exactly(full_node_2, 320) + log.warning(f"full node height {full_node_2.full_node.blockchain.get_peak().height}") + assert node_height_between(full_node_2, 320, 400) diff --git a/tests/core/full_node/test_coin_store.py b/tests/core/full_node/test_coin_store.py index 4bbb3083b210..ad92b6de048a 100644 --- a/tests/core/full_node/test_coin_store.py +++ b/tests/core/full_node/test_coin_store.py @@ -18,7 +18,7 @@ from chia.types.full_block import FullBlock from chia.types.generator_types import BlockGenerator from chia.util.generator_tools import tx_removals_and_additions from chia.util.ints import uint64, uint32 -from tests.wallet_tools import WalletTool +from chia.util.wallet_tools import WalletTool from chia.util.db_wrapper import DBWrapper from tests.setup_nodes import bt, test_constants diff --git a/tests/core/full_node/test_conditions.py b/tests/core/full_node/test_conditions.py index 1f9fc8465e8c..aeedec9b1e75 100644 --- a/tests/core/full_node/test_conditions.py +++ b/tests/core/full_node/test_conditions.py @@ -23,7 +23,7 @@ from chia.types.coin_solution import CoinSolution from chia.types.condition_opcodes import ConditionOpcode from chia.types.full_block import FullBlock from chia.types.spend_bundle import SpendBundle -from tests.block_tools import BlockTools, test_constants +from chia.util.block_tools import BlockTools, test_constants from chia.util.errors import Err from chia.util.ints import uint32 diff --git a/tests/core/full_node/test_full_node.py b/tests/core/full_node/test_full_node.py index 16f9dd114807..9ae638bc327c 100644 --- a/tests/core/full_node/test_full_node.py +++ b/tests/core/full_node/test_full_node.py @@ -30,14 +30,14 @@ from chia.types.mempool_inclusion_status import MempoolInclusionStatus from chia.types.peer_info import PeerInfo, TimestampedPeerInfo from chia.types.spend_bundle import SpendBundle from chia.types.unfinished_block import UnfinishedBlock -from tests.block_tools import get_signage_point +from chia.util.block_tools import get_signage_point from chia.util.clvm import int_to_bytes from chia.util.errors import Err from chia.util.hash import std_hash from chia.util.ints import uint8, uint16, uint32, uint64 from chia.util.recursive_replace import recursive_replace from chia.util.vdf_prover import get_vdf_info_and_proof -from tests.wallet_tools import WalletTool +from chia.util.wallet_tools import WalletTool from tests.core.fixtures import empty_blockchain # noqa: F401 from chia.wallet.cc_wallet.cc_wallet import CCWallet from chia.wallet.transaction_record import TransactionRecord diff --git a/tests/core/full_node/test_full_node_store.py b/tests/core/full_node/test_full_node_store.py index 1f73ea9de6c0..ec5c183a6eb9 100644 --- a/tests/core/full_node/test_full_node_store.py +++ b/tests/core/full_node/test_full_node_store.py @@ -16,7 +16,7 @@ from chia.protocols.timelord_protocol import NewInfusionPointVDF from chia.types.blockchain_format.sized_bytes import bytes32 from chia.types.unfinished_block import UnfinishedBlock from chia.util.block_cache import BlockCache -from tests.block_tools import get_signage_point, BlockTools +from chia.util.block_tools import get_signage_point, BlockTools from chia.util.hash import std_hash from chia.util.ints import uint8, uint32, uint64, uint128 from tests.core.fixtures import default_1000_blocks, create_blockchain # noqa: F401 diff --git a/tests/core/full_node/test_mempool.py b/tests/core/full_node/test_mempool.py index d3cd57a717b7..567723f5f0e1 100644 --- a/tests/core/full_node/test_mempool.py +++ b/tests/core/full_node/test_mempool.py @@ -1,14 +1,11 @@ import asyncio import logging - -from typing import Dict, List, Optional, Tuple, Callable +from time import time +from typing import Dict, List, Optional import pytest -import chia.server.ws_connection as ws - from chia.full_node.mempool import Mempool -from chia.full_node.full_node_api import FullNodeAPI from chia.protocols import full_node_protocol from chia.simulator.simulator_protocol import FarmNewBlockProtocol from chia.types.announcement import Announcement @@ -21,9 +18,6 @@ from chia.util.clvm import int_to_bytes from chia.util.condition_tools import conditions_for_solution from chia.util.errors import Err from chia.util.ints import uint64 -from chia.util.hash import std_hash -from chia.types.mempool_inclusion_status import MempoolInclusionStatus -from chia.util.api_decorators import api_request, peer_required, bytes_required from tests.connection_utils import connect_and_get_peer from tests.core.node_height import node_height_at_least @@ -101,29 +95,6 @@ class TestMempool: assert spend_bundle is not None -@peer_required -@api_request -@bytes_required -async def respond_transaction( - node: FullNodeAPI, - tx: full_node_protocol.RespondTransaction, - peer: ws.WSChiaConnection, - tx_bytes: bytes = b"", - test: bool = False, -) -> Tuple[MempoolInclusionStatus, Optional[Err]]: - """ - Receives a full transaction from peer. - If tx is added to mempool, send tx_id to others. (new_transaction) - """ - assert tx_bytes != b"" - spend_name = std_hash(tx_bytes) - if spend_name in node.full_node.full_node_store.pending_tx_request: - node.full_node.full_node_store.pending_tx_request.pop(spend_name) - if spend_name in node.full_node.full_node_store.peers_with_tx: - node.full_node.full_node_store.peers_with_tx.pop(spend_name) - return await node.full_node.respond_transaction(tx.transaction, spend_name, peer, test) - - class TestMempoolManager: @pytest.mark.asyncio async def test_basic_mempool_manager(self, two_nodes): @@ -178,9 +149,7 @@ class TestMempoolManager: assert spend_bundle1 is not None tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(spend_bundle1) - status, err = await respond_transaction(full_node_1, tx1, peer) - assert status == MempoolInclusionStatus.SUCCESS - assert err is None + await full_node_1.respond_transaction(tx1, peer) spend_bundle2 = generate_test_spend_bundle( list(blocks[-1].get_included_reward_coins())[0], @@ -188,15 +157,13 @@ class TestMempoolManager: ) assert spend_bundle2 is not None tx2: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(spend_bundle2) - status, err = await respond_transaction(full_node_1, tx2, peer) + await full_node_1.respond_transaction(tx2, peer) sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) sb2 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle2.name()) assert sb1 == spend_bundle1 assert sb2 is None - assert status == MempoolInclusionStatus.PENDING - assert err == Err.MEMPOOL_CONFLICT async def send_sb(self, node, peer, sb): tx = full_node_protocol.RespondTransaction(sb) @@ -326,11 +293,125 @@ class TestMempoolManager: tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(spend_bundle1) - status, err = await respond_transaction(full_node_1, tx1, peer) - return blocks, spend_bundle1, peer, status, err + await full_node_1.respond_transaction(tx1, peer) + return blocks, spend_bundle1, peer @pytest.mark.asyncio - async def condition_tester2(self, two_nodes, test_fun: Callable[[Coin, Coin], SpendBundle]): + async def test_invalid_block_index(self, two_nodes): + + full_node_1, full_node_2, server_1, server_2 = two_nodes + blocks = await full_node_1.get_all_full_blocks() + start_height = blocks[-1].height + cvp = ConditionWithArgs( + ConditionOpcode.ASSERT_HEIGHT_ABSOLUTE, + [uint64(start_height + 5).to_bytes(4, "big")], + ) + dic = {ConditionOpcode.ASSERT_HEIGHT_ABSOLUTE: [cvp]} + blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic) + sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) + + assert sb1 is None + + @pytest.mark.asyncio + async def test_correct_block_index(self, two_nodes): + + full_node_1, full_node_2, server_1, server_2 = two_nodes + cvp = ConditionWithArgs(ConditionOpcode.ASSERT_HEIGHT_ABSOLUTE, [uint64(1).to_bytes(4, "big")]) + dic = {ConditionOpcode.ASSERT_HEIGHT_ABSOLUTE: [cvp]} + blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic) + sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) + + assert sb1 is spend_bundle1 + + @pytest.mark.asyncio + async def test_invalid_block_age(self, two_nodes): + + full_node_1, full_node_2, server_1, server_2 = two_nodes + cvp = ConditionWithArgs(ConditionOpcode.ASSERT_HEIGHT_RELATIVE, [uint64(5).to_bytes(4, "big")]) + dic = {cvp.opcode: [cvp]} + blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic) + sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) + assert sb1 is None + + @pytest.mark.asyncio + async def test_correct_block_age(self, two_nodes): + + full_node_1, full_node_2, server_1, server_2 = two_nodes + cvp = ConditionWithArgs(ConditionOpcode.ASSERT_HEIGHT_RELATIVE, [uint64(1).to_bytes(4, "big")]) + dic = {cvp.opcode: [cvp]} + blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic, num_blocks=4) + + sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) + + assert sb1 is spend_bundle1 + + @pytest.mark.asyncio + async def test_correct_my_id(self, two_nodes): + + full_node_1, full_node_2, server_1, server_2 = two_nodes + blocks = await full_node_1.get_all_full_blocks() + coin = list(blocks[-1].get_included_reward_coins())[0] + cvp = ConditionWithArgs(ConditionOpcode.ASSERT_MY_COIN_ID, [coin.name()]) + dic = {cvp.opcode: [cvp]} + blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic, coin=coin) + + sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) + + assert sb1 is spend_bundle1 + + @pytest.mark.asyncio + async def test_invalid_my_id(self, two_nodes): + + full_node_1, full_node_2, server_1, server_2 = two_nodes + blocks = await full_node_1.get_all_full_blocks() + coin = list(blocks[-1].get_included_reward_coins())[0] + coin_2 = list(blocks[-2].get_included_reward_coins())[0] + cvp = ConditionWithArgs(ConditionOpcode.ASSERT_MY_COIN_ID, [coin_2.name()]) + dic = {cvp.opcode: [cvp]} + blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic, coin=coin) + + sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) + + assert sb1 is None + + @pytest.mark.asyncio + async def test_assert_time_exceeds(self, two_nodes): + + full_node_1, full_node_2, server_1, server_2 = two_nodes + time_now = uint64(int(time())) + + cvp = ConditionWithArgs(ConditionOpcode.ASSERT_SECONDS_ABSOLUTE, [time_now.to_bytes(8, "big")]) + dic = {cvp.opcode: [cvp]} + blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic) + sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) + + assert sb1 is spend_bundle1 + + @pytest.mark.asyncio + async def test_assert_time_relative_exceeds(self, two_nodes): + + full_node_1, full_node_2, server_1, server_2 = two_nodes + time_relative = uint64(3) + + cvp = ConditionWithArgs(ConditionOpcode.ASSERT_SECONDS_RELATIVE, [time_relative.to_bytes(8, "big")]) + dic = {cvp.opcode: [cvp]} + blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic) + + sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) + assert sb1 is None + + for i in range(0, 4): + await full_node_1.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"0")) + + tx2: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(spend_bundle1) + await full_node_1.respond_transaction(tx2, peer) + + sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) + + assert sb1 is spend_bundle1 + + @pytest.mark.asyncio + async def test_correct_coin_announcement_consumed(self, two_nodes): reward_ph = WALLET_A.get_new_puzzlehash() full_node_1, full_node_2, server_1, server_2 = two_nodes blocks = await full_node_1.get_all_full_blocks() @@ -352,242 +433,68 @@ class TestMempoolManager: coin_1 = list(blocks[-2].get_included_reward_coins())[0] coin_2 = list(blocks[-1].get_included_reward_coins())[0] - bundle = test_fun(coin_1, coin_2) + announce = Announcement(coin_2.name(), bytes("test", "utf-8")) + + cvp = ConditionWithArgs(ConditionOpcode.ASSERT_COIN_ANNOUNCEMENT, [announce.name()]) + + dic = {cvp.opcode: [cvp]} + + cvp2 = ConditionWithArgs(ConditionOpcode.CREATE_COIN_ANNOUNCEMENT, [bytes("test", "utf-8")]) + dic2 = {cvp.opcode: [cvp2]} + spend_bundle1 = generate_test_spend_bundle(coin_1, dic) + + spend_bundle2 = generate_test_spend_bundle(coin_2, dic2) + + bundle = SpendBundle.aggregate([spend_bundle1, spend_bundle2]) tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(bundle) - status, err = await respond_transaction(full_node_1, tx1, peer) + await full_node_1.respond_transaction(tx1, peer) - return blocks, bundle, status, err - - @pytest.mark.asyncio - async def test_invalid_block_index(self, two_nodes): - - full_node_1, full_node_2, server_1, server_2 = two_nodes - blocks = await full_node_1.get_all_full_blocks() - start_height = blocks[-1].height - cvp = ConditionWithArgs( - ConditionOpcode.ASSERT_HEIGHT_ABSOLUTE, - [int_to_bytes(start_height + 5)], - ) - dic = {ConditionOpcode.ASSERT_HEIGHT_ABSOLUTE: [cvp]} - blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic) - sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) - assert sb1 is None - # the transaction may become valid later - assert status == MempoolInclusionStatus.PENDING - assert err == Err.ASSERT_HEIGHT_ABSOLUTE_FAILED - - @pytest.mark.asyncio - async def test_correct_block_index(self, two_nodes): - - full_node_1, full_node_2, server_1, server_2 = two_nodes - cvp = ConditionWithArgs(ConditionOpcode.ASSERT_HEIGHT_ABSOLUTE, [int_to_bytes(1)]) - dic = {ConditionOpcode.ASSERT_HEIGHT_ABSOLUTE: [cvp]} - blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic) - sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) - assert sb1 is spend_bundle1 - assert status == MempoolInclusionStatus.SUCCESS - assert err is None - - @pytest.mark.asyncio - async def test_negative_block_index(self, two_nodes): - - full_node_1, full_node_2, server_1, server_2 = two_nodes - cvp = ConditionWithArgs(ConditionOpcode.ASSERT_HEIGHT_ABSOLUTE, [int_to_bytes(-1)]) - dic = {ConditionOpcode.ASSERT_HEIGHT_ABSOLUTE: [cvp]} - blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic) - sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) - assert sb1 is spend_bundle1 - assert status == MempoolInclusionStatus.SUCCESS - assert err is None - - @pytest.mark.asyncio - async def test_invalid_block_age(self, two_nodes): - - full_node_1, full_node_2, server_1, server_2 = two_nodes - cvp = ConditionWithArgs(ConditionOpcode.ASSERT_HEIGHT_RELATIVE, [int_to_bytes(5)]) - dic = {cvp.opcode: [cvp]} - blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic) - sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) - assert sb1 is None - # the transaction may become valid later - assert status == MempoolInclusionStatus.PENDING - assert err == Err.ASSERT_HEIGHT_RELATIVE_FAILED - - @pytest.mark.asyncio - async def test_correct_block_age(self, two_nodes): - - full_node_1, full_node_2, server_1, server_2 = two_nodes - cvp = ConditionWithArgs(ConditionOpcode.ASSERT_HEIGHT_RELATIVE, [int_to_bytes(1)]) - dic = {cvp.opcode: [cvp]} - blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic, num_blocks=4) - - sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) - assert sb1 is spend_bundle1 - assert status == MempoolInclusionStatus.SUCCESS - assert err is None - - @pytest.mark.asyncio - async def test_negative_block_age(self, two_nodes): - - full_node_1, full_node_2, server_1, server_2 = two_nodes - cvp = ConditionWithArgs(ConditionOpcode.ASSERT_HEIGHT_RELATIVE, [int_to_bytes(-1)]) - dic = {cvp.opcode: [cvp]} - blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic, num_blocks=4) - - sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) - assert sb1 is spend_bundle1 - assert status == MempoolInclusionStatus.SUCCESS - assert err is None - - @pytest.mark.asyncio - async def test_correct_my_id(self, two_nodes): - - full_node_1, full_node_2, server_1, server_2 = two_nodes - blocks = await full_node_1.get_all_full_blocks() - coin = list(blocks[-1].get_included_reward_coins())[0] - cvp = ConditionWithArgs(ConditionOpcode.ASSERT_MY_COIN_ID, [coin.name()]) - dic = {cvp.opcode: [cvp]} - blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic, coin=coin) - - sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) - assert sb1 is spend_bundle1 - assert status == MempoolInclusionStatus.SUCCESS - assert err is None - - @pytest.mark.asyncio - async def test_invalid_my_id(self, two_nodes): - - full_node_1, full_node_2, server_1, server_2 = two_nodes - blocks = await full_node_1.get_all_full_blocks() - coin = list(blocks[-1].get_included_reward_coins())[0] - coin_2 = list(blocks[-2].get_included_reward_coins())[0] - cvp = ConditionWithArgs(ConditionOpcode.ASSERT_MY_COIN_ID, [coin_2.name()]) - dic = {cvp.opcode: [cvp]} - blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic, coin=coin) - - sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) - assert sb1 is None - assert status == MempoolInclusionStatus.FAILED - assert err == Err.ASSERT_MY_COIN_ID_FAILED - - @pytest.mark.asyncio - async def test_assert_time_exceeds(self, two_nodes): - - full_node_1, full_node_2, server_1, server_2 = two_nodes - # 5 seconds should be before the next block - time_now = full_node_1.full_node.blockchain.get_peak().timestamp + 5 - - cvp = ConditionWithArgs(ConditionOpcode.ASSERT_SECONDS_ABSOLUTE, [int_to_bytes(time_now)]) - dic = {cvp.opcode: [cvp]} - blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic) - sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) - assert sb1 is spend_bundle1 - assert status == MempoolInclusionStatus.SUCCESS - assert err is None - - @pytest.mark.asyncio - async def test_assert_time_negative(self, two_nodes): - - full_node_1, full_node_2, server_1, server_2 = two_nodes - time_now = -1 - - cvp = ConditionWithArgs(ConditionOpcode.ASSERT_SECONDS_ABSOLUTE, [int_to_bytes(time_now)]) - dic = {cvp.opcode: [cvp]} - blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic) - sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) - assert sb1 is spend_bundle1 - assert status == MempoolInclusionStatus.SUCCESS - assert err is None - - @pytest.mark.asyncio - async def test_assert_time_relative_exceeds(self, two_nodes): - - full_node_1, full_node_2, server_1, server_2 = two_nodes - time_relative = 3 - - cvp = ConditionWithArgs(ConditionOpcode.ASSERT_SECONDS_RELATIVE, [int_to_bytes(time_relative)]) - dic = {cvp.opcode: [cvp]} - blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic) - - sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) - assert sb1 is None - assert status == MempoolInclusionStatus.FAILED - assert err == Err.ASSERT_SECONDS_RELATIVE_FAILED - - for i in range(0, 4): - await full_node_1.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"0")) - - tx2: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(spend_bundle1) - - status, err = await respond_transaction(full_node_1, tx2, peer) - - sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) - assert sb1 is spend_bundle1 - assert status == MempoolInclusionStatus.SUCCESS - assert err is None - - @pytest.mark.asyncio - async def test_assert_time_relative_negative(self, two_nodes): - - full_node_1, full_node_2, server_1, server_2 = two_nodes - time_relative = -3 - - cvp = ConditionWithArgs(ConditionOpcode.ASSERT_SECONDS_RELATIVE, [int_to_bytes(time_relative)]) - dic = {cvp.opcode: [cvp]} - blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic) - - sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) - assert sb1 is spend_bundle1 - assert status == MempoolInclusionStatus.SUCCESS - assert err is None - - @pytest.mark.asyncio - async def test_correct_coin_announcement_consumed(self, two_nodes): - def test_fun(coin_1: Coin, coin_2: Coin) -> SpendBundle: - announce = Announcement(coin_2.name(), b"test") - cvp = ConditionWithArgs(ConditionOpcode.ASSERT_COIN_ANNOUNCEMENT, [announce.name()]) - dic = {cvp.opcode: [cvp]} - - cvp2 = ConditionWithArgs(ConditionOpcode.CREATE_COIN_ANNOUNCEMENT, [b"test"]) - dic2 = {cvp.opcode: [cvp2]} - spend_bundle1 = generate_test_spend_bundle(coin_1, dic) - spend_bundle2 = generate_test_spend_bundle(coin_2, dic2) - bundle = SpendBundle.aggregate([spend_bundle1, spend_bundle2]) - return bundle - - full_node_1, full_node_2, server_1, server_2 = two_nodes - blocks, bundle, status, err = await self.condition_tester2(two_nodes, test_fun) mempool_bundle = full_node_1.full_node.mempool_manager.get_spendbundle(bundle.name()) assert mempool_bundle is bundle - assert status == MempoolInclusionStatus.SUCCESS - assert err is None @pytest.mark.asyncio async def test_coin_announcement_too_big(self, two_nodes): + reward_ph = WALLET_A.get_new_puzzlehash() full_node_1, full_node_2, server_1, server_2 = two_nodes + blocks = await full_node_1.get_all_full_blocks() + start_height = blocks[-1].height if len(blocks) > 0 else -1 + blocks = bt.get_consecutive_blocks( + 3, + block_list_input=blocks, + guarantee_transaction_block=True, + farmer_reward_puzzle_hash=reward_ph, + pool_reward_puzzle_hash=reward_ph, + ) + peer = await connect_and_get_peer(server_1, server_2) - def test_fun(coin_1: Coin, coin_2: Coin): - announce = Announcement(coin_2.name(), bytes([1] * 10000)) + for block in blocks: + await full_node_1.full_node.respond_block(full_node_protocol.RespondBlock(block)) - cvp = ConditionWithArgs(ConditionOpcode.ASSERT_COIN_ANNOUNCEMENT, [announce.name()]) + await time_out_assert(60, node_height_at_least, True, full_node_1, start_height + 3) - dic = {cvp.opcode: [cvp]} + coin_1 = list(blocks[-2].get_included_reward_coins())[0] + coin_2 = list(blocks[-1].get_included_reward_coins())[0] - cvp2 = ConditionWithArgs(ConditionOpcode.CREATE_COIN_ANNOUNCEMENT, [b"test"]) - dic2 = {cvp.opcode: [cvp2]} - spend_bundle1 = generate_test_spend_bundle(coin_1, dic) + announce = Announcement(coin_2.name(), bytes([1] * 10000)) - spend_bundle2 = generate_test_spend_bundle(coin_2, dic2) + cvp = ConditionWithArgs(ConditionOpcode.ASSERT_COIN_ANNOUNCEMENT, [announce.name()]) - return SpendBundle.aggregate([spend_bundle1, spend_bundle2]) + dic = {cvp.opcode: [cvp]} - blocks, bundle, status, err = await self.condition_tester2(two_nodes, test_fun) + cvp2 = ConditionWithArgs(ConditionOpcode.CREATE_COIN_ANNOUNCEMENT, [bytes("test", "utf-8")]) + dic2 = {cvp.opcode: [cvp2]} + spend_bundle1 = generate_test_spend_bundle(coin_1, dic) + + spend_bundle2 = generate_test_spend_bundle(coin_2, dic2) + + bundle = SpendBundle.aggregate([spend_bundle1, spend_bundle2]) + + tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(bundle) + await full_node_1.respond_transaction(tx1, peer) assert full_node_1.full_node.mempool_manager.get_spendbundle(bundle.name()) is None - assert status == MempoolInclusionStatus.FAILED - assert err == Err.ASSERT_ANNOUNCE_CONSUMED_FAILED blocks = bt.get_consecutive_blocks( 1, block_list_input=blocks, guarantee_transaction_block=True, transaction_data=bundle @@ -600,150 +507,236 @@ class TestMempoolManager: @pytest.mark.asyncio async def test_invalid_coin_announcement_rejected(self, two_nodes): + reward_ph = WALLET_A.get_new_puzzlehash() full_node_1, full_node_2, server_1, server_2 = two_nodes + blocks = await full_node_1.get_all_full_blocks() + start_height = blocks[-1].height if len(blocks) > 0 else -1 + blocks = bt.get_consecutive_blocks( + 3, + block_list_input=blocks, + guarantee_transaction_block=True, + farmer_reward_puzzle_hash=reward_ph, + pool_reward_puzzle_hash=reward_ph, + ) + peer = await connect_and_get_peer(server_1, server_2) - def test_fun(coin_1: Coin, coin_2: Coin): - announce = Announcement(coin_2.name(), b"test") + for block in blocks: + await full_node_1.full_node.respond_block(full_node_protocol.RespondBlock(block)) - cvp = ConditionWithArgs(ConditionOpcode.ASSERT_COIN_ANNOUNCEMENT, [announce.name()]) + await time_out_assert(60, node_height_at_least, True, full_node_1, start_height + 3) - dic = {cvp.opcode: [cvp]} - # Wrong message - cvp2 = ConditionWithArgs( - ConditionOpcode.CREATE_COIN_ANNOUNCEMENT, - [b"wrong test"], - ) - dic2 = {cvp.opcode: [cvp2]} - spend_bundle1 = generate_test_spend_bundle(coin_1, dic) + coin_1 = list(blocks[-2].get_included_reward_coins())[0] + coin_2 = list(blocks[-1].get_included_reward_coins())[0] - spend_bundle2 = generate_test_spend_bundle(coin_2, dic2) + announce = Announcement(coin_2.name(), bytes("test", "utf-8")) - return SpendBundle.aggregate([spend_bundle1, spend_bundle2]) + cvp = ConditionWithArgs(ConditionOpcode.ASSERT_COIN_ANNOUNCEMENT, [announce.name()]) - blocks, bundle, status, err = await self.condition_tester2(two_nodes, test_fun) + dic = {cvp.opcode: [cvp]} + # Wrong message + cvp2 = ConditionWithArgs( + ConditionOpcode.CREATE_COIN_ANNOUNCEMENT, + [bytes("wrong test", "utf-8")], + ) + dic2 = {cvp.opcode: [cvp2]} + spend_bundle1 = generate_test_spend_bundle(coin_1, dic) + + spend_bundle2 = generate_test_spend_bundle(coin_2, dic2) + + bundle = SpendBundle.aggregate([spend_bundle1, spend_bundle2]) + + tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(spend_bundle1) + await full_node_1.respond_transaction(tx1, peer) mempool_bundle = full_node_1.full_node.mempool_manager.get_spendbundle(bundle.name()) assert mempool_bundle is None - assert status == MempoolInclusionStatus.FAILED - assert err == Err.ASSERT_ANNOUNCE_CONSUMED_FAILED @pytest.mark.asyncio async def test_invalid_coin_announcement_rejected_two(self, two_nodes): + reward_ph = WALLET_A.get_new_puzzlehash() full_node_1, full_node_2, server_1, server_2 = two_nodes + blocks = await full_node_1.get_all_full_blocks() + start_height = blocks[-1].height if len(blocks) > 0 else -1 + blocks = bt.get_consecutive_blocks( + 3, + block_list_input=blocks, + guarantee_transaction_block=True, + farmer_reward_puzzle_hash=reward_ph, + pool_reward_puzzle_hash=reward_ph, + ) + peer = await connect_and_get_peer(server_1, server_2) - def test_fun(coin_1: Coin, coin_2: Coin): - announce = Announcement(coin_1.name(), b"test") + for block in blocks: + await full_node_1.full_node.respond_block(full_node_protocol.RespondBlock(block)) - cvp = ConditionWithArgs(ConditionOpcode.ASSERT_COIN_ANNOUNCEMENT, [announce.name()]) + await time_out_assert(60, node_height_at_least, True, full_node_1, start_height + 3) - dic = {cvp.opcode: [cvp]} + coin_1 = list(blocks[-2].get_included_reward_coins())[0] + coin_2 = list(blocks[-1].get_included_reward_coins())[0] - cvp2 = ConditionWithArgs( - ConditionOpcode.CREATE_COIN_ANNOUNCEMENT, - [b"test"], - ) - dic2 = {cvp.opcode: [cvp2]} - spend_bundle1 = generate_test_spend_bundle(coin_1, dic) + announce = Announcement(coin_1.name(), bytes("test", "utf-8")) - # coin 2 is making the announcement, right message wrong coin - spend_bundle2 = generate_test_spend_bundle(coin_2, dic2) + cvp = ConditionWithArgs(ConditionOpcode.ASSERT_COIN_ANNOUNCEMENT, [announce.name()]) - return SpendBundle.aggregate([spend_bundle1, spend_bundle2]) + dic = {cvp.opcode: [cvp]} + + cvp2 = ConditionWithArgs( + ConditionOpcode.CREATE_COIN_ANNOUNCEMENT, + [bytes("test", "utf-8")], + ) + dic2 = {cvp.opcode: [cvp2]} + spend_bundle1 = generate_test_spend_bundle(coin_1, dic) + + # coin 2 is making the announcement, right message wrong coin + spend_bundle2 = generate_test_spend_bundle(coin_2, dic2) + + bundle = SpendBundle.aggregate([spend_bundle1, spend_bundle2]) + + tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(spend_bundle1) + await full_node_1.respond_transaction(tx1, peer) - blocks, bundle, status, err = await self.condition_tester2(two_nodes, test_fun) mempool_bundle = full_node_1.full_node.mempool_manager.get_spendbundle(bundle.name()) assert mempool_bundle is None - assert status == MempoolInclusionStatus.FAILED - assert err == Err.ASSERT_ANNOUNCE_CONSUMED_FAILED @pytest.mark.asyncio async def test_correct_puzzle_announcement(self, two_nodes): + reward_ph = WALLET_A.get_new_puzzlehash() full_node_1, full_node_2, server_1, server_2 = two_nodes + blocks = await full_node_1.get_all_full_blocks() + start_height = blocks[-1].height if len(blocks) > 0 else -1 + blocks = bt.get_consecutive_blocks( + 3, + block_list_input=blocks, + guarantee_transaction_block=True, + farmer_reward_puzzle_hash=reward_ph, + pool_reward_puzzle_hash=reward_ph, + ) + peer = await connect_and_get_peer(server_1, server_2) - def test_fun(coin_1: Coin, coin_2: Coin): - announce = Announcement(coin_2.puzzle_hash, bytes(0x80)) + for block in blocks: + await full_node_1.full_node.respond_block(full_node_protocol.RespondBlock(block)) - cvp = ConditionWithArgs(ConditionOpcode.ASSERT_PUZZLE_ANNOUNCEMENT, [announce.name()]) + await time_out_assert(60, node_height_at_least, True, full_node_1, start_height + 3) - dic = {cvp.opcode: [cvp]} + coin_1 = list(blocks[-2].get_included_reward_coins())[0] + coin_2 = list(blocks[-1].get_included_reward_coins())[0] - cvp2 = ConditionWithArgs(ConditionOpcode.CREATE_PUZZLE_ANNOUNCEMENT, [bytes(0x80)]) - dic2 = {cvp.opcode: [cvp2]} - spend_bundle1 = generate_test_spend_bundle(coin_1, dic) + announce = Announcement(coin_2.puzzle_hash, bytes(0x80)) - spend_bundle2 = generate_test_spend_bundle(coin_2, dic2) + cvp = ConditionWithArgs(ConditionOpcode.ASSERT_PUZZLE_ANNOUNCEMENT, [announce.name()]) - return SpendBundle.aggregate([spend_bundle1, spend_bundle2]) + dic = {cvp.opcode: [cvp]} - blocks, bundle, status, err = await self.condition_tester2(two_nodes, test_fun) + cvp2 = ConditionWithArgs(ConditionOpcode.CREATE_PUZZLE_ANNOUNCEMENT, [bytes(0x80)]) + dic2 = {cvp.opcode: [cvp2]} + spend_bundle1 = generate_test_spend_bundle(coin_1, dic) + + spend_bundle2 = generate_test_spend_bundle(coin_2, dic2) + + bundle = SpendBundle.aggregate([spend_bundle1, spend_bundle2]) + + tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(bundle) + await full_node_1.respond_transaction(tx1, peer) mempool_bundle = full_node_1.full_node.mempool_manager.get_spendbundle(bundle.name()) assert mempool_bundle is bundle - assert status == MempoolInclusionStatus.SUCCESS - assert err is None @pytest.mark.asyncio async def test_invalid_puzzle_announcement_rejected(self, two_nodes): + reward_ph = WALLET_A.get_new_puzzlehash() full_node_1, full_node_2, server_1, server_2 = two_nodes + blocks = await full_node_1.get_all_full_blocks() + start_height = blocks[-1].height if len(blocks) > 0 else -1 + blocks = bt.get_consecutive_blocks( + 3, + block_list_input=blocks, + guarantee_transaction_block=True, + farmer_reward_puzzle_hash=reward_ph, + pool_reward_puzzle_hash=reward_ph, + ) + peer = await connect_and_get_peer(server_1, server_2) - def test_fun(coin_1: Coin, coin_2: Coin): - announce = Announcement(coin_2.puzzle_hash, bytes("test", "utf-8")) + for block in blocks: + await full_node_1.full_node.respond_block(full_node_protocol.RespondBlock(block)) - cvp = ConditionWithArgs(ConditionOpcode.ASSERT_PUZZLE_ANNOUNCEMENT, [announce.name()]) + await time_out_assert(60, node_height_at_least, True, full_node_1, start_height + 3) - dic = {cvp.opcode: [cvp]} + coin_1 = list(blocks[-2].get_included_reward_coins())[0] + coin_2 = list(blocks[-1].get_included_reward_coins())[0] - cvp2 = ConditionWithArgs( - ConditionOpcode.CREATE_PUZZLE_ANNOUNCEMENT, - [b"wrong test"], - ) - dic2 = {cvp.opcode: [cvp2]} - spend_bundle1 = generate_test_spend_bundle(coin_1, dic) + announce = Announcement(coin_2.puzzle_hash, bytes("test", "utf-8")) - spend_bundle2 = generate_test_spend_bundle(coin_2, dic2) + cvp = ConditionWithArgs(ConditionOpcode.ASSERT_PUZZLE_ANNOUNCEMENT, [announce.name()]) - return SpendBundle.aggregate([spend_bundle1, spend_bundle2]) + dic = {cvp.opcode: [cvp]} - blocks, bundle, status, err = await self.condition_tester2(two_nodes, test_fun) + cvp2 = ConditionWithArgs( + ConditionOpcode.CREATE_PUZZLE_ANNOUNCEMENT, + [bytes("wrong test", "utf-8")], + ) + dic2 = {cvp.opcode: [cvp2]} + spend_bundle1 = generate_test_spend_bundle(coin_1, dic) + + spend_bundle2 = generate_test_spend_bundle(coin_2, dic2) + + bundle = SpendBundle.aggregate([spend_bundle1, spend_bundle2]) + + tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(spend_bundle1) + await full_node_1.respond_transaction(tx1, peer) mempool_bundle = full_node_1.full_node.mempool_manager.get_spendbundle(bundle.name()) assert mempool_bundle is None - assert status == MempoolInclusionStatus.FAILED - assert err == Err.ASSERT_ANNOUNCE_CONSUMED_FAILED @pytest.mark.asyncio async def test_invalid_puzzle_announcement_rejected_two(self, two_nodes): + reward_ph = WALLET_A.get_new_puzzlehash() full_node_1, full_node_2, server_1, server_2 = two_nodes + blocks = await full_node_1.get_all_full_blocks() + start_height = blocks[-1].height if len(blocks) > 0 else -1 + blocks = bt.get_consecutive_blocks( + 3, + block_list_input=blocks, + guarantee_transaction_block=True, + farmer_reward_puzzle_hash=reward_ph, + pool_reward_puzzle_hash=reward_ph, + ) + peer = await connect_and_get_peer(server_1, server_2) - def test_fun(coin_1: Coin, coin_2: Coin): - announce = Announcement(coin_2.puzzle_hash, b"test") + for block in blocks: + await full_node_1.full_node.respond_block(full_node_protocol.RespondBlock(block)) - cvp = ConditionWithArgs(ConditionOpcode.ASSERT_PUZZLE_ANNOUNCEMENT, [announce.name()]) + await time_out_assert(60, node_height_at_least, True, full_node_1, start_height + 3) - dic = {cvp.opcode: [cvp]} - # Wrong type of Create_announcement - cvp2 = ConditionWithArgs( - ConditionOpcode.CREATE_COIN_ANNOUNCEMENT, - [b"test"], - ) - dic2 = {cvp.opcode: [cvp2]} - spend_bundle1 = generate_test_spend_bundle(coin_1, dic) + coin_1 = list(blocks[-2].get_included_reward_coins())[0] + coin_2 = list(blocks[-1].get_included_reward_coins())[0] - spend_bundle2 = generate_test_spend_bundle(coin_2, dic2) + announce = Announcement(coin_2.puzzle_hash, bytes("test", "utf-8")) - return SpendBundle.aggregate([spend_bundle1, spend_bundle2]) + cvp = ConditionWithArgs(ConditionOpcode.ASSERT_PUZZLE_ANNOUNCEMENT, [announce.name()]) - blocks, bundle, status, err = await self.condition_tester2(two_nodes, test_fun) + dic = {cvp.opcode: [cvp]} + # Wrong type of Create_announcement + cvp2 = ConditionWithArgs( + ConditionOpcode.CREATE_COIN_ANNOUNCEMENT, + [bytes("test", "utf-8")], + ) + dic2 = {cvp.opcode: [cvp2]} + spend_bundle1 = generate_test_spend_bundle(coin_1, dic) + + spend_bundle2 = generate_test_spend_bundle(coin_2, dic2) + + bundle = SpendBundle.aggregate([spend_bundle1, spend_bundle2]) + + tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(spend_bundle1) + await full_node_1.respond_transaction(tx1, peer) mempool_bundle = full_node_1.full_node.mempool_manager.get_spendbundle(bundle.name()) assert mempool_bundle is None - assert status == MempoolInclusionStatus.FAILED - assert err == Err.ASSERT_ANNOUNCE_CONSUMED_FAILED @pytest.mark.asyncio async def test_assert_fee_condition(self, two_nodes): @@ -751,35 +744,17 @@ class TestMempoolManager: full_node_1, full_node_2, server_1, server_2 = two_nodes cvp = ConditionWithArgs(ConditionOpcode.RESERVE_FEE, [int_to_bytes(10)]) dic = {cvp.opcode: [cvp]} - blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic, fee=10) + blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic, fee=10) mempool_bundle = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) assert mempool_bundle is not None - assert status == MempoolInclusionStatus.SUCCESS - assert err is None @pytest.mark.asyncio async def test_assert_fee_condition_negative_fee(self, two_nodes): full_node_1, full_node_2, server_1, server_2 = two_nodes cvp = ConditionWithArgs(ConditionOpcode.RESERVE_FEE, [int_to_bytes(-1)]) dic = {cvp.opcode: [cvp]} - blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic, fee=10) - assert status == MempoolInclusionStatus.FAILED - assert err == Err.RESERVE_FEE_CONDITION_FAILED - blocks = bt.get_consecutive_blocks( - 1, block_list_input=blocks, guarantee_transaction_block=True, transaction_data=spend_bundle1 - ) - assert full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) is None - assert (await full_node_1.full_node.blockchain.receive_block(blocks[-1]))[1] == Err.RESERVE_FEE_CONDITION_FAILED - - @pytest.mark.asyncio - async def test_assert_fee_condition_fee_too_large(self, two_nodes): - full_node_1, full_node_2, server_1, server_2 = two_nodes - cvp = ConditionWithArgs(ConditionOpcode.RESERVE_FEE, [int_to_bytes(2 ** 64)]) - dic = {cvp.opcode: [cvp]} - blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic, fee=10) - assert status == MempoolInclusionStatus.FAILED - assert err == Err.RESERVE_FEE_CONDITION_FAILED + blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic, fee=10) blocks = bt.get_consecutive_blocks( 1, block_list_input=blocks, guarantee_transaction_block=True, transaction_data=spend_bundle1 ) @@ -793,12 +768,10 @@ class TestMempoolManager: cvp = ConditionWithArgs(ConditionOpcode.RESERVE_FEE, [int_to_bytes(10)]) dic = {cvp.opcode: [cvp]} - blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic, fee=9) + blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic, fee=9) mempool_bundle = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) assert mempool_bundle is None - assert status == MempoolInclusionStatus.FAILED - assert err == Err.RESERVE_FEE_CONDITION_FAILED @pytest.mark.asyncio async def test_stealing_fee(self, two_nodes): @@ -849,13 +822,11 @@ class TestMempoolManager: tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(spend_bundle1) - status, err = await respond_transaction(full_node_1, tx1, peer) + await full_node_1.respond_transaction(tx1, peer) mempool_bundle = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) assert mempool_bundle is None - assert status == MempoolInclusionStatus.FAILED - assert err == Err.RESERVE_FEE_CONDITION_FAILED @pytest.mark.asyncio async def test_double_spend_same_bundle(self, two_nodes): @@ -892,12 +863,10 @@ class TestMempoolManager: tx: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(spend_bundle_combined) - status, err = await respond_transaction(full_node_1, tx, peer) + await full_node_1.respond_transaction(tx, peer) sb = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle_combined.name()) assert sb is None - assert status == MempoolInclusionStatus.FAILED - assert err == Err.DOUBLE_SPEND @pytest.mark.asyncio async def test_agg_sig_condition(self, two_nodes): @@ -957,13 +926,11 @@ class TestMempoolManager: coin = list(blocks[-1].get_included_reward_coins())[0] cvp = ConditionWithArgs(ConditionOpcode.ASSERT_MY_PARENT_ID, [coin.parent_coin_info]) dic = {cvp.opcode: [cvp]} - blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic, coin=coin) + blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic, coin=coin) sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) assert sb1 is spend_bundle1 - assert status == MempoolInclusionStatus.SUCCESS - assert err is None @pytest.mark.asyncio async def test_invalid_my_parent(self, two_nodes): @@ -974,13 +941,11 @@ class TestMempoolManager: coin_2 = list(blocks[-2].get_included_reward_coins())[0] cvp = ConditionWithArgs(ConditionOpcode.ASSERT_MY_PARENT_ID, [coin_2.parent_coin_info]) dic = {cvp.opcode: [cvp]} - blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic, coin=coin) + blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic, coin=coin) sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) assert sb1 is None - assert status == MempoolInclusionStatus.FAILED - assert err == Err.ASSERT_MY_PARENT_ID_FAILED @pytest.mark.asyncio async def test_correct_my_puzhash(self, two_nodes): @@ -990,13 +955,11 @@ class TestMempoolManager: coin = list(blocks[-1].get_included_reward_coins())[0] cvp = ConditionWithArgs(ConditionOpcode.ASSERT_MY_PUZZLEHASH, [coin.puzzle_hash]) dic = {cvp.opcode: [cvp]} - blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic, coin=coin) + blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic, coin=coin) sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) assert sb1 is spend_bundle1 - assert status == MempoolInclusionStatus.SUCCESS - assert err is None @pytest.mark.asyncio async def test_invalid_my_puzhash(self, two_nodes): @@ -1006,13 +969,11 @@ class TestMempoolManager: coin = list(blocks[-1].get_included_reward_coins())[0] cvp = ConditionWithArgs(ConditionOpcode.ASSERT_MY_PUZZLEHASH, [Program.to([]).get_tree_hash()]) dic = {cvp.opcode: [cvp]} - blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic, coin=coin) + blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic, coin=coin) sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) assert sb1 is None - assert status == MempoolInclusionStatus.FAILED - assert err == Err.ASSERT_MY_PUZZLEHASH_FAILED @pytest.mark.asyncio async def test_correct_my_amount(self, two_nodes): @@ -1020,57 +981,24 @@ class TestMempoolManager: full_node_1, full_node_2, server_1, server_2 = two_nodes blocks = await full_node_1.get_all_full_blocks() coin = list(blocks[-1].get_included_reward_coins())[0] - cvp = ConditionWithArgs(ConditionOpcode.ASSERT_MY_AMOUNT, [int_to_bytes(coin.amount)]) + cvp = ConditionWithArgs(ConditionOpcode.ASSERT_MY_AMOUNT, [coin.amount]) dic = {cvp.opcode: [cvp]} - blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic, coin=coin) + blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic, coin=coin) sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) assert sb1 is spend_bundle1 - assert status == MempoolInclusionStatus.SUCCESS - assert err is None @pytest.mark.asyncio async def test_invalid_my_amount(self, two_nodes): full_node_1, full_node_2, server_1, server_2 = two_nodes blocks = await full_node_1.get_all_full_blocks() - cvp = ConditionWithArgs(ConditionOpcode.ASSERT_MY_AMOUNT, [int_to_bytes(1000)]) + coin = list(blocks[-1].get_included_reward_coins())[0] + cvp = ConditionWithArgs(ConditionOpcode.ASSERT_MY_AMOUNT, [1000]) dic = {cvp.opcode: [cvp]} - blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic) + blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic, coin=coin) sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) assert sb1 is None - assert status == MempoolInclusionStatus.FAILED - assert err == Err.ASSERT_MY_AMOUNT_FAILED - - @pytest.mark.asyncio - async def test_negative_my_amount(self, two_nodes): - - full_node_1, full_node_2, server_1, server_2 = two_nodes - blocks = await full_node_1.get_all_full_blocks() - cvp = ConditionWithArgs(ConditionOpcode.ASSERT_MY_AMOUNT, [int_to_bytes(-1)]) - dic = {cvp.opcode: [cvp]} - blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic) - - sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) - - assert sb1 is None - assert status == MempoolInclusionStatus.FAILED - assert err == Err.ASSERT_MY_AMOUNT_FAILED - - @pytest.mark.asyncio - async def test_my_amount_too_large(self, two_nodes): - - full_node_1, full_node_2, server_1, server_2 = two_nodes - blocks = await full_node_1.get_all_full_blocks() - cvp = ConditionWithArgs(ConditionOpcode.ASSERT_MY_AMOUNT, [int_to_bytes(2 ** 64)]) - dic = {cvp.opcode: [cvp]} - blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic) - - sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) - - assert sb1 is None - assert status == MempoolInclusionStatus.FAILED - assert err == Err.ASSERT_MY_AMOUNT_FAILED diff --git a/tests/core/full_node/test_performance.py b/tests/core/full_node/test_performance.py index 46f81377a2ff..45484b5f493c 100644 --- a/tests/core/full_node/test_performance.py +++ b/tests/core/full_node/test_performance.py @@ -17,7 +17,7 @@ from chia.types.condition_with_args import ConditionWithArgs from chia.types.unfinished_block import UnfinishedBlock from chia.util.clvm import int_to_bytes from chia.util.ints import uint64 -from tests.wallet_tools import WalletTool +from chia.util.wallet_tools import WalletTool from tests.core.fixtures import empty_blockchain # noqa: F401 from tests.connection_utils import add_dummy_connection, connect_and_get_peer diff --git a/tests/core/ssl/test_ssl.py b/tests/core/ssl/test_ssl.py index ea9f9cdfbd73..79423650e93c 100644 --- a/tests/core/ssl/test_ssl.py +++ b/tests/core/ssl/test_ssl.py @@ -9,7 +9,7 @@ from chia.server.server import ChiaServer, ssl_context_for_client from chia.server.ws_connection import WSChiaConnection from chia.ssl.create_ssl import generate_ca_signed_cert from chia.types.peer_info import PeerInfo -from tests.block_tools import test_constants +from chia.util.block_tools import test_constants from chia.util.ints import uint16 from tests.setup_nodes import ( bt, diff --git a/tests/core/test_farmer_harvester_rpc.py b/tests/core/test_farmer_harvester_rpc.py index af82aa928df4..599037735b17 100644 --- a/tests/core/test_farmer_harvester_rpc.py +++ b/tests/core/test_farmer_harvester_rpc.py @@ -16,7 +16,7 @@ from chia.rpc.harvester_rpc_client import HarvesterRpcClient from chia.rpc.rpc_server import start_rpc_server from chia.types.blockchain_format.sized_bytes import bytes32 from chia.util.bech32m import decode_puzzle_hash, encode_puzzle_hash -from tests.block_tools import get_plot_dir +from chia.util.block_tools import get_plot_dir from chia.util.byte_types import hexstr_to_bytes from chia.util.config import load_config, save_config from chia.util.hash import std_hash diff --git a/tests/core/test_full_node_rpc.py b/tests/core/test_full_node_rpc.py index d65ae69173b0..5b06080ef0f6 100644 --- a/tests/core/test_full_node_rpc.py +++ b/tests/core/test_full_node_rpc.py @@ -16,7 +16,7 @@ from chia.types.unfinished_block import UnfinishedBlock from chia.util.block_tools import get_signage_point from chia.util.hash import std_hash from chia.util.ints import uint16, uint8 -from tests.wallet_tools import WalletTool +from chia.util.wallet_tools import WalletTool from tests.connection_utils import connect_and_get_peer from tests.setup_nodes import bt, self_hostname, setup_simulators_and_wallets, test_constants from tests.time_out_assert import time_out_assert diff --git a/tests/setup_nodes.py b/tests/setup_nodes.py index b28fe158a160..c72946cba1e4 100644 --- a/tests/setup_nodes.py +++ b/tests/setup_nodes.py @@ -18,7 +18,7 @@ from chia.simulator.start_simulator import service_kwargs_for_full_node_simulato from chia.timelord.timelord_launcher import kill_processes, spawn_process from chia.types.peer_info import PeerInfo from chia.util.bech32m import encode_puzzle_hash -from tests.block_tools import BlockTools, test_constants +from chia.util.block_tools import BlockTools, test_constants from chia.util.hash import std_hash from chia.util.ints import uint16, uint32 from chia.util.keychain import Keychain, bytes_to_mnemonic diff --git a/tests/simulation/test_simulation.py b/tests/simulation/test_simulation.py index d125137e6897..01335bf3027f 100644 --- a/tests/simulation/test_simulation.py +++ b/tests/simulation/test_simulation.py @@ -1,7 +1,7 @@ import pytest from chia.types.peer_info import PeerInfo -from tests.block_tools import BlockTools +from chia.util.block_tools import BlockTools from chia.util.ints import uint16 from tests.core.node_height import node_height_at_least from tests.setup_nodes import self_hostname, setup_full_node, setup_full_system, test_constants diff --git a/tests/util/benchmark_cost.py b/tests/util/benchmark_cost.py index 417467917a5f..412d6ddfe27f 100644 --- a/tests/util/benchmark_cost.py +++ b/tests/util/benchmark_cost.py @@ -9,7 +9,7 @@ from chia.types.blockchain_format.program import Program, INFINITE_COST from chia.types.condition_opcodes import ConditionOpcode from chia.types.condition_with_args import ConditionWithArgs from chia.util.ints import uint32 -from tests.wallet_tools import WalletTool +from chia.util.wallet_tools import WalletTool from chia.wallet.derive_keys import master_sk_to_wallet_sk from chia.wallet.puzzles.p2_delegated_puzzle import puzzle_for_pk diff --git a/tests/util/key_tool.py b/tests/util/key_tool.py index 14e96c7a8e6d..4914f1659787 100644 --- a/tests/util/key_tool.py +++ b/tests/util/key_tool.py @@ -6,7 +6,7 @@ from chia.types.blockchain_format.sized_bytes import bytes32 from chia.types.coin_solution import CoinSolution from chia.util.condition_tools import conditions_by_opcode, conditions_for_solution, pkm_pairs_for_conditions_dict from tests.core.make_block_generator import GROUP_ORDER, int_to_public_key -from tests.block_tools import test_constants +from chia.util.block_tools import test_constants class KeyTool(dict): diff --git a/tests/wallet/cc_wallet/test_trades.py b/tests/wallet/cc_wallet/test_trades.py index 583a90d00924..f8bb1d1f6fa0 100644 --- a/tests/wallet/cc_wallet/test_trades.py +++ b/tests/wallet/cc_wallet/test_trades.py @@ -1,4 +1,5 @@ import asyncio +import time from pathlib import Path from secrets import token_bytes @@ -11,8 +12,6 @@ from chia.wallet.cc_wallet.cc_wallet import CCWallet from chia.wallet.trade_manager import TradeManager from chia.wallet.trading.trade_status import TradeStatus from tests.setup_nodes import setup_simulators_and_wallets -from tests.time_out_assert import time_out_assert -from tests.wallet.sync.test_wallet_sync import wallet_height_at_least @pytest.fixture(scope="module") @@ -21,6 +20,19 @@ def event_loop(): yield loop +async def time_out_assert(timeout: int, function, value, arg=None): + start = time.time() + while time.time() - start < timeout: + if arg is None: + function_result = await function() + else: + function_result = await function(arg) + if value == function_result: + return None + await asyncio.sleep(2) + assert False + + @pytest.fixture(scope="module") async def two_wallet_nodes(): async for _ in setup_simulators_and_wallets(1, 2, {}): @@ -74,7 +86,7 @@ class TestCCTrades: for i in range(1, buffer_blocks): await full_node.farm_new_transaction_block(FarmNewBlockProtocol(token_bytes())) - await time_out_assert(15, wallet_height_at_least, True, wallet_node_0, 27) + await time_out_assert(15, cc_wallet.get_confirmed_balance, 100) await time_out_assert(15, cc_wallet.get_unconfirmed_balance, 100) @@ -89,14 +101,13 @@ class TestCCTrades: for i in range(0, buffer_blocks): await full_node.farm_new_transaction_block(FarmNewBlockProtocol(token_bytes())) - await time_out_assert(15, wallet_height_at_least, True, wallet_node_0, 31) + # send cc_wallet 2 a coin cc_hash = await cc_wallet_2.get_new_inner_hash() tx_record = await cc_wallet.generate_signed_transaction([uint64(1)], [cc_hash]) await wallet_0.wallet_state_manager.add_pending_transaction(tx_record) for i in range(0, buffer_blocks): await full_node.farm_new_transaction_block(FarmNewBlockProtocol(token_bytes())) - await time_out_assert(15, wallet_height_at_least, True, wallet_node_0, 35) trade_manager_0 = wallet_node_0.wallet_state_manager.trade_manager trade_manager_1 = wallet_node_1.wallet_state_manager.trade_manager @@ -130,7 +141,6 @@ class TestCCTrades: for i in range(0, buffer_blocks): await full_node.farm_new_transaction_block(FarmNewBlockProtocol(token_bytes())) - await time_out_assert(15, wallet_height_at_least, True, wallet_node_0, 39) await time_out_assert(15, cc_wallet_2.get_confirmed_balance, 31) await time_out_assert(15, cc_wallet_2.get_unconfirmed_balance, 31) trade_2 = await trade_manager_0.get_trade_by_id(trade_offer.trade_id) diff --git a/tests/wallet/rl_wallet/test_rl_rpc.py b/tests/wallet/rl_wallet/test_rl_rpc.py index 2507b81d28ca..d1491b41516c 100644 --- a/tests/wallet/rl_wallet/test_rl_rpc.py +++ b/tests/wallet/rl_wallet/test_rl_rpc.py @@ -13,7 +13,6 @@ from chia.util.ints import uint16 from chia.wallet.util.wallet_types import WalletType from tests.setup_nodes import self_hostname, setup_simulators_and_wallets from tests.time_out_assert import time_out_assert -from tests.wallet.sync.test_wallet_sync import wallet_height_at_least @pytest.fixture(scope="module") @@ -158,7 +157,7 @@ class TestRLWallet: await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"\0")) await time_out_assert(15, check_balance, 90, api_user, user_wallet_id) await time_out_assert(15, receiving_wallet.get_spendable_balance, 108) - await time_out_assert(15, wallet_height_at_least, True, wallet_node, 72) + val = await api_admin.send_clawback_transaction({"wallet_id": admin_wallet_id, "fee": 11}) await time_out_assert(15, is_transaction_in_mempool, True, api_admin, val["transaction_id"]) for i in range(0, num_blocks): diff --git a/tests/weight_proof/test_weight_proof.py b/tests/weight_proof/test_weight_proof.py index 7f2f9301e42a..2fcb12b7e29c 100644 --- a/tests/weight_proof/test_weight_proof.py +++ b/tests/weight_proof/test_weight_proof.py @@ -18,7 +18,7 @@ from chia.server.start_full_node import SERVICE_NAME from chia.types.blockchain_format.sized_bytes import bytes32 from chia.types.blockchain_format.sub_epoch_summary import SubEpochSummary from chia.util.block_cache import BlockCache -from tests.block_tools import test_constants +from chia.util.block_tools import test_constants from chia.util.config import load_config from chia.util.default_root import DEFAULT_ROOT_PATH from chia.util.generator_tools import get_block_header