This commit is contained in:
arty 2021-06-21 18:58:35 -07:00
commit 23a1e688c5
No known key found for this signature in database
GPG Key ID: 089F5591892F88F0
34 changed files with 489 additions and 324 deletions

View File

@ -44,6 +44,16 @@ 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 \
@ -82,10 +92,12 @@ 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 }}
@ -93,6 +105,7 @@ 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/
@ -105,13 +118,25 @@ 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: Upload Release Files
- 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/')
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_scrpits/final_installer
sudo rm -rf build_scripts/final_installer

View File

@ -78,6 +78,16 @@ 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 }}
@ -107,6 +117,7 @@ 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 }}
@ -114,6 +125,7 @@ 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: |
@ -132,10 +144,29 @@ 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: Upload Release Files
- 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/')
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/

View File

@ -146,9 +146,20 @@ 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/

View File

@ -113,10 +113,12 @@ 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 }}
@ -124,6 +126,7 @@ 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: |
@ -138,11 +141,23 @@ 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: Upload Release Files
- 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/')
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/

View File

@ -111,11 +111,19 @@ 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/')
condition: contains(variables['build.sourceBranch'], 'refs/tags/')

@ -1 +1 @@
Subproject commit 725071236eff8c81d5b267dc8eb69d7e03f3df8c
Subproject commit 444c6966fe50183c8d72cbc972c5403db341739c

View File

@ -1761,9 +1761,10 @@ 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))
@ -1798,11 +1799,12 @@ 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:
self.log.debug("did not replace any proof, vdf does not match")
return
continue
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))
@ -1811,7 +1813,10 @@ class FullNode:
):
return None
async with self.blockchain.compact_proof_lock:
await self._replace_proof(request.vdf_info, request.vdf_proof, request.height, field_vdf)
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
msg = make_msg(
ProtocolMessageTypes.new_compact_vdf,
full_node_protocol.NewCompactVDF(request.height, request.header_hash, request.field_vdf, request.vdf_info),
@ -1890,7 +1895,10 @@ class FullNode:
async with self.blockchain.compact_proof_lock:
if self.blockchain.seen_compact_proofs(request.vdf_info, request.height):
return None
await self._replace_proof(request.vdf_info, request.vdf_proof, request.height, field_vdf)
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
msg = make_msg(
ProtocolMessageTypes.new_compact_vdf,
full_node_protocol.NewCompactVDF(request.height, request.header_hash, request.field_vdf, request.vdf_info),

View File

@ -25,6 +25,7 @@ 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
@ -211,6 +212,8 @@ 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,
},
}

View File

@ -8,7 +8,6 @@ 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
@ -81,6 +80,8 @@ 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"

View File

@ -1,5 +1,5 @@
if __name__ == "__main__":
from chia.util.block_tools import BlockTools, test_constants
from tests.block_tools import BlockTools, test_constants
from chia.util.default_root import DEFAULT_ROOT_PATH
# TODO: mariano: fix this with new consensus

View File

@ -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 chia.util.block_tools import BlockTools, test_constants
from tests.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

View File

@ -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

View File

