async def test_transaction_freeze(self, wallet_node_30_freeze): num_blocks = 5 full_nodes, wallets = wallet_node_30_freeze full_node_api: FullNodeSimulator = full_nodes[0] full_node_server = full_node_api.server wallet_node, server_2 = wallets[0] wallet = wallet_node.wallet_state_manager.main_wallet ph = await wallet.get_new_puzzlehash() incoming_queue, node_id = await add_dummy_connection(full_node_server, 12312) await server_2.start_client(PeerInfo(self_hostname, uint16(full_node_server._port)), None) for i in range(num_blocks): await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph)) funds = sum( [calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i)) for i in range(1, num_blocks)] ) # funds += calculate_base_farmer_reward(0) await asyncio.sleep(2) print(await wallet.get_confirmed_balance(), funds) await time_out_assert(10, wallet.get_confirmed_balance, funds) tx: TransactionRecord = await wallet.generate_signed_transaction(100, ph, 0) spend = wallet_protocol.SendTransaction(tx.spend_bundle) response = await full_node_api.send_transaction(spend) assert wallet_protocol.TransactionAck.from_bytes(response.data).status == MempoolInclusionStatus.FAILED new_spend = full_node_protocol.NewTransaction(tx.spend_bundle.name(), 1, 0) response = await full_node_api.new_transaction(new_spend) assert response is None peer = full_node_server.all_connections[node_id] new_spend = full_node_protocol.RespondTransaction(tx.spend_bundle) response = await full_node_api.respond_transaction(new_spend, peer=peer) assert response is None for i in range(26): await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph)) new_spend = full_node_protocol.NewTransaction(tx.spend_bundle.name(), 1, 0) response = await full_node_api.new_transaction(new_spend) assert response is not None assert ProtocolMessageTypes(response.type) == ProtocolMessageTypes.request_transaction tx: TransactionRecord = await wallet.generate_signed_transaction(100, ph, 0) spend = wallet_protocol.SendTransaction(tx.spend_bundle) response = await full_node_api.send_transaction(spend) assert response is not None assert wallet_protocol.TransactionAck.from_bytes(response.data).status == MempoolInclusionStatus.SUCCESS assert ProtocolMessageTypes(response.type) == ProtocolMessageTypes.transaction_ack
async def _messages_to_resend(self) -> List[Message]: if self.wallet_state_manager is None or self.backup_initialized is False or self._shut_down: return [] messages: List[Message] = [] records: List[TransactionRecord] = await self.wallet_state_manager.tx_store.get_not_sent() for record in records: if record.spend_bundle is None: continue msg = Message( "send_transaction", wallet_protocol.SendTransaction(record.spend_bundle), ) messages.append(msg) return messages
async def _messages_to_resend(self) -> List[Tuple[Message, Set[bytes32]]]: if self.wallet_state_manager is None or self.backup_initialized is False or self._shut_down: return [] messages: List[Tuple[Message, Set[bytes32]]] = [] records: List[TransactionRecord] = await self.wallet_state_manager.tx_store.get_not_sent() for record in records: if record.spend_bundle is None: continue msg = make_msg( ProtocolMessageTypes.send_transaction, wallet_protocol.SendTransaction(record.spend_bundle), ) already_sent = set() for peer, status, _ in record.sent_to: already_sent.add(hexstr_to_bytes(peer)) messages.append((msg, already_sent)) return messages
async def _messages_to_resend(self) -> List[OutboundMessage]: messages: List[OutboundMessage] = [] records: List[ TransactionRecord] = await self.wallet_state_manager.tx_store.get_not_sent( ) for record in records: if record.spend_bundle is None: continue msg = OutboundMessage( NodeType.FULL_NODE, Message( "send_transaction", wallet_protocol.SendTransaction(record.spend_bundle), ), Delivery.BROADCAST, ) messages.append(msg) return messages
async def test_send_transaction(self, two_nodes, wallet_blocks): full_node_1, full_node_2, server_1, server_2 = two_nodes wallet_a, wallet_receiver, blocks = wallet_blocks await server_2.start_client(PeerInfo("localhost", uint16(server_1._port)), None) blocks_list = await get_block_path(full_node_1) blocks_new = bt.get_consecutive_blocks( test_constants, 1, block_list=blocks_list, seed=b"test_request_additions", ) async for _ in full_node_1.respond_block(fnp.RespondBlock(blocks_new[-1])): pass spend_bundle = wallet_a.generate_signed_transaction( 100, wallet_a.get_new_puzzlehash(), blocks_new[-1].get_coinbase(), ) spend_bundle_bad = wallet_a.generate_signed_transaction( constants.MAX_COIN_AMOUNT, wallet_a.get_new_puzzlehash(), blocks_new[-1].get_coinbase(), ) msgs = [ _ async for _ in full_node_1.send_transaction( wallet_protocol.SendTransaction(spend_bundle) ) ] assert len(msgs) == 2 wallet_message = None for msg in msgs: if msg.peer_type == NodeType.WALLET: wallet_message = msg assert wallet_message is not None assert wallet_message.message.data == wallet_protocol.TransactionAck( spend_bundle.name(), MempoolInclusionStatus.SUCCESS, None ) msgs = [ _ async for _ in full_node_1.send_transaction( wallet_protocol.SendTransaction(spend_bundle) ) ] assert len(msgs) == 2 ack_msg = None for msg in msgs: if msg.message.function == "transaction_ack": ack_msg = msg assert ack_msg is not None assert ack_msg.message.data == wallet_protocol.TransactionAck( spend_bundle.name(), MempoolInclusionStatus.SUCCESS, None ) msgs = [ _ async for _ in full_node_1.send_transaction( wallet_protocol.SendTransaction(spend_bundle_bad) ) ] assert len(msgs) == 1 assert msgs[0].message.data == wallet_protocol.TransactionAck( spend_bundle_bad.name(), MempoolInclusionStatus.FAILED, Err.COIN_AMOUNT_EXCEEDS_MAXIMUM.name, )