CN117971679A - Intelligent contract test data generation method, device, equipment and storage medium - Google Patents

Intelligent contract test data generation method, device, equipment and storage medium Download PDF

Info

Publication number
CN117971679A
CN117971679A CN202410150101.0A CN202410150101A CN117971679A CN 117971679 A CN117971679 A CN 117971679A CN 202410150101 A CN202410150101 A CN 202410150101A CN 117971679 A CN117971679 A CN 117971679A
Authority
CN
China
Prior art keywords
test
test data
data
contract
intelligent contract
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202410150101.0A
Other languages
Chinese (zh)
Inventor
刘浛
赵鸿伯
刘少杰
杨志强
陈邦道
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Oxford Hainan Blockchain Research Institute Co ltd
Original Assignee
Oxford Hainan Blockchain Research Institute Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Oxford Hainan Blockchain Research Institute Co ltd filed Critical Oxford Hainan Blockchain Research Institute Co ltd
Priority to CN202410150101.0A priority Critical patent/CN117971679A/en
Publication of CN117971679A publication Critical patent/CN117971679A/en
Pending legal-status Critical Current

Links

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

The application discloses a method, a device, equipment and a storage medium for generating intelligent contract test data, which are applied to the technical field of intelligent contracts and comprise the steps of acquiring test task metadata and business logic codes; wherein; the business logic code is a code developed based on a domain-specific language and representing test data generation logic; performing data query by using a block chain network index database according to the requirements of the test task metadata and the service logic codes to obtain intelligent contract data on a real chain; and generating target test data according to the intelligent contract data on the real chain by using the business logic code. The application can generate the test data based on the intelligent contract data on the real chain by utilizing the logic code generated by the test data which is developed based on the domain specific language and represents the test data generation logic, and the accuracy and the authenticity of the intelligent contract test data can be improved because the test data is based on the data on the real chain in the process of generating the test data.

Description

