mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2025-01-08 18:34:27 +03:00
hints and strict type checking for test_wallet (#11541)
* hints and strict type checking for test_wallet * fixup * flip flop
This commit is contained in:
parent
31ed32628f
commit
cb5470b806
@ -65,7 +65,7 @@ class Wallet:
|
||||
self.cost_of_single_tx = None
|
||||
return self
|
||||
|
||||
async def get_max_send_amount(self, records=None):
|
||||
async def get_max_send_amount(self, records: Optional[Set[WalletCoinRecord]] = None) -> int:
|
||||
spendable: List[WalletCoinRecord] = list(
|
||||
await self.wallet_state_manager.get_spendable_coins_for_wallet(self.id(), records)
|
||||
)
|
||||
@ -77,6 +77,7 @@ class Wallet:
|
||||
tx = await self.generate_signed_transaction(
|
||||
coin.amount, coin.puzzle_hash, coins={coin}, ignore_max_send_amount=True
|
||||
)
|
||||
assert tx.spend_bundle is not None
|
||||
program: BlockGenerator = simple_solution_generator(tx.spend_bundle)
|
||||
# npc contains names of the coins removed, puzzle_hashes and their spend conditions
|
||||
result: NPCResult = get_name_puzzle_conditions(
|
||||
|
@ -1,11 +1,13 @@
|
||||
import asyncio
|
||||
import time
|
||||
from typing import List, Tuple
|
||||
|
||||
import pytest
|
||||
|
||||
from chia.consensus.block_rewards import calculate_base_farmer_reward, calculate_pool_reward
|
||||
from chia.protocols.full_node_protocol import RespondBlock
|
||||
from chia.server.server import ChiaServer
|
||||
from chia.simulator.full_node_simulator import FullNodeSimulator
|
||||
from chia.simulator.simulator_protocol import FarmNewBlockProtocol, ReorgProtocol
|
||||
from chia.types.blockchain_format.program import Program
|
||||
from chia.types.blockchain_format.sized_bytes import bytes32
|
||||
@ -15,6 +17,7 @@ from chia.wallet.derive_keys import master_sk_to_wallet_sk
|
||||
from chia.wallet.transaction_record import TransactionRecord
|
||||
from chia.wallet.util.compute_memos import compute_memos
|
||||
from chia.wallet.util.transaction_type import TransactionType
|
||||
from chia.wallet.util.wallet_types import AmountWithPuzzlehash
|
||||
from chia.wallet.wallet_node import WalletNode
|
||||
from chia.wallet.wallet_state_manager import WalletStateManager
|
||||
from tests.time_out_assert import time_out_assert, time_out_assert_not_none
|
||||
@ -27,13 +30,19 @@ class TestWalletSimulator:
|
||||
[True, False],
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_wallet_coinbase(self, wallet_node_sim_and_wallet, trusted, self_hostname):
|
||||
async def test_wallet_coinbase(
|
||||
self,
|
||||
wallet_node_sim_and_wallet: Tuple[List[FullNodeSimulator], List[Tuple[WalletNode, ChiaServer]]],
|
||||
trusted: bool,
|
||||
self_hostname: str,
|
||||
) -> None:
|
||||
num_blocks = 10
|
||||
full_nodes, wallets = wallet_node_sim_and_wallet
|
||||
full_node_api = full_nodes[0]
|
||||
server_1: ChiaServer = full_node_api.full_node.server
|
||||
wallet_node, server_2 = wallets[0]
|
||||
|
||||
assert wallet_node.wallet_state_manager is not None
|
||||
wallet = wallet_node.wallet_state_manager.main_wallet
|
||||
ph = await wallet.get_new_puzzlehash()
|
||||
if trusted:
|
||||
@ -54,7 +63,8 @@ class TestWalletSimulator:
|
||||
]
|
||||
)
|
||||
|
||||
async def check_tx_are_pool_farm_rewards():
|
||||
async def check_tx_are_pool_farm_rewards() -> bool:
|
||||
assert wallet_node.wallet_state_manager is not None
|
||||
wsm: WalletStateManager = wallet_node.wallet_state_manager
|
||||
all_txs = await wsm.get_all_transactions(1)
|
||||
expected_count = (num_blocks + 1) * 2
|
||||
@ -64,9 +74,9 @@ class TestWalletSimulator:
|
||||
farm_rewards = 0
|
||||
|
||||
for tx in all_txs:
|
||||
if tx.type == TransactionType.COINBASE_REWARD:
|
||||
if TransactionType(tx.type) == TransactionType.COINBASE_REWARD:
|
||||
pool_rewards += 1
|
||||
elif tx.type == TransactionType.FEE_REWARD:
|
||||
elif TransactionType(tx.type) == TransactionType.FEE_REWARD:
|
||||
farm_rewards += 1
|
||||
|
||||
if pool_rewards != expected_count / 2:
|
||||
@ -83,13 +93,20 @@ class TestWalletSimulator:
|
||||
[True, False],
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_wallet_make_transaction(self, two_wallet_nodes, trusted, self_hostname):
|
||||
async def test_wallet_make_transaction(
|
||||
self,
|
||||
two_wallet_nodes: Tuple[List[FullNodeSimulator], List[Tuple[WalletNode, ChiaServer]]],
|
||||
trusted: bool,
|
||||
self_hostname: str,
|
||||
) -> None:
|
||||
num_blocks = 5
|
||||
full_nodes, wallets = two_wallet_nodes
|
||||
full_node_api = full_nodes[0]
|
||||
server_1 = full_node_api.full_node.server
|
||||
wallet_node, server_2 = wallets[0]
|
||||
assert wallet_node.wallet_state_manager is not None
|
||||
wallet_node_2, server_3 = wallets[1]
|
||||
assert wallet_node_2.wallet_state_manager is not None
|
||||
wallet = wallet_node.wallet_state_manager.main_wallet
|
||||
ph = await wallet.get_new_puzzlehash()
|
||||
if trusted:
|
||||
@ -112,9 +129,9 @@ class TestWalletSimulator:
|
||||
await time_out_assert(5, wallet.get_unconfirmed_balance, funds)
|
||||
|
||||
tx = await wallet.generate_signed_transaction(
|
||||
10,
|
||||
uint64(10),
|
||||
await wallet_node_2.wallet_state_manager.main_wallet.get_new_puzzlehash(),
|
||||
0,
|
||||
uint64(0),
|
||||
)
|
||||
await wallet.push_transaction(tx)
|
||||
|
||||
@ -140,12 +157,18 @@ class TestWalletSimulator:
|
||||
[True, False],
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_wallet_coinbase_reorg(self, wallet_node_sim_and_wallet, trusted, self_hostname):
|
||||
async def test_wallet_coinbase_reorg(
|
||||
self,
|
||||
wallet_node_sim_and_wallet: Tuple[List[FullNodeSimulator], List[Tuple[WalletNode, ChiaServer]]],
|
||||
trusted: bool,
|
||||
self_hostname: str,
|
||||
) -> None:
|
||||
num_blocks = 5
|
||||
full_nodes, wallets = wallet_node_sim_and_wallet
|
||||
full_node_api = full_nodes[0]
|
||||
fn_server = full_node_api.full_node.server
|
||||
wallet_node, server_2 = wallets[0]
|
||||
assert wallet_node.wallet_state_manager is not None
|
||||
wallet = wallet_node.wallet_state_manager.main_wallet
|
||||
ph = await wallet.get_new_puzzlehash()
|
||||
if trusted:
|
||||
@ -163,7 +186,9 @@ class TestWalletSimulator:
|
||||
|
||||
await time_out_assert(25, wallet.get_confirmed_balance, funds)
|
||||
|
||||
await full_node_api.reorg_from_index_to_new_index(ReorgProtocol(uint32(2), uint32(num_blocks + 6), 32 * b"0"))
|
||||
await full_node_api.reorg_from_index_to_new_index(
|
||||
ReorgProtocol(uint32(2), uint32(num_blocks + 6), bytes32(32 * b"0"))
|
||||
)
|
||||
|
||||
funds = sum(
|
||||
[
|
||||
@ -179,11 +204,18 @@ class TestWalletSimulator:
|
||||
[True, False],
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_wallet_send_to_three_peers(self, three_sim_two_wallets, trusted, self_hostname):
|
||||
async def test_wallet_send_to_three_peers(
|
||||
self,
|
||||
three_sim_two_wallets: Tuple[List[FullNodeSimulator], List[Tuple[WalletNode, ChiaServer]]],
|
||||
trusted: bool,
|
||||
self_hostname: str,
|
||||
) -> None:
|
||||
num_blocks = 10
|
||||
full_nodes, wallets = three_sim_two_wallets
|
||||
|
||||
wallet_0, wallet_server_0 = wallets[0]
|
||||
assert wallet_0.wallet_state_manager is not None
|
||||
|
||||
full_node_api_0 = full_nodes[0]
|
||||
full_node_api_1 = full_nodes[1]
|
||||
full_node_api_2 = full_nodes[2]
|
||||
@ -225,7 +257,10 @@ class TestWalletSimulator:
|
||||
|
||||
await time_out_assert(5, wallet_0.wallet_state_manager.main_wallet.get_confirmed_balance, funds)
|
||||
|
||||
tx = await wallet_0.wallet_state_manager.main_wallet.generate_signed_transaction(10, 32 * b"0", 0)
|
||||
tx = await wallet_0.wallet_state_manager.main_wallet.generate_signed_transaction(
|
||||
uint64(10), bytes32(32 * b"0"), uint64(0)
|
||||
)
|
||||
assert tx.spend_bundle is not None
|
||||
await wallet_0.wallet_state_manager.main_wallet.push_transaction(tx)
|
||||
|
||||
await time_out_assert_not_none(5, full_node_0.mempool_manager.get_spendbundle, tx.spend_bundle.name())
|
||||
@ -245,7 +280,12 @@ class TestWalletSimulator:
|
||||
[True, False],
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_wallet_make_transaction_hop(self, two_wallet_nodes_five_freeze, trusted, self_hostname):
|
||||
async def test_wallet_make_transaction_hop(
|
||||
self,
|
||||
two_wallet_nodes_five_freeze: Tuple[List[FullNodeSimulator], List[Tuple[WalletNode, ChiaServer]]],
|
||||
trusted: bool,
|
||||
self_hostname: str,
|
||||
) -> None:
|
||||
num_blocks = 10
|
||||
full_nodes, wallets = two_wallet_nodes_five_freeze
|
||||
full_node_api_0 = full_nodes[0]
|
||||
@ -253,7 +293,10 @@ class TestWalletSimulator:
|
||||
server_0 = full_node_0.server
|
||||
|
||||
wallet_node_0, wallet_0_server = wallets[0]
|
||||
assert wallet_node_0.wallet_state_manager is not None
|
||||
wallet_node_1, wallet_1_server = wallets[1]
|
||||
assert wallet_node_1.wallet_state_manager is not None
|
||||
|
||||
wallet_0 = wallet_node_0.wallet_state_manager.main_wallet
|
||||
wallet_1 = wallet_node_1.wallet_state_manager.main_wallet
|
||||
ph = await wallet_0.get_new_puzzlehash()
|
||||
@ -281,9 +324,9 @@ class TestWalletSimulator:
|
||||
assert await wallet_0.get_unconfirmed_balance() == funds
|
||||
|
||||
tx = await wallet_0.generate_signed_transaction(
|
||||
10,
|
||||
uint64(10),
|
||||
await wallet_node_1.wallet_state_manager.main_wallet.get_new_puzzlehash(),
|
||||
0,
|
||||
uint64(0),
|
||||
)
|
||||
|
||||
await wallet_0.push_transaction(tx)
|
||||
@ -294,7 +337,7 @@ class TestWalletSimulator:
|
||||
await time_out_assert(5, wallet_0.get_unconfirmed_balance, funds - 10)
|
||||
|
||||
for i in range(0, 4):
|
||||
await full_node_api_0.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"0"))
|
||||
await full_node_api_0.farm_new_transaction_block(FarmNewBlockProtocol(bytes32(32 * b"0")))
|
||||
|
||||
# here it's num_blocks + 1 because our last reward is included in the first block that we just farmed
|
||||
new_funds = sum(
|
||||
@ -309,12 +352,12 @@ class TestWalletSimulator:
|
||||
await time_out_assert(5, wallet_0.get_unconfirmed_balance, new_funds - 10)
|
||||
await time_out_assert(5, wallet_1.get_confirmed_balance, 10)
|
||||
|
||||
tx = await wallet_1.generate_signed_transaction(5, await wallet_0.get_new_puzzlehash(), 0)
|
||||
tx = await wallet_1.generate_signed_transaction(uint64(5), await wallet_0.get_new_puzzlehash(), uint64(0))
|
||||
await wallet_1.push_transaction(tx)
|
||||
await time_out_assert(5, full_node_0.mempool_manager.get_spendbundle, tx.spend_bundle, tx.name)
|
||||
|
||||
for i in range(0, 4):
|
||||
await full_node_api_0.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"0"))
|
||||
await full_node_api_0.farm_new_transaction_block(FarmNewBlockProtocol(bytes32(32 * b"0")))
|
||||
|
||||
await wallet_0.get_confirmed_balance()
|
||||
await wallet_0.get_unconfirmed_balance()
|
||||
@ -365,12 +408,21 @@ class TestWalletSimulator:
|
||||
[True, False],
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_wallet_make_transaction_with_fee(self, two_wallet_nodes, trusted, self_hostname):
|
||||
async def test_wallet_make_transaction_with_fee(
|
||||
self,
|
||||
two_wallet_nodes: Tuple[List[FullNodeSimulator], List[Tuple[WalletNode, ChiaServer]]],
|
||||
trusted: bool,
|
||||
self_hostname: str,
|
||||
) -> None:
|
||||
num_blocks = 5
|
||||
full_nodes, wallets = two_wallet_nodes
|
||||
full_node_1 = full_nodes[0]
|
||||
|
||||
wallet_node, server_2 = wallets[0]
|
||||
assert wallet_node.wallet_state_manager is not None
|
||||
wallet_node_2, server_3 = wallets[1]
|
||||
assert wallet_node_2.wallet_state_manager is not None
|
||||
|
||||
wallet = wallet_node.wallet_state_manager.main_wallet
|
||||
ph = await wallet.get_new_puzzlehash()
|
||||
if trusted:
|
||||
@ -400,10 +452,11 @@ class TestWalletSimulator:
|
||||
tx_amount = 3200000000000
|
||||
tx_fee = 10
|
||||
tx = await wallet.generate_signed_transaction(
|
||||
tx_amount,
|
||||
uint64(tx_amount),
|
||||
await wallet_node_2.wallet_state_manager.main_wallet.get_new_puzzlehash(),
|
||||
tx_fee,
|
||||
uint64(tx_fee),
|
||||
)
|
||||
assert tx.spend_bundle is not None
|
||||
|
||||
fees = tx.spend_bundle.fees()
|
||||
assert fees == tx_fee
|
||||
@ -415,7 +468,7 @@ class TestWalletSimulator:
|
||||
await time_out_assert(5, wallet.get_unconfirmed_balance, funds - tx_amount - tx_fee)
|
||||
|
||||
for i in range(0, num_blocks):
|
||||
await full_node_1.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"0"))
|
||||
await full_node_1.farm_new_transaction_block(FarmNewBlockProtocol(bytes32(32 * b"0")))
|
||||
|
||||
new_funds = sum(
|
||||
[
|
||||
@ -432,12 +485,20 @@ class TestWalletSimulator:
|
||||
[True, False],
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_wallet_create_hit_max_send_amount(self, two_wallet_nodes, trusted, self_hostname):
|
||||
async def test_wallet_create_hit_max_send_amount(
|
||||
self,
|
||||
two_wallet_nodes: Tuple[List[FullNodeSimulator], List[Tuple[WalletNode, ChiaServer]]],
|
||||
trusted: bool,
|
||||
self_hostname: str,
|
||||
) -> None:
|
||||
num_blocks = 5
|
||||
full_nodes, wallets = two_wallet_nodes
|
||||
full_node_1 = full_nodes[0]
|
||||
|
||||
wallet_node, server_2 = wallets[0]
|
||||
assert wallet_node.wallet_state_manager is not None
|
||||
wallet_node_2, server_3 = wallets[1]
|
||||
|
||||
wallet = wallet_node.wallet_state_manager.main_wallet
|
||||
ph = await wallet.get_new_puzzlehash()
|
||||
if trusted:
|
||||
@ -461,18 +522,19 @@ class TestWalletSimulator:
|
||||
|
||||
await time_out_assert(5, wallet.get_confirmed_balance, funds)
|
||||
|
||||
primaries = []
|
||||
primaries: List[AmountWithPuzzlehash] = []
|
||||
for i in range(0, 60):
|
||||
primaries.append({"puzzlehash": ph, "amount": 1000000000 + i})
|
||||
primaries.append({"puzzlehash": ph, "amount": uint64(1000000000 + i), "memos": []})
|
||||
|
||||
tx_split_coins = await wallet.generate_signed_transaction(1, ph, 0, primaries=primaries)
|
||||
tx_split_coins = await wallet.generate_signed_transaction(uint64(1), ph, uint64(0), primaries=primaries)
|
||||
assert tx_split_coins.spend_bundle is not None
|
||||
|
||||
await wallet.push_transaction(tx_split_coins)
|
||||
await time_out_assert(
|
||||
15, tx_in_pool, True, full_node_1.full_node.mempool_manager, tx_split_coins.spend_bundle.name()
|
||||
)
|
||||
for i in range(0, num_blocks):
|
||||
await full_node_1.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"0"))
|
||||
await full_node_1.farm_new_transaction_block(FarmNewBlockProtocol(bytes32(32 * b"0")))
|
||||
|
||||
funds = sum(
|
||||
[
|
||||
@ -488,9 +550,9 @@ class TestWalletSimulator:
|
||||
under_limit_tx = None
|
||||
try:
|
||||
under_limit_tx = await wallet.generate_signed_transaction(
|
||||
max_sent_amount - 1,
|
||||
uint64(max_sent_amount - 1),
|
||||
ph,
|
||||
0,
|
||||
uint64(0),
|
||||
)
|
||||
except ValueError:
|
||||
assert ValueError
|
||||
@ -501,9 +563,9 @@ class TestWalletSimulator:
|
||||
at_limit_tx = None
|
||||
try:
|
||||
at_limit_tx = await wallet.generate_signed_transaction(
|
||||
max_sent_amount,
|
||||
uint64(max_sent_amount),
|
||||
ph,
|
||||
0,
|
||||
uint64(0),
|
||||
)
|
||||
except ValueError:
|
||||
assert ValueError
|
||||
@ -514,9 +576,9 @@ class TestWalletSimulator:
|
||||
above_limit_tx = None
|
||||
try:
|
||||
above_limit_tx = await wallet.generate_signed_transaction(
|
||||
max_sent_amount + 1,
|
||||
uint64(max_sent_amount + 1),
|
||||
ph,
|
||||
0,
|
||||
uint64(0),
|
||||
)
|
||||
except ValueError:
|
||||
pass
|
||||
@ -528,12 +590,21 @@ class TestWalletSimulator:
|
||||
[True, False],
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_wallet_prevent_fee_theft(self, two_wallet_nodes, trusted, self_hostname):
|
||||
async def test_wallet_prevent_fee_theft(
|
||||
self,
|
||||
two_wallet_nodes: Tuple[List[FullNodeSimulator], List[Tuple[WalletNode, ChiaServer]]],
|
||||
trusted: bool,
|
||||
self_hostname: str,
|
||||
) -> None:
|
||||
num_blocks = 5
|
||||
full_nodes, wallets = two_wallet_nodes
|
||||
full_node_1 = full_nodes[0]
|
||||
|
||||
wallet_node, server_2 = wallets[0]
|
||||
assert wallet_node.wallet_state_manager is not None
|
||||
wallet_node_2, server_3 = wallets[1]
|
||||
assert wallet_node_2.wallet_state_manager is not None
|
||||
|
||||
wallet = wallet_node.wallet_state_manager.main_wallet
|
||||
ph = await wallet.get_new_puzzlehash()
|
||||
if trusted:
|
||||
@ -563,10 +634,11 @@ class TestWalletSimulator:
|
||||
tx_amount = 3200000000000
|
||||
tx_fee = 300000000000
|
||||
tx = await wallet.generate_signed_transaction(
|
||||
tx_amount,
|
||||
uint64(tx_amount),
|
||||
await wallet_node_2.wallet_state_manager.main_wallet.get_new_puzzlehash(),
|
||||
tx_fee,
|
||||
uint64(tx_fee),
|
||||
)
|
||||
assert tx.spend_bundle is not None
|
||||
|
||||
# extract coin_spend from generated spend_bundle
|
||||
for cs in tx.spend_bundle.coin_spends:
|
||||
@ -581,8 +653,8 @@ class TestWalletSimulator:
|
||||
stolen_tx = TransactionRecord(
|
||||
confirmed_at_height=uint32(0),
|
||||
created_at_time=now,
|
||||
to_puzzle_hash=32 * b"0",
|
||||
amount=0,
|
||||
to_puzzle_hash=bytes32(32 * b"0"),
|
||||
amount=uint64(0),
|
||||
fee_amount=stolen_cs.coin.amount,
|
||||
confirmed=False,
|
||||
sent=uint32(0),
|
||||
@ -602,7 +674,7 @@ class TestWalletSimulator:
|
||||
await time_out_assert(5, wallet.get_unconfirmed_balance, funds - stolen_cs.coin.amount)
|
||||
|
||||
for i in range(0, num_blocks):
|
||||
await full_node_1.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"0"))
|
||||
await full_node_1.farm_new_transaction_block(FarmNewBlockProtocol(bytes32(32 * b"0")))
|
||||
|
||||
# Funds have not decreased because stolen_tx was rejected
|
||||
outstanding_coinbase_rewards = 2000000000000
|
||||
@ -613,14 +685,22 @@ class TestWalletSimulator:
|
||||
[True, False],
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_wallet_tx_reorg(self, two_wallet_nodes, trusted, self_hostname):
|
||||
async def test_wallet_tx_reorg(
|
||||
self,
|
||||
two_wallet_nodes: Tuple[List[FullNodeSimulator], List[Tuple[WalletNode, ChiaServer]]],
|
||||
trusted: bool,
|
||||
self_hostname: str,
|
||||
) -> None:
|
||||
num_blocks = 5
|
||||
full_nodes, wallets = two_wallet_nodes
|
||||
full_node_api = full_nodes[0]
|
||||
fn_server = full_node_api.full_node.server
|
||||
|
||||
wallet_node, server_2 = wallets[0]
|
||||
wallet_node: WalletNode = wallet_node
|
||||
assert wallet_node.wallet_state_manager is not None
|
||||
wallet_node_2, server_3 = wallets[1]
|
||||
assert wallet_node_2.wallet_state_manager is not None
|
||||
|
||||
wallet = wallet_node.wallet_state_manager.main_wallet
|
||||
wallet_2 = wallet_node_2.wallet_state_manager.main_wallet
|
||||
|
||||
@ -648,22 +728,26 @@ class TestWalletSimulator:
|
||||
coin = list(all_blocks[-3].get_included_reward_coins())[0]
|
||||
await asyncio.sleep(5)
|
||||
|
||||
tx = await wallet.generate_signed_transaction(1000, ph2, coins={coin})
|
||||
tx = await wallet.generate_signed_transaction(uint64(1000), ph2, coins={coin})
|
||||
assert tx.spend_bundle is not None
|
||||
await wallet.push_transaction(tx)
|
||||
await full_node_api.full_node.respond_transaction(tx.spend_bundle, tx.name)
|
||||
await time_out_assert(5, full_node_api.full_node.mempool_manager.get_spendbundle, tx.spend_bundle, tx.name)
|
||||
await time_out_assert(5, wallet.get_confirmed_balance, funds)
|
||||
for i in range(0, 2):
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"0"))
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(bytes32(32 * b"0")))
|
||||
await time_out_assert(5, wallet_2.get_confirmed_balance, 1000)
|
||||
funds -= 1000
|
||||
|
||||
await time_out_assert(5, wallet_node.wallet_state_manager.blockchain.get_peak_height, 7)
|
||||
peak_height = full_node_api.full_node.blockchain.get_peak().height
|
||||
peak = full_node_api.full_node.blockchain.get_peak()
|
||||
assert peak is not None
|
||||
peak_height = peak.height
|
||||
print(peak_height)
|
||||
|
||||
# Perform a reorg, which will revert the transaction in the full node and wallet, and cause wallet to resubmit
|
||||
await full_node_api.reorg_from_index_to_new_index(
|
||||
ReorgProtocol(uint32(peak_height - 3), uint32(peak_height + 3), 32 * b"0")
|
||||
ReorgProtocol(uint32(peak_height - 3), uint32(peak_height + 3), bytes32(32 * b"0"))
|
||||
)
|
||||
|
||||
funds = sum(
|
||||
@ -679,7 +763,7 @@ class TestWalletSimulator:
|
||||
# Farm a few blocks so we can confirm the resubmitted transaction
|
||||
for i in range(0, num_blocks):
|
||||
await asyncio.sleep(1)
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"0"))
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(bytes32(32 * b"0")))
|
||||
|
||||
# By this point, the transaction should be confirmed
|
||||
await time_out_assert(15, wallet.get_confirmed_balance, funds - 1000)
|
||||
@ -687,13 +771,16 @@ class TestWalletSimulator:
|
||||
unconfirmed = await wallet_node.wallet_state_manager.tx_store.get_unconfirmed_for_wallet(int(wallet.id()))
|
||||
assert len(unconfirmed) == 0
|
||||
tx_record = await wallet_node.wallet_state_manager.tx_store.get_transaction_record(tx.name)
|
||||
assert tx_record is not None
|
||||
removed = tx_record.removals[0]
|
||||
added = tx_record.additions[0]
|
||||
added_1 = tx_record.additions[1]
|
||||
wallet_coin_record_rem = await wallet_node.wallet_state_manager.coin_store.get_coin_record(removed.name())
|
||||
assert wallet_coin_record_rem is not None
|
||||
assert wallet_coin_record_rem.spent
|
||||
|
||||
coin_record_full_node = await full_node_api.full_node.coin_store.get_coin_record(removed.name())
|
||||
assert coin_record_full_node is not None
|
||||
assert coin_record_full_node.spent
|
||||
add_1_coin_record_full_node = await full_node_api.full_node.coin_store.get_coin_record(added.name())
|
||||
assert add_1_coin_record_full_node is not None
|
||||
@ -707,11 +794,17 @@ class TestWalletSimulator:
|
||||
[False],
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_address_sliding_window(self, wallet_node_100_pk, trusted, self_hostname):
|
||||
async def test_address_sliding_window(
|
||||
self,
|
||||
wallet_node_100_pk: Tuple[List[FullNodeSimulator], List[Tuple[WalletNode, ChiaServer]]],
|
||||
trusted: bool,
|
||||
self_hostname: str,
|
||||
) -> None:
|
||||
full_nodes, wallets = wallet_node_100_pk
|
||||
full_node_api = full_nodes[0]
|
||||
server_1: ChiaServer = full_node_api.full_node.server
|
||||
wallet_node, server_2 = wallets[0]
|
||||
assert wallet_node.wallet_state_manager is not None
|
||||
if trusted:
|
||||
wallet_node.config["trusted_peers"] = {server_1.node_id.hex(): server_1.node_id.hex()}
|
||||
else:
|
||||
@ -722,27 +815,27 @@ class TestWalletSimulator:
|
||||
|
||||
puzzle_hashes = []
|
||||
for i in range(211):
|
||||
pubkey = master_sk_to_wallet_sk(wallet_node.wallet_state_manager.private_key, i).get_g1()
|
||||
pubkey = master_sk_to_wallet_sk(wallet_node.wallet_state_manager.private_key, uint32(i)).get_g1()
|
||||
puzzle: Program = wallet.puzzle_for_pk(bytes(pubkey))
|
||||
puzzle_hash: bytes32 = puzzle.get_tree_hash()
|
||||
puzzle_hashes.append(puzzle_hash)
|
||||
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"0"))
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(bytes32(32 * b"0")))
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(puzzle_hashes[0]))
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(puzzle_hashes[210]))
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(puzzle_hashes[114]))
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"0"))
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(bytes32(32 * b"0")))
|
||||
|
||||
await time_out_assert(60, wallet.get_confirmed_balance, 2 * 10 ** 12)
|
||||
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(puzzle_hashes[50]))
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"0"))
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(bytes32(32 * b"0")))
|
||||
|
||||
await time_out_assert(60, wallet.get_confirmed_balance, 8 * 10 ** 12)
|
||||
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(puzzle_hashes[113]))
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(puzzle_hashes[209]))
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"0"))
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(bytes32(32 * b"0")))
|
||||
await time_out_assert(60, wallet.get_confirmed_balance, 12 * 10 ** 12)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@ -750,13 +843,22 @@ class TestWalletSimulator:
|
||||
[True, False],
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_wallet_transaction_options(self, two_wallet_nodes, trusted, self_hostname):
|
||||
async def test_wallet_transaction_options(
|
||||
self,
|
||||
two_wallet_nodes: Tuple[List[FullNodeSimulator], List[Tuple[WalletNode, ChiaServer]]],
|
||||
trusted: bool,
|
||||
self_hostname: str,
|
||||
) -> None:
|
||||
num_blocks = 5
|
||||
full_nodes, wallets = two_wallet_nodes
|
||||
full_node_api = full_nodes[0]
|
||||
server_1 = full_node_api.full_node.server
|
||||
|
||||
wallet_node, server_2 = wallets[0]
|
||||
assert wallet_node.wallet_state_manager is not None
|
||||
wallet_node_2, server_3 = wallets[1]
|
||||
assert wallet_node_2.wallet_state_manager is not None
|
||||
|
||||
wallet = wallet_node.wallet_state_manager.main_wallet
|
||||
ph = await wallet.get_new_puzzlehash()
|
||||
if trusted:
|
||||
@ -783,17 +885,19 @@ class TestWalletSimulator:
|
||||
await time_out_assert(5, wallet.get_unconfirmed_balance, funds)
|
||||
|
||||
AMOUNT_TO_SEND = 4000000000000
|
||||
coins = list(await wallet.select_coins(AMOUNT_TO_SEND))
|
||||
coins = await wallet.select_coins(uint64(AMOUNT_TO_SEND))
|
||||
coin_list = list(coins)
|
||||
|
||||
tx = await wallet.generate_signed_transaction(
|
||||
AMOUNT_TO_SEND,
|
||||
uint64(AMOUNT_TO_SEND),
|
||||
await wallet_node_2.wallet_state_manager.main_wallet.get_new_puzzlehash(),
|
||||
0,
|
||||
uint64(0),
|
||||
coins=coins,
|
||||
origin_id=coins[2].name(),
|
||||
origin_id=coin_list[2].name(),
|
||||
)
|
||||
assert tx.spend_bundle is not None
|
||||
paid_coin = [coin for coin in tx.spend_bundle.additions() if coin.amount == AMOUNT_TO_SEND][0]
|
||||
assert paid_coin.parent_coin_info == coins[2].name()
|
||||
assert paid_coin.parent_coin_info == coin_list[2].name()
|
||||
await wallet.push_transaction(tx)
|
||||
|
||||
await time_out_assert(5, wallet.get_confirmed_balance, funds)
|
||||
|
Loading…
Reference in New Issue
Block a user