@ -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 chia.util.wallet_tools import WalletTool
from tests.wallet_tools import WalletTool
from chia.wallet.derive_keys import (
master_sk_to_farmer_sk,
master_sk_to_local_sk,

View File

@ -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 chia.util.block_tools import BlockTools, get_vdf_info_and_proof
from tests.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 chia.util.wallet_tools import WalletTool
from tests.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

View File

@ -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 chia.util.wallet_tools import WalletTool
from tests.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

View File

@ -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 chia.util.block_tools import BlockTools
from tests.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

View File

@ -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.warning(f"full node height {full_node_2.full_node.blockchain.get_peak().height}")
assert node_height_between(full_node_2, 320, 400)
log.info(f"full node height {full_node_2.full_node.blockchain.get_peak().height}")
assert node_height_exactly(full_node_2, 320)

View File

@ -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 chia.util.wallet_tools import WalletTool
from tests.wallet_tools import WalletTool
from chia.util.db_wrapper import DBWrapper
from tests.setup_nodes import bt, test_constants

View File

@ -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 chia.util.block_tools import BlockTools, test_constants
from tests.block_tools import BlockTools, test_constants
from chia.util.errors import Err
from chia.util.ints import uint32

View File

@ -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 chia.util.block_tools import get_signage_point
from tests.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 chia.util.wallet_tools import WalletTool
from tests.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

View File

@ -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 chia.util.block_tools import get_signage_point, BlockTools
from tests.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

View File

@ -1,11 +1,14 @@
import asyncio
import logging
from time import time
from typing import Dict, List, Optional
from typing import Dict, List, Optional, Tuple, Callable
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
@ -18,6 +21,9 @@ 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
@ -95,6 +101,29 @@ 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):
@ -149,7 +178,9 @@ class TestMempoolManager:
assert spend_bundle1 is not None
tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(spend_bundle1)
await full_node_1.respond_transaction(tx1, peer)
status, err = await respond_transaction(full_node_1, tx1, peer)
assert status == MempoolInclusionStatus.SUCCESS
assert err is None
spend_bundle2 = generate_test_spend_bundle(
list(blocks[-1].get_included_reward_coins())[0],
@ -157,13 +188,15 @@ class TestMempoolManager:
)
assert spend_bundle2 is not None
tx2: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(spend_bundle2)
await full_node_1.respond_transaction(tx2, peer)
status, err = await respond_transaction(full_node_1, 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)
@ -293,8 +326,38 @@ class TestMempoolManager:
tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(spend_bundle1)
await full_node_1.respond_transaction(tx1, peer)
return blocks, spend_bundle1, peer
status, err = await respond_transaction(full_node_1, tx1, peer)
return blocks, spend_bundle1, peer, status, err
@pytest.mark.asyncio
async def condition_tester2(self, two_nodes, test_fun: Callable[[Coin, Coin], SpendBundle]):
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)
for block in blocks:
await full_node_1.full_node.respond_block(full_node_protocol.RespondBlock(block))
await time_out_assert(60, node_height_at_least, True, full_node_1, start_height + 3)
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)
tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(bundle)
status, err = await respond_transaction(full_node_1, tx1, peer)
return blocks, bundle, status, err
@pytest.mark.asyncio
async def test_invalid_block_index(self, two_nodes):
@ -304,46 +367,78 @@ class TestMempoolManager:
start_height = blocks[-1].height
cvp = ConditionWithArgs(
ConditionOpcode.ASSERT_HEIGHT_ABSOLUTE,
[uint64(start_height + 5).to_bytes(4, "big")],
[int_to_bytes(start_height + 5)],
)
dic = {ConditionOpcode.ASSERT_HEIGHT_ABSOLUTE: [cvp]}
blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic)
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, [uint64(1).to_bytes(4, "big")])
cvp = ConditionWithArgs(ConditionOpcode.ASSERT_HEIGHT_ABSOLUTE, [int_to_bytes(1)])
dic = {ConditionOpcode.ASSERT_HEIGHT_ABSOLUTE: [cvp]}
blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic)
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, [uint64(5).to_bytes(4, "big")])
cvp = ConditionWithArgs(ConditionOpcode.ASSERT_HEIGHT_RELATIVE, [int_to_bytes(5)])
dic = {cvp.opcode: [cvp]}
blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic)
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, [uint64(1).to_bytes(4, "big")])
cvp = ConditionWithArgs(ConditionOpcode.ASSERT_HEIGHT_RELATIVE, [int_to_bytes(1)])
dic = {cvp.opcode: [cvp]}
blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic, num_blocks=4)
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):
@ -353,11 +448,12 @@ class TestMempoolManager:
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)
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):
@ -368,133 +464,130 @@ class TestMempoolManager:
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)
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
time_now = uint64(int(time()))
# 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, [time_now.to_bytes(8, "big")])
cvp = ConditionWithArgs(ConditionOpcode.ASSERT_SECONDS_ABSOLUTE, [int_to_bytes(time_now)])
dic = {cvp.opcode: [cvp]}
blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic)
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 = uint64(3)
time_relative = 3
cvp = ConditionWithArgs(ConditionOpcode.ASSERT_SECONDS_RELATIVE, [time_relative.to_bytes(8, "big")])
cvp = ConditionWithArgs(ConditionOpcode.ASSERT_SECONDS_RELATIVE, [int_to_bytes(time_relative)])
dic = {cvp.opcode: [cvp]}
blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic)
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)
await full_node_1.respond_transaction(tx2, peer)
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):
reward_ph = WALLET_A.get_new_puzzlehash()
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 = 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)
for block in blocks:
await full_node_1.full_node.respond_block(full_node_protocol.RespondBlock(block))
await time_out_assert(60, node_height_at_least, True, full_node_1, start_height + 3)
coin_1 = list(blocks[-2].get_included_reward_coins())[0]
coin_2 = list(blocks[-1].get_included_reward_coins())[0]
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)
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 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)
for block in blocks:
await full_node_1.full_node.respond_block(full_node_protocol.RespondBlock(block))
def test_fun(coin_1: Coin, coin_2: Coin):
announce = Announcement(coin_2.name(), bytes([1] * 10000))
await time_out_assert(60, node_height_at_least, True, full_node_1, start_height + 3)
cvp = ConditionWithArgs(ConditionOpcode.ASSERT_COIN_ANNOUNCEMENT, [announce.name()])
coin_1 = list(blocks[-2].get_included_reward_coins())[0]
coin_2 = list(blocks[-1].get_included_reward_coins())[0]
dic = {cvp.opcode: [cvp]}
announce = Announcement(coin_2.name(), bytes([1] * 10000))
cvp2 = ConditionWithArgs(ConditionOpcode.CREATE_COIN_ANNOUNCEMENT, [b"test"])
dic2 = {cvp.opcode: [cvp2]}
spend_bundle1 = generate_test_spend_bundle(coin_1, dic)
cvp = ConditionWithArgs(ConditionOpcode.ASSERT_COIN_ANNOUNCEMENT, [announce.name()])
spend_bundle2 = generate_test_spend_bundle(coin_2, dic2)
dic = {cvp.opcode: [cvp]}
return SpendBundle.aggregate([spend_bundle1, spend_bundle2])
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)
blocks, bundle, status, err = await self.condition_tester2(two_nodes, test_fun)
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
@ -507,236 +600,150 @@ 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)
for block in blocks:
await full_node_1.full_node.respond_block(full_node_protocol.RespondBlock(block))
def test_fun(coin_1: Coin, coin_2: Coin):
announce = Announcement(coin_2.name(), b"test")
await time_out_assert(60, node_height_at_least, True, full_node_1, start_height + 3)
cvp = ConditionWithArgs(ConditionOpcode.ASSERT_COIN_ANNOUNCEMENT, [announce.name()])
coin_1 = list(blocks[-2].get_included_reward_coins())[0]
coin_2 = list(blocks[-1].get_included_reward_coins())[0]
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)
announce = Announcement(coin_2.name(), bytes("test", "utf-8"))
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]}
# 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)
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_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)
for block in blocks:
await full_node_1.full_node.respond_block(full_node_protocol.RespondBlock(block))
def test_fun(coin_1: Coin, coin_2: Coin):
announce = Announcement(coin_1.name(), b"test")
await time_out_assert(60, node_height_at_least, True, full_node_1, start_height + 3)
cvp = ConditionWithArgs(ConditionOpcode.ASSERT_COIN_ANNOUNCEMENT, [announce.name()])
coin_1 = list(blocks[-2].get_included_reward_coins())[0]
coin_2 = list(blocks[-1].get_included_reward_coins())[0]
dic = {cvp.opcode: [cvp]}
announce = Announcement(coin_1.name(), bytes("test", "utf-8"))
cvp2 = ConditionWithArgs(
ConditionOpcode.CREATE_COIN_ANNOUNCEMENT,
[b"test"],
)
dic2 = {cvp.opcode: [cvp2]}
spend_bundle1 = generate_test_spend_bundle(coin_1, dic)
cvp = ConditionWithArgs(ConditionOpcode.ASSERT_COIN_ANNOUNCEMENT, [announce.name()])
# coin 2 is making the announcement, right message wrong coin
spend_bundle2 = generate_test_spend_bundle(coin_2, dic2)
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)
return SpendBundle.aggregate([spend_bundle1, spend_bundle2])
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)
for block in blocks:
await full_node_1.full_node.respond_block(full_node_protocol.RespondBlock(block))
def test_fun(coin_1: Coin, coin_2: Coin):
announce = Announcement(coin_2.puzzle_hash, bytes(0x80))
await time_out_assert(60, node_height_at_least, True, full_node_1, start_height + 3)
cvp = ConditionWithArgs(ConditionOpcode.ASSERT_PUZZLE_ANNOUNCEMENT, [announce.name()])
coin_1 = list(blocks[-2].get_included_reward_coins())[0]
coin_2 = list(blocks[-1].get_included_reward_coins())[0]
dic = {cvp.opcode: [cvp]}
announce = Announcement(coin_2.puzzle_hash, bytes(0x80))
cvp2 = ConditionWithArgs(ConditionOpcode.CREATE_PUZZLE_ANNOUNCEMENT, [bytes(0x80)])
dic2 = {cvp.opcode: [cvp2]}
spend_bundle1 = generate_test_spend_bundle(coin_1, dic)
cvp = ConditionWithArgs(ConditionOpcode.ASSERT_PUZZLE_ANNOUNCEMENT, [announce.name()])
spend_bundle2 = generate_test_spend_bundle(coin_2, dic2)
dic = {cvp.opcode: [cvp]}
return SpendBundle.aggregate([spend_bundle1, spend_bundle2])
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)
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_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)
for block in blocks:
await full_node_1.full_node.respond_block(full_node_protocol.RespondBlock(block))
def test_fun(coin_1: Coin, coin_2: Coin):
announce = Announcement(coin_2.puzzle_hash, bytes("test", "utf-8"))
await time_out_assert(60, node_height_at_least, True, full_node_1, start_height + 3)
cvp = ConditionWithArgs(ConditionOpcode.ASSERT_PUZZLE_ANNOUNCEMENT, [announce.name()])
coin_1 = list(blocks[-2].get_included_reward_coins())[0]
coin_2 = list(blocks[-1].get_included_reward_coins())[0]
dic = {cvp.opcode: [cvp]}
announce = Announcement(coin_2.puzzle_hash, bytes("test", "utf-8"))
cvp2 = ConditionWithArgs(
ConditionOpcode.CREATE_PUZZLE_ANNOUNCEMENT,
[b"wrong test"],
)
dic2 = {cvp.opcode: [cvp2]}
spend_bundle1 = generate_test_spend_bundle(coin_1, dic)
cvp = ConditionWithArgs(ConditionOpcode.ASSERT_PUZZLE_ANNOUNCEMENT, [announce.name()])
spend_bundle2 = generate_test_spend_bundle(coin_2, dic2)
dic = {cvp.opcode: [cvp]}
return SpendBundle.aggregate([spend_bundle1, spend_bundle2])
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)
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_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)
for block in blocks:
await full_node_1.full_node.respond_block(full_node_protocol.RespondBlock(block))
def test_fun(coin_1: Coin, coin_2: Coin):
announce = Announcement(coin_2.puzzle_hash, b"test")
await time_out_assert(60, node_height_at_least, True, full_node_1, start_height + 3)
cvp = ConditionWithArgs(ConditionOpcode.ASSERT_PUZZLE_ANNOUNCEMENT, [announce.name()])
coin_1 = list(blocks[-2].get_included_reward_coins())[0]
coin_2 = list(blocks[-1].get_included_reward_coins())[0]
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)
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]}
# 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)
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_assert_fee_condition(self, two_nodes):
@ -744,17 +751,35 @@ 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 = await self.condition_tester(two_nodes, dic, fee=10)
blocks, spend_bundle1, peer, status, err = 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 = await self.condition_tester(two_nodes, dic, fee=10)
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 = bt.get_consecutive_blocks(
1, block_list_input=blocks, guarantee_transaction_block=True, transaction_data=spend_bundle1
)
@ -768,10 +793,12 @@ class TestMempoolManager:
cvp = ConditionWithArgs(ConditionOpcode.RESERVE_FEE, [int_to_bytes(10)])
dic = {cvp.opcode: [cvp]}
blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic, fee=9)
blocks, spend_bundle1, peer, status, err = 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):
@ -822,11 +849,13 @@ class TestMempoolManager:
tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(spend_bundle1)
await full_node_1.respond_transaction(tx1, peer)
status, err = await respond_transaction(full_node_1, 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):
@ -863,10 +892,12 @@ class TestMempoolManager:
tx: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(spend_bundle_combined)
await full_node_1.respond_transaction(tx, peer)
status, err = await respond_transaction(full_node_1, 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):
@ -926,11 +957,13 @@ 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 = await self.condition_tester(two_nodes, dic, coin=coin)
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_parent(self, two_nodes):
@ -941,11 +974,13 @@ 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 = await self.condition_tester(two_nodes, dic, coin=coin)
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_PARENT_ID_FAILED
@pytest.mark.asyncio
async def test_correct_my_puzhash(self, two_nodes):
@ -955,11 +990,13 @@ 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 = await self.condition_tester(two_nodes, dic, coin=coin)
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_puzhash(self, two_nodes):
@ -969,11 +1006,13 @@ 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 = await self.condition_tester(two_nodes, dic, coin=coin)
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_PUZZLEHASH_FAILED
@pytest.mark.asyncio
async def test_correct_my_amount(self, two_nodes):
@ -981,24 +1020,57 @@ 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, [coin.amount])
cvp = ConditionWithArgs(ConditionOpcode.ASSERT_MY_AMOUNT, [int_to_bytes(coin.amount)])
dic = {cvp.opcode: [cvp]}
blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic, coin=coin)
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_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()
coin = list(blocks[-1].get_included_reward_coins())[0]
cvp = ConditionWithArgs(ConditionOpcode.ASSERT_MY_AMOUNT, [1000])
cvp = ConditionWithArgs(ConditionOpcode.ASSERT_MY_AMOUNT, [int_to_bytes(1000)])
dic = {cvp.opcode: [cvp]}
blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic, coin=coin)
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_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

