CN111352835B - Intelligent contract testing method, device, equipment and storage medium - Google Patents

Intelligent contract testing method, device, equipment and storage medium Download PDF

Info

Publication number
CN111352835B
CN111352835B CN202010117685.3A CN202010117685A CN111352835B CN 111352835 B CN111352835 B CN 111352835B CN 202010117685 A CN202010117685 A CN 202010117685A CN 111352835 B CN111352835 B CN 111352835B
Authority
CN
China
Prior art keywords
contract
test
tested
intelligent contract
compiled
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.)
Active
Application number
CN202010117685.3A
Other languages
Chinese (zh)
Other versions
CN111352835A (en
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.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen 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 Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN202010117685.3A priority Critical patent/CN111352835B/en
Publication of CN111352835A publication Critical patent/CN111352835A/en
Application granted granted Critical
Publication of CN111352835B publication Critical patent/CN111352835B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test 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 application discloses a testing method, a device, equipment and a storage medium of an intelligent contract, which comprise 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, the 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 means, the intelligent contract is automatically tested, and the testing efficiency of the intelligent contract is improved.

Description

Intelligent contract testing method, device, equipment and storage medium
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method, an apparatus, a device, and a storage medium for testing an intelligent contract.
Background
Smart contracts are a type of computer protocol that aims to propagate, verify or execute contracts in an informative manner, capable of allowing trusted transactions to be made without third parties, and which can be tracked as tamper-proof.
Traditional intelligent contract testing basically adopts on-line compilers such as corresponding interfaces or dependencies remix written at an application layer to realize white box function level testing. The method has low automation degree, time consuming use case writing and difficult direct access to the source code level test of the intelligent contract. Traditional contract test schemes focus on interface debugging and are difficult to reuse.
Disclosure of Invention
The embodiment of the application provides a testing method, device and equipment for intelligent contracts and a storage medium, which can realize automatic testing and improve testing efficiency.
The embodiment of the application provides a testing 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 application also provides a testing device of the intelligent contract, which comprises:
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 generation 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 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 contracts to be tested and the compiled test contracts on a blockchain;
and executing the compiled test contract to obtain a test result of the intelligent contract to be tested.
The embodiment of the application also provides a device, which comprises a processor, an input device, an output device and a memory, wherein the processor, the input device, the output device and the memory are mutually connected, the memory is used for storing a computer program, the computer program comprises program instructions, and the processor is configured to call the program instructions and execute the method.
Embodiments of the present application also provide a computer-readable storage medium storing a computer program that is executed by a processor to implement the method.
The embodiment of the application has at least the following beneficial effects:
According to the embodiment of the application, the 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 means, 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 invention or the technical solutions in the prior art, the drawings that are required in the embodiments or the description of the prior art will be briefly described, it being obvious that the drawings in the following description are only some embodiments of the invention, and that other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
Wherein:
FIG. 1 is an interactive schematic diagram of a testing method of an intelligent contract according to an embodiment of the present invention;
FIG. 2 is a flow chart of a testing method of an intelligent contract according to an embodiment of the present invention;
FIG. 3 is a flow chart of a testing method of an intelligent contract according to an embodiment of the present invention;
FIG. 4 is a flow chart of a testing method of an intelligent contract according to an embodiment of the present invention;
FIG. 5 is a flow chart of a method for testing an intelligent contract according to an embodiment of the present invention;
FIG. 6 is a schematic diagram of an apparatus according to an embodiment of the present invention;
fig. 7 is a schematic structural diagram of a testing device for intelligent contracts according to an embodiment of the present invention.
Detailed Description
The following description of the embodiments of the present application will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present application, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
The terms first, second and the like in the description and in the claims and in the above-described figures are used for distinguishing between different objects and not necessarily for describing a sequential or chronological order. Furthermore, the terms "comprise" and "have," as well as any variations thereof, are intended to cover a non-exclusive inclusion. For example, a process, method, system, article, or apparatus that comprises a list of steps or elements is not limited to only those listed steps or elements but may 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 may be included in at least one embodiment of the application. The appearances of such phrases 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. Those of skill in the art will explicitly and implicitly appreciate that the described embodiments of the application may be combined with other embodiments.
Because the traditional intelligent contract test is basically realized by writing a corresponding web3.js interface or relying on remix on-line compilers, the method has low automation degree, takes time for writing use cases and is difficult to test the intelligent contract source code level. The traditional contract test scheme focuses on interface debugging, is difficult to reuse, and the test process is difficult to trace back, so that completeness cannot be guaranteed; meanwhile, the test process and contract deployment are independently separated, so that the time cost is increased.
Therefore, the intelligent contract testing method can realize automatic testing. On the other hand, the test of the scheme is carried out on a blockchain, and the test process is consensus and can not be tampered.
The blockchain is a novel application mode of computer technologies such as distributed data storage, point-to-point transmission, a consensus mechanism, an encryption algorithm and the like. The blockchain (Blockchain), essentially a de-centralized database, is a string of data blocks that are generated in association using cryptographic methods, each of which contains information from a batch of network transactions for verifying the validity (anti-counterfeit) of its information and generating the next block. The blockchain may include a blockchain underlying platform, a platform product services layer, and an application services layer.
The blockchain underlying platform may include processing modules for user management, basic services, smart contracts, operation monitoring, and the like. The user management module is responsible for identity information management of all blockchain participants, including maintenance of public and private key generation (account management), key management, maintenance of corresponding relation between the real identity of the user and the blockchain address (authority management) and the like, and under the condition of authorization, supervision and audit of transaction conditions of certain real identities, and provision of rule configuration (wind control audit) of risk control; the basic service module is deployed on all block chain node devices, is used for verifying the validity of a service request, recording the service request on a storage after the effective request is identified, for a new service request, the basic service firstly analyzes interface adaptation and authenticates the interface adaptation, encrypts service information (identification management) through an identification algorithm, and transmits the encrypted service information to a shared account book (network communication) in a complete and consistent manner, and records and stores the service information; the intelligent contract module is responsible for registering and issuing contracts, triggering contracts and executing contracts, a developer can define contract logic through a certain programming language, issue the contract logic to a blockchain (contract registering), invoke keys or other event triggering execution according to the logic of contract clauses to complete the contract logic, and simultaneously provide a function of registering contract upgrading; the operation monitoring module is mainly responsible for deployment in the product release process, modification of configuration, contract setting, cloud adaptation and visual output of real-time states in product operation, for example: alarms, monitoring network conditions, monitoring node device health status, etc.
The platform product service layer provides basic capabilities and implementation frameworks of typical applications, and developers can complete the blockchain implementation of business logic based on the basic capabilities and the characteristics of the superposition business. The application service layer provides the application service based on the block chain scheme to the business participants for use.
Referring to fig. 1, fig. 1 is an interaction schematic diagram of a testing method of an intelligent contract according to an embodiment of the present application. As shown in fig. 1, it may include a test server 101 and a request server 102, where the test server 101 receives a test request sent by the request server 102, and the test 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 in response to the test request.
According to the embodiment of the application, the 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 means, 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 flow chart of a testing method of an intelligent contract according to an embodiment of the application. As shown in fig. 2, it may include steps 201-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.
Where smart contracts are a computer protocol that aims to propagate, verify or execute contracts in an informative manner, can allow trusted transactions to be made without third parties, and these transactions can be tracked untampered.
The smart contract 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 to-be-tested contract.
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 an 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 above processing may be compiling the smart contract to be tested and the test contract, deploying the smart contract to a blockchain, and the like, and then executing the test contract to test the smart 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, the 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 means, 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 flow chart of a testing method of an intelligent contract according to an embodiment of the application. As shown in fig. 3, it may include steps 301-310, which are specifically as follows:
301. Receiving a test request sent by a server, wherein the test request carries an intelligent contract to be tested;
302. Acquiring interface description of the intelligent contract to be tested;
and automatically generating the test contract covering the common test scene of the interface by analyzing the interface description of the intelligent contract to be tested.
303. Generating a test contract corresponding to the test scene of the interface description according to the interface description;
there are tested functions in the smart contracts to be tested, which contain an input parameter as input, specifying the type and size of the input parameters, and a return value. The generated test contracts may simulate various abnormal cases for the entries.
Specifically, the generating a test contract corresponding to the test scene of the interface description according to the interface description includes:
obtaining a test contract template;
acquiring an abnormal parameter corresponding to the interface description; the abnormal parameters are parameters which do not accord with the description of the interface;
And filling the abnormal parameters corresponding to the interface description into the test contract template to obtain the test contract.
Wherein the present solution employs python's template library jinja to generate a test contract. jinja2 is a template system developed by the python web framework Flask author that is widely used for its flexibility, rapidity, 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 utilizing jinja library in python, analyzing the type and the size of the function input parameters in the intelligent contract to be tested, and automatically simulating parameters of various anomaly types and parameters of anomaly lengths. The exception parameters are then filled into the test contract template by the jinja rendering method to generate the test contract described above.
If the interface description of the smart contract to be tested includes isBlacklisted, it is determined whether an address is in the blacklist. And according to the description, acquiring the abnormal parameters corresponding to the interface description, namely acquiring the address which is not in the blacklist, filling the address which is not in the blacklist into a test contract template by a jinja rendering method, and further generating a corresponding test contract.
Wherein the test contract may cover the following test scenarios:
1, testing whether the parameter length of an interface accords with a preset length;
Such as whether the length of the testable field meets a preset length.
2, Testing whether the interface parameter type accords with a preset type;
Such as whether the field type is a string or the like.
3, Testing whether the interface address is in a preset address blacklist;
And 4, testing whether the interface address is not in a preset address blacklist.
The test contract may cover a test scenario not limited to the above list, but may also include testing whether a preset field is included, and so on. Such as test contracts may also cover: and testing whether the interface parameters contain preset fields and the like. The preset field may be an arbitrarily set field.
In particular, the present solution may employ python's template library jinja2 to generate a test contract.
Wherein jinja is a template system developed by the python web framework Flask author, initially a template engine that emulates the django template, providing template support for Flask. Is widely used because of its advantages of flexibility, rapidness, safety, etc. The development flow is as follows:
(1) Downloading the installation jinja;
pip3 install jinja2
(2) Template files of test contracts are written.
(3) After being rendered by jinja <2 > template engine, a test contract is generated.
template.render()
304. Compiling the intelligent contract to be tested to obtain a compiled intelligent contract to be tested;
305. recording the compiled intelligent contract to be tested on a blockchain, 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 blockchain, 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 enable deployment of the intelligent contracts to be tested and the test contracts on the blockchain. Wherein the smart contract may be deployed, for example, through truffle.
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;
According to the address information, a target to be tested can be determined, so that the intelligent contract to be tested can be tested.
Since the test contract is written in the constructor for the interface call of the smart contract to be tested, execution can be automatically triggered after the test contract is initialized. Of course, the test contract can be executed in the common function of the test contract.
The test results may be automatically generated. The test results may include success rate, failure rate, execution time, etc.
310. And sending the test result to the server to respond to the test request.
According to the embodiment of the application, the 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 means, the intelligent contract can be automatically tested, and the testing efficiency of the intelligent contract is improved. On the other hand, the testing of the scheme is carried out on the block chain, and the testing process is consensus and non-tamperable, so that the disclosure, transparency and traceability of the testing are ensured.
Referring to fig. 4, fig. 4 is a flow chart of a testing method of an intelligent contract according to an embodiment of the application. As shown in fig. 4, it may include steps 401-411, as follows:
401. Initializing a block chain;
Wherein execution of the smart contract relies on the construction of an underlying blockchain platform, such as ethereum. And starting the node after the construction is completed.
The deployment procedure of ethereum client Geth is as follows:
(1) Download and install geth
git clone https://github.com/ethereum/go-ethereum
cd go-ethereum
make geth
Wherein the version number can be viewed through geth version
(2) Start geth
Several accounts are created using geth.
geth--datadir path/to/custom/data/folder account new
A generation block creation block configuration is created.
Creating an creation 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 interactions and starts.
geth attach ipc:/Users/zhangpeng/ethData/geth.ipc
Starting: miner.start ()
402. Receiving a test request sent by a server, wherein the test request carries an intelligent contract to be tested;
and performing contract test in the deployed blockchain environment.
Fig. 5 is a schematic flow chart of a testing method of an intelligent contract according to an embodiment of the present application. The intelligent contract to be tested is written through development, and then the intelligent contract is upgraded to REQ, wherein REQ is a software development upgrade flow management platform and is used for managing the whole life cycle of software version development, upgrade, defect submission, regression test, release and the like. The REQ platform distributes the intelligent contract to different auditors for auditing. And after the verification is passed, initiating a test request to enter a test flow.
403. Acquiring 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 includes testing whether the interface parameter length meets a preset length.
Or the test contract includes testing whether the interface parameter type meets a preset type.
Or the test contract includes testing whether the interface address is in a preset address blacklist.
The test contract may be any one of the above, or any two or more of them may be combined, and the specific limitation is not given here.
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 contracts to be tested and the compiled test contracts on a blockchain;
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 on a blockchain, 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 blockchain, 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 the 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. Acquiring a first event in the test contract;
the first event may be any event of a test contract. For example, it may be obtained whether a function is running in a 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 the test contract event is automatically acquired, the test contract event is matched with a preset event, and when the matching is successful, the test contract event can be used for triggering functions such as front-end mail notification or other random reminding.
411. If so, a preset reminder is sent out.
If a certain event is acquired, an alarm reminding is sent out by comparing the event which is found to be required to be acquired.
Specifically, acquiring a contract event, triggering a mail notification, and constructing a contract instance by web3.js to acquire an event notification of a test contract.
First, instantiating a contract; then, subscribing to a contract event; and when the triggering event occurs, acquiring post-event mail output.
According to the embodiment of the application, the 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 means, the intelligent contract can be automatically tested, and the testing efficiency of the intelligent contract is improved. On the other hand, the testing of the scheme is carried out on the block chain, and the testing process is consensus and non-tamperable, so that the disclosure, transparency and traceability of the testing are ensured.
When the blockchain service is put down or a major security hole appears in the contract, destroying the contract to be intelligently or the test contract. In particular, the blockchain bottom layer typically provides two types of contracts by functional classification. The two contracts are a common business contract and a governance contract. Wherein, a method destory for destroying the business contract is provided in the governance contract. The destruction contract can be implemented by instantiating the governance contract and calling the destruction method in the governance contract by way of RPC (remote procedure call).
In accordance with the foregoing embodiments, referring to fig. 6, fig. 6 is a schematic structural diagram of an apparatus provided in an embodiment of the present application, where 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, and the memory is configured to store a computer program, where the computer program includes program instructions, where the processor is configured to invoke the program instructions, and where 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, the 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 means, the intelligent contract can be automatically tested, and the testing efficiency of the intelligent contract is improved.
The foregoing description of the embodiments of the present application has been presented primarily in terms of a method-side implementation. It will be appreciated that, in order to achieve the above-mentioned functions, the terminal includes corresponding hardware structures and/or software modules for performing the respective functions. Those of skill in the art will readily appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as hardware or combinations of hardware and computer software. Whether a function is implemented as hardware or computer software driven 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.
The embodiment of the application can divide the functional units of the terminal according to the method example, for example, each functional unit can be divided corresponding to each function, and two or more functions can be integrated in one processing unit. The integrated units may be implemented in hardware or in software functional units. It should be noted that, in the embodiment of the present application, the division of the units is schematic, which is merely a logic function division, and other division manners may be implemented in actual practice.
In accordance with the foregoing, referring to fig. 7, fig. 7 is a schematic structural diagram of a testing device for intelligent contracts 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 is specifically 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;
A processing module 703, configured to process the smart contract to be tested and the test contract to obtain a test result of the smart contract to be tested;
and a sending module 704, configured to send the test result to the server, so as to respond to the test request.
It can be seen that, according to the embodiment of the application, the 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 means, 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 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: obtaining a test contract template; acquiring an abnormal parameter 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 whether the test contract includes whether the test interface parameter type meets a preset type, or whether 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 a compiled intelligent contract to be tested; recording the compiled intelligent contract to be tested on a blockchain, 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 blockchain, 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 the test result of the intelligent contract to be tested.
Further, the apparatus further comprises: an acquisition module for: acquiring a first event in the test contract; the test contract comprises a first event, and whether the first event is matched with a preset event or not is confirmed; if so, a preset reminder is sent out.
Further, the device also comprises a destruction module for: when the preset conditions are met, acquiring a treatment contract; and respectively processing the intelligent contract to be tested and the test contract according to the treatment contract so as to destroy the intelligent contract to be tested and the test contract.
The embodiment of the application also provides a device, which comprises a processor, an input device, an output device and a memory, wherein the processor, the input device, the output device and the memory are mutually connected, the memory is used for storing a computer program, the computer program comprises program instructions, and the processor is configured to call the program instructions and execute part or all of the steps of the testing method of any intelligent contract described in the embodiment of the method.
Embodiments of the present application also provide a computer-readable storage medium storing a computer program that is executed by a processor to implement some or all of the steps of a testing method of any one of the smart contracts as described in the method embodiments above.
It should be noted that, for simplicity of description, the foregoing method embodiments are all described as a series of acts, but it should be understood by those skilled in the art that the present application is not limited by the order of acts described, as some steps may be performed in other orders or concurrently in accordance with the present application. Further, those skilled in the art will also appreciate that the embodiments described in the specification are all preferred embodiments, and that the acts and modules referred to are not necessarily required for the present application.
In the foregoing embodiments, the descriptions of the embodiments are emphasized, and for parts of one embodiment that are not described in detail, reference may be made to related descriptions of other embodiments.
In the several embodiments provided by the present application, it should be understood that the disclosed apparatus may be implemented in other manners. For example, the apparatus embodiments described above are merely illustrative, such as the division of the units, merely a logical function division, and there may be additional manners of dividing the actual implementation, such as multiple units or components may be combined or integrated into another system, or some features may be omitted, or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be an indirect coupling or communication connection via some interfaces, devices or units, or may be in electrical or other forms.
The units described as separate units may or may not be physically separate, and units shown 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 may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In addition, each functional unit in each embodiment of the present invention may be integrated in one processing unit, each unit may exist alone physically, or two or more units may be integrated in one unit. The integrated units described above may be implemented either in hardware or in software program modules.
The integrated units, if implemented in the form of software program modules, may be stored in a computer-readable memory for sale or use as a stand-alone product. Based on this understanding, the technical solution of the present application may be embodied essentially or partly in the form of a software product, or all or part of the technical solution, which is stored in a memory, and includes several instructions for causing a computer device (which may be a personal computer, a server, a network device, or the like) to perform all or part of the steps of the method according to the embodiments of the present application. And the aforementioned memory includes: a U-disk, a read-only memory (ROM), a random access memory (random access memory, RAM), a removable hard disk, a magnetic disk, or an optical disk, or other various media capable of storing program codes.
Those of ordinary skill in the art will appreciate that all or a portion of the steps in the various methods of the above embodiments may be implemented by a program that instructs associated hardware, and the program may be stored in a computer readable memory, which may include: flash disk, read-only memory, random access memory, magnetic or optical disk, etc.
The foregoing has outlined rather broadly the more detailed description of embodiments of the application, wherein the principles and embodiments of the application are explained in detail using specific examples, the above examples being provided solely to facilitate the understanding of the method and core concepts of the application; 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 application, the present description should not be construed as limiting the present application in view of the above.

Claims (9)

1. A method for testing an intelligent contract, comprising:
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;
Compiling the intelligent contract to be tested to obtain a compiled intelligent contract to be tested;
Recording the compiled intelligent contract to be tested on a blockchain, 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 blockchain, and acquiring the address of the compiled test contract;
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 sending the test result to the server to respond to the test request.
2. The method of claim 1, wherein the generating a test contract corresponding to the smart contract to be tested from the smart contract to be tested comprises:
Acquiring 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 a test contract corresponding to a test scenario of the interface description from the interface description comprises:
obtaining a test contract template;
Acquiring an abnormal parameter 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 testing contract includes testing whether the interface parameter length meets a predetermined length,
Or the test contract includes testing whether the interface parameter type meets a preset type,
Or the test contract includes testing whether the interface address is in a preset address blacklist.
5. The method of claim 1, wherein the test contract includes a first event, the method further comprising:
acquiring a first event in the test contract;
Confirming whether the first event is matched with a preset event;
If so, a preset reminder is sent out.
6. The method according to any one of claims 1 to 5, further comprising:
When the preset conditions are met, acquiring a treatment contract;
And respectively processing the intelligent contract to be tested and the test contract according to the treatment contract so as to destroy the intelligent contract to be tested and the test contract.
7. A testing 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 generation 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 compiling the intelligent contract to be tested to obtain a compiled intelligent contract to be tested;
The processing module is further used for recording the compiled intelligent contract to be tested on a blockchain and acquiring the address of the compiled intelligent contract to be tested;
The processing module is further configured to write the address of the compiled intelligent contract to be tested into the test contract, so as to obtain an updated test contract;
the processing module is further configured to compile the updated test contract to obtain a compiled test contract;
the processing module is further configured to record the compiled test contract onto the blockchain, and obtain an address of the compiled test contract;
The processing module is further configured to execute the compiled test contract according to the address of the compiled test contract, so as 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.
8. A device 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 adapted 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 6.
9. 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 6.
CN202010117685.3A 2020-02-25 2020-02-25 Intelligent contract testing method, device, equipment and storage medium Active CN111352835B (en)

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 CN111352835A (en) 2020-06-30
CN111352835B true 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)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
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

