mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2024-09-21 00:24:37 +03:00
test coin consumed mempool condition
This commit is contained in:
parent
2787901205
commit
86252ce000
@ -7,6 +7,7 @@ from src.server.outbound_message import OutboundMessage
|
||||
from src.protocols import full_node_protocol
|
||||
from src.types.condition_var_pair import ConditionVarPair
|
||||
from src.types.condition_opcodes import ConditionOpcode
|
||||
from src.types.hashable.spend_bundle import SpendBundle
|
||||
from src.util.ints import uint64
|
||||
from tests.setup_nodes import setup_two_nodes, test_constants, bt
|
||||
from tests.wallet_tools import WalletTool
|
||||
@ -573,3 +574,97 @@ class TestMempool:
|
||||
sb1 = full_node_1.mempool_manager.get_spendbundle(spend_bundle1.name())
|
||||
|
||||
assert sb1 is spend_bundle1
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_correct_coin_consumed(self, two_nodes):
|
||||
num_blocks = 4
|
||||
wallet_a = WalletTool()
|
||||
coinbase_puzzlehash = wallet_a.get_new_puzzlehash()
|
||||
wallet_receiver = WalletTool()
|
||||
receiver_puzzlehash = wallet_receiver.get_new_puzzlehash()
|
||||
|
||||
blocks = bt.get_consecutive_blocks(
|
||||
test_constants, num_blocks, [], 10, b"", coinbase_puzzlehash
|
||||
)
|
||||
full_node_1, full_node_2, server_1, server_2 = two_nodes
|
||||
|
||||
block = blocks[1]
|
||||
block2 = blocks[2]
|
||||
|
||||
for b in blocks:
|
||||
async for _ in full_node_1.respond_block(
|
||||
full_node_protocol.RespondBlock(b)
|
||||
):
|
||||
pass
|
||||
|
||||
cvp = ConditionVarPair(
|
||||
ConditionOpcode.ASSERT_COIN_CONSUMED, block2.body.coinbase.name(), None
|
||||
)
|
||||
dic = {cvp.opcode: [cvp]}
|
||||
|
||||
spend_bundle1 = wallet_a.generate_signed_transaction(
|
||||
1000, receiver_puzzlehash, block.body.coinbase, dic
|
||||
)
|
||||
|
||||
spend_bundle2 = wallet_a.generate_signed_transaction(
|
||||
1000, receiver_puzzlehash, block2.body.coinbase
|
||||
)
|
||||
|
||||
bundle = SpendBundle.aggregate([spend_bundle1, spend_bundle2])
|
||||
|
||||
assert spend_bundle1 is not None
|
||||
tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(
|
||||
bundle
|
||||
)
|
||||
async for _ in full_node_1.respond_transaction(tx1):
|
||||
outbound: OutboundMessage = _
|
||||
# Maybe transaction means that it's accepted in mempool
|
||||
assert outbound.message.function == "new_transaction"
|
||||
|
||||
mempool_bundle = full_node_1.mempool_manager.get_spendbundle(bundle.name())
|
||||
|
||||
assert mempool_bundle is bundle
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_invalid_coin_consumed(self, two_nodes):
|
||||
num_blocks = 4
|
||||
wallet_a = WalletTool()
|
||||
coinbase_puzzlehash = wallet_a.get_new_puzzlehash()
|
||||
wallet_receiver = WalletTool()
|
||||
receiver_puzzlehash = wallet_receiver.get_new_puzzlehash()
|
||||
|
||||
blocks = bt.get_consecutive_blocks(
|
||||
test_constants, num_blocks, [], 10, b"", coinbase_puzzlehash
|
||||
)
|
||||
full_node_1, full_node_2, server_1, server_2 = two_nodes
|
||||
|
||||
block = blocks[1]
|
||||
block2 = blocks[2]
|
||||
|
||||
for b in blocks:
|
||||
async for _ in full_node_1.respond_block(
|
||||
full_node_protocol.RespondBlock(b)
|
||||
):
|
||||
pass
|
||||
|
||||
cvp = ConditionVarPair(
|
||||
ConditionOpcode.ASSERT_COIN_CONSUMED, block2.body.coinbase.name(), None
|
||||
)
|
||||
dic = {cvp.opcode: [cvp]}
|
||||
|
||||
spend_bundle1 = wallet_a.generate_signed_transaction(
|
||||
1000, receiver_puzzlehash, block.body.coinbase, dic
|
||||
)
|
||||
|
||||
assert spend_bundle1 is not None
|
||||
tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(
|
||||
spend_bundle1
|
||||
)
|
||||
async for _ in full_node_1.respond_transaction(tx1):
|
||||
outbound: OutboundMessage = _
|
||||
# Maybe transaction means that it's accepted in mempool
|
||||
assert outbound.message.function == "new_transaction"
|
||||
|
||||
mempool_bundle = full_node_1.mempool_manager.get_spendbundle(spend_bundle1.name())
|
||||
|
||||
assert mempool_bundle is None
|
||||
|
Loading…
Reference in New Issue
Block a user