Skip to content

Commit

Permalink
add test for minting coin check in block_body_validation (Chia-Networ…
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidn authored Jul 14, 2021
1 parent 4474026 commit 35dfdbc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
4 changes: 4 additions & 0 deletions tests/block_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1557,6 +1557,10 @@ def create_test_foliage(
for coin in additions:
addition_amount += coin.amount
spend_bundle_fees = removal_amount - addition_amount
# in order to allow creating blocks that mint coins, clamp the fee
# to 0, if it ends up being negative
if spend_bundle_fees < 0:
spend_bundle_fees = 0
else:
spend_bundle_fees = 0

Expand Down
30 changes: 29 additions & 1 deletion tests/blockchain/test_blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -2348,7 +2348,35 @@ async def test_double_spent_in_reorg(self, empty_blockchain):

@pytest.mark.asyncio
async def test_minting_coin(self, empty_blockchain):
# 16 TODO
# 16 Minting coin check
b = empty_blockchain
blocks = bt.get_consecutive_blocks(
3,
guarantee_transaction_block=True,
farmer_reward_puzzle_hash=bt.pool_ph,
pool_reward_puzzle_hash=bt.pool_ph,
)
assert (await b.receive_block(blocks[0]))[0] == ReceiveBlockResult.NEW_PEAK
assert (await b.receive_block(blocks[1]))[0] == ReceiveBlockResult.NEW_PEAK
assert (await b.receive_block(blocks[2]))[0] == ReceiveBlockResult.NEW_PEAK

wt: WalletTool = bt.get_pool_wallet_tool()

spend = list(blocks[-1].get_included_reward_coins())[0]
print("spend=", spend)
# this create coin will spend all of the coin, so the 10 mojos below
# will be "minted".
output = ConditionWithArgs(ConditionOpcode.CREATE_COIN, [bt.pool_ph, int_to_bytes(spend.amount)])
condition_dict = {ConditionOpcode.CREATE_COIN: [output]}

tx: SpendBundle = wt.generate_signed_transaction(
10, wt.get_new_puzzlehash(), spend, condition_dic=condition_dict
)

blocks = bt.get_consecutive_blocks(
1, block_list_input=blocks, guarantee_transaction_block=True, transaction_data=tx
)
assert (await b.receive_block(blocks[-1]))[1] == Err.MINTING_COIN
# 17 is tested in mempool tests
pass

Expand Down

0 comments on commit 35dfdbc

Please sign in to comment.