From 370444a7ffb077e9654645fd4ef7d6d8305a64fd Mon Sep 17 00:00:00 2001 From: Florin Chirica Date: Wed, 16 Jun 2021 19:48:28 +0300 Subject: [PATCH 01/11] Fix compact error message. (#6808) --- chia/full_node/full_node.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/chia/full_node/full_node.py b/chia/full_node/full_node.py index 08f83183df94..2522c88a7535 100644 --- a/chia/full_node/full_node.py +++ b/chia/full_node/full_node.py @@ -1761,9 +1761,10 @@ class FullNode: vdf_proof: VDFProof, height: uint32, field_vdf: CompressibleVDFField, - ): + ) -> bool: full_blocks = await self.block_store.get_full_blocks_at([height]) assert len(full_blocks) > 0 + replaced = False for block in full_blocks: new_block = None block_record = await self.blockchain.get_block_record_from_db(self.blockchain.height_to_hash(height)) @@ -1798,11 +1799,12 @@ class FullNode: if block.reward_chain_block.challenge_chain_ip_vdf == vdf_info: new_block = dataclasses.replace(block, challenge_chain_ip_proof=vdf_proof) if new_block is None: - self.log.debug("did not replace any proof, vdf does not match") - return + continue async with self.db_wrapper.lock: await self.block_store.add_full_block(new_block.header_hash, new_block, block_record) await self.block_store.db_wrapper.commit_transaction() + replaced = True + return replaced async def respond_compact_proof_of_time(self, request: timelord_protocol.RespondCompactProofOfTime): field_vdf = CompressibleVDFField(int(request.field_vdf)) @@ -1811,7 +1813,10 @@ class FullNode: ): return None async with self.blockchain.compact_proof_lock: - await self._replace_proof(request.vdf_info, request.vdf_proof, request.height, field_vdf) + replaced = await self._replace_proof(request.vdf_info, request.vdf_proof, request.height, field_vdf) + if not replaced: + self.log.error(f"Could not replace compact proof: {request.height}") + return None msg = make_msg( ProtocolMessageTypes.new_compact_vdf, full_node_protocol.NewCompactVDF(request.height, request.header_hash, request.field_vdf, request.vdf_info), @@ -1890,7 +1895,10 @@ class FullNode: async with self.blockchain.compact_proof_lock: if self.blockchain.seen_compact_proofs(request.vdf_info, request.height): return None - await self._replace_proof(request.vdf_info, request.vdf_proof, request.height, field_vdf) + replaced = await self._replace_proof(request.vdf_info, request.vdf_proof, request.height, field_vdf) + if not replaced: + self.log.error(f"Could not replace compact proof: {request.height}") + return None msg = make_msg( ProtocolMessageTypes.new_compact_vdf, full_node_protocol.NewCompactVDF(request.height, request.header_hash, request.field_vdf, request.vdf_info), From 662286cc1a76c99d48a67151cb22c949815b9d5b Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 16 Jun 2021 20:10:46 +0200 Subject: [PATCH 02/11] extend and improve Mempool tests (#6781) * make sure mempool condition tests fail for the right reason * use int_to_bytes * add more mempool condition tests * simplify one mempool test --- tests/core/full_node/test_mempool.py | 276 ++++++++++++++++++++++----- 1 file changed, 228 insertions(+), 48 deletions(-) diff --git a/tests/core/full_node/test_mempool.py b/tests/core/full_node/test_mempool.py index 567723f5f0e1..f75f3bd03c06 100644 --- a/tests/core/full_node/test_mempool.py +++ b/tests/core/full_node/test_mempool.py @@ -1,11 +1,14 @@ import asyncio import logging from time import time -from typing import Dict, List, Optional +from typing import Dict, List, Optional, Tuple import pytest +import chia.server.ws_connection as ws + from chia.full_node.mempool import Mempool +from chia.full_node.full_node_api import FullNodeAPI from chia.protocols import full_node_protocol from chia.simulator.simulator_protocol import FarmNewBlockProtocol from chia.types.announcement import Announcement @@ -18,6 +21,9 @@ from chia.util.clvm import int_to_bytes from chia.util.condition_tools import conditions_for_solution from chia.util.errors import Err from chia.util.ints import uint64 +from chia.util.hash import std_hash +from chia.types.mempool_inclusion_status import MempoolInclusionStatus +from chia.util.api_decorators import api_request, peer_required, bytes_required from tests.connection_utils import connect_and_get_peer from tests.core.node_height import node_height_at_least @@ -95,6 +101,29 @@ class TestMempool: assert spend_bundle is not None +@peer_required +@api_request +@bytes_required +async def respond_transaction( + node: FullNodeAPI, + tx: full_node_protocol.RespondTransaction, + peer: ws.WSChiaConnection, + tx_bytes: bytes = b"", + test: bool = False, +) -> Tuple[MempoolInclusionStatus, Optional[Err]]: + """ + Receives a full transaction from peer. + If tx is added to mempool, send tx_id to others. (new_transaction) + """ + assert tx_bytes != b"" + spend_name = std_hash(tx_bytes) + if spend_name in node.full_node.full_node_store.pending_tx_request: + node.full_node.full_node_store.pending_tx_request.pop(spend_name) + if spend_name in node.full_node.full_node_store.peers_with_tx: + node.full_node.full_node_store.peers_with_tx.pop(spend_name) + return await node.full_node.respond_transaction(tx.transaction, spend_name, peer, test) + + class TestMempoolManager: @pytest.mark.asyncio async def test_basic_mempool_manager(self, two_nodes): @@ -149,7 +178,9 @@ class TestMempoolManager: assert spend_bundle1 is not None tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(spend_bundle1) - await full_node_1.respond_transaction(tx1, peer) + status, err = await respond_transaction(full_node_1, tx1, peer) + assert status == MempoolInclusionStatus.SUCCESS + assert err is None spend_bundle2 = generate_test_spend_bundle( list(blocks[-1].get_included_reward_coins())[0], @@ -157,13 +188,15 @@ class TestMempoolManager: ) assert spend_bundle2 is not None tx2: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(spend_bundle2) - await full_node_1.respond_transaction(tx2, peer) + status, err = await respond_transaction(full_node_1, tx2, peer) sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) sb2 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle2.name()) assert sb1 == spend_bundle1 assert sb2 is None + assert status == MempoolInclusionStatus.PENDING + assert err == Err.MEMPOOL_CONFLICT async def send_sb(self, node, peer, sb): tx = full_node_protocol.RespondTransaction(sb) @@ -293,8 +326,8 @@ class TestMempoolManager: tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(spend_bundle1) - await full_node_1.respond_transaction(tx1, peer) - return blocks, spend_bundle1, peer + status, err = await respond_transaction(full_node_1, tx1, peer) + return blocks, spend_bundle1, peer, status, err @pytest.mark.asyncio async def test_invalid_block_index(self, two_nodes): @@ -304,46 +337,78 @@ class TestMempoolManager: start_height = blocks[-1].height cvp = ConditionWithArgs( ConditionOpcode.ASSERT_HEIGHT_ABSOLUTE, - [uint64(start_height + 5).to_bytes(4, "big")], + [int_to_bytes(start_height + 5)], ) dic = {ConditionOpcode.ASSERT_HEIGHT_ABSOLUTE: [cvp]} - blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic) + blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic) sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) - assert sb1 is None + # the transaction may become valid later + assert status == MempoolInclusionStatus.PENDING + assert err == Err.ASSERT_HEIGHT_ABSOLUTE_FAILED @pytest.mark.asyncio async def test_correct_block_index(self, two_nodes): full_node_1, full_node_2, server_1, server_2 = two_nodes - cvp = ConditionWithArgs(ConditionOpcode.ASSERT_HEIGHT_ABSOLUTE, [uint64(1).to_bytes(4, "big")]) + cvp = ConditionWithArgs(ConditionOpcode.ASSERT_HEIGHT_ABSOLUTE, [int_to_bytes(1)]) dic = {ConditionOpcode.ASSERT_HEIGHT_ABSOLUTE: [cvp]} - blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic) + blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic) sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) - assert sb1 is spend_bundle1 + assert status == MempoolInclusionStatus.SUCCESS + assert err is None + + @pytest.mark.asyncio + async def test_negative_block_index(self, two_nodes): + + full_node_1, full_node_2, server_1, server_2 = two_nodes + cvp = ConditionWithArgs(ConditionOpcode.ASSERT_HEIGHT_ABSOLUTE, [int_to_bytes(-1)]) + dic = {ConditionOpcode.ASSERT_HEIGHT_ABSOLUTE: [cvp]} + blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic) + sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) + assert sb1 is spend_bundle1 + assert status == MempoolInclusionStatus.SUCCESS + assert err is None @pytest.mark.asyncio async def test_invalid_block_age(self, two_nodes): full_node_1, full_node_2, server_1, server_2 = two_nodes - cvp = ConditionWithArgs(ConditionOpcode.ASSERT_HEIGHT_RELATIVE, [uint64(5).to_bytes(4, "big")]) + cvp = ConditionWithArgs(ConditionOpcode.ASSERT_HEIGHT_RELATIVE, [int_to_bytes(5)]) dic = {cvp.opcode: [cvp]} - blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic) + blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic) sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) assert sb1 is None + # the transaction may become valid later + assert status == MempoolInclusionStatus.PENDING + assert err == Err.ASSERT_HEIGHT_RELATIVE_FAILED @pytest.mark.asyncio async def test_correct_block_age(self, two_nodes): full_node_1, full_node_2, server_1, server_2 = two_nodes - cvp = ConditionWithArgs(ConditionOpcode.ASSERT_HEIGHT_RELATIVE, [uint64(1).to_bytes(4, "big")]) + cvp = ConditionWithArgs(ConditionOpcode.ASSERT_HEIGHT_RELATIVE, [int_to_bytes(1)]) dic = {cvp.opcode: [cvp]} - blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic, num_blocks=4) + blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic, num_blocks=4) sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) - assert sb1 is spend_bundle1 + assert status == MempoolInclusionStatus.SUCCESS + assert err is None + + @pytest.mark.asyncio + async def test_negative_block_age(self, two_nodes): + + full_node_1, full_node_2, server_1, server_2 = two_nodes + cvp = ConditionWithArgs(ConditionOpcode.ASSERT_HEIGHT_RELATIVE, [int_to_bytes(-1)]) + dic = {cvp.opcode: [cvp]} + blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic, num_blocks=4) + + sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) + assert sb1 is spend_bundle1 + assert status == MempoolInclusionStatus.SUCCESS + assert err is None @pytest.mark.asyncio async def test_correct_my_id(self, two_nodes): @@ -353,11 +418,12 @@ class TestMempoolManager: coin = list(blocks[-1].get_included_reward_coins())[0] cvp = ConditionWithArgs(ConditionOpcode.ASSERT_MY_COIN_ID, [coin.name()]) dic = {cvp.opcode: [cvp]} - blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic, coin=coin) + blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic, coin=coin) sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) - assert sb1 is spend_bundle1 + assert status == MempoolInclusionStatus.SUCCESS + assert err is None @pytest.mark.asyncio async def test_invalid_my_id(self, two_nodes): @@ -368,11 +434,12 @@ class TestMempoolManager: coin_2 = list(blocks[-2].get_included_reward_coins())[0] cvp = ConditionWithArgs(ConditionOpcode.ASSERT_MY_COIN_ID, [coin_2.name()]) dic = {cvp.opcode: [cvp]} - blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic, coin=coin) + blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic, coin=coin) sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) - assert sb1 is None + assert status == MempoolInclusionStatus.FAILED + assert err == Err.ASSERT_MY_COIN_ID_FAILED @pytest.mark.asyncio async def test_assert_time_exceeds(self, two_nodes): @@ -380,12 +447,27 @@ class TestMempoolManager: full_node_1, full_node_2, server_1, server_2 = two_nodes time_now = uint64(int(time())) - cvp = ConditionWithArgs(ConditionOpcode.ASSERT_SECONDS_ABSOLUTE, [time_now.to_bytes(8, "big")]) + cvp = ConditionWithArgs(ConditionOpcode.ASSERT_SECONDS_ABSOLUTE, [int_to_bytes(time_now)]) dic = {cvp.opcode: [cvp]} - blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic) + blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic) sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) - assert sb1 is spend_bundle1 + assert status == MempoolInclusionStatus.SUCCESS + assert err is None + + @pytest.mark.asyncio + async def test_assert_time_negative(self, two_nodes): + + full_node_1, full_node_2, server_1, server_2 = two_nodes + time_now = -1 + + cvp = ConditionWithArgs(ConditionOpcode.ASSERT_SECONDS_ABSOLUTE, [int_to_bytes(time_now)]) + dic = {cvp.opcode: [cvp]} + blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic) + sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) + assert sb1 is spend_bundle1 + assert status == MempoolInclusionStatus.SUCCESS + assert err is None @pytest.mark.asyncio async def test_assert_time_relative_exceeds(self, two_nodes): @@ -393,22 +475,41 @@ class TestMempoolManager: full_node_1, full_node_2, server_1, server_2 = two_nodes time_relative = uint64(3) - cvp = ConditionWithArgs(ConditionOpcode.ASSERT_SECONDS_RELATIVE, [time_relative.to_bytes(8, "big")]) + cvp = ConditionWithArgs(ConditionOpcode.ASSERT_SECONDS_RELATIVE, [int_to_bytes(time_relative)]) dic = {cvp.opcode: [cvp]} - blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic) + blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic) sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) assert sb1 is None + assert status == MempoolInclusionStatus.FAILED + assert err == Err.ASSERT_SECONDS_RELATIVE_FAILED for i in range(0, 4): await full_node_1.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"0")) tx2: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(spend_bundle1) - await full_node_1.respond_transaction(tx2, peer) + + status, err = await respond_transaction(full_node_1, tx2, peer) sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) - assert sb1 is spend_bundle1 + assert status == MempoolInclusionStatus.SUCCESS + assert err is None + + @pytest.mark.asyncio + async def test_assert_time_relative_negative(self, two_nodes): + + full_node_1, full_node_2, server_1, server_2 = two_nodes + time_relative = -3 + + cvp = ConditionWithArgs(ConditionOpcode.ASSERT_SECONDS_RELATIVE, [int_to_bytes(time_relative)]) + dic = {cvp.opcode: [cvp]} + blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic) + + sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) + assert sb1 is spend_bundle1 + assert status == MempoolInclusionStatus.SUCCESS + assert err is None @pytest.mark.asyncio async def test_correct_coin_announcement_consumed(self, two_nodes): @@ -448,11 +549,13 @@ class TestMempoolManager: bundle = SpendBundle.aggregate([spend_bundle1, spend_bundle2]) tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(bundle) - await full_node_1.respond_transaction(tx1, peer) + status, err = await respond_transaction(full_node_1, tx1, peer) mempool_bundle = full_node_1.full_node.mempool_manager.get_spendbundle(bundle.name()) assert mempool_bundle is bundle + assert status == MempoolInclusionStatus.SUCCESS + assert err is None @pytest.mark.asyncio async def test_coin_announcement_too_big(self, two_nodes): @@ -492,9 +595,11 @@ class TestMempoolManager: bundle = SpendBundle.aggregate([spend_bundle1, spend_bundle2]) tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(bundle) - await full_node_1.respond_transaction(tx1, peer) + status, err = await respond_transaction(full_node_1, tx1, peer) assert full_node_1.full_node.mempool_manager.get_spendbundle(bundle.name()) is None + assert status == MempoolInclusionStatus.FAILED + assert err == Err.ASSERT_ANNOUNCE_CONSUMED_FAILED blocks = bt.get_consecutive_blocks( 1, block_list_input=blocks, guarantee_transaction_block=True, transaction_data=bundle @@ -546,11 +651,13 @@ class TestMempoolManager: bundle = SpendBundle.aggregate([spend_bundle1, spend_bundle2]) tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(spend_bundle1) - await full_node_1.respond_transaction(tx1, peer) + status, err = await respond_transaction(full_node_1, tx1, peer) mempool_bundle = full_node_1.full_node.mempool_manager.get_spendbundle(bundle.name()) assert mempool_bundle is None + assert status == MempoolInclusionStatus.FAILED + assert err == Err.ASSERT_ANNOUNCE_CONSUMED_FAILED @pytest.mark.asyncio async def test_invalid_coin_announcement_rejected_two(self, two_nodes): @@ -594,11 +701,13 @@ class TestMempoolManager: bundle = SpendBundle.aggregate([spend_bundle1, spend_bundle2]) tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(spend_bundle1) - await full_node_1.respond_transaction(tx1, peer) + status, err = await respond_transaction(full_node_1, tx1, peer) mempool_bundle = full_node_1.full_node.mempool_manager.get_spendbundle(bundle.name()) assert mempool_bundle is None + assert status == MempoolInclusionStatus.FAILED + assert err == Err.ASSERT_ANNOUNCE_CONSUMED_FAILED @pytest.mark.asyncio async def test_correct_puzzle_announcement(self, two_nodes): @@ -638,11 +747,13 @@ class TestMempoolManager: bundle = SpendBundle.aggregate([spend_bundle1, spend_bundle2]) tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(bundle) - await full_node_1.respond_transaction(tx1, peer) + status, err = await respond_transaction(full_node_1, tx1, peer) mempool_bundle = full_node_1.full_node.mempool_manager.get_spendbundle(bundle.name()) assert mempool_bundle is bundle + assert status == MempoolInclusionStatus.SUCCESS + assert err is None @pytest.mark.asyncio async def test_invalid_puzzle_announcement_rejected(self, two_nodes): @@ -685,11 +796,13 @@ class TestMempoolManager: bundle = SpendBundle.aggregate([spend_bundle1, spend_bundle2]) tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(spend_bundle1) - await full_node_1.respond_transaction(tx1, peer) + status, err = await respond_transaction(full_node_1, tx1, peer) mempool_bundle = full_node_1.full_node.mempool_manager.get_spendbundle(bundle.name()) assert mempool_bundle is None + assert status == MempoolInclusionStatus.FAILED + assert err == Err.ASSERT_ANNOUNCE_CONSUMED_FAILED @pytest.mark.asyncio async def test_invalid_puzzle_announcement_rejected_two(self, two_nodes): @@ -732,11 +845,13 @@ class TestMempoolManager: bundle = SpendBundle.aggregate([spend_bundle1, spend_bundle2]) tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(spend_bundle1) - await full_node_1.respond_transaction(tx1, peer) + status, err = await respond_transaction(full_node_1, tx1, peer) mempool_bundle = full_node_1.full_node.mempool_manager.get_spendbundle(bundle.name()) assert mempool_bundle is None + assert status == MempoolInclusionStatus.FAILED + assert err == Err.ASSERT_ANNOUNCE_CONSUMED_FAILED @pytest.mark.asyncio async def test_assert_fee_condition(self, two_nodes): @@ -744,17 +859,35 @@ class TestMempoolManager: full_node_1, full_node_2, server_1, server_2 = two_nodes cvp = ConditionWithArgs(ConditionOpcode.RESERVE_FEE, [int_to_bytes(10)]) dic = {cvp.opcode: [cvp]} - blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic, fee=10) + blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic, fee=10) mempool_bundle = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) assert mempool_bundle is not None + assert status == MempoolInclusionStatus.SUCCESS + assert err is None @pytest.mark.asyncio async def test_assert_fee_condition_negative_fee(self, two_nodes): full_node_1, full_node_2, server_1, server_2 = two_nodes cvp = ConditionWithArgs(ConditionOpcode.RESERVE_FEE, [int_to_bytes(-1)]) dic = {cvp.opcode: [cvp]} - blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic, fee=10) + blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic, fee=10) + assert status == MempoolInclusionStatus.FAILED + assert err == Err.RESERVE_FEE_CONDITION_FAILED + blocks = bt.get_consecutive_blocks( + 1, block_list_input=blocks, guarantee_transaction_block=True, transaction_data=spend_bundle1 + ) + assert full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) is None + assert (await full_node_1.full_node.blockchain.receive_block(blocks[-1]))[1] == Err.RESERVE_FEE_CONDITION_FAILED + + @pytest.mark.asyncio + async def test_assert_fee_condition_fee_too_large(self, two_nodes): + full_node_1, full_node_2, server_1, server_2 = two_nodes + cvp = ConditionWithArgs(ConditionOpcode.RESERVE_FEE, [int_to_bytes(2 ** 64)]) + dic = {cvp.opcode: [cvp]} + blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic, fee=10) + assert status == MempoolInclusionStatus.FAILED + assert err == Err.RESERVE_FEE_CONDITION_FAILED blocks = bt.get_consecutive_blocks( 1, block_list_input=blocks, guarantee_transaction_block=True, transaction_data=spend_bundle1 ) @@ -768,10 +901,12 @@ class TestMempoolManager: cvp = ConditionWithArgs(ConditionOpcode.RESERVE_FEE, [int_to_bytes(10)]) dic = {cvp.opcode: [cvp]} - blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic, fee=9) + blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic, fee=9) mempool_bundle = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) assert mempool_bundle is None + assert status == MempoolInclusionStatus.FAILED + assert err == Err.RESERVE_FEE_CONDITION_FAILED @pytest.mark.asyncio async def test_stealing_fee(self, two_nodes): @@ -822,11 +957,13 @@ class TestMempoolManager: tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(spend_bundle1) - await full_node_1.respond_transaction(tx1, peer) + status, err = await respond_transaction(full_node_1, tx1, peer) mempool_bundle = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) assert mempool_bundle is None + assert status == MempoolInclusionStatus.FAILED + assert err == Err.RESERVE_FEE_CONDITION_FAILED @pytest.mark.asyncio async def test_double_spend_same_bundle(self, two_nodes): @@ -863,10 +1000,12 @@ class TestMempoolManager: tx: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(spend_bundle_combined) - await full_node_1.respond_transaction(tx, peer) + status, err = await respond_transaction(full_node_1, tx, peer) sb = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle_combined.name()) assert sb is None + assert status == MempoolInclusionStatus.FAILED + assert err == Err.DOUBLE_SPEND @pytest.mark.asyncio async def test_agg_sig_condition(self, two_nodes): @@ -926,11 +1065,13 @@ class TestMempoolManager: coin = list(blocks[-1].get_included_reward_coins())[0] cvp = ConditionWithArgs(ConditionOpcode.ASSERT_MY_PARENT_ID, [coin.parent_coin_info]) dic = {cvp.opcode: [cvp]} - blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic, coin=coin) + blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic, coin=coin) sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) assert sb1 is spend_bundle1 + assert status == MempoolInclusionStatus.SUCCESS + assert err is None @pytest.mark.asyncio async def test_invalid_my_parent(self, two_nodes): @@ -941,11 +1082,13 @@ class TestMempoolManager: coin_2 = list(blocks[-2].get_included_reward_coins())[0] cvp = ConditionWithArgs(ConditionOpcode.ASSERT_MY_PARENT_ID, [coin_2.parent_coin_info]) dic = {cvp.opcode: [cvp]} - blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic, coin=coin) + blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic, coin=coin) sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) assert sb1 is None + assert status == MempoolInclusionStatus.FAILED + assert err == Err.ASSERT_MY_PARENT_ID_FAILED @pytest.mark.asyncio async def test_correct_my_puzhash(self, two_nodes): @@ -955,11 +1098,13 @@ class TestMempoolManager: coin = list(blocks[-1].get_included_reward_coins())[0] cvp = ConditionWithArgs(ConditionOpcode.ASSERT_MY_PUZZLEHASH, [coin.puzzle_hash]) dic = {cvp.opcode: [cvp]} - blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic, coin=coin) + blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic, coin=coin) sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) assert sb1 is spend_bundle1 + assert status == MempoolInclusionStatus.SUCCESS + assert err is None @pytest.mark.asyncio async def test_invalid_my_puzhash(self, two_nodes): @@ -969,11 +1114,13 @@ class TestMempoolManager: coin = list(blocks[-1].get_included_reward_coins())[0] cvp = ConditionWithArgs(ConditionOpcode.ASSERT_MY_PUZZLEHASH, [Program.to([]).get_tree_hash()]) dic = {cvp.opcode: [cvp]} - blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic, coin=coin) + blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic, coin=coin) sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) assert sb1 is None + assert status == MempoolInclusionStatus.FAILED + assert err == Err.ASSERT_MY_PUZZLEHASH_FAILED @pytest.mark.asyncio async def test_correct_my_amount(self, two_nodes): @@ -981,24 +1128,57 @@ class TestMempoolManager: full_node_1, full_node_2, server_1, server_2 = two_nodes blocks = await full_node_1.get_all_full_blocks() coin = list(blocks[-1].get_included_reward_coins())[0] - cvp = ConditionWithArgs(ConditionOpcode.ASSERT_MY_AMOUNT, [coin.amount]) + cvp = ConditionWithArgs(ConditionOpcode.ASSERT_MY_AMOUNT, [int_to_bytes(coin.amount)]) dic = {cvp.opcode: [cvp]} - blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic, coin=coin) + blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic, coin=coin) sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) assert sb1 is spend_bundle1 + assert status == MempoolInclusionStatus.SUCCESS + assert err is None @pytest.mark.asyncio async def test_invalid_my_amount(self, two_nodes): full_node_1, full_node_2, server_1, server_2 = two_nodes blocks = await full_node_1.get_all_full_blocks() - coin = list(blocks[-1].get_included_reward_coins())[0] - cvp = ConditionWithArgs(ConditionOpcode.ASSERT_MY_AMOUNT, [1000]) + cvp = ConditionWithArgs(ConditionOpcode.ASSERT_MY_AMOUNT, [int_to_bytes(1000)]) dic = {cvp.opcode: [cvp]} - blocks, spend_bundle1, peer = await self.condition_tester(two_nodes, dic, coin=coin) + blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic) sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) assert sb1 is None + assert status == MempoolInclusionStatus.FAILED + assert err == Err.ASSERT_MY_AMOUNT_FAILED + + @pytest.mark.asyncio + async def test_negative_my_amount(self, two_nodes): + + full_node_1, full_node_2, server_1, server_2 = two_nodes + blocks = await full_node_1.get_all_full_blocks() + cvp = ConditionWithArgs(ConditionOpcode.ASSERT_MY_AMOUNT, [int_to_bytes(-1)]) + dic = {cvp.opcode: [cvp]} + blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic) + + sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) + + assert sb1 is None + assert status == MempoolInclusionStatus.FAILED + assert err == Err.ASSERT_MY_AMOUNT_FAILED + + @pytest.mark.asyncio + async def test_my_amount_too_large(self, two_nodes): + + full_node_1, full_node_2, server_1, server_2 = two_nodes + blocks = await full_node_1.get_all_full_blocks() + cvp = ConditionWithArgs(ConditionOpcode.ASSERT_MY_AMOUNT, [int_to_bytes(2 ** 64)]) + dic = {cvp.opcode: [cvp]} + blocks, spend_bundle1, peer, status, err = await self.condition_tester(two_nodes, dic) + + sb1 = full_node_1.full_node.mempool_manager.get_spendbundle(spend_bundle1.name()) + + assert sb1 is None + assert status == MempoolInclusionStatus.FAILED + assert err == Err.ASSERT_MY_AMOUNT_FAILED From 42fde9a8d44449dc56c901d4dbd2a79f2f260d40 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 16 Jun 2021 20:12:26 +0200 Subject: [PATCH 03/11] move chia.util.block_tools and chia.util.wallet_tools into tests (#6799) * move chia.util.block_tools and chia.util.wallet_tools into tests * only depend on block_tools when we actually run the wallet in test mode --- chia/server/start_wallet.py | 3 ++- chia/simulator/simulator_constants.py | 2 +- chia/simulator/start_simulator.py | 2 +- {chia/util => tests}/block_tools.py | 2 +- tests/blockchain/test_blockchain.py | 4 ++-- tests/blockchain/test_blockchain_transactions.py | 2 +- tests/core/daemon/test_daemon.py | 2 +- tests/core/full_node/test_coin_store.py | 2 +- tests/core/full_node/test_conditions.py | 2 +- tests/core/full_node/test_full_node.py | 4 ++-- tests/core/full_node/test_full_node_store.py | 2 +- tests/core/full_node/test_performance.py | 2 +- tests/core/ssl/test_ssl.py | 2 +- tests/core/test_farmer_harvester_rpc.py | 2 +- tests/core/test_full_node_rpc.py | 2 +- tests/setup_nodes.py | 2 +- tests/simulation/test_simulation.py | 2 +- tests/util/benchmark_cost.py | 2 +- tests/util/key_tool.py | 2 +- {chia/util => tests}/wallet_tools.py | 0 tests/weight_proof/test_weight_proof.py | 2 +- 21 files changed, 23 insertions(+), 22 deletions(-) rename {chia/util => tests}/block_tools.py (99%) rename {chia/util => tests}/wallet_tools.py (100%) diff --git a/chia/server/start_wallet.py b/chia/server/start_wallet.py index ac602f74a5cd..20cf96b2c37a 100644 --- a/chia/server/start_wallet.py +++ b/chia/server/start_wallet.py @@ -8,7 +8,6 @@ from chia.rpc.wallet_rpc_api import WalletRpcApi from chia.server.outbound_message import NodeType from chia.server.start_service import run_service from chia.types.peer_info import PeerInfo -from chia.util.block_tools import test_constants from chia.util.config import load_config_cli, load_config from chia.util.default_root import DEFAULT_ROOT_PATH from chia.util.keychain import Keychain @@ -81,6 +80,8 @@ def main() -> None: # This is simulator local_test = config["testing"] if local_test is True: + from tests.block_tools import test_constants + constants = test_constants current = config["database_path"] config["database_path"] = f"{current}_simulation" diff --git a/chia/simulator/simulator_constants.py b/chia/simulator/simulator_constants.py index d77a47a98635..f3d8ff6463e2 100644 --- a/chia/simulator/simulator_constants.py +++ b/chia/simulator/simulator_constants.py @@ -1,5 +1,5 @@ if __name__ == "__main__": - from chia.util.block_tools import BlockTools, test_constants + from tests.block_tools import BlockTools, test_constants from chia.util.default_root import DEFAULT_ROOT_PATH # TODO: mariano: fix this with new consensus diff --git a/chia/simulator/start_simulator.py b/chia/simulator/start_simulator.py index 286865a25435..509fe11760fc 100644 --- a/chia/simulator/start_simulator.py +++ b/chia/simulator/start_simulator.py @@ -6,7 +6,7 @@ from chia.full_node.full_node import FullNode from chia.rpc.full_node_rpc_api import FullNodeRpcApi from chia.server.outbound_message import NodeType from chia.server.start_service import run_service -from chia.util.block_tools import BlockTools, test_constants +from tests.block_tools import BlockTools, test_constants from chia.util.config import load_config_cli from chia.util.default_root import DEFAULT_ROOT_PATH from chia.util.path import mkdir, path_from_root diff --git a/chia/util/block_tools.py b/tests/block_tools.py similarity index 99% rename from chia/util/block_tools.py rename to tests/block_tools.py index 950add364e56..6b04d1deb29f 100644 --- a/chia/util/block_tools.py +++ b/tests/block_tools.py @@ -65,7 +65,7 @@ from chia.util.ints import uint8, uint32, uint64, uint128 from chia.util.keychain import Keychain, bytes_to_mnemonic from chia.util.path import mkdir from chia.util.vdf_prover import get_vdf_info_and_proof -from chia.util.wallet_tools import WalletTool +from tests.wallet_tools import WalletTool from chia.wallet.derive_keys import ( master_sk_to_farmer_sk, master_sk_to_local_sk, diff --git a/tests/blockchain/test_blockchain.py b/tests/blockchain/test_blockchain.py index de6d2d3f8181..a46225aa8020 100644 --- a/tests/blockchain/test_blockchain.py +++ b/tests/blockchain/test_blockchain.py @@ -28,13 +28,13 @@ from chia.types.end_of_slot_bundle import EndOfSubSlotBundle from chia.types.full_block import FullBlock from chia.types.spend_bundle import SpendBundle from chia.types.unfinished_block import UnfinishedBlock -from chia.util.block_tools import BlockTools, get_vdf_info_and_proof +from tests.block_tools import BlockTools, get_vdf_info_and_proof from chia.util.errors import Err from chia.util.hash import std_hash from chia.util.ints import uint8, uint64, uint32 from chia.util.merkle_set import MerkleSet from chia.util.recursive_replace import recursive_replace -from chia.util.wallet_tools import WalletTool +from tests.wallet_tools import WalletTool from tests.core.fixtures import default_400_blocks # noqa: F401; noqa: F401 from tests.core.fixtures import default_1000_blocks # noqa: F401 from tests.core.fixtures import default_10000_blocks # noqa: F401 diff --git a/tests/blockchain/test_blockchain_transactions.py b/tests/blockchain/test_blockchain_transactions.py index 4d30306a94ea..1cda186263c9 100644 --- a/tests/blockchain/test_blockchain_transactions.py +++ b/tests/blockchain/test_blockchain_transactions.py @@ -12,7 +12,7 @@ from chia.types.condition_with_args import ConditionWithArgs from chia.types.spend_bundle import SpendBundle from chia.util.errors import ConsensusError, Err from chia.util.ints import uint64 -from chia.util.wallet_tools import WalletTool +from tests.wallet_tools import WalletTool from tests.core.full_node.test_full_node import connect_and_get_peer from tests.setup_nodes import bt, setup_two_nodes, test_constants from tests.util.generator_tools_testing import run_and_get_removals_and_additions diff --git a/tests/core/daemon/test_daemon.py b/tests/core/daemon/test_daemon.py index b5b0b7cde4c2..cef16709c9ae 100644 --- a/tests/core/daemon/test_daemon.py +++ b/tests/core/daemon/test_daemon.py @@ -6,7 +6,7 @@ import pytest from chia.server.outbound_message import NodeType from chia.server.server import ssl_context_for_server from chia.types.peer_info import PeerInfo -from chia.util.block_tools import BlockTools +from tests.block_tools import BlockTools from chia.util.ints import uint16 from chia.util.ws_message import create_payload from tests.core.node_height import node_height_at_least diff --git a/tests/core/full_node/test_coin_store.py b/tests/core/full_node/test_coin_store.py index ad92b6de048a..4bbb3083b210 100644 --- a/tests/core/full_node/test_coin_store.py +++ b/tests/core/full_node/test_coin_store.py @@ -18,7 +18,7 @@ from chia.types.full_block import FullBlock from chia.types.generator_types import BlockGenerator from chia.util.generator_tools import tx_removals_and_additions from chia.util.ints import uint64, uint32 -from chia.util.wallet_tools import WalletTool +from tests.wallet_tools import WalletTool from chia.util.db_wrapper import DBWrapper from tests.setup_nodes import bt, test_constants diff --git a/tests/core/full_node/test_conditions.py b/tests/core/full_node/test_conditions.py index 5cd784181515..6c8d273d69f2 100644 --- a/tests/core/full_node/test_conditions.py +++ b/tests/core/full_node/test_conditions.py @@ -22,7 +22,7 @@ from chia.types.coin_solution import CoinSolution from chia.types.condition_opcodes import ConditionOpcode from chia.types.full_block import FullBlock from chia.types.spend_bundle import SpendBundle -from chia.util.block_tools import BlockTools, test_constants +from tests.block_tools import BlockTools, test_constants from chia.util.errors import Err from .ram_db import create_ram_blockchain diff --git a/tests/core/full_node/test_full_node.py b/tests/core/full_node/test_full_node.py index e1629d3e16c8..496580213b94 100644 --- a/tests/core/full_node/test_full_node.py +++ b/tests/core/full_node/test_full_node.py @@ -30,14 +30,14 @@ from chia.types.mempool_inclusion_status import MempoolInclusionStatus from chia.types.peer_info import PeerInfo, TimestampedPeerInfo from chia.types.spend_bundle import SpendBundle from chia.types.unfinished_block import UnfinishedBlock -from chia.util.block_tools import get_signage_point +from tests.block_tools import get_signage_point from chia.util.clvm import int_to_bytes from chia.util.errors import Err from chia.util.hash import std_hash from chia.util.ints import uint8, uint16, uint32, uint64 from chia.util.recursive_replace import recursive_replace from chia.util.vdf_prover import get_vdf_info_and_proof -from chia.util.wallet_tools import WalletTool +from tests.wallet_tools import WalletTool from tests.core.fixtures import empty_blockchain # noqa: F401 from chia.wallet.cc_wallet.cc_wallet import CCWallet from chia.wallet.transaction_record import TransactionRecord diff --git a/tests/core/full_node/test_full_node_store.py b/tests/core/full_node/test_full_node_store.py index 7a5e9d1ddb01..7ab2cc828ab2 100644 --- a/tests/core/full_node/test_full_node_store.py +++ b/tests/core/full_node/test_full_node_store.py @@ -15,7 +15,7 @@ from chia.protocols.timelord_protocol import NewInfusionPointVDF from chia.types.blockchain_format.sized_bytes import bytes32 from chia.types.unfinished_block import UnfinishedBlock from chia.util.block_cache import BlockCache -from chia.util.block_tools import get_signage_point +from tests.block_tools import get_signage_point from chia.util.hash import std_hash from chia.util.ints import uint8, uint32, uint64, uint128 from tests.core.fixtures import default_1000_blocks, empty_blockchain # noqa: F401 diff --git a/tests/core/full_node/test_performance.py b/tests/core/full_node/test_performance.py index 45484b5f493c..46f81377a2ff 100644 --- a/tests/core/full_node/test_performance.py +++ b/tests/core/full_node/test_performance.py @@ -17,7 +17,7 @@ from chia.types.condition_with_args import ConditionWithArgs from chia.types.unfinished_block import UnfinishedBlock from chia.util.clvm import int_to_bytes from chia.util.ints import uint64 -from chia.util.wallet_tools import WalletTool +from tests.wallet_tools import WalletTool from tests.core.fixtures import empty_blockchain # noqa: F401 from tests.connection_utils import add_dummy_connection, connect_and_get_peer diff --git a/tests/core/ssl/test_ssl.py b/tests/core/ssl/test_ssl.py index 79423650e93c..ea9f9cdfbd73 100644 --- a/tests/core/ssl/test_ssl.py +++ b/tests/core/ssl/test_ssl.py @@ -9,7 +9,7 @@ from chia.server.server import ChiaServer, ssl_context_for_client from chia.server.ws_connection import WSChiaConnection from chia.ssl.create_ssl import generate_ca_signed_cert from chia.types.peer_info import PeerInfo -from chia.util.block_tools import test_constants +from tests.block_tools import test_constants from chia.util.ints import uint16 from tests.setup_nodes import ( bt, diff --git a/tests/core/test_farmer_harvester_rpc.py b/tests/core/test_farmer_harvester_rpc.py index 8b9f3fe31dc2..435f9d9df501 100644 --- a/tests/core/test_farmer_harvester_rpc.py +++ b/tests/core/test_farmer_harvester_rpc.py @@ -14,7 +14,7 @@ from chia.rpc.harvester_rpc_client import HarvesterRpcClient from chia.rpc.rpc_server import start_rpc_server from chia.types.blockchain_format.sized_bytes import bytes32 from chia.util.bech32m import decode_puzzle_hash, encode_puzzle_hash -from chia.util.block_tools import get_plot_dir +from tests.block_tools import get_plot_dir from chia.util.config import load_config from chia.util.hash import std_hash from chia.util.ints import uint8, uint16, uint32, uint64 diff --git a/tests/core/test_full_node_rpc.py b/tests/core/test_full_node_rpc.py index f46dbcd915d1..3ea58229af1d 100644 --- a/tests/core/test_full_node_rpc.py +++ b/tests/core/test_full_node_rpc.py @@ -11,7 +11,7 @@ from chia.types.spend_bundle import SpendBundle from chia.types.unfinished_block import UnfinishedBlock from chia.util.hash import std_hash from chia.util.ints import uint16 -from chia.util.wallet_tools import WalletTool +from tests.wallet_tools import WalletTool from tests.setup_nodes import bt, self_hostname, setup_simulators_and_wallets, test_constants from tests.time_out_assert import time_out_assert diff --git a/tests/setup_nodes.py b/tests/setup_nodes.py index c72946cba1e4..b28fe158a160 100644 --- a/tests/setup_nodes.py +++ b/tests/setup_nodes.py @@ -18,7 +18,7 @@ from chia.simulator.start_simulator import service_kwargs_for_full_node_simulato from chia.timelord.timelord_launcher import kill_processes, spawn_process from chia.types.peer_info import PeerInfo from chia.util.bech32m import encode_puzzle_hash -from chia.util.block_tools import BlockTools, test_constants +from tests.block_tools import BlockTools, test_constants from chia.util.hash import std_hash from chia.util.ints import uint16, uint32 from chia.util.keychain import Keychain, bytes_to_mnemonic diff --git a/tests/simulation/test_simulation.py b/tests/simulation/test_simulation.py index 01335bf3027f..d125137e6897 100644 --- a/tests/simulation/test_simulation.py +++ b/tests/simulation/test_simulation.py @@ -1,7 +1,7 @@ import pytest from chia.types.peer_info import PeerInfo -from chia.util.block_tools import BlockTools +from tests.block_tools import BlockTools from chia.util.ints import uint16 from tests.core.node_height import node_height_at_least from tests.setup_nodes import self_hostname, setup_full_node, setup_full_system, test_constants diff --git a/tests/util/benchmark_cost.py b/tests/util/benchmark_cost.py index 412d6ddfe27f..417467917a5f 100644 --- a/tests/util/benchmark_cost.py +++ b/tests/util/benchmark_cost.py @@ -9,7 +9,7 @@ from chia.types.blockchain_format.program import Program, INFINITE_COST from chia.types.condition_opcodes import ConditionOpcode from chia.types.condition_with_args import ConditionWithArgs from chia.util.ints import uint32 -from chia.util.wallet_tools import WalletTool +from tests.wallet_tools import WalletTool from chia.wallet.derive_keys import master_sk_to_wallet_sk from chia.wallet.puzzles.p2_delegated_puzzle import puzzle_for_pk diff --git a/tests/util/key_tool.py b/tests/util/key_tool.py index 4914f1659787..14e96c7a8e6d 100644 --- a/tests/util/key_tool.py +++ b/tests/util/key_tool.py @@ -6,7 +6,7 @@ from chia.types.blockchain_format.sized_bytes import bytes32 from chia.types.coin_solution import CoinSolution from chia.util.condition_tools import conditions_by_opcode, conditions_for_solution, pkm_pairs_for_conditions_dict from tests.core.make_block_generator import GROUP_ORDER, int_to_public_key -from chia.util.block_tools import test_constants +from tests.block_tools import test_constants class KeyTool(dict): diff --git a/chia/util/wallet_tools.py b/tests/wallet_tools.py similarity index 100% rename from chia/util/wallet_tools.py rename to tests/wallet_tools.py diff --git a/tests/weight_proof/test_weight_proof.py b/tests/weight_proof/test_weight_proof.py index 2fcb12b7e29c..7f2f9301e42a 100644 --- a/tests/weight_proof/test_weight_proof.py +++ b/tests/weight_proof/test_weight_proof.py @@ -18,7 +18,7 @@ from chia.server.start_full_node import SERVICE_NAME from chia.types.blockchain_format.sized_bytes import bytes32 from chia.types.blockchain_format.sub_epoch_summary import SubEpochSummary from chia.util.block_cache import BlockCache -from chia.util.block_tools import test_constants +from tests.block_tools import test_constants from chia.util.config import load_config from chia.util.default_root import DEFAULT_ROOT_PATH from chia.util.generator_tools import get_block_header From 867fd09d70a28a724cb1f3d4e1535e210d489cde Mon Sep 17 00:00:00 2001 From: Almog De Paz Date: Wed, 16 Jun 2021 21:15:06 +0300 Subject: [PATCH 04/11] fix flaky cc test (#6800) * fix flaky cc test * lint * add assert * lower test times * dont use timeout * lint --- .../full_node/full_sync/test_full_sync.py | 12 +++++----- tests/wallet/cc_wallet/test_trades.py | 22 +++++-------------- tests/wallet/rl_wallet/test_rl_rpc.py | 3 ++- 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/tests/core/full_node/full_sync/test_full_sync.py b/tests/core/full_node/full_sync/test_full_sync.py index 81a0dd17bf75..3671162aac02 100644 --- a/tests/core/full_node/full_sync/test_full_sync.py +++ b/tests/core/full_node/full_sync/test_full_sync.py @@ -344,13 +344,11 @@ class TestFullSync: for block in default_1000_blocks[1000 - num_blocks_initial :]: await full_node_2.full_node.respond_block(full_node_protocol.RespondBlock(block)) - await time_out_assert(180, node_height_exactly, True, full_node_2, 999) + assert node_height_exactly(full_node_2, 999) @pytest.mark.asyncio - async def test_block_ses_mismatch(self, three_nodes, default_1000_blocks): - full_node_1, full_node_2, full_node_3 = three_nodes - server_1 = full_node_1.full_node.server - server_2 = full_node_2.full_node.server + async def test_block_ses_mismatch(self, two_nodes, default_1000_blocks): + full_node_1, full_node_2, server_1, server_2 = two_nodes blocks = default_1000_blocks for block in blocks[:501]: @@ -363,6 +361,7 @@ class TestFullSync: summaries1, _ = _validate_sub_epoch_summaries(full_node_1.full_node.weight_proof_handler.constants, wp) summaries2 = summaries1 s = summaries1[1] + # change summary so check would fail on 2 sub epoch summaries2[1] = SubEpochSummary( s.prev_subepoch_summary_hash, s.reward_chain_hash, @@ -371,4 +370,5 @@ class TestFullSync: s.new_sub_slot_iters * 2, ) await full_node_2.full_node.sync_from_fork_point(0, 500, peak1.header_hash, summaries2) - await time_out_assert(180, node_height_exactly, True, full_node_2, 320) + log.info(f"full node height {full_node_2.full_node.blockchain.get_peak().height}") + assert node_height_exactly(full_node_2, 320) diff --git a/tests/wallet/cc_wallet/test_trades.py b/tests/wallet/cc_wallet/test_trades.py index f8bb1d1f6fa0..583a90d00924 100644 --- a/tests/wallet/cc_wallet/test_trades.py +++ b/tests/wallet/cc_wallet/test_trades.py @@ -1,5 +1,4 @@ import asyncio -import time from pathlib import Path from secrets import token_bytes @@ -12,6 +11,8 @@ from chia.wallet.cc_wallet.cc_wallet import CCWallet from chia.wallet.trade_manager import TradeManager from chia.wallet.trading.trade_status import TradeStatus from tests.setup_nodes import setup_simulators_and_wallets +from tests.time_out_assert import time_out_assert +from tests.wallet.sync.test_wallet_sync import wallet_height_at_least @pytest.fixture(scope="module") @@ -20,19 +21,6 @@ def event_loop(): yield loop -async def time_out_assert(timeout: int, function, value, arg=None): - start = time.time() - while time.time() - start < timeout: - if arg is None: - function_result = await function() - else: - function_result = await function(arg) - if value == function_result: - return None - await asyncio.sleep(2) - assert False - - @pytest.fixture(scope="module") async def two_wallet_nodes(): async for _ in setup_simulators_and_wallets(1, 2, {}): @@ -86,7 +74,7 @@ class TestCCTrades: for i in range(1, buffer_blocks): await full_node.farm_new_transaction_block(FarmNewBlockProtocol(token_bytes())) - + await time_out_assert(15, wallet_height_at_least, True, wallet_node_0, 27) await time_out_assert(15, cc_wallet.get_confirmed_balance, 100) await time_out_assert(15, cc_wallet.get_unconfirmed_balance, 100) @@ -101,13 +89,14 @@ class TestCCTrades: for i in range(0, buffer_blocks): await full_node.farm_new_transaction_block(FarmNewBlockProtocol(token_bytes())) - + await time_out_assert(15, wallet_height_at_least, True, wallet_node_0, 31) # send cc_wallet 2 a coin cc_hash = await cc_wallet_2.get_new_inner_hash() tx_record = await cc_wallet.generate_signed_transaction([uint64(1)], [cc_hash]) await wallet_0.wallet_state_manager.add_pending_transaction(tx_record) for i in range(0, buffer_blocks): await full_node.farm_new_transaction_block(FarmNewBlockProtocol(token_bytes())) + await time_out_assert(15, wallet_height_at_least, True, wallet_node_0, 35) trade_manager_0 = wallet_node_0.wallet_state_manager.trade_manager trade_manager_1 = wallet_node_1.wallet_state_manager.trade_manager @@ -141,6 +130,7 @@ class TestCCTrades: for i in range(0, buffer_blocks): await full_node.farm_new_transaction_block(FarmNewBlockProtocol(token_bytes())) + await time_out_assert(15, wallet_height_at_least, True, wallet_node_0, 39) await time_out_assert(15, cc_wallet_2.get_confirmed_balance, 31) await time_out_assert(15, cc_wallet_2.get_unconfirmed_balance, 31) trade_2 = await trade_manager_0.get_trade_by_id(trade_offer.trade_id) diff --git a/tests/wallet/rl_wallet/test_rl_rpc.py b/tests/wallet/rl_wallet/test_rl_rpc.py index d1491b41516c..2507b81d28ca 100644 --- a/tests/wallet/rl_wallet/test_rl_rpc.py +++ b/tests/wallet/rl_wallet/test_rl_rpc.py @@ -13,6 +13,7 @@ from chia.util.ints import uint16 from chia.wallet.util.wallet_types import WalletType from tests.setup_nodes import self_hostname, setup_simulators_and_wallets from tests.time_out_assert import time_out_assert +from tests.wallet.sync.test_wallet_sync import wallet_height_at_least @pytest.fixture(scope="module") @@ -157,7 +158,7 @@ class TestRLWallet: await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"\0")) await time_out_assert(15, check_balance, 90, api_user, user_wallet_id) await time_out_assert(15, receiving_wallet.get_spendable_balance, 108) - + await time_out_assert(15, wallet_height_at_least, True, wallet_node, 72) val = await api_admin.send_clawback_transaction({"wallet_id": admin_wallet_id, "fee": 11}) await time_out_assert(15, is_transaction_in_mempool, True, api_admin, val["transaction_id"]) for i in range(0, num_blocks): From f46bfd61978b9e049612fbb50baa083174782077 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 16 Jun 2021 23:39:57 +0200 Subject: [PATCH 05/11] don't use wall-clock time in mempool test for absolute time condition. The validation does not use wall-clock, but expected time based on the peak timestamp (#6801) --- tests/core/full_node/test_mempool.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/core/full_node/test_mempool.py b/tests/core/full_node/test_mempool.py index f75f3bd03c06..7cd5e553b3ef 100644 --- a/tests/core/full_node/test_mempool.py +++ b/tests/core/full_node/test_mempool.py @@ -1,6 +1,6 @@ import asyncio import logging -from time import time + from typing import Dict, List, Optional, Tuple import pytest @@ -445,7 +445,8 @@ class TestMempoolManager: async def test_assert_time_exceeds(self, two_nodes): full_node_1, full_node_2, server_1, server_2 = two_nodes - time_now = uint64(int(time())) + # 5 seconds should be before the next block + time_now = full_node_1.full_node.blockchain.get_peak().timestamp + 5 cvp = ConditionWithArgs(ConditionOpcode.ASSERT_SECONDS_ABSOLUTE, [int_to_bytes(time_now)]) dic = {cvp.opcode: [cvp]} @@ -473,7 +474,7 @@ class TestMempoolManager: async def test_assert_time_relative_exceeds(self, two_nodes): full_node_1, full_node_2, server_1, server_2 = two_nodes - time_relative = uint64(3) + time_relative = 3 cvp = ConditionWithArgs(ConditionOpcode.ASSERT_SECONDS_RELATIVE, [int_to_bytes(time_relative)]) dic = {cvp.opcode: [cvp]} From 5a1bad45ba7d3c303804cdb04d3653a36826b0b8 Mon Sep 17 00:00:00 2001 From: Justin England Date: Thu, 17 Jun 2021 12:51:28 -0600 Subject: [PATCH 06/11] second times a charm (#6834) * second times a charm * Update .github/workflows/build-linux-arm64-installer.yml Co-authored-by: Chris Marslender * Update .github/workflows/build-linux-installer.yml Co-authored-by: Chris Marslender * fixing yaml bug * fixing syntax Co-authored-by: Chris Marslender --- .github/workflows/build-linux-arm64-installer.yml | 15 ++++++++++++++- .github/workflows/build-linux-installer.yml | 14 +++++++++++++- .github/workflows/build-windows-installer.yml | 5 ++++- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-linux-arm64-installer.yml b/.github/workflows/build-linux-arm64-installer.yml index 930a20ede20f..8c13069c89cc 100644 --- a/.github/workflows/build-linux-arm64-installer.yml +++ b/.github/workflows/build-linux-arm64-installer.yml @@ -44,6 +44,16 @@ jobs: echo "::set-output name=CHIA_INSTALLER_VERSION::$(python3 ./build_scripts/installer-version.py)" deactivate + - name: Test for secrets access + id: check_secrets + shell: bash + run: | + unset HAS_SECRET + if [ -n "$SECRET" ]; then HAS_SECRET='true' ; fi + echo ::set-output name=HAS_SECRET::${HAS_SECRET} + env: + SECRET: "${{ secrets.test_pypi_password }" + - name: Build ARM64 Installer run: | podman run --rm=true \ @@ -82,10 +92,12 @@ jobs: path: ${{ github.workspace }}/build_scripts/final_installer/ - name: Install AWS CLI + if: steps.check_secrets.outputs.HAS_SECRET run: | sudo apt-get install -y awscli - name: Configure AWS Credentials + if: steps.check_secrets.outputs.HAS_SECRET uses: aws-actions/configure-aws-credentials@v1 with: aws-access-key-id: ${{ secrets.INSTALLER_UPLOAD_KEY }} @@ -93,6 +105,7 @@ jobs: aws-region: us-west-2 - name: Upload to s3 + if: steps.check_secrets.outputs.HAS_SECRET run: | aws s3 cp ${{ github.workspace }}/build_scripts/final_installer/*.deb s3://download-chia-net/builds/ @@ -106,7 +119,7 @@ jobs: ls ${{ github.workspace }}/build_scripts/final_installer/ - name: Upload Release Files - if: startsWith(github.ref, 'refs/tags/') + if: steps.check_secrets.outputs.HAS_SECRET && startsWith(github.ref, 'refs/tags/') run: | ls ${{ github.workspace }}/build_scripts/final_installer/ aws s3 cp ${{ github.workspace }}/build_scripts/final_installer/*.deb s3://download-chia-net/install/ diff --git a/.github/workflows/build-linux-installer.yml b/.github/workflows/build-linux-installer.yml index 600c3242e9d0..35b641e855a1 100644 --- a/.github/workflows/build-linux-installer.yml +++ b/.github/workflows/build-linux-installer.yml @@ -78,6 +78,16 @@ jobs: echo "::set-output name=CHIA_INSTALLER_VERSION::$(python3 ./build_scripts/installer-version.py)" deactivate + - name: Test for secrets access + id: check_secrets + shell: bash + run: | + unset HAS_SECRET + if [ -n "$SECRET" ]; then HAS_SECRET='true' ; fi + echo ::set-output name=HAS_SECRET::${HAS_SECRET} + env: + SECRET: "${{ secrets.test_pypi_password }" + - name: Run install script env: INSTALL_PYTHON_VERSION: ${{ matrix.python-version }} @@ -107,6 +117,7 @@ jobs: path: ${{ github.workspace }}/build_scripts/final_installer/ - name: Configure AWS Credentials + if: steps.check_secrets.outputs.HAS_SECRET uses: aws-actions/configure-aws-credentials@v1 with: aws-access-key-id: ${{ secrets.INSTALLER_UPLOAD_KEY }} @@ -114,6 +125,7 @@ jobs: aws-region: us-west-2 - name: Upload to s3 + if: steps.check_secrets.outputs.HAS_SECRET env: CHIA_INSTALLER_VERSION: ${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }} run: | @@ -133,7 +145,7 @@ jobs: ls ${{ github.workspace }}/build_scripts/final_installer/ - name: Upload Release Files - if: startsWith(github.ref, 'refs/tags/') + if: steps.check_secrets.outputs.HAS_SECRET && startsWith(github.ref, 'refs/tags/') run: | aws s3 cp ${{ github.workspace }}/build_scripts/final_installer/chia-blockchain_${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}_amd64.deb s3://download-chia-net/install/ aws s3 cp ${{ github.workspace }}/build_scripts/final_installer/chia-blockchain_${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}_amd64.deb.sha256 s3://download-chia-net/install/ diff --git a/.github/workflows/build-windows-installer.yml b/.github/workflows/build-windows-installer.yml index 3a7ea7e70924..90561c4892e2 100644 --- a/.github/workflows/build-windows-installer.yml +++ b/.github/workflows/build-windows-installer.yml @@ -113,10 +113,12 @@ jobs: - name: Install AWS CLI + if: steps.check_secrets.outputs.HAS_SECRET run: | msiexec.exe /i https://awscli.amazonaws.com/AWSCLIV2.msi - name: Configure AWS Credentials + if: steps.check_secrets.outputs.HAS_SECRET uses: aws-actions/configure-aws-credentials@v1 with: aws-access-key-id: ${{ secrets.INSTALLER_UPLOAD_KEY }} @@ -124,6 +126,7 @@ jobs: aws-region: us-west-2 - name: Upload to s3 + if: steps.check_secrets.outputs.HAS_SECRET env: CHIA_INSTALLER_VERSION: ${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }} run: | @@ -139,7 +142,7 @@ jobs: ls ${{ github.workspace }}\chia-blockchain-gui\release-builds\windows-installer\ - name: Upload Release Files - if: startsWith(github.ref, 'refs/tags/') + if: steps.check_secrets.outputs.HAS_SECRET && startsWith(github.ref, 'refs/tags/') env: AWS_ACCESS_KEY_ID: ${{ secrets.INSTALLER_UPLOAD_KEY }} AWS_SECRET_ACCESS_KEY: ${{ secrets.INSTALLER_UPLOAD_SECRET }} From 150b6cc9b029c2401e4300636c0e2447f14f929d Mon Sep 17 00:00:00 2001 From: Earle Lowe <30607889+emlowe@users.noreply.github.com> Date: Fri, 18 Jun 2021 05:22:01 -0700 Subject: [PATCH 07/11] remove non-ascii space (#6842) --- chia/util/initial-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chia/util/initial-config.yaml b/chia/util/initial-config.yaml index 1cb0167f2d91..1f4a348d9d1f 100644 --- a/chia/util/initial-config.yaml +++ b/chia/util/initial-config.yaml @@ -115,7 +115,7 @@ logging: &logging log_maxfilesrotation: 7 # Max files in rotation. Default value 7 if the key is not set log_syslog: False # If True, outputs to SysLog host and port specified log_syslog_host: "localhost" # Send logging messages to a remote or local Unix syslog - log_syslog_port: 514 # UDP port of the remote or local Unix syslog + log_syslog_port: 514 # UDP port of the remote or local Unix syslog harvester: # The harvester server (if run) will run on this port From b1e7d45e9b821b4d5fac47c2bbe80f8eb7256bd0 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Fri, 18 Jun 2021 14:22:27 +0200 Subject: [PATCH 08/11] factor out common test boilerplate from mempool tests (#6815) --- tests/core/full_node/test_mempool.py | 347 +++++++++------------------ 1 file changed, 119 insertions(+), 228 deletions(-) diff --git a/tests/core/full_node/test_mempool.py b/tests/core/full_node/test_mempool.py index 7cd5e553b3ef..d3cd57a717b7 100644 --- a/tests/core/full_node/test_mempool.py +++ b/tests/core/full_node/test_mempool.py @@ -1,7 +1,7 @@ import asyncio import logging -from typing import Dict, List, Optional, Tuple +from typing import Dict, List, Optional, Tuple, Callable import pytest @@ -329,6 +329,36 @@ class TestMempoolManager: status, err = await respond_transaction(full_node_1, tx1, peer) return blocks, spend_bundle1, peer, status, err + @pytest.mark.asyncio + async def condition_tester2(self, two_nodes, test_fun: Callable[[Coin, Coin], SpendBundle]): + reward_ph = WALLET_A.get_new_puzzlehash() + full_node_1, full_node_2, server_1, server_2 = two_nodes + blocks = await full_node_1.get_all_full_blocks() + start_height = blocks[-1].height if len(blocks) > 0 else -1 + blocks = bt.get_consecutive_blocks( + 3, + block_list_input=blocks, + guarantee_transaction_block=True, + farmer_reward_puzzle_hash=reward_ph, + pool_reward_puzzle_hash=reward_ph, + ) + peer = await connect_and_get_peer(server_1, server_2) + + for block in blocks: + await full_node_1.full_node.respond_block(full_node_protocol.RespondBlock(block)) + + await time_out_assert(60, node_height_at_least, True, full_node_1, start_height + 3) + + coin_1 = list(blocks[-2].get_included_reward_coins())[0] + coin_2 = list(blocks[-1].get_included_reward_coins())[0] + + bundle = test_fun(coin_1, coin_2) + + tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(bundle) + status, err = await respond_transaction(full_node_1, tx1, peer) + + return blocks, bundle, status, err + @pytest.mark.asyncio async def test_invalid_block_index(self, two_nodes): @@ -514,44 +544,20 @@ class TestMempoolManager: @pytest.mark.asyncio async def test_correct_coin_announcement_consumed(self, two_nodes): - reward_ph = WALLET_A.get_new_puzzlehash() + def test_fun(coin_1: Coin, coin_2: Coin) -> SpendBundle: + announce = Announcement(coin_2.name(), b"test") + cvp = ConditionWithArgs(ConditionOpcode.ASSERT_COIN_ANNOUNCEMENT, [announce.name()]) + dic = {cvp.opcode: [cvp]} + + cvp2 = ConditionWithArgs(ConditionOpcode.CREATE_COIN_ANNOUNCEMENT, [b"test"]) + dic2 = {cvp.opcode: [cvp2]} + spend_bundle1 = generate_test_spend_bundle(coin_1, dic) + spend_bundle2 = generate_test_spend_bundle(coin_2, dic2) + bundle = SpendBundle.aggregate([spend_bundle1, spend_bundle2]) + return bundle + full_node_1, full_node_2, server_1, server_2 = two_nodes - blocks = await full_node_1.get_all_full_blocks() - start_height = blocks[-1].height if len(blocks) > 0 else -1 - blocks = bt.get_consecutive_blocks( - 3, - block_list_input=blocks, - guarantee_transaction_block=True, - farmer_reward_puzzle_hash=reward_ph, - pool_reward_puzzle_hash=reward_ph, - ) - peer = await connect_and_get_peer(server_1, server_2) - - for block in blocks: - await full_node_1.full_node.respond_block(full_node_protocol.RespondBlock(block)) - - await time_out_assert(60, node_height_at_least, True, full_node_1, start_height + 3) - - coin_1 = list(blocks[-2].get_included_reward_coins())[0] - coin_2 = list(blocks[-1].get_included_reward_coins())[0] - - announce = Announcement(coin_2.name(), bytes("test", "utf-8")) - - cvp = ConditionWithArgs(ConditionOpcode.ASSERT_COIN_ANNOUNCEMENT, [announce.name()]) - - dic = {cvp.opcode: [cvp]} - - cvp2 = ConditionWithArgs(ConditionOpcode.CREATE_COIN_ANNOUNCEMENT, [bytes("test", "utf-8")]) - dic2 = {cvp.opcode: [cvp2]} - spend_bundle1 = generate_test_spend_bundle(coin_1, dic) - - spend_bundle2 = generate_test_spend_bundle(coin_2, dic2) - - bundle = SpendBundle.aggregate([spend_bundle1, spend_bundle2]) - - tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(bundle) - status, err = await respond_transaction(full_node_1, tx1, peer) - + blocks, bundle, status, err = await self.condition_tester2(two_nodes, test_fun) mempool_bundle = full_node_1.full_node.mempool_manager.get_spendbundle(bundle.name()) assert mempool_bundle is bundle @@ -560,43 +566,24 @@ class TestMempoolManager: @pytest.mark.asyncio async def test_coin_announcement_too_big(self, two_nodes): - reward_ph = WALLET_A.get_new_puzzlehash() full_node_1, full_node_2, server_1, server_2 = two_nodes - blocks = await full_node_1.get_all_full_blocks() - start_height = blocks[-1].height if len(blocks) > 0 else -1 - blocks = bt.get_consecutive_blocks( - 3, - block_list_input=blocks, - guarantee_transaction_block=True, - farmer_reward_puzzle_hash=reward_ph, - pool_reward_puzzle_hash=reward_ph, - ) - peer = await connect_and_get_peer(server_1, server_2) - for block in blocks: - await full_node_1.full_node.respond_block(full_node_protocol.RespondBlock(block)) + def test_fun(coin_1: Coin, coin_2: Coin): + announce = Announcement(coin_2.name(), bytes([1] * 10000)) - await time_out_assert(60, node_height_at_least, True, full_node_1, start_height + 3) + cvp = ConditionWithArgs(ConditionOpcode.ASSERT_COIN_ANNOUNCEMENT, [announce.name()]) - coin_1 = list(blocks[-2].get_included_reward_coins())[0] - coin_2 = list(blocks[-1].get_included_reward_coins())[0] + dic = {cvp.opcode: [cvp]} - announce = Announcement(coin_2.name(), bytes([1] * 10000)) + cvp2 = ConditionWithArgs(ConditionOpcode.CREATE_COIN_ANNOUNCEMENT, [b"test"]) + dic2 = {cvp.opcode: [cvp2]} + spend_bundle1 = generate_test_spend_bundle(coin_1, dic) - cvp = ConditionWithArgs(ConditionOpcode.ASSERT_COIN_ANNOUNCEMENT, [announce.name()]) + spend_bundle2 = generate_test_spend_bundle(coin_2, dic2) - dic = {cvp.opcode: [cvp]} + return SpendBundle.aggregate([spend_bundle1, spend_bundle2]) - cvp2 = ConditionWithArgs(ConditionOpcode.CREATE_COIN_ANNOUNCEMENT, [bytes("test", "utf-8")]) - dic2 = {cvp.opcode: [cvp2]} - spend_bundle1 = generate_test_spend_bundle(coin_1, dic) - - spend_bundle2 = generate_test_spend_bundle(coin_2, dic2) - - bundle = SpendBundle.aggregate([spend_bundle1, spend_bundle2]) - - tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(bundle) - status, err = await respond_transaction(full_node_1, tx1, peer) + blocks, bundle, status, err = await self.condition_tester2(two_nodes, test_fun) assert full_node_1.full_node.mempool_manager.get_spendbundle(bundle.name()) is None assert status == MempoolInclusionStatus.FAILED @@ -613,46 +600,27 @@ class TestMempoolManager: @pytest.mark.asyncio async def test_invalid_coin_announcement_rejected(self, two_nodes): - reward_ph = WALLET_A.get_new_puzzlehash() full_node_1, full_node_2, server_1, server_2 = two_nodes - blocks = await full_node_1.get_all_full_blocks() - start_height = blocks[-1].height if len(blocks) > 0 else -1 - blocks = bt.get_consecutive_blocks( - 3, - block_list_input=blocks, - guarantee_transaction_block=True, - farmer_reward_puzzle_hash=reward_ph, - pool_reward_puzzle_hash=reward_ph, - ) - peer = await connect_and_get_peer(server_1, server_2) - for block in blocks: - await full_node_1.full_node.respond_block(full_node_protocol.RespondBlock(block)) + def test_fun(coin_1: Coin, coin_2: Coin): + announce = Announcement(coin_2.name(), b"test") - await time_out_assert(60, node_height_at_least, True, full_node_1, start_height + 3) + cvp = ConditionWithArgs(ConditionOpcode.ASSERT_COIN_ANNOUNCEMENT, [announce.name()]) - coin_1 = list(blocks[-2].get_included_reward_coins())[0] - coin_2 = list(blocks[-1].get_included_reward_coins())[0] + dic = {cvp.opcode: [cvp]} + # Wrong message + cvp2 = ConditionWithArgs( + ConditionOpcode.CREATE_COIN_ANNOUNCEMENT, + [b"wrong test"], + ) + dic2 = {cvp.opcode: [cvp2]} + spend_bundle1 = generate_test_spend_bundle(coin_1, dic) - announce = Announcement(coin_2.name(), bytes("test", "utf-8")) + spend_bundle2 = generate_test_spend_bundle(coin_2, dic2) - cvp = ConditionWithArgs(ConditionOpcode.ASSERT_COIN_ANNOUNCEMENT, [announce.name()]) + return SpendBundle.aggregate([spend_bundle1, spend_bundle2]) - dic = {cvp.opcode: [cvp]} - # Wrong message - cvp2 = ConditionWithArgs( - ConditionOpcode.CREATE_COIN_ANNOUNCEMENT, - [bytes("wrong test", "utf-8")], - ) - dic2 = {cvp.opcode: [cvp2]} - spend_bundle1 = generate_test_spend_bundle(coin_1, dic) - - spend_bundle2 = generate_test_spend_bundle(coin_2, dic2) - - bundle = SpendBundle.aggregate([spend_bundle1, spend_bundle2]) - - tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(spend_bundle1) - status, err = await respond_transaction(full_node_1, tx1, peer) + blocks, bundle, status, err = await self.condition_tester2(two_nodes, test_fun) mempool_bundle = full_node_1.full_node.mempool_manager.get_spendbundle(bundle.name()) @@ -662,48 +630,28 @@ class TestMempoolManager: @pytest.mark.asyncio async def test_invalid_coin_announcement_rejected_two(self, two_nodes): - reward_ph = WALLET_A.get_new_puzzlehash() full_node_1, full_node_2, server_1, server_2 = two_nodes - blocks = await full_node_1.get_all_full_blocks() - start_height = blocks[-1].height if len(blocks) > 0 else -1 - blocks = bt.get_consecutive_blocks( - 3, - block_list_input=blocks, - guarantee_transaction_block=True, - farmer_reward_puzzle_hash=reward_ph, - pool_reward_puzzle_hash=reward_ph, - ) - peer = await connect_and_get_peer(server_1, server_2) - for block in blocks: - await full_node_1.full_node.respond_block(full_node_protocol.RespondBlock(block)) + def test_fun(coin_1: Coin, coin_2: Coin): + announce = Announcement(coin_1.name(), b"test") - await time_out_assert(60, node_height_at_least, True, full_node_1, start_height + 3) + cvp = ConditionWithArgs(ConditionOpcode.ASSERT_COIN_ANNOUNCEMENT, [announce.name()]) - coin_1 = list(blocks[-2].get_included_reward_coins())[0] - coin_2 = list(blocks[-1].get_included_reward_coins())[0] + dic = {cvp.opcode: [cvp]} - announce = Announcement(coin_1.name(), bytes("test", "utf-8")) + cvp2 = ConditionWithArgs( + ConditionOpcode.CREATE_COIN_ANNOUNCEMENT, + [b"test"], + ) + dic2 = {cvp.opcode: [cvp2]} + spend_bundle1 = generate_test_spend_bundle(coin_1, dic) - cvp = ConditionWithArgs(ConditionOpcode.ASSERT_COIN_ANNOUNCEMENT, [announce.name()]) + # coin 2 is making the announcement, right message wrong coin + spend_bundle2 = generate_test_spend_bundle(coin_2, dic2) - dic = {cvp.opcode: [cvp]} - - cvp2 = ConditionWithArgs( - ConditionOpcode.CREATE_COIN_ANNOUNCEMENT, - [bytes("test", "utf-8")], - ) - dic2 = {cvp.opcode: [cvp2]} - spend_bundle1 = generate_test_spend_bundle(coin_1, dic) - - # coin 2 is making the announcement, right message wrong coin - spend_bundle2 = generate_test_spend_bundle(coin_2, dic2) - - bundle = SpendBundle.aggregate([spend_bundle1, spend_bundle2]) - - tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(spend_bundle1) - status, err = await respond_transaction(full_node_1, tx1, peer) + return SpendBundle.aggregate([spend_bundle1, spend_bundle2]) + blocks, bundle, status, err = await self.condition_tester2(two_nodes, test_fun) mempool_bundle = full_node_1.full_node.mempool_manager.get_spendbundle(bundle.name()) assert mempool_bundle is None @@ -712,43 +660,24 @@ class TestMempoolManager: @pytest.mark.asyncio async def test_correct_puzzle_announcement(self, two_nodes): - reward_ph = WALLET_A.get_new_puzzlehash() full_node_1, full_node_2, server_1, server_2 = two_nodes - blocks = await full_node_1.get_all_full_blocks() - start_height = blocks[-1].height if len(blocks) > 0 else -1 - blocks = bt.get_consecutive_blocks( - 3, - block_list_input=blocks, - guarantee_transaction_block=True, - farmer_reward_puzzle_hash=reward_ph, - pool_reward_puzzle_hash=reward_ph, - ) - peer = await connect_and_get_peer(server_1, server_2) - for block in blocks: - await full_node_1.full_node.respond_block(full_node_protocol.RespondBlock(block)) + def test_fun(coin_1: Coin, coin_2: Coin): + announce = Announcement(coin_2.puzzle_hash, bytes(0x80)) - await time_out_assert(60, node_height_at_least, True, full_node_1, start_height + 3) + cvp = ConditionWithArgs(ConditionOpcode.ASSERT_PUZZLE_ANNOUNCEMENT, [announce.name()]) - coin_1 = list(blocks[-2].get_included_reward_coins())[0] - coin_2 = list(blocks[-1].get_included_reward_coins())[0] + dic = {cvp.opcode: [cvp]} - announce = Announcement(coin_2.puzzle_hash, bytes(0x80)) + cvp2 = ConditionWithArgs(ConditionOpcode.CREATE_PUZZLE_ANNOUNCEMENT, [bytes(0x80)]) + dic2 = {cvp.opcode: [cvp2]} + spend_bundle1 = generate_test_spend_bundle(coin_1, dic) - cvp = ConditionWithArgs(ConditionOpcode.ASSERT_PUZZLE_ANNOUNCEMENT, [announce.name()]) + spend_bundle2 = generate_test_spend_bundle(coin_2, dic2) - dic = {cvp.opcode: [cvp]} + return SpendBundle.aggregate([spend_bundle1, spend_bundle2]) - cvp2 = ConditionWithArgs(ConditionOpcode.CREATE_PUZZLE_ANNOUNCEMENT, [bytes(0x80)]) - dic2 = {cvp.opcode: [cvp2]} - spend_bundle1 = generate_test_spend_bundle(coin_1, dic) - - spend_bundle2 = generate_test_spend_bundle(coin_2, dic2) - - bundle = SpendBundle.aggregate([spend_bundle1, spend_bundle2]) - - tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(bundle) - status, err = await respond_transaction(full_node_1, tx1, peer) + blocks, bundle, status, err = await self.condition_tester2(two_nodes, test_fun) mempool_bundle = full_node_1.full_node.mempool_manager.get_spendbundle(bundle.name()) @@ -758,46 +687,27 @@ class TestMempoolManager: @pytest.mark.asyncio async def test_invalid_puzzle_announcement_rejected(self, two_nodes): - reward_ph = WALLET_A.get_new_puzzlehash() full_node_1, full_node_2, server_1, server_2 = two_nodes - blocks = await full_node_1.get_all_full_blocks() - start_height = blocks[-1].height if len(blocks) > 0 else -1 - blocks = bt.get_consecutive_blocks( - 3, - block_list_input=blocks, - guarantee_transaction_block=True, - farmer_reward_puzzle_hash=reward_ph, - pool_reward_puzzle_hash=reward_ph, - ) - peer = await connect_and_get_peer(server_1, server_2) - for block in blocks: - await full_node_1.full_node.respond_block(full_node_protocol.RespondBlock(block)) + def test_fun(coin_1: Coin, coin_2: Coin): + announce = Announcement(coin_2.puzzle_hash, bytes("test", "utf-8")) - await time_out_assert(60, node_height_at_least, True, full_node_1, start_height + 3) + cvp = ConditionWithArgs(ConditionOpcode.ASSERT_PUZZLE_ANNOUNCEMENT, [announce.name()]) - coin_1 = list(blocks[-2].get_included_reward_coins())[0] - coin_2 = list(blocks[-1].get_included_reward_coins())[0] + dic = {cvp.opcode: [cvp]} - announce = Announcement(coin_2.puzzle_hash, bytes("test", "utf-8")) + cvp2 = ConditionWithArgs( + ConditionOpcode.CREATE_PUZZLE_ANNOUNCEMENT, + [b"wrong test"], + ) + dic2 = {cvp.opcode: [cvp2]} + spend_bundle1 = generate_test_spend_bundle(coin_1, dic) - cvp = ConditionWithArgs(ConditionOpcode.ASSERT_PUZZLE_ANNOUNCEMENT, [announce.name()]) + spend_bundle2 = generate_test_spend_bundle(coin_2, dic2) - dic = {cvp.opcode: [cvp]} + return SpendBundle.aggregate([spend_bundle1, spend_bundle2]) - cvp2 = ConditionWithArgs( - ConditionOpcode.CREATE_PUZZLE_ANNOUNCEMENT, - [bytes("wrong test", "utf-8")], - ) - dic2 = {cvp.opcode: [cvp2]} - spend_bundle1 = generate_test_spend_bundle(coin_1, dic) - - spend_bundle2 = generate_test_spend_bundle(coin_2, dic2) - - bundle = SpendBundle.aggregate([spend_bundle1, spend_bundle2]) - - tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(spend_bundle1) - status, err = await respond_transaction(full_node_1, tx1, peer) + blocks, bundle, status, err = await self.condition_tester2(two_nodes, test_fun) mempool_bundle = full_node_1.full_node.mempool_manager.get_spendbundle(bundle.name()) @@ -807,46 +717,27 @@ class TestMempoolManager: @pytest.mark.asyncio async def test_invalid_puzzle_announcement_rejected_two(self, two_nodes): - reward_ph = WALLET_A.get_new_puzzlehash() full_node_1, full_node_2, server_1, server_2 = two_nodes - blocks = await full_node_1.get_all_full_blocks() - start_height = blocks[-1].height if len(blocks) > 0 else -1 - blocks = bt.get_consecutive_blocks( - 3, - block_list_input=blocks, - guarantee_transaction_block=True, - farmer_reward_puzzle_hash=reward_ph, - pool_reward_puzzle_hash=reward_ph, - ) - peer = await connect_and_get_peer(server_1, server_2) - for block in blocks: - await full_node_1.full_node.respond_block(full_node_protocol.RespondBlock(block)) + def test_fun(coin_1: Coin, coin_2: Coin): + announce = Announcement(coin_2.puzzle_hash, b"test") - await time_out_assert(60, node_height_at_least, True, full_node_1, start_height + 3) + cvp = ConditionWithArgs(ConditionOpcode.ASSERT_PUZZLE_ANNOUNCEMENT, [announce.name()]) - coin_1 = list(blocks[-2].get_included_reward_coins())[0] - coin_2 = list(blocks[-1].get_included_reward_coins())[0] + dic = {cvp.opcode: [cvp]} + # Wrong type of Create_announcement + cvp2 = ConditionWithArgs( + ConditionOpcode.CREATE_COIN_ANNOUNCEMENT, + [b"test"], + ) + dic2 = {cvp.opcode: [cvp2]} + spend_bundle1 = generate_test_spend_bundle(coin_1, dic) - announce = Announcement(coin_2.puzzle_hash, bytes("test", "utf-8")) + spend_bundle2 = generate_test_spend_bundle(coin_2, dic2) - cvp = ConditionWithArgs(ConditionOpcode.ASSERT_PUZZLE_ANNOUNCEMENT, [announce.name()]) + return SpendBundle.aggregate([spend_bundle1, spend_bundle2]) - dic = {cvp.opcode: [cvp]} - # Wrong type of Create_announcement - cvp2 = ConditionWithArgs( - ConditionOpcode.CREATE_COIN_ANNOUNCEMENT, - [bytes("test", "utf-8")], - ) - dic2 = {cvp.opcode: [cvp2]} - spend_bundle1 = generate_test_spend_bundle(coin_1, dic) - - spend_bundle2 = generate_test_spend_bundle(coin_2, dic2) - - bundle = SpendBundle.aggregate([spend_bundle1, spend_bundle2]) - - tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(spend_bundle1) - status, err = await respond_transaction(full_node_1, tx1, peer) + blocks, bundle, status, err = await self.condition_tester2(two_nodes, test_fun) mempool_bundle = full_node_1.full_node.mempool_manager.get_spendbundle(bundle.name()) From dfc79fa5001975b17c5d3ac3a274fb4993aa6755 Mon Sep 17 00:00:00 2001 From: Maran Date: Fri, 18 Jun 2021 14:23:52 +0200 Subject: [PATCH 09/11] Adds Farmer and Pool public keys to API. Required for Chia-Network/chia-blockchain-gui#286 (#6694) Co-authored-by: Animazing --- chia/rpc/wallet_rpc_api.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/chia/rpc/wallet_rpc_api.py b/chia/rpc/wallet_rpc_api.py index cb201c4f7e7d..39f8c8f336ec 100644 --- a/chia/rpc/wallet_rpc_api.py +++ b/chia/rpc/wallet_rpc_api.py @@ -22,6 +22,7 @@ from chia.util.path import path_from_root from chia.util.ws_message import WsRpcMessage, create_payload_dict from chia.wallet.cc_wallet.cc_wallet import CCWallet from chia.wallet.rl_wallet.rl_wallet import RLWallet +from chia.wallet.derive_keys import master_sk_to_farmer_sk, master_sk_to_pool_sk from chia.wallet.did_wallet.did_wallet import DIDWallet from chia.wallet.trade_record import TradeRecord from chia.wallet.transaction_record import TransactionRecord @@ -202,6 +203,8 @@ class WalletRpcApi: "fingerprint": fingerprint, "sk": bytes(sk).hex(), "pk": bytes(sk.get_g1()).hex(), + "farmer_pk": bytes(master_sk_to_farmer_sk(sk).get_g1()).hex(), + "pool_pk": bytes(master_sk_to_pool_sk(sk).get_g1()).hex(), "seed": s, }, } From d2d869066fa53b3e96155d68ff774a6dcf95f2e5 Mon Sep 17 00:00:00 2001 From: arvidn Date: Sat, 19 Jun 2021 10:07:58 +0200 Subject: [PATCH 10/11] fix typo in build-linux-installer.yml and build-linux-arm64-installer.yml --- .github/workflows/build-linux-arm64-installer.yml | 2 +- .github/workflows/build-linux-installer.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-linux-arm64-installer.yml b/.github/workflows/build-linux-arm64-installer.yml index 8c13069c89cc..13aaf69fa586 100644 --- a/.github/workflows/build-linux-arm64-installer.yml +++ b/.github/workflows/build-linux-arm64-installer.yml @@ -52,7 +52,7 @@ jobs: if [ -n "$SECRET" ]; then HAS_SECRET='true' ; fi echo ::set-output name=HAS_SECRET::${HAS_SECRET} env: - SECRET: "${{ secrets.test_pypi_password }" + SECRET: "${{ secrets.test_pypi_password }}" - name: Build ARM64 Installer run: | diff --git a/.github/workflows/build-linux-installer.yml b/.github/workflows/build-linux-installer.yml index 35b641e855a1..263863efab00 100644 --- a/.github/workflows/build-linux-installer.yml +++ b/.github/workflows/build-linux-installer.yml @@ -86,7 +86,7 @@ jobs: if [ -n "$SECRET" ]; then HAS_SECRET='true' ; fi echo ::set-output name=HAS_SECRET::${HAS_SECRET} env: - SECRET: "${{ secrets.test_pypi_password }" + SECRET: "${{ secrets.test_pypi_password }}" - name: Run install script env: From c300533c0e54b103d713d362e478806d948b8024 Mon Sep 17 00:00:00 2001 From: nirajpathak13 <72772761+nirajpathak13@users.noreply.github.com> Date: Mon, 21 Jun 2021 19:42:46 -0400 Subject: [PATCH 11/11] generate and upload torrent files (#6810) Generate and Upload torrent files for chia installers. Files are located here: https://s3.console.aws.amazon.com/s3/buckets/download-chia-net?region=us-west-2&prefix=torrents/&showversions=false --- .../workflows/build-linux-arm64-installer.yml | 14 +++++++++++++- .github/workflows/build-linux-installer.yml | 19 +++++++++++++++++++ .github/workflows/build-macos-installer.yml | 11 +++++++++++ .github/workflows/build-windows-installer.yml | 12 ++++++++++++ azure-pipelines.yml | 10 +++++++++- 5 files changed, 64 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-linux-arm64-installer.yml b/.github/workflows/build-linux-arm64-installer.yml index 13aaf69fa586..29cc8872211b 100644 --- a/.github/workflows/build-linux-arm64-installer.yml +++ b/.github/workflows/build-linux-arm64-installer.yml @@ -118,13 +118,25 @@ jobs: sha256sum ${{ github.workspace }}/build_scripts/final_installer/chia-blockchain_${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}_arm64.deb > ${{ github.workspace }}/build_scripts/final_installer/chia-blockchain_${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}_arm64.deb.sha256 ls ${{ github.workspace }}/build_scripts/final_installer/ + - name: Install py3createtorrent + if: startsWith(github.ref, 'refs/tags/') + run: | + pip3 install py3createtorrent + + - name: Create torrent + if: startsWith(github.ref, 'refs/tags/') + run: | + py3createtorrent -f -t udp://tracker.opentrackr.org:1337/announce ${{ github.workspace }}/build_scripts/final_installer/chia-blockchain_${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}_arm64.deb -o ${{ github.workspace }}/build_scripts/final_installer/chia-blockchain_${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}_arm64.deb.torrent --webseed https://download-chia-net.s3.us-west-2.amazonaws.com/install/chia-blockchain_${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}_arm64.deb + ls ${{ github.workspace }}/build_scripts/final_installer/ + - name: Upload Release Files if: steps.check_secrets.outputs.HAS_SECRET && startsWith(github.ref, 'refs/tags/') run: | ls ${{ github.workspace }}/build_scripts/final_installer/ aws s3 cp ${{ github.workspace }}/build_scripts/final_installer/*.deb s3://download-chia-net/install/ aws s3 cp ${{ github.workspace }}/build_scripts/final_installer/*.sha256 s3://download-chia-net/install/ + aws s3 cp ${{ github.workspace }}/build_scripts/final_installer/chia-blockchain_${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}_arm64.deb.torrent s3://download-chia-net/torrents/ - name: Clean up on self hosted runner run: | - sudo rm -rf build_scrpits/final_installer + sudo rm -rf build_scripts/final_installer \ No newline at end of file diff --git a/.github/workflows/build-linux-installer.yml b/.github/workflows/build-linux-installer.yml index 263863efab00..c22116559f97 100644 --- a/.github/workflows/build-linux-installer.yml +++ b/.github/workflows/build-linux-installer.yml @@ -144,10 +144,29 @@ jobs: sha256sum ${{ github.workspace }}/build_scripts/final_installer/chia-blockchain_${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}_amd64.deb > ${{ github.workspace }}/build_scripts/final_installer/chia-blockchain_${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}_amd64.deb.sha256 ls ${{ github.workspace }}/build_scripts/final_installer/ + - name: Install py3createtorrent + if: startsWith(github.ref, 'refs/tags/') + run: | + pip3 install py3createtorrent + + - name: Create .rpm torrent + if: startsWith(github.ref, 'refs/tags/') + run: | + py3createtorrent -f -t udp://tracker.opentrackr.org:1337/announce ${{ github.workspace }}/build_scripts/final_installer/chia-blockchain-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}-1.x86_64.rpm -o ${{ github.workspace }}/build_scripts/final_installer/chia-blockchain-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}-1.x86_64.rpm.torrent --webseed https://download-chia-net.s3.us-west-2.amazonaws.com/install/chia-blockchain-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}-1.x86_64.rpm + ls + + - name: Create .deb torrent + if: startsWith(github.ref, 'refs/tags/') + run: | + py3createtorrent -f -t udp://tracker.opentrackr.org:1337/announce ${{ github.workspace }}/build_scripts/final_installer/chia-blockchain_${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}_amd64.deb -o ${{ github.workspace }}/build_scripts/final_installer/chia-blockchain_${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}_amd64.deb.torrent --webseed https://download-chia-net.s3.us-west-2.amazonaws.com/install/chia-blockchain_${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}_amd64.deb + ls + - name: Upload Release Files if: steps.check_secrets.outputs.HAS_SECRET && startsWith(github.ref, 'refs/tags/') run: | aws s3 cp ${{ github.workspace }}/build_scripts/final_installer/chia-blockchain_${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}_amd64.deb s3://download-chia-net/install/ aws s3 cp ${{ github.workspace }}/build_scripts/final_installer/chia-blockchain_${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}_amd64.deb.sha256 s3://download-chia-net/install/ + aws s3 cp ${{ github.workspace }}/build_scripts/final_installer/chia-blockchain_${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}_amd64.deb.torrent s3://download-chia-net/torrents/ aws s3 cp ${{ github.workspace }}/build_scripts/final_installer/chia-blockchain-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}-1.x86_64.rpm s3://download-chia-net/install/ aws s3 cp ${{ github.workspace }}/build_scripts/final_installer/chia-blockchain-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}-1.x86_64.rpm.sha256 s3://download-chia-net/install/ + aws s3 cp ${{ github.workspace }}/build_scripts/final_installer/chia-blockchain-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}-1.x86_64.rpm.torrent s3://download-chia-net/torrents/ diff --git a/.github/workflows/build-macos-installer.yml b/.github/workflows/build-macos-installer.yml index 751ccc7902d2..6f0ad748da58 100644 --- a/.github/workflows/build-macos-installer.yml +++ b/.github/workflows/build-macos-installer.yml @@ -146,9 +146,20 @@ jobs: run: | aws s3 cp ${{ github.workspace }}/build_scripts/final_installer/Chia-Catalina-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}.dmg s3://download-chia-net/builds/ + - name: Install py3createtorrent + if: startsWith(github.ref, 'refs/tags/') + run: | + pip3 install py3createtorrent + + - name: Create torrent + if: startsWith(github.ref, 'refs/tags/') + run: | + py3createtorrent -t torrent.chia.net ${{ github.workspace }}/build_scripts/final_installer/Chia-Catalina-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}.dmg ${{ github.workspace }}/build_scripts/final_installer/Chia-Catalina-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}.dmg.torrent + #Temporarily disable release uploads # - name: Upload Release Files # if: startsWith(github.ref, 'refs/tags/') # run: | # aws s3 cp ${{ github.workspace }}/build_scripts/final_installer/Chia-Catalina-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}.dmg s3://download-chia-net/install/ # aws s3 cp ${{ github.workspace }}/build_scripts/final_installer/Chia-Catalina-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}.dmg.sha256 s3://download-chia-net/install/ +# aws s3 cp ${{ github.workspace }}/build_scripts/final_installer/Chia-Catalina-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}.dmg.torrent s3://download-chia-net/install/ \ No newline at end of file diff --git a/.github/workflows/build-windows-installer.yml b/.github/workflows/build-windows-installer.yml index 90561c4892e2..631929f84044 100644 --- a/.github/workflows/build-windows-installer.yml +++ b/.github/workflows/build-windows-installer.yml @@ -141,6 +141,17 @@ jobs: certutil.exe -hashfile ${{ github.workspace }}\chia-blockchain-gui\release-builds\windows-installer\ChiaSetup-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}.exe SHA256 > ${{ github.workspace }}\chia-blockchain-gui\release-builds\windows-installer\ChiaSetup-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}.exe.checksum ls ${{ github.workspace }}\chia-blockchain-gui\release-builds\windows-installer\ + - name: Install py3createtorrent + if: startsWith(github.ref, 'refs/tags/') + run: | + pip3 install py3createtorrent + + - name: Create torrent + if: startsWith(github.ref, 'refs/tags/') + run: | + py3createtorrent -f -t udp://tracker.opentrackr.org:1337/announce ${{ github.workspace }}\chia-blockchain-gui\release-builds\windows-installer\ChiaSetup-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}.exe -o ${{ github.workspace }}\chia-blockchain-gui\release-builds\windows-installer\ChiaSetup-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}.exe.torrent --webseed https://download-chia-net.s3.us-west-2.amazonaws.com/install/ChiaSetup-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}.exe + ls + - name: Upload Release Files if: steps.check_secrets.outputs.HAS_SECRET && startsWith(github.ref, 'refs/tags/') env: @@ -149,3 +160,4 @@ jobs: run: | aws s3 cp ${{ github.workspace }}\chia-blockchain-gui\release-builds\windows-installer\ChiaSetup-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}.exe s3://download-chia-net/install/ aws s3 cp ${{ github.workspace }}\chia-blockchain-gui\release-builds\windows-installer\ChiaSetup-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}.exe.checksum s3://download-chia-net/install/ + aws s3 cp ${{ github.workspace }}\chia-blockchain-gui\release-builds\windows-installer\ChiaSetup-${{ steps.version_number.outputs.CHIA_INSTALLER_VERSION }}.exe.torrent s3://download-chia-net/torrents/ diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 3f9d46d78785..eeaf7248668b 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -111,11 +111,19 @@ steps: aws s3 cp $(System.DefaultWorkingDirectory)/build_scripts/final_installer/*.dmg s3://download-chia-net/builds/ displayName: "Upload to S3" + - bash: | + pip3 install py3createtorrent + py3createtorrent -f -t udp://tracker.opentrackr.org:1337/announce $(System.DefaultWorkingDirectory)/build_scripts/final_installer/$CHIA_VERSION.dmg -o $(System.DefaultWorkingDirectory)/build_scripts/final_installer/$CHIA_VERSION.dmg.torrent --webseed https://download-chia-net.s3.us-west-2.amazonaws.com/install/$CHIA_VERSION.dmg + ls + displayName: "Create torrent file" + condition: contains(variables['build.sourceBranch'], 'refs/tags/') + - bash: | export AWS_ACCESS_KEY_ID=$(AccessKey) export AWS_SECRET_ACCESS_KEY=$(SecretKey) export AWS_DEFAULT_REGION=us-west-2 aws s3 cp $(System.DefaultWorkingDirectory)/build_scripts/final_installer/$CHIA_VERSION.dmg s3://download-chia-net/install/ aws s3 cp $(System.DefaultWorkingDirectory)/build_scripts/final_installer/$CHIA_VERSION.dmg.sha256 s3://download-chia-net/install/ + aws s3 cp $(System.DefaultWorkingDirectory)/build_scripts/final_installer/$CHIA_VERSION.dmg.torrent s3://download-chia-net/torrents/ displayName: "Upload Release Files" - condition: contains(variables['build.sourceBranch'], 'refs/tags/') + condition: contains(variables['build.sourceBranch'], 'refs/tags/') \ No newline at end of file