CN111352835A - Intelligent contract testing method, device, equipment and storage medium - Google Patents
Intelligent contract testing method, device, equipment and storage medium Download PDFInfo
- Publication number
- CN111352835A CN111352835A CN202010117685.3A CN202010117685A CN111352835A CN 111352835 A CN111352835 A CN 111352835A CN 202010117685 A CN202010117685 A CN 202010117685A CN 111352835 A CN111352835 A CN 111352835A
- Authority
- CN
- China
- Prior art keywords
- test
- contract
- tested
- intelligent contract
- intelligent
- 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.)
- Granted
Links
- 238000012360 testing method Methods 0.000 title claims abstract description 311
- 238000000034 method Methods 0.000 claims abstract description 62
- 238000012545 processing Methods 0.000 claims abstract description 30
- 238000004590 computer program Methods 0.000 claims description 12
- 230000002159 abnormal effect Effects 0.000 claims description 9
- 238000012544 monitoring process Methods 0.000 claims description 9
- 238000010998 test method Methods 0.000 claims description 4
- 230000006870 function Effects 0.000 description 16
- 230000008569 process Effects 0.000 description 12
- 238000007726 management method Methods 0.000 description 9
- 238000010586 diagram Methods 0.000 description 6
- 230000006978 adaptation Effects 0.000 description 3
- 238000012550 audit Methods 0.000 description 3
- 238000004891 communication Methods 0.000 description 3
- 230000008878 coupling Effects 0.000 description 3
- 238000010168 coupling process Methods 0.000 description 3
- 238000005859 coupling reaction Methods 0.000 description 3
- 230000006378 damage Effects 0.000 description 3
- 238000009877 rendering Methods 0.000 description 3
- 238000011161 development Methods 0.000 description 2
- 230000003993 interaction Effects 0.000 description 2
- 238000012423 maintenance Methods 0.000 description 2
- 238000005065 mining Methods 0.000 description 2
- 230000003287 optical effect Effects 0.000 description 2
- 230000001960 triggered effect Effects 0.000 description 2
- 238000004458 analytical method Methods 0.000 description 1
- 238000013475 authorization Methods 0.000 description 1
- 238000009412 basement excavation Methods 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000005540 biological transmission Effects 0.000 description 1
- 238000010276 construction Methods 0.000 description 1
- 238000013500 data storage Methods 0.000 description 1
- 230000007547 defect Effects 0.000 description 1
- 238000013461 design Methods 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 230000003862 health status Effects 0.000 description 1
- 230000000977 initiatory effect Effects 0.000 description 1
- 230000007246 mechanism Effects 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 238000012552 review Methods 0.000 description 1
- 238000012954 risk control Methods 0.000 description 1
- 230000000007 visual effect Effects 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Preventing errors by testing or debugging software
- G06F11/3668—Software testing
- G06F11/3672—Test management
- G06F11/3684—Test management for test design, e.g. generating new test cases
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Computer Hardware Design (AREA)
- Quality & Reliability (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Debugging And Monitoring (AREA)
Abstract
The embodiment of the invention discloses a method, a device, equipment and a storage medium for testing an intelligent contract, which comprises the following steps: receiving a test request sent by a server, wherein the test request carries an intelligent contract to be tested; generating a test contract corresponding to the intelligent contract to be tested according to the intelligent contract to be tested; processing the intelligent contract to be tested and the test contract to obtain a test result of the intelligent contract to be tested; and sending the test result to the server to respond to the test request. According to the embodiment of the application, a test contract corresponding to the intelligent contract to be tested is generated according to the intelligent contract to be tested; and then processing the intelligent contract to be tested and the test contract to obtain a test result of the intelligent contract to be tested. By adopting the method, the automatic testing of the intelligent contract is realized, and the testing efficiency of the intelligent contract is improved.
Description
Technical Field
The invention relates to the technical field of computers, in particular to a method, a device, equipment and a storage medium for testing an intelligent contract.
Background
Smart contracts are a computer protocol intended to propagate, verify or execute contracts in an informational manner, capable of allowing trusted transactions to be conducted without third parties, and these transactions are traceable and non-tamperable.
In the traditional test aiming at the intelligent contract, the white-box function level test is basically realized by writing a corresponding interface in an application layer or relying on an online compiler such as remix and the like. The method has low automation degree, consumes time for writing the use case, and is difficult to directly touch the test of the source code level of the intelligent contract. The traditional contract testing scheme focuses on interface debugging and is difficult to reuse.
Disclosure of Invention
The embodiment of the application provides a test method, a test device, equipment and a storage medium of an intelligent contract, which can realize automatic test and improve test efficiency.
The embodiment of the application provides a test method of an intelligent contract, which comprises the following steps:
receiving a test request sent by a server, wherein the test request carries an intelligent contract to be tested;
generating a test contract corresponding to the intelligent contract to be tested according to the intelligent contract to be tested;
processing the intelligent contract to be tested and the test contract to obtain a test result of the intelligent contract to be tested;
and sending the test result to the server to respond to the test request.
The embodiment of the present application further provides a testing apparatus for an intelligent contract, including:
the receiving module is used for receiving a test request sent by the server, wherein the test request carries an intelligent contract to be tested;
the generating module is used for generating a test contract corresponding to the intelligent contract to be tested according to the intelligent contract to be tested;
the processing module is used for processing the intelligent contract to be tested and the test contract to obtain a test result of the intelligent contract to be tested;
and the sending module is used for sending the test result to the server so as to respond to the test request.
Optionally, the generating module is specifically configured to:
acquiring an interface description of the intelligent contract to be tested;
and generating a test contract corresponding to the test scene of the interface description according to the interface description.
Optionally, the processing module is specifically configured to:
compiling the intelligent contract to be tested and the test contract respectively to obtain a compiled intelligent contract to be tested and a compiled test contract;
recording the compiled intelligent contract to be tested and the compiled test contract to a block chain;
and executing the compiled test contract to obtain a test result of the intelligent contract to be tested.
The embodiment of the present application further provides an apparatus, which includes a processor, an input device, an output device, and a memory, where the processor, the input device, the output device, and the memory are connected to each other, where the memory is used to store a computer program, the computer program includes program instructions, and the processor is configured to call the program instructions to execute the method.
The embodiment of the application also provides a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to realize the method.
The embodiment of the application has at least the following beneficial effects:
according to the embodiment of the application, a test contract corresponding to the intelligent contract to be tested is generated according to the intelligent contract to be tested; and then processing the intelligent contract to be tested and the test contract to obtain a test result of the intelligent contract to be tested. By adopting the method, the intelligent contract can be automatically tested, and the testing efficiency of the intelligent contract is improved.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the drawings without creative efforts.
Wherein:
fig. 1 is an interaction diagram of a method for testing an intelligent contract according to an embodiment of the present invention;
FIG. 2 is a schematic flow chart of a method for testing an intelligent contract according to an embodiment of the present invention;
FIG. 3 is a flow chart of a method for testing an intelligent contract according to an embodiment of the present invention;
FIG. 4 is a flowchart illustrating a method for testing an intelligent contract according to an embodiment of the present invention;
FIG. 5 is a flowchart illustrating a method for testing an intelligent contract according to an embodiment of the present invention;
FIG. 6 is a schematic structural diagram of an apparatus provided by an embodiment of the present invention;
fig. 7 is a schematic structural diagram of a testing apparatus for an intelligent contract according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
The terms "first," "second," and the like in the description and claims of the present application and in the above-described drawings are used for distinguishing between different objects and not for describing a particular order. Furthermore, the terms "include" and "have," as well as any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, system, article, or apparatus that comprises a list of steps or elements is not limited to only those steps or elements listed, but may alternatively include other steps or elements not listed, or inherent to such process, method, article, or apparatus.
Reference in the specification to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the specification. The appearances of the phrase in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. It is explicitly and implicitly understood by one skilled in the art that the embodiments described herein can be combined with other embodiments.
Because the traditional test aiming at the intelligent contract basically depends on an application layer to write a corresponding web3.js interface or depends on an online compiler such as remix to realize the interface function test, the method has low automation degree, consumes time for writing use cases and is difficult to test the source code level of the intelligent contract. The traditional contract test scheme focuses on interface debugging and is difficult to reuse, and the test process is difficult to trace and can not ensure completeness; meanwhile, the test process and contract deployment are independently opened, and the time cost is increased.
Therefore, the scheme provides a test method of the intelligent contract, and automatic test can be realized. On the other hand, the test of the scheme is carried out on the block chain, and the test process is identified and cannot be tampered.
The blockchain is a novel application mode of computer technologies such as distributed data storage, point-to-point transmission, a consensus mechanism and an encryption algorithm. A block chain (Blockchain), which is essentially a decentralized database, is a series of data blocks associated by using a cryptographic method, and each data block contains information of a batch of network transactions, so as to verify the validity (anti-counterfeiting) of the information and generate a next block. The blockchain may include a blockchain underlying platform, a platform product services layer, and an application services layer.
The block chain underlying platform can comprise processing modules such as user management, basic service, intelligent contract and operation monitoring. The user management module is responsible for identity information management of all blockchain participants, and comprises public and private key generation maintenance (account management), key management, user real identity and blockchain address corresponding relation maintenance (authority management) and the like, and under the authorization condition, the user management module supervises and audits the transaction condition of certain real identities and provides rule configuration (wind control audit) of risk control; the basic service module is deployed on all block chain node equipment and used for verifying the validity of the service request, recording the service request to storage after consensus on the valid request is completed, for a new service request, the basic service firstly performs interface adaptation analysis and authentication processing (interface adaptation), then encrypts service information (consensus management) through a consensus algorithm, transmits the service information to a shared account (network communication) completely and consistently after encryption, and performs recording and storage; the intelligent contract module is responsible for registering and issuing contracts, triggering the contracts and executing the contracts, developers can define contract logics through a certain programming language, issue the contract logics to a block chain (contract registration), call keys or other event triggering and executing according to the logics of contract clauses, complete the contract logics and simultaneously provide the function of upgrading and canceling the contracts; the operation monitoring module is mainly responsible for deployment, configuration modification, contract setting, cloud adaptation in the product release process and visual output of real-time states in product operation, such as: alarm, monitoring network conditions, monitoring node equipment health status, and the like.
The platform product service layer provides basic capability and an implementation framework of typical application, and developers can complete block chain implementation of business logic based on the basic capability and the characteristics of the superposed business. The application service layer provides the application service based on the block chain scheme for the business participants to use.
Referring to fig. 1, fig. 1 is an interaction diagram of a testing method for an intelligent contract according to an embodiment of the present application. As shown in fig. 1, it may include a testing server 101 and a request server 102, where the testing server 101 receives a testing request sent by the request server 102, and the testing request carries an intelligent contract to be tested; the test server 101 generates a test contract corresponding to the intelligent contract to be tested according to the intelligent contract to be tested; processing the intelligent contract to be tested and the test contract to obtain a test result of the intelligent contract to be tested; finally, the test server 101 sends the test result to the request server 102 to respond to the test request.
According to the embodiment of the application, a test contract corresponding to the intelligent contract to be tested is generated according to the intelligent contract to be tested; and then processing the intelligent contract to be tested and the test contract to obtain a test result of the intelligent contract to be tested. By adopting the method, the intelligent contract can be automatically tested, and the testing efficiency of the intelligent contract is improved.
Referring to fig. 2, fig. 2 is a schematic flowchart of a method for testing an intelligent contract according to an embodiment of the present application. As shown in fig. 2, it may include steps 201 and 204 as follows:
201. receiving a test request sent by a server, wherein the test request carries an intelligent contract to be tested;
the intelligent contract to be tested is the intelligent contract for testing.
Smart contracts are, among other things, computer protocols intended to propagate, verify or execute contracts in an informational manner, capable of allowing trusted transactions without third parties, and these transactions are traceable and non-tamperable.
The intelligent contracts to be tested may be located on a blockchain.
202. Generating a test contract corresponding to the intelligent contract to be tested according to the intelligent contract to be tested;
the test contract is a contract for testing the contract to be tested.
And the test server generates a test contract corresponding to the intelligent contract to be tested according to the intelligent contract to be tested so as to test the intelligent contract to be tested.
The method comprises the steps of obtaining interface description corresponding to the intelligent contract to be tested, and automatically generating a test contract covering a common test scene of the interface.
203. Processing the intelligent contract to be tested and the test contract to obtain a test result of the intelligent contract to be tested;
the processing may be compiling the intelligent contract to be tested and the test contract, deploying the compiled intelligent contract and the test contract to a block chain, and executing the test contract to test the intelligent contract to be tested.
204. And sending the test result to the server to respond to the test request.
The test results may be in the form of test reports, etc.
According to the embodiment of the application, a test contract corresponding to the intelligent contract to be tested is generated according to the intelligent contract to be tested; and then processing the intelligent contract to be tested and the test contract to obtain a test result of the intelligent contract to be tested. By adopting the method, the intelligent contract can be automatically tested, and the testing efficiency of the intelligent contract is improved.
Referring to fig. 3, fig. 3 is a schematic flowchart of a method for testing an intelligent contract according to an embodiment of the present application. As shown in fig. 3, it may include steps 301 and 310 as follows:
301. receiving a test request sent by a server, wherein the test request carries an intelligent contract to be tested;
302. acquiring an interface description of the intelligent contract to be tested;
the method comprises the steps of analyzing the interface description of the intelligent contract to be tested, and automatically generating a test contract covering the common test scene of the interface.
303. Generating a test contract corresponding to the test scene of the interface description according to the interface description;
the intelligent contract to be tested comprises a tested function, wherein the tested function comprises an input parameter and a return value, the input parameter is used as an input, and the input parameter specifies the type and the size of an input parameter. The generated test contract may simulate various exception cases against the entries.
Specifically, the generating of the test contract corresponding to the test scenario described by the interface according to the interface description includes:
acquiring a test contract template;
acquiring abnormal parameters corresponding to the interface description; wherein, the abnormal parameter is a parameter which does not conform to the interface description;
and filling the abnormal parameters corresponding to the interface description into the test contract template to obtain the test contract.
In the scheme, a template library jinja2 of python is adopted to generate a test contract. jinja2 is a template system developed by python web framework flash authors and is widely used due to its flexibility, speed and security. The test contract template has fixed content and variable content, and the variable content can be abstracted into parameters. And loading a test contract template by using a jinja2 library in python, analyzing the type and the size of a function entry parameter in the intelligent contract to be tested, and automatically simulating the parameters of various exception types and the parameters of exception lengths. And then filling the abnormal parameters into a test contract template through a method of jinja2 rendering to generate the test contract.
If the interface description of the intelligent contract to be tested contains isBlacklisted, whether a certain address of the Ethernet workshop is in a blacklist is judged. According to the description, obtaining abnormal parameters corresponding to the interface description, namely obtaining the Ethernet bay address not in the blacklist, filling the Ethernet bay address not in the blacklist into a test contract template through a jinja2 rendering method, and further generating a corresponding test contract.
Wherein the test contract may cover the following test scenarios:
1, testing whether the interface parameter length accords with a preset length;
for example, it is possible to test whether the field length satisfies the predetermined length.
2, testing whether the interface parameter type accords with a preset type;
such as whether the field type is a string, etc.
3, testing whether the interface address is in a preset address blacklist or not;
and 4, testing whether the interface address is not in a preset address blacklist.
The test contract may cover the test scenario and is not limited to the above enumeration but may also include testing whether preset fields are included, and so on. If a test contract can also cover: and testing whether the interface parameters contain preset fields and the like. The preset field may be an arbitrarily set field.
Specifically, the scheme may employ a template library jinja2 of python to generate a test contract.
The jinja2 is a template system developed by a python web framework flash author, and is a template engine imitating a django template to provide template support for flash. It is widely used because of its advantages of flexibility, quickness and safety. The development process is as follows:
(1) download install jinja 2;
pip3 install jinja2
(2) and writing a template file of the test contract.
(3) And generating a test contract after the jinja2 template engine rendering.
template.render()
304. Compiling the intelligent contract to be tested to obtain the compiled intelligent contract to be tested;
305. recording the compiled intelligent contract to be tested to a block chain, and acquiring the address of the compiled intelligent contract to be tested;
306. writing the address of the compiled intelligent contract to be tested into the test contract to obtain an updated test contract;
307. compiling the updated test contract to obtain a compiled test contract;
308. recording the compiled test contract to the block chain, and acquiring the address of the compiled test contract;
the compiling refers to converting the intelligent contract to be tested and the contract code corresponding to the test contract into a binary code which can be identified by the virtual machine. The compiling operation is to implement the deployment of the intelligent contract to be tested and the test contract on the blockchain. Wherein, the intelligent contract can be deployed through a shuffle, for example.
309. Executing the compiled test contract according to the address of the compiled test contract to obtain a test result of the intelligent contract to be tested;
and further, a target to be tested can be determined according to the address information so as to test the intelligent contract to be tested.
Since the test contract is written in the constructor for the interface call of the intelligent contract to be tested, the execution can be triggered automatically after the test contract is initialized. Of course, it may be placed in the normal function of a test contract for execution.
The test results can be generated automatically. The test result may include a success rate, a failure rate, a execution time, and the like.
310. And sending the test result to the server to respond to the test request.
According to the embodiment of the application, a test contract corresponding to the intelligent contract to be tested is generated according to the intelligent contract to be tested; and then processing the intelligent contract to be tested and the test contract to obtain a test result of the intelligent contract to be tested. By adopting the method, the intelligent contract can be automatically tested, and the testing efficiency of the intelligent contract is improved. On the other hand, the test of the scheme is carried out on the block chain, the test process is identified and cannot be tampered, and the test disclosure, transparency and traceability are guaranteed.
Referring to fig. 4, fig. 4 is a schematic flowchart of a testing method for an intelligent contract according to an embodiment of the present application. As shown in fig. 4, it may include steps 401 and 411, which are as follows:
401. initializing a block chain;
wherein the execution of the intelligent contract depends on the building of a bottom layer blockchain platform such as ethereum. And starting the node to dig the mine after the construction is finished.
The deployment process of the ethereum client Geth is as follows:
(1) download and install geth
git clone https://github.com/ethereum/go-ethereum
cd go-ethereum
makegeth
Wherein, the version number can be checked through geth version
(2) Start geth
Geth is used to create several accounts for use in mining.
geth--datadir path/to/custom/data/folder account new
An arrangement of a genetics block creation block is created.
Creating a created block:
Geth—datadirpath/to/custom/data/folderinitpath/to/store/genesisfile/genesis.json
starting:
geth--datadirpath/to/custom/data/folder—ipcpath path/to/custom/data/folder/geth.ipc--networkid 15
(3) attach interacts and initiates mining.
geth attach ipc:/Users/zhangpeng/ethData/geth.ipc
Starting ore excavation: start ()
402. Receiving a test request sent by a server, wherein the test request carries an intelligent contract to be tested;
and carrying out contract testing in the block chain environment with the deployment completed.
Fig. 5 is a schematic flow chart of a method for testing an intelligent contract according to an embodiment of the present application. The intelligent contract to be tested is developed and compiled into an intelligent contract, and then the intelligent contract is provided with the REQ, wherein the REQ is a software development and testing flow management platform and is used for managing the whole life cycle of software version development, testing, defect submission, regression testing, release and the like. The REQ platform distributes the smart contracts to different reviewers for review. And when the audit is passed, initiating a test request to enter a test flow.
403. Acquiring an interface description of the intelligent contract to be tested;
404. generating a test contract corresponding to the test scene of the interface description according to the interface description;
the test contract comprises whether the test interface parameter length conforms to the preset length.
Or, the test contract comprises whether the test interface parameter type conforms to a preset type.
Or, the test contract comprises whether the test interface address is in a preset address blacklist.
The test contract may be any one of the above tests, or may be a combination of any two or more of them, and is not specifically limited herein.
405. Compiling the intelligent contract to be tested and the test contract respectively to obtain a compiled intelligent contract to be tested and a compiled test contract;
406. recording the compiled intelligent contract to be tested and the compiled test contract to a block chain;
407. executing the compiled test contract to obtain a test result of the intelligent contract to be tested;
specifically, compiling the intelligent contract to be tested to obtain a compiled intelligent contract to be tested; recording the compiled intelligent contract to be tested to a block chain, and acquiring the address of the compiled intelligent contract to be tested; writing the address of the compiled intelligent contract to be tested into the test contract to obtain an updated test contract; compiling the updated test contract to obtain a compiled test contract; recording the compiled test contract to the block chain, and acquiring the address of the compiled test contract; and executing the compiled test contract according to the address of the compiled test contract to obtain a test result of the intelligent contract to be tested.
408. And sending the test result to the server to respond to the test request.
409. Monitoring a first event in the test contract;
the first event may be any event of a test contract. For example, it may be monitored whether a function is run in the test contract. Wherein an event may be added to a test contract when the test contract is generated.
410. Confirming whether the first event is matched with a preset event;
when automatically monitoring the contract testing event, the system can be matched with the preset event, and when the matching is successful, the system can be used for triggering functions such as front-end mail notification or other random reminding.
411. And if the matching is carried out, sending out a preset prompt.
If the event is detected, the comparison shows that the event is the event needing to be detected, and an alarm prompt is sent out.
Specifically, contract events are monitored, mail notifications are triggered, a contract instance can be constructed by adopting web3.js, and event notifications of test contracts are monitored.
First, instantiate a contract; then, subscribing contract events; and when the trigger event occurs, monitoring the mail output after the event.
According to the embodiment of the application, a test contract corresponding to the intelligent contract to be tested is generated according to the intelligent contract to be tested; and then processing the intelligent contract to be tested and the test contract to obtain a test result of the intelligent contract to be tested. By adopting the method, the intelligent contract can be automatically tested, and the testing efficiency of the intelligent contract is improved. On the other hand, the test of the scheme is carried out on the block chain, the test process is identified and cannot be tampered, and the test disclosure, transparency and traceability are guaranteed.
When the block chain service is off-shelf or a major security vulnerability occurs to a contract, the contract to be intelligently tested or the test contract is destroyed. In particular, typically the blockchain bottom layer provides two types of contracts by functional classification. The two contracts are a common business contract and a governance contract. Wherein, the governing contract provides a method of destroying the service contract. The destruction contract can be realized by instantiating the governance contract and calling the destruction method in the governance contract in an RPC (remote procedure call) mode.
In accordance with the foregoing embodiments, please refer to fig. 6, fig. 6 is a schematic structural diagram of an apparatus provided in an embodiment of the present application, and as shown in the drawing, the apparatus includes a processor, an input device, an output device, and a memory, where the processor, the input device, the output device, and the memory are connected to each other, where the memory is used to store a computer program, the computer program includes program instructions, the processor is configured to call the program instructions, and the program includes instructions for performing the following steps;
receiving a test request sent by a server, wherein the test request carries an intelligent contract to be tested;
generating a test contract corresponding to the intelligent contract to be tested according to the intelligent contract to be tested;
processing the intelligent contract to be tested and the test contract to obtain a test result of the intelligent contract to be tested;
and sending the test result to the server to respond to the test request.
According to the embodiment of the application, a test contract corresponding to the intelligent contract to be tested is generated according to the intelligent contract to be tested; and then processing the intelligent contract to be tested and the test contract to obtain a test result of the intelligent contract to be tested. By adopting the method, the intelligent contract can be automatically tested, and the testing efficiency of the intelligent contract is improved.
The above description has introduced the solution of the embodiment of the present application mainly from the perspective of the method-side implementation process. It is understood that the terminal includes corresponding hardware structures and/or software modules for performing the respective functions in order to implement the above-described functions. Those of skill in the art will readily appreciate that the present application is capable of hardware or a combination of hardware and computer software implementing the various illustrative elements and algorithm steps described in connection with the embodiments provided herein. Whether a function is performed as hardware or computer software drives hardware 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 application.
In the embodiment of the present application, the terminal may be divided into the functional units according to the above method example, for example, each functional unit may be divided corresponding to each function, or two or more functions may be integrated into one processing unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit. It should be noted that the division of the unit in the embodiment of the present application is schematic, and is only a logic function division, and there may be another division manner in actual implementation.
In accordance with the above, please refer to fig. 7, fig. 7 is a schematic structural diagram of a testing apparatus for an intelligent contract according to an embodiment of the present application. The system comprises a receiving module 701, a generating module 702, a processing module 703 and a sending module 704, and the specific steps are as follows:
a receiving module 701, configured to receive a test request sent by a server, where the test request carries an intelligent contract to be tested;
a generating module 702, configured to generate a test contract corresponding to the intelligent contract to be tested according to the intelligent contract to be tested;
the processing module 703 is configured to process the intelligent contract to be tested and the test contract to obtain a test result of the intelligent contract to be tested;
a sending module 704, configured to send the test result to the server to respond to the test request.
It can be seen that, according to the embodiment of the application, a test contract corresponding to the intelligent contract to be tested is generated according to the intelligent contract to be tested; and then processing the intelligent contract to be tested and the test contract to obtain a test result of the intelligent contract to be tested. By adopting the method, the intelligent contract can be automatically tested, and the testing efficiency of the intelligent contract is improved.
Further, the generating module 702 is specifically configured to:
acquiring an interface description of the intelligent contract to be tested; and generating a test contract corresponding to the test scene of the interface description according to the interface description.
Further, the generating module 702 is specifically configured to: acquiring a test contract template; acquiring abnormal parameters corresponding to the interface description; and filling the abnormal parameters into the test contract template to obtain the test contract.
Further, the test contract includes whether the test interface parameter length meets a preset length, or the test contract includes whether the test interface parameter type meets a preset type, or the test contract includes whether the test interface address is in a preset address blacklist.
Further, the processing module 703 is specifically configured to: compiling the intelligent contract to be tested to obtain the compiled intelligent contract to be tested; recording the compiled intelligent contract to be tested to a block chain, and acquiring the address of the compiled intelligent contract to be tested; writing the address of the compiled intelligent contract to be tested into the test contract to obtain an updated test contract; compiling the updated test contract to obtain a compiled test contract; recording the compiled test contract to the block chain, and acquiring the address of the compiled test contract; and executing the compiled test contract according to the address of the compiled test contract to obtain a test result of the intelligent contract to be tested.
Further, the apparatus further comprises: a listening module to: monitoring a first event in the test contract; the test contract comprises a first event and confirms whether the first event is matched with a preset event or not; and if the matching is carried out, sending out a preset prompt.
Further, the apparatus further comprises a destruction module configured to: when a preset condition is met, acquiring a treatment contract; and respectively processing the intelligent contract to be tested and the test contract according to the governance contract so as to destroy the intelligent contract to be tested and the test contract.
The present invention also provides an apparatus, including a processor, an input device, an output device, and a memory, where the processor, the input device, the output device, and the memory are connected to each other, where the memory is used to store a computer program, and the computer program includes program instructions, and the processor is configured to call the program instructions to perform part or all of the steps of any one of the methods for testing an intelligent contract as described in the above method embodiments.
Embodiments of the present application further provide a computer-readable storage medium, which stores a computer program, where the computer program is executed by a processor to implement part or all of the steps of any one of the methods for testing an intelligent contract described in the above method embodiments.
It should be noted that, for simplicity of description, the above-mentioned method embodiments are described as a series of acts or combination of acts, but those skilled in the art will recognize that the present application is not limited by the order of acts described, as some steps may occur in other orders or concurrently depending on the application. Further, those skilled in the art should also appreciate that the embodiments described in the specification are preferred embodiments and that the acts and modules referred to are not necessarily required in this application.
In the foregoing embodiments, the descriptions of the respective embodiments have respective emphasis, and for parts that are not described in detail in a certain embodiment, reference may be made to related descriptions of other embodiments.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus may be implemented in other manners. For example, the above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units is only one type of division of logical functions, and there may be other divisions when actually implementing, for example, a plurality of units or components may be combined or may be integrated into another system, or some features may be omitted, or not implemented. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection of some interfaces, devices or units, and may be an electric or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit may be implemented in the form of hardware, or may be implemented in the form of a software program module.
The integrated units, if implemented in the form of software program modules and sold or used as stand-alone products, may be stored in a computer readable memory. Based on such understanding, the technical solution of the present application may be substantially implemented or a part of or all or part of the technical solution contributing to the prior art may be embodied in the form of a software product stored in a memory, and including several instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method described in the embodiments of the present application. And the aforementioned memory comprises: various media capable of storing program codes, such as a usb disk, a read-only memory (ROM), a Random Access Memory (RAM), a removable hard disk, a magnetic or optical disk, and the like.
Those skilled in the art will appreciate that all or part of the steps in the methods of the above embodiments may be implemented by associated hardware instructed by a program, which may be stored in a computer-readable memory, which may include: flash memory disks, read-only memory, random access memory, magnetic or optical disks, and the like.
The foregoing detailed description of the embodiments of the present application has been presented to illustrate the principles and implementations of the present application, and the above description of the embodiments is only provided to help understand the method and the core concept of the present application; meanwhile, for a person skilled in the art, according to the idea of the present application, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present application.
Claims (10)
1. A test method of an intelligent contract is characterized by comprising the following steps:
receiving a test request sent by a server, wherein the test request carries an intelligent contract to be tested;
generating a test contract corresponding to the intelligent contract to be tested according to the intelligent contract to be tested;
processing the intelligent contract to be tested and the test contract to obtain a test result of the intelligent contract to be tested;
and sending the test result to the server to respond to the test request.
2. The method of claim 1, wherein generating a test contract corresponding to the intelligent contract to be tested according to the intelligent contract to be tested comprises:
acquiring an interface description of the intelligent contract to be tested;
and generating a test contract corresponding to the test scene of the interface description according to the interface description.
3. The method of claim 2, wherein generating, according to the interface description, a test contract corresponding to a test scenario of the interface description comprises:
acquiring a test contract template;
acquiring abnormal parameters corresponding to the interface description;
and filling the abnormal parameters into the test contract template to obtain the test contract.
4. The method of claim 2 or 3, wherein the test contract comprises testing whether an interface parameter length meets a preset length,
or, the test contract comprises whether the test interface parameter type conforms to a preset type,
or, the test contract comprises whether the test interface address is in a preset address blacklist.
5. The method according to any one of claims 1 to 4, wherein the processing the intelligent contracts to be tested and the test contracts to obtain test results of the intelligent contracts to be tested comprises:
compiling the intelligent contract to be tested to obtain the compiled intelligent contract to be tested;
recording the compiled intelligent contract to be tested to a block chain, and acquiring the address of the compiled intelligent contract to be tested;
writing the address of the compiled intelligent contract to be tested into the test contract to obtain an updated test contract;
compiling the updated test contract to obtain a compiled test contract;
recording the compiled test contract to the block chain, and acquiring the address of the compiled test contract;
and executing the compiled test contract according to the address of the compiled test contract to obtain a test result of the intelligent contract to be tested.
6. The method of claim 5, wherein the test contract contains a first event, the method further comprising:
monitoring a first event in the test contract;
confirming whether the first event is matched with a preset event;
and if the matching is carried out, sending out a preset prompt.
7. The method according to any one of claims 1 to 6, further comprising:
when a preset condition is met, acquiring a treatment contract;
and respectively processing the intelligent contract to be tested and the test contract according to the governance contract so as to destroy the intelligent contract to be tested and the test contract.
8. A test apparatus for intelligent contracts, comprising:
the receiving module is used for receiving a test request sent by the server, wherein the test request carries an intelligent contract to be tested;
the generating module is used for generating a test contract corresponding to the intelligent contract to be tested according to the intelligent contract to be tested;
the processing module is used for processing the intelligent contract to be tested and the test contract to obtain a test result of the intelligent contract to be tested;
and the sending module is used for sending the test result to the server so as to respond to the test request.
9. An apparatus comprising a processor, an input device, an output device and a memory, the processor, the input device, the output device and the memory being interconnected, wherein the memory is configured to store a computer program comprising program instructions, the processor being configured to invoke the program instructions to perform the method of any of claims 1 to 7.
10. A computer-readable storage medium, characterized in that the computer-readable storage medium stores a computer program which is executed by a processor to implement the method of any one of claims 1 to 7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010117685.3A CN111352835B (en) | 2020-02-25 | 2020-02-25 | Intelligent contract testing method, device, equipment and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010117685.3A CN111352835B (en) | 2020-02-25 | 2020-02-25 | Intelligent contract testing method, device, equipment and storage medium |
Publications (2)
Publication Number | Publication Date |
---|---|
CN111352835A true CN111352835A (en) | 2020-06-30 |
CN111352835B CN111352835B (en) | 2024-04-26 |
Family
ID=71194178
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010117685.3A Active CN111352835B (en) | 2020-02-25 | 2020-02-25 | Intelligent contract testing method, device, equipment and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN111352835B (en) |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111917729A (en) * | 2020-07-09 | 2020-11-10 | 财付通支付科技有限公司 | Dynamic injection test method and device and related equipment |
CN111949532A (en) * | 2020-08-10 | 2020-11-17 | 上海熙菱信息技术有限公司 | Test strategy based on risk handling under contract test |
CN112199096A (en) * | 2020-09-30 | 2021-01-08 | 深圳壹账通智能科技有限公司 | Intelligent contract deployment detection method and device, node equipment and storage medium |
Citations (10)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN107943691A (en) * | 2017-11-17 | 2018-04-20 | 深圳圣马歌科技有限公司 | A kind of method and device for the functional test page for automatically generating intelligent contract |
CN108304307A (en) * | 2018-01-24 | 2018-07-20 | 深圳圣马歌科技有限公司 | The method for testing performance of intelligent contract on a kind of block chain |
US20180225194A1 (en) * | 2016-05-16 | 2018-08-09 | Jpmorgan Chase Bank, N.A. | Method and system for implementing an automation software testing and packaging framework with entitlements |
CN108510389A (en) * | 2018-03-30 | 2018-09-07 | 深圳前海微众银行股份有限公司 | Intelligent contract call method, equipment and readable storage medium storing program for executing based on block chain |
EP3388994A1 (en) * | 2017-04-12 | 2018-10-17 | Siemens Aktiengesellschaft | Method and apparatus for computer-assisted testing of a blockchain |
CN109408373A (en) * | 2018-09-26 | 2019-03-01 | 深圳壹账通智能科技有限公司 | Test method, computer readable storage medium and the test terminal of intelligent contract |
JP2019053729A (en) * | 2017-09-15 | 2019-04-04 | 富士通株式会社 | Test method and test apparatus of smart contract |
WO2019101234A2 (en) * | 2019-03-04 | 2019-05-31 | Alibaba Group Holding Limited | Methods and devices for performing off-chain testing on smart contract |
WO2019180702A1 (en) * | 2018-03-18 | 2019-09-26 | Valid Network Ltd | Method and system for assessing future execution of a smart contract based on previous executions on a blockchain-based platform |
CN110633199A (en) * | 2018-06-22 | 2019-12-31 | 富士通株式会社 | Testing apparatus, method, and medium for block chain supporting intelligent contract |
-
2020
- 2020-02-25 CN CN202010117685.3A patent/CN111352835B/en active Active
Patent Citations (11)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20180225194A1 (en) * | 2016-05-16 | 2018-08-09 | Jpmorgan Chase Bank, N.A. | Method and system for implementing an automation software testing and packaging framework with entitlements |
EP3388994A1 (en) * | 2017-04-12 | 2018-10-17 | Siemens Aktiengesellschaft | Method and apparatus for computer-assisted testing of a blockchain |
JP2019053729A (en) * | 2017-09-15 | 2019-04-04 | 富士通株式会社 | Test method and test apparatus of smart contract |
CN107943691A (en) * | 2017-11-17 | 2018-04-20 | 深圳圣马歌科技有限公司 | A kind of method and device for the functional test page for automatically generating intelligent contract |
CN108304307A (en) * | 2018-01-24 | 2018-07-20 | 深圳圣马歌科技有限公司 | The method for testing performance of intelligent contract on a kind of block chain |
WO2019180702A1 (en) * | 2018-03-18 | 2019-09-26 | Valid Network Ltd | Method and system for assessing future execution of a smart contract based on previous executions on a blockchain-based platform |
CN108510389A (en) * | 2018-03-30 | 2018-09-07 | 深圳前海微众银行股份有限公司 | Intelligent contract call method, equipment and readable storage medium storing program for executing based on block chain |
CN110633199A (en) * | 2018-06-22 | 2019-12-31 | 富士通株式会社 | Testing apparatus, method, and medium for block chain supporting intelligent contract |
CN109408373A (en) * | 2018-09-26 | 2019-03-01 | 深圳壹账通智能科技有限公司 | Test method, computer readable storage medium and the test terminal of intelligent contract |
WO2019101234A2 (en) * | 2019-03-04 | 2019-05-31 | Alibaba Group Holding Limited | Methods and devices for performing off-chain testing on smart contract |
CN110809876A (en) * | 2019-03-04 | 2020-02-18 | 阿里巴巴集团控股有限公司 | Method and equipment for executing out-of-chain test on intelligent contract |
Cited By (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111917729A (en) * | 2020-07-09 | 2020-11-10 | 财付通支付科技有限公司 | Dynamic injection test method and device and related equipment |
CN111917729B (en) * | 2020-07-09 | 2023-04-07 | 财付通支付科技有限公司 | Dynamic injection test method and device and related equipment |
CN111949532A (en) * | 2020-08-10 | 2020-11-17 | 上海熙菱信息技术有限公司 | Test strategy based on risk handling under contract test |
CN112199096A (en) * | 2020-09-30 | 2021-01-08 | 深圳壹账通智能科技有限公司 | Intelligent contract deployment detection method and device, node equipment and storage medium |
Also Published As
Publication number | Publication date |
---|---|
CN111352835B (en) | 2024-04-26 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN109314642B (en) | Counting system and method for secure voting and distribution implemented with blockchain | |
Jürjens | Sound methods and effective tools for model-based security engineering with UML | |
Garamvölgyi et al. | Towards model-driven engineering of smart contracts for cyber-physical systems | |
CN110730973A (en) | Method and apparatus for computer-aided testing of blockchains | |
CN109002297B (en) | Deployment method, device, equipment and storage medium of consensus mechanism | |
CN111352835A (en) | Intelligent contract testing method, device, equipment and storage medium | |
CN110443075A (en) | A kind of method and device of block chain intelligence contract verifying deployment | |
Whittle et al. | Executable misuse cases for modeling security concerns | |
CN111949531B (en) | Block chain network testing method, device, medium and electronic equipment | |
CN111078554A (en) | Applet debugging method, device, equipment and storage medium | |
CN116155771A (en) | Network anomaly test method, device, equipment, storage medium and program | |
CN111444090B (en) | Contract testing method and device in blockchain, electronic equipment and storage medium | |
Apvrille et al. | Model-driven engineering for designing safe and secure embedded systems | |
Ameur-Boulifa et al. | Sysml model transformation for safety and security analysis | |
CN116361807A (en) | Risk management and control method and device, storage medium and electronic equipment | |
CN111221904A (en) | Intelligent contract deployment and execution method and device, electronic equipment and storage medium | |
AlSobeh et al. | Weavesim: A scalable and reusable cloud simulation framework leveraging aspect-oriented programming | |
Alrimawi et al. | Incidents are meant for learning, not repeating: sharing knowledge about security incidents in cyber-physical systems | |
Panzica La Manna | Local dynamic update for component-based distributed systems | |
Barnes | Experiences in the industrial use of formal methods | |
CN114707146B (en) | Workflow identification method, system, computer device and readable storage medium | |
Singh et al. | Demand based test case generation for object oriented system | |
CN109740351A (en) | A kind of leak detection method, device and the equipment of embedded firmware | |
CN115563205A (en) | Block chain system deployment method, device, medium and electronic equipment | |
CN113706131A (en) | Block chain transaction method, device and equipment based on encryption card |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
REG | Reference to a national code |
Ref country code: HK Ref legal event code: DE Ref document number: 40024807 Country of ref document: HK |
|
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |