Smart Contract Test Case Generation via Structured Parameter Mutation

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Generating test cases for smart contracts in blockchain systems is inefficient due to the difficulty in parsing data through interfaces, leading to incomplete coverage of program paths and reduced testing effectiveness.

Innovation Solution

A method and apparatus for generating smart contract test cases by selecting and mutating structured parameters based on their parameter structures, ensuring the mutated parameters can be identified and executed by the smart contract, thereby covering deeper program paths.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Productivity

If traditional test case generation methods are used, then test cases can be generated, but the test cases cannot be parsed through smart contract interfaces due to format requirements, leading to inefficient testing

Engineering Contradiction:
Improvetest case generation efficiencyVSAvoidtest case parsing success rate
Core Design Contradiction:
ProductivityVSReliability

Solution Approach 1:

The patent applies parameter changes by mutating structured parameters (such as changing data types, modifying parameter structures, altering null values, etc.) to generate diverse test cases that conform to smart contract interface requirements. This allows the generation of valid test cases that can be successfully parsed and executed by the smart contract interfaces.

Inventive Principle:
Principle #35Parameter changes

Solution Approach 2:

The patent performs preliminary actions by pre-defining parameter structures and validation rules before test case generation. The system establishes the expected parameter formats and structures in advance, then uses these pre-defined structures to guide the mutation and generation process, ensuring that generated test cases meet interface requirements from the outset.

Inventive Principle:
Principle #10Preliminary action

2Productivity

If test cases are generated without considering parameter structures, then generation speed may be faster, but the test cases cannot cover deeper program paths due to parsing failures

Engineering Contradiction:
Improvetest case generation speedVSAvoidprogram path coverage quality
Core Design Contradiction:
ProductivityVSManufacturing precision

Solution Approach 1:

The system performs structured parameter mutations including changing data types (e.g., from string to integer), modifying parameter structures (adding/removing fields), altering null values, and changing array structures. These parameter changes are applied systematically to generate test cases that both maintain generation speed and achieve deep program path coverage by exploring different execution branches.

Inventive Principle:
Principle #35Parameter changes

Solution Approach 2:

The patent implements dynamic test case generation where the mutation operations are applied adaptively based on the parameter structure analysis. The system dynamically adjusts which mutation operations to apply and in what sequence, allowing flexible exploration of program paths while maintaining efficient generation throughput.

Inventive Principle:
Principle #15Dynamics

3Reliability

If comprehensive parameter mutation is performed to cover all program paths, then testing coverage improves, but the complexity of the generation process increases

Engineering Contradiction:
Improveprogram path coverageVSAvoidtest case generation process complexity
Core Design Contradiction:
ReliabilityVSDevice complexity

Solution Approach 1:

The patent segments the test case generation process into distinct modular steps: parameter structure analysis, identification of mutable parameters, application of specific mutation operations, and validation. This segmentation allows each step to be independently implemented and optimized, reducing overall process complexity while achieving comprehensive coverage through systematic exploration of parameter variations.

Inventive Principle:
Principle #1Segmentation

Solution Approach 2:

The system employs a comprehensive set of parameter change operations including type mutation, structure mutation, null value insertion, and array manipulation. By categorizing and systematically applying these different types of parameter changes, the system achieves thorough program path coverage without requiring an overly complex monolithic generation process.

Inventive Principle:
Principle #35Parameter changes

Data Source

PatentUS11204860B2Methods and apparatuses for generating smart contract test case
Publication Date: 2021.12.21 ANT BLOCKCHAIN TECHNOLOGY (SHANGHAI) CO LTD
  • US11204860B2 patent drawing
  • US11204860B2 patent drawing
  • US11204860B2 patent drawing

AI summary

Embodiments of the present specification provide a method and an apparatus for generating a smart contract test case. A test case that can be parsed by the smart contract includes one or more structured parameters, and the structured parameters are used to invoke interfaces of the smart contract. If a structured parameter can be identified by an interface of the smart contract, a mutated structured parameter obtained by mutating the structured parameter based on a parameter structure of the structured parameter can also be identified by the interface of the smart contract, a test case including the mutated structured parameter can be generated, which ensures that the test case generated can be executed by the smart contract and can cover a deeper program path in the smart contract, thereby improving the efficiency of testing the smart contract.