一句话:提出 Solmigrator,首次基于迁移的智能合约测试生成,从链上真实使用提取并迁移测试用例到新合约。
智能合约部署前测试对功能正确性至关重要,但合约有状态且功能繁多,人工编写覆盖各种用法的测试用例成本高;现有方法多检测重入等底层漏洞,而非生成与功能相关且有表现力的测试。本文提出 Solmigrator,一种基于迁移的自动测试生成技术:给定待测目标合约和功能相似的链上源合约,先利用链上交易回放与依赖分析,将源合约的真实链上使用转为链下可执行测试用例,再通过细粒度静态分析把增强后的测试用例迁移到目标合约。作者实现原型并在 ERC20 与 ERC721 真实合约上评估,平均精确率 96.3%、准确率 93.6%,迁移用例能有效覆盖目标合约的常见关键功能。
Pre-deployment testing has become essential to ensure the functional correctness of smart contracts. However, since smart contracts are stateful programs integrating many different functionalities, manually writing test cases to cover all potential usages requires significant effort from developers, leading to insufficient testing and increasing risks in practice. Although several testing techniques for smart contracts have been proposed, they primarily focus on detecting common low-level vulnerabilities such as re-entrancy, rather than generating expressive and function-relevant test cases that can reduce manual testing efforts. To bridge the gap, we propose Solmigrator, an automated technique designed to generate expressive and representative test cases for smart contracts. To our knowledge, Solmigrator is the first migration-based test generation technique for smart contracts, which extracts test cases from real-world usages of on-chain contracts and migrates them to test newly developed smart contracts with similar functionalities. Given a target smart contract to be tested and an on-chain similar source smart contract, Solmigrator first transforms the on-chain usage of the source contract into off-chain executable test cases based on on-chain transaction replay and dependency analysis. It then employs fine-grained static analysis to migrate the augmented test cases from the source to the target smart contract. We built a prototype of Solmigrator and have evaluated it on real-world smart contracts within the two most popular categories, ERC20 and ERC721. Our evaluation results demonstrate that Solmigrator effectively extracts test cases from existing on-chain smart contracts and accurately migrates them across different smart contracts, achieving an average precision of 96.3% and accuracy of 93.6%. Furthermore, the results indicate that these migrated test cases effectively cover common key functionalities of the target smart contracts. This provides promising evidence that real-world usages of existing smart contracts can be transformed into effective test cases for other newly developed smart contracts.
DOI 原文 ·
@inproceedings{paperbot8696,
title = {Automated Test Generation For Smart Contracts via On-Chain Test Case Augmentation and Migration},
author = {Jiashuo Zhang and Jiachi Chen and John Grundy and Jianbo Gao and Yanlin Wang and Ting Chen and Zhi Guan and Zhong Chen},
booktitle = {ICSE},
year = {2025},
doi = {10.1109/icse55347.2025.00096}
}