View File

@ -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 chia.util.wallet_tools import WalletTool
from tests.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

View File

@ -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 chia.util.block_tools import test_constants
from tests.block_tools import test_constants
from chia.util.ints import uint16
from tests.setup_nodes import (
bt,

View File

@ -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 chia.util.block_tools import get_plot_dir
from tests.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

View File

@ -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 chia.util.wallet_tools import WalletTool
from tests.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

View File

@ -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 chia.util.block_tools import BlockTools, test_constants
from tests.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

View File

@ -1,7 +1,7 @@
import pytest
from chia.types.peer_info import PeerInfo
from chia.util.block_tools import BlockTools
from tests.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

View File

@ -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 chia.util.wallet_tools import WalletTool
from tests.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

View File

@ -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 chia.util.block_tools import test_constants
from tests.block_tools import test_constants
class KeyTool(dict):

View File

@ -1,5 +1,4 @@
import asyncio
import time
from pathlib import Path
from secrets import token_bytes
@ -12,6 +11,8 @@ 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")
@ -20,19 +21,6 @@ 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, {}):
@ -86,7 +74,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)
@ -101,13 +89,14 @@ 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
@ -141,6 +130,7 @@ 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)

View File

@ -13,6 +13,7 @@ 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")
@ -157,7 +158,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):

View File

@ -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 chia.util.block_tools import test_constants
from tests.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