Intelligent contract test data generation method, device, equipment and storage medium
Technical Field
The present invention relates to the field of intelligent contracts, and in particular, to a method, an apparatus, a device, and a storage medium for generating intelligent contract test data.
Background
Smart contract testing refers to testing activities performed against smart contract codes in order to ensure the correctness and security of smart contracts. The goal of intelligent contract testing is to ensure that the contract run process meets design expectations and that errors in the contract are discovered prior to formal deployment of the contract.
The methods commonly used for intelligent contract testing are static testing: static testing is testing by static analysis of intelligent contract codes under the condition that contracts are not operated; dynamic test: dynamic testing refers to deploying intelligent contracts in a simulated blockchain environment, and testing the contracts under the running state of the contracts. Therefore, when testing intelligent contracts, the intelligent contracts are mainly analyzed manually or tested in a simulation environment, the intelligent contracts are tested manually, so that the testing efficiency is low, the intelligent contracts are tested in a model environment due to the fact that the intelligent contracts are tested dynamically, and the testing accuracy is low.
Disclosure of Invention
Accordingly, the present invention aims to provide a method, a device and a storage medium for generating intelligent contract test data, which solve the technical problem that the test data in the prior art is not true, resulting in poor intelligent contract test effect.
In order to solve the technical problems, the invention provides an intelligent contract test data generation method, which comprises the following steps:
Acquiring test task metadata and service logic codes; wherein; the business logic code is a code which is developed based on a domain-specific language and used for representing test data generation logic;
Performing data query by using a block chain network index database according to the test task metadata and the requirements of the service logic codes to obtain intelligent contract data on a real chain;
and generating target test data according to the intelligent contract data on the real chain by utilizing the business logic code.
Optionally, the obtaining test task metadata and service logic codes includes:
The method comprises the steps of obtaining a chain ID of a real block chain, a contract address of a contract on the real block chain, a test contract address associated with a test task, a generated test data type and a test data generation frequency.
Optionally, the performing data query by using a blockchain network index database according to the test task metadata and the service logic code requirements to obtain intelligent contract data on a real chain includes:
processing the test task metadata and the business logic codes by using a semantic interpreter to obtain a target demand query statement;
and carrying out data query in the blockchain network index database by using the target demand query statement to obtain intelligent contract data on the real chain.
Optionally, before the data query is performed by using the blockchain network index database according to the test task metadata and the service logic code requirements to obtain the intelligent contract data on the real chain, the method further includes:
Monitoring the state change of the synchronous block chain network in real time;
And updating the block chain network index database in real time according to the state change of the block chain network to obtain the latest block chain network index database.
Optionally, the method further comprises:
Compiling the latest test data according to the requirements to generate a logic code;
And replacing the business logic code with the latest test data generation logic code to update test data generation logic.
Optionally, after the generating, by using the business logic code, target test data according to the intelligent contract data on the real chain, the method further includes:
constructing a test transaction according to the test contract address in the test task metadata and the target test data;
triggering the development platform contract execution environment to test the intelligent contract according to the test transaction.
The application also provides an intelligent contract test data generating device, which comprises:
The test task metadata and business logic code acquisition module is used for acquiring test task metadata and business logic codes; wherein; the business logic code is a code which is developed based on a domain-specific language and used for representing test data generation logic;
the data query module is used for carrying out data query by utilizing a block chain network index database according to the test task metadata and the requirements of the service logic codes to obtain intelligent contract data on a real chain;
and the test data generation module is used for generating target test data according to the intelligent contract data on the real chain by utilizing the business logic code.
Optionally, the test task metadata and service logic code acquisition module includes:
and the test task metadata and business logic code acquisition unit is used for acquiring the chain ID of the real block chain, the contract address of the contract on the real block chain, the test contract address associated with the test task, the type of the generated test data and the frequency of the generation of the test data.
The application also provides intelligent contract test data generating equipment, which comprises the following steps:
a memory for storing a computer program;
and the processor is used for realizing the intelligent contract test data generation method when executing the computer program.
The present application also provides a storage medium having stored thereon a computer program which, when executed by a processor, implements the steps of the smart contract test data generation method as described above.
Therefore, the application obtains the intelligent contract data on the real chain by utilizing the block chain network index database to perform data query according to the test task metadata and the requirements of the business logic codes, thereby generating the target test data according to the intelligent contract data on the real chain by utilizing the business logic codes. Compared with the current manual input generation test data or the test of static analysis of intelligent contract codes under the condition that intelligent contracts do not run, the method and the device can generate the test data based on the intelligent contract data on the real chain by utilizing the logic codes generated by the test data which are developed based on the domain specific language and represent the test data generation logic, and can improve the accuracy and the authenticity of the intelligent contract test data because the test data are based on the data on the real chain in the generation process of the test data.
In addition, the invention also provides an intelligent contract test data generating device, equipment and a storage medium, which have the same beneficial effects.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings that are required to be used in the embodiments or the description of the prior art will be briefly described below, and it is obvious that the drawings in the following description are only embodiments of the present invention, and that other drawings can be obtained according to the provided drawings without inventive effort for a person skilled in the art.
FIG. 1 is a flowchart of a method for generating intelligent contract test data, provided by an embodiment of the invention;
FIG. 2 is a flowchart illustrating a method for generating intelligent contract test data according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of an overall framework of a method for generating intelligent contract test data according to an embodiment of the present invention;
FIG. 4 is a schematic structural diagram of an intelligent contract test data generating device according to an embodiment of the present invention;
fig. 5 is a schematic structural diagram of an intelligent contract test data generating device according to an embodiment of the present invention.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present invention more apparent, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention, and it is apparent that the described embodiments are only some embodiments of the present invention, not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
Blockchain is a distributed system with features such as decentralization, non-tamperability, etc. The blockchain system ensures the security and reliability of data through cryptography. The data stored in a blockchain system is organized by what is referred to as a "blocky" data structure. Each block has a number and the block contains the hash value of the last numbered block in addition to the data of the current block. The data stored on a blockchain is referred to as the world state or on-chain state of the blockchain.
A smart contract is a program that runs on a blockchain. Smart contracts can be used to implement a variety of application logic. Typically, smart contracts deployed on blockchains have a unique contract address that is used to identify the contract identity. The smart contract user automatically executes corresponding application logic through the interface of the transaction triggered smart contract. The smart contracts may store data, and the data stored in the smart contracts is referred to as contract states. The intelligent contracts can be mutually called when the conditions are met. Smart contract testing refers to testing activities performed against smart contract codes in order to ensure the correctness and security of smart contracts. The goal of intelligent contract testing is to ensure that the contract run process meets design expectations and that errors in the contract are discovered prior to formal deployment of the contract.
Referring to fig. 1, fig. 1 is a flowchart of a method for generating intelligent contract test data according to an embodiment of the present invention. The method may include:
s101, acquiring test task metadata and service logic codes; wherein; business logic code is code developed based on a domain-specific language that represents test data generation logic.
The execution subject of this embodiment may be any electronic device, e.g., a computer, a cell phone, etc. The test task metadata in this embodiment refers to data describing the actual blockchain data type and/or the manner of acquisition and/or the type of generation data required. The embodiment is not limited to specific test task metadata, for example, the test task metadata may include a chain ID (identification) of a real blockchain, a contract address of a contract on the real blockchain, a test contract address associated with a test task; or the test task metadata in this embodiment may include a chain ID of the real blockchain, a contract address of a contract on the real blockchain, and a test data generation frequency; or the test task metadata in this embodiment may include a chain ID of the real blockchain, a contract address of a contract on the real blockchain, a test data type generated by the test contract address associated with the test task, and a test data generation frequency. The business logic code in this embodiment may have been edited before, or may be edited when it is required to generate test data, the business logic code in this embodiment corresponds to the test task metadata, and the business logic code in this embodiment may have a plurality of different business logic codes and generate different test data. It can be appreciated that when the test task metadata includes a chain ID of a real blockchain, a contract address of a contract on the real blockchain, a test contract address associated with a test task, a type of test data generated, and a frequency of generating the test data, the test data is generated more accurately, and the frequency more meets the requirements of users. The business logic code in this embodiment is a code developed based on a domain-specific language that represents test data generation logic, and the embodiment is not limited to a specific business logic code. For example, the business logic code in this embodiment may query the number of passes of a specific user stored in the contract according to the chain ID and the contract address specified by the test task metadata, and when the number of passes decreases, generate test data according to the decreased number and transaction data that causes the decrease in the number of passes, that is, the decreased number is used as the test data, and the generation logic determines the decrease in the number of passes according to the number of passes of the feature user; or the business logic code in this embodiment may also be a code that queries a specified contract state a of the contract according to the chain ID and the contract address specified by the test task metadata, queries data of another contract state B when the contract state is equal to a specific value, and uses the data of the other contract state B as test data, i.e., the normal logic in this embodiment is a code that determines the contract state B according to a specified contract state a when the contract state a is equal to a specific value; or the business logic code in the embodiment can also query the aggregate states of two specific users under the contract according to the chain ID and the contract address specified by the test task metadata, and calculate the difference between the two aggregate states to generate as test data.
S102, utilizing a blockchain network index database to perform data query according to the requirements of the test task metadata and the business logic codes, and obtaining intelligent contract data on a real chain.
The business logic code in this embodiment determines the process of querying the data, and the task metadata determines the targets of the query. The blockchain network index database in this embodiment is an index database storing blockchain network data. According to the embodiment, data query can be performed according to the requirements of the test task metadata and the business logic codes, and intelligent contract data on a real chain is obtained. For example, a task execution request of a frequency construction server is generated according to test data in the test task metadata, so that data is obtained from a blockchain network index database according to the frequency, or a chain ID of a real blockchain, a contract address of a contract on the real blockchain and a test contract address associated with a test task are obtained from the blockchain network index database according to the test task metadata; or may retrieve data from a blockchain network index database based on the inputs required by the business logic code. It will be appreciated that when there is a coupling relationship between contracts, the participation of the contract function will often depend on the contract states of other contracts, and the participation of functions of some contracts will also depend on the on-chain states, for which, if the intelligent contract development platform is tested in a simulated development environment, it is often impossible to give a simulated environment of a real on-chain state, and in order to fully test the intelligent contract before the intelligent contract is on-line, a developer needs to manually refer to the real on-chain state data as test data.
It should be further noted that, in order to improve the efficiency of data query, the above-mentioned data query using the blockchain network index database according to the requirements of the test task metadata and the service logic code to obtain the intelligent contract data on the real chain may include: processing the test task metadata and the business logic codes by using a semantic interpreter to obtain a target demand query statement; and carrying out data query in the block chain network index database by utilizing the target demand query statement to obtain intelligent contract data on the real chain. According to the embodiment, the test task metadata and the business logic codes can be directly processed according to the language interpreter to obtain target demand query sentences capable of carrying out data query, so that the target demand query sentences are directly utilized to carry out data query in the blockchain network index database to obtain intelligent contract data on a real chain. Because the manually constructed query statement is not required to be acquired, the target demand query statement can be directly obtained to perform data query, and therefore the data query efficiency can be improved.
It should be further noted that, in order to improve accuracy of the blockchain index database, before the above-mentioned using the blockchain network index database to perform data query according to the test task metadata and the service logic code requirements to obtain the intelligent contract data on the real chain, the method may further include: monitoring the state change of the synchronous block chain network in real time; and updating the block chain network index database in real time according to the state change of the block chain network to obtain the latest block chain network index database. The embodiment monitors the blockchain network in real time, so that the data in the blockchain network index database is updated in real time, and the accuracy of the blockchain index database is improved.
S103, generating target test data according to intelligent contract data on a real chain by utilizing the business logic code.
The target test data in this embodiment is data that can test the smart contract. After the target test data are generated, the intelligent contract can be tested by using the target test data, and the correctness and the safety of the intelligent contract are ensured. For ease of understanding, this embodiment presents an embodiment of a testing process for smart contracts based on targeted test data. For example, the number of passes of a specific user stored in a contract is queried based on a chain ID and a contract address specified by test task metadata, and when the number of passes decreases, transaction data based on the decreased number and resulting in a decrease in the number of passes is used as test data. The test data are input into a test contract deployed on the contract development platform, the tested contract executes transaction according to the transaction data in the test data, whether the number of the authenticated reductions of the tested users in the tested contract after the transaction is executed accords with the number of the reductions in the test data is checked, and if so, the intelligent contract test is passed. Or inquiring a designated contract state A of the contract according to the chain ID and the contract address designated by the test task metadata, and inquiring data of another contract state B and transaction data which causes the contract state A to change to generate test data when the contract state is equal to a specific value. The test data is input into a test contract deployed in the contract development platform, the tested contract executes transaction according to the transaction data in the test data, whether the contract state B in the tested contract is the same as the contract state B in the test data after the transaction is executed is checked, and if the contract state B is the same, the intelligent contract test is passed. Or inquiring the aggregate states of two specific users under the contract according to the chain ID and the contract address specified by the test task metadata, and solving the difference set of the two aggregate states to be used as test data to generate. And inserting the difference set data into the aggregate states of the two tested users in a transaction mode, checking whether the aggregate states of the tested users of the inserted tested contract are equal to the difference set in the tested data, and passing the intelligent contract test when the aggregate states are equal to the difference set in the tested data.
It should be further noted that the method may further include: compiling the latest test data according to the requirements to generate a logic code; the business logic code is replaced with the latest test data generation logic code to update the test data generation logic. By interacting with the real blockchain, the test data will also change according to the change in the real blockchain data. However, the logic for generating the test data does not change, so that a user needs to write new test data generation logic according to own requirements to create a new test task. The user can write new test data generating logic codes and update the test data generating logic of the old task by replacing the business logic codes of the old task. According to the application, the service logic codes are replaced, and the test data generation logic is updated, so that other test data are generated.
It should be further noted that, in order to improve the efficiency of the intelligent contract test, after generating the target test data according to the intelligent contract data on the real chain by using the business logic code, the method may further include: constructing a test transaction according to the test contract address and the target test data in the test task metadata; and triggering the development platform contract execution environment to test the intelligent contract according to the test transaction. This embodiment stores the results of the current test on the smart contract in a log for review after the test. According to the embodiment, the intelligent contract testing environment can be timely constructed, intelligent contract data on a real chain are utilized for testing intelligent contracts, and the efficiency of intelligent contract testing is improved.
The method for generating the intelligent contract test data provided by the embodiment of the application can comprise the following steps: s101, acquiring test task metadata and service logic codes; wherein; the business logic code is a code developed based on a domain-specific language and representing test data generation logic; s102, carrying out data query by utilizing a blockchain network index database according to the requirements of test task metadata and service logic codes to obtain intelligent contract data on a real chain; s103, generating target test data according to intelligent contract data on a real chain by utilizing the business logic code. Compared with the current manual input generation test data or the test of static analysis of intelligent contract codes under the condition that the intelligent contract is not operated, the method and the device can generate the test data based on the intelligent contract data on the real chain and the logic codes generated by the test data which are developed based on the domain specific language and represent the test data generation logic, so that the intelligent contract can be tested according to the generated test data, and the accuracy and the authenticity of the intelligent contract test data can be improved because the test data are based on the data on the real chain in the generation process of the test data, thereby improving the accuracy of the intelligent contract test. In addition, the test task metadata comprises a chain ID of a real block chain, a contract address of a contract on the real block chain, a test contract address related to a test task, a generated test data type and a test data generation frequency, so that the test data generation is more accurate; in addition, the query statement of the target requirement can be directly obtained to query the data without obtaining the query statement of the manual structure, so that the efficiency of the data query can be improved; in addition, the embodiment monitors the block chain network in real time, so that the data in the block chain network index database is updated in real time, and the accuracy of the block chain index database is improved; in addition, the embodiment can write the latest test data according to the requirements to generate logic codes to replace service logic codes, and adjust the service logic codes, so that the service logic codes are adjusted in time, and the diversity of test data generation is improved; in addition, the embodiment can timely construct a testing environment to test the intelligent contracts by utilizing the intelligent contract data on the real chain, so that the efficiency of testing the intelligent contracts is improved.
In order to facilitate understanding of the present invention, referring to fig. 2 in detail, fig. 2 is a flowchart illustrating a method for generating intelligent contract test data according to an embodiment of the present invention, which may specifically include:
s201, creating a test data generation task according to intelligent contract logic.
This embodiment creates a test data generation task that may include data demand targets, acquisition modes, and the like.
S202, analyzing the test data generation task to obtain task metadata.
The embodiment can analyze the task of generating the test data so as to obtain the required task metadata, wherein the metadata can comprise the required data type and the mode of generating the test data.
S203, performing data query by utilizing the blockchain network index database according to the test task metadata and the requirements of service logic codes to obtain intelligent contract data on a real chain, wherein the service logic codes are developed based on a domain specific language.
The business logic code in this embodiment may be a business logic code edited from a test data generation task. According to the embodiment, data query can be performed according to the test task metadata to obtain intelligent contract data on the real chain, and data query can be performed according to the requirements of the business logic codes at the same time to obtain the intelligent contract data on the real chain. It can be appreciated that when the test task metadata cannot accurately obtain the input data required by the service logic code, the data needs to be supplemented according to the input requirement of the service logic code.
S204, executing business logic codes according to the task metadata and the intelligent contract data on the real chain, and generating test data.
According to the embodiment, an automatic test data generation task can be generated according to the developed intelligent contract logic, state metadata on a real chain on which the task depends and test data generation logic codes developed based on a domain specific language are obtained, the test data is automatically generated according to the metadata provided by the task and the test data generation logic codes, and the efficiency and the accuracy of test data generation are improved.
In order to facilitate understanding of the present invention, referring to fig. 3 in detail, fig. 3 is a schematic diagram of an overall framework of an intelligent contract test data generation method according to an embodiment of the present invention, which may specifically include:
Step ①, the intelligent contract development platform acquires task metadata corresponding to the test task and business logic codes written based on the domain specific language; the task metadata comprises a chain of a real blockchain, a contract address of a contract on the real blockchain, a test contract address associated with a test task, a generated test data type and a test data generation frequency;
②, storing a test task by a test task manager in the intelligent contract development platform;
Step ③, a test task manager in the intelligent contract development platform builds a task execution request according to the test data generation frequency;
After receiving the task execution request, the service interface of the ④ th test data generation server analyzes the task metadata and the service logic code, and sends the task metadata and the service logic code to the language interpreter for execution;
step ⑤, the language interpreter sends a data query request on the chain according to the task metadata and the business logic code;
⑥, a data service interface of the test data generation server queries data according to the on-chain data query request;
Step ⑦, a service interface of the data server analyzes the data query request on the chain to generate a query statement of the index database, and queries in the index database;
⑧, synchronizing state changes of the blockchain network in real time by an index database;
Step ⑨, the index database returns the result to the service interface of the data server according to the query data requirement;
step ⑩, the service interface of the data server returns the query interface to the service interface of the test data generation server;
First, the The data service interface returns the inquired target data to the language interpreter;
First, the Generating test data by the language interpreter according to the target data and the test data code generation logic calculation and returning the test data to the service interface;
First, the Step, the service interface returns test data to the test task manager;
First, the And step, the test task manager constructs test transaction based on the returned test data according to the test contract address managed in the task metadata, and triggers the development platform execution environment to execute the test intelligent contract.
The embodiment of the invention has the following beneficial effects:
1. based on the real on-chain state, the real on-chain contract state generates test data, and accuracy and authenticity of the intelligent contract test data are improved.
2. The online test data generation task creation can be combined with an online intelligent contract platform without adding additional development tools.
3. The method can automatically and custom generate test data, and can help simulate the real execution scene of the intelligent on-the-real-chain environment.
4. By writing test data generation code in a domain-specific language, a user can create new data on the basis of the state on the real chain.
5. The development difficulty of the test data generation logic is reduced based on the domain-specific language.
The following describes an apparatus for generating intelligent contract test data according to an embodiment of the present invention, where the apparatus for generating intelligent contract test data described below and the method for generating intelligent contract test data described above may be referred to correspondingly with each other.
Referring to fig. 4 specifically, fig. 4 is a schematic structural diagram of an intelligent contract test data generating apparatus according to an embodiment of the present invention, which may include:
the test task metadata and service logic code acquisition module 100 is used for acquiring test task metadata and service logic codes; wherein; the business logic code is a code which is developed based on a domain-specific language and used for representing test data generation logic;
The data query module 200 is configured to perform data query according to the test task metadata and the service logic code requirements by using a blockchain network index database, so as to obtain intelligent contract data on a real chain;
and the test data generating module 300 is used for generating target test data according to the intelligent contract data on the real chain by utilizing the business logic code.
Further, based on the above embodiment, the above test task metadata and service logic code obtaining module 100 may include:
and the test task metadata and business logic code acquisition unit is used for acquiring the chain ID of the real block chain, the contract address of the contract on the real block chain, the test contract address associated with the test task, the type of the generated test data and the frequency of the generation of the test data.
Further, based on any of the above embodiments, the data query module 200 may include:
The target demand query statement determining unit is used for processing the test task metadata and the business logic codes by utilizing a semantic interpreter to obtain a target demand query statement;
And the data query unit is used for performing data query in the block chain network index database by utilizing the target demand query statement to obtain intelligent contract data on the real chain.
Further, based on any of the above embodiments, the above intelligent contract test data generating apparatus may further include:
the block chain network monitoring module is used for monitoring the state change of the synchronous block chain network in real time;
And the database updating unit is used for updating the block chain network index database in real time according to the state change of the block chain network to obtain the latest block chain network index database.
Further, based on any of the above embodiments, the above intelligent contract test data generating apparatus may further include:
The latest logic code writing module is used for writing latest test data according to requirements to generate logic codes;
And the test data generation logic updating module is used for replacing the business logic code by the latest test data generation logic code so as to update the test data generation logic.
Further, based on any of the above embodiments, the above intelligent contract test data generating apparatus may further include:
The test transaction construction module is used for constructing a test transaction according to the test contract address in the test task metadata and the target test data;
And the intelligent contract testing module is used for triggering the development platform contract execution environment to test the intelligent contract according to the test transaction.
The modules and units in the intelligent contract test data generation apparatus can change the order of the modules and units before and after the modules and units do not affect the logic.
The device for generating intelligent contract test data provided by the embodiment of the application can comprise: the test task metadata and service logic code acquisition module 100 is used for acquiring test task metadata and service logic codes; wherein; the business logic code is a code which is developed based on a domain-specific language and used for representing test data generation logic; the data query module 200 is configured to perform data query according to the test task metadata and the service logic code requirements by using a blockchain network index database, so as to obtain intelligent contract data on a real chain; and the test data generating module 300 is used for generating target test data according to the intelligent contract data on the real chain by utilizing the business logic code. Compared with the current manual input generation test data or the test of static analysis of intelligent contract codes under the condition that the intelligent contract is not operated, the method and the device can generate the test data based on the intelligent contract data on the real chain and the logic codes generated by the test data which are developed based on the domain specific language and represent the test data generation logic, so that the intelligent contract can be tested according to the generated test data, and the accuracy and the authenticity of the intelligent contract test data can be improved because the test data are based on the data on the real chain in the generation process of the test data, thereby improving the accuracy of the intelligent contract test. In addition, the test task metadata comprises a chain ID of a real block chain, a contract address of a contract on the real block chain, a test contract address related to a test task, a generated test data type and a test data generation frequency, so that the test data generation is more accurate; in addition, the query statement of the target requirement can be directly obtained to query the data without obtaining the query statement of the manual structure, so that the efficiency of the data query can be improved; in addition, the embodiment monitors the block chain network in real time, so that the data in the block chain network index database is updated in real time, and the accuracy of the block chain index database is improved; in addition, the embodiment can write the latest test data according to the requirements to generate logic codes to replace service logic codes, and adjust the service logic codes, so that the service logic codes are adjusted in time, and the diversity of test data generation is improved; in addition, the embodiment can timely construct a testing environment to test the intelligent contracts by utilizing the intelligent contract data on the real chain, so that the efficiency of testing the intelligent contracts is improved.
The following describes an apparatus for generating intelligent contract test data according to an embodiment of the present invention, where the apparatus for generating intelligent contract test data described below and the method for generating intelligent contract test data described above may be referred to correspondingly to each other.
Referring to fig. 5, fig. 5 is a schematic structural diagram of an intelligent contract test data generating apparatus according to an embodiment of the present invention, which may include:
A memory 10 for storing a computer program;
and a processor 20 for executing a computer program to implement the above-described smart contract test data generation method.
The memory 10, the processor 20, and the communication interface 30 all communicate with each other via a communication bus 40.
In the embodiment of the present invention, the memory 10 is used for storing one or more programs, the programs may include program codes, the program codes include computer operation instructions, and in the embodiment of the present invention, the memory 10 may store programs for implementing the following functions:
Acquiring test task metadata and service logic codes; wherein; the business logic code is a code developed based on a domain-specific language and representing test data generation logic;
Performing data query by using a block chain network index database according to the requirements of the test task metadata and the service logic codes to obtain intelligent contract data on a real chain;
and generating target test data according to the intelligent contract data on the real chain by using the business logic code.
In one possible implementation, the memory 10 may include a storage program area and a storage data area, wherein the storage program area may store an operating system, and at least one application program required for functions, etc.; the storage data area may store data created during use.
In addition, memory 10 may include read only memory and random access memory and provide instructions and data to the processor. A portion of the memory may also include NVRAM. The memory stores an operating system and operating instructions, executable modules or data structures, or a subset thereof, or an extended set thereof, where the operating instructions may include various operating instructions for performing various operations. The operating system may include various system programs for implementing various basic tasks as well as handling hardware-based tasks.
The processor 20 may be a central processing unit (Central Processing Unit, CPU), an asic, a dsp, a fpga or other programmable logic device, and the processor 20 may be a microprocessor or any conventional processor. The processor 20 may call a program stored in the memory 10.
The communication interface 30 may be an interface of a communication module for connecting with other devices or systems.
Of course, it should be noted that the structure shown in fig. 5 does not limit the smart contract test data generation apparatus according to the embodiment of the present invention, and the smart contract test data generation apparatus may include more or less components than those shown in fig. 5 or may combine some components in practical applications.
The following describes a storage medium provided in an embodiment of the present invention, and the storage medium described below and an intelligent contract test data generation method described above may be referred to correspondingly.
The invention also provides a storage medium, wherein the storage medium stores a computer program, and the computer program realizes the steps of the intelligent contract test data generation method when being executed by a processor.
The storage medium may include: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
In this specification, each embodiment is described in a progressive manner, and each embodiment is mainly described in a different point from other embodiments, so that the same or similar parts between the embodiments are referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant points refer to the description of the method section.
Those of skill would further appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or combinations of both, and that the various illustrative elements and steps are described above generally in terms of functionality in order to clearly illustrate the interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
Finally, it is further noted that, in this document, relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus.
The foregoing has described in detail the method, apparatus, device and storage medium for generating intelligent contract test data, and specific examples have been used herein to illustrate the principles and embodiments of the present invention, and the above examples are only for aiding in the understanding of the method and core ideas of the present invention; meanwhile, as those skilled in the art will have variations in the specific embodiments and application scope in accordance with the ideas of the present invention, the present description should not be construed as limiting the present invention in view of the above.

