mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2025-01-06 04:07:16 +03:00
add SizedBytes.random()
/.secret()
, replace token_bytes()
usage (#16276)
This commit is contained in:
parent
b9475bdf09
commit
cd9d6eff33
@ -8,7 +8,6 @@ import time
|
||||
import traceback
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from datetime import datetime, timezone
|
||||
from secrets import token_bytes
|
||||
from typing import TYPE_CHECKING, Dict, List, Optional, Set, Tuple
|
||||
|
||||
from blspy import AugSchemeMPL, G1Element, G2Element
|
||||
@ -215,7 +214,7 @@ class FullNodeAPI:
|
||||
if task_id in full_node.full_node_store.tx_fetch_tasks:
|
||||
full_node.full_node_store.tx_fetch_tasks.pop(task_id)
|
||||
|
||||
task_id: bytes32 = bytes32(token_bytes(32))
|
||||
task_id: bytes32 = bytes32.secret()
|
||||
fetch_task = asyncio.create_task(
|
||||
tx_request_and_timeout(self.full_node, transaction.transaction_id, task_id)
|
||||
)
|
||||
|
@ -3,7 +3,6 @@ from __future__ import annotations
|
||||
import logging
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from secrets import token_bytes
|
||||
from typing import Dict, List, Optional, Tuple
|
||||
|
||||
from blspy import AugSchemeMPL, G1Element, PrivateKey
|
||||
@ -191,7 +190,7 @@ async def create_plots(
|
||||
assert len(test_private_keys) == num
|
||||
sk: PrivateKey = test_private_keys[i]
|
||||
else:
|
||||
sk = AugSchemeMPL.key_gen(token_bytes(32))
|
||||
sk = AugSchemeMPL.key_gen(bytes32.secret())
|
||||
|
||||
# The plot public key is the combination of the harvester and farmer keys
|
||||
# New plots will also include a taproot of the keys, for extensibility
|
||||
|
@ -6,7 +6,6 @@ import math
|
||||
import time
|
||||
import traceback
|
||||
from dataclasses import dataclass, field
|
||||
from secrets import token_bytes
|
||||
from typing import Any, Awaitable, Callable, Dict, List, Optional, Set, Tuple, Union
|
||||
|
||||
from aiohttp import ClientSession, WSCloseCode, WSMessage, WSMsgType
|
||||
@ -457,7 +456,7 @@ class WSChiaConnection:
|
||||
async def incoming_message_handler(self) -> None:
|
||||
while True:
|
||||
message = await self.incoming_queue.get()
|
||||
task_id: bytes32 = bytes32(token_bytes(32))
|
||||
task_id: bytes32 = bytes32.secret()
|
||||
api_task = asyncio.create_task(self._api_call(message, task_id))
|
||||
self.api_tasks[task_id] = api_task
|
||||
|
||||
|
@ -8,7 +8,6 @@ import sqlite3
|
||||
import time
|
||||
from contextlib import asynccontextmanager, contextmanager
|
||||
from pathlib import Path
|
||||
from secrets import token_bytes
|
||||
from types import FrameType
|
||||
from typing import Any, AsyncGenerator, Dict, Iterator, List, Optional, Tuple, Union
|
||||
|
||||
@ -44,6 +43,7 @@ from chia.ssl.create_ssl import create_all_ssl
|
||||
from chia.timelord.timelord import Timelord
|
||||
from chia.timelord.timelord_api import TimelordAPI
|
||||
from chia.timelord.timelord_launcher import kill_processes, spawn_process
|
||||
from chia.types.blockchain_format.sized_bytes import bytes32
|
||||
from chia.types.peer_info import UnresolvedPeerInfo
|
||||
from chia.util.bech32m import encode_puzzle_hash
|
||||
from chia.util.config import config_path_for_filename, load_config, lock_and_load_config, save_config
|
||||
@ -281,7 +281,7 @@ async def setup_wallet_node(
|
||||
service_config["spam_filter_after_n_txs"] = spam_filter_after_n_txs
|
||||
service_config["xch_spam_amount"] = xch_spam_amount
|
||||
|
||||
entropy = token_bytes(32)
|
||||
entropy = bytes32.secret()
|
||||
if key_seed is None:
|
||||
key_seed = entropy
|
||||
keychain.add_private_key(bytes_to_mnemonic(key_seed))
|
||||
|
@ -1,6 +1,5 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from secrets import token_bytes
|
||||
from typing import Dict, List
|
||||
|
||||
from chia.rpc.full_node_rpc_api import FullNodeRpcApi
|
||||
@ -90,7 +89,7 @@ class SimulatorFullNodeRpcApi(FullNodeRpcApi):
|
||||
new_blocks = int(str(_request.get("num_of_new_blocks", 1))) # how many extra blocks should we add
|
||||
all_blocks = bool(_request.get("revert_all_blocks", False)) # fork all blocks
|
||||
use_random_seed = bool(_request.get("random_seed", True)) # randomize the seed to differentiate reorgs
|
||||
random_seed = bytes32(token_bytes(32)) if use_random_seed else None
|
||||
random_seed = bytes32.secret() if use_random_seed else None
|
||||
cur_height = self.service.blockchain.get_peak_height()
|
||||
if cur_height is None:
|
||||
raise ValueError("No blocks to revert")
|
||||
|
@ -1,11 +1,15 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import BinaryIO, Iterable, SupportsBytes, Type, TypeVar, Union
|
||||
import random
|
||||
import secrets
|
||||
from typing import BinaryIO, Iterable, Optional, SupportsBytes, Type, TypeVar, Union
|
||||
|
||||
from typing_extensions import SupportsIndex
|
||||
|
||||
_T_SizedBytes = TypeVar("_T_SizedBytes", bound="SizedBytes")
|
||||
|
||||
system_random = secrets.SystemRandom()
|
||||
|
||||
|
||||
def hexstr_to_bytes(input_str: str) -> bytes:
|
||||
"""
|
||||
@ -52,6 +56,19 @@ class SizedBytes(bytes):
|
||||
return cls.fromhex(input_str[2:])
|
||||
return cls.fromhex(input_str)
|
||||
|
||||
@classmethod
|
||||
def random(cls: Type[_T_SizedBytes], r: Optional[random.Random] = None) -> _T_SizedBytes:
|
||||
if r is None:
|
||||
getrandbits = random.getrandbits
|
||||
else:
|
||||
getrandbits = r.getrandbits
|
||||
|
||||
return cls(getrandbits(cls._size * 8).to_bytes(cls._size, "big"))
|
||||
|
||||
@classmethod
|
||||
def secret(cls: Type[_T_SizedBytes]) -> _T_SizedBytes:
|
||||
return cls.random(r=system_random)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.hex()
|
||||
|
||||
|
@ -5,7 +5,6 @@ import unicodedata
|
||||
from dataclasses import dataclass
|
||||
from hashlib import pbkdf2_hmac
|
||||
from pathlib import Path
|
||||
from secrets import token_bytes
|
||||
from typing import Any, Dict, List, Optional, Tuple
|
||||
|
||||
import pkg_resources
|
||||
@ -13,6 +12,7 @@ from bitstring import BitArray # pyright: reportMissingImports=false
|
||||
from blspy import AugSchemeMPL, G1Element, PrivateKey # pyright: reportMissingImports=false
|
||||
from typing_extensions import final
|
||||
|
||||
from chia.types.blockchain_format.sized_bytes import bytes32
|
||||
from chia.util.errors import (
|
||||
KeychainException,
|
||||
KeychainFingerprintExists,
|
||||
@ -57,7 +57,7 @@ def bip39_word_list() -> str:
|
||||
|
||||
|
||||
def generate_mnemonic() -> str:
|
||||
mnemonic_bytes = token_bytes(32)
|
||||
mnemonic_bytes = bytes32.secret()
|
||||
mnemonic = bytes_to_mnemonic(mnemonic_bytes)
|
||||
return mnemonic
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from secrets import token_bytes
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
from chia.types.blockchain_format.sized_bytes import bytes32
|
||||
from chia.util.json_util import dict_to_json_str
|
||||
|
||||
# Messages must follow this format
|
||||
@ -55,7 +55,7 @@ def create_payload_dict(command: str, data: Optional[Dict[str, Any]], origin: st
|
||||
command=command,
|
||||
ack=False,
|
||||
data=data,
|
||||
request_id=token_bytes().hex(),
|
||||
request_id=bytes32.secret().hex(),
|
||||
destination=destination,
|
||||
origin=origin,
|
||||
)
|
||||
|
@ -4,7 +4,6 @@ import dataclasses
|
||||
import logging
|
||||
import time
|
||||
import traceback
|
||||
from secrets import token_bytes
|
||||
from typing import TYPE_CHECKING, Any, ClassVar, Dict, List, Optional, Set, Tuple, cast
|
||||
|
||||
from blspy import AugSchemeMPL, G1Element, G2Element
|
||||
@ -169,7 +168,7 @@ class CATWallet:
|
||||
sent_to=[],
|
||||
trade_id=None,
|
||||
type=uint32(TransactionType.INCOMING_TX.value),
|
||||
name=bytes32(token_bytes()),
|
||||
name=bytes32.secret(),
|
||||
memos=[],
|
||||
valid_times=ConditionValidTimes(),
|
||||
)
|
||||
|
@ -5,7 +5,6 @@ import json
|
||||
import logging
|
||||
import re
|
||||
import time
|
||||
from secrets import token_bytes
|
||||
from typing import TYPE_CHECKING, Any, ClassVar, Dict, List, Optional, Set, Tuple, cast
|
||||
|
||||
from blspy import AugSchemeMPL, G1Element, G2Element
|
||||
@ -616,7 +615,7 @@ class DIDWallet:
|
||||
sent_to=[],
|
||||
trade_id=None,
|
||||
type=uint32(TransactionType.OUTGOING_TX.value),
|
||||
name=bytes32(token_bytes()),
|
||||
name=bytes32.secret(),
|
||||
memos=list(compute_memos(spend_bundle).items()),
|
||||
valid_times=parse_timelock_info(extra_conditions),
|
||||
)
|
||||
@ -713,7 +712,7 @@ class DIDWallet:
|
||||
sent_to=[],
|
||||
trade_id=None,
|
||||
type=uint32(TransactionType.OUTGOING_TX.value),
|
||||
name=bytes32(token_bytes()),
|
||||
name=bytes32.secret(),
|
||||
memos=list(compute_memos(spend_bundle).items()),
|
||||
valid_times=parse_timelock_info(extra_conditions),
|
||||
)
|
||||
@ -834,7 +833,7 @@ class DIDWallet:
|
||||
sent_to=[],
|
||||
trade_id=None,
|
||||
type=uint32(TransactionType.OUTGOING_TX.value),
|
||||
name=bytes32(token_bytes()),
|
||||
name=bytes32.secret(),
|
||||
memos=list(compute_memos(spend_bundle).items()),
|
||||
valid_times=ConditionValidTimes(),
|
||||
)
|
||||
@ -916,7 +915,7 @@ class DIDWallet:
|
||||
sent_to=[],
|
||||
trade_id=None,
|
||||
type=uint32(TransactionType.INCOMING_TX.value),
|
||||
name=bytes32(token_bytes()),
|
||||
name=bytes32.secret(),
|
||||
memos=list(compute_memos(spend_bundle).items()),
|
||||
valid_times=parse_timelock_info(extra_conditions),
|
||||
)
|
||||
@ -1045,7 +1044,7 @@ class DIDWallet:
|
||||
sent_to=[],
|
||||
trade_id=None,
|
||||
type=uint32(TransactionType.OUTGOING_TX.value),
|
||||
name=bytes32(token_bytes()),
|
||||
name=bytes32.secret(),
|
||||
memos=list(compute_memos(spend_bundle).items()),
|
||||
valid_times=ConditionValidTimes(),
|
||||
)
|
||||
@ -1287,7 +1286,7 @@ class DIDWallet:
|
||||
sent_to=[],
|
||||
trade_id=None,
|
||||
type=uint32(TransactionType.INCOMING_TX.value),
|
||||
name=bytes32(token_bytes()),
|
||||
name=bytes32.secret(),
|
||||
memos=[],
|
||||
valid_times=ConditionValidTimes(),
|
||||
)
|
||||
|
@ -7,7 +7,6 @@ import time
|
||||
import traceback
|
||||
from contextlib import asynccontextmanager
|
||||
from pathlib import Path
|
||||
from secrets import token_bytes
|
||||
from typing import TYPE_CHECKING, Any, AsyncIterator, Callable, Dict, List, Optional, Set, Tuple, Type, TypeVar, Union
|
||||
|
||||
import aiosqlite
|
||||
@ -1562,7 +1561,7 @@ class WalletStateManager:
|
||||
sent_to=[],
|
||||
trade_id=None,
|
||||
type=uint32(tx_type),
|
||||
name=bytes32(token_bytes()),
|
||||
name=bytes32.secret(),
|
||||
memos=[],
|
||||
valid_times=ConditionValidTimes(),
|
||||
)
|
||||
|
@ -3,10 +3,10 @@ from __future__ import annotations
|
||||
import dataclasses
|
||||
import logging
|
||||
import multiprocessing
|
||||
import random
|
||||
import time
|
||||
from contextlib import asynccontextmanager
|
||||
from dataclasses import replace
|
||||
from secrets import token_bytes
|
||||
from typing import List
|
||||
|
||||
import pytest
|
||||
@ -1367,7 +1367,7 @@ class TestBlockHeaderValidation:
|
||||
attempts += 1
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_pool_target_contract(self, empty_blockchain, bt):
|
||||
async def test_pool_target_contract(self, empty_blockchain, bt, seeded_random: random.Random):
|
||||
# 20c invalid pool target with contract
|
||||
blocks_initial = bt.get_consecutive_blocks(2)
|
||||
await _validate_and_add_block(empty_blockchain, blocks_initial[0])
|
||||
@ -1381,7 +1381,7 @@ class TestBlockHeaderValidation:
|
||||
)
|
||||
if blocks[-1].foliage.foliage_block_data.pool_signature is None:
|
||||
block_bad: FullBlock = recursive_replace(
|
||||
blocks[-1], "foliage.foliage_block_data.pool_target.puzzle_hash", bytes32(token_bytes(32))
|
||||
blocks[-1], "foliage.foliage_block_data.pool_target.puzzle_hash", bytes32.random(seeded_random)
|
||||
)
|
||||
new_m = block_bad.foliage.foliage_block_data.get_hash()
|
||||
new_fsb_sig = bt.get_plot_signature(new_m, blocks[-1].reward_chain_block.proof_of_space.plot_public_key)
|
||||
|
@ -72,6 +72,13 @@ from chia.simulator.setup_nodes import setup_farmer_multi_harvester
|
||||
from chia.util.keyring_wrapper import KeyringWrapper
|
||||
|
||||
|
||||
@pytest.fixture(name="seeded_random")
|
||||
def seeded_random_fixture() -> random.Random:
|
||||
seeded_random = random.Random()
|
||||
seeded_random.seed(a=0, version=2)
|
||||
return seeded_random
|
||||
|
||||
|
||||
@pytest.fixture(name="node_name_for_file")
|
||||
def node_name_for_file_fixture(request: SubRequest) -> str:
|
||||
# TODO: handle other characters banned on windows
|
||||
|
@ -1,7 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import random
|
||||
from dataclasses import dataclass
|
||||
from secrets import token_bytes
|
||||
from typing import Optional
|
||||
|
||||
import pytest
|
||||
@ -126,7 +126,7 @@ def test_verify_and_get_quality_string(caplog: pytest.LogCaptureFixture, case: P
|
||||
|
||||
class TestProofOfSpace:
|
||||
@pytest.mark.parametrize("prefix_bits", [DEFAULT_CONSTANTS.NUMBER_ZERO_BITS_PLOT_FILTER, 8, 7, 6, 5, 1, 0])
|
||||
def test_can_create_proof(self, prefix_bits: int) -> None:
|
||||
def test_can_create_proof(self, prefix_bits: int, seeded_random: random.Random) -> None:
|
||||
"""
|
||||
Tests that the change of getting a correct proof is exactly 1/target_filter.
|
||||
"""
|
||||
@ -134,9 +134,9 @@ class TestProofOfSpace:
|
||||
success_count = 0
|
||||
target_filter = 2**prefix_bits
|
||||
for _ in range(num_trials):
|
||||
challenge_hash = bytes32(token_bytes(32))
|
||||
plot_id = bytes32(token_bytes(32))
|
||||
sp_output = bytes32(token_bytes(32))
|
||||
challenge_hash = bytes32.random(seeded_random)
|
||||
plot_id = bytes32.random(seeded_random)
|
||||
sp_output = bytes32.random(seeded_random)
|
||||
|
||||
if passes_plot_filter(prefix_bits, plot_id, challenge_hash, sp_output):
|
||||
success_count += 1
|
||||
|
@ -2,7 +2,7 @@ from __future__ import annotations
|
||||
|
||||
import dataclasses
|
||||
import logging
|
||||
from secrets import token_bytes
|
||||
import random
|
||||
from typing import AsyncIterator, List, Optional
|
||||
|
||||
import pytest
|
||||
@ -77,6 +77,7 @@ class TestFullNodeStore:
|
||||
empty_blockchain: Blockchain,
|
||||
custom_block_tools: BlockTools,
|
||||
normalized_to_identity: bool,
|
||||
seeded_random: random.Random,
|
||||
) -> None:
|
||||
blockchain = empty_blockchain
|
||||
blocks = custom_block_tools.get_consecutive_blocks(
|
||||
@ -119,7 +120,7 @@ class TestFullNodeStore:
|
||||
assert store.get_candidate_block(unfinished_blocks[8].get_hash()) is not None
|
||||
|
||||
# Test seen unfinished blocks
|
||||
h_hash_1 = bytes32(token_bytes(32))
|
||||
h_hash_1 = bytes32.random(seeded_random)
|
||||
assert not store.seen_unfinished_block(h_hash_1)
|
||||
assert store.seen_unfinished_block(h_hash_1)
|
||||
store.clear_seen_unfinished_blocks()
|
||||
|
@ -5,7 +5,6 @@ import dataclasses
|
||||
import logging
|
||||
import random
|
||||
import time
|
||||
from secrets import token_bytes
|
||||
from typing import Dict, List, Optional, Tuple
|
||||
|
||||
import pytest
|
||||
@ -832,7 +831,7 @@ class TestFullNodeProtocol:
|
||||
await time_out_assert(10, time_out_messages(incoming_queue, "request_block", 1))
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_new_transaction_and_mempool(self, wallet_nodes, self_hostname):
|
||||
async def test_new_transaction_and_mempool(self, wallet_nodes, self_hostname, seeded_random: random.Random):
|
||||
full_node_1, full_node_2, server_1, server_2, wallet_a, wallet_receiver, bt = wallet_nodes
|
||||
wallet_ph = wallet_a.get_new_puzzlehash()
|
||||
blocks = bt.get_consecutive_blocks(
|
||||
@ -951,6 +950,7 @@ class TestFullNodeProtocol:
|
||||
assert full_node_1.full_node.mempool_manager.mempool.get_min_fee_rate(10500000 * group_size) > 0
|
||||
assert not force_high_fee
|
||||
not_included_tx += 1
|
||||
assert successful_bundle is not None
|
||||
assert full_node_1.full_node.mempool_manager.mempool.at_full_capacity(10000000 * group_size)
|
||||
|
||||
# these numbers reflect the capacity of the mempool. In these
|
||||
@ -961,7 +961,7 @@ class TestFullNodeProtocol:
|
||||
assert seen_bigger_transaction_has_high_fee
|
||||
|
||||
# Mempool is full
|
||||
new_transaction = fnp.NewTransaction(token_bytes(32), 10000000, uint64(1))
|
||||
new_transaction = fnp.NewTransaction(bytes32.random(seeded_random), uint64(10000000), uint64(1))
|
||||
await full_node_1.new_transaction(new_transaction, fake_peer)
|
||||
assert full_node_1.full_node.mempool_manager.mempool.at_full_capacity(10000000 * group_size)
|
||||
assert full_node_2.full_node.mempool_manager.mempool.at_full_capacity(10000000 * group_size)
|
||||
@ -983,7 +983,7 @@ class TestFullNodeProtocol:
|
||||
await full_node_1.farm_new_transaction_block(FarmNewBlockProtocol(receiver_puzzlehash))
|
||||
|
||||
# No longer full
|
||||
new_transaction = fnp.NewTransaction(token_bytes(32), uint64(1000000), uint64(1))
|
||||
new_transaction = fnp.NewTransaction(bytes32.random(seeded_random), uint64(1000000), uint64(1))
|
||||
await full_node_1.new_transaction(new_transaction, fake_peer)
|
||||
|
||||
# Cannot resubmit transaction, but not because of ALREADY_INCLUDING
|
||||
@ -1013,7 +1013,7 @@ class TestFullNodeProtocol:
|
||||
assert status == MempoolInclusionStatus.SUCCESS
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_request_respond_transaction(self, wallet_nodes, self_hostname):
|
||||
async def test_request_respond_transaction(self, wallet_nodes, self_hostname, seeded_random: random.Random):
|
||||
full_node_1, full_node_2, server_1, server_2, wallet_a, wallet_receiver, bt = wallet_nodes
|
||||
wallet_ph = wallet_a.get_new_puzzlehash()
|
||||
blocks = await full_node_1.get_all_full_blocks()
|
||||
@ -1037,7 +1037,7 @@ class TestFullNodeProtocol:
|
||||
# Farm another block to clear mempool
|
||||
await full_node_1.farm_new_transaction_block(FarmNewBlockProtocol(wallet_ph))
|
||||
|
||||
tx_id = token_bytes(32)
|
||||
tx_id = bytes32.random(seeded_random)
|
||||
request_transaction = fnp.RequestTransaction(tx_id)
|
||||
msg = await full_node_1.request_transaction(request_transaction)
|
||||
assert msg is None
|
||||
@ -1061,7 +1061,7 @@ class TestFullNodeProtocol:
|
||||
assert msg.data == bytes(fnp.RespondTransaction(spend_bundle))
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_respond_transaction_fail(self, wallet_nodes, self_hostname):
|
||||
async def test_respond_transaction_fail(self, wallet_nodes, self_hostname, seeded_random: random.Random):
|
||||
full_node_1, full_node_2, server_1, server_2, wallet_a, wallet_receiver, bt = wallet_nodes
|
||||
blocks = await full_node_1.get_all_full_blocks()
|
||||
cb_ph = wallet_a.get_new_puzzlehash()
|
||||
@ -1069,7 +1069,7 @@ class TestFullNodeProtocol:
|
||||
incoming_queue, dummy_node_id = await add_dummy_connection(server_1, self_hostname, 12312)
|
||||
peer = await connect_and_get_peer(server_1, server_2, self_hostname)
|
||||
|
||||
tx_id = token_bytes(32)
|
||||
tx_id = bytes32.random(seeded_random)
|
||||
request_transaction = fnp.RequestTransaction(tx_id)
|
||||
msg = await full_node_1.request_transaction(request_transaction)
|
||||
assert msg is None
|
||||
|
@ -1,7 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from secrets import token_bytes
|
||||
import random
|
||||
from typing import Optional
|
||||
|
||||
import pytest
|
||||
@ -11,6 +11,7 @@ from chia.consensus.block_rewards import calculate_base_farmer_reward, calculate
|
||||
from chia.full_node.full_node_api import FullNodeAPI
|
||||
from chia.simulator.simulator_protocol import FarmNewBlockProtocol
|
||||
from chia.simulator.time_out_assert import time_out_assert
|
||||
from chia.types.blockchain_format.sized_bytes import bytes32
|
||||
from chia.types.peer_info import PeerInfo
|
||||
from chia.util.ints import uint16, uint32
|
||||
from chia.wallet.util.tx_config import DEFAULT_TX_CONFIG
|
||||
@ -40,7 +41,7 @@ class TestTransactions:
|
||||
await time_out_assert(20, wallet.get_confirmed_balance, funds)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_tx_propagation(self, three_nodes_two_wallets, self_hostname):
|
||||
async def test_tx_propagation(self, three_nodes_two_wallets, self_hostname, seeded_random: random.Random):
|
||||
num_blocks = 5
|
||||
full_nodes, wallets, _ = three_nodes_two_wallets
|
||||
|
||||
@ -106,7 +107,7 @@ class TestTransactions:
|
||||
|
||||
# Farm another block
|
||||
for i in range(1, 8):
|
||||
await full_node_api_1.farm_new_transaction_block(FarmNewBlockProtocol(token_bytes()))
|
||||
await full_node_api_1.farm_new_transaction_block(FarmNewBlockProtocol(bytes32.random(seeded_random)))
|
||||
funds = sum(
|
||||
[
|
||||
calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i))
|
||||
@ -122,7 +123,7 @@ class TestTransactions:
|
||||
await time_out_assert(20, wallet_1.wallet_state_manager.main_wallet.get_confirmed_balance, 10)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_mempool_tx_sync(self, three_nodes_two_wallets, self_hostname):
|
||||
async def test_mempool_tx_sync(self, three_nodes_two_wallets, self_hostname, seeded_random: random.Random):
|
||||
num_blocks = 5
|
||||
full_nodes, wallets, _ = three_nodes_two_wallets
|
||||
|
||||
@ -155,7 +156,7 @@ class TestTransactions:
|
||||
await time_out_assert(20, wallet_0.wallet_state_manager.main_wallet.get_confirmed_balance, funds)
|
||||
|
||||
tx = await wallet_0.wallet_state_manager.main_wallet.generate_signed_transaction(
|
||||
10, token_bytes(), DEFAULT_TX_CONFIG, 0
|
||||
10, bytes32.random(seeded_random), DEFAULT_TX_CONFIG, 0
|
||||
)
|
||||
await wallet_0.wallet_state_manager.main_wallet.push_transaction(tx)
|
||||
|
||||
|
@ -2,8 +2,8 @@ from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
import random
|
||||
from dataclasses import dataclass
|
||||
from secrets import token_bytes
|
||||
from typing import List, Optional, cast
|
||||
|
||||
import pytest
|
||||
@ -25,12 +25,8 @@ def get_transaction_queue_entry(peer_id: Optional[bytes32], tx_index: int) -> Tr
|
||||
return cast(TransactionQueueEntry, FakeTransactionQueueEntry(index=tx_index, peer_id=peer_id))
|
||||
|
||||
|
||||
def get_peer_id() -> bytes32:
|
||||
return bytes32(token_bytes(32))
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_local_txs() -> None:
|
||||
async def test_local_txs(seeded_random: random.Random) -> None:
|
||||
transaction_queue = TransactionQueue(1000, log)
|
||||
# test 1 tx
|
||||
first_tx = get_transaction_queue_entry(None, 0)
|
||||
@ -42,7 +38,7 @@ async def test_local_txs() -> None:
|
||||
|
||||
# test 2000 txs
|
||||
num_txs = 2000
|
||||
list_txs = [get_transaction_queue_entry(get_peer_id(), i) for i in range(num_txs)]
|
||||
list_txs = [get_transaction_queue_entry(bytes32.random(seeded_random), i) for i in range(num_txs)]
|
||||
for tx in list_txs:
|
||||
await transaction_queue.put(tx, None)
|
||||
|
||||
@ -55,10 +51,10 @@ async def test_local_txs() -> None:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_one_peer_and_await() -> None:
|
||||
async def test_one_peer_and_await(seeded_random: random.Random) -> None:
|
||||
transaction_queue = TransactionQueue(1000, log)
|
||||
num_txs = 100
|
||||
peer_id = get_peer_id()
|
||||
peer_id = bytes32.random(seeded_random)
|
||||
|
||||
list_txs = [get_transaction_queue_entry(peer_id, i) for i in range(num_txs)]
|
||||
for tx in list_txs:
|
||||
@ -89,12 +85,12 @@ async def test_one_peer_and_await() -> None:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_lots_of_peers() -> None:
|
||||
async def test_lots_of_peers(seeded_random: random.Random) -> None:
|
||||
transaction_queue = TransactionQueue(1000, log)
|
||||
num_peers = 1000
|
||||
num_txs = 100
|
||||
total_txs = num_txs * num_peers
|
||||
peer_ids: List[bytes32] = [get_peer_id() for _ in range(num_peers)]
|
||||
peer_ids: List[bytes32] = [bytes32.random(seeded_random) for _ in range(num_peers)]
|
||||
|
||||
# 100 txs per peer
|
||||
list_txs = [get_transaction_queue_entry(peer_id, i) for peer_id in peer_ids for i in range(num_txs)]
|
||||
@ -111,12 +107,12 @@ async def test_lots_of_peers() -> None:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_full_queue() -> None:
|
||||
async def test_full_queue(seeded_random: random.Random) -> None:
|
||||
transaction_queue = TransactionQueue(1000, log)
|
||||
num_peers = 100
|
||||
num_txs = 1000
|
||||
total_txs = num_txs * num_peers
|
||||
peer_ids: List[bytes32] = [get_peer_id() for _ in range(num_peers)]
|
||||
peer_ids: List[bytes32] = [bytes32.random(seeded_random) for _ in range(num_peers)]
|
||||
|
||||
# 999 txs per peer then 1 to fail later
|
||||
list_txs = [get_transaction_queue_entry(peer_id, i) for peer_id in peer_ids for i in range(num_txs)]
|
||||
@ -133,11 +129,11 @@ async def test_full_queue() -> None:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_queue_cleanup_and_fairness() -> None:
|
||||
async def test_queue_cleanup_and_fairness(seeded_random: random.Random) -> None:
|
||||
transaction_queue = TransactionQueue(1000, log)
|
||||
peer_a = get_peer_id()
|
||||
peer_b = get_peer_id()
|
||||
peer_c = get_peer_id()
|
||||
peer_a = bytes32.random(seeded_random)
|
||||
peer_b = bytes32.random(seeded_random)
|
||||
peer_c = bytes32.random(seeded_random)
|
||||
|
||||
# 2 for a, 1 for b, 2 for c
|
||||
peer_tx_a = [get_transaction_queue_entry(peer_a, i) for i in range(2)]
|
||||
|
@ -1,14 +1,15 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import random
|
||||
from dataclasses import replace
|
||||
from secrets import token_bytes
|
||||
from typing import Callable, List, Optional, Tuple
|
||||
|
||||
import pytest
|
||||
from blspy import AugSchemeMPL, G1Element, PrivateKey
|
||||
|
||||
from chia.simulator.keyring import TempKeyring
|
||||
from chia.types.blockchain_format.sized_bytes import bytes32
|
||||
from chia.util.errors import (
|
||||
KeychainFingerprintExists,
|
||||
KeychainFingerprintNotFound,
|
||||
@ -41,7 +42,7 @@ public_key = G1Element.from_bytes(
|
||||
|
||||
|
||||
class TestKeychain:
|
||||
def test_basic_add_delete(self, empty_temp_file_keyring: TempKeyring):
|
||||
def test_basic_add_delete(self, empty_temp_file_keyring: TempKeyring, seeded_random: random.Random):
|
||||
kc: Keychain = Keychain(user="testing-1.8.0", service="chia-testing-1.8.0")
|
||||
kc.delete_all_keys()
|
||||
|
||||
@ -91,9 +92,9 @@ class TestKeychain:
|
||||
assert kc._get_free_private_key_index() == 0
|
||||
assert len(kc.get_all_private_keys()) == 0
|
||||
|
||||
kc.add_private_key(bytes_to_mnemonic(token_bytes(32)))
|
||||
kc.add_private_key(bytes_to_mnemonic(token_bytes(32)))
|
||||
kc.add_private_key(bytes_to_mnemonic(token_bytes(32)))
|
||||
kc.add_private_key(bytes_to_mnemonic(bytes32.random(seeded_random)))
|
||||
kc.add_private_key(bytes_to_mnemonic(bytes32.random(seeded_random)))
|
||||
kc.add_private_key(bytes_to_mnemonic(bytes32.random(seeded_random)))
|
||||
|
||||
assert len(kc.get_all_public_keys()) == 3
|
||||
|
||||
@ -101,7 +102,7 @@ class TestKeychain:
|
||||
assert kc.get_first_public_key() is not None
|
||||
|
||||
kc.delete_all_keys()
|
||||
kc.add_private_key(bytes_to_mnemonic(token_bytes(32)))
|
||||
kc.add_private_key(bytes_to_mnemonic(bytes32.random(seeded_random)))
|
||||
assert kc.get_first_public_key() is not None
|
||||
|
||||
def test_add_private_key_label(self, empty_temp_file_keyring: TempKeyring):
|
||||
|
@ -4,7 +4,6 @@ import dataclasses
|
||||
import logging
|
||||
import random
|
||||
import time
|
||||
from secrets import token_bytes
|
||||
from typing import Any, Callable, List, Tuple, Type, Union
|
||||
|
||||
import pytest
|
||||
@ -163,8 +162,8 @@ async def run_sync_step(receiver: Receiver, sync_step: SyncStepData) -> None:
|
||||
assert receiver._last_sync.time_done == last_sync_time_before
|
||||
|
||||
|
||||
def plot_sync_setup() -> Tuple[Receiver, List[SyncStepData]]:
|
||||
harvester_connection = get_dummy_connection(NodeType.HARVESTER)
|
||||
def plot_sync_setup(seeded_random: random.Random) -> Tuple[Receiver, List[SyncStepData]]:
|
||||
harvester_connection = get_dummy_connection(NodeType.HARVESTER, bytes32.random(seeded_random))
|
||||
receiver = Receiver(harvester_connection, dummy_callback) # type:ignore[arg-type]
|
||||
|
||||
# Create example plot data
|
||||
@ -173,7 +172,7 @@ def plot_sync_setup() -> Tuple[Receiver, List[SyncStepData]]:
|
||||
Plot(
|
||||
filename=str(x),
|
||||
size=uint8(0),
|
||||
plot_id=bytes32(token_bytes(32)),
|
||||
plot_id=bytes32.random(seeded_random),
|
||||
pool_contract_puzzle_hash=None,
|
||||
pool_public_key=None,
|
||||
plot_public_key=G1Element(),
|
||||
@ -211,13 +210,21 @@ def plot_sync_setup() -> Tuple[Receiver, List[SyncStepData]]:
|
||||
return receiver, sync_steps
|
||||
|
||||
|
||||
def test_default_values() -> None:
|
||||
assert_default_values(Receiver(get_dummy_connection(NodeType.HARVESTER), dummy_callback)) # type:ignore[arg-type]
|
||||
def test_default_values(seeded_random: random.Random) -> None:
|
||||
assert_default_values(
|
||||
Receiver(
|
||||
get_dummy_connection(
|
||||
NodeType.HARVESTER,
|
||||
bytes32.random(seeded_random),
|
||||
), # type:ignore[arg-type]
|
||||
dummy_callback, # type:ignore[arg-type]
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_reset() -> None:
|
||||
receiver, sync_steps = plot_sync_setup()
|
||||
async def test_reset(seeded_random: random.Random) -> None:
|
||||
receiver, sync_steps = plot_sync_setup(seeded_random=seeded_random)
|
||||
connection_before = receiver.connection()
|
||||
# Assign some dummy values
|
||||
receiver._current_sync.state = State.done
|
||||
@ -250,8 +257,8 @@ async def test_reset() -> None:
|
||||
|
||||
@pytest.mark.parametrize("counts_only", [True, False])
|
||||
@pytest.mark.asyncio
|
||||
async def test_to_dict(counts_only: bool) -> None:
|
||||
receiver, sync_steps = plot_sync_setup()
|
||||
async def test_to_dict(counts_only: bool, seeded_random: random.Random) -> None:
|
||||
receiver, sync_steps = plot_sync_setup(seeded_random=seeded_random)
|
||||
plot_sync_dict_1 = receiver.to_dict(counts_only)
|
||||
|
||||
assert get_list_or_len(plot_sync_dict_1["plots"], not counts_only) == 10
|
||||
@ -331,8 +338,8 @@ async def test_to_dict(counts_only: bool) -> None:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sync_flow() -> None:
|
||||
receiver, sync_steps = plot_sync_setup()
|
||||
async def test_sync_flow(seeded_random: random.Random) -> None:
|
||||
receiver, sync_steps = plot_sync_setup(seeded_random=seeded_random)
|
||||
|
||||
for plot_info in sync_steps[State.loaded].args[0]:
|
||||
assert plot_info.filename not in receiver.plots()
|
||||
@ -373,8 +380,8 @@ async def test_sync_flow() -> None:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_invalid_ids() -> None:
|
||||
receiver, sync_steps = plot_sync_setup()
|
||||
async def test_invalid_ids(seeded_random: random.Random) -> None:
|
||||
receiver, sync_steps = plot_sync_setup(seeded_random=seeded_random)
|
||||
for state in State:
|
||||
assert receiver.current_sync().state == state
|
||||
current_step = sync_steps[state]
|
||||
@ -424,8 +431,8 @@ async def test_invalid_ids() -> None:
|
||||
],
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_plot_errors(state_to_fail: State, expected_error_code: ErrorCodes) -> None:
|
||||
receiver, sync_steps = plot_sync_setup()
|
||||
async def test_plot_errors(state_to_fail: State, expected_error_code: ErrorCodes, seeded_random: random.Random) -> None:
|
||||
receiver, sync_steps = plot_sync_setup(seeded_random=seeded_random)
|
||||
for state in State:
|
||||
assert receiver.current_sync().state == state
|
||||
current_step = sync_steps[state]
|
||||
|
@ -1,5 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import random
|
||||
|
||||
import pytest
|
||||
|
||||
from chia.plot_sync.exceptions import AlreadyStartedError, InvalidConnectionTypeError
|
||||
@ -10,6 +12,7 @@ from chia.protocols.harvester_protocol import PlotSyncIdentifier, PlotSyncRespon
|
||||
from chia.protocols.protocol_message_types import ProtocolMessageTypes
|
||||
from chia.server.outbound_message import NodeType
|
||||
from chia.simulator.block_tools import BlockTools
|
||||
from chia.types.blockchain_format.sized_bytes import bytes32
|
||||
from chia.util.ints import int16, uint64
|
||||
from tests.plot_sync.util import get_dummy_connection, plot_sync_identifier
|
||||
|
||||
@ -28,8 +31,8 @@ def test_default_values(bt: BlockTools) -> None:
|
||||
assert sender._harvesting_mode == HarvestingMode.CPU
|
||||
|
||||
|
||||
def test_set_connection_values(bt: BlockTools) -> None:
|
||||
farmer_connection = get_dummy_connection(NodeType.FARMER)
|
||||
def test_set_connection_values(bt: BlockTools, seeded_random: random.Random) -> None:
|
||||
farmer_connection = get_dummy_connection(NodeType.FARMER, bytes32.random(seeded_random))
|
||||
sender = Sender(bt.plot_manager, HarvestingMode.CPU)
|
||||
# Test invalid NodeType values
|
||||
for connection_type in NodeType:
|
||||
|
@ -3,11 +3,11 @@ from __future__ import annotations
|
||||
import asyncio
|
||||
import functools
|
||||
import logging
|
||||
import random
|
||||
import time
|
||||
from dataclasses import dataclass, field
|
||||
from enum import Enum
|
||||
from pathlib import Path
|
||||
from secrets import token_bytes
|
||||
from typing import Any, Dict, List, Optional, Set, Tuple
|
||||
|
||||
import pytest
|
||||
@ -259,7 +259,7 @@ async def create_test_runner(
|
||||
return TestRunner(harvesters, farmer, event_loop)
|
||||
|
||||
|
||||
def create_example_plots(count: int) -> List[PlotInfo]:
|
||||
def create_example_plots(count: int, seeded_random: random.Random) -> List[PlotInfo]:
|
||||
@dataclass
|
||||
class DiskProver:
|
||||
file_name: str
|
||||
@ -280,7 +280,7 @@ def create_example_plots(count: int) -> List[PlotInfo]:
|
||||
|
||||
return [
|
||||
PlotInfo(
|
||||
prover=DiskProver(f"{x}", bytes32(token_bytes(32)), 25 + x % 26),
|
||||
prover=DiskProver(f"{x}", bytes32.random(seeded_random), 25 + x % 26),
|
||||
pool_public_key=None,
|
||||
pool_contract_puzzle_hash=None,
|
||||
plot_public_key=G1Element(),
|
||||
@ -297,11 +297,12 @@ async def test_sync_simulated(
|
||||
List[Service[Harvester, HarvesterAPI]], Service[Farmer, FarmerAPI], BlockTools
|
||||
],
|
||||
event_loop: asyncio.events.AbstractEventLoop,
|
||||
seeded_random: random.Random,
|
||||
) -> None:
|
||||
harvester_services, farmer_service, _ = farmer_three_harvester_not_started
|
||||
farmer: Farmer = farmer_service._node
|
||||
test_runner: TestRunner = await create_test_runner(harvester_services, farmer_service, event_loop)
|
||||
plots = create_example_plots(31000)
|
||||
plots = create_example_plots(31000, seeded_random=seeded_random)
|
||||
|
||||
await test_runner.run(
|
||||
0, loaded=plots[0:10000], removed=[], invalid=[], keys_missing=[], duplicates=plots[0:1000], initial=True
|
||||
@ -379,12 +380,13 @@ async def test_farmer_error_simulation(
|
||||
],
|
||||
event_loop: asyncio.events.AbstractEventLoop,
|
||||
simulate_error: ErrorSimulation,
|
||||
seeded_random: random.Random,
|
||||
) -> None:
|
||||
Constants.message_timeout = 5
|
||||
harvester_services, farmer_service, _ = farmer_one_harvester_not_started
|
||||
test_runner: TestRunner = await create_test_runner(harvester_services, farmer_service, event_loop)
|
||||
batch_size = test_runner.test_data[0].harvester.plot_manager.refresh_parameter.batch_size
|
||||
plots = create_example_plots(batch_size + 3)
|
||||
plots = create_example_plots(batch_size + 3, seeded_random=seeded_random)
|
||||
receiver = test_runner.test_data[0].plot_sync_receiver
|
||||
receiver.simulate_error = simulate_error # type: ignore[attr-defined]
|
||||
await test_runner.run(
|
||||
@ -406,12 +408,13 @@ async def test_sync_reset_cases(
|
||||
],
|
||||
event_loop: asyncio.events.AbstractEventLoop,
|
||||
simulate_error: ErrorSimulation,
|
||||
seeded_random: random.Random,
|
||||
) -> None:
|
||||
harvester_services, farmer_service, _ = farmer_one_harvester_not_started
|
||||
test_runner: TestRunner = await create_test_runner(harvester_services, farmer_service, event_loop)
|
||||
test_data: TestData = test_runner.test_data[0]
|
||||
plot_manager: PlotManager = test_data.harvester.plot_manager
|
||||
plots = create_example_plots(30)
|
||||
plots = create_example_plots(30, seeded_random=seeded_random)
|
||||
# Inject some data into `PlotManager` of the harvester so that we can validate the reset worked and triggered a
|
||||
# fresh sync of all available data of the plot manager
|
||||
for plot_info in plots[0:10]:
|
||||
|
@ -2,7 +2,6 @@ from __future__ import annotations
|
||||
|
||||
import time
|
||||
from dataclasses import dataclass
|
||||
from secrets import token_bytes
|
||||
from typing import Optional
|
||||
|
||||
from chia.farmer.farmer import Farmer
|
||||
@ -30,8 +29,8 @@ class WSChiaConnectionDummy:
|
||||
self.last_sent_message = message
|
||||
|
||||
|
||||
def get_dummy_connection(node_type: NodeType, peer_id: Optional[bytes32] = None) -> WSChiaConnectionDummy:
|
||||
return WSChiaConnectionDummy(node_type, bytes32(token_bytes(32)) if peer_id is None else peer_id)
|
||||
def get_dummy_connection(node_type: NodeType, peer_id: bytes32) -> WSChiaConnectionDummy:
|
||||
return WSChiaConnectionDummy(node_type, peer_id)
|
||||
|
||||
|
||||
def plot_sync_identifier(current_sync_id: uint64, message_id: uint64) -> PlotSyncIdentifier:
|
||||
|
@ -1,7 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import random
|
||||
from dataclasses import dataclass, field
|
||||
from secrets import token_bytes
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
import pytest
|
||||
@ -17,8 +17,10 @@ from chia.wallet.wallet_pool_store import WalletPoolStore
|
||||
from tests.util.db_connection import DBConnection
|
||||
|
||||
|
||||
def make_child_solution(coin_spend: Optional[CoinSpend], new_coin: Optional[Coin] = None) -> CoinSpend:
|
||||
new_puzzle_hash: bytes32 = bytes32(token_bytes(32))
|
||||
def make_child_solution(
|
||||
coin_spend: Optional[CoinSpend], new_coin: Optional[Coin], seeded_random: random.Random
|
||||
) -> CoinSpend:
|
||||
new_puzzle_hash: bytes32 = bytes32.random(seeded_random)
|
||||
solution = "()"
|
||||
puzzle = f"(q . ((51 0x{new_puzzle_hash.hex()} 1)))"
|
||||
puzzle_prog = Program.to(binutils.assemble(puzzle))
|
||||
@ -43,6 +45,7 @@ async def assert_db_spends(store: WalletPoolStore, wallet_id: int, spends: List[
|
||||
|
||||
@dataclass
|
||||
class DummySpends:
|
||||
seeded_random: random.Random
|
||||
spends_per_wallet: Dict[int, List[CoinSpend]] = field(default_factory=dict)
|
||||
|
||||
def generate(self, wallet_id: int, count: int) -> None:
|
||||
@ -51,23 +54,29 @@ class DummySpends:
|
||||
coin = None
|
||||
last_spend = None if len(current) == 0 else current[-1]
|
||||
if last_spend is None:
|
||||
coin = Coin(token_bytes(32), token_bytes(32), uint64(12312))
|
||||
current.append(make_child_solution(last_spend, coin))
|
||||
coin = Coin(bytes32.random(self.seeded_random), bytes32.random(self.seeded_random), uint64(12312))
|
||||
current.append(make_child_solution(coin_spend=last_spend, new_coin=coin, seeded_random=self.seeded_random))
|
||||
|
||||
|
||||
class TestWalletPoolStore:
|
||||
@pytest.mark.asyncio
|
||||
async def test_store(self):
|
||||
async def test_store(self, seeded_random: random.Random):
|
||||
async with DBConnection(1) as db_wrapper:
|
||||
store = await WalletPoolStore.create(db_wrapper)
|
||||
|
||||
try:
|
||||
async with db_wrapper.writer():
|
||||
coin_0 = Coin(token_bytes(32), token_bytes(32), uint64(12312))
|
||||
coin_0_alt = Coin(token_bytes(32), token_bytes(32), uint64(12312))
|
||||
solution_0: CoinSpend = make_child_solution(None, coin_0)
|
||||
solution_0_alt: CoinSpend = make_child_solution(None, coin_0_alt)
|
||||
solution_1: CoinSpend = make_child_solution(solution_0)
|
||||
coin_0 = Coin(bytes32.random(seeded_random), bytes32.random(seeded_random), uint64(12312))
|
||||
coin_0_alt = Coin(bytes32.random(seeded_random), bytes32.random(seeded_random), uint64(12312))
|
||||
solution_0: CoinSpend = make_child_solution(
|
||||
coin_spend=None, new_coin=coin_0, seeded_random=seeded_random
|
||||
)
|
||||
solution_0_alt: CoinSpend = make_child_solution(
|
||||
coin_spend=None, new_coin=coin_0_alt, seeded_random=seeded_random
|
||||
)
|
||||
solution_1: CoinSpend = make_child_solution(
|
||||
coin_spend=solution_0, new_coin=None, seeded_random=seeded_random
|
||||
)
|
||||
|
||||
assert await store.get_spends_for_wallet(0) == []
|
||||
assert await store.get_spends_for_wallet(1) == []
|
||||
@ -92,18 +101,18 @@ class TestWalletPoolStore:
|
||||
await store.add_spend(1, solution_1, 100)
|
||||
assert await store.get_spends_for_wallet(1) == [(100, solution_1)]
|
||||
|
||||
solution_1_alt: CoinSpend = make_child_solution(solution_0_alt)
|
||||
solution_1_alt: CoinSpend = make_child_solution(solution_0_alt, new_coin=None, seeded_random=seeded_random)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
await store.add_spend(1, solution_1_alt, 100)
|
||||
|
||||
assert await store.get_spends_for_wallet(1) == [(100, solution_1)]
|
||||
|
||||
solution_2: CoinSpend = make_child_solution(solution_1)
|
||||
solution_2: CoinSpend = make_child_solution(solution_1, new_coin=None, seeded_random=seeded_random)
|
||||
await store.add_spend(1, solution_2, 100)
|
||||
solution_3: CoinSpend = make_child_solution(solution_2)
|
||||
solution_3: CoinSpend = make_child_solution(solution_2, new_coin=None, seeded_random=seeded_random)
|
||||
await store.add_spend(1, solution_3, 100)
|
||||
solution_4: CoinSpend = make_child_solution(solution_3)
|
||||
solution_4: CoinSpend = make_child_solution(solution_3, new_coin=None, seeded_random=seeded_random)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
await store.add_spend(1, solution_4, 99)
|
||||
@ -126,15 +135,15 @@ class TestWalletPoolStore:
|
||||
await store.add_spend(1, solution_1, 105)
|
||||
|
||||
await store.add_spend(1, solution_4, 105)
|
||||
solution_5: CoinSpend = make_child_solution(solution_4)
|
||||
solution_5: CoinSpend = make_child_solution(solution_4, new_coin=None, seeded_random=seeded_random)
|
||||
await store.add_spend(1, solution_5, 105)
|
||||
await store.rollback(99, 1)
|
||||
assert await store.get_spends_for_wallet(1) == []
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_delete_wallet() -> None:
|
||||
dummy_spends = DummySpends()
|
||||
async def test_delete_wallet(seeded_random: random.Random) -> None:
|
||||
dummy_spends = DummySpends(seeded_random=seeded_random)
|
||||
for i in range(5):
|
||||
dummy_spends.generate(i, i * 5)
|
||||
async with DBConnection(1) as db_wrapper:
|
||||
|
@ -1,7 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import random
|
||||
import time
|
||||
from secrets import token_bytes
|
||||
|
||||
from blspy import AugSchemeMPL, PrivateKey
|
||||
from clvm_tools import binutils
|
||||
@ -9,6 +9,7 @@ from clvm_tools import binutils
|
||||
from chia.consensus.default_constants import DEFAULT_CONSTANTS
|
||||
from chia.simulator.wallet_tools import WalletTool
|
||||
from chia.types.blockchain_format.program import INFINITE_COST, Program
|
||||
from chia.types.blockchain_format.sized_bytes import bytes32
|
||||
from chia.types.condition_opcodes import ConditionOpcode
|
||||
from chia.types.condition_with_args import ConditionWithArgs
|
||||
from chia.util.ints import uint32
|
||||
@ -111,11 +112,18 @@ if __name__ == "__main__":
|
||||
private_keys = []
|
||||
public_keys = []
|
||||
|
||||
seeded_random = random.Random()
|
||||
seeded_random.seed(a=0, version=2)
|
||||
|
||||
for i in range(0, 1000):
|
||||
private_key: PrivateKey = master_sk_to_wallet_sk(secret_key, uint32(i))
|
||||
public_key = private_key.get_g1()
|
||||
solution = wallet_tool.make_solution(
|
||||
{ConditionOpcode.ASSERT_MY_COIN_ID: [ConditionWithArgs(ConditionOpcode.ASSERT_MY_COIN_ID, [token_bytes()])]}
|
||||
{
|
||||
ConditionOpcode.ASSERT_MY_COIN_ID: [
|
||||
ConditionWithArgs(ConditionOpcode.ASSERT_MY_COIN_ID, [bytes32.random(seeded_random)])
|
||||
]
|
||||
}
|
||||
)
|
||||
puzzle = puzzle_for_pk(bytes(public_key))
|
||||
puzzles.append(puzzle)
|
||||
@ -137,7 +145,7 @@ if __name__ == "__main__":
|
||||
|
||||
private_key = master_sk_to_wallet_sk(secret_key, uint32(0))
|
||||
public_key = private_key.get_g1()
|
||||
message = token_bytes()
|
||||
message = bytes32.random(seeded_random)
|
||||
signature = AugSchemeMPL.sign(private_key, message)
|
||||
pk_message_pair = (public_key, message)
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from secrets import token_bytes
|
||||
import random
|
||||
from typing import List, Tuple
|
||||
|
||||
import pytest
|
||||
@ -24,6 +24,7 @@ async def test_is_recipient(
|
||||
simulator_and_wallet: Tuple[List[FullNodeSimulator], List[Tuple[WalletNode, ChiaServer]], BlockTools],
|
||||
trusted: bool,
|
||||
self_hostname: str,
|
||||
seeded_random: random.Random,
|
||||
) -> None:
|
||||
full_nodes, wallets, _ = simulator_and_wallet
|
||||
full_node_api = full_nodes[0]
|
||||
@ -33,10 +34,10 @@ async def test_is_recipient(
|
||||
puzhash_1 = await wallet.get_new_puzzlehash()
|
||||
puzhash_2 = await wallet.get_new_puzzlehash()
|
||||
await server_2.start_client(PeerInfo(self_hostname, uint16(server_1._port)), None)
|
||||
invalid_data = ClawbackMetadata(uint64(500), bytes32(token_bytes()), bytes32(token_bytes()))
|
||||
invalid_data = ClawbackMetadata(uint64(500), bytes32.random(seeded_random), bytes32.random(seeded_random))
|
||||
both_data = ClawbackMetadata(uint64(500), puzhash_1, puzhash_2)
|
||||
sender_data = ClawbackMetadata(uint64(500), puzhash_1, bytes32(token_bytes()))
|
||||
recipient_data = ClawbackMetadata(uint64(500), bytes32(token_bytes()), puzhash_2)
|
||||
sender_data = ClawbackMetadata(uint64(500), puzhash_1, bytes32.random(seeded_random))
|
||||
recipient_data = ClawbackMetadata(uint64(500), bytes32.random(seeded_random), puzhash_2)
|
||||
# Test invalid metadata
|
||||
has_exception = False
|
||||
try:
|
||||
|
@ -2,7 +2,7 @@ from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
from secrets import token_bytes
|
||||
import random
|
||||
from typing import Any, Callable, Coroutine, Optional, Tuple
|
||||
|
||||
import pytest
|
||||
@ -56,7 +56,7 @@ async def get_nft_count(wallet: NFTWallet) -> int:
|
||||
@pytest.mark.parametrize("zero_royalties", [True, False])
|
||||
@pytest.mark.asyncio
|
||||
async def test_nft_offer_sell_nft(
|
||||
self_hostname: str, two_wallet_nodes: Any, trusted: Any, zero_royalties: bool
|
||||
self_hostname: str, two_wallet_nodes: Any, trusted: Any, zero_royalties: bool, seeded_random: random.Random
|
||||
) -> None:
|
||||
full_nodes, wallets, _ = two_wallet_nodes
|
||||
full_node_api: FullNodeSimulator = full_nodes[0]
|
||||
@ -68,7 +68,7 @@ async def test_nft_offer_sell_nft(
|
||||
|
||||
ph_maker = await wallet_maker.get_new_puzzlehash()
|
||||
ph_taker = await wallet_taker.get_new_puzzlehash()
|
||||
ph_token = bytes32(token_bytes())
|
||||
ph_token = bytes32.random(seeded_random)
|
||||
|
||||
if trusted:
|
||||
wallet_node_maker.config["trusted_peers"] = {
|
||||
@ -210,7 +210,7 @@ async def test_nft_offer_sell_nft(
|
||||
@pytest.mark.parametrize("zero_royalties", [True, False])
|
||||
@pytest.mark.asyncio
|
||||
async def test_nft_offer_request_nft(
|
||||
self_hostname: str, two_wallet_nodes: Any, trusted: Any, zero_royalties: bool
|
||||
self_hostname: str, two_wallet_nodes: Any, trusted: Any, zero_royalties: bool, seeded_random: random.Random
|
||||
) -> None:
|
||||
full_nodes, wallets, _ = two_wallet_nodes
|
||||
full_node_api: FullNodeSimulator = full_nodes[0]
|
||||
@ -222,7 +222,7 @@ async def test_nft_offer_request_nft(
|
||||
|
||||
ph_maker = await wallet_maker.get_new_puzzlehash()
|
||||
ph_taker = await wallet_taker.get_new_puzzlehash()
|
||||
ph_token = bytes32(token_bytes())
|
||||
ph_token = bytes32.random(seeded_random)
|
||||
|
||||
if trusted:
|
||||
wallet_node_maker.config["trusted_peers"] = {
|
||||
@ -362,7 +362,7 @@ async def test_nft_offer_request_nft(
|
||||
@pytest.mark.parametrize("zero_royalties", [True, False])
|
||||
@pytest.mark.asyncio
|
||||
async def test_nft_offer_sell_did_to_did(
|
||||
self_hostname: str, two_wallet_nodes: Any, trusted: Any, zero_royalties: bool
|
||||
self_hostname: str, two_wallet_nodes: Any, trusted: Any, zero_royalties: bool, seeded_random: random.Random
|
||||
) -> None:
|
||||
full_nodes, wallets, _ = two_wallet_nodes
|
||||
full_node_api: FullNodeSimulator = full_nodes[0]
|
||||
@ -374,7 +374,7 @@ async def test_nft_offer_sell_did_to_did(
|
||||
|
||||
ph_maker = await wallet_maker.get_new_puzzlehash()
|
||||
ph_taker = await wallet_taker.get_new_puzzlehash()
|
||||
ph_token = bytes32(token_bytes())
|
||||
ph_token = bytes32.random(seeded_random)
|
||||
|
||||
if trusted:
|
||||
wallet_node_maker.config["trusted_peers"] = {
|
||||
@ -537,7 +537,7 @@ async def test_nft_offer_sell_did_to_did(
|
||||
@pytest.mark.parametrize("zero_royalties", [True, False])
|
||||
@pytest.mark.asyncio
|
||||
async def test_nft_offer_sell_nft_for_cat(
|
||||
self_hostname: str, two_wallet_nodes: Any, trusted: Any, zero_royalties: bool
|
||||
self_hostname: str, two_wallet_nodes: Any, trusted: Any, zero_royalties: bool, seeded_random: random.Random
|
||||
) -> None:
|
||||
full_nodes, wallets, _ = two_wallet_nodes
|
||||
full_node_api: FullNodeSimulator = full_nodes[0]
|
||||
@ -549,7 +549,7 @@ async def test_nft_offer_sell_nft_for_cat(
|
||||
|
||||
ph_maker = await wallet_maker.get_new_puzzlehash()
|
||||
ph_taker = await wallet_taker.get_new_puzzlehash()
|
||||
ph_token = bytes32(token_bytes())
|
||||
ph_token = bytes32.random(seeded_random)
|
||||
|
||||
if trusted:
|
||||
wallet_node_maker.config["trusted_peers"] = {
|
||||
@ -734,7 +734,7 @@ async def test_nft_offer_sell_nft_for_cat(
|
||||
@pytest.mark.parametrize("test_change", [True, False])
|
||||
@pytest.mark.asyncio
|
||||
async def test_nft_offer_request_nft_for_cat(
|
||||
self_hostname: str, two_wallet_nodes: Any, trusted: bool, test_change: bool
|
||||
self_hostname: str, two_wallet_nodes: Any, trusted: bool, test_change: bool, seeded_random: random.Random
|
||||
) -> None:
|
||||
full_nodes, wallets, _ = two_wallet_nodes
|
||||
full_node_api: FullNodeSimulator = full_nodes[0]
|
||||
@ -746,7 +746,7 @@ async def test_nft_offer_request_nft_for_cat(
|
||||
|
||||
ph_maker = await wallet_maker.get_new_puzzlehash()
|
||||
ph_taker = await wallet_taker.get_new_puzzlehash()
|
||||
ph_token = bytes32(token_bytes())
|
||||
ph_token = bytes32.random(seeded_random)
|
||||
|
||||
if trusted:
|
||||
wallet_node_maker.config["trusted_peers"] = {
|
||||
@ -941,7 +941,9 @@ async def test_nft_offer_request_nft_for_cat(
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
# @pytest.mark.skip
|
||||
async def test_nft_offer_sell_cancel(self_hostname: str, two_wallet_nodes: Any, trusted: Any) -> None:
|
||||
async def test_nft_offer_sell_cancel(
|
||||
self_hostname: str, two_wallet_nodes: Any, trusted: Any, seeded_random: random.Random
|
||||
) -> None:
|
||||
full_nodes, wallets, _ = two_wallet_nodes
|
||||
full_node_api: FullNodeSimulator = full_nodes[0]
|
||||
full_node_server = full_node_api.server
|
||||
@ -949,7 +951,7 @@ async def test_nft_offer_sell_cancel(self_hostname: str, two_wallet_nodes: Any,
|
||||
wallet_maker = wallet_node_maker.wallet_state_manager.main_wallet
|
||||
|
||||
ph_maker = await wallet_maker.get_new_puzzlehash()
|
||||
ph_token = bytes32(token_bytes())
|
||||
ph_token = bytes32.random(seeded_random)
|
||||
|
||||
if trusted:
|
||||
wallet_node_maker.config["trusted_peers"] = {
|
||||
@ -1059,7 +1061,9 @@ async def test_nft_offer_sell_cancel(self_hostname: str, two_wallet_nodes: Any,
|
||||
[True],
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_nft_offer_sell_cancel_in_batch(self_hostname: str, two_wallet_nodes: Any, trusted: Any) -> None:
|
||||
async def test_nft_offer_sell_cancel_in_batch(
|
||||
self_hostname: str, two_wallet_nodes: Any, trusted: Any, seeded_random: random.Random
|
||||
) -> None:
|
||||
num_blocks = 3
|
||||
full_nodes, wallets, _ = two_wallet_nodes
|
||||
full_node_api: FullNodeSimulator = full_nodes[0]
|
||||
@ -1068,7 +1072,7 @@ async def test_nft_offer_sell_cancel_in_batch(self_hostname: str, two_wallet_nod
|
||||
wallet_maker = wallet_node_maker.wallet_state_manager.main_wallet
|
||||
|
||||
ph_maker = await wallet_maker.get_new_puzzlehash()
|
||||
ph_token = bytes32(token_bytes())
|
||||
ph_token = bytes32.random(seeded_random)
|
||||
|
||||
if trusted:
|
||||
wallet_node_maker.config["trusted_peers"] = {
|
||||
@ -1191,7 +1195,11 @@ async def test_nft_offer_sell_cancel_in_batch(self_hostname: str, two_wallet_nod
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_complex_nft_offer(
|
||||
self_hostname: str, two_wallet_nodes: Any, trusted: Any, royalty_pts: Tuple[int, int, int]
|
||||
self_hostname: str,
|
||||
two_wallet_nodes: Any,
|
||||
trusted: Any,
|
||||
royalty_pts: Tuple[int, int, int],
|
||||
seeded_random: random.Random,
|
||||
) -> None:
|
||||
"""
|
||||
This test is going to create an offer where the maker offers 1 NFT and 1 CAT for 2 NFTs, an XCH and a CAT
|
||||
@ -1208,7 +1216,7 @@ async def test_complex_nft_offer(
|
||||
|
||||
ph_maker = await wallet_maker.get_new_puzzlehash()
|
||||
ph_taker = await wallet_taker.get_new_puzzlehash()
|
||||
ph_token = bytes32(token_bytes())
|
||||
ph_token = bytes32.random(seeded_random)
|
||||
if trusted:
|
||||
wallet_node_maker.config["trusted_peers"] = {
|
||||
full_node_api.full_node.server.node_id.hex(): full_node_api.full_node.server.node_id.hex()
|
||||
|
@ -1,6 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from secrets import token_bytes
|
||||
import random
|
||||
from typing import Any, Dict
|
||||
|
||||
import pytest
|
||||
@ -35,7 +35,9 @@ async def nft_count(wallet: NFTWallet) -> int:
|
||||
[True, False],
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_nft_mint_from_did(self_hostname: str, two_wallet_nodes: Any, trusted: Any) -> None:
|
||||
async def test_nft_mint_from_did(
|
||||
self_hostname: str, two_wallet_nodes: Any, trusted: Any, seeded_random: random.Random
|
||||
) -> None:
|
||||
full_nodes, wallets, _ = two_wallet_nodes
|
||||
full_node_api: FullNodeSimulator = full_nodes[0]
|
||||
full_node_server = full_node_api.server
|
||||
@ -45,7 +47,7 @@ async def test_nft_mint_from_did(self_hostname: str, two_wallet_nodes: Any, trus
|
||||
wallet_1 = wallet_node_1.wallet_state_manager.main_wallet
|
||||
api_0 = WalletRpcApi(wallet_node_0)
|
||||
ph_maker = await wallet_0.get_new_puzzlehash()
|
||||
ph_token = bytes32(token_bytes())
|
||||
ph_token = bytes32.random(seeded_random)
|
||||
|
||||
if trusted:
|
||||
wallet_node_0.config["trusted_peers"] = {
|
||||
@ -100,7 +102,7 @@ async def test_nft_mint_from_did(self_hostname: str, two_wallet_nodes: Any, trus
|
||||
metadata_list = [
|
||||
{
|
||||
"program": Program.to(
|
||||
[("u", ["https://www.chia.net/img/branding/chia-logo.svg"]), ("h", token_bytes(32).hex())]
|
||||
[("u", ["https://www.chia.net/img/branding/chia-logo.svg"]), ("h", bytes32.random(seeded_random).hex())]
|
||||
),
|
||||
"royalty_pc": royalty_pc,
|
||||
"royalty_ph": royalty_addr,
|
||||
@ -148,7 +150,10 @@ async def test_nft_mint_from_did(self_hostname: str, two_wallet_nodes: Any, trus
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_nft_mint_from_did_rpc(
|
||||
two_wallet_nodes_services: SimulatorsAndWalletsServices, trusted: Any, self_hostname: str
|
||||
two_wallet_nodes_services: SimulatorsAndWalletsServices,
|
||||
trusted: Any,
|
||||
self_hostname: str,
|
||||
seeded_random: random.Random,
|
||||
) -> None:
|
||||
[full_node_service], wallet_services, bt = two_wallet_nodes_services
|
||||
full_node_api: FullNodeSimulator = full_node_service._api
|
||||
@ -162,7 +167,7 @@ async def test_nft_mint_from_did_rpc(
|
||||
|
||||
ph_maker = await wallet_maker.get_new_puzzlehash()
|
||||
ph_taker = await wallet_taker.get_new_puzzlehash()
|
||||
ph_token = bytes32(token_bytes())
|
||||
ph_token = bytes32.random(seeded_random)
|
||||
|
||||
if trusted:
|
||||
wallet_node_maker.config["trusted_peers"] = {
|
||||
@ -240,11 +245,11 @@ async def test_nft_mint_from_did_rpc(
|
||||
n = 10
|
||||
metadata_list = [
|
||||
{
|
||||
"hash": bytes32(token_bytes(32)).hex(),
|
||||
"hash": bytes32.random(seeded_random).hex(),
|
||||
"uris": ["https://data.com/{}".format(i)],
|
||||
"meta_hash": bytes32(token_bytes(32)).hex(),
|
||||
"meta_hash": bytes32.random(seeded_random).hex(),
|
||||
"meta_uris": ["https://meatadata.com/{}".format(i)],
|
||||
"license_hash": bytes32(token_bytes(32)).hex(),
|
||||
"license_hash": bytes32.random(seeded_random).hex(),
|
||||
"license_uris": ["https://license.com/{}".format(i)],
|
||||
"edition_number": i + 1,
|
||||
"edition_total": n,
|
||||
@ -252,7 +257,7 @@ async def test_nft_mint_from_did_rpc(
|
||||
for i in range(n)
|
||||
]
|
||||
target_list = [encode_puzzle_hash((ph_taker), "xch") for x in range(n)]
|
||||
royalty_address = encode_puzzle_hash(bytes32(token_bytes(32)), "xch")
|
||||
royalty_address = encode_puzzle_hash(bytes32.random(seeded_random), "xch")
|
||||
royalty_percentage = 300
|
||||
fee = 100
|
||||
required_amount = n + (fee * n)
|
||||
@ -339,7 +344,10 @@ async def test_nft_mint_from_did_rpc(
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_nft_mint_from_did_rpc_no_royalties(
|
||||
two_wallet_nodes_services: SimulatorsAndWalletsServices, trusted: Any, self_hostname: str
|
||||
two_wallet_nodes_services: SimulatorsAndWalletsServices,
|
||||
trusted: Any,
|
||||
self_hostname: str,
|
||||
seeded_random: random.Random,
|
||||
) -> None:
|
||||
[full_node_service], wallet_services, bt = two_wallet_nodes_services
|
||||
full_node_api: FullNodeSimulator = full_node_service._api
|
||||
@ -353,7 +361,7 @@ async def test_nft_mint_from_did_rpc_no_royalties(
|
||||
|
||||
ph_maker = await wallet_maker.get_new_puzzlehash()
|
||||
ph_taker = await wallet_taker.get_new_puzzlehash()
|
||||
ph_token = bytes32(token_bytes())
|
||||
ph_token = bytes32.random(seeded_random)
|
||||
|
||||
if trusted:
|
||||
wallet_node_maker.config["trusted_peers"] = {
|
||||
@ -430,11 +438,11 @@ async def test_nft_mint_from_did_rpc_no_royalties(
|
||||
n = 10
|
||||
metadata_list = [
|
||||
{
|
||||
"hash": bytes32(token_bytes(32)).hex(),
|
||||
"hash": bytes32.random(seeded_random).hex(),
|
||||
"uris": ["https://data.com/{}".format(i)],
|
||||
"meta_hash": bytes32(token_bytes(32)).hex(),
|
||||
"meta_hash": bytes32.random(seeded_random).hex(),
|
||||
"meta_uris": ["https://meatadata.com/{}".format(i)],
|
||||
"license_hash": bytes32(token_bytes(32)).hex(),
|
||||
"license_hash": bytes32.random(seeded_random).hex(),
|
||||
"license_uris": ["https://license.com/{}".format(i)],
|
||||
"edition_number": i + 1,
|
||||
"edition_total": n,
|
||||
@ -509,7 +517,9 @@ async def test_nft_mint_from_did_rpc_no_royalties(
|
||||
[True, False],
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_nft_mint_from_did_multiple_xch(self_hostname: str, two_wallet_nodes: Any, trusted: Any) -> None:
|
||||
async def test_nft_mint_from_did_multiple_xch(
|
||||
self_hostname: str, two_wallet_nodes: Any, trusted: Any, seeded_random: random.Random
|
||||
) -> None:
|
||||
full_nodes, wallets, _ = two_wallet_nodes
|
||||
full_node_api: FullNodeSimulator = full_nodes[0]
|
||||
full_node_server = full_node_api.server
|
||||
@ -520,7 +530,7 @@ async def test_nft_mint_from_did_multiple_xch(self_hostname: str, two_wallet_nod
|
||||
api_0 = WalletRpcApi(wallet_node_0)
|
||||
ph_maker = await wallet_maker.get_new_puzzlehash()
|
||||
ph_taker = await wallet_taker.get_new_puzzlehash()
|
||||
ph_token = bytes32(token_bytes())
|
||||
ph_token = bytes32.random(seeded_random)
|
||||
|
||||
if trusted:
|
||||
wallet_node_0.config["trusted_peers"] = {
|
||||
@ -621,7 +631,9 @@ async def test_nft_mint_from_did_multiple_xch(self_hostname: str, two_wallet_nod
|
||||
[True, False],
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_nft_mint_from_xch(self_hostname: str, two_wallet_nodes: Any, trusted: Any) -> None:
|
||||
async def test_nft_mint_from_xch(
|
||||
self_hostname: str, two_wallet_nodes: Any, trusted: Any, seeded_random: random.Random
|
||||
) -> None:
|
||||
full_nodes, wallets, _ = two_wallet_nodes
|
||||
full_node_api: FullNodeSimulator = full_nodes[0]
|
||||
full_node_server = full_node_api.server
|
||||
@ -631,7 +643,7 @@ async def test_nft_mint_from_xch(self_hostname: str, two_wallet_nodes: Any, trus
|
||||
wallet_1 = wallet_node_1.wallet_state_manager.main_wallet
|
||||
api_0 = WalletRpcApi(wallet_node_0)
|
||||
ph_maker = await wallet_0.get_new_puzzlehash()
|
||||
ph_token = bytes32(token_bytes())
|
||||
ph_token = bytes32.random(seeded_random)
|
||||
|
||||
if trusted:
|
||||
wallet_node_0.config["trusted_peers"] = {
|
||||
@ -686,7 +698,7 @@ async def test_nft_mint_from_xch(self_hostname: str, two_wallet_nodes: Any, trus
|
||||
metadata_list = [
|
||||
{
|
||||
"program": Program.to(
|
||||
[("u", ["https://www.chia.net/img/branding/chia-logo.svg"]), ("h", token_bytes(32).hex())]
|
||||
[("u", ["https://www.chia.net/img/branding/chia-logo.svg"]), ("h", bytes32.random(seeded_random).hex())]
|
||||
),
|
||||
"royalty_pc": royalty_pc,
|
||||
"royalty_ph": royalty_addr,
|
||||
@ -733,7 +745,10 @@ async def test_nft_mint_from_xch(self_hostname: str, two_wallet_nodes: Any, trus
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_nft_mint_from_xch_rpc(
|
||||
two_wallet_nodes_services: SimulatorsAndWalletsServices, trusted: Any, self_hostname: str
|
||||
two_wallet_nodes_services: SimulatorsAndWalletsServices,
|
||||
trusted: Any,
|
||||
self_hostname: str,
|
||||
seeded_random: random.Random,
|
||||
) -> None:
|
||||
[full_node_service], wallet_services, bt = two_wallet_nodes_services
|
||||
full_node_api: FullNodeSimulator = full_node_service._api
|
||||
@ -747,7 +762,7 @@ async def test_nft_mint_from_xch_rpc(
|
||||
|
||||
ph_maker = await wallet_maker.get_new_puzzlehash()
|
||||
ph_taker = await wallet_taker.get_new_puzzlehash()
|
||||
ph_token = bytes32(token_bytes())
|
||||
ph_token = bytes32.random(seeded_random)
|
||||
|
||||
if trusted:
|
||||
wallet_node_maker.config["trusted_peers"] = {
|
||||
@ -825,11 +840,11 @@ async def test_nft_mint_from_xch_rpc(
|
||||
n = 10
|
||||
metadata_list = [
|
||||
{
|
||||
"hash": bytes32(token_bytes(32)).hex(),
|
||||
"hash": bytes32.random(seeded_random).hex(),
|
||||
"uris": ["https://data.com/{}".format(i)],
|
||||
"meta_hash": bytes32(token_bytes(32)).hex(),
|
||||
"meta_hash": bytes32.random(seeded_random).hex(),
|
||||
"meta_uris": ["https://meatadata.com/{}".format(i)],
|
||||
"license_hash": bytes32(token_bytes(32)).hex(),
|
||||
"license_hash": bytes32.random(seeded_random).hex(),
|
||||
"license_uris": ["https://license.com/{}".format(i)],
|
||||
"edition_number": i + 1,
|
||||
"edition_total": n,
|
||||
@ -837,7 +852,7 @@ async def test_nft_mint_from_xch_rpc(
|
||||
for i in range(n)
|
||||
]
|
||||
target_list = [encode_puzzle_hash((ph_taker), "xch") for x in range(n)]
|
||||
royalty_address = encode_puzzle_hash(bytes32(token_bytes(32)), "xch")
|
||||
royalty_address = encode_puzzle_hash(bytes32.random(seeded_random), "xch")
|
||||
royalty_percentage = 300
|
||||
fee = 100
|
||||
required_amount = n + (fee * n)
|
||||
@ -914,7 +929,9 @@ async def test_nft_mint_from_xch_rpc(
|
||||
[True, False],
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_nft_mint_from_xch_multiple_xch(self_hostname: str, two_wallet_nodes: Any, trusted: Any) -> None:
|
||||
async def test_nft_mint_from_xch_multiple_xch(
|
||||
self_hostname: str, two_wallet_nodes: Any, trusted: Any, seeded_random: random.Random
|
||||
) -> None:
|
||||
full_nodes, wallets, _ = two_wallet_nodes
|
||||
full_node_api: FullNodeSimulator = full_nodes[0]
|
||||
full_node_server = full_node_api.server
|
||||
@ -925,7 +942,7 @@ async def test_nft_mint_from_xch_multiple_xch(self_hostname: str, two_wallet_nod
|
||||
api_0 = WalletRpcApi(wallet_node_0)
|
||||
ph_maker = await wallet_maker.get_new_puzzlehash()
|
||||
ph_taker = await wallet_taker.get_new_puzzlehash()
|
||||
ph_token = bytes32(token_bytes())
|
||||
ph_token = bytes32.random(seeded_random)
|
||||
|
||||
if trusted:
|
||||
wallet_node_0.config["trusted_peers"] = {
|
||||
|
@ -1,6 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from secrets import token_bytes
|
||||
import random
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
import pytest
|
||||
@ -40,7 +40,9 @@ async def get_trade_and_status(trade_manager, trade) -> TradeStatus: # type: ig
|
||||
[True, False],
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_nft_offer_with_fee(self_hostname: str, two_wallet_nodes: Any, trusted: Any, reuse_puzhash: bool) -> None:
|
||||
async def test_nft_offer_with_fee(
|
||||
self_hostname: str, two_wallet_nodes: Any, trusted: Any, reuse_puzhash: bool, seeded_random: random.Random
|
||||
) -> None:
|
||||
full_nodes, wallets, _ = two_wallet_nodes
|
||||
full_node_api: FullNodeSimulator = full_nodes[0]
|
||||
full_node_server = full_node_api.server
|
||||
@ -53,7 +55,7 @@ async def test_nft_offer_with_fee(self_hostname: str, two_wallet_nodes: Any, tru
|
||||
|
||||
maker_ph = await wallet_maker.get_new_puzzlehash()
|
||||
taker_ph = await wallet_taker.get_new_puzzlehash()
|
||||
token_ph = bytes32(token_bytes())
|
||||
token_ph = bytes32.random(seeded_random)
|
||||
|
||||
if trusted:
|
||||
wallet_node_0.config["trusted_peers"] = {
|
||||
@ -233,7 +235,9 @@ async def test_nft_offer_with_fee(self_hostname: str, two_wallet_nodes: Any, tru
|
||||
[False],
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_nft_offer_cancellations(self_hostname: str, two_wallet_nodes: Any, trusted: Any) -> None:
|
||||
async def test_nft_offer_cancellations(
|
||||
self_hostname: str, two_wallet_nodes: Any, trusted: Any, seeded_random: random.Random
|
||||
) -> None:
|
||||
full_nodes, wallets, _ = two_wallet_nodes
|
||||
full_node_api: FullNodeSimulator = full_nodes[0]
|
||||
full_node_server = full_node_api.server
|
||||
@ -244,7 +248,7 @@ async def test_nft_offer_cancellations(self_hostname: str, two_wallet_nodes: Any
|
||||
|
||||
maker_ph = await wallet_maker.get_new_puzzlehash()
|
||||
taker_ph = await wallet_taker.get_new_puzzlehash()
|
||||
token_ph = bytes32(token_bytes())
|
||||
token_ph = bytes32.random(seeded_random)
|
||||
|
||||
if trusted:
|
||||
wallet_node_0.config["trusted_peers"] = {
|
||||
@ -344,7 +348,9 @@ async def test_nft_offer_cancellations(self_hostname: str, two_wallet_nodes: Any
|
||||
[False],
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_nft_offer_with_metadata_update(self_hostname: str, two_wallet_nodes: Any, trusted: Any) -> None:
|
||||
async def test_nft_offer_with_metadata_update(
|
||||
self_hostname: str, two_wallet_nodes: Any, trusted: Any, seeded_random: random.Random
|
||||
) -> None:
|
||||
full_nodes, wallets, _ = two_wallet_nodes
|
||||
full_node_api: FullNodeSimulator = full_nodes[0]
|
||||
full_node_server = full_node_api.server
|
||||
@ -355,7 +361,7 @@ async def test_nft_offer_with_metadata_update(self_hostname: str, two_wallet_nod
|
||||
|
||||
maker_ph = await wallet_maker.get_new_puzzlehash()
|
||||
taker_ph = await wallet_taker.get_new_puzzlehash()
|
||||
token_ph = bytes32(token_bytes())
|
||||
token_ph = bytes32.random(seeded_random)
|
||||
|
||||
if trusted:
|
||||
wallet_node_0.config["trusted_peers"] = {
|
||||
@ -482,7 +488,11 @@ async def test_nft_offer_with_metadata_update(self_hostname: str, two_wallet_nod
|
||||
@pytest.mark.parametrize("reuse_puzhash", [True, False])
|
||||
@pytest.mark.asyncio
|
||||
async def test_nft_offer_nft_for_cat(
|
||||
self_hostname: str, two_wallet_nodes: Any, trusted: Any, reuse_puzhash: bool
|
||||
self_hostname: str,
|
||||
two_wallet_nodes: Any,
|
||||
trusted: Any,
|
||||
reuse_puzhash: bool,
|
||||
seeded_random: random.Random,
|
||||
) -> None:
|
||||
full_nodes, wallets, _ = two_wallet_nodes
|
||||
full_node_api: FullNodeSimulator = full_nodes[0]
|
||||
@ -494,7 +504,7 @@ async def test_nft_offer_nft_for_cat(
|
||||
|
||||
maker_ph = await wallet_maker.get_new_puzzlehash()
|
||||
taker_ph = await wallet_taker.get_new_puzzlehash()
|
||||
token_ph = bytes32(token_bytes())
|
||||
token_ph = bytes32.random(seeded_random)
|
||||
|
||||
if trusted:
|
||||
wallet_node_0.config["trusted_peers"] = {
|
||||
@ -739,7 +749,9 @@ async def test_nft_offer_nft_for_cat(
|
||||
[False],
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_nft_offer_nft_for_nft(self_hostname: str, two_wallet_nodes: Any, trusted: Any) -> None:
|
||||
async def test_nft_offer_nft_for_nft(
|
||||
self_hostname: str, two_wallet_nodes: Any, trusted: Any, seeded_random: random.Random
|
||||
) -> None:
|
||||
full_nodes, wallets, _ = two_wallet_nodes
|
||||
full_node_api: FullNodeSimulator = full_nodes[0]
|
||||
full_node_server = full_node_api.server
|
||||
@ -750,7 +762,7 @@ async def test_nft_offer_nft_for_nft(self_hostname: str, two_wallet_nodes: Any,
|
||||
|
||||
maker_ph = await wallet_maker.get_new_puzzlehash()
|
||||
taker_ph = await wallet_taker.get_new_puzzlehash()
|
||||
token_ph = bytes32(token_bytes())
|
||||
token_ph = bytes32.random(seeded_random)
|
||||
|
||||
if trusted:
|
||||
wallet_node_0.config["trusted_peers"] = {
|
||||
|
@ -1,6 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from secrets import token_bytes
|
||||
import random
|
||||
from typing import Tuple
|
||||
|
||||
from clvm.casts import int_from_bytes
|
||||
@ -40,7 +40,7 @@ NFT_METADATA_UPDATER_DEFAULT = load_clvm(
|
||||
)
|
||||
|
||||
|
||||
def test_nft_transfer_puzzle_hashes():
|
||||
def test_nft_transfer_puzzle_hashes(seeded_random: random.Random):
|
||||
maker_pk = int_to_public_key(111)
|
||||
maker_p2_puz = puzzle_for_pk(maker_pk)
|
||||
maker_p2_ph = maker_p2_puz.get_tree_hash()
|
||||
@ -73,7 +73,11 @@ def test_nft_transfer_puzzle_hashes():
|
||||
nft_puz = SINGLETON_MOD.curry(SINGLETON_STRUCT, metadata_puz)
|
||||
|
||||
nft_info = match_puzzle(uncurry_puzzle(nft_puz))
|
||||
assert nft_info.also().also() is not None
|
||||
assert nft_info is not None
|
||||
also = nft_info.also()
|
||||
assert also is not None
|
||||
also_also = also.also()
|
||||
assert also_also is not None
|
||||
|
||||
unft = uncurry_nft.UncurriedNFT.uncurry(*nft_puz.uncurry())
|
||||
assert unft is not None
|
||||
@ -85,7 +89,7 @@ def test_nft_transfer_puzzle_hashes():
|
||||
taker_p2_ph = taker_p2_puz.get_tree_hash()
|
||||
|
||||
# make nft solution
|
||||
fake_lineage_proof = Program.to([token_bytes(32), maker_p2_ph, 1])
|
||||
fake_lineage_proof = Program.to([bytes32.random(seeded_random), maker_p2_ph, 1])
|
||||
transfer_conditions = Program.to([[51, taker_p2_ph, 1, [taker_p2_ph]], [-10, [], [], []]])
|
||||
|
||||
ownership_sol = Program.to([solution_for_conditions(transfer_conditions)])
|
||||
|
@ -4,8 +4,8 @@ import asyncio
|
||||
import dataclasses
|
||||
import json
|
||||
import logging
|
||||
import random
|
||||
from operator import attrgetter
|
||||
from secrets import token_bytes
|
||||
from typing import Any, Dict, List, Optional, Tuple, cast
|
||||
|
||||
import aiosqlite
|
||||
@ -1900,7 +1900,10 @@ async def test_get_coin_records_rpc(wallet_rpc_environment: WalletRpcTestEnviron
|
||||
|
||||
@pytest.mark.limit_consensus_modes(allowed=[ConsensusMode.PLAIN, ConsensusMode.HARD_FORK_2_0], reason="save time")
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_coin_records_rpc_limits(wallet_rpc_environment: WalletRpcTestEnvironment) -> None:
|
||||
async def test_get_coin_records_rpc_limits(
|
||||
wallet_rpc_environment: WalletRpcTestEnvironment,
|
||||
seeded_random: random.Random,
|
||||
) -> None:
|
||||
env: WalletRpcTestEnvironment = wallet_rpc_environment
|
||||
wallet_node: WalletNode = env.wallet_1.node
|
||||
client: WalletRpcClient = env.wallet_1.rpc_client
|
||||
@ -1916,8 +1919,10 @@ async def test_get_coin_records_rpc_limits(wallet_rpc_environment: WalletRpcTest
|
||||
max_coins = api.max_get_coin_records_limit * 10
|
||||
coin_records = [
|
||||
WalletCoinRecord(
|
||||
Coin(token_bytes(32), token_bytes(32), uint64.from_bytes(token_bytes(8))),
|
||||
uint32(uint32.from_bytes(token_bytes(4))),
|
||||
Coin(
|
||||
bytes32.random(seeded_random), bytes32.random(seeded_random), uint64(seeded_random.randrange(2**64))
|
||||
),
|
||||
uint32(seeded_random.randrange(2**32)),
|
||||
uint32(0),
|
||||
False,
|
||||
False,
|
||||
@ -1971,16 +1976,19 @@ async def test_get_coin_records_rpc_limits(wallet_rpc_environment: WalletRpcTest
|
||||
|
||||
@pytest.mark.limit_consensus_modes(allowed=[ConsensusMode.PLAIN, ConsensusMode.HARD_FORK_2_0], reason="save time")
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_coin_records_rpc_failures(wallet_rpc_environment: WalletRpcTestEnvironment) -> None:
|
||||
async def test_get_coin_records_rpc_failures(
|
||||
wallet_rpc_environment: WalletRpcTestEnvironment,
|
||||
seeded_random: random.Random,
|
||||
) -> None:
|
||||
env: WalletRpcTestEnvironment = wallet_rpc_environment
|
||||
client: WalletRpcClient = env.wallet_1.rpc_client
|
||||
rpc_server: Optional[RpcServer] = wallet_rpc_environment.wallet_1.service.rpc_server
|
||||
assert rpc_server is not None
|
||||
api = cast(WalletRpcApi, rpc_server.rpc_api)
|
||||
|
||||
too_many_hashes = [bytes32(token_bytes(32)) for _ in range(api.max_get_coin_records_filter_items + 1)]
|
||||
too_many_hashes = [bytes32.random(seeded_random) for _ in range(api.max_get_coin_records_filter_items + 1)]
|
||||
too_many_amounts = [
|
||||
uint64(uint64.from_bytes(token_bytes(8))) for _ in range(api.max_get_coin_records_filter_items + 1)
|
||||
uint64(uint64(seeded_random.randrange(2**64))) for _ in range(api.max_get_coin_records_filter_items + 1)
|
||||
]
|
||||
# Run requests which exceeds the allowed limit and contain too much filter items
|
||||
for name, request in {
|
||||
|
@ -1,7 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import random
|
||||
from dataclasses import dataclass, field
|
||||
from secrets import token_bytes
|
||||
from typing import Dict, List
|
||||
|
||||
import pytest
|
||||
@ -16,11 +16,11 @@ from chia.wallet.wallet_nft_store import WalletNftStore
|
||||
from tests.util.db_connection import DBConnection
|
||||
|
||||
|
||||
def get_dummy_nft() -> NFTCoinInfo:
|
||||
def get_dummy_nft(random_: random.Random) -> NFTCoinInfo:
|
||||
return NFTCoinInfo(
|
||||
bytes32(token_bytes(32)),
|
||||
Coin(bytes32(token_bytes(32)), bytes32(token_bytes(32)), uint64(1)),
|
||||
LineageProof(bytes32(token_bytes(32)), bytes32(token_bytes(32)), uint64(1)),
|
||||
bytes32.random(random_),
|
||||
Coin(bytes32.random(random_), bytes32.random(random_), uint64(1)),
|
||||
LineageProof(bytes32.random(random_), bytes32.random(random_), uint64(1)),
|
||||
Program.to(["A Test puzzle"]),
|
||||
uint32(1),
|
||||
)
|
||||
@ -28,12 +28,13 @@ def get_dummy_nft() -> NFTCoinInfo:
|
||||
|
||||
@dataclass
|
||||
class DummyNFTs:
|
||||
seeded_random: random.Random
|
||||
nfts_per_wallet: Dict[uint32, List[NFTCoinInfo]] = field(default_factory=dict)
|
||||
|
||||
def generate(self, wallet_id: int, count: int) -> None:
|
||||
nfts = self.nfts_per_wallet.setdefault(uint32(wallet_id), [])
|
||||
for _ in range(count):
|
||||
nfts.append(get_dummy_nft())
|
||||
nfts.append(get_dummy_nft(random_=self.seeded_random))
|
||||
|
||||
|
||||
class TestNftStore:
|
||||
@ -171,8 +172,8 @@ class TestNftStore:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_delete_wallet() -> None:
|
||||
dummy_nfts = DummyNFTs()
|
||||
async def test_delete_wallet(seeded_random: random.Random) -> None:
|
||||
dummy_nfts = DummyNFTs(seeded_random=seeded_random)
|
||||
for i in range(5):
|
||||
dummy_nfts.generate(i, i * 5)
|
||||
async with DBConnection(1) as wrapper:
|
||||
|
@ -1,8 +1,8 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import random
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
from secrets import token_bytes
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
@ -54,7 +54,9 @@ async def test_notification_store_backwards_compat() -> None:
|
||||
[True, False],
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_notifications(self_hostname: str, two_wallet_nodes: Any, trusted: Any) -> None:
|
||||
async def test_notifications(
|
||||
self_hostname: str, two_wallet_nodes: Any, trusted: Any, seeded_random: random.Random
|
||||
) -> None:
|
||||
full_nodes, wallets, _ = two_wallet_nodes
|
||||
full_node_api: FullNodeSimulator = full_nodes[0]
|
||||
full_node_server = full_node_api.server
|
||||
@ -67,7 +69,7 @@ async def test_notifications(self_hostname: str, two_wallet_nodes: Any, trusted:
|
||||
|
||||
ph_1 = await wallet_1.get_new_puzzlehash()
|
||||
ph_2 = await wallet_2.get_new_puzzlehash()
|
||||
ph_token = bytes32(token_bytes())
|
||||
ph_token = bytes32.random(seeded_random)
|
||||
|
||||
if trusted:
|
||||
wallet_node_1.config["trusted_peers"] = {
|
||||
|
@ -1,7 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import random
|
||||
from dataclasses import dataclass, field
|
||||
from secrets import token_bytes
|
||||
from typing import Dict, List
|
||||
|
||||
import pytest
|
||||
@ -15,11 +15,11 @@ from chia.wallet.wallet_puzzle_store import WalletPuzzleStore
|
||||
from tests.util.db_connection import DBConnection
|
||||
|
||||
|
||||
def get_dummy_record(index: int, wallet_id: int) -> DerivationRecord:
|
||||
def get_dummy_record(index: int, wallet_id: int, seeded_random: random.Random) -> DerivationRecord:
|
||||
return DerivationRecord(
|
||||
uint32(index),
|
||||
bytes32(token_bytes(32)),
|
||||
AugSchemeMPL.key_gen(token_bytes(32)).get_g1(),
|
||||
bytes32.random(seeded_random),
|
||||
AugSchemeMPL.key_gen(bytes32.random(seeded_random)).get_g1(),
|
||||
WalletType.STANDARD_WALLET,
|
||||
uint32(wallet_id),
|
||||
False,
|
||||
@ -28,6 +28,7 @@ def get_dummy_record(index: int, wallet_id: int) -> DerivationRecord:
|
||||
|
||||
@dataclass
|
||||
class DummyDerivationRecords:
|
||||
seeded_random: random.Random
|
||||
index_per_wallet: Dict[int, int] = field(default_factory=dict)
|
||||
records_per_wallet: Dict[int, List[DerivationRecord]] = field(default_factory=dict)
|
||||
|
||||
@ -35,13 +36,15 @@ class DummyDerivationRecords:
|
||||
records = self.records_per_wallet.setdefault(wallet_id, [])
|
||||
self.index_per_wallet.setdefault(wallet_id, 0)
|
||||
for _ in range(count):
|
||||
records.append(get_dummy_record(self.index_per_wallet[wallet_id], wallet_id))
|
||||
records.append(
|
||||
get_dummy_record(self.index_per_wallet[wallet_id], wallet_id, seeded_random=self.seeded_random)
|
||||
)
|
||||
self.index_per_wallet[wallet_id] += 1
|
||||
|
||||
|
||||
class TestPuzzleStore:
|
||||
@pytest.mark.asyncio
|
||||
async def test_puzzle_store(self):
|
||||
async def test_puzzle_store(self, seeded_random: random.Random):
|
||||
async with DBConnection(1) as wrapper:
|
||||
db = await WalletPuzzleStore.create(wrapper)
|
||||
derivation_recs = []
|
||||
@ -49,8 +52,8 @@ class TestPuzzleStore:
|
||||
derivation_recs.append(
|
||||
DerivationRecord(
|
||||
uint32(i),
|
||||
token_bytes(32),
|
||||
AugSchemeMPL.key_gen(token_bytes(32)).get_g1(),
|
||||
bytes32.random(seeded_random),
|
||||
AugSchemeMPL.key_gen(bytes32.random(seeded_random)).get_g1(),
|
||||
WalletType.STANDARD_WALLET,
|
||||
uint32(1),
|
||||
False,
|
||||
@ -59,8 +62,8 @@ class TestPuzzleStore:
|
||||
derivation_recs.append(
|
||||
DerivationRecord(
|
||||
uint32(i),
|
||||
token_bytes(32),
|
||||
AugSchemeMPL.key_gen(token_bytes(32)).get_g1(),
|
||||
bytes32.random(seeded_random),
|
||||
AugSchemeMPL.key_gen(bytes32.random(seeded_random)).get_g1(),
|
||||
WalletType.CAT,
|
||||
uint32(2),
|
||||
False,
|
||||
@ -97,8 +100,8 @@ class TestPuzzleStore:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_delete_wallet() -> None:
|
||||
dummy_records = DummyDerivationRecords()
|
||||
async def test_delete_wallet(seeded_random: random.Random) -> None:
|
||||
dummy_records = DummyDerivationRecords(seeded_random=seeded_random)
|
||||
for i in range(5):
|
||||
dummy_records.generate(i, i * 5)
|
||||
async with DBConnection(1) as wrapper:
|
||||
|
@ -1,7 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import dataclasses
|
||||
from secrets import token_bytes
|
||||
import random
|
||||
from typing import Any, List, Optional, Tuple
|
||||
|
||||
import pytest
|
||||
@ -18,14 +18,17 @@ from chia.wallet.util.transaction_type import TransactionType
|
||||
from chia.wallet.wallet_transaction_store import WalletTransactionStore, filter_ok_mempool_status
|
||||
from tests.util.db_connection import DBConnection
|
||||
|
||||
coin_1 = Coin(token_bytes(32), token_bytes(32), uint64(12312))
|
||||
coin_2 = Coin(token_bytes(32), token_bytes(32), uint64(1234))
|
||||
coin_3 = Coin(token_bytes(32), token_bytes(32), uint64(12312 - 1234))
|
||||
module_seeded_random = random.Random()
|
||||
module_seeded_random.seed(a=0, version=2)
|
||||
|
||||
coin_1 = Coin(bytes32.random(module_seeded_random), bytes32.random(module_seeded_random), uint64(12312))
|
||||
coin_2 = Coin(bytes32.random(module_seeded_random), bytes32.random(module_seeded_random), uint64(1234))
|
||||
coin_3 = Coin(bytes32.random(module_seeded_random), bytes32.random(module_seeded_random), uint64(12312 - 1234))
|
||||
|
||||
tr1 = TransactionRecord(
|
||||
uint32(0), # confirmed height
|
||||
uint64(1000), # created_at_time
|
||||
bytes32(token_bytes(32)), # to_puzzle_hash
|
||||
bytes32(bytes32.random(module_seeded_random)), # to_puzzle_hash
|
||||
uint64(1234), # amount
|
||||
uint64(12), # fee_amount
|
||||
False, # confirmed
|
||||
@ -35,9 +38,9 @@ tr1 = TransactionRecord(
|
||||
[coin_1], # removals
|
||||
uint32(1), # wallet_id
|
||||
[], # List[Tuple[str, uint8, Optional[str]]] sent_to
|
||||
bytes32(token_bytes(32)), # trade_id
|
||||
bytes32(bytes32.random(module_seeded_random)), # trade_id
|
||||
uint32(TransactionType.OUTGOING_TX), # type
|
||||
bytes32(token_bytes(32)), # name
|
||||
bytes32(bytes32.random(module_seeded_random)), # name
|
||||
[], # List[Tuple[bytes32, List[bytes]]] memos
|
||||
ConditionValidTimes(),
|
||||
)
|
||||
@ -78,12 +81,15 @@ async def test_set_confirmed() -> None:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_increment_sent_noop() -> None:
|
||||
async def test_increment_sent_noop(seeded_random: random.Random) -> None:
|
||||
async with DBConnection(1) as db_wrapper:
|
||||
store = await WalletTransactionStore.create(db_wrapper)
|
||||
|
||||
assert (
|
||||
await store.increment_sent(bytes32(token_bytes(32)), "peer1", MempoolInclusionStatus.PENDING, None) is False
|
||||
await store.increment_sent(
|
||||
bytes32(bytes32.random(seeded_random)), "peer1", MempoolInclusionStatus.PENDING, None
|
||||
)
|
||||
is False
|
||||
)
|
||||
|
||||
|
||||
@ -175,12 +181,12 @@ async def test_tx_reorged_add() -> None:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_tx_record() -> None:
|
||||
async def test_get_tx_record(seeded_random: random.Random) -> None:
|
||||
async with DBConnection(1) as db_wrapper:
|
||||
store = await WalletTransactionStore.create(db_wrapper)
|
||||
|
||||
tr2 = dataclasses.replace(tr1, name=token_bytes(32))
|
||||
tr3 = dataclasses.replace(tr1, name=token_bytes(32))
|
||||
tr2 = dataclasses.replace(tr1, name=bytes32.random(seeded_random))
|
||||
tr3 = dataclasses.replace(tr1, name=bytes32.random(seeded_random))
|
||||
|
||||
assert await store.get_transaction_record(tr1.name) is None
|
||||
await store.add_transaction_record(tr1)
|
||||
@ -200,7 +206,7 @@ async def test_get_tx_record() -> None:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_farming_rewards() -> None:
|
||||
async def test_get_farming_rewards(seeded_random: random.Random) -> None:
|
||||
async with DBConnection(1) as db_wrapper:
|
||||
store = await WalletTransactionStore.create(db_wrapper)
|
||||
|
||||
@ -219,7 +225,7 @@ async def test_get_farming_rewards() -> None:
|
||||
test_trs.append(
|
||||
dataclasses.replace(
|
||||
tr1,
|
||||
name=token_bytes(32),
|
||||
name=bytes32.random(seeded_random),
|
||||
confirmed=conf,
|
||||
confirmed_at_height=uint32(100 if conf else 0),
|
||||
type=type,
|
||||
@ -237,11 +243,13 @@ async def test_get_farming_rewards() -> None:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_all_unconfirmed() -> None:
|
||||
async def test_get_all_unconfirmed(seeded_random: random.Random) -> None:
|
||||
async with DBConnection(1) as db_wrapper:
|
||||
store = await WalletTransactionStore.create(db_wrapper)
|
||||
|
||||
tr2 = dataclasses.replace(tr1, name=token_bytes(32), confirmed=True, confirmed_at_height=uint32(100))
|
||||
tr2 = dataclasses.replace(
|
||||
tr1, name=bytes32.random(seeded_random), confirmed=True, confirmed_at_height=uint32(100)
|
||||
)
|
||||
await store.add_transaction_record(tr1)
|
||||
await store.add_transaction_record(tr2)
|
||||
|
||||
@ -249,13 +257,15 @@ async def test_get_all_unconfirmed() -> None:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_unconfirmed_for_wallet() -> None:
|
||||
async def test_get_unconfirmed_for_wallet(seeded_random: random.Random) -> None:
|
||||
async with DBConnection(1) as db_wrapper:
|
||||
store = await WalletTransactionStore.create(db_wrapper)
|
||||
|
||||
tr2 = dataclasses.replace(tr1, name=token_bytes(32), confirmed=True, confirmed_at_height=uint32(100))
|
||||
tr3 = dataclasses.replace(tr1, name=token_bytes(32), wallet_id=uint32(2))
|
||||
tr4 = dataclasses.replace(tr2, name=token_bytes(32), wallet_id=uint32(2))
|
||||
tr2 = dataclasses.replace(
|
||||
tr1, name=bytes32.random(seeded_random), confirmed=True, confirmed_at_height=uint32(100)
|
||||
)
|
||||
tr3 = dataclasses.replace(tr1, name=bytes32.random(seeded_random), wallet_id=uint32(2))
|
||||
tr4 = dataclasses.replace(tr2, name=bytes32.random(seeded_random), wallet_id=uint32(2))
|
||||
await store.add_transaction_record(tr1)
|
||||
await store.add_transaction_record(tr2)
|
||||
await store.add_transaction_record(tr3)
|
||||
@ -266,22 +276,22 @@ async def test_get_unconfirmed_for_wallet() -> None:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_transaction_count_for_wallet() -> None:
|
||||
async def test_transaction_count_for_wallet(seeded_random: random.Random) -> None:
|
||||
async with DBConnection(1) as db_wrapper:
|
||||
store = await WalletTransactionStore.create(db_wrapper)
|
||||
|
||||
tr2 = dataclasses.replace(tr1, name=token_bytes(32), wallet_id=uint32(2))
|
||||
tr2 = dataclasses.replace(tr1, name=bytes32.random(seeded_random), wallet_id=uint32(2))
|
||||
|
||||
# 5 transactions in wallet_id 1
|
||||
await store.add_transaction_record(tr1)
|
||||
await store.add_transaction_record(dataclasses.replace(tr1, name=token_bytes(32)))
|
||||
await store.add_transaction_record(dataclasses.replace(tr1, name=token_bytes(32)))
|
||||
await store.add_transaction_record(dataclasses.replace(tr1, name=token_bytes(32)))
|
||||
await store.add_transaction_record(dataclasses.replace(tr1, name=token_bytes(32)))
|
||||
await store.add_transaction_record(dataclasses.replace(tr1, name=bytes32.random(seeded_random)))
|
||||
await store.add_transaction_record(dataclasses.replace(tr1, name=bytes32.random(seeded_random)))
|
||||
await store.add_transaction_record(dataclasses.replace(tr1, name=bytes32.random(seeded_random)))
|
||||
await store.add_transaction_record(dataclasses.replace(tr1, name=bytes32.random(seeded_random)))
|
||||
|
||||
# 2 transactions in wallet_id 2
|
||||
await store.add_transaction_record(tr2)
|
||||
await store.add_transaction_record(dataclasses.replace(tr2, name=token_bytes(32)))
|
||||
await store.add_transaction_record(dataclasses.replace(tr2, name=bytes32.random(seeded_random)))
|
||||
|
||||
assert await store.get_transaction_count_for_wallet(1) == 5
|
||||
assert await store.get_transaction_count_for_wallet(2) == 2
|
||||
@ -306,7 +316,7 @@ async def test_transaction_count_for_wallet() -> None:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_all_transactions_for_wallet() -> None:
|
||||
async def test_all_transactions_for_wallet(seeded_random: random.Random) -> None:
|
||||
async with DBConnection(1) as db_wrapper:
|
||||
store = await WalletTransactionStore.create(db_wrapper)
|
||||
|
||||
@ -320,7 +330,9 @@ async def test_all_transactions_for_wallet() -> None:
|
||||
TransactionType.INCOMING_TRADE,
|
||||
TransactionType.OUTGOING_TRADE,
|
||||
]:
|
||||
test_trs.append(dataclasses.replace(tr1, name=token_bytes(32), wallet_id=uint32(wallet_id), type=type))
|
||||
test_trs.append(
|
||||
dataclasses.replace(tr1, name=bytes32.random(seeded_random), wallet_id=uint32(wallet_id), type=type)
|
||||
)
|
||||
|
||||
for tr in test_trs:
|
||||
await store.add_transaction_record(tr)
|
||||
@ -350,14 +362,14 @@ def cmp(lhs: List[Any], rhs: List[Any]) -> bool:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_all_transactions() -> None:
|
||||
async def test_get_all_transactions(seeded_random: random.Random) -> None:
|
||||
async with DBConnection(1) as db_wrapper:
|
||||
store = await WalletTransactionStore.create(db_wrapper)
|
||||
|
||||
test_trs: List[TransactionRecord] = []
|
||||
assert await store.get_all_transactions() == []
|
||||
for wallet_id in [1, 2, 3, 4]:
|
||||
test_trs.append(dataclasses.replace(tr1, name=token_bytes(32), wallet_id=uint32(wallet_id)))
|
||||
test_trs.append(dataclasses.replace(tr1, name=bytes32.random(seeded_random), wallet_id=uint32(wallet_id)))
|
||||
|
||||
for tr in test_trs:
|
||||
await store.add_transaction_record(tr)
|
||||
@ -367,14 +379,16 @@ async def test_get_all_transactions() -> None:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_transaction_above() -> None:
|
||||
async def test_get_transaction_above(seeded_random: random.Random) -> None:
|
||||
async with DBConnection(1) as db_wrapper:
|
||||
store = await WalletTransactionStore.create(db_wrapper)
|
||||
|
||||
test_trs: List[TransactionRecord] = []
|
||||
assert await store.get_transaction_above(uint32(0)) == []
|
||||
for height in range(10):
|
||||
test_trs.append(dataclasses.replace(tr1, name=token_bytes(32), confirmed_at_height=uint32(height)))
|
||||
test_trs.append(
|
||||
dataclasses.replace(tr1, name=bytes32.random(seeded_random), confirmed_at_height=uint32(height))
|
||||
)
|
||||
|
||||
for tr in test_trs:
|
||||
await store.add_transaction_record(tr)
|
||||
@ -385,13 +399,13 @@ async def test_get_transaction_above() -> None:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_tx_by_trade_id() -> None:
|
||||
async def test_get_tx_by_trade_id(seeded_random: random.Random) -> None:
|
||||
async with DBConnection(1) as db_wrapper:
|
||||
store = await WalletTransactionStore.create(db_wrapper)
|
||||
|
||||
tr2 = dataclasses.replace(tr1, name=token_bytes(32), trade_id=token_bytes(32))
|
||||
tr3 = dataclasses.replace(tr1, name=token_bytes(32), trade_id=token_bytes(32))
|
||||
tr4 = dataclasses.replace(tr1, name=token_bytes(32))
|
||||
tr2 = dataclasses.replace(tr1, name=bytes32.random(seeded_random), trade_id=bytes32.random(seeded_random))
|
||||
tr3 = dataclasses.replace(tr1, name=bytes32.random(seeded_random), trade_id=bytes32.random(seeded_random))
|
||||
tr4 = dataclasses.replace(tr1, name=bytes32.random(seeded_random))
|
||||
|
||||
assert await store.get_transactions_by_trade_id(tr1.trade_id) == []
|
||||
await store.add_transaction_record(tr1)
|
||||
@ -417,13 +431,15 @@ async def test_get_tx_by_trade_id() -> None:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_rollback_to_block() -> None:
|
||||
async def test_rollback_to_block(seeded_random: random.Random) -> None:
|
||||
async with DBConnection(1) as db_wrapper:
|
||||
store = await WalletTransactionStore.create(db_wrapper)
|
||||
|
||||
test_trs: List[TransactionRecord] = []
|
||||
for height in range(10):
|
||||
test_trs.append(dataclasses.replace(tr1, name=token_bytes(32), confirmed_at_height=uint32(height)))
|
||||
test_trs.append(
|
||||
dataclasses.replace(tr1, name=bytes32.random(seeded_random), confirmed_at_height=uint32(height))
|
||||
)
|
||||
|
||||
for tr in test_trs:
|
||||
await store.add_transaction_record(tr)
|
||||
@ -438,15 +454,18 @@ async def test_rollback_to_block() -> None:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_delete_unconfirmed() -> None:
|
||||
async def test_delete_unconfirmed(seeded_random: random.Random) -> None:
|
||||
async with DBConnection(1) as db_wrapper:
|
||||
store = await WalletTransactionStore.create(db_wrapper)
|
||||
|
||||
tr2 = dataclasses.replace(tr1, name=token_bytes(32), confirmed=True)
|
||||
tr3 = dataclasses.replace(tr1, name=token_bytes(32), confirmed=True, wallet_id=uint32(2))
|
||||
tr4 = dataclasses.replace(tr1, name=token_bytes(32), wallet_id=uint32(2))
|
||||
tr2 = dataclasses.replace(tr1, name=bytes32.random(seeded_random), confirmed=True)
|
||||
tr3 = dataclasses.replace(tr1, name=bytes32.random(seeded_random), confirmed=True, wallet_id=uint32(2))
|
||||
tr4 = dataclasses.replace(tr1, name=bytes32.random(seeded_random), wallet_id=uint32(2))
|
||||
tr5 = dataclasses.replace(
|
||||
tr1, name=token_bytes(32), wallet_id=uint32(2), type=uint32(TransactionType.INCOMING_CLAWBACK_RECEIVE.value)
|
||||
tr1,
|
||||
name=bytes32.random(seeded_random),
|
||||
wallet_id=uint32(2),
|
||||
type=uint32(TransactionType.INCOMING_CLAWBACK_RECEIVE.value),
|
||||
)
|
||||
|
||||
await store.add_transaction_record(tr1)
|
||||
@ -463,16 +482,27 @@ async def test_delete_unconfirmed() -> None:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_transactions_between_confirmed() -> None:
|
||||
async def test_get_transactions_between_confirmed(seeded_random: random.Random) -> None:
|
||||
async with DBConnection(1) as db_wrapper:
|
||||
store = await WalletTransactionStore.create(db_wrapper)
|
||||
|
||||
tr2 = dataclasses.replace(tr1, name=token_bytes(32), confirmed=True, confirmed_at_height=uint32(1))
|
||||
tr3 = dataclasses.replace(tr1, name=token_bytes(32), confirmed=True, confirmed_at_height=uint32(2))
|
||||
tr4 = dataclasses.replace(tr1, name=token_bytes(32), confirmed=True, confirmed_at_height=uint32(3))
|
||||
tr5 = dataclasses.replace(tr1, name=token_bytes(32), confirmed=True, confirmed_at_height=uint32(4))
|
||||
tr2 = dataclasses.replace(
|
||||
tr1, name=bytes32.random(seeded_random), confirmed=True, confirmed_at_height=uint32(1)
|
||||
)
|
||||
tr3 = dataclasses.replace(
|
||||
tr1, name=bytes32.random(seeded_random), confirmed=True, confirmed_at_height=uint32(2)
|
||||
)
|
||||
tr4 = dataclasses.replace(
|
||||
tr1, name=bytes32.random(seeded_random), confirmed=True, confirmed_at_height=uint32(3)
|
||||
)
|
||||
tr5 = dataclasses.replace(
|
||||
tr1, name=bytes32.random(seeded_random), confirmed=True, confirmed_at_height=uint32(4)
|
||||
)
|
||||
tr6 = dataclasses.replace(
|
||||
tr1, name=token_bytes(32), confirmed_at_height=uint32(5), type=uint32(TransactionType.COINBASE_REWARD.value)
|
||||
tr1,
|
||||
name=bytes32.random(seeded_random),
|
||||
confirmed_at_height=uint32(5),
|
||||
type=uint32(TransactionType.COINBASE_REWARD.value),
|
||||
)
|
||||
|
||||
await store.add_transaction_record(tr1)
|
||||
@ -544,34 +574,66 @@ async def test_get_transactions_between_confirmed() -> None:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_transactions_between_relevance() -> None:
|
||||
async def test_get_transactions_between_relevance(seeded_random: random.Random) -> None:
|
||||
async with DBConnection(1) as db_wrapper:
|
||||
store = await WalletTransactionStore.create(db_wrapper)
|
||||
|
||||
t1 = dataclasses.replace(
|
||||
tr1, name=token_bytes(32), confirmed=False, confirmed_at_height=uint32(2), created_at_time=uint32(1000)
|
||||
tr1,
|
||||
name=bytes32.random(seeded_random),
|
||||
confirmed=False,
|
||||
confirmed_at_height=uint32(2),
|
||||
created_at_time=uint32(1000),
|
||||
)
|
||||
t2 = dataclasses.replace(
|
||||
tr1, name=token_bytes(32), confirmed=False, confirmed_at_height=uint32(2), created_at_time=uint32(999)
|
||||
tr1,
|
||||
name=bytes32.random(seeded_random),
|
||||
confirmed=False,
|
||||
confirmed_at_height=uint32(2),
|
||||
created_at_time=uint32(999),
|
||||
)
|
||||
t3 = dataclasses.replace(
|
||||
tr1, name=token_bytes(32), confirmed=False, confirmed_at_height=uint32(1), created_at_time=uint32(1000)
|
||||
tr1,
|
||||
name=bytes32.random(seeded_random),
|
||||
confirmed=False,
|
||||
confirmed_at_height=uint32(1),
|
||||
created_at_time=uint32(1000),
|
||||
)
|
||||
t4 = dataclasses.replace(
|
||||
tr1, name=token_bytes(32), confirmed=False, confirmed_at_height=uint32(1), created_at_time=uint32(999)
|
||||
tr1,
|
||||
name=bytes32.random(seeded_random),
|
||||
confirmed=False,
|
||||
confirmed_at_height=uint32(1),
|
||||
created_at_time=uint32(999),
|
||||
)
|
||||
|
||||
t5 = dataclasses.replace(
|
||||
tr1, name=token_bytes(32), confirmed=True, confirmed_at_height=uint32(2), created_at_time=uint32(1000)
|
||||
tr1,
|
||||
name=bytes32.random(seeded_random),
|
||||
confirmed=True,
|
||||
confirmed_at_height=uint32(2),
|
||||
created_at_time=uint32(1000),
|
||||
)
|
||||
t6 = dataclasses.replace(
|
||||
tr1, name=token_bytes(32), confirmed=True, confirmed_at_height=uint32(2), created_at_time=uint32(999)
|
||||
tr1,
|
||||
name=bytes32.random(seeded_random),
|
||||
confirmed=True,
|
||||
confirmed_at_height=uint32(2),
|
||||
created_at_time=uint32(999),
|
||||
)
|
||||
t7 = dataclasses.replace(
|
||||
tr1, name=token_bytes(32), confirmed=True, confirmed_at_height=uint32(1), created_at_time=uint32(1000)
|
||||
tr1,
|
||||
name=bytes32.random(seeded_random),
|
||||
confirmed=True,
|
||||
confirmed_at_height=uint32(1),
|
||||
created_at_time=uint32(1000),
|
||||
)
|
||||
t8 = dataclasses.replace(
|
||||
tr1, name=token_bytes(32), confirmed=True, confirmed_at_height=uint32(1), created_at_time=uint32(999)
|
||||
tr1,
|
||||
name=bytes32.random(seeded_random),
|
||||
confirmed=True,
|
||||
confirmed_at_height=uint32(1),
|
||||
created_at_time=uint32(999),
|
||||
)
|
||||
|
||||
await store.add_transaction_record(t1)
|
||||
@ -643,17 +705,25 @@ async def test_get_transactions_between_relevance() -> None:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_transactions_between_to_puzzle_hash() -> None:
|
||||
async def test_get_transactions_between_to_puzzle_hash(seeded_random: random.Random) -> None:
|
||||
async with DBConnection(1) as db_wrapper:
|
||||
store = await WalletTransactionStore.create(db_wrapper)
|
||||
|
||||
ph1 = token_bytes(32)
|
||||
ph2 = token_bytes(32)
|
||||
ph1 = bytes32.random(seeded_random)
|
||||
ph2 = bytes32.random(seeded_random)
|
||||
|
||||
tr2 = dataclasses.replace(tr1, name=token_bytes(32), confirmed_at_height=uint32(1), to_puzzle_hash=ph1)
|
||||
tr3 = dataclasses.replace(tr1, name=token_bytes(32), confirmed_at_height=uint32(2), to_puzzle_hash=ph1)
|
||||
tr4 = dataclasses.replace(tr1, name=token_bytes(32), confirmed_at_height=uint32(3), to_puzzle_hash=ph2)
|
||||
tr5 = dataclasses.replace(tr1, name=token_bytes(32), confirmed_at_height=uint32(4), to_puzzle_hash=ph2)
|
||||
tr2 = dataclasses.replace(
|
||||
tr1, name=bytes32.random(seeded_random), confirmed_at_height=uint32(1), to_puzzle_hash=ph1
|
||||
)
|
||||
tr3 = dataclasses.replace(
|
||||
tr1, name=bytes32.random(seeded_random), confirmed_at_height=uint32(2), to_puzzle_hash=ph1
|
||||
)
|
||||
tr4 = dataclasses.replace(
|
||||
tr1, name=bytes32.random(seeded_random), confirmed_at_height=uint32(3), to_puzzle_hash=ph2
|
||||
)
|
||||
tr5 = dataclasses.replace(
|
||||
tr1, name=bytes32.random(seeded_random), confirmed_at_height=uint32(4), to_puzzle_hash=ph2
|
||||
)
|
||||
|
||||
await store.add_transaction_record(tr1)
|
||||
await store.add_transaction_record(tr2)
|
||||
@ -681,13 +751,15 @@ async def test_get_transactions_between_to_puzzle_hash() -> None:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_not_sent() -> None:
|
||||
async def test_get_not_sent(seeded_random: random.Random) -> None:
|
||||
async with DBConnection(1) as db_wrapper:
|
||||
store = await WalletTransactionStore.create(db_wrapper)
|
||||
|
||||
tr2 = dataclasses.replace(tr1, name=token_bytes(32), confirmed=True, confirmed_at_height=uint32(1))
|
||||
tr3 = dataclasses.replace(tr1, name=token_bytes(32))
|
||||
tr4 = dataclasses.replace(tr1, name=token_bytes(32))
|
||||
tr2 = dataclasses.replace(
|
||||
tr1, name=bytes32.random(seeded_random), confirmed=True, confirmed_at_height=uint32(1)
|
||||
)
|
||||
tr3 = dataclasses.replace(tr1, name=bytes32.random(seeded_random))
|
||||
tr4 = dataclasses.replace(tr1, name=bytes32.random(seeded_random))
|
||||
|
||||
await store.add_transaction_record(tr1)
|
||||
await store.add_transaction_record(tr2)
|
||||
|
@ -1,7 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import random
|
||||
from dataclasses import dataclass, field, replace
|
||||
from secrets import token_bytes
|
||||
from typing import Dict, List, Optional, Tuple
|
||||
|
||||
import pytest
|
||||
@ -20,15 +20,18 @@ from tests.util.db_connection import DBConnection
|
||||
|
||||
clawback_metadata = ClawbackMetadata(uint64(0), bytes32(b"1" * 32), bytes32(b"2" * 32))
|
||||
|
||||
coin_1 = Coin(token_bytes(32), token_bytes(32), uint64(12312))
|
||||
coin_2 = Coin(coin_1.parent_coin_info, token_bytes(32), uint64(12311))
|
||||
coin_3 = Coin(token_bytes(32), token_bytes(32), uint64(12312))
|
||||
coin_4 = Coin(token_bytes(32), token_bytes(32), uint64(12312))
|
||||
coin_5 = Coin(token_bytes(32), token_bytes(32), uint64(12312))
|
||||
coin_6 = Coin(token_bytes(32), coin_4.puzzle_hash, uint64(12312))
|
||||
coin_7 = Coin(token_bytes(32), token_bytes(32), uint64(12312))
|
||||
coin_8 = Coin(token_bytes(32), token_bytes(32), uint64(2))
|
||||
coin_9 = Coin(coin_5.name(), token_bytes(32), uint64(4))
|
||||
module_seeded_random = random.Random()
|
||||
module_seeded_random.seed(a=0, version=2)
|
||||
|
||||
coin_1 = Coin(bytes32.random(module_seeded_random), bytes32.random(module_seeded_random), uint64(12312))
|
||||
coin_2 = Coin(coin_1.parent_coin_info, bytes32.random(module_seeded_random), uint64(12311))
|
||||
coin_3 = Coin(bytes32.random(module_seeded_random), bytes32.random(module_seeded_random), uint64(12312))
|
||||
coin_4 = Coin(bytes32.random(module_seeded_random), bytes32.random(module_seeded_random), uint64(12312))
|
||||
coin_5 = Coin(bytes32.random(module_seeded_random), bytes32.random(module_seeded_random), uint64(12312))
|
||||
coin_6 = Coin(bytes32.random(module_seeded_random), coin_4.puzzle_hash, uint64(12312))
|
||||
coin_7 = Coin(bytes32.random(module_seeded_random), bytes32.random(module_seeded_random), uint64(12312))
|
||||
coin_8 = Coin(bytes32.random(module_seeded_random), bytes32.random(module_seeded_random), uint64(2))
|
||||
coin_9 = Coin(coin_5.name(), bytes32.random(module_seeded_random), uint64(4))
|
||||
record_replaced = WalletCoinRecord(coin_1, uint32(8), uint32(0), False, True, WalletType.STANDARD_WALLET, 0)
|
||||
record_1 = WalletCoinRecord(coin_1, uint32(4), uint32(0), False, True, WalletType.STANDARD_WALLET, 0)
|
||||
record_2 = WalletCoinRecord(coin_2, uint32(5), uint32(0), False, True, WalletType.STANDARD_WALLET, 0)
|
||||
@ -101,9 +104,9 @@ record_9 = WalletCoinRecord(
|
||||
)
|
||||
|
||||
|
||||
def get_dummy_record(wallet_id: int) -> WalletCoinRecord:
|
||||
def get_dummy_record(wallet_id: int, seeded_random: random.Random) -> WalletCoinRecord:
|
||||
return WalletCoinRecord(
|
||||
Coin(token_bytes(32), token_bytes(32), uint64(12312)),
|
||||
Coin(bytes32.random(seeded_random), bytes32.random(seeded_random), uint64(12312)),
|
||||
uint32(0),
|
||||
uint32(0),
|
||||
False,
|
||||
@ -115,12 +118,13 @@ def get_dummy_record(wallet_id: int) -> WalletCoinRecord:
|
||||
|
||||
@dataclass
|
||||
class DummyWalletCoinRecords:
|
||||
seeded_random: random.Random
|
||||
records_per_wallet: Dict[int, List[WalletCoinRecord]] = field(default_factory=dict)
|
||||
|
||||
def generate(self, wallet_id: int, count: int) -> None:
|
||||
records = self.records_per_wallet.setdefault(wallet_id, [])
|
||||
for _ in range(count):
|
||||
records.append(get_dummy_record(wallet_id))
|
||||
records.append(get_dummy_record(wallet_id, seeded_random=self.seeded_random))
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@ -206,7 +210,7 @@ async def test_set_spent() -> None:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_records_by_puzzle_hash() -> None:
|
||||
async def test_get_records_by_puzzle_hash(seeded_random: random.Random) -> None:
|
||||
async with DBConnection(1) as db_wrapper:
|
||||
store = await WalletCoinStore.create(db_wrapper)
|
||||
|
||||
@ -218,10 +222,10 @@ async def test_get_records_by_puzzle_hash() -> None:
|
||||
|
||||
await store.add_coin_record(record_6)
|
||||
assert len(await store.get_coin_records_by_puzzle_hash(record_6.coin.puzzle_hash)) == 2 # 4 and 6
|
||||
assert len(await store.get_coin_records_by_puzzle_hash(token_bytes(32))) == 0
|
||||
assert len(await store.get_coin_records_by_puzzle_hash(bytes32.random(seeded_random))) == 0
|
||||
|
||||
assert await store.get_coin_record(coin_6.name()) == record_6
|
||||
assert await store.get_coin_record(token_bytes(32)) is None
|
||||
assert await store.get_coin_record(bytes32.random(seeded_random)) is None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@ -921,13 +925,13 @@ async def test_rollback_to_block() -> None:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_count_small_unspent() -> None:
|
||||
async def test_count_small_unspent(seeded_random: random.Random) -> None:
|
||||
async with DBConnection(1) as db_wrapper:
|
||||
store = await WalletCoinStore.create(db_wrapper)
|
||||
|
||||
coin_1 = Coin(token_bytes(32), token_bytes(32), uint64(1))
|
||||
coin_2 = Coin(token_bytes(32), token_bytes(32), uint64(2))
|
||||
coin_3 = Coin(token_bytes(32), token_bytes(32), uint64(4))
|
||||
coin_1 = Coin(bytes32.random(seeded_random), bytes32.random(seeded_random), uint64(1))
|
||||
coin_2 = Coin(bytes32.random(seeded_random), bytes32.random(seeded_random), uint64(2))
|
||||
coin_3 = Coin(bytes32.random(seeded_random), bytes32.random(seeded_random), uint64(4))
|
||||
|
||||
r1 = record(coin_1, confirmed=1, spent=0)
|
||||
r2 = record(coin_2, confirmed=2, spent=0)
|
||||
@ -979,8 +983,8 @@ async def test_get_coin_records_between() -> None:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_delete_wallet() -> None:
|
||||
dummy_records = DummyWalletCoinRecords()
|
||||
async def test_delete_wallet(seeded_random: random.Random) -> None:
|
||||
dummy_records = DummyWalletCoinRecords(seeded_random=seeded_random)
|
||||
for i in range(5):
|
||||
dummy_records.generate(i, i * 5)
|
||||
async with DBConnection(1) as wrapper:
|
||||
|
@ -1,10 +1,11 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from secrets import token_bytes
|
||||
import random
|
||||
|
||||
import pytest
|
||||
|
||||
from chia.types.blockchain_format.coin import Coin
|
||||
from chia.types.blockchain_format.sized_bytes import bytes32
|
||||
from chia.util.ints import uint64
|
||||
from chia.wallet.wallet_interested_store import WalletInterestedStore
|
||||
from tests.util.db_connection import DBConnection
|
||||
@ -12,11 +13,11 @@ from tests.util.db_connection import DBConnection
|
||||
|
||||
class TestWalletInterestedStore:
|
||||
@pytest.mark.asyncio
|
||||
async def test_store(self):
|
||||
async def test_store(self, seeded_random: random.Random):
|
||||
async with DBConnection(1) as db_wrapper:
|
||||
store = await WalletInterestedStore.create(db_wrapper)
|
||||
coin_1 = Coin(token_bytes(32), token_bytes(32), uint64(12312))
|
||||
coin_2 = Coin(token_bytes(32), token_bytes(32), uint64(12312))
|
||||
coin_1 = Coin(bytes32.random(seeded_random), bytes32.random(seeded_random), uint64(12312))
|
||||
coin_2 = Coin(bytes32.random(seeded_random), bytes32.random(seeded_random), uint64(12312))
|
||||
assert (await store.get_interested_coin_ids()) == []
|
||||
await store.add_interested_coin_id(coin_1.name())
|
||||
assert (await store.get_interested_coin_ids()) == [coin_1.name()]
|
||||
@ -26,7 +27,7 @@ class TestWalletInterestedStore:
|
||||
assert set(await store.get_interested_coin_ids()) == {coin_1.name(), coin_2.name()}
|
||||
await store.remove_interested_coin_id(coin_1.name())
|
||||
assert set(await store.get_interested_coin_ids()) == {coin_2.name()}
|
||||
puzzle_hash = token_bytes(32)
|
||||
puzzle_hash = bytes32.random(seeded_random)
|
||||
assert len(await store.get_interested_puzzle_hashes()) == 0
|
||||
|
||||
await store.add_interested_puzzle_hash(puzzle_hash, 2)
|
||||
|
@ -1,7 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import random
|
||||
import time
|
||||
from secrets import token_bytes
|
||||
|
||||
import pytest
|
||||
from blspy import G2Element
|
||||
@ -20,16 +20,19 @@ from chia.wallet.wallet_coin_record import WalletCoinRecord
|
||||
from chia.wallet.wallet_coin_store import WalletCoinStore
|
||||
from tests.util.db_connection import DBConnection
|
||||
|
||||
coin_1 = Coin(token_bytes(32), token_bytes(32), uint64(12311))
|
||||
coin_2 = Coin(coin_1.parent_coin_info, token_bytes(32), uint64(12312))
|
||||
coin_3 = Coin(coin_1.parent_coin_info, token_bytes(32), uint64(12313))
|
||||
module_seeded_random = random.Random()
|
||||
module_seeded_random.seed(a=0, version=2)
|
||||
|
||||
coin_1 = Coin(bytes32.random(module_seeded_random), bytes32.random(module_seeded_random), uint64(12311))
|
||||
coin_2 = Coin(coin_1.parent_coin_info, bytes32.random(module_seeded_random), uint64(12312))
|
||||
coin_3 = Coin(coin_1.parent_coin_info, bytes32.random(module_seeded_random), uint64(12313))
|
||||
record_1 = WalletCoinRecord(coin_1, uint32(4), uint32(0), False, True, WalletType.STANDARD_WALLET, 0)
|
||||
record_2 = WalletCoinRecord(coin_2, uint32(5), uint32(0), False, True, WalletType.STANDARD_WALLET, 0)
|
||||
record_3 = WalletCoinRecord(coin_3, uint32(6), uint32(0), False, True, WalletType.STANDARD_WALLET, 0)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_coins_of_interest_with_trade_statuses() -> None:
|
||||
async def test_get_coins_of_interest_with_trade_statuses(seeded_random: random.Random) -> None:
|
||||
async with DBConnection(1) as db_wrapper:
|
||||
coin_store = await WalletCoinStore.create(db_wrapper)
|
||||
trade_store = await TradeStore.create(db_wrapper)
|
||||
@ -37,7 +40,7 @@ async def test_get_coins_of_interest_with_trade_statuses() -> None:
|
||||
await coin_store.add_coin_record(record_2)
|
||||
await coin_store.add_coin_record(record_3)
|
||||
|
||||
tr1_name: bytes32 = bytes32(token_bytes(32))
|
||||
tr1_name: bytes32 = bytes32.random(seeded_random)
|
||||
tr1 = TradeRecord(
|
||||
confirmed_at_index=uint32(0),
|
||||
accepted_at_time=None,
|
||||
@ -52,9 +55,9 @@ async def test_get_coins_of_interest_with_trade_statuses() -> None:
|
||||
sent_to=[],
|
||||
valid_times=ConditionValidTimes(),
|
||||
)
|
||||
await trade_store.add_trade_record(tr1, offer_name=bytes32(token_bytes(32)))
|
||||
await trade_store.add_trade_record(tr1, offer_name=bytes32.random(seeded_random))
|
||||
|
||||
tr2_name: bytes32 = bytes32(token_bytes(32))
|
||||
tr2_name: bytes32 = bytes32.random(seeded_random)
|
||||
tr2 = TradeRecord(
|
||||
confirmed_at_index=uint32(0),
|
||||
accepted_at_time=None,
|
||||
@ -69,7 +72,7 @@ async def test_get_coins_of_interest_with_trade_statuses() -> None:
|
||||
sent_to=[],
|
||||
valid_times=ConditionValidTimes(),
|
||||
)
|
||||
await trade_store.add_trade_record(tr2, offer_name=bytes32(token_bytes(32)))
|
||||
await trade_store.add_trade_record(tr2, offer_name=bytes32.random(seeded_random))
|
||||
|
||||
assert await trade_store.get_coin_ids_of_interest_with_trade_statuses([TradeStatus.PENDING_CONFIRM]) == {
|
||||
coin_1.name(),
|
||||
@ -94,7 +97,7 @@ async def test_get_coins_of_interest_with_trade_statuses() -> None:
|
||||
sent_to=[],
|
||||
valid_times=ConditionValidTimes(),
|
||||
)
|
||||
await trade_store.add_trade_record(tr2_1, offer_name=bytes32(token_bytes(32)))
|
||||
await trade_store.add_trade_record(tr2_1, offer_name=bytes32.random(seeded_random))
|
||||
|
||||
assert await trade_store.get_coin_ids_of_interest_with_trade_statuses([TradeStatus.PENDING_CONFIRM]) == {
|
||||
coin_2.name()
|
||||
|
Loading…
Reference in New Issue
Block a user