CN115687064A - Intelligent contract testing method based on block chain and related equipment - Google Patents

Intelligent contract testing method based on block chain and related equipment Download PDF

Info

Publication number
CN115687064A
CN115687064A CN202110856321.1A CN202110856321A CN115687064A CN 115687064 A CN115687064 A CN 115687064A CN 202110856321 A CN202110856321 A CN 202110856321A CN 115687064 A CN115687064 A CN 115687064A
Authority
CN
China
Prior art keywords
contract
tested
test
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.)
Pending
Application number
CN202110856321.1A
Other languages
Chinese (zh)
Inventor
种衍雪
孔利
崔嘉辉
石巍
李茂材
付博
何畅
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tenpay Payment Technology Co Ltd
Original Assignee
Tenpay Payment Technology 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 Tenpay Payment Technology Co Ltd filed Critical Tenpay Payment Technology Co Ltd
Priority to CN202110856321.1A priority Critical patent/CN115687064A/en
Publication of CN115687064A publication Critical patent/CN115687064A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

The embodiment of the disclosure provides an intelligent contract testing method based on a block chain and related equipment. The method comprises the following steps: creating an automated testing framework for testing intelligent contracts; loading a test code of the intelligent contract to be tested through an automatic test framework; analyzing contract configuration information in the test code by using an automatic test framework to obtain a contract code; creating a virtual account for testing the intelligent contract to be tested through an automatic testing framework; deploying contract codes of intelligent contracts to be tested into a blockchain environment by utilizing an automatic testing framework; analyzing contract codes of the intelligent contracts to be tested into account objects and contract objects through an automatic testing framework, wherein the account objects comprise account addresses in the intelligent contracts to be tested; the automatic testing framework utilizes the virtual account and the account object in the process of executing the testing code, and calls a method in the contract code of the intelligent contract to be tested through the contract object to obtain a contract testing result of the intelligent contract to be tested.

Description

Intelligent contract testing method based on block chain and related equipment
Technical Field
The present disclosure relates to the field of block chain technologies, and in particular, to an intelligent contract testing method based on a block chain, an intelligent contract testing apparatus based on a block chain, an electronic device, and a computer-readable medium.
Background
The block chain is a multi-party common maintenance, transmission and access safety is guaranteed by using cryptography, a data consistent storage, tampering difficulty and repudiation prevention accounting technology can be realized, and the block chain is a distributed accounting book technology.
Smart contracts are computer protocols that are intended to propagate, validate, or execute contracts in an informational manner, allowing for viable transactions without third parties. Due to the complex diversity of the service scene, the intelligent contract needs to meet the turing completeness, so that an abnormal and complex service logic may exist, and testing the issued intelligent contract is an essential link in order to ensure the quality of the intelligent contract.
Under the intelligent contract code issuing scene, the problem of code coding irregularity exists. With the increase and large-scale development of intelligent contracts, security problems frequently occur, the problems are not solved, and economic losses are immeasurable. How to effectively manage and control an intelligent contract, ensure safe contract execution, avoid loopholes and the like is increasingly important. And the contract codes have the characteristics of being open and unchangeable in uploading, so that how to quickly audit, evaluate and repair the intelligent contract codes in the shortest time is more urgent.
In the related art, there are several ways to test smart contracts.
The first is unit testing of a contract program, the intelligent contract itself is a computer program, and some functions independent of the interface related to the blockchain can use the testing framework of the language itself to perform unit testing.
The second is based on the first test mode, and the interface function related to the block chain is piled, that is, false data is returned to simulate the block chain execution environment of the intelligent contract, so that the function of the intelligent contract itself can be tested to a certain extent.
However, the first and second intelligent contract test methods have limited functions, and only can effectively test the logic functions in the intelligent contract that are not related to the context of the block chain, and cannot test complex intelligent contract use scenarios.
Disclosure of Invention
The embodiment of the disclosure provides an intelligent contract testing method and device based on a block chain, an electronic device and a computer readable medium, so that the problem of intelligent contract testing in the block chain in the related art is solved at least to a certain extent.
The embodiment of the disclosure provides an intelligent contract testing method based on a block chain, which includes: creating an automated testing framework for testing intelligent contracts; loading a test code of the intelligent contract to be tested through an automatic test framework; analyzing contract configuration information in the test codes by using the automatic test framework to obtain contract codes of the intelligent contracts to be tested; creating a virtual account for testing the intelligent contract to be tested through the automatic testing framework; deploying contract codes of the intelligent contracts to be tested into a blockchain environment by utilizing the automatic testing framework; analyzing contract codes of the intelligent contracts to be tested into account objects and contract objects through the automatic testing framework, wherein the account objects comprise account addresses in the intelligent contracts to be tested; and the automatic testing framework utilizes the virtual account and the account object in the process of executing the testing code, and obtains a contract testing result of the intelligent contract to be tested by calling a method in the contract code of the intelligent contract to be tested through the contract object.
The embodiment of the present disclosure provides an intelligent contract testing apparatus based on a block chain, where the apparatus includes: the intelligent contract testing framework creating unit is used for creating an automatic testing framework for testing the intelligent contract; the test code loading unit is used for loading the test codes of the intelligent contract to be tested through the automatic test framework; the contract configuration analysis unit is used for analyzing the contract configuration information in the test codes by utilizing the automatic test framework to obtain the contract codes of the intelligent contracts to be tested; the virtual account creating unit is used for creating a virtual account for testing the intelligent contract to be tested through the automatic testing framework; the intelligent contract deployment unit is used for deploying contract codes of the intelligent contracts to be tested into a block chain environment by utilizing the automatic testing framework; the global object analyzing unit is used for analyzing the contract codes of the intelligent contracts to be tested into account objects and contract objects through the automatic testing framework, and the account objects comprise account addresses in the intelligent contracts to be tested; and the test code execution unit is used for acquiring a contract test result of the intelligent contract to be tested by utilizing the virtual account and the account object and calling a method in the contract code of the intelligent contract to be tested through the contract object in the process of executing the test code by the automatic test framework.
In some exemplary embodiments of the present disclosure, the apparatus further comprises: and the contract function packaging unit is used for packaging the account object and the contract object into a contract function through the automatic testing framework.
Wherein, the test code execution unit includes: and the contract method execution unit is used for calling a method in the contract code of the intelligent contract to be tested by utilizing the contract object in the contract function.
In some exemplary embodiments of the present disclosure, the apparatus further comprises: the interactive object instance construction unit is used for constructing an interactive object instance through a software development kit interface object of the automatic test framework; and the block chain interaction unit is used for interacting with the block chain by using the interaction object instance in the process of executing the test code by the automatic test framework.
In some exemplary embodiments of the present disclosure, the apparatus further comprises: the transaction object instantiation unit is used for instantiating a transaction object according to the transaction object format of the block chain if the test code comprises the transaction object; and the transaction pushing unit is used for pushing the transaction corresponding to the transaction object to the block chain through the interaction object instance.
In some exemplary embodiments of the present disclosure, the apparatus further comprises: and the block chain state snapshot unit is used for calling a block chain state snapshot interface in a real block chain environment through the automatic test framework to save the pre-test state of the block chain if the block chain environment is the real block chain environment before the automatic test framework executes the test code process.
The device further comprises: and the block chain snapshot recovery unit is used for calling a block chain state recovery interface in the real block chain environment through the automatic test framework after the automatic test framework executes the test code, and recovering the state of the block chain to the state before the test.
In some exemplary embodiments of the present disclosure, the apparatus further comprises: the virtual block chain creating unit is used for building a virtual block chain in the virtual block chain environment if the block chain environment is a virtual block chain environment before the contract code of the intelligent contract to be tested is deployed into the block chain environment by using the automatic testing framework, wherein the virtual block chain comprises a virtual node; the state data storage unit is used for storing the state and the data of the virtual block chain in a memory; the transaction execution unit is used for generating a block when the virtual block link receives a transaction and executing the transaction in the block; the execution engine providing unit is used for providing an execution engine for executing the intelligent contract to be tested; and the environment interface providing unit is used for providing the environment interfaces related to the block chains in the intelligent contract to be tested.
In some exemplary embodiments of the present disclosure, the apparatus further comprises: and the test framework integration unit is used for integrating the automatic test framework in an intelligent contract integrated development environment.
In some exemplary embodiments of the present disclosure, the apparatus further comprises: the first test file generating unit is used for responding to the selection and the triggering operation of the intelligent contract to be tested in a file browser of the intelligent contract integrated development environment and displaying a test file creating control; determining a test file name of the test file, a contract identifier of the intelligent contract to be tested and a contract file path in response to the input operation of the test file creation control, wherein the file type of the test file is the same as that of the intelligent contract to be tested; and creating the test file in a current directory where the intelligent contract to be tested is located or a specified test directory in a file manager of the intelligent contract integrated development environment so as to edit the test code in the test file.
In some exemplary embodiments of the present disclosure, the apparatus further comprises: the second test file generating unit is used for responding to the input operation of a file browser of the intelligent contract integrated development environment, determining the test file name of the test file and triggering a prompt control; responding to the selection operation of the prompt control, and determining a contract file path of the intelligent contract to be tested; responding to the input operation aiming at the test file, and determining a contract identification of the intelligent contract to be tested; and creating the test file in a current directory where the intelligent contract to be tested is located or a specified test directory in a file manager of the intelligent contract integrated development environment.
In some exemplary embodiments of the present disclosure, the apparatus further comprises: and the contract configuration code automatic generation unit is used for automatically generating contract configuration information in the test code through the automatic test framework, and the contract configuration information is used for associating the contract identification and the contract file path of the intelligent contract to be tested.
In some exemplary embodiments of the present disclosure, the test code execution unit includes: a target node information monitoring unit, configured to add a monitor in the process of running the test code through the intelligent contract integrated development environment, so as to monitor target node information in the process of executing the test code; and the contract test result counting unit is used for counting according to the target node information by the automatic test framework to obtain the contract test result.
Wherein the apparatus further comprises: and the contract test result display unit is used for displaying the contract test result through the intelligent contract integrated development environment.
An embodiment of the present disclosure provides an electronic device, including: at least one processor; storage means for storing at least one program which, when executed by the at least one processor, causes the at least one processor to implement the blockchain based intelligent contract testing method as described in the above embodiments.
The embodiment of the present disclosure provides a computer readable medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the intelligent contract testing method based on a block chain as described in the above embodiment.
According to an aspect of the application, a computer program product or computer program is provided, comprising computer instructions, the computer instructions being stored in a computer readable storage medium. The processor of the computer device reads the computer instructions from the computer-readable storage medium, and executes the computer instructions, so that the computer device executes the intelligent contract testing method based on the block chain provided in the above-mentioned various optional implementation modes.
In the technical scheme provided by some embodiments of the disclosure, an automated testing framework for testing an intelligent contract is constructed based on a block chain environment, so that the automated testing framework has a testing code loading function of an intelligent contract to be tested, a contract configuration information analysis function in a testing code, a function of creating a virtual account for testing the intelligent contract to be tested, a function of deploying a contract code of the intelligent contract to be tested into the block chain environment, a function of analyzing the contract code of the intelligent contract to be tested into an account object and a contract object, a function of automatically executing the testing code, and the like, thereby enabling a user to simply construct the testing code related to the intelligent contract to be tested, not needing to care about the complex interaction details of the intelligent contract to be tested and the block chain, improving the testing efficiency of the intelligent contract to be tested, further improving the development efficiency of the intelligent contract to be tested, and ensuring the quality and safety of the intelligent contract to be tested before being on line, and the like.
In other embodiments of the present disclosure, by integrating the automated testing framework into the intelligent contract integrated development environment, the user can simply, directly and quickly create, configure, execute, and view the contract testing result of the testing file and the testing code of the intelligent contract to be tested in the intelligent contract integrated development environment, thereby providing a set of complete intelligent contract testing modes, and flows.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and together with the description, serve to explain the principles of the disclosure. It is to be understood that the drawings in the following description are merely exemplary of the disclosure, and that other drawings may be derived from those drawings by one of ordinary skill in the art without the exercise of inventive faculty.
Fig. 1 is a schematic architecture diagram of a data processing system based on a blockchain according to an embodiment of the present disclosure.
Fig. 2 is a schematic diagram of a block chain network according to an embodiment of the disclosure.
Fig. 3 is a schematic structural diagram of a block according to an embodiment of the disclosure.
Fig. 4 is a schematic diagram of a new block generation process provided by an embodiment of the present disclosure.
FIG. 5 schematically shows a flowchart of a blockchain-based intelligent contract testing method according to one embodiment of the present disclosure.
FIG. 6 schematically illustrates a flow diagram of a blockchain-based intelligent contract testing method according to another embodiment of the present disclosure.
FIG. 7 schematically shows a flowchart for creating a test file according to one embodiment of the present disclosure.
FIG. 8 schematically illustrates a flow diagram of a blockchain-based intelligent contract testing method according to yet another embodiment of the present disclosure.
FIG. 9 schematically illustrates a block diagram of a blockchain-based intelligent contract testing apparatus, according to yet another embodiment of the present disclosure.
FIG. 10 shows a schematic diagram of an electronic device suitable for use in implementing embodiments of the present disclosure.
Detailed Description
Example embodiments will now be described more fully with reference to the accompanying drawings. Example embodiments may, however, be embodied in many different forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the concept of example embodiments to those skilled in the art.
Furthermore, the described features, structures, or characteristics may be combined in any suitable manner in one or more embodiments. In the following description, numerous specific details are provided to give a thorough understanding of embodiments of the disclosure. One skilled in the relevant art will recognize, however, that the subject matter of the present disclosure can be practiced without one or more of the specific details, or with other methods, components, devices, steps, and so forth. In other instances, well-known methods, devices, implementations, or operations have not been shown or described in detail to avoid obscuring aspects of the disclosure.
The block diagrams shown in the figures are functional entities only and do not necessarily correspond to physically separate entities. I.e. these functional entities may be implemented in the form of software, or in at least one hardware module or integrated circuit, or in different networks and/or processor means and/or microcontroller means.
The flow charts shown in the drawings are merely illustrative and do not necessarily include all of the contents and operations/steps, nor do they necessarily have to be performed in the order described. For example, some operations/steps may be decomposed, and some operations/steps may be combined or partially combined, so that the actual execution sequence may be changed according to the actual situation.
The block chain (block chain or block chain) related to the embodiment of the disclosure is a novel application mode of computer technologies such as distributed data storage, point-to-point (Peer-to-Peer, P2P) transmission, consensus mechanism, encryption algorithm and the like, is essentially a decentralized database, and is a string of data blocks generated by correlation using a cryptography method, wherein each data block contains information of a batch of network transactions, and is used for verifying the validity (anti-counterfeiting) of the information and generating the next block. The blockchain can comprise a blockchain bottom platform, a platform product service layer and an application service layer; the blockchain can be composed of a plurality of connected transaction records (also called blocks) which are connected in series by cryptography and protect the contents, and the distributed accounts connected in series by the blockchain can effectively record the transaction by multiple parties and can permanently check the transaction (can not be tampered). The consensus mechanism is a mathematical algorithm for establishing trust and obtaining rights and interests among different nodes in the block chain network, namely the consensus mechanism is a mathematical algorithm commonly recognized by all network nodes of the block chain.
As shown in fig. 1, the data processing system based on a blockchain according to the embodiment of the present disclosure may include a blockchain network 100 and a plurality of terminal devices, where fig. 1 takes three terminal devices as an example, which are a first terminal 201, a second terminal 202, and a third terminal 203. The first terminal 201, the second terminal 202, and the third terminal 203 may be configured to obtain transaction data (including a transaction request or transaction data generated after the transaction request is executed) from the blockchain network, or upload the transaction data to the blockchain network.
As shown in fig. 2, the blockchain network 100 in the embodiment of fig. 1 may include a plurality of node devices 101, the plurality of node devices 101 may refer to respective clients in the blockchain network, and the blockchain network 100 refers to a system for performing data sharing between the node devices 101 and the node devices 101. Each node device 101 may receive transaction data while operating normally and maintain shared data within the blockchain network 100 based on the received transaction data. In order to ensure information interworking in the blockchain network 100, there may be an information connection between each node device 101 in the blockchain network 100, and information transmission may be performed between the node devices 101 through the information connection. For example, when any node device 101 in the blockchain network 100 receives transaction data, other node devices 101 in the blockchain network 100 acquire the transaction data according to a consensus algorithm, and store the transaction data as data in shared data, so that the data stored on all node devices 101 in the blockchain network 100 are consistent.
The node device 101, the first terminal 201, the second terminal 202, and the third terminal 203 in the block chain network 100 may be any electronic devices, including but not limited to a mobile phone, a tablet computer, a notebook computer, a palm computer, a smart audio, a Mobile Internet Device (MID), a Point Of Sale (POS) device, and a wearable device (e.g., a smart watch, a smart bracelet, etc.); the system can also be an independent server, or a server cluster consisting of a plurality of servers, or a cloud computing center.
Each node device 101 in the blockchain network 100 has a node device identifier corresponding thereto, and each node device 101 in the blockchain network 100 may store the node device identifiers of other node devices 101 in the blockchain network 100, so that the generated block is broadcast to other node devices 101 in the blockchain network 100 according to the node device identifiers of other node devices 101 in the blockchain network 100. Each node device 101 may maintain a node device identifier list as shown in table 1 below, and store the node device name and the node device identifier in the node device identifier list correspondingly. The node device identifier may be an IP (Internet Protocol) address and any other information that can be used to identify the node device, and table 1 only illustrates the IP address as an example. Wherein N is a positive integer greater than or equal to 1.
TABLE 1
Node name Node identification
Node 1 117.114.151.174
Node 2 117.116.189.145
Node N 119.123.789.258
Each node apparatus 101 in the blockchain network 100 stores one identical blockchain. The block chain is composed of a plurality of blocks, each block comprises a cryptographic hash (represented by a hash value calculated by a merkel tree algorithm) of a previous block, a corresponding time stamp and transaction data, and the design is such that the contents of the block have the characteristic of being difficult to tamper with.
Referring to fig. 3, a block chain is composed of a plurality of blocks, a starting block includes a block header and a block main body, a transaction data feature value, a version number, a timestamp and a difficulty value are stored in the block header, and transaction data are stored in the block main body; the next block of the starting block takes the starting block as a parent block, the next block also comprises a block head and a block main body, the block head stores the transaction data characteristic value of the current block, the block head characteristic value of the parent block, the version number, the timestamp and the difficulty value, and the like, so that the block data stored in each block in the block chain is associated with the block data stored in the parent block, and the security of the transaction data in the blocks is ensured.
When each block in the block chain is generated, referring to fig. 4, when the node device where the block chain is located receives transaction data, the transaction data is verified, and after the verification is completed, the transaction data is stored in the memory pool, and the hash tree for recording the transaction data is updated; and then, updating the updating time stamp to the time when the transaction data is received, trying different random numbers, and calculating the characteristic value for multiple times, so that the calculated characteristic value can meet the following formula:
SHA256(SHA256(version+prev_hash+merkle_root+ntime+nbits+x))<TARGET (1)
wherein, SHA256 is a characteristic value algorithm used for calculating a characteristic value; version is version information of the relevant block protocol in the block chain; prev _ hash is a block head characteristic value of a parent block of the current block; merkle _ root is a characteristic value of the transaction data; ntime is the update time of the update timestamp; nbits is the current difficulty, is a fixed value within a period of time, and is determined again after exceeding a fixed time period; x is a random number; TARGET is a feature threshold, which can be determined from nbits.
Therefore, when the random number meeting the formula is obtained through calculation, the information can be correspondingly stored, and the block head and the block main body are generated to obtain the current block. Then, the node device where the blockchain is located sends the newly generated blocks to other node devices in the blockchain network 100 where the newly generated blocks are located respectively according to the node device identifiers of the other node devices in the blockchain network 100, the newly generated blocks are verified by the other node devices, and the newly generated blocks are added to the blockchain stored in the newly generated blocks after the verification is completed.
FIG. 5 schematically illustrates a flowchart of a blockchain-based intelligent contract testing method according to one embodiment of the present disclosure. The method provided in the embodiment of fig. 5 may be executed by any electronic device, for example, any terminal device in the first terminal 201, the second terminal 202, and the third terminal 203 in fig. 1.
As shown in fig. 5, the method provided by the embodiment of the present disclosure may include the following steps.
In step S510, an automated testing framework for testing smart contracts is created.
In the embodiment of the disclosure, an automated testing framework for testing an intelligent contract is created, so that the automated testing framework has a testing code loading function of an intelligent contract to be tested, a contract configuration information analysis function in a testing code, a function of creating a virtual account for testing the intelligent contract to be tested, a function of deploying the contract code of the intelligent contract to be tested into a block chain environment, a function of analyzing the contract code of the intelligent contract to be tested into an account object and a contract object, a function of automatically executing the testing code, and the like, and may further include other functions for realizing automatic testing of the intelligent contract.
In step S520, the test code of the intelligent contract to be tested is loaded through the automated testing framework.
In an exemplary embodiment, the method may further include: and integrating the automatic testing framework in an intelligent contract integrated development environment.
In the embodiment of the present disclosure, an intelligent contract Integrated Development Environment (IDE) is an application program for providing a program Development Environment, and may include tools such as a code editor, a compiler, a debugger, and a graphical user interface, which is hereinafter abbreviated as IDE.
The IDE employed by the embodiments of the present disclosure is a Visual IDE, such as an online intelligent contract IDE, a VS Code (Visual Studio Code) plug-in, and the like.
The automated testing framework in the embodiment of the disclosure is a tool for running tests, and tests can be added to the intelligent contract to be tested through the automated testing framework, so that the quality of contract codes of the intelligent contract to be tested is ensured.
In the embodiment of the disclosure, the user may use a programming language such as C + +, js, solidity, python, and the like to program the agreed terms into the intelligent contract to be tested, and when the terms are satisfied, the intelligent contract to be tested may be automatically executed by the blockchain system, for example, to execute a transaction. In the following description, js is used as an example for illustration, but the present disclosure is not limited thereto.
In the embodiment of the present disclosure, assuming that the contract code of the intelligent contract to be tested is written in js (short for javascript, which is a lightweight, interpreted, or just-in-time programming language with function priority), the automated testing framework may use js code testing framework mocha (mocha), chai, or the like, but the present disclosure is not limited thereto.
The mocha is a js code testing framework with rich functions, and can be operated in a browser environment or a node. By using the mocha, the user only needs to concentrate on writing the test code itself, and then let the mocha run all tests automatically and give contract test results.
In the embodiment of the disclosure, an automated testing framework is fused into an IDE environment, for example, a plug-in mechanism of VS Code may be adopted.
In the embodiment of the disclosure, the automatic testing framework is fused into the intelligent contract integrated development environment, so that a user can simply, directly and quickly create, configure and execute the testing file and the testing code of the intelligent contract to be tested in the intelligent contract integrated development environment and check the contract testing result, and a set of complete intelligent contract testing mode, mode and flow is provided.
In the embodiment of the disclosure, the intelligent contract to be tested can be any intelligent contract to be tested, and whether the intelligent contract has a problem or not is confirmed through testing.
The intelligent contract to be tested is a computer protocol which aims at propagating, verifying or executing the contract in an informatization mode, can execute the terms of a certain contract, is realized by codes which are deployed on a shared account and executed when certain conditions are met, is used for completing automatic transaction according to actual business requirement codes, such as inquiring the logistics state purchased by a buyer, and transferring the electronic resource of the buyer to the address of a merchant after the buyer signs goods; of course, the intelligent contracts to be tested are not limited to executing contracts for trading, but may also execute contracts that process received information. The smart contracts to be tested allow trusted transactions to be conducted without a third party, which transactions are traceable and irreversible.
The intelligent contracts to be tested on the blockchain are contracts which can be executed by transaction triggering on the blockchain. The intelligent contracts to be tested may be defined in the form of contract code.
Taking the ethernet as an example, the support user creates and invokes some complex logic in the ethernet network. The etherhouse serves as a programmable block chain, the core of the etherhouse is an Etherhouse Virtual Machine (EVM), and each etherhouse node can run the EVM. The EVM is a well-defined virtual machine through which various complex logic can be implemented. The issuing and calling of the intelligent contracts to be tested in the ethernet workshop by the user is performed on the EVM. In fact, EVM runs directly virtual machine code (virtual machine bytecode, abbreviated as "bytecode"), so the smart contract to be tested deployed on the blockchain can be bytecode.
In an exemplary embodiment, the method may further include: responding to the selection and the triggering operation of the intelligent contract to be tested in a file browser of the intelligent contract integrated development environment, and displaying a test file creation control; responding to the input operation of the test file creating control, and determining a test file name of the test file, a contract identifier of the intelligent contract to be tested and a contract file path, wherein the file type of the test file is the same as the file type of the intelligent contract to be tested; and creating the test file in a current directory where the intelligent contract to be tested is located or a specified test directory in a file manager of the intelligent contract integrated development environment so as to edit the test code in the test file.
In an exemplary embodiment, the method may further include: responding to the input operation of a file browser of the intelligent contract integrated development environment, and determining a test file name of the test file to trigger a prompt control; responding to the selection operation of the prompt control, and determining a contract file path of the intelligent contract to be tested; determining a contract identification of the intelligent contract to be tested in response to an input operation aiming at the test file; and creating the test file in a current directory where the intelligent contract to be tested is located or a specified test directory in a file manager of the intelligent contract integrated development environment.
In an exemplary embodiment, the method may further include: automatically generating, by the automated testing framework, contract configuration information in the testing code, the contract configuration information being used to associate a contract identifier and a contract file path of the intelligent contract to be tested.
In an intelligent contract integrated development environment of an integrated automation testing framework, a test file of an intelligent contract to be tested is created and contract identification information of the intelligent contract to be tested is determined.
In an exemplary embodiment, the contract identification information of the intelligent contract to be tested may include a contract Identification (ID) of the intelligent contract to be tested.
In the embodiment of the disclosure, the test file is a script for testing the contract code of the intelligent contract to be tested, the test file is the same as the contract code of the intelligent contract to be tested, if the file type of the intelligent contract to be tested is js, the file type of the test file is js, and the suffix name of the test file may be test.
In an exemplary embodiment, the contract identification information of the intelligent contracts to be tested comprises contract file paths and contract identifications of the intelligent contracts to be tested.
In step S530, the automated testing framework is used to analyze the contract configuration information in the testing code, and obtain the contract code of the intelligent contract to be tested.
In step S540, a virtual account for testing the intelligent contract to be tested is created through the automated testing framework.
In step S550, contract code of the intelligent contract to be tested is deployed into a blockchain environment by using the automated testing framework.
In step S560, the contract code of the intelligent contract to be tested is parsed into an account object and a contract object by the automated testing framework, wherein the account object includes an account address in the intelligent contract to be tested.
In an exemplary embodiment, the method may further include: encapsulating, by the automated testing framework, the account object and the contract object into a contract function.
The contract function comprises a contract identification and a callback function of the intelligent contract to be tested so as to represent that the contract function is a test case of the intelligent contract to be tested. The callback function may include an account object and the contract object, the account object may represent an account address array in a blockchain used by the contract function, and the test account in the blockchain may be included in the account address array. The contract object may be used to invoke a method in the contract code of the intelligent contract to be tested.
The intelligent contracts to be tested in the embodiment of the disclosure can comprise contract codes and data, for example, variables and methods in the contract codes (abbreviated as contract methods) can be included, and corresponding functions can be realized by executing the contract methods.
When the smart contract to be tested needs to be tested, a message may be sent to a blockchain environment or a blockchain node in a blockchain network (e.g., node device 101 in fig. 2). The message can carry an account address of a test account as a message sender and an account address of a test account as a message receiver, and the account address of the test account as the message receiver is an account address of the intelligent contract to be tested, which needs to be called, so as to indicate that the message is sent to the intelligent contract to be tested corresponding to the account address. The account address of the test account that is the sender of the message may be an external account address.
The account address in the etherhouse may include an external account address and a contract account address, among others. The external account address refers to an account address of the user, and the account address of the user can be obtained according to a private key of the user and is used for identifying the user. The contract account address is an account address of the intelligent contract to be tested for identifying the intelligent contract to be tested. The message may also carry test-related parameters, for example, may also carry contract execution parameters, so that the intelligent contract to be tested may be executed according to the contract execution parameters. The contract execution parameters are parameters which need to be input into the intelligent contracts to be tested when the intelligent contracts to be tested are tested, and the account addresses of the intelligent contracts to be tested are used for determining the tested intelligent contracts to be tested.
The contract execution parameters may be determined according to the type of intelligent contract to be tested. For example, if the intelligent contract to be tested includes a transfer method, the contract execution parameters may include the transfer amount. The contract execution parameters may include signature data if the smart contract to be tested includes a signature authentication method. The test result determining strategy is used for determining a contract test result of the intelligent contract to be tested. For example, when the contract execution parameter is the resource transfer amount, the test result determination policy may be: for the test account of the transferred resources, when the quantity of the resources before the transfer is equal to the quantity of the transferred resources plus the quantity of the transferred resources; and for the test account receiving the resources, when the quantity of the resources before the transfer is equal to the quantity of the resources after the transfer minus the quantity of the transferred resources, the test result is passed.
One intelligent contract to be tested may include one or more methods, such as a resource transfer method, a quantity calculation method, or a consensus method. One or more of contract execution parameters, account addresses of intelligent contracts to be tested, test result determination strategies or contract methods to be called are written, and the written parameters can be directly acquired for testing during execution. When the intelligent contract to be tested is executed, the intelligent contract to be tested can be loaded in the Etherhouse virtual machine to be executed. The Etherhouse virtual machine is the running environment of the intelligent contract to be tested. The code of the intelligent contract to be tested is byte code which can be operated in the EtherFang virtual machine after compiling. The intelligent contract to be tested comprises functions which can be called, namely contract methods, can execute all contract methods, and can also execute part of contract methods, for example, a message can carry a method identification of a method to be called, and the corresponding contract method is executed according to the method identification. The contract test result refers to a result obtained by executing a contract method of the intelligent contract to be tested. The test is executed in the block chain environment, so that the problems of the intelligent contract to be tested can be more accurately detected, and the test efficiency of the intelligent contract to be tested is improved.
In the embodiment of the present disclosure, one or more contract functions (contract functions) may be included in the test code, each contract function may include one or more it blocks, a contract function may be used to represent a group of related tests for the same intelligent contract to be tested, and is a function, a first argument may be a name of the intelligent contract to be tested (for example, assuming that the name of the intelligent contract to be tested is testHello, the name may be used as a contract ID of the intelligent contract to be tested), and a second argument may be an actually executed function, and in the embodiment of the present disclosure, may be a callback function. A callback function is a function passed as a parameter.
The it block may be called a test case, which represents an individual test, is the minimum unit of the test, and is also a function, where the first parameter is the name of the test case, and the second parameter is an actually executed function.
An example test code is as follows:
Figure BDA0003184281680000141
in an exemplary embodiment, the method may further include: and constructing an interactive object instance through a software development kit interface object of the automatic test framework.
In an exemplary embodiment, the method may further include: if the test code comprises a transaction object, instantiating the transaction object according to the transaction object format of the block chain; and pushing the transaction corresponding to the transaction object to the block chain through the interaction object instance.
In the embodiment of the present disclosure, the writing of the test code follows the test case writing method of an automated test framework, such as mocha, and at the same time, an intelligent contract framework may be used to package incoming related API (Application Programming Interface) functions and global objects, where the related API functions may include, for example, a contact function, a callback function, and the like, the global objects may include, for example, an account object, a contact object, a transaction object, and the like, and the related API functions and the global objects may be directly called in the test code without any introduction.
Wherein, the contact function represents a group of related test cases of the intelligent contract to be tested. The last parameter of the contact function may be a callback function, in which two parameters are defined: account objects and contact objects.
The accounts object represents an account address array in a block chain which can be used by a current test case, the contact object represents an intelligent contract object analyzed by an intelligent contract to be tested, the contact object can be directly used for calling a method/contract method in the intelligent contract to be tested without concern about interaction with the block chain, and a user can directly use two parameters, namely the accounts object and the contact object, in a test code to interact with the intelligent contract to be tested and the block chain.
An example is as follows, assuming that the name of the intelligent contract to be tested is testhi.
Figure BDA0003184281680000151
The test code for the test case corresponding to the testhi.js may be:
Figure BDA0003184281680000161
Figure BDA0003184281680000171
the test case (it block) contains one or more assertions. The assertion function is realized by an assertion library, and the mocha does not have the assertion library and can be introduced into the assertion library firstly. There are many types of assertion libraries, mocha does not limit which one is used. An assertion library that may also be introduced is, for example, chai and specifies the expect assertion style that uses it. If the expect assertion fails, an error is thrown. The test case passes if no errors are thrown. Js and browser, and can be integrated with any js test framework.
In the embodiment of the disclosure, the intelligent contract to be tested is actually a contract code to be executed on the block chain, and the contract code has a method, and executing the intelligent contract to be tested on the block chain is to make the block chain find the intelligent contract to be tested, and then call a certain method in the intelligent contract to be tested. The test code first needs to find the intelligent contract to be tested, see the example above, and uses the contract file path of the intelligent contract to be tested to search. When the test code calls the method in the intelligent contract to be tested, the intelligent contract to be tested is resolved into an object (namely a contact object in the test code) through an automatic test framework, the test code takes the object and can directly use the method in the object, and the automatic test framework converts the call of the test code to the contract method into the execution of the method of the intelligent contract to be tested in the block chain.
In the embodiment of the present disclosure, a related interface instance of a blockchain SDK (Software Development Kit) may also be used, so that interactions with the blockchain may also be processed in the test code at the same time. In particular, the automated test framework exposes an SDK interface object as an SDK interface object that interacts with the blockchain. In some complex situations, if the global object exposed by the current automated testing framework cannot be used, the SDK interface object can be directly used to interact with the blockchain.
For example:
Figure BDA0003184281680000181
in the disclosed embodiment, a transaction object represents a transaction in a blockchain to handle complex interactions.
Specifically, a transaction object tx may be instantiated according to a transaction object format required by the blockchain, and in the embodiment of the present disclosure, the format of the transaction object is not particularly limited, for example, a transaction is issued to b electronic resources, and specific fields are defined in tx. The transaction push is then pushed to the blockchain through the SDK interface object exposed above.
In an exemplary embodiment, before the automated test framework executes the test code process, the method may further comprise: if the block chain environment is a real block chain environment, calling a block chain state snapshot interface in the real block chain environment through the automatic test framework so as to save the pre-test state of the block chain.
In an exemplary embodiment, before deploying the contract code of the intelligent contract to be tested into a blockchain environment using the automated testing framework, the method may further include: if the block chain environment is a virtual block chain environment, constructing a virtual block chain in the virtual block chain environment, wherein the virtual block chain comprises a virtual node; storing the state and data of the virtual block chain in a memory; when the virtual block link receives a transaction, generating a block and executing the transaction in the block; providing an execution engine for executing the intelligent contract to be tested; and providing an environment interface related to the block chain in the intelligent contract to be tested.
In the embodiment of the present disclosure, the IDE may provide functions such as highlighting, automatic supplementation, parameter prompt, and the like for writing the test code, and may add an API function related to the test to the prompt configuration, and the specifically displayed prompt information may be determined according to an actual situation, which is not limited by the present disclosure.
In step S570, the automated testing framework obtains a contract testing result of the intelligent contract to be tested by using the virtual account and the account object and calling a method in the contract code of the intelligent contract to be tested through the contract object in the process of executing the testing code.
In an exemplary embodiment, invoking, with the contract object, a method in contract code of the intelligent contract to be tested may include: and calling a method in contract code of the intelligent contract to be tested by utilizing the contract object in the contract function. And the automatic test framework utilizes the interaction object instance to interact with the block chain in the process of executing the test code.
In an exemplary embodiment, after the automated test framework executes the test code, the method may further include: and calling a block chain state recovery interface in the real block chain environment through the automatic test framework, and recovering the state of the block chain to the state before the test.
In an exemplary embodiment, obtaining the contract test result of the intelligent contract to be tested may include: adding a monitor in the process of running the test code through the intelligent contract integrated development environment, wherein the monitor is used for monitoring target node information in the test code execution process; and the automatic testing framework obtains the contract testing result according to the target node information statistics.
For example, the intercepted target node information may include, but is not limited to: the test starting time in the test code executing process, the test starting time of each intelligent contract to be tested, the execution result of each test case of each intelligent contract to be tested, and the test ending time of each intelligent contract to be tested.
Statistically derived contract test results may include, but are not limited to: and counting according to the test starting time in the test code executing process, the test starting time of each intelligent contract to be tested, the execution result of each test case of each intelligent contract to be tested and the test ending time of each intelligent contract to be tested to obtain the total test case number, the total test time, the number of case cases successful in test, the number of case cases failed in test, the number of case cases blocked in test, the test time of each intelligent contract to be tested, the test case success number of each intelligent contract to be tested, the test case failure number of each intelligent contract to be tested, the test case blocking number of each intelligent contract to be tested, the time of each test case and the error information of each failed case to be used as the contract test result.
In an exemplary embodiment, the method may further include: and displaying the contract testing result through the intelligent contract integrated development environment.
In the embodiment of the present disclosure, a listener may be added in the process of test execution to monitor the following key nodes of test execution for data statistics:
when the whole test process starts, namely the test starting time in the test code execution process, if a plurality of intelligent contracts to be tested are executed in batch, the test codes correspondingly comprise a plurality of intelligent contracts;
when the execution of each test contract starts, namely the test starting time of each intelligent contract to be tested;
when each test case of the contract is successfully executed, the execution result of each test case of each intelligent contract to be tested may include success in execution, failure in execution, and execution blocking, where the execution result of each test case of each intelligent contract to be tested is the time of success in execution;
when each test case of the contract fails to execute, the execution result of each test case of each intelligent contract to be tested is the time of executing failure;
when each test case of the contract is blocked, the execution result of each test case of each intelligent contract to be tested is the time for executing the blockage;
when the execution of each test contract is finished, namely the test finishing time of each intelligent contract to be tested;
at the end of the entire testing process.
The statistical information available from the above nodes may include the following information:
the total number of test cases, namely the total number of test cases;
total test time, i.e. total test time;
the number of cases successfully tested;
the number of cases that failed the test;
testing the number of blocked cases;
when testing each contract, namely testing each intelligent contract to be tested;
the success number, the failure number and the blocking number of the test cases of each contract are respectively the success number of the test cases of each intelligent contract to be tested, the failure number of the test cases of each intelligent contract to be tested and the blocking number of the test cases of each intelligent contract to be tested;
the use time of each test case, namely the use time of each test case;
error information (such as stack) for each failed use case.
According to the statistical information, a contract test result is obtained, and a test report can be formed in an html (HyperText Markup Language) mode when the test execution is finished and is output to an independent window or area of the current IDE.
In the embodiment of the disclosure, after the test code is edited, the test file can be launched by right-clicking the test file in a file manager of the IDE, or adding a shortcut menu or a toolbar button in the IDE. The result of the run, i.e. the execution result of the test code, as the contract test result, can be shown in a separate window of the IDE, in the form of html page, the outline of the content is as follows:
testing code paths
Test code execution progress indication
Overview of test code operation results (number of test cases passed, number of test cases failed, total time)
[ detailed information ]
Test contract name [ test title ]
case1 results, name, and time of use (if too short of time of use, when not shown, click show case code)
case2 results, name, and time of use (if too short of time of use, when not shown, click show case code)
……
Test contract second name [ test title ]
case1 results, name, and time of use (if too short of time of use, when not shown, click show case code)
case2 result, name, and time of use (if too short of time of use, not show time of use, click can show case code)
……
……
The intelligent contract testing method based on the block chain provided by the embodiment of the disclosure is based on the block chain environment, and an automatic testing frame for testing the intelligent contract is constructed, so that the automatic testing frame has a testing code loading function of the intelligent contract to be tested, a contract configuration information analysis function in the testing code, a function of creating a virtual account for testing the intelligent contract to be tested, a function of deploying the contract code of the intelligent contract to be tested into the block chain environment, a function of analyzing the contract code of the intelligent contract to be tested into an account object and a contract object, a function of automatically executing the testing code, and the like, so that a user can simply construct the testing code related to the intelligent contract to be tested, does not need to care about the complex interaction details of the intelligent contract to be tested and the block chain, the testing efficiency of the intelligent contract to be tested is improved, the development efficiency of the intelligent contract to be tested can be improved, and the quality and the safety of the intelligent contract to be tested before being on line are guaranteed.
The method provided by the embodiment of the present disclosure is illustrated with reference to fig. 6 to 8.
Embodiments of the present disclosure may integrate automation test framework related functionality in a smart contract IDE, such as an online version of a Remix IDE, or a VS Code plug-in used to write a smart contract to be tested.
In the embodiment of the present disclosure, the running environment of the test code is a blockchain environment, which may include a real blockchain environment and a virtual blockchain environment. If the test is executed in the real block chain environment, the node of the block chain provides a block chain state snapshot interface and a block chain state recovery interface, so that the test execution does not affect the state of the current block chain, and the specific process is as shown in fig. 6 below.
FIG. 6 schematically illustrates a flow diagram of a blockchain-based intelligent contract testing method according to another embodiment of the present disclosure.
As shown in fig. 6, the method provided by the embodiment of the present disclosure may include the following steps.
In step S610, a snapshot of the block chain state is saved.
Namely, the block chain state snapshot interface is called to save the pre-test state of the block chain.
In step S620, a test case of the intelligent contract to be tested is run.
In step S630, the block chaining state is restored to the last snapshot.
And after executing the test code to obtain the contract test result, calling the block chain state recovery interface to recover the state of the block chain to the saved pre-test state.
In the embodiment of the present disclosure, the blockchain may be written in any language, for example js, where the blockchain is actually a distributed book, and is a set of states, before the test is performed, the state before the test is saved in the blockchain, that is, a snapshot of the current state of the blockchain is taken, and when the test is completed, the saved state before the test is restored to the state of the blockchain, that is, the state is restored.
If running in a virtual blockchain environment, before conducting testing of the intelligent contract to be tested, the virtual blockchain environment may be constructed as follows:
no consensus, only one virtual node;
all block chain states and data are stored in the memory;
when each transaction arrives, a block is immediately sent out, and the transaction is executed;
providing an execution engine for the intelligent contract to be tested;
and providing an environment interface related to the block chain in the intelligent contract to be tested.
In an embodiment of the present disclosure, constructing a virtual tile link environment may include: configuring an API (application programming interface) required by running of an intelligent contract to be tested; configuring a global account book state required by the running of the intelligent contract to be tested; the method comprises the steps of configuring block data required by running of the intelligent contracts to be tested (determining target blocks related to the running of the intelligent contracts to be tested in the real block chain network environment, generating simulation blocks corresponding to the target blocks, and simplifying the data of the simulation blocks into a key value pair form to be stored in a memory, wherein only block data related to the intelligent contracts to be tested currently are stored in the virtual block chain environment, all block data in the real block chain environment do not need to be acquired, and the workload of a user is reduced.
Specifically, the global account book state in the virtual block chain environment may be configured according to the current global account book state in the real block chain environment, and global account book state data in the real block chain environment is first acquired; and then, a local key-value pair database is created, the acquired global account book state data is stored in the local key-value pair database, the acquired global account book state data can be stored by configuring a redis key-value pair database, and the acquired global account book state data can also be stored in a map data structure mode in a memory. The method comprises the steps of determining basic frameworks of the real block chain environment supporting the intelligent contract to be tested to run by analyzing and decomposing the real block chain environment of the intelligent contract to be tested to run actually, simulating the functions of the basic frameworks, and building a virtual block chain environment capable of supporting the intelligent contract to be tested to run.
The basic framework supporting the intelligent contract to be tested to run can comprise: first, an Application Programming Interface (API) of a bottom layer block chain comprises fundamental interfaces such as invoker data writing, query data query, range query and the like; secondly, block blocks in the block chain network are connected in series in a chain form in a real block chain environment, are stored in a block chain file system and comprise all historical data and events occurring on the block chain network; thirdly, a global ledger state world state in the blockchain network, the global ledger state being used for storing the latest values of all key/value key-value pairs in the current blockchain network; fourthly, when the intelligent contract to be tested is called and triggered, corresponding trigger data are obtained. Because the data of the simulation blocks in the virtual block chain environment is stored in the form of key value pairs, when the data of the corresponding simulation blocks is called by the intelligent contract to be tested, the data needs to be converted into a block data format in the real block chain environment, so as to provide a uniform return interface for the upper-layer intelligent contract to be tested. Specifically, the data format conversion can be performed in a mode of simulating API piling when corresponding block data is called, so that the isolation of the intelligent contract to be tested and the underlying data structure in the virtual block chain environment is also realized.
During testing, the intelligent contract to be tested can be loaded to the virtual block chain environment; compiling the intelligent contract to be tested to obtain an executable file; executing the executable file to generate a service of the intelligent contract to be tested; the service is invoked and trigger data is provided to trigger the intelligent contract to be tested to run in a virtual blockchain environment. The virtual block chain environment is an operation environment obtained by simulating a real block chain environment in which the intelligent contract to be tested actually operates. The real block chain environment in which the intelligent contract to be tested actually runs refers to the real block chain environment in which the intelligent contract to be tested actually runs after being issued. The virtual blockchain environment may provide external dependency data, consistent underlying interfaces, and consistent trigger data that are consistent with the real blockchain environment, such that the intelligent contract to be tested can exhibit consistent behavioral logic when running in the virtual blockchain environment as it does when running in the real blockchain environment.
An executable file may be generated by compiling source code of contract code of the intelligent contract under test in a virtual blockchain environment. Specifically, a source code of the intelligent contract to be tested is stored in a class library unit (package) in a virtual block chain environment, and an executable file is obtained by compiling the source code of the intelligent contract to be tested in the corresponding class library unit. The executable file, after execution, may generate a service for triggering the execution of the intelligent contract to be tested. A plurality of intelligent contracts to be tested can be loaded into the virtual block chain environment, and are respectively stored in different class library units, and then the services are generated by jointly executing compilation. And providing different trigger data through the application program to trigger the service to call and run the intelligent contract to be tested corresponding to the corresponding trigger data. The service runs in the background of the virtual blockchain environment and waits to be triggered and invoked. The triggering and calling of the smart contract to be tested may be done by an application, and the virtual blockchain environment provides an access interface that is consistent with the real blockchain environment, for example, the access interface may be a Restful interface. Thus, an application can access the virtual blockchain environment as it does to the real blockchain network, invoking the service and providing trigger data to trigger the intelligent contract to be tested to run in the virtual blockchain environment. The provided trigger data is consistent with the trigger data of the intelligent contract to be tested when the intelligent contract runs in the real block chain environment, and when the intelligent contract is actually applied, the corresponding service can be called through an application program and the trigger data is provided.
The intelligent contracts to be tested run in the virtual block chain environment, the running state of the intelligent contracts to be tested can be checked at any time in the virtual block chain environment, and the debugging of the codes of the intelligent contracts to be tested can be conveniently and directly carried out. And interrupting the running of the intelligent contract to be tested at the specified breakpoint, and outputting the current running state information of the intelligent contract to be tested. The intelligent contracts to be tested running in the virtual block chain environment can specify a breakpoint at any time, and the running of the intelligent contracts is interrupted at the breakpoint, for example, when a user needs to check the state of a certain time point when a certain intelligent contract to be tested runs, the running of the intelligent contract to be tested can be interrupted by setting the breakpoint, and meanwhile, the virtual block chain environment can output the running state of the intelligent contract to be tested when the intelligent contract to be tested is interrupted, so that the intelligent contract can be used by the user. The virtual block chain environment is an operating environment separated from a real block chain environment, and can support the operation of the intelligent contract to be tested and also not influence a real block chain network, so that the operation of the intelligent contract to be tested can be interrupted at any time, the debugging of the code of the intelligent contract to be tested can be supported at any time, and the development and the testing of the intelligent contract to be tested are facilitated for a user.
The method and the device for testing the intelligent contracts can adopt js language as the development language of the testing codes of the intelligent contracts to be tested, adopt js code automatic testing frameworks mocha and chai to carry out secondary packaging, and mainly integrate functions related to block chains and contract functions with the js automatic testing frameworks.
Js, that is, a js file, which is a file of test codes of the smart contract to be tested, so that IDEs supporting js, such as VS Code, can be fully utilized. In addition, the file name rule defined in the way can conveniently identify the test code and the test file in the IDE and monitor the creating action of the test file in the current project in real time.
FIG. 7 schematically shows a flowchart for creating a test file according to one embodiment of the present disclosure. As shown in fig. 7, the method provided by the embodiment of the present disclosure may include the following steps.
In step S710, a test file is created in the IDE, and step S720 may be performed, or step S730 may be performed.
In step S720, the intelligent contract to be tested is selected in the IDE file browser, a right-click menu is created, and then step S750 is performed.
In the embodiment of the disclosure, two ways of creating and configuring test files are provided, one is that a certain intelligent contract file can be selected in a file browser of an IDE as an intelligent contract to be tested, a menu or a shortcut button is clicked to create a corresponding test file, and the test file can be created in a current directory where the intelligent contract to be tested is located or a certain specified test directory in a file manager, but cannot be renamed with the existing test file.
For example, in the VS Code file browser, a certain contract file, such as a js file, is right-clicked and determined as an intelligent contract to be tested, and then a menu appears, and an option 'create a contract test file' is added in the menu.
In step S730, a test file of the intelligent contract to be tested is directly created through the IDE menu command or button.
In step S740, a prompt is made to select a contract file path of the intelligent contract to be tested, and then step S750 is executed.
In step S750, the user inputs a test file name.
In step S760, the user inputs a contract deployment ID at test.
In another mode, the intelligent contract to be tested is not selected in the file browser of the IDE, a new test file is directly created, and after the test file is created, the contract file path of the intelligent to be tested is prompted to be selected and the contract ID of the intelligent to be tested to be deployed during testing is filled in.
For example, in a VS Code file browser, a test file is directly created, and the extension of the test file is the extension of the test file of the specified intelligent contract to be tested, for example, test.
In step S770, a contract configuration related code is automatically generated and written into the newly-created contract test file.
In the embodiment of the disclosure, a relevant code or comment may be automatically generated in the created test file to be used for associating the contract file path of the intelligent contract to be tested with the contract ID of the intelligent contract to be tested when the intelligent contract is deployed, so that the intelligent contract to be tested can be successfully found and deployed in the block chain during the execution of the test code, which is exemplified as follows.
Figure BDA0003184281680000261
Fig. 8 schematically shows the following steps performed by the test code execution engine.
In step S810, test code is loaded.
In step S820, the contract configuration in the test code, i.e., the configuration information generated in the test file for associating the contract file path of the intelligent contract to be tested with the contract identification, is parsed.
Step S820 may find the contract code of the intelligent contract to be tested by analyzing the configuration information in the test code.
In step S830, an interactive object instance with the blockchain is constructed.
In the disclosed embodiment, the blockchain has an interface exposed to the outside for sending transaction, query status, etc., and this interface object is stored for use as an object interaction instance.
In blockchain frameworks such as etherhouses or superridge fabrics, each function call needs to be handled by the means of initiating a transaction. Calling a specific function in the intelligent contract to be tested needs to submit a transaction, and the transaction can be regarded as an atomic operation. Several transactions are submitted to invoke several functions to achieve a specific purpose.
In the blockchain system, the calling of each function in the intelligent contract to be tested is realized by initiating a transaction. In each transaction, a from field is included, which represents the initiator of the transaction, and the transactions initiated by different users have different contents, and different users are simulated to access the same intelligent contract by setting different from fields in different test cases.
In step S840, a snapshot is taken of the block chain.
Reference may be made to the description of the embodiment of fig. 6 above.
In step S850, a blockchain account for test use is created.
In the disclosed embodiment, a database can be used in the blockchain to store accounts and the existing electronic resources of the accounts, and the account creation interface is exposed for creating the accounts and recharging.
In the embodiment of the present disclosure, the test account may also be referred to as a virtual account, and may be an account address in the blockchain, and may call an intelligent contract to be tested, execute a transaction, and the like, and according to an address format of the blockchain, N accounts may be created in the test for use as the test. The virtual account is an account used in the test, is created and recharged in the block chain snapshot, and is not used after the test is completed, so that the state of the block chain is not influenced.
All transactions in the blockchain require the consumption of gas (a type of electronic resource) and the account must have a corresponding balance to make the transaction.
In step S860, the smart contract to be tested is deployed in the blockchain.
In the embodiment of the disclosure, the intelligent contract to be tested is stored in the block chain, so that the intelligent contract can be called by any node device, and the contract ID, the contract code and the like of the intelligent contract can be stored by using the database.
Any of the intelligent contracts to be tested in the embodiments of the present disclosure may be deployed onto the blockchain network in the following manner, but the present disclosure is not limited thereto. After a user sends a transaction (transaction) containing the creation of the intelligent contract to be tested to the blockchain network, each node device can execute the transaction in the EVM. Wherein the From field in the transaction is used To record the address of the account From which the intelligent contract To be tested was initiated, the contract code held in the field value of the Data field of the transaction may be bytecode, and the field value of the To field of the transaction is a null account. After the nodes reach agreement through a consensus mechanism, the intelligent contract to be tested is successfully created, and a subsequent user can call the intelligent contract to be tested.
After each intelligent contract to be tested is established, a contract account corresponding to each intelligent contract to be tested appears on the block chain, and the block chain has a specific address. The contract Code (Code) will be saved in the account store (Storage) for the contract account. The behavior of the intelligent contract to be tested is controlled by the contract code, while the account storage of the intelligent contract to be tested preserves the state of the contract. That is, the intelligent contract to be tested causes a virtual account to be generated on the blockchain that contains the contract code and the account storage. A variety of members may be declared in a smart contract under test, including state variables, functions, function modifiers, events, and the like. A state variable is a value permanently stored in an account Storage (Storage) field of a smart contract to be tested, for saving the state of the smart contract to be tested.
In step S870, the contract is parsed into a contract object whose methods may be directly invoked.
In step S880, global objects such as account objects, contract objects, etc. are packaged in the automation test framework.
In the embodiment of the present disclosure, the accounts object and the extract object are objects that are already prepared by the automated testing framework, the testing code can be directly used, and the testing code is written in the extract function.
In the embodiment of the disclosure, functions in the intelligent contracts to be tested can be packaged, that is, the intelligent contracts to be tested are packaged into a class, and methods in the intelligent contracts to be tested are packaged into class examples, so that the test codes are convenient to use.
In step S890, contract test code is executed.
As shown in fig. 2, it is assumed that there are 4 node apparatuses 101 belonging to the same block chain. Each node device 101 may deploy an intelligent contract to be tested. When the intelligent contract to be tested needs to be tested, a test message is sent to the node device 101, the message carries the account address of the intelligent contract to be tested, and the node device 101 can execute the test code of the intelligent contract to be tested according to the message to obtain a contract test result. Since node devices 101 may broadcast messages, other individual node devices 101 may also execute test code for the intelligent contract to be tested. The node apparatuses 101 may be connected to each other via a network to perform consensus authentication.
In step S8100, a test execution result report is output.
The obtained contract test results can be displayed in a report form.
In step S8110, the block chain is restored to the snapshot state before the test execution.
Reference may be made to the description of the embodiment of fig. 6 above.
The intelligent contract testing method based on the block chain provided by the embodiment of the disclosure provides an automatic testing framework, a flow and a mode for carrying out code testing on an intelligent contract, so that an intelligent contract developer can quickly and simply carry out code testing on the intelligent contract. On one hand, the method and the device are based on a real block chain environment or a virtual block chain environment, fuse automatic testing frame technologies (such as js code testing frame mocha, chai and the like), add processes of snapshot and recovery of a block chain, deployment of an intelligent contract, creation and recharging of a virtual account, function encapsulation of the intelligent contract and the like in an automatic testing frame, write testing logics and scenes efficiently, hide details of interaction with the block chain, enable a user to simply build a testing case related to the intelligent contract, do not need to care about complex interaction details of the intelligent contract and the block chain, and execute the testing cases in batch and display contract testing results of the intelligent contract executed in the block chain; on the other hand, the automated testing framework is fused into a visual IDE environment, such as an online intelligent contract IDE, a VS Code plug-in and the like, so that a user can simply and directly create, configure, execute and view a test result of a contract test program in the IDE, and conveniently execute the test program and view the test execution result. The embodiment of the disclosure can be used for developing an ecological tool set and a testing tool set of the block chain intelligent contract, improving the development efficiency of the intelligent contract, and ensuring the quality, safety and the like of the contract before the contract is on line.
The following describes embodiments of a device according to the present disclosure, which can be used to execute the above-mentioned intelligent contract testing method based on block chains according to the present disclosure. For details not disclosed in the embodiments of the related apparatus of the present disclosure, please refer to the embodiments of the intelligent contract testing method based on block chains described above in the present disclosure.
FIG. 9 schematically illustrates a block diagram of a blockchain-based intelligent contract testing apparatus according to an embodiment of the present disclosure.
Referring to fig. 9, a block chain based intelligent contract testing apparatus 900 according to an embodiment of the present disclosure may include: an intelligent contract test framework creation unit 910, a test code loading unit 920, a contract configuration parsing unit 930, a virtual account creation unit 940, an intelligent contract deployment unit 950, a global object parsing unit 960, and a test code execution unit 970.
In the disclosed embodiment, the intelligent contract test framework creating unit 910 may be used to create an automated test framework for testing intelligent contracts. The test code loading unit 920 may be used to load test code of the intelligent contract to be tested through the automated testing framework. The contract configuration parsing unit 930 may be configured to parse the contract configuration information in the test code using the automated testing framework to obtain the contract code of the intelligent contract to be tested. The virtual account creation unit 940 may be configured to create a virtual account for testing the intelligent contract to be tested by the automated testing framework. The intelligent contract deployment unit 950 may be configured to deploy contract code for the intelligent contract to be tested into a blockchain environment using the automated testing framework. The global object parsing unit 960 may be configured to parse, by the automated testing framework, contract codes of the intelligent contracts to be tested into account objects and contract objects, where the account objects include account addresses in the intelligent contracts to be tested. The test code execution unit 970 may be configured to, during the execution of the test code, utilize the virtual account and the account object, and call, by the contract object, a method in the contract code of the intelligent contract to be tested, so as to obtain a contract test result of the intelligent contract to be tested.
In an exemplary embodiment, the blockchain-based intelligent contract testing apparatus 900 may further include: a contract function encapsulation unit that may be used to encapsulate the account object and the contract object into a contract function through the automated testing framework.
The test code execution unit 970 may include: a contract method execution unit operable to invoke a method in contract code of the intelligent contract to be tested using the contract object in the contract function.
In an exemplary embodiment, the intelligent contract testing apparatus 900 based on block chains may further include: the interactive object instance construction unit can be used for constructing an interactive object instance through a software development kit interface object of the automatic test framework; and the block chain interaction unit can be used for the automated test framework to interact with the block chain by using the interaction object instance in the process of executing the test code.
In an exemplary embodiment, the blockchain-based intelligent contract testing apparatus 900 may further include: the transaction object instantiation unit can be used for instantiating a transaction object according to the transaction object format of the block chain if the test code comprises the transaction object; and the transaction pushing unit can be used for pushing the transaction corresponding to the transaction object to the block chain through the interaction object instance.
In an exemplary embodiment, the blockchain-based intelligent contract testing apparatus 900 may further include: the block chain state snapshot unit may be configured to, before the automated test framework executes the test code process, call, by the automated test framework, a block chain state snapshot interface in the real block chain environment if the block chain environment is the real block chain environment, so as to save a pre-test state of the block chain.
The intelligent contract testing apparatus 900 based on block chains may further include: and the block chain snapshot recovery unit may be configured to, after the automated test framework executes the test code, call a block chain state recovery interface in the real block chain environment through the automated test framework, and recover the state of the block chain to the pre-test state.
In an exemplary embodiment, the blockchain-based intelligent contract testing apparatus 900 may further include: the virtual block chain creating unit may be configured to, before deploying the contract code of the intelligent contract to be tested into a block chain environment by using the automated testing framework, if the block chain environment is a virtual block chain environment, construct a virtual block chain in the virtual block chain environment, where the virtual block chain includes one virtual node; the state data storage unit may be configured to store the state and data of the virtual block chain in a memory; a transaction execution unit, which may be configured to generate a tile when the virtual tile link receives a transaction, and execute the transaction in the tile; the execution engine providing unit can be used for providing an execution engine for executing the intelligent contract to be tested; and the environment interface providing unit can be used for providing the environment interface related to the block chain in the intelligent contract to be tested.
In an exemplary embodiment, the blockchain-based intelligent contract testing apparatus 900 may further include: and the test framework integration unit is used for integrating the automatic test framework in an intelligent contract integrated development environment.
In an exemplary embodiment, the blockchain-based intelligent contract testing apparatus 900 may further include: the first test file generation unit may be configured to respond to selection and trigger operation of the intelligent contract to be tested in a file browser of the intelligent contract integrated development environment, and display a test file creation control; determining a test file name of the test file, a contract identifier of the intelligent contract to be tested and a contract file path in response to the input operation of the test file creation control, wherein the file type of the test file is the same as that of the intelligent contract to be tested; and creating the test file in a current directory where the intelligent contract to be tested is located or a specified test directory in a file manager of the intelligent contract integrated development environment so as to edit the test code in the test file.
In an exemplary embodiment, the intelligent contract testing apparatus 900 based on block chains may further include: the second test file generating unit may be configured to determine a test file name of the test file in response to an input operation to a file browser of the intelligent contract integrated development environment, so as to trigger a prompt control; responding to the selection operation of the prompt control, and determining a contract file path of the intelligent contract to be tested; responding to the input operation aiming at the test file, and determining a contract identification of the intelligent contract to be tested; and creating the test file in a current directory where the intelligent contract to be tested is located or a specified test directory in a file manager of the intelligent contract integrated development environment.
In an exemplary embodiment, the blockchain-based intelligent contract testing apparatus 900 may further include: and the contract configuration code automatic generation unit can be used for automatically generating contract configuration information in the test code through the automatic test framework, wherein the contract configuration information is used for associating the contract identification and the contract file path of the intelligent contract to be tested.
In an exemplary embodiment, the test code execution unit 970 may include: a target node information monitoring unit, configured to add a monitor in the process of running the test code through the intelligent contract integrated development environment, so as to monitor target node information in the process of executing the test code; and the contract test result counting unit can be used for the automatic test framework to obtain the contract test result according to the target node information statistics.
The intelligent contract testing apparatus 900 based on the blockchain may further include: and the contract test result display unit can be used for displaying the contract test result through the intelligent contract integrated development environment.
The intelligent contract testing device based on the block chain, provided by the embodiment of the disclosure, is based on the block chain environment, and is used for constructing an automatic testing frame for testing an intelligent contract, so that the automatic testing frame has a testing code loading function of the intelligent contract to be tested, a contract configuration information analysis function in a testing code, a function of creating a virtual account for testing the intelligent contract to be tested, a function of deploying the contract code of the intelligent contract to be tested into the block chain environment, a function of analyzing the contract code of the intelligent contract to be tested into an account object and a contract object, a function of automatically executing the testing code and the like, so that a user can simply construct the testing code related to the intelligent contract to be tested, does not need to care about complex interaction details of the intelligent contract to be tested and the block chain, the testing efficiency of the intelligent contract to be tested is improved, the development efficiency of the intelligent contract to be tested can be improved, and the quality and the safety of the intelligent contract to be tested before being on line are guaranteed.
FIG. 10 shows a schematic diagram of an electronic device suitable for use in implementing embodiments of the present disclosure. It should be noted that the electronic device 1000 shown in fig. 10 is only an example, and should not bring any limitation to the functions and the application scope of the embodiment of the present disclosure.
As shown in fig. 10, the electronic apparatus 1000 includes a Central Processing Unit (CPU) 1001 that can perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM) 1002 or a program loaded from a storage section 1008 into a Random Access Memory (RAM) 1003. In the RAM 1003, various programs and data necessary for system operation are also stored. The CPU 1001, ROM 1002, and RAM 1003 are connected to each other by a bus 1004. An input/output (I/O) interface 1005 is also connected to bus 1004.
The following components are connected to the I/O interface 1005: an input section 1006 including a keyboard, a mouse, and the like; an output portion 1007 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage portion 1008 including a hard disk and the like; and a communication section 1009 including a network interface card such as a LAN card, a modem, or the like. The communication section 1009 performs communication processing via a network such as the internet. A drive 1010 is also connected to the I/O interface 1005 as necessary. A removable medium 1011 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 1010 as necessary, so that a computer program read out therefrom is mounted into the storage section 1008 as necessary.
In particular, the processes described below with reference to the flowcharts may be implemented as computer software programs, according to embodiments of the present disclosure. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer-readable medium, the computer program comprising program code for performing the method illustrated by the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication part 1009 and/or installed from the removable medium 1011. When the computer program is executed by a Central Processing Unit (CPU) 1001, various functions defined in the system of the present application are executed.
It should be noted that the computer readable media shown in the present disclosure may be computer readable signal media or computer readable storage media or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having at least one wire, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In contrast, in the present disclosure, a computer-readable signal medium may include a propagated data signal with computer-readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises at least one executable instruction for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules and/or units and/or sub-units described in the embodiments of the present disclosure may be implemented by software, or may be implemented by hardware, and the described modules and/or units and/or sub-units may also be disposed in a processor. Wherein the names of such modules and/or units and/or sub-units in some cases do not constitute a limitation on the modules and/or units and/or sub-units themselves.
As another aspect, the present application also provides a computer-readable medium, which may be contained in the electronic device described in the above embodiment; or may exist separately without being assembled into the electronic device. The computer readable medium carries one or more programs which, when executed by an electronic device, cause the electronic device to implement the method as described in the embodiments below. For example, the electronic device may implement the steps shown in fig. 5 or fig. 6 or fig. 7 or fig. 8.
It should be noted that although in the above detailed description several modules or units or sub-units of the device for action execution are mentioned, such a division is not mandatory. Indeed, the features and functions of two or more modules or units or sub-units described above may be embodied in one module or unit or sub-unit, according to embodiments of the present disclosure. Conversely, the features and functions of one module or unit described above may be further divided into embodiments by a plurality of modules or units or sub-units.
Through the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein may be implemented by software, and may also be implemented by software in combination with necessary hardware. Therefore, the technical solution according to the embodiments of the present disclosure may be embodied in the form of a software product, which may be stored in a non-volatile storage medium (which may be a CD-ROM, a usb disk, a removable hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which may be a personal computer, a server, a touch terminal, or a network device, etc.) to execute the method according to the embodiments of the present disclosure.

Claims (14)

1. An intelligent contract testing method based on a block chain is characterized by comprising the following steps:
creating an automated testing framework for testing intelligent contracts;
loading a test code of the intelligent contract to be tested through the automatic test framework;
analyzing contract configuration information in the test codes by using the automatic test framework to obtain contract codes of the intelligent contracts to be tested;
creating a virtual account for testing the intelligent contract to be tested through the automatic testing framework;
deploying contract codes of the intelligent contracts to be tested into a blockchain environment by utilizing the automatic testing framework;
analyzing contract codes of the intelligent contracts to be tested into account objects and contract objects through the automatic testing framework, wherein the account objects comprise account addresses in the intelligent contracts to be tested;
and the automatic testing framework utilizes the virtual account and the account object in the process of executing the testing code, and obtains a contract testing result of the intelligent contract to be tested by calling a method in the contract code of the intelligent contract to be tested through the contract object.
2. The method of claim 1, further comprising:
packaging, by the automated testing framework, the account object and the contract object into a contract function;
the method for calling the contract code of the intelligent contract to be tested by using the contract object comprises the following steps:
and calling a method in contract code of the intelligent contract to be tested by utilizing the contract object in the contract function.
3. The method of claim 1, further comprising:
constructing an interactive object example through a software development kit interface object of the automatic test framework;
and the automatic test framework utilizes the interaction object instance to interact with the block chain in the process of executing the test code.
4. The method of claim 3, further comprising:
if the test code comprises a transaction object, instantiating the transaction object according to the transaction object format of the block chain;
and pushing the transaction corresponding to the transaction object to the block chain through the interaction object instance.
5. The method of claim 1, wherein the automated test framework, prior to executing the test code process, further comprises:
if the block chain environment is a real block chain environment, calling a block chain state snapshot interface in the real block chain environment through the automatic test framework to save a pre-test state of the block chain;
after the automated test framework executes the test code, the method further comprises:
and calling a block chain state recovery interface in the real block chain environment through the automatic test framework to recover the state of the block chain to the state before test.
6. The method of claim 1, wherein prior to deploying contract code for the intelligent contract to be tested into a blockchain environment with the automated testing framework, the method further comprises:
if the block chain environment is a virtual block chain environment, constructing a virtual block chain in the virtual block chain environment, wherein the virtual block chain comprises a virtual node;
storing the state and data of the virtual block chain in a memory;
when the virtual tile link receives a transaction, generating a tile and executing the transaction in the tile;
providing an execution engine for executing the intelligent contract to be tested;
and providing an environment interface related to the block chain in the intelligent contract to be tested.
7. The method of claim 1, further comprising:
and integrating the automatic testing framework in an intelligent contract integrated development environment.
8. The method of claim 7, further comprising:
responding to the selection and triggering operation of the intelligent contract to be tested in a file browser of the intelligent contract integrated development environment, and displaying a test file creating control;
responding to the input operation of the test file creating control, and determining a test file name of the test file, a contract identifier of the intelligent contract to be tested and a contract file path, wherein the file type of the test file is the same as the file type of the intelligent contract to be tested;
and creating the test file in a current directory where the intelligent contract to be tested is located or a specified test directory in a file manager of the intelligent contract integrated development environment so as to edit the test code in the test file.
9. The method of claim 7, further comprising:
responding to the input operation of a file browser of the intelligent contract integrated development environment, and determining a test file name of the test file to trigger a prompt control;
responding to the selection operation of the prompt control, and determining a contract file path of the intelligent contract to be tested;
responding to the input operation aiming at the test file, and determining a contract identification of the intelligent contract to be tested;
and creating the test file in a current directory where the intelligent contract to be tested is located or a specified test directory in a file manager of the intelligent contract integrated development environment.
10. The method of claim 8 or 9, further comprising:
automatically generating contract configuration information in the test code through the automatic test framework, wherein the contract configuration information is used for associating contract identification and a contract file path of the intelligent contract to be tested.
11. The method of claim 7, wherein obtaining contract test results for the intelligent contracts to be tested comprises:
adding a monitor in the process of running the test code through the intelligent contract integrated development environment to monitor the target node information in the test code execution process;
the automatic testing framework obtains the contract testing result according to the target node information statistics;
wherein the method further comprises:
and displaying the contract testing result through the intelligent contract integrated development environment.
12. An intelligent contract testing device based on a block chain is characterized by comprising:
the intelligent contract testing framework creating unit is used for creating an automatic testing framework for testing the intelligent contract;
the test code loading unit is used for loading the test codes of the intelligent contracts to be tested through the automatic test framework;
the contract configuration analysis unit is used for analyzing the contract configuration information in the test codes by using the automatic test framework to obtain the contract codes of the intelligent contracts to be tested;
the virtual account creating unit is used for creating a virtual account for testing the intelligent contract to be tested through the automatic testing framework;
the intelligent contract deployment unit is used for deploying contract codes of the intelligent contracts to be tested into a block chain environment by utilizing the automatic testing framework;
the global object analysis unit is used for analyzing the contract codes of the intelligent contracts to be tested into account objects and contract objects through the automatic testing framework, and the account objects comprise account addresses in the intelligent contracts to be tested;
and the test code execution unit is used for acquiring a contract test result of the intelligent contract to be tested by utilizing the virtual account and the account object and calling a method in the contract code of the intelligent contract to be tested through the contract object in the process of executing the test code by the automatic test framework.
13. An electronic device, comprising:
at least one processor;
storage means for storing at least one program;
when executed by the at least one processor, cause the at least one processor to implement the method of any one of claims 1-11.
14. A computer-readable medium, on which a computer program is stored, which program, when being executed by a processor, is adapted to carry out the method of any one of claims 1-11.
CN202110856321.1A 2021-07-28 2021-07-28 Intelligent contract testing method based on block chain and related equipment Pending CN115687064A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110856321.1A CN115687064A (en) 2021-07-28 2021-07-28 Intelligent contract testing method based on block chain and related equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110856321.1A CN115687064A (en) 2021-07-28 2021-07-28 Intelligent contract testing method based on block chain and related equipment

Publications (1)

Publication Number Publication Date
CN115687064A true CN115687064A (en) 2023-02-03

Family

ID=85058692

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110856321.1A Pending CN115687064A (en) 2021-07-28 2021-07-28 Intelligent contract testing method based on block chain and related equipment

Country Status (1)

Country Link
CN (1) CN115687064A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117061403A (en) * 2023-10-10 2023-11-14 中铱数字科技有限公司 Automatic testing method and system based on blockchain BaaS

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117061403A (en) * 2023-10-10 2023-11-14 中铱数字科技有限公司 Automatic testing method and system based on blockchain BaaS

Similar Documents

Publication Publication Date Title
WO2019072110A1 (en) Method for generating application program, apparatus, system, device, and medium
Vivar et al. A security framework for Ethereum smart contracts
CN116155771A (en) Network anomaly test method, device, equipment, storage medium and program
CN111949531B (en) Block chain network testing method, device, medium and electronic equipment
Mahmud et al. Android compatibility issue detection using api differences
US11816479B2 (en) System and method for implementing a code audit tool
CN113590454A (en) Test method, test device, computer equipment and storage medium
Mahmood et al. A framework for automated API fuzzing at enterprise scale
CN115687064A (en) Intelligent contract testing method based on block chain and related equipment
CN114116509A (en) Program analysis method, program analysis device, electronic device, and storage medium
CN110598419A (en) Block chain client vulnerability mining method, device, equipment and storage medium
US10310962B2 (en) Infrastructure rule generation
CN113778897A (en) Automatic test method, device, equipment and storage medium of interface
CN111917729B (en) Dynamic injection test method and device and related equipment
US11368554B2 (en) Systems and methods for regulating service behavior
US20230359746A1 (en) Systems and methods for shift left testing
CN113590465A (en) Method for automatically generating mock service based on SDK
US10606569B2 (en) Declarative configuration elements
CN114840410A (en) Test analysis method and device, computer equipment and storage medium
CN116795701A (en) Method and device for generating universal test case of interface program
Virani et al. A Systematic Literature Review on Smart Contracts Security
Mazuera-Rozo et al. Detecting connectivity issues in android apps
CN116521509A (en) Intelligent contract testing method, device, equipment, storage medium and product
Varghese et al. Can commercial testing automation tools work for iot? A case study of selenium and node-red
Endo Model based testing of service oriented 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: 40080490

Country of ref document: HK

SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination