Reentrancy vulnerability commonly exists in smart contract, which results in serious economic losses. Existing symbolic execution-based static analyzing tools detect reentrancy vulnerability by evaluating default rules. However, the incompleteness of the default rules can lead to false positive judgments. Therefore, we attempt to solve this problem from the perspective of test case generation based on dynamic execution. In this paper, the application scenario is abstracted as a mathematical model of automated test case generation for path coverage (ATCG-PC) with reentrancy loop paths. Reentrancy vulnerability can be detected by executing the test cases of reentrancy loop paths. The swarm intelligence algorithm represented by the pigeon optimization algorithm is a common method for solving the black-box optimization problem. Pigeon-inspired optimization algorithm searches in the neighbor of the population optimal solution. However, the optimal solution of the large-scale black-box optimization problem may not be in this neighbor. To improve the path coverage rate of the pigeon-inspired optimization algorithm for ATCG-PC, an improved pigeoninspired optimization algorithm is proposed. The proposed algorithm allocates more computational resources to the subspace related to the target path, thereby improving the effectiveness of the pigeon-inspired optimization algorithm. It helps pigeon-inspired optimization algorithm to cover the reetrancy loop path. The experimental results show that the improved pigeon-inspired optimization algorithm can effectively generate path coverage test cases in different smart contracts. The proposed method can also find all possible paths and detect reentrancy vulnerabilities accurately when other tools (i.e., Oyente, Securify, and Smartcheck) make false positive judgments in the selected eight benchmarks. The recognition accuracy of reentrancy vulnerabilities is improved by 12.5%, 12.5%, and 25%, respectively.