Citations (9)

* Cited by examiner, † Cited by third party
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
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

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10489278B2 (en) * 2016-05-16 2019-11-26 Jpmorgan Chase Bank, N.A. Method and system for implementing an automation software testing and packaging framework with entitlements

Patent Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
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

Also Published As

Publication number Publication date
CN111352835A (en) 2020-06-30

Similar Documents

Publication Publication Date Title
CN109314642B (en) Counting system and method for secure voting and distribution implemented with blockchain
CN102171652B (en) The method providing trusted software for electronic installation
US11621973B2 (en) Blockchain cybersecurity audit platform
CN112182655A (en) Data interaction method among multiple devices and related devices
CN110443075A (en) A kind of method and device of block chain intelligence contract verifying deployment
CN111352835B (en) Intelligent contract testing method, device, equipment and storage medium
CN112039866B (en) Design method of block chain-based data trusted configuration management system
CN113867913A (en) Business request processing method, device, equipment and storage medium for microservice
CN111078554A (en) Applet debugging method, device, equipment and storage medium
CN112596754A (en) Block chain intelligent contract deployment method and device
CN113553269A (en) Page buried point reporting method and related device
CN111444090B (en) Contract testing method and device in blockchain, electronic equipment and storage medium
CN111782551B (en) Test method and device for block chain item and computer equipment
CN106709281B (en) Patch granting and acquisition methods, device
CN112017007A (en) User behavior data processing method and device, computer equipment and storage medium
CN105678118B (en) A kind of software version generation method and device containing digital certificate
CN110727575B (en) Information processing method, system, device and storage medium
CN108008977B (en) Software development service platform oriented to function outsourcing
Strodl et al. Digital preservation of a process and its application to e-science experiments
CN109583192A (en) A kind of fixed safety system of mobile terminal application and method based on emulation
Singh et al. Demand based test case generation for object oriented system
CN113515269B (en) Application package processing method and device, computer equipment and storage medium
CN112150299B (en) Annuity data processing method, annuity data processing device, medium and electronic equipment
CN115563205A (en) Block chain system deployment method, device, medium and electronic equipment
Moebius et al. Model-driven code generation for secure smart card applications

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