Claims (10)

1. A method for generating intelligent contract test data, comprising:
Acquiring test task metadata and service logic codes; wherein; the business logic code is a code which is developed based on a domain-specific language and used for representing test data generation logic;
Performing data query by using a block chain network index database according to the test task metadata and the requirements of the service logic codes to obtain intelligent contract data on a real chain;
and generating target test data according to the intelligent contract data on the real chain by utilizing the business logic code.
2. The smart contract test data generation method of claim 1, wherein the acquiring test task metadata and business logic code includes:
The method comprises the steps of obtaining a chain ID of a real block chain, a contract address of a contract on the real block chain, a test contract address associated with a test task, a generated test data type and a test data generation frequency.
3. The method for generating intelligent contract test data according to claim 1, wherein the step of using a blockchain network index database to perform data query according to the test task metadata and the service logic code requirements to obtain intelligent contract data on a real chain includes:
processing the test task metadata and the business logic codes by using a semantic interpreter to obtain a target demand query statement;
and carrying out data query in the blockchain network index database by using the target demand query statement to obtain intelligent contract data on the real chain.
4. The method for generating intelligent contract test data according to claim 1, further comprising, before said using a blockchain network index database to perform data query according to the test task metadata and the requirements of the business logic code, obtaining intelligent contract data on a real chain:
Monitoring the state change of the synchronous block chain network in real time;
And updating the block chain network index database in real time according to the state change of the block chain network to obtain the latest block chain network index database.
5. The smart contract test data generation method of any one of claims 1 to 4, further comprising:
Compiling the latest test data according to the requirements to generate a logic code;
And replacing the business logic code with the latest test data generation logic code to update test data generation logic.
6. The smart contract test data generation method of claim 1, further comprising, after the generating target test data from smart contract data on the real chain using the business logic code:
constructing a test transaction according to the test contract address in the test task metadata and the target test data;
triggering the development platform contract execution environment to test the intelligent contract according to the test transaction.
7. An intelligent contract test data generation apparatus, comprising:
The test task metadata and business logic code acquisition module is used for acquiring test task metadata and business logic codes; wherein; the business logic code is a code which is developed based on a domain-specific language and used for representing test data generation logic;
the data query module is used for carrying out data query by utilizing a block chain network index database according to the test task metadata and the requirements of the service logic codes to obtain intelligent contract data on a real chain;
and the test data generation module is used for generating target test data according to the intelligent contract data on the real chain by utilizing the business logic code.
8. The smart contract test data generation apparatus of claim 7, wherein the test task metadata and business logic code acquisition module comprises:
and the test task metadata and business logic code acquisition unit is used for acquiring the chain ID of the real block chain, the contract address of the contract on the real block chain, the test contract address associated with the test task, the type of the generated test data and the frequency of the generation of the test data.
9. An intelligent contract test data generation apparatus, comprising:
a memory for storing a computer program;
a processor for implementing the smart contract test data generation method of any one of claims 1 to 6 when executing the computer program.
10. A storage medium having stored thereon a computer program which, when executed by a processor, implements the steps of the smart contract test data generation method of any of claims 1 to 6.
CN202410150101.0A 2024-02-02 2024-02-02 Intelligent contract test data generation method, device, equipment and storage medium Pending CN117971679A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202410150101.0A CN117971679A (en) 2024-02-02 2024-02-02 Intelligent contract test data generation method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202410150101.0A CN117971679A (en) 2024-02-02 2024-02-02 Intelligent contract test data generation method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN117971679A true CN117971679A (en) 2024-05-03

Family

ID=90851202

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202410150101.0A Pending CN117971679A (en) 2024-02-02 2024-02-02 Intelligent contract test data generation method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN117971679A (en)

Similar Documents

Publication Publication Date Title
CN111722839B (en) Code generation method and device, electronic equipment and storage medium
CN105279090B (en) Test script generation method and device applied to financial field
EP2095236B1 (en) Method, system and computer program for testing software applications based on multiple data sources
CN112052172B (en) Rapid test method and device for third-party channel and electronic equipment
CN108111364B (en) Service system testing method and device
CN110955409B (en) Method and device for creating resources on cloud platform
JP2023086678A (en) Method and apparatus for generating and applying deep learning model based on deep learning framework
CN104573127B (en) Assess the method and system of data variance
US20220067101A1 (en) Concept prediction to create new intents and assign examples automatically in dialog systems
CN116974874A (en) Database testing method and device, electronic equipment and readable storage medium
CN116225622A (en) Docker-based PaaS application parameter template testing method
CN117971679A (en) Intelligent contract test data generation method, device, equipment and storage medium
Mateos et al. Keeping web service interface complexity low using an oo metric-based early approach
CN111444618B (en) Simulation method and device based on variable dictionary
CN112181825A (en) Test case library construction method and device, electronic equipment and medium
CN110008098B (en) Method and device for evaluating operation condition of nodes in business process
CN114116244A (en) Data processing method, device and system, electronic equipment and storage medium
Alipour et al. Software reliability assessment based on a formal requirements specification
Mårtensson et al. An approach for performance evaluation of software architectures using prototyping
US20230259701A1 (en) Automated calculation predictions with explanations
CN112667503A (en) Financial research and development task online method, device, equipment and storage medium
CN115687130A (en) Financial business testing method and related equipment
CN114490291A (en) Information processing method and device, electronic equipment and computer readable storage medium
CN114510404A (en) Information processing method and device, electronic equipment and computer readable storage medium
CN117370184A (en) Interface testing method, device, equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication