[go: up one dir, main page]

CN112202647B - Test method, device and test equipment in block chain network - Google Patents

Test method, device and test equipment in block chain network Download PDF

Info

Publication number
CN112202647B
CN112202647B CN202011429270.6A CN202011429270A CN112202647B CN 112202647 B CN112202647 B CN 112202647B CN 202011429270 A CN202011429270 A CN 202011429270A CN 112202647 B CN112202647 B CN 112202647B
Authority
CN
China
Prior art keywords
code
node
block chain
blockchain
nodes
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202011429270.6A
Other languages
Chinese (zh)
Other versions
CN112202647A (en
Inventor
陈金龙
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN202011429270.6A priority Critical patent/CN112202647B/en
Publication of CN112202647A publication Critical patent/CN112202647A/en
Application granted granted Critical
Publication of CN112202647B publication Critical patent/CN112202647B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L43/00Arrangements for monitoring or testing data switching networks
    • H04L43/50Testing arrangements
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L9/00Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
    • H04L9/50Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols using hash chains, e.g. blockchains or hash trees

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Debugging And Monitoring (AREA)
  • Financial Or Insurance-Related Operations Such As Payment And Settlement (AREA)

Abstract

The embodiment of the invention discloses a test method, a test device and test equipment in a block chain network, wherein the test method comprises the following steps: in the process of testing the block chain service based on the test case set, when a code coverage information collection event exists, acquiring code coverage information corresponding to each node in M nodes at the current moment; and determining the joint code coverage rate of the block chain network at the current moment according to the code coverage information corresponding to each node in the M nodes, and carrying out test management on the block chain service based on the joint code coverage rate. The embodiment of the invention can improve the completeness and the convenience of the block chain service test in the block chain network.

Description

Test method, device and test equipment in block chain network
Technical Field
The present application relates to the field of block chain technologies, and in particular, to a test method, an apparatus, and a test device in a block chain network.
Background
The block chain is a multi-party common maintenance, transmission and access safety is guaranteed by using cryptography, and a data consistent storage, difficult tampering and repudiation prevention accounting technology, namely a distributed accounting book technology, can be realized. Recent research has shown that blockchains may become an underlying technology for internet applications in the next few years, and may be applied to various projects in various industries, such as commodity tracing.
When blockchains are applied in different industries, corresponding blockchain products or corresponding blockchain items (the blockchain products and the blockchain items can be collectively referred to as blockchain services) need to be developed based on blockchain technology, and corresponding blockchain networks need to be deployed. In order to ensure that the blockchain can better provide services for the user, the blockchain products or blockchain items need to be tested in the blockchain network before being put into use in the blockchain network. Therefore, in the field of blockchain technology, how to perform blockchain service testing is a major concern today.
Disclosure of Invention
The embodiment of the invention provides a testing method, a testing device and testing equipment in a block chain network, which can improve the completeness and convenience of a block chain service test in the block chain network.
In one aspect, an embodiment of the present invention provides a method for testing a block chain network, where the block chain network includes M nodes, and M is an integer greater than 1; each node is provided with a blockchain code used for providing blockchain service, and the blockchain code comprises an stub code, and the method comprises the following steps:
in the process of testing the block chain service based on the test case set, when a code coverage information collection event exists, acquiring code coverage information corresponding to each node in the M nodes at the current moment; the code coverage information corresponding to the node M is collected by the node M through running the stub code contained in the block chain code deployed in the node M, and M is greater than or equal to 1 and less than or equal to M;
and determining the joint code coverage rate of the block chain network at the current moment according to the code coverage information corresponding to each node in the M nodes, and carrying out test management on the block chain service based on the joint code coverage rate.
In one aspect, an embodiment of the present invention provides a testing apparatus in a blockchain network, where the blockchain network includes M nodes, where M is an integer greater than 1; each node is provided with a block chain code used for providing block chain service, and the block chain code comprises an stub code, and the device comprises:
an obtaining unit, configured to obtain, when a code coverage information collection event exists in a process of testing the block chain service based on a test case set, code coverage information corresponding to each node in the M nodes at a current time; the code coverage information corresponding to the node M is collected by the node M through running the stub code contained in the block chain code deployed in the node M, and M is greater than or equal to 1 and less than or equal to M;
and the processing unit is used for determining the joint code coverage rate of the block chain network at the current moment according to the code coverage rate information corresponding to each node in the M nodes, and carrying out test management on the block chain service based on the joint code coverage rate.
In one embodiment, the blockchain code comprises at least one code module, and the corresponding code coverage information of each node comprises the code module which is deployed in each node and is executed by the blockchain code; when determining the joint code coverage rate of the block chain network at the current moment according to the code coverage information corresponding to each node in the M nodes, the processing unit executes the following steps:
performing union operation on the code modules of the block chain codes deployed in the nodes, wherein the block chain codes are operated, so as to obtain the code modules of the block chain codes operated in the block chain network; determining a joint code coverage rate of the blockchain network at a current time based on the total number of the at least one code module and a first number of code modules in the blockchain network for which the blockchain code has been executed.
In one embodiment, the code coverage information collection event refers to receiving a code instruction for triggering coverage information collection; or, the code coverage information collection event refers to detection of completion of execution of any one test case in the test case set.
In one embodiment, the test apparatus further comprises a display unit for: if a code instruction for checking the code coverage rate in the node n is detected, displaying the code coverage rate in the node n, wherein n is more than or equal to 1 and less than or equal to M; the code coverage in the node n is determined based on the number of code modules of the blockchain code deployed in the node n that have been run and the total number of at least one code module included in the blockchain code.
In an embodiment, the processing unit is configured to generate a coverage report corresponding to the blockchain network according to the joint code coverage, where the coverage report includes marked blockchain codes, code contents of code modules that have been executed in the marked blockchain codes are marked in a first form, and code contents of code modules that have not been executed in the marked blockchain codes are marked in a second form.
In one embodiment, the code coverage information collection event refers to receiving a code instruction for triggering coverage information collection, and the code instruction is received when the target test case in the test case set is executed; or, the code coverage information collection event refers to detecting that the target test case is executed;
the processing unit is further configured to: establishing a corresponding relation between the target test case and a code module in the block chain network, wherein the block chain code is operated; and optimizing the target test case according to the corresponding relation so that the number of code modules of the block chain code which is operated in the block chain network is greater than the first number when the optimized target test user tests the block chain service.
In one embodiment, the testing apparatus further includes a storage unit, where the storage unit is configured to store the correspondence relationship into a reference information set used for constructing test cases, where the reference information set includes correspondence relationships between groups of test cases and code modules in the blockchain network where the blockchain code has been executed;
the processing unit is further configured to construct a new test case based on the reference information set, so that when the blockchain service is tested based on the new test case, a target code module in the blockchain code in the blockchain network is run.
In one embodiment, the obtaining unit is further configured to: acquiring node attribute information corresponding to each node in the M nodes; the processing unit is further configured to deploy the block chain code carrying the stub code in each node according to the node attribute information corresponding to each node.
In one embodiment, when the processing unit performs test management on the blockchain service based on the joint code coverage, the processing unit performs the following steps: and if the combined code coverage rate is greater than or equal to a code coverage rate threshold value, determining that the block chain service test is completed, and stopping the block chain service test.
In one aspect, an embodiment of the present invention provides a test apparatus, which includes: a processor adapted to implement one or more computer programs; and a computer storage medium storing one or more computer programs adapted to be loaded and executed by the processor to:
in the process of testing the block chain service based on the test case set, when a code coverage information collection event exists, acquiring code coverage information corresponding to each node in the M nodes at the current moment; the code coverage information corresponding to the node M is collected by the node M through running the stub code contained in the block chain code deployed in the node M, and M is greater than or equal to 1 and less than or equal to M;
and determining the joint code coverage rate of the block chain network at the current moment according to the code coverage information corresponding to each node in the M nodes, and carrying out test management on the block chain service based on the joint code coverage rate.
In one aspect, an embodiment of the present invention provides a computer storage medium, where a computer program is stored in the computer storage medium, and when executed by a processor, the computer program is configured to perform the following steps:
in the process of testing the block chain service based on the test case set, when a code coverage information collection event exists, acquiring code coverage information corresponding to each node in the M nodes at the current moment; the code coverage information corresponding to the node M is collected by the node M through running the stub code contained in the block chain code deployed in the node M, and M is greater than or equal to 1 and less than or equal to M;
and determining the joint code coverage rate of the block chain network at the current moment according to the code coverage information corresponding to each node in the M nodes, and carrying out test management on the block chain service based on the joint code coverage rate.
In one aspect, an embodiment of the present invention provides a computer program product or a computer program, where the computer program product includes a computer program, and the computer program is stored in a computer storage medium; a processor of the test device reads the computer program from the computer storage medium, the processor executing the computer program to cause the test device to perform:
in the process of testing the block chain service based on the test case set, when a code coverage information collection event exists, acquiring code coverage information corresponding to each node in the M nodes at the current moment; the code coverage information corresponding to the node M is collected by the node M through running the stub code contained in the block chain code deployed in the node M, and M is greater than or equal to 1 and less than or equal to M;
and determining the joint code coverage rate of the block chain network at the current moment according to the code coverage information corresponding to each node in the M nodes, and carrying out test management on the block chain service based on the joint code coverage rate.
In the embodiment of the invention, the blockchain network comprises M nodes, each node is provided with a blockchain code for providing blockchain service, the blockchain code carries an stub code, the stub code runs along with the running of the blockchain code in each node, and the running of the stub code can collect the code coverage information of the blockchain code in the corresponding node in real time. In the process of testing the block chain service in the block chain network based on the test case set, when a code coverage information collection event exists, acquiring code coverage information corresponding to each node in M nodes at the current moment; further, determining the joint code coverage rate of the block chain network at the current moment according to the code coverage information corresponding to each node in the M nodes, and performing test management on the block chain service based on the joint code coverage rate.
In the testing method, the code coverage rate in the block chain network can be collected at any time in the testing process, the running condition of the block chain codes can be checked in real time, and compared with the prior art that the code coverage rate can be checked only after the test safety quit, the testing convenience is improved. In addition, because the block chain network is a distributed network, all nodes are related to each other rather than independent, and the joint code coverage rate is determined based on the code coverage information of all nodes in the embodiment of the invention, the running condition of the block chain codes in the distributed network can be more accurately reflected, and the completeness and the accuracy of the block chain service test can be improved.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
Fig. 1a is a schematic structural diagram of a blockchain network according to an embodiment of the present invention;
fig. 1b is a schematic diagram of a block chain structure according to an embodiment of the present invention;
fig. 2 is a schematic flowchart of a testing method in a blockchain network according to an embodiment of the present invention;
FIG. 3 is a diagram illustrating a set of test cases for starting up a test case according to an embodiment of the present invention;
FIG. 4 is a diagram illustrating goc functional instructions according to an embodiment of the present invention;
fig. 5 is a flowchart illustrating another testing method in a blockchain network according to an embodiment of the present invention;
fig. 6 is a schematic diagram of a coverage generation report provided by an embodiment of the present invention;
FIG. 7 is an edit window in a go language provided by an embodiment of the present invention;
fig. 8a is a schematic diagram of another blockchain network provided by an embodiment of the present invention;
fig. 8b is a schematic diagram illustrating a testing method in a blockchain network according to an embodiment of the present invention;
fig. 8c is a schematic diagram of another testing method in a blockchain network according to an embodiment of the present invention;
fig. 9 is a schematic structural diagram of a testing apparatus in a blockchain network according to an embodiment of the present invention;
fig. 10 is a schematic structural diagram of a testing apparatus according to an embodiment of the present invention.
Detailed Description
The technical solution in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention.
The block chain is a multi-party common maintenance, transmission and access safety is guaranteed by using cryptography, and a data consistent storage, difficult tampering and repudiation prevention accounting technology, namely a distributed accounting book technology, can be realized. A blockchain network based on blockchain technology may be understood as a data sharing system for node-to-node data sharing.
Referring to fig. 1a, a schematic structural diagram of a block chain network according to an embodiment of the present invention is provided. In the blockchain network shown in fig. 1a, 100 denotes a blockchain network, and a plurality of nodes 101 may be included in the blockchain network 100, and the plurality of nodes 101 may be terminal devices or servers in the access blockchain network 100. The terminal can be an intelligent collection device, a tablet computer, a notebook computer, a desktop computer, an intelligent sound box, an intelligent watch, an intelligent vehicle-mounted device and the like. The server can be an independent physical server, a server cluster or a distributed system formed by a plurality of physical servers, and can also be a cloud server for providing basic cloud computing services such as cloud service, a cloud database, cloud computing, cloud functions, cloud storage, network service, cloud communication, middleware service, domain name service, security service, CDN, big data and artificial intelligence platform and the like.
In one embodiment, each node 101 in the blockchain network 100 may receive information input into the blockchain network 100 during normal operation and maintain shared data within the blockchain network based on the received input information. In order to ensure information intercommunication in the blockchain network, information connection may exist between each node 101 in the blockchain network, and information transmission may be performed among the nodes through the information connection. For example, when an arbitrary node 101 in the blockchain network receives input information, other nodes 101 in the blockchain network acquire the input information according to the consensus algorithm, and store the input information as data in shared data, so that the data stored on all nodes 101 in the blockchain network are consistent.
Each node 101 in the blockchain network has a corresponding node identifier, and each node 101 in the blockchain network can store the node identifiers of other nodes 101 in the blockchain network, so that the node names and the node identifiers are correspondingly stored in the node identifier list according to a node identifier list which can be maintained in other nodes 101. The node identifier may be an IP (Internet Protocol) address or any other information that can be used to identify the node, and table 1 only illustrates the IP address as an example.
TABLE 1
Node name Node identification
Node
1 117.114.151.174
Node 2 117.116.189.145
Node N 119.123.789.258
In one embodiment, each node in the blockchain network stores one identical blockchain. The block chain is composed of a plurality of blocks, and fig. 1b is a schematic structural diagram of a block chain according to an embodiment of the present invention. The block chain shown in fig. 1b may include a plurality of blocks, such as block 1, block 2, and block 3, each block includes the hash value of the block and the hash value of the previous block, and the blocks are connected by the hash values to form the block chain. A block chain (Blockchain), which is essentially a decentralized database, is a string of data blocks associated by using cryptography, and each data block contains related information for verifying the validity (anti-counterfeiting) of the information and generating a next block.
In one embodiment, the structure of the blockchain network may be understood as a P2P network. The P2P network is also called a peer-to-peer network, and the node roles in the network can be either a client or a server. Each device in the P2P network can act as both a requester of network services and provide resources, services, and content in response to requests from other devices. The life cycle of the blockchain is as follows: a node in the blockchain network receives a transaction submitted by a user (i.e., the transaction submitted by the user is the information input into the blockchain network described above), and broadcasts the transaction to other nodes through the P2P network; a consensus mechanism randomly selects a billing node, wherein the billing node is called a block-out node or an endorsement node; the accounting node packs and assembles a plurality of transactions into a block to be verified, and broadcasts the block to be verified to other nodes; after receiving the block to be verified, other nodes verify the transaction in the block, vote the block to be verified, and then broadcast the voting information; a certain node performs consensus verification on the block according to voting information from other nodes; after the consensus verification for the block passes, the block is committed to the blockchain storage tier to cause the blockchain storage tier to add the block to the blockchain, and then the generation and consensus of the next block begins.
In the blockchain network, in order to achieve the purpose of multi-center and non-falsification, multiple nodes in the blockchain network need to satisfy a certain fault-tolerant mechanism, such as a byzantine fault-tolerant mechanism, that is, in the blockchain network formed by multiple nodes, if a certain node is down, and the memory is overflowed or is bad, the entire blockchain network can also normally operate.
Only if the blockchain network operates normally, the blockchain service attached to the blockchain network can operate normally. On the contrary, even if the blockchain network can normally operate, the blockchain service deployed in the blockchain network cannot be guaranteed to normally operate. Therefore, after developing a blockchain service, it needs to be tested in the blockchain network, which can be posted after normal operation in the blockchain network. Currently, in the testing process of the blockchain service, code coverage is generally adopted as one of the evaluation means of the test completeness, and the code coverage is the proportion and the degree of the test execution of the program source code described in the software test. Code coverage is the manner derived from systematic software testing, and the basic code coverage criteria are function coverage, instruction coverage, judgment coverage, conditional coverage, and conditional/judgment coverage.
The traditional collection method for the software program code coverage rate usually adopts a coverage rate collection tool matched with a program language, such as Grov in C + +, Jacoco in Java, and GoCov in Go language. The tools can collect the code coverage rate only by safely exiting the tested program, and cannot realize real-time collection, and the service coverage rate of the stand-alone software is usually collected in the prior art, so that the joint coverage rate of a distributed system such as a block chain cannot be counted.
Based on this, an embodiment of the present invention provides a test scheme in a blockchain network, where the blockchain network includes M nodes, each node is deployed with a blockchain code for providing a blockchain service, the blockchain code carries an stub code, and the stub code runs along with the running of the blockchain code in each node, and the running of the stub code can collect code coverage information of the blockchain code in the corresponding node in real time. In the process of testing the block chain service in the block chain network based on the test case set, when a code coverage information collection event exists, acquiring code coverage information corresponding to each node in M nodes at the current moment; further, determining the joint code coverage rate of the block chain network at the current moment according to the code coverage information corresponding to each node in the M nodes, and performing test management on the block chain service based on the joint code coverage rate.
In the test method, the code coverage rate of the block chain network can be collected at any time in the test process, the running condition of the block chain codes can be checked in real time, and compared with the prior art that the code coverage rate can be checked only after the test safety quit, the test convenience is improved. In addition, because the block chain network is a distributed network, all nodes are related to each other rather than independent, and the joint code coverage rate is determined based on the code coverage information of all nodes in the embodiment of the invention, the running condition of the block chain code in the distributed network can be more accurately reflected, and thus the completeness and the accuracy of the test can be improved.
Based on the above test scheme of the blockchain network, the embodiment of the invention provides a test method in the blockchain network. Referring to fig. 2, a schematic flowchart of a testing method in a blockchain network according to an embodiment of the present invention is provided. The testing method in the blockchain network shown in fig. 2 is applied to a blockchain network, where the blockchain network includes M nodes, and a blockchain code for providing blockchain services is deployed in each node of the M nodes, where the blockchain code includes an stub code.
The testing method shown in fig. 2 may be performed by a testing device, and in particular may be performed by a processor of the testing device. The test device may be a terminal or a server. The terminal can be a smart phone, a tablet computer, a notebook computer, a desktop computer, a smart sound box, a smart watch, a smart car and the like; the server can be an independent physical server, a server cluster or a distributed system formed by a plurality of physical servers, and can also be a cloud server for providing basic cloud computing services such as cloud service, a cloud database, cloud computing, cloud functions, cloud storage, network service, cloud communication, middleware service, domain name service, security service, CDN, big data and artificial intelligence platform and the like. The testing method in the blockchain network shown in fig. 2 may include the following steps:
step S201, in the process of testing the block chain service based on the test case set, when a code coverage information collection event exists, code coverage information corresponding to each node in M nodes at the current time is obtained.
In one embodiment, the test case set may include a plurality of test cases, which may be written in advance by a tester and used for testing the blockchain service. The execution of the test case suite is triggered by the execution of a test script. Optionally, referring to fig. 3, a schematic diagram of a test case set starting method provided in the embodiment of the present invention is shown. As can be seen from fig. 3, in the test script placement pipeline for starting the test case set, when the blockchain code is submitted to the code management open source platform git, the execution of the pipeline is triggered, that is, the execution of each test case in the test case set is triggered. A plurality of test cases in the test case set are input into the blockchain network one by one, and one test case may be understood as one service or one transaction submitted into the blockchain network.
In one embodiment, the same blockchain code for providing blockchain services is deployed in each of the M nodes of the blockchain network. The blockchain code in each node may be deployed to each node according to the node attribute information of each node after the test device constructs the blockchain network. In specific implementation, node attribute information corresponding to each node in M nodes is obtained; and deploying the block chain code carrying the stub code in each node according to the node attribute information corresponding to each node. The node attribute information of each node may include an Internet Protocol (IP) address, a port number, a user name, and a user password, where the user password may be stored in an encrypted manner. And the test equipment deploys a block chain code into each node according to the node attribute information of each node.
In one embodiment, as test cases are executed in the set of test cases, each node in the blockchain network executes each test case by running the respective deployed blockchain code. With the execution of the blockchain code in each node, the stub code carried in the blockchain code is also run, and each node can count the code coverage information of the blockchain code in the node in real time by running the stub code. In a specific implementation, the stub code of each node may count the code coverage information corresponding to the node once when execution of one test case is completed, perform union operation on the code coverage information counted at the next time and the code coverage information counted at the previous time, and use the operation result as the latest counted code coverage information. When a code coverage information collection event is detected, each node reports the coverage information counted up to the current moment to the test equipment.
In one embodiment, the code coverage information collection event may refer to the receipt of a code instruction, such as a goc server, for triggering the collection of coverage information. In other words, the embodiment of the present invention is implemented by the coverage tool goc based on go language, which is capable of implementing real-time statistics of code coverage information by each node and reporting the counted code coverage information to the test equipment. In the embodiment of the invention, the go coverage tool goc abandons the old go test-c-cover mode in design, and directly interacts with the go tool, so that a series of defects caused by a go test command are avoided. Goc, it does not choose to do the instrumentation by itself, but also considers the compatibility of go language and the performance problem, after all, go tool, originally adopts the structure body to define the counter collector, each file has a separate structure body, the performance contrast is more reliable.
In one embodiment, some of the functional instructions included in the coverage tool goc may be as shown in FIG. 4. For example, the build in fig. 4 is used to compile the code under test as shown in 400 in fig. 4, a binary program with a instrumented version is generated, and in a specific application, a compiling function for the code under test can be started through a code instruction goc build; for another example, the profile is used for displaying the code coverage information of the node to be tested in real time, as shown in 401 in fig. 4, when the function is applied specifically, the function may be started through a code instruction goc profile; as another example, a server is used to implement the initiating coverage information collection as shown at 402 in fig. 4, and in a specific application, the function may be initiated by a code instruction goc server.
In other embodiments, the code coverage information collection event may further refer to detection of completion of execution of any one of the test cases in the test case set. In specific implementation, the test equipment can be preset, when any test case is executed, the code coverage information of each node is collected, and the joint code coverage rate of the block chain network is counted according to the code coverage information of each node.
In one embodiment, the blockchain code may include at least one code module, and the corresponding code coverage information of each node may include a code module in which the blockchain code deployed in each node has been executed, for example, the blockchain code includes code module 1, code module 2, and code module 3; assuming that code module 1 and code module 2 have been executed in the blockchain code deployed in node 1, and code module 2 and code module 3 have been executed in the blockchain code deployed in node 2; then the code coverage information corresponding to node 1 may indicate that code module 1 and code module 2 have been run, and the code coverage information corresponding to node 2 may indicate that code module 2 has been run.
In other embodiments, the code coverage information corresponding to each node may further include a real-time running report of the blockchain code corresponding to each node. The real-time running report of the blockchain code corresponding to each node may include marked blockchain codes, code content in code modules which have been run in the marked blockchain codes may be marked in a first mark form, and code content in code modules which have not been run may be marked in a second mark form. Wherein the first mark form may refer to a first color and the second mark form may refer to a second color different from the first color, for example, the first mark form is green and the second mark form is red; alternatively, the first markup form may refer to a first font, and the second markup form may refer to a second font, for example, the first markup form may refer to a song style, and the second markup form may refer to a regular font.
Step S202, determining the joint code coverage rate of the block chain network at the current moment according to the code coverage information corresponding to each node in the M nodes, and performing test management on the block chain service based on the joint code coverage rate.
In an embodiment, if the code coverage information corresponding to each node includes a code module in which a blockchain code deployed in each node has been executed, the determining, according to the code coverage information corresponding to each node of the M nodes, a joint code coverage rate of the blockchain network at the current time may include: performing union operation on code modules, deployed in each node, of which the blockchain codes are already operated to obtain the code modules, in which the blockchain codes are already operated, in the blockchain network; determining a joint code coverage rate of the blockchain network at a current time based on the total number of the at least one code module and a first number of code modules in the blockchain network for which the blockchain code has been executed.
In the specific implementation, assuming that the blockchain network includes a node 1 and a node 2, and the blockchain codes deployed in the node 1 and the node 2 have already been run as shown in the above example, performing a union operation on the code modules, in which the blockchain codes deployed in the nodes have already been run, refers to: the code module 1 and the code module 2 which have been operated in the node 2 perform union set operation, and the obtained operation result is: code module 1 and code module 2.
The operation result is used as a code module in which the blockchain code is executed in the blockchain network, that is, the code module in which the blockchain code is executed in the blockchain network includes a code module 1 and a code module 2. Further, if the number of code modules of the blockchain code that have been executed in the blockchain network is obtained as 2, and the total number of code modules included in the blockchain code is obtained as 3, then the joint code coverage rate in the blockchain network is equal to the number of code modules that have been executed divided by the total number of code modules included in the blockchain code, that is, the joint code coverage rate in the blockchain network is equal to 2/3.
In other embodiments, if the code coverage information corresponding to each node includes a real-time running report of a blockchain code corresponding to each node, the determining, according to the code coverage information corresponding to each node of the M nodes, a joint code coverage rate of the blockchain network at the current time includes: counting code modules which are deployed in each node and run the blockchain codes according to the blockchain code real-time running report corresponding to each node; performing union operation on code modules, deployed in each node, of which the blockchain codes are already operated to obtain the code modules, in which the blockchain codes are already operated, in the blockchain network; determining a joint code coverage rate of the blockchain network at a current time based on the total number of the at least one code module and a first number of code modules in the blockchain network for which the blockchain code has been executed.
In one embodiment, after the testing device determines the code coverage rate in the blockchain network, the testing device may perform testing management on the blockchain service based on the code coverage rate. In a specific implementation, the performing test management on the blockchain service based on the code coverage includes: if the combined code coverage rate is greater than or equal to a code coverage rate threshold value, determining that the testing of the block chain service is finished, and stopping the testing of the block chain service; and if the joint code coverage rate is smaller than the code coverage rate threshold value, continuously executing the test case set so as to continuously test the block chain service. It should be understood that the higher the code coverage of the blockchain network is, the more code modules are executed in the blockchain network, the more code modules are executed, and the more services provided by the blockchain code are tested, so that the more the test accuracy is ensured.
In the embodiment of the invention, the blockchain network comprises M nodes, each node of the M nodes is provided with a blockchain code for providing blockchain service, the blockchain code carries an stub code, the stub code runs along with the running of the blockchain code in each node, and the running of the stub code can collect the code coverage information of the blockchain code in the corresponding node in real time. In the process of testing the block chain service in the block chain network based on the test case set, when a code coverage information collection event exists, acquiring code coverage information corresponding to each node in M nodes at the current moment; further, determining the joint code coverage rate of the block chain network at the current moment according to the code coverage information corresponding to each node in the M nodes, and performing test management on the block chain service based on the joint code coverage rate.
In the test method, the code coverage rate of the block chain network can be collected at any time in the test process, the running condition of the block chain codes can be checked in real time, and compared with the prior art that the code coverage rate can be checked only after the test safety quit, the test convenience is improved. In addition, because the block chain network is a distributed network, all nodes are related to each other rather than independent, and the joint code coverage rate is determined based on the code coverage information of all nodes in the embodiment of the invention, the running condition of the block chain code in the distributed network can be more accurately reflected, and thus the completeness and the accuracy of the test can be improved.
Based on the above testing method for the blockchain network, an embodiment of the present invention further provides another testing method for the blockchain network, and referring to fig. 5, a flowchart of the testing method for the blockchain network provided by the embodiment of the present invention is shown. The testing method shown in fig. 5 may be performed by a testing device, which may be an end user or a server. The test method shown in fig. 5 may include the following steps:
step S501, node attribute information corresponding to each node in the M nodes is obtained, and a block chain code carrying a pile code is deployed in each node according to the node attribute information corresponding to each node.
Step S502, in the process of testing the blockchain service based on the test case set, when the target test case in the test case set is executed, a code module in which a blockchain code deployed in each node of the M nodes at the current moment is operated is obtained.
As described in the embodiment of FIG. 2, the test cases in the test case set are input into the blockchain network one by one. And with the operation of the block chain codes in each node, the stub codes included by the block chain codes are also operated, and the operation of the stub codes realizes the real-time statistics of the code coverage information of the block chain codes in each node when each test case is completed.
If the test equipment is preset, when the execution of any test case in the test case set is finished, collecting the code module in which the blockchain code deployed in each node in the blockchain network at the current moment is operated, and counting the joint code coverage rate of the blockchain network at the current moment according to the code module in which the blockchain code deployed in each node is operated. The blockchain network detects the execution of each test case in the test case set, and after the execution of the target test case is detected to be completed, the code module in which the blockchain code deployed in each node is operated is obtained. The target test case may refer to any test case in the test case set.
Step S503, performing union operation on the code modules, in which the blockchain codes deployed in each node have been executed, to obtain the code modules, in which the blockchain codes have been executed, in the blockchain network.
Step S504, determining a joint code coverage rate of the blockchain network at the current time based on the total number of at least one code module included in the blockchain code and the first number of code modules in the blockchain network, where the blockchain code has already been executed, and performing test management on the blockchain service based on the joint code coverage rate.
In an embodiment, some possible implementations included in steps S503 to S504 may refer to the detailed description in the embodiment in fig. 2, and are not described herein again.
And step S505, generating a coverage rate report corresponding to the block chain network according to the joint code coverage rate.
In one embodiment, the coverage report is used to reflect the running proportion and extent of blockchain codes in the blockchain network at the current time. Optionally, the coverage rate report may include marked blockchain code, in the marked blockchain code, the code content in the executed code module may be marked in a first form, and the code content in the code module that is not executed may be marked in a second form.
Wherein the first form may refer to a first color and the second form may refer to a second color different from the first color, such as green for the first form and red for the second form; alternatively, the first form may refer to a first font, and the second form may refer to a second font, for example, the first form may refer to a font, and the second font may refer to a second font. Alternatively, the first form may refer to framing the code content of a code module that has been executed in a first shape box, such as a dashed rectangle box, and the second form may refer to framing the code content of a code module that has not been executed in a second shape box, such as a solid rectangle box. For example, referring to fig. 6, a schematic diagram of a coverage generation report provided by the embodiment of the present invention is shown, where 601 represents the code content in the code module marked in the first form that has been executed, and 602 represents the code content in the code module marked in the second form that has not been executed.
In one embodiment, code coverage may also be included in the coverage generation report, as shown at 603 in fig. 6. The coverage generation report may also include a code coverage evaluation of the current time, such as 604 in fig. 6, where the code coverage evaluation may be "high coverage", "low coverage", and "medium coverage". Optionally, the evaluation of the code coverage condition may be determined by the test device according to the code coverage and a code coverage threshold, assuming that the test device presets two code coverage thresholds, which are a first code coverage and a second code coverage, respectively, and the first code coverage is smaller than the second code coverage; if the code coverage rate of the block chain network at the current moment is smaller than the first code coverage rate, the code coverage condition is evaluated as low coverage rate; if the test equipment determines that the code coverage rate of the block chain network at the current moment is greater than the first code coverage rate and less than the second code coverage rate, determining that the code coverage condition at the current moment is evaluated as the medium coverage rate; and if the code coverage rate of the block chain network at the current moment is larger than the second code coverage rate, the code coverage condition at the current moment is evaluated as high coverage rate.
Step S506, establishing a corresponding relation between the target test case and the code module in the block chain network, wherein the block chain code is operated, and optimizing the target test case based on the corresponding relation.
After the test device determines the code module in which the blockchain code has been executed in the blockchain network through step S503, it may establish a corresponding relationship between the target test case and the code module in which the blockchain code has been executed in the blockchain network.
As an alternative implementation, the test device may optimize the target test case based on a correspondence between the target test case and the code modules in the blockchain network, where the blockchain code has been executed, so that when the blockchain network is tested based on the optimized target test case, the number of the code modules in the blockchain network, where the blockchain code has been executed, is greater than the first number.
In short, when the target test case is definitely executed, after which code modules of the block chain code are executed, the target test case may be modified and adjusted appropriately, so that the modified test case may be executed to cover more code modules in the block chain code.
As another alternative implementation, the test device may store the correspondence in a reference information set used for constructing test cases, where the reference information set may include a correspondence between multiple groups of test cases and code modules in a blockchain network where blockchain codes have been run; further, a new test case is constructed based on the reference information set, so that when the blockchain network is tested based on the new test case, the target code module in the blockchain code in the blockchain network is operated.
In brief, in the testing process of the blockchain service in the blockchain network, the corresponding relations between a plurality of groups of test cases and the operated code modules are collected, and a basis is provided for accurate testing based on the collected corresponding relations.
It should be understood that the above only states that the correspondence relationship between a group of test cases and the code module in the blockchain network, of which the blockchain code has been executed, is obtained, and the correspondence relationship between a plurality of groups of test cases and the code module in the blockchain network, of which the blockchain code has been executed, can be obtained by repeatedly executing the above steps.
For example, the blockchain code may include code module 1, code module 2, and code module 3, and when the blockchain service is tested in the blockchain network through the first test case, code module 1 that collects the blockchain code in the blockchain network is run; at this time, the first test case has a corresponding relationship with the code module 1; when the blockchain service is tested in the blockchain network through the second test case, the code module 2 which collects the blockchain codes in the blockchain network is operated, and at the moment, the second test case and the code module 2 have a corresponding relation.
Subsequently, if the target code module of the block chain code to be tested is the code module 2, the second test case can be directly used as a new test case; if the target code module of the block chain code to be tested is the code module 1, the first test case can be directly used as a new test case; if the target code modules of the block chain code to be tested are the code modules 1 and 2, a new test case can be constructed according to the first test case and the second test case.
In one embodiment, when the test equipment monitors a code instruction to view the code coverage of the node n, the test equipment may display the code coverage of the node n, which is determined based on the number of code modules of the blockchain code deployed in the node n that have been executed and the total number of at least one code module included in the blockchain code, as can be seen in the foregoing. The code instruction for checking the code coverage of the node n may include address information of the node n, for example, the address information of the node n is http://127.0.0.1:36817, and the code instruction for checking the code coverage of the node n may be represented as "goc profile — center =" http://127.0.0.1:36817 "> cov.out & & go tool cover-html = cov.out-o cov.html". When the test equipment displays the code coverage rate of the node n, the test equipment can also display the address information of the node n.
As can be seen from the foregoing, in the embodiment of the present invention, the collection of the overlay information is implemented based on the go language, so that the code instruction for viewing the code coverage of the node n may be input in the editing window of the go language, and the code coverage of the node n may also be displayed in the editing window of the go language. For example, referring to fig. 7, an editing window in a go language is provided, 701 represents code coverage of a node n and address information of the node n collected at two different times.
In the embodiment of the invention, the test equipment acquires the node attribute information of each node and deploys the block chain code for providing the block chain service in each node according to the node attribute information. In the process of testing the block chain service in the block chain network based on the test case set, if a coverage information collection event is detected when the target test case is executed, the code module in which the block chain code deployed in each node is operated is obtained, so that the test is not required to be quitted, the block chain code operation condition in each node can be collected at any time in the test process, and the test convenience is improved.
Furthermore, the test equipment performs fetch-and-gather operation on the code modules, which are deployed in each node and have been run, to obtain the code modules, in which the blockchain codes have been run, in the blockchain network; the joint code coverage of the blockchain network at the current time is then determined based on the total number of code modules included in the blockchain code and the first number of code modules in the blockchain network for which the blockchain code has been executed. It should be understood that after the code coverage information of each node is collected, secondary statistics is performed based on the code coverage information of each node to obtain the joint code coverage rate of the blockchain network, which can reflect the condition that the blockchain code is operated in a distributed network such as the blockchain network, and thus the completeness of the test is improved.
In order to facilitate the generation of subsequent accurate test cases and the optimization of the test cases, the invention can also establish the corresponding relation between the target test case and the code modules of the block chain codes in the block chain network, and then the test cases can be optimized based on the corresponding relation or more accurate test cases can be generated.
Based on the above embodiment of the test method for the blockchain network, an embodiment of the present invention provides an application embodiment of the test method. A developer constructs a blockchain network as shown in fig. 8a, develops a corresponding blockchain product or blockchain project in the blockchain network, and needs to perform a test procedure as shown in fig. 8b and 8c in order to test the operation of the developed blockchain product in the blockchain network as shown in fig. 8 a. The specific implementation can include:
(1) each module of the blockchain product (i.e., each code module of the blockchain code) is provided to the software development and development providing process management platform REQ, which is used to manage software version development, providing and testing, defect provision, regression testing, and release the entire life cycle.
(2) The REQ platform collects node attribute information of the node under test in the blockchain network of fig. 8a, such as an IP address, port information, a user name, and a user password, and distributes a blockchain code to each node based on the node attribute information of the node under test, and in fig. 8C, it is assumed that the node under test is node a, node B, node C, and node D.
(3) Then starts the coverage collection server, specifically, the open source coverage collection tool goc starts the gore server registry based on the go language, and executes the command gore server.
(4) And starting a blockchain code in the node to be tested, wherein the blockchain code carries an stub code, and the blockchain code can be regarded as a binary packet with an stub, for example, represented as 'nohup./xxx _ blockchain _ cov &'.
(5) And triggering the execution of the test case set on the block chain automatic pipeline platform. And starting to run each test case in the test case set one by one in the block chain network to realize the test of the block chain network. In the testing process, each tested node dynamically collects code coverage information of each node when the test case is executed every time the test case is executed, wherein the code coverage information may include a code module in which a block chain code deployed in each node has been run, and the code coverage information may also include a code coverage rate of the block chain code in each node.
(6) In the testing process, a code instruction for collecting code coverage information can be input through the REQ platform, each node reports the dynamically collected code coverage information at the moment, the REQ platform determines the joint code coverage rate of the block chain network according to the code coverage information reported by each node, and generates a coverage rate report according to the joint code coverage rate.
(7) As can be seen from the foregoing, the coverage rate report includes the marked blockchain code and the joint code coverage rate, and if the developer determines that the blockchain product can be normally used in the blockchain network according to the joint code coverage rate and the marked blockchain code, and reaches the distributable standard, the test is ended, and the blockchain product is distributed online.
Based on the above method embodiment, the embodiment of the present invention provides a testing apparatus in a block chain network. Fig. 9 is a schematic structural diagram of a testing apparatus in a blockchain network according to an embodiment of the present invention. The blockchain network comprises M nodes, wherein M is an integer greater than 1; and a blockchain code used for prompting blockchain service is deployed in each node, and the blockchain code comprises an stub code. The test apparatus shown in fig. 9 can operate as follows:
an obtaining unit 901, configured to obtain, when a code coverage information collection event exists in a process of testing the block chain service based on a test case set, code coverage information corresponding to each node in the M nodes at a current time; the code coverage information corresponding to the node M is collected by the node M through running the stub code contained in the block chain code deployed in the node M, and M is greater than or equal to 1 and less than or equal to M;
a processing unit 902, configured to determine, according to the code coverage information corresponding to each node of the M nodes, a joint code coverage rate of the blockchain network at the current time, and perform test management on the blockchain service based on the joint code coverage rate.
In one embodiment, the blockchain code comprises at least one code module, and the corresponding code coverage information of each node comprises the code module which is deployed in each node and is executed by the blockchain code; when determining the joint code coverage rate of the blockchain network at the current time according to the code coverage information corresponding to each node of the M nodes, the processing unit 902 executes the following steps:
performing union operation on the code modules of the block chain codes deployed in the nodes, wherein the block chain codes are operated, so as to obtain the code modules of the block chain codes operated in the block chain network; determining a joint code coverage rate of the blockchain network at a current time based on the total number of the at least one code module and a first number of code modules in the blockchain network for which the blockchain code has been executed.
In one embodiment, the code coverage information collection event refers to receiving a code instruction for triggering coverage information collection; or, the code coverage information collection event is the detection of the completion of the execution of a test case. The code coverage information collection event is that a code instruction for triggering coverage information collection is received; or, the code coverage information collection event refers to detection of completion of execution of any one test case in the test case set.
In one embodiment, the testing apparatus shown in fig. 9 further includes a display unit 903, where the display unit 903 is configured to display the code coverage rate in the node n if a code instruction for checking the code coverage rate in the node n is detected, where n is greater than or equal to 1 and less than or equal to M; the code coverage in the node n is determined based on the number of code modules of the blockchain code deployed in the node n that have been run and the total number of at least one code module included in the blockchain code.
In an embodiment, the processing unit 902 is further configured to generate a coverage report corresponding to the blockchain network according to the joint code coverage, where the coverage report includes marked blockchain codes, where code content in code modules that have been executed in the marked blockchain codes is marked in a first form, and code content in code modules that have not been executed in the marked blockchain codes is marked in a second form.
In one embodiment, the code coverage information collection event refers to receiving a code instruction for triggering coverage information collection, and the code instruction is received when the target test case in the test case set is executed; or, the code coverage information collection event refers to detecting that the target test case is executed;
the processing unit 902 is further configured to establish a correspondence between the target test case and a code module in the blockchain network where the blockchain code has been executed; and optimizing the target test case according to the corresponding relation so that the number of code modules of the block chain code which is operated in the block chain network is greater than the first number when the optimized target test user tests the block chain service.
In an embodiment, the testing apparatus shown in fig. 9 further includes a storage unit 904, where the storage unit 904 is configured to store the correspondence relationship into a reference information set used for constructing test cases, where the reference information set includes correspondence relationships between groups of test cases and code modules in the blockchain network where the blockchain code has been executed; the processing unit 902 is further configured to construct a new test case based on the reference information set, so that when the blockchain service is tested based on the new test case, a target code module in the blockchain code in the blockchain network is run.
In an embodiment, the obtaining unit 901 is further configured to obtain node attribute information corresponding to each node in the M nodes; the processing unit 902 is further configured to deploy the block chain code carrying the stub code in each node according to the node attribute information corresponding to each node.
In one embodiment, the processing unit 902, when performing test management on the blockchain service based on the joint code coverage, performs the following steps: and if the combined code coverage rate is greater than or equal to a code coverage rate threshold value, determining that the block chain service test is completed, and stopping the block chain service test.
According to an embodiment of the present invention, the steps involved in the test method shown in fig. 2 and 5 may be performed by the units in the test apparatus shown in fig. 9. For example, step S201 described in fig. 2 may be performed by the acquiring unit 901 in the testing apparatus shown in fig. 9, and step S202 may be performed by the processing unit 902 in the testing apparatus shown in fig. 9. As another example, steps S501 and S502 shown in fig. 5 may be performed by the acquisition unit 901 in the test apparatus shown in fig. 9, and steps S503 to S506 may be performed by the processing unit 902 in the test apparatus shown in fig. 9.
According to another embodiment of the present invention, the units in the testing apparatus shown in fig. 9 may be respectively or entirely combined into one or several other units to form one or several other units, or some unit(s) therein may be further split into multiple units with smaller functions to form one or several other units, which may achieve the same operation without affecting the achievement of the technical effect of the embodiment of the present invention. The units are divided based on logic functions, and in practical application, the functions of one unit can be realized by a plurality of units, or the functions of a plurality of units can be realized by one unit. In other embodiments of the present invention, the testing device may also include other units, and in practical applications, these functions may also be implemented by the assistance of other units, and may be implemented by cooperation of a plurality of units.
According to another embodiment of the present invention, the test apparatus as shown in fig. 9 may be constructed by running a computer program (including program codes) capable of executing the steps involved in the respective methods as shown in fig. 2 and 5 on a general-purpose computing device such as a computer including a processing element such as a Central Processing Unit (CPU), a random access storage medium (RAM), a read-only storage medium (ROM), and a storage element, and a test method according to an embodiment of the present invention may be implemented. The computer program may be embodied on a computer storage medium, for example, and loaded into and run on the test apparatus via the computer storage medium.
In the embodiment of the invention, the blockchain network comprises M nodes, each node of the M nodes is provided with a blockchain code for providing blockchain service, the blockchain code carries an stub code, the stub code runs along with the running of the blockchain code in each node, and the running of the stub code can collect the code coverage information of the blockchain code in the corresponding node in real time. In the process of testing the block chain service in the block chain network based on the test case set, when a code coverage information collection event exists, acquiring code coverage information corresponding to each node in M nodes at the current moment; further, determining the joint code coverage rate of the block chain network at the current moment according to the code coverage information corresponding to each node in the M nodes, and performing test management on the block chain service based on the joint code coverage rate.
In the test method, the code coverage rate of the block chain network can be collected at any time in the test process, the running condition of the block chain codes can be checked in real time, and compared with the prior art that the code coverage rate can be checked only after the test safety quit, the test convenience is improved. In addition, because the block chain network is a distributed network, all nodes are related to each other rather than independent, and the joint code coverage rate is determined based on the code coverage information of all nodes in the embodiment of the invention, the running condition of the block chain code in the distributed network can be more accurately reflected, and thus the completeness and the accuracy of the test can be improved.
Based on the above method embodiment and apparatus embodiment, an embodiment of the present invention further provides a test device, where the test device may be configured to execute a test method in a block chain network, where the block chain network includes M nodes, and M is an integer greater than 1; each node is provided with a block chain code used for providing block chain service, and the block chain code comprises an stub code. Referring to fig. 10, a schematic structural diagram of a testing apparatus according to an embodiment of the present invention is provided. The test equipment shown in fig. 10 may include at least a processor 1001, an input interface 1002, an output interface 1003, and a computer storage medium 1004. The processor 1001, the input interface 1002, the output interface 1003, and the computer storage medium 1004 may be connected by a bus or other means.
A computer storage medium 1004 may be stored in the memory of the test device, said computer storage medium 1001 being adapted to store a computer program, said processor 1001 being adapted to execute the computer program stored by said computer storage medium 1004. The processor 1001 (or CPU) is a computing core and a control core of the testing apparatus, and is adapted to implement one or more computer programs, and specifically adapted to load and execute:
in the process of testing the block chain service based on the test case set, when a code coverage information collection event exists, acquiring code coverage information corresponding to each node in the M nodes at the current moment; the code coverage information corresponding to the node M is collected by the node M through running the stub code contained in the block chain code deployed in the node M, and M is greater than or equal to 1 and less than or equal to M; and determining the joint code coverage rate of the block chain network at the current moment according to the code coverage information corresponding to each node in the M nodes, and carrying out test management on the block chain service based on the joint code coverage rate.
The embodiment of the invention also provides a computer storage medium (Memory), which is a Memory device in the test device and is used for storing programs and data. It is understood that the computer storage medium herein may include both the built-in storage medium of the testing device and, of course, the extended storage medium supported by the testing device. The computer storage medium provides a storage space that stores an operating system of the test equipment. Also stored in this memory space are one or more computer programs, which may be one or more instructions (including program code), suitable for loading and execution by processor 801. The computer storage medium may be a high-speed RAM memory, or may be a non-volatile memory (non-volatile memory), such as at least one disk memory; and optionally at least one computer storage medium located remotely from the processor.
In one embodiment, the blockchain code comprises at least one code module, and the corresponding code coverage information of each node comprises the code module which is deployed in each node and is executed by the blockchain code; when determining the joint code coverage of the blockchain network at the current time according to the code coverage information corresponding to each node of the M nodes, the processor 1001 executes the following steps:
performing union operation on the code modules of the block chain codes deployed in the nodes, wherein the block chain codes are operated, so as to obtain the code modules of the block chain codes operated in the block chain network; determining a joint code coverage rate of the blockchain network at a current time based on the total number of the at least one code module and a first number of code modules in the blockchain network for which the blockchain code has been executed.
In one embodiment, the code coverage information collection event refers to receiving a code instruction for triggering coverage information collection; or, the code coverage information collection event refers to detection of completion of execution of any one test case in the test case set.
In one embodiment, the processor 1001 is further configured to: if a code instruction for checking the code coverage rate in the node n is detected, displaying the code coverage rate in the node n, wherein n is more than or equal to 1 and less than or equal to M; the code coverage in the node n is determined based on the number of code modules of the blockchain code deployed in the node n that have been run and the total number of at least one code module included in the blockchain code.
In one embodiment, the processor 1001 is further configured to: and generating a coverage rate report corresponding to the blockchain network according to the joint code coverage rate, wherein the coverage rate report comprises marked blockchain codes, the code content in the executed code modules in the marked blockchain codes is marked in a first form, and the code content in the code modules which are not executed in the marked blockchain codes is marked in a second form.
In one embodiment, the code coverage information collection event refers to receiving a code instruction for triggering coverage information collection, and the code instruction is received when the target test case in the test case set is executed; or, the code coverage information collection event refers to detecting that the target test case is executed; the processor 1001 is further configured to:
establishing a corresponding relation between the target test case and a code module in the block chain network, wherein the block chain code is operated; and optimizing the target test case according to the corresponding relation so that the number of code modules of the block chain code which is operated in the block chain network is greater than the first number when the optimized target test user tests the block chain service.
In one embodiment, the processor 1001 is further configured to: storing the corresponding relation into a reference information set for constructing test cases, wherein the reference information set comprises corresponding relations between a plurality of groups of test cases and code modules of the block chain codes which are operated in the block chain network; and constructing a new test case based on the reference information set, so that when the blockchain service is tested based on the new test case, an object code module in the blockchain code in the blockchain network is operated.
In one embodiment, the processor 1001 is further configured to: acquiring node attribute information corresponding to each node in the M nodes; and deploying the block chain code carrying the stub code in each node according to the node attribute information corresponding to each node.
In one embodiment, the processor 1001, when performing test management on the blockchain service based on the joint code coverage, performs the following steps: and if the combined code coverage rate is greater than or equal to a code coverage rate threshold value, determining that the block chain service test is completed, and stopping the block chain service test.
In the embodiment of the invention, the blockchain network comprises M nodes, each node is provided with a blockchain code for providing blockchain service, the blockchain code carries an stub code, the stub code runs along with the running of the blockchain code in each node, and the running of the stub code can collect the code coverage information of the blockchain code in the corresponding node in real time. In the process of testing the block chain service in the block chain network based on the test case set, when a code coverage information collection event exists, acquiring code coverage information corresponding to each node in M nodes at the current moment; further, determining the joint code coverage rate of the block chain network at the current moment according to the code coverage information corresponding to each node in the M nodes, and performing test management on the block chain service based on the joint code coverage rate.
In the testing method, the code coverage rate in the block chain network can be collected at any time in the testing process, the running condition of the block chain codes can be checked in real time, and compared with the prior art that the code coverage rate can be checked only after the test safety quit, the testing convenience is improved. In addition, because the block chain network is a distributed network, all nodes are related to each other rather than independent, and the joint code coverage rate is determined based on the code coverage information of all nodes in the embodiment of the invention, the running condition of the block chain codes in the distributed network can be more accurately reflected, and the completeness and the accuracy of the block chain service test can be improved.
According to an aspect of the present application, an embodiment of the present invention also provides a computer program product or a computer program, the computer program product comprising a computer program, the computer program being stored in a computer storage medium. The processor 1001 reads the computer program from the computer storage medium, and the processor 1001 executes the computer program, so that the testing device executes the testing method in the blockchain network described in fig. 2 and 5, specifically:
in the process of testing the block chain service based on the test case set, when a code coverage information collection event exists, acquiring code coverage information corresponding to each node in the M nodes at the current moment; the code coverage information corresponding to the node M is collected by the node M through running the stub code contained in the block chain code deployed in the node M, and M is greater than or equal to 1 and less than or equal to M; and determining the joint code coverage rate of the block chain network at the current moment according to the code coverage information corresponding to each node in the M nodes, and carrying out test management on the block chain service based on the joint code coverage rate.
In the embodiment of the invention, the blockchain network comprises M nodes, each node is provided with a blockchain code for providing blockchain service, the blockchain code carries an stub code, the stub code runs along with the running of the blockchain code in each node, and the running of the stub code can collect the code coverage information of the blockchain code in the corresponding node in real time. In the process of testing the block chain service in the block chain network based on the test case set, when a code coverage information collection event exists, acquiring code coverage information corresponding to each node in M nodes at the current moment; further, determining the joint code coverage rate of the block chain network at the current moment according to the code coverage information corresponding to each node in the M nodes, and performing test management on the block chain service based on the joint code coverage rate.
In the testing method, the code coverage rate in the block chain network can be collected at any time in the testing process, the running condition of the block chain codes can be checked in real time, and compared with the prior art that the code coverage rate can be checked only after the test safety quit, the testing convenience is improved. In addition, because the block chain network is a distributed network, all nodes are related to each other rather than independent, and the joint code coverage rate is determined based on the code coverage information of all nodes in the embodiment of the invention, the running condition of the block chain codes in the distributed network can be more accurately reflected, and the completeness and the accuracy of the block chain service test can be improved.

Claims (12)

1. The test method in the block chain network is characterized in that the block chain network comprises M nodes, wherein M is an integer greater than 1; each node stores node identifiers of other nodes except the node identifier, information connection is established among the nodes based on the node identifiers so that information transmission is carried out among the nodes based on the information connection, the same block chain codes used for providing block chain services are deployed in each node, and each block chain code comprises a stub code, and the method comprises the following steps:
testing the block chain service based on the test case set, comprising: submitting any test case in the test case set to the blockchain network as a transaction; after any node in the M nodes receives the transaction, broadcasting the transaction to a billing node in the M nodes by running the blockchain code in the any node, wherein the billing node is selected from the M nodes through a consensus mechanism; the accounting node packs the transaction into a block to be verified by running the block chain code, broadcasts the block to be verified to other nodes, so that the other nodes perform consensus verification on the block to be verified, and adds the block to a block chain by running the block chain code after the consensus verification is passed;
in the process of testing the block chain service based on the test case set, when a code coverage information collection event exists, acquiring code coverage information corresponding to each node in the M nodes at the current moment; the code coverage information corresponding to the node M is collected by the node M through running the stub code contained in the block chain code deployed in the node M, and M is greater than or equal to 1 and less than or equal to M;
and determining the joint code coverage rate of the block chain network at the current moment according to the code coverage information corresponding to each node in the M nodes, and carrying out test management on the block chain service based on the joint code coverage rate.
2. The method of claim 1, wherein the blockchain code comprises at least one code module, and wherein the code coverage information corresponding to each node comprises the code modules deployed in each node on which the blockchain code has been run; the determining the joint code coverage rate of the block chain network at the current time according to the code coverage information corresponding to each node of the M nodes includes:
performing union operation on the code modules of the block chain codes deployed in the nodes, wherein the block chain codes are operated, so as to obtain the code modules of the block chain codes operated in the block chain network;
determining a joint code coverage rate of the blockchain network at a current time based on the total number of the at least one code module and a first number of code modules in the blockchain network for which the blockchain code has been executed.
3. The method of claim 2, wherein the code coverage information collection event is receipt of a code instruction to trigger coverage information collection; or, the code coverage information collection event refers to detection of completion of execution of any one test case in the test case set.
4. The method of claim 1, wherein the method further comprises:
if a code instruction for checking the code coverage rate in the node n is detected, displaying the code coverage rate in the node n, wherein n is more than or equal to 1 and less than or equal to M; the code coverage in the node n is determined based on the number of code modules of the blockchain code deployed in the node n that have been run and the total number of at least one code module included in the blockchain code.
5. The method of claim 1, wherein the method further comprises:
and generating a coverage rate report corresponding to the blockchain network according to the joint code coverage rate, wherein the coverage rate report comprises marked blockchain codes, the code content in the executed code modules in the marked blockchain codes is marked in a first form, and the code content in the code modules which are not executed in the marked blockchain codes is marked in a second form.
6. The method of claim 3, wherein the code coverage information collection event is that a code instruction for triggering coverage information collection is received, and the code instruction is received when execution of a target test case in the set of test cases is completed; or, the code coverage information collection event refers to detection of completion of execution of the target test case, and the method further includes:
establishing a corresponding relation between the target test case and a code module in the block chain network, wherein the block chain code is operated;
and optimizing the target test case according to the corresponding relation so that the number of code modules of the block chain code which is operated in the block chain network is greater than the first number when the optimized target test user tests the block chain service.
7. The method of claim 6, wherein the method further comprises:
storing the corresponding relation into a reference information set for constructing test cases, wherein the reference information set comprises corresponding relations between a plurality of groups of test cases and code modules of the block chain codes which are operated in the block chain network;
and constructing a new test case based on the reference information set, so that when the blockchain service is tested based on the new test case, an object code module in the blockchain code in the blockchain network is operated.
8. The method of claim 1, wherein the method further comprises:
acquiring node attribute information corresponding to each node in the M nodes;
and deploying the block chain code carrying the stub code in each node according to the node attribute information corresponding to each node.
9. The method of claim 1, wherein the test management of the blockchain service based on the joint code coverage comprises:
and if the combined code coverage rate is greater than or equal to a code coverage rate threshold value, determining that the block chain service test is completed, and stopping the block chain service test.
10. A testing device in a block chain network is characterized in that the block chain network comprises M nodes, wherein M is an integer larger than 1; each node stores node identifiers of other nodes except the node identifier, information connection is established among the nodes based on the node identifiers so that information transmission is carried out among the nodes based on the information connection, the same block chain codes used for providing block chain services are deployed in each node, and each block chain code comprises a stub code, and the device comprises:
an obtaining unit, configured to obtain, when a code coverage information collection event exists in a process of testing the block chain service based on a test case set, code coverage information corresponding to each node in the M nodes at a current time; the code coverage information corresponding to the node M is collected by the node M through running the stub code contained in the block chain code deployed in the node M, and M is greater than or equal to 1 and less than or equal to M;
the processing unit is used for determining the joint code coverage rate of the block chain network at the current moment according to the code coverage information corresponding to each node in the M nodes and carrying out test management on the block chain service based on the joint code coverage rate;
wherein the testing the block chain service based on the test case set comprises: submitting any test case in the test case set to the blockchain network as a transaction;
after any node in the M nodes receives the transaction, broadcasting the transaction to a billing node in the M nodes by running the blockchain code in the any node, wherein the billing node is selected from the M nodes through a consensus mechanism;
and the accounting node packs the transaction into a block to be verified by operating the block chain code, broadcasts the block to be verified to other nodes so that the other nodes perform consensus verification on the block to be verified, and adds the block to a block chain by operating the block chain code after the consensus verification is passed.
11. A test apparatus, comprising:
a processor adapted to implement one or more computer programs; and
computer storage medium storing one or more computer programs adapted to be loaded by the processor and to perform a test method in a blockchain network according to any one of claims 1 to 9.
12. A computer storage medium, characterized in that the computer storage medium stores a computer program for performing a test method in a blockchain network according to any one of claims 1 to 9 when the computer program is executed by a processor.
CN202011429270.6A 2020-12-09 2020-12-09 Test method, device and test equipment in block chain network Active CN112202647B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011429270.6A CN112202647B (en) 2020-12-09 2020-12-09 Test method, device and test equipment in block chain network

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011429270.6A CN112202647B (en) 2020-12-09 2020-12-09 Test method, device and test equipment in block chain network

Publications (2)

Publication Number Publication Date
CN112202647A CN112202647A (en) 2021-01-08
CN112202647B true CN112202647B (en) 2021-03-16

Family

ID=74033889

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011429270.6A Active CN112202647B (en) 2020-12-09 2020-12-09 Test method, device and test equipment in block chain network

Country Status (1)

Country Link
CN (1) CN112202647B (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112783795B (en) * 2021-02-22 2024-02-09 中国工商银行股份有限公司 Software test coverage rate detection method and system
CN113095594A (en) * 2021-04-30 2021-07-09 中国银行股份有限公司 Block chain-based test joint debugging method and device
CN113364650A (en) * 2021-06-17 2021-09-07 上海万向区块链股份公司 Block chain testing method and system based on chaotic engineering

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103095518B (en) * 2011-11-08 2016-08-10 阿里巴巴集团控股有限公司 Coverage rate test processing method, device, coverage rate test server and system
CN106294114A (en) * 2015-06-08 2017-01-04 阿里巴巴集团控股有限公司 A kind of code coverage acquisition methods, server and application apparatus to be measured
CN106874187B (en) * 2016-12-29 2020-09-11 腾讯科技(深圳)有限公司 Code coverage rate collection method and device
CN107329888B (en) * 2017-05-31 2019-10-18 深圳前海微众银行股份有限公司 Smart contract operation code coverage calculation method and system
WO2020003131A1 (en) * 2018-06-25 2020-01-02 Blocktest Global Systems and methods to automatically evaluate blockchain-based solution performance
CN110096439B (en) * 2019-04-26 2020-07-14 河海大学 Test case generation method for solidity language
CN111625454A (en) * 2020-05-22 2020-09-04 平安普惠企业管理有限公司 Data processing method based on test case and related equipment

Also Published As

Publication number Publication date
CN112202647A (en) 2021-01-08

Similar Documents

Publication Publication Date Title
CN112073269B (en) Block chain network testing method, device, server and storage medium
CN112202647B (en) Test method, device and test equipment in block chain network
CN112134762B (en) Testing method, device, terminal and storage medium for block chain network structure
CN111752850B (en) Method and related equipment for testing block chain system
CN110046073B (en) Log collection method and device, equipment and storage medium
CN112860569A (en) Automatic testing method and device, electronic equipment and storage medium
CN110750458A (en) Big data platform testing method and device, readable storage medium and electronic equipment
CN112559525B (en) Data checking system, method, device and server
CN110705893B (en) Service node management method, device, equipment and storage medium
CN116155771A (en) Network anomaly test method, device, equipment, storage medium and program
CN116974874A (en) Database testing method and device, electronic equipment and readable storage medium
CN111782551A (en) Test method and device for block chain item and computer equipment
CN114281784A (en) Transaction log playback method, device, device and medium of distributed core system
CN114595127B (en) Log exception processing method, device, equipment and storage medium
CN111679978B (en) Program testing method, program testing device, electronic equipment and storage medium
CN110503297B (en) Service scene acquisition method and device, electronic equipment and medium
CN113360363B (en) Method, device, equipment and computer storage medium for testing micro service system
HK40038178B (en) Method and apparatus for testing in blockchain network and device for testing
HK40038178A (en) Method and apparatus for testing in blockchain network and device for testing
CN116455782A (en) Block chain network testing method and related device
CN115269424A (en) Automatic regression testing method, device, equipment and storage medium for production flow
CN115987858A (en) Pressure testing method of block chain network and related equipment
CN113238966A (en) Report platform front end testing method, device, equipment and storage medium
CN112988591A (en) Charging logic verification method, device, equipment and storage medium
CN119324921B (en) Method, system, equipment and medium for improving data acquisition efficiency of ammeter

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
REG Reference to a national code

Ref country code: HK

Ref legal event code: DE

Ref document number: 40038178

Country of ref document: HK