CN112035350B - Test method and device for block chain system and computer equipment - Google Patents
Test method and device for block chain system and computer equipment Download PDFInfo
- Publication number
- CN112035350B CN112035350B CN202010877316.4A CN202010877316A CN112035350B CN 112035350 B CN112035350 B CN 112035350B CN 202010877316 A CN202010877316 A CN 202010877316A CN 112035350 B CN112035350 B CN 112035350B
- Authority
- CN
- China
- Prior art keywords
- resource consumption
- intelligent contract
- target
- blockchain system
- contract
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Preventing errors by testing or debugging software
- G06F11/3668—Software testing
- G06F11/3672—Test management
- G06F11/3688—Test management for test execution, e.g. scheduling of test suites
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06Q—INFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
- G06Q20/00—Payment architectures, schemes or protocols
- G06Q20/04—Payment circuits
- G06Q20/06—Private payment circuits, e.g. involving electronic currency used among participants of a common payment scheme
- G06Q20/065—Private payment circuits, e.g. involving electronic currency used among participants of a common payment scheme using e-cash
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Business, Economics & Management (AREA)
- General Physics & Mathematics (AREA)
- Accounting & Taxation (AREA)
- Physics & Mathematics (AREA)
- Strategic Management (AREA)
- General Business, Economics & Management (AREA)
- Finance (AREA)
- Computer Hardware Design (AREA)
- Quality & Reliability (AREA)
- General Engineering & Computer Science (AREA)
- Financial Or Insurance-Related Operations Such As Payment And Settlement (AREA)
- Management, Administration, Business Operations System, And Electronic Commerce (AREA)
Abstract
The embodiment of the application provides a testing method, a testing device and computer equipment for a block chain system, wherein the method comprises the following steps: acquiring an intelligent contract set comprising a first reference intelligent contract and a second reference intelligent contract; deploying a first reference intelligent contract and a second reference intelligent contract into a block chain system, and acquiring a first resource consumption corresponding to the first reference intelligent contract and a second resource consumption corresponding to the second reference intelligent contract; merging the first reference intelligent contract and the second reference intelligent contract to obtain a target intelligent contract, deploying the target intelligent contract into a block chain system, and obtaining target resource consumption corresponding to the target intelligent contract; and determining a test result of a resource consumption calculation mechanism of the intelligent contract according to the first resource consumption, the second resource consumption and the target resource consumption. By adopting the mode, the automatic test of the resource consumption computing mechanism of the intelligent contract can be realized.
Description
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a method and an apparatus for testing a block chain system, a computer device, and a computer-readable storage medium.
Background
Since the birth of Bizhou, blockchain technology is gradually known, trusted and widely used. The block chain technology is a multi-party common maintenance technology, adopts cryptography to ensure transmission and access safety, and can realize consistent data storage, difficult tampering and repudiation prevention, namely a distributed accounting book technology.
Because the block chain technology service based on the bit currency has the problem of insufficient expansibility, the intelligent contract solution is introduced into subsequent block chain products such as an Ether shop and the like, so that the application of the block chain is expanded to all business logics from simple payment transfer, and decentralized automatic execution of the contract is realized.
For the block chain underlying technology, Gas (i.e. the counting unit of the cost consumed when performing the operation on the chain) is required for the operation of the intelligent contract as the execution procedure cost to guarantee the acquisition of the corresponding operation and storage resources. In practical application, the accuracy of the Gas computing mechanism of the intelligent contract in the block chain system needs to be ensured, and the condition of charge confusion cannot occur, otherwise, the reliability and the continuous development of the underlying technology of the block chain are damaged. Therefore, how to test the accuracy of the Gas computing mechanism of the intelligent contract is a problem which needs to be solved urgently at present.
Disclosure of Invention
The embodiment of the application provides a testing method and device for a block chain system and computer equipment, which can realize automatic testing of a resource consumption computing mechanism of an intelligent contract, effectively improve testing efficiency and effectively ensure accuracy of a testing result.
In one aspect, an embodiment of the present application provides a testing method for a blockchain system, where the method is used to test a resource consumption calculation mechanism in the blockchain system, and the blockchain system calculates a resource consumption of an intelligent contract through the resource consumption calculation mechanism, where the method includes:
obtaining an intelligent contract set, wherein the intelligent contract set comprises a first reference intelligent contract and a second reference intelligent contract;
deploying the first reference intelligent contract and the second reference intelligent contract into the blockchain system, and acquiring a first resource consumption amount corresponding to the first reference intelligent contract and a second resource consumption amount corresponding to the second reference intelligent contract under the blockchain system;
merging the first reference intelligent contract and the second reference intelligent contract to obtain a target intelligent contract, deploying the target intelligent contract into the block chain system, and acquiring the target resource consumption corresponding to the target intelligent contract under the block chain system;
and determining a test result of a resource consumption calculation mechanism related to the intelligent contract in the blockchain system according to the first resource consumption, the second resource consumption and the target resource consumption.
In one aspect, an embodiment of the present application provides a testing apparatus, where the apparatus is configured to test a resource consumption calculation mechanism in a blockchain system, and the blockchain system calculates a resource consumption of an intelligent contract through the resource consumption calculation mechanism, where the apparatus includes:
an acquisition unit configured to acquire an intelligent contract set, the intelligent contract set including a first reference intelligent contract and a second reference intelligent contract;
the processing unit is used for deploying the first reference intelligent contract and the second reference intelligent contract into the blockchain system, and acquiring a first resource consumption amount corresponding to the first reference intelligent contract and a second resource consumption amount corresponding to the second reference intelligent contract under the blockchain system;
the merging unit is used for merging the first reference intelligent contract and the second reference intelligent contract to obtain a target intelligent contract;
the processing unit is further configured to deploy the target intelligent contract to the blockchain system, and obtain a target resource consumption amount corresponding to the target intelligent contract in the blockchain system; and determining a test result of a resource consumption calculation mechanism related to the intelligent contract in the blockchain system according to the first resource consumption, the second resource consumption and the target resource consumption.
In an embodiment, the merging unit is specifically configured to: carrying out AST (abstract syntax tree) structuralization on the first reference intelligent contract to obtain a first AST data structure; AST structuring is carried out on the second reference intelligent contract to obtain a second AST data structure; determining a target smart contract based on the first AST data structure and the second AST data structure.
In an embodiment, the merging unit is specifically configured to: merging the first AST data structure and the second AST data structure to form a new AST data structure; a target intelligent contract is determined based on the new AST data structure.
In an embodiment, the processing unit is specifically configured to: determining a sum of resource consumption amounts of the first resource consumption amount and the second resource consumption amount; comparing the total resource consumption with the target resource consumption to obtain a comparison result; and determining a test result of a resource consumption calculation mechanism related to the intelligent contract in the blockchain system according to the comparison result.
In an embodiment, the processing unit is specifically configured to: if the comparison result indicates that the target resource consumption is greater than the sum of the resource consumption, determining that a test result of a resource consumption calculation mechanism related to an intelligent contract in the blockchain system is abnormal; and if the comparison result indicates that the target resource consumption is less than or equal to the sum of the resource consumption, determining that the test result of the resource consumption calculation mechanism related to the intelligent contract in the blockchain system is normal.
In an embodiment, the processing unit is specifically configured to: if the comparison result indicates that the target resource consumption is less than or equal to the sum of the resource consumption and the target resource consumption is detected to be greater than or equal to a third resource consumption, determining that a test result of a resource consumption calculation mechanism related to an intelligent contract in the blockchain system is normal;
the processing unit is further configured to determine that a test result of a resource consumption calculation mechanism related to an intelligent contract in the blockchain system is abnormal if it is detected that the target resource consumption is smaller than the third resource consumption.
In an embodiment, the obtaining unit is further configured to obtain a basic calculation rule regarding resource consumption of the intelligent contract;
the processing unit is further configured to: calculating the reference resource consumption of the first benchmark intelligent contract and the reference resource consumption of the second benchmark intelligent contract according to the basic calculation rule; and if the reference resource consumption of the first benchmark intelligent contract is matched with the first resource consumption and the reference resource consumption of the second benchmark intelligent contract is matched with the second resource consumption, triggering the merging unit to merge the first benchmark intelligent contract and the second benchmark intelligent contract to obtain a target intelligent contract.
Accordingly, an embodiment of the present application provides a computer device, including: the system comprises a processor, a communication interface and a memory, wherein the processor, the communication interface and the memory are connected with each other, the memory stores executable program codes, and the processor is used for calling the executable program codes and executing the test method for the blockchain system.
Accordingly, the present application also provides a computer-readable storage medium, which stores instructions that, when executed on a computer, cause the computer to execute the above testing method for the blockchain system.
Accordingly, embodiments of the present application also provide a computer program product or a computer program, which includes computer instructions stored in a computer-readable storage medium. The computer instructions are read from the computer readable storage medium by a processor of a computer device, and the computer instructions are executed by the processor to cause the computer device to execute the test method for the blockchain system.
According to the method and the device for testing the resource consumption of the intelligent contract, the first resource consumption corresponding to the first reference intelligent contract and the second resource consumption corresponding to the second reference intelligent contract under the block chain system are obtained, the first reference intelligent contract and the second reference intelligent contract are combined into the target intelligent contract, the target resource consumption corresponding to the target intelligent contract under the block chain system is obtained, and finally the test result of the resource consumption computing mechanism of the intelligent contract in the block chain system is determined according to the first resource consumption, the second resource consumption and the target resource consumption, so that the automatic test of the resource consumption computing mechanism of the intelligent contract can be achieved, the test efficiency of the resource consumption computing mechanism of the intelligent contract is effectively improved, and the accuracy of the test result can be effectively guaranteed.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present application, and for those skilled in the art, other drawings can be obtained according to the drawings without creative efforts.
Fig. 1 is a block chain system according to an embodiment of the present disclosure;
fig. 2 is a schematic structural diagram of a block according to an embodiment of the present disclosure;
FIG. 3 is a block chain system according to another embodiment of the present disclosure;
FIG. 4 is a block diagram of a test system according to an embodiment of the present disclosure;
fig. 5 is a flowchart illustrating a testing method for a blockchain system according to an embodiment of the present disclosure;
FIG. 6 illustrates one manner of obtaining resource consumption by a benchmark smart contract;
fig. 7 illustrates one manner in which an AST is structured and two intelligent contracts are merged;
FIG. 8 illustrates one manner of obtaining resource consumption by a consolidated intelligent contract;
FIG. 9 is a schematic structural diagram of a testing apparatus according to an embodiment of the present disclosure;
fig. 10 is a schematic structural diagram of a computer device according to an embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
With the coming of the scientific and technological era and the development of the mobile internet, the pace of network revolution is getting faster and faster, the information fusion of the same field or multiple fields is realized, and the process of providing an all-dimensional informatization scheme for customers also faces new challenges of improving the system structure, supporting gravity center transfer and the like. Therefore, the blockchain technology, as a specific implementation of the distributed ledger, is gradually becoming the preferred way to store data and transaction data in various fields by virtue of its natural advantages of storing and managing data.
The blockchain system is a distributed system and can be formed by connecting a plurality of nodes in a network communication mode. The node may be any computing device in the access network, such as a server, a terminal, and other computing devices. The server may be an independent physical server, a server cluster or a distributed system formed by a plurality of physical servers, or a cloud server providing basic cloud computing services such as cloud service, a cloud database, cloud computing, a cloud function, cloud storage, network service, cloud communication, middleware service, domain name service, security service, CDN, and a big data and artificial intelligence platform. The terminal may be a smart phone (e.g., an Android phone, an iOS phone, etc.), a tablet computer, a notebook computer, a desktop computer, a smart speaker, a smart watch, etc., but is not limited thereto. The nodes may be directly or indirectly connected through wired or wireless communication, and the application is not limited herein.
Fig. 1 is a schematic diagram of an alternative architecture of a blockchain system according to an embodiment of the present invention. The block chain system is formed by a plurality of nodes, a point-To-point (P2P, Peer To Peer) network is formed among the nodes, and the P2P Protocol is an application layer Protocol operating on a Transmission Control Protocol (TCP). In the blockchain system, any machine such as a server and a terminal can be added to become a node, and the node comprises a hardware layer, a middle layer, an operating system layer and an application layer.
Referring to the functions of each node in the blockchain system shown in fig. 1, the functions involved include:
1) routing, a basic function that a node has, is used to support communication between nodes.
Besides the routing function, the node may also have the following functions:
2) the Block chain comprises a series of blocks (blocks) which are connected with each other according to the generated chronological order, new blocks cannot be removed once being added into the Block chain, and recorded data submitted by nodes in the Block chain system, such as transaction data and the like, are recorded in the blocks.
Referring to fig. 2, which is an optional schematic diagram of a Block Structure (Block Structure) provided in the embodiment of the present application, each Block includes a hash value of a data record stored in the Block (hash value of the Block) and a hash value of a previous Block, and the blocks are connected by the hash values to form a Block chain (Block chain). The block may include information such as a time stamp at the time of block generation. A blockchain, which is essentially a decentralized database, is a string of data blocks associated using cryptography, each data block containing relevant information for verifying the validity of the information (anti-counterfeiting) and generating the next block.
3) The application is used for being deployed in a block chain, realizing specific services according to actual service requirements, recording data related to the realization functions to form recording data, carrying a digital signature in the recording data to represent a source of task data, and sending the recording data to other nodes in the block chain system, so that the other nodes add the recording data to a temporary block when the source and integrity of the recording data are verified successfully.
For example, the services implemented by the application include:
and 3.1) the wallet is used for providing a function of performing transaction of virtual resources, wherein the function comprises initiating transaction, namely, sending the transaction record of the current transaction to other nodes in the blockchain system, and storing the record data of the transaction into a temporary block of the blockchain as a response for confirming that the transaction is valid after the other nodes are successfully verified.
And 3.2) sharing the account book, wherein the shared account book is used for providing functions of operations such as storage, inquiry and modification of account data, the recorded data of the operations on the account data are sent to other nodes in the block chain system, and after the other nodes verify the validity, the recorded data are stored in the temporary block as a response for acknowledging that the account data are valid, and confirmation can be sent to the node initiating the operations.
3.3) Intelligent contracts, computerized agreements, which can execute the terms of a certain contract, are realized by codes deployed on a shared book for execution when certain conditions are met, and are used for completing automated transactions according to actual business requirement codes, such as querying the logistics state of goods purchased by buyers, and transferring virtual resources of the buyers to the addresses of merchants after the buyers sign for goods; of course, smart contracts are not limited to executing contracts for trading, but may also execute contracts that process received information.
4) And the consensus is used for solving and ensuring the consistency and correctness of each transaction or data on all accounting nodes. The consensus mechanism of blockchains is the way to determine a certain consensus and maintain consensus. The consensus mechanism of the block chain enables the block chain to still cooperate and complete the operation efficiently in a large scale without depending on centralized organization.
Fig. 3 is a schematic diagram of another block chain system according to an embodiment of the present disclosure. As shown in fig. 3, the nodes in the blockchain system may include terminal devices corresponding to banks, insurance companies, government buildings, shops, schools, hospitals, and the like. The terminal devices corresponding to the bank, the insurance company, the government building, the shop, the school and the hospital all participate in the management and the processing of the same blockchain system, and also participate in the monitoring of the legality of the transaction so as to achieve the fairness of the blockchain system in the processing or the storage of the transaction data. Meanwhile, the bank, the insurance company, the government building, the shop, the school and the hospital belong to different fields, and the quality and the efficiency of social work can be better improved through information fusion and interaction in the different fields. Any node in the blockchain system can check the acquired transaction data, and when the check result is that the check is successful, a block can be generated based on the transaction data and issued to the blockchain, so that other terminal devices in the blockchain system can perform distributed storage on the block. And each terminal device can perform distributed storage on the block after the block consensus passes. For example, as shown in fig. 3, the nodes in the blockchain system may include terminal devices corresponding to banks, insurance companies, government buildings, shops, schools, and hospitals, and the terminal devices corresponding to the banks, insurance companies, government buildings, shops, schools, and hospitals may store the identity information of the same user a in a distributed manner, so that the user a to any one of the institutions may query the identity information of the user a.
Because the block chain technology service based on the bit currency has the problem of insufficient expansibility, the intelligent contract solution is introduced into subsequent block chain products such as an Ether shop and the like, so that the application of the block chain is expanded to all business logics from simple payment transfer, and decentralized automatic execution of the contract is realized. With the development of blockchain technology and intelligent contract technology, more and more decentralized applications will run in blockchain systems using intelligent contracts in the future. For the block chain underlying technology, a Gas (i.e. a counting unit of cost required to be consumed when performing operations on a chain) value is set according to different operation instructions and storage resource conditions, and various operation and storage combinations can be generated in the intelligent operation process to meet the requirements of the intelligent operation chain underlying technology. The operation of the intelligent contract requires Gas as an execution commission to ensure that the corresponding operation and storage resources are obtained. A Gas computing mechanism of the smart contract is typically deployed in the blockchain system to compute the amount of Gas that the smart contract needs to consume during operation. In practical application, the accuracy of a Gas computing mechanism of an intelligent contract deployed in a block chain system needs to be ensured, and a messy charging situation cannot occur, otherwise, the reliability and the continuous development of the underlying technology of the block chain are damaged. Therefore, how to test the accuracy of the Gas computing mechanism of the intelligent contract is a problem which needs to be solved urgently at present.
Based on this, the present application provides a testing method for a blockchain system, the method is used for testing a resource consumption calculation mechanism (i.e., a Gas calculation mechanism) deployed in the blockchain system, wherein the blockchain system calculates a resource consumption (i.e., a Gas value, or an operating Gas value) of an intelligent contract through the resource consumption calculation mechanism. Fig. 4 shows a system architecture to which the test method for the blockchain system is applied. The system comprises a test platform and a blockchain system, wherein the blockchain system comprises a plurality of nodes. In this case, the test platform is a computer device that exists independently of the blockchain system, and a communication connection is established between the test platform and the blockchain system. In a possible embodiment, the test platform may also be a node in the blockchain system.
Specifically, the test platform acquires a first reference intelligent contract and a second reference intelligent contract from an intelligent contract set, and acquires a first resource consumption amount corresponding to the first reference intelligent contract and a second resource consumption amount corresponding to the second reference intelligent contract under the blockchain system by deploying the first reference intelligent contract and the second reference intelligent contract into the blockchain system; then merging the first reference intelligent contract and the second reference intelligent contract to obtain a target intelligent contract, and deploying the target intelligent contract into the block chain system to obtain the target resource consumption corresponding to the target intelligent contract under the block chain system; and finally determining a test result of a resource consumption calculation mechanism about the intelligent contract deployed in the block chain system according to the obtained first resource consumption, the obtained second resource consumption and the obtained target resource consumption. The obtained test result is used for indicating whether the resource consumption calculation mechanism of the intelligent contract is normal or not, and if the resource consumption calculation mechanism is normal, the accuracy of the resource consumption calculation mechanism is better and meets the requirement; the exception indicates that the resource consumption calculation mechanism is inaccurate, and a certain problem exists. By adopting the mode, the automatic test of the resource consumption computing mechanism about the intelligent contract deployed in the block chain system can be realized, so that the test efficiency of the resource consumption computing mechanism about the intelligent contract is effectively improved; the accuracy of the test result can be effectively ensured.
The main steps of the testing method for the blockchain system described in the embodiments of the present application are introduced above, and the following describes each step of the testing method for the blockchain system in detail. Please refer to fig. 5, which is a flowchart illustrating a testing method for a blockchain system according to an embodiment of the present disclosure. The testing method described in the embodiment of the present application is executed by a testing platform (for example, as shown in fig. 4), and the testing method is used for testing a resource consumption calculation mechanism about an intelligent contract, which is deployed in a blockchain system (for example, as shown in fig. 4), wherein the blockchain system calculates the resource consumption of the intelligent contract through the resource consumption calculation mechanism, and under the same resource consumption calculation mechanism, the more operations corresponding to the intelligent contract, the higher the resource consumption, and vice versa, the lower the resource consumption. The testing method for the block chain system includes but is not limited to the following steps:
s501, the test platform obtains an intelligent contract set, wherein the intelligent contract set comprises a first reference intelligent contract and a second reference intelligent contract.
In the embodiment of the application, the test platform can acquire the intelligent contract set from an internal database or an external database. The intelligent contract set comprises at least two reference intelligent contracts, the reference intelligent contracts can be predefined operation classes or independently-operated intelligent contracts of resource classes, and the operation classes refer to various calculation processing on data, such as accumulated amount of money on a certain field of the data; the resource class refers to operations such as adding, deleting, modifying and checking data, and the like, wherein the data are related to storage operations. In one embodiment, the at least two reference smart contracts may be in an orthogonal relationship, where orthogonal means that the functions involved between the reference smart contracts are not duplicated. It should be noted that the intelligent contracts described in the embodiments of the present application may refer to intelligent contract codes, and the reference intelligent contracts in the intelligent contract set may be written into the internal database or the external database by a tester in advance.
The at least two reference intelligent contracts comprise a first reference intelligent contract and a second reference intelligent contract, wherein the first reference intelligent contract is any one of the at least two reference intelligent contracts and can be an independently-operated intelligent contract of an operation class or a resource class; the second reference intelligent contract is any one of the at least two reference intelligent contracts except the first reference intelligent contract, and can be an independently-operated intelligent contract of an operation class or a resource class. As previously described, the first reference smart contract and the second reference smart contract may be in an orthogonal relationship.
S502, the test platform deploys the first reference intelligent contract and the second reference intelligent contract to a blockchain system, and obtains a first resource consumption amount corresponding to the first reference intelligent contract and a second resource consumption amount corresponding to the second reference intelligent contract in the blockchain system.
In the embodiment of the application, a test platform acquires a first resource consumption amount corresponding to a first reference intelligent contract under a blockchain system by deploying the first reference intelligent contract into the blockchain system; and acquiring a second resource consumption corresponding to the second reference intelligent contract under the blockchain system by deploying the second reference intelligent contract into the blockchain system. It should be noted that the test platform may deploy the first reference intelligent contract and the second reference intelligent contract to the blockchain system at the same time, or may deploy the first reference intelligent contract and the second reference intelligent contract to the blockchain system sequentially.
During the process of deploying the first reference intelligent contract, the blockchain system calculates a first resource consumption (i.e. a first Gas value) of the first reference intelligent contract through a resource consumption calculation mechanism (i.e. a Gas calculation mechanism) about the intelligent contract, which is deployed in advance by the blockchain system, and returns the first resource consumption corresponding to the first reference intelligent contract to the test platform after the first reference intelligent contract is deployed successfully. Similarly, in the process of deploying the second reference intelligent contract, the blockchain system calculates a second resource consumption (i.e. a second Gas value) of the second reference intelligent contract through a resource consumption calculation mechanism about the intelligent contract, which is deployed in advance by the blockchain system, and returns the second resource consumption corresponding to the second reference intelligent contract to the test platform after the second reference intelligent contract is deployed successfully. It should be noted that, deploying the intelligent contracts into the blockchain system may refer to deploying the intelligent contracts onto one or more nodes supporting intelligent contract deployment in the blockchain system; successful deployment of the intelligent contract may refer to successful chaining of the intelligent contract.
And S503, the test platform combines the first reference intelligent contract and the second reference intelligent contract to obtain a target intelligent contract.
In the embodiment of the application, the test platform performs AST structuring on the first reference intelligent contract to obtain a first AST data structure; and AST structuring is carried out on the second reference intelligent contract to obtain a second AST data structure. AST structuring refers to a data structure that parses source code as plain text into an Abstract Syntax Tree (AST), which is an intermediate representation of a program. For example, as shown in fig. 7, after the intelligent contract AST of the operation class is structured, its AST data structure is composed of a root node, a deployment function, and an operation function (which also includes a calculation rule, a variable, and the like); after the AST is structured, the AST data structure is composed of a root node, a storage structure (again including variables, etc.), and deployment functions (again including initializing the storage structure, etc.). The deployment function is used for indicating that the intelligent contract is issued to a deployment operation to be executed on a chain, the storage structure body is a code structure mapped to a global space on the chain, for example, the structure body Person { name, age }, and is mapped to a Person table in a database of the global space, and the name and the age are columns.
After parsing to obtain a first AST data structure for a first baseline smart contract and parsing to obtain a second AST data structure for a second baseline smart contract, the testing platform determines a target smart contract based on the first AST data structure and the second AST data structure. In one embodiment, the test platform combines the first AST data structure and the second AST data structure to form a new AST data structure. For example, as shown in fig. 7, after the AST data structure of the operation-type intelligence contract and the AST data structure of the resource-type intelligence contract are merged, the obtained new AST data structure is composed of a root node, a storage structure, a deployment function, and an operation function. Further, the test platform determines a target intelligent contract according to the determined new AST data structure. In one embodiment, the test platform determines a code of the target intelligent contract according to the determined new AST data structure, the source code of the first reference intelligent contract, and the source code of the second reference intelligent contract, so as to obtain the target intelligent contract. By adopting the mode, the merging effectiveness of the intelligent contract can be effectively ensured through the AST structuring mode.
In an embodiment, the test platform combines the first reference intelligent contract and the second reference intelligent contract, and before the target intelligent contract is obtained, the accuracy of the first resource consumption and the accuracy of the second resource consumption are verified, so that the accuracy of a subsequent test result is ensured. Specifically, the test platform first obtains the basic calculation rule about the resource consumption of the intelligent contract from the internal database or the external database. The underlying calculation rule may be an underlying calculation formula (i.e., an underlying Gas charge definition formula) defined by the relevant organization and exposed to the external public regarding the resource consumption of the intelligent contract. The basic calculation rule may be directly used as a calculation mechanism for resource consumption of the intelligent contract deployed by the blockchain system, or may be used as a calculation mechanism for resource consumption of the intelligent contract deployed by the blockchain system after a certain adjustment is made based on the basic calculation rule, for example, the basic calculation formula is further multiplied by an appropriate weight, and a value range of the weight may be specified by a relevant organization, for example, [0.7, 1.2 ].
Further, the test platform calculates the reference resource consumption of the first benchmark intelligent contract and calculates the reference resource consumption of the second benchmark intelligent contract according to the basic calculation rule. If the reference resource consumption of the first benchmark intelligent contract is matched with the first resource consumption (for example, the ratio of the first resource consumption to the reference resource consumption is within the value range), and the reference resource consumption of the second benchmark intelligent contract is matched with the second resource consumption (for example, the ratio of the second resource consumption to the reference resource consumption is within the value range), step S503 is executed to combine the first benchmark intelligent contract and the second benchmark intelligent contract to obtain the target intelligent contract. If the reference resource consumption of the first benchmark intelligent contract does not match the first resource consumption, or the reference resource consumption of the second benchmark intelligent contract does not match the second resource consumption, it may be directly determined that the test result of the resource consumption calculation mechanism related to the intelligent contract deployed in the block chain system is abnormal. The exception indicates that the resource consumption calculation mechanism is inaccurate, and a certain problem exists.
S504, the testing platform deploys the target intelligent contract into the blockchain system, and target resource consumption corresponding to the target intelligent contract under the blockchain system is obtained.
In the embodiment of the application, the test platform acquires the target resource consumption corresponding to the target standard intelligent contract under the blockchain system by deploying the target intelligent contract into the blockchain system. In the process of deploying the target intelligent contract, the blockchain system calculates the target resource consumption (namely the target Gas value) of the target reference intelligent contract through a resource consumption calculation mechanism (namely a Gas calculation mechanism) which is deployed in advance by the blockchain system and is related to the intelligent contract, and returns the target resource consumption corresponding to the target intelligent contract to the test platform after the target intelligent contract is deployed successfully. It should be noted that, deploying the intelligent contracts into the blockchain system may refer to deploying the intelligent contracts onto one or more nodes supporting intelligent contract deployment in the blockchain system; successful deployment of the intelligent contract may refer to successful chaining of the intelligent contract.
And S505, the testing platform determines a testing result of a resource consumption calculation mechanism related to the intelligent contract in the blockchain system according to the first resource consumption, the second resource consumption and the target resource consumption.
In the embodiment of the application, the test platform determines the sum of the resource consumption of the first resource consumption and the second resource consumption, and compares the sum of the resource consumption with the target resource consumption to obtain a comparison result; and determining a test result of the resource consumption calculation mechanism related to the intelligent contract in the blockchain system according to the comparison result.
In an embodiment, if the comparison result indicates that the target resource consumption is less than or equal to the sum of the resource consumption of the first resource consumption and the second resource consumption, the test result of the resource consumption calculation mechanism for the intelligent contract deployed in the blockchain system is determined to be normal. And if the resource consumption is normal, the accuracy of the resource consumption calculation mechanism is better and meets the requirement. On the contrary, if the comparison result indicates that the target resource consumption is greater than the sum of the resource consumption of the first resource consumption and the second resource consumption, determining that the test result of the resource consumption calculation mechanism related to the intelligent contract deployed in the blockchain system is abnormal. The exception indicates that the resource consumption calculation mechanism is inaccurate, and a certain problem exists.
The reason why the judgment can be made accordingly is that under the same resource consumption calculation mechanism, the more the corresponding operations of the intelligent contract are, the higher the resource consumption is, and otherwise, the lower the resource consumption is; the target intelligent contract is obtained by combining the first reference intelligent contract and the second reference intelligent contract, and the same operation in the first reference intelligent contract and the second reference intelligent contract can be combined in the combining process, so that the operation corresponding to the target intelligent contract is necessarily less than or equal to the sum of the operation corresponding to the first reference intelligent contract and the second reference intelligent contract. If the same operation in the first reference intelligent contract and the second reference intelligent contract is not merged in the merging process, even if the same operation exists in the target intelligent contract obtained by merging, the same operation does not need to be repeatedly executed in the actual application process, and if the same operation is not repeatedly executed, the resource consumption of the same operation is calculated only once and is not calculated for multiple times. Therefore, if the resource consumption calculation mechanism for the intelligent contract deployed in the blockchain system is normal, the target resource consumption corresponding to the target intelligent contract is necessarily less than or equal to the sum of the resource consumption of the first resource consumption and the second resource consumption. Therefore, the test result determined by the method has higher accuracy.
In another embodiment, the test platform compares the target resource consumption with a third resource consumption in addition to comparing the sum of the first resource consumption and the second resource consumption with the target resource consumption. The third resource consumption may be a minimum value of resource consumption corresponding to any two reference intelligent contracts in the intelligent contract set after merging, where the minimum value may be obtained experimentally or calculated according to the basic calculation rule described above.
And if the comparison result indicates that the target resource consumption is less than or equal to the sum of the resource consumption of the first resource consumption and the resource consumption of the second resource consumption, and the target resource consumption is detected to be greater than or equal to the third resource consumption, determining that the test result of the resource consumption calculation mechanism related to the intelligent contract deployed in the blockchain system is normal. And if the resource consumption is normal, the accuracy of the resource consumption calculation mechanism is better and meets the requirement. On the contrary, if the comparison result indicates that the target resource consumption is greater than the sum of the resource consumption of the first resource consumption and the resource consumption of the second resource consumption, or the target resource consumption is detected to be less than the third resource consumption, it is determined that the test result of the resource consumption calculation mechanism related to the intelligent contract deployed in the blockchain system is abnormal. The exception indicates that the resource consumption calculation mechanism is inaccurate, and a certain problem exists. By adopting the mode, the accuracy of the test result can be further improved to a certain extent.
In a possible embodiment, before the testing platform determines the testing result of the resource consumption calculation mechanism for the intelligent contract deployed in the blockchain system according to the first resource consumption, the second resource consumption and the target resource consumption, the reference resource consumption of the target intelligent contract is calculated according to the basic calculation rule for the resource consumption of the intelligent contract described above. If the reference resource consumption of the target intelligent contract matches the target resource consumption, step S505 is executed to determine a test result of the resource consumption calculation mechanism related to the intelligent contract in the blockchain system according to the first resource consumption, the second resource consumption and the target resource consumption. If the reference resource consumption of the target intelligent contract does not match with the target resource consumption, the test result of the resource consumption calculation mechanism related to the intelligent contract, which is deployed in the blockchain system, can be directly determined to be abnormal.
In another possible embodiment, after the testing platform determines that the testing result of the resource consumption calculation mechanism related to the intelligent contract deployed in the blockchain system is normal according to the first resource consumption, the second resource consumption and the target resource consumption, the testing platform obtains a new first reference intelligent contract and a new second reference intelligent contract from the intelligent contract set again, and performs steps S502 to S505 based on the new first reference intelligent contract and the new second reference intelligent contract to determine again the testing result of the resource consumption calculation mechanism related to the intelligent contract deployed in the blockchain system. If the new test result is abnormal, determining that the test result of the resource consumption calculation mechanism about the intelligent contract deployed in the block chain system is abnormal; if the new test result is normal, repeating the steps until the combination number of the detected reference intelligent contracts exceeds the preset number; and if the test results are normal in the process, determining that the test result of the resource consumption calculation mechanism related to the intelligent contract deployed in the block chain system is normal. By adopting the mode, the accuracy of the test result can be further improved.
In the embodiment of the application, when it is determined that the test result of the resource consumption calculation mechanism about the intelligent contract deployed in the blockchain system is abnormal, abnormal prompt information can be output to prompt a tester that the resource consumption calculation mechanism deployed in the blockchain system tested is abnormal. In a feasible implementation manner, the test platform may further perform anomaly analysis on a resource consumption calculation mechanism deployed in the tested blockchain system, and generate a test report, so that a tester can quickly locate a problem.
According to the method and the device for testing the resource consumption of the intelligent contract, the first resource consumption corresponding to the first reference intelligent contract and the second resource consumption corresponding to the second reference intelligent contract under the block chain system are obtained, the first reference intelligent contract and the second reference intelligent contract are combined into the target intelligent contract, the target resource consumption corresponding to the target intelligent contract under the block chain system is obtained, and finally the test result of the resource consumption computing mechanism of the intelligent contract in the block chain system is determined according to the first resource consumption, the second resource consumption and the target resource consumption, so that the automatic test of the resource consumption computing mechanism of the intelligent contract can be achieved, the test efficiency of the resource consumption computing mechanism of the intelligent contract is effectively improved, and the accuracy of the test result can be effectively guaranteed.
To better understand the testing method described in the embodiment of the present application for the resource consumption calculation mechanism (i.e., Gas calculation mechanism) related to the intelligent contracts deployed in the blockchain system, the following description is made by way of example in conjunction with fig. 6, fig. 7, and fig. 8.
First, as shown in fig. 6, a plurality of orthogonal and independently operable reference intelligent contracts (or reference intelligent contract codes) of the operation class and the resource class are defined, and each reference intelligent contract is deployed into the blockchain system to obtain a Gas value of each orthogonal and independently operable reference intelligent contract returned by the blockchain system.
And under the condition of ensuring that the Gas value of each reference intelligent contract returned by the block chain system is accurate, performing AST structurization on each reference intelligent contract, and realizing code combination through an AST node, thereby realizing that the reference intelligent contracts are combined pairwise to form a new intelligent contract. As shown in fig. 7, an operation-class base intelligence contract and a resource-class base intelligence contract may be combined into a new intelligence contract. Because the reference intelligent contract is a code class, grammatical or semantic problems can be caused by directly combining the source codes in a text mode; therefore, according to the embodiment of the application, an AST structuring mode is adopted, and then merging is carried out, after the AST structuring, two AST data structures can be quickly and effectively merged together to form a new AST structure tree, and then two reference intelligent contracts are quickly merged to form a new intelligent contract; in addition, the merging effectiveness of the intelligent contracts can be ensured through the AST structuring mode. Further, as shown in fig. 8, two-by-two merged intelligent contracts are deployed into the blockchain system to obtain Gas values required by the merged intelligent contracts returned by the blockchain system.
Even if the same operation exists in the combined intelligent contracts, the same operation does not need to be repeatedly executed in the actual application process, and the resource consumption of the same operation is calculated only once and not for many times if the operation is not repeatedly executed; the Gas value required by the merged smart contract will necessarily be less than or equal to the sum of the Gas values of the two reference smart contracts. If the combined intelligent contract has the calculation of the same operation, the Gas value required by the combined intelligent contract is inevitably smaller than the sum of the Gas values of the two reference intelligent contracts; however, if the merged smart contract does not have the same operation calculation, the Gas value required by the merged smart contract is equal to the sum of the Gas values of the two reference smart contracts. Based on this, the test result of the resource consumption calculation mechanism on the intelligent contract deployed in the blockchain system can be accurately determined based on the magnitude relation between the Gas value required by the merged intelligent contract and the sum of the Gas values of the two reference intelligent contracts. Specifically, if it is detected that the Gas value required by the merged intelligent contract is less than or equal to the sum of the Gas values of the two reference intelligent contracts, it is determined that the test result of the resource consumption calculation mechanism for the intelligent contract in the block chain system is normal. And if the resource consumption is normal, the accuracy of the resource consumption calculation mechanism is better and meets the requirement. On the contrary, if the Gas value required by the combined intelligent contract is detected to be larger than the sum of the Gas values of the two reference intelligent contracts, the test result of the resource consumption calculation mechanism of the intelligent contract in the block chain system is determined to be abnormal. The exception indicates that the resource consumption calculation mechanism is inaccurate, and a certain problem exists.
By adopting the mode, the orthogonal and independently-operated intelligent contracts of the calculation classes and the resources classes can be used for carrying out combined test according to the characteristics of the intelligent contracts provided by the block chain technology, so that on one hand, the integrity of the operation and storage capacity of the intelligent contracts can be ensured, on the other hand, the corresponding Gas values returned by the block chain system can be rapidly acquired, and the test efficiency is improved. In addition, the merging effectiveness of the intelligent contract can be ensured through the AST structuring mode, so that the accuracy of the test result can be ensured.
Please refer to fig. 9, which is a schematic structural diagram of a testing apparatus according to an embodiment of the present disclosure. The testing apparatus described in the embodiment of the present application corresponds to the testing platform described above, and is configured to test a resource consumption calculation mechanism in a blockchain system, where the blockchain system calculates resource consumption of an intelligent contract through the resource consumption calculation mechanism; the test device includes:
an obtaining unit 901, configured to obtain an intelligent contract set, where the intelligent contract set includes a first reference intelligent contract and a second reference intelligent contract;
a processing unit 902, configured to deploy the first reference intelligent contract and the second reference intelligent contract into the blockchain system, and obtain a first resource consumption amount corresponding to the first reference intelligent contract and a second resource consumption amount corresponding to the second reference intelligent contract in the blockchain system;
a merging unit 903, configured to merge the first reference intelligent contract and the second reference intelligent contract to obtain a target intelligent contract;
the processing unit 902 is further configured to deploy the target intelligent contract into the blockchain system, and obtain a target resource consumption amount corresponding to the target intelligent contract in the blockchain system; and determining a test result of a resource consumption calculation mechanism related to the intelligent contract in the blockchain system according to the first resource consumption, the second resource consumption and the target resource consumption.
In an embodiment, the merging unit 903 is specifically configured to: carrying out AST (abstract syntax tree) structuralization on the first reference intelligent contract to obtain a first AST data structure; AST structuring is carried out on the second reference intelligent contract to obtain a second AST data structure; determining a target smart contract based on the first AST data structure and the second AST data structure.
In an embodiment, the merging unit 903 is specifically configured to: merging the first AST data structure and the second AST data structure to form a new AST data structure; a target intelligent contract is determined based on the new AST data structure.
In an embodiment, the processing unit 902 is specifically configured to: determining a sum of resource consumption amounts of the first resource consumption amount and the second resource consumption amount; comparing the total resource consumption with the target resource consumption to obtain a comparison result; and determining a test result of a resource consumption calculation mechanism related to the intelligent contract in the blockchain system according to the comparison result.
In an embodiment, the processing unit 902 is specifically configured to: if the comparison result indicates that the target resource consumption is greater than the sum of the resource consumption, determining that a test result of a resource consumption calculation mechanism related to an intelligent contract in the blockchain system is abnormal; and if the comparison result indicates that the target resource consumption is less than or equal to the sum of the resource consumption, determining that the test result of the resource consumption calculation mechanism related to the intelligent contract in the blockchain system is normal.
In an embodiment, the processing unit 902 is specifically configured to: if the comparison result indicates that the target resource consumption is less than or equal to the sum of the resource consumption and the target resource consumption is detected to be greater than or equal to a third resource consumption, determining that a test result of a resource consumption calculation mechanism related to an intelligent contract in the blockchain system is normal;
the processing unit 902 is further configured to determine that a test result of a resource consumption calculation mechanism related to an intelligent contract in the blockchain system is abnormal if it is detected that the target resource consumption is smaller than the third resource consumption.
In an embodiment, the obtaining unit 901 is further configured to obtain a basic calculation rule regarding the resource consumption amount of the smart contract;
the processing unit is further configured to: calculating the reference resource consumption of the first benchmark intelligent contract and the reference resource consumption of the second benchmark intelligent contract according to the basic calculation rule; if the reference resource consumption of the first benchmark intelligent contract is matched with the first resource consumption, and the reference resource consumption of the second benchmark intelligent contract is matched with the second resource consumption, the merging unit 903 is triggered to merge the first benchmark intelligent contract and the second benchmark intelligent contract to obtain the target intelligent contract.
It can be understood that the functions of the functional units of the test apparatus provided in the embodiment of the present application may be specifically implemented according to the method in the foregoing method embodiment, and the specific implementation process may refer to the related description of the foregoing method embodiment, which is not described herein again.
According to the method and the device for testing the resource consumption of the intelligent contract, the first resource consumption corresponding to the first reference intelligent contract and the second resource consumption corresponding to the second reference intelligent contract under the block chain system are obtained, the first reference intelligent contract and the second reference intelligent contract are combined into the target intelligent contract, the target resource consumption corresponding to the target intelligent contract under the block chain system is obtained, and finally the test result of the resource consumption computing mechanism of the intelligent contract in the block chain system is determined according to the first resource consumption, the second resource consumption and the target resource consumption, so that the automatic test of the resource consumption computing mechanism of the intelligent contract can be achieved, the test efficiency of the resource consumption computing mechanism of the intelligent contract is effectively improved, and the accuracy of the test result can be effectively guaranteed.
Please refer to fig. 10, which is a schematic structural diagram of a computer device according to an embodiment of the present application. The computer device described in the embodiment of the present application corresponds to the test platform described above, and the computer device includes: a processor 1001, a user interface 1002, a communication interface 1003, and a memory 1004. The processor 1001, the user interface 1002, the communication interface 1003, and the memory 1004 may be connected by a bus or in other manners, and in the embodiment of the present application, the connection by the bus is taken as an example.
The processor 1001 (or referred to as a Central Processing Unit (CPU)) is a computing core and a control core of the computer device, and can analyze various instructions in the computer device and process various data of the computer device, for example: the CPU can be used for analyzing a power-on and power-off instruction sent to the computer equipment by a user and controlling the computer equipment to carry out power-on and power-off operation; the following steps are repeated: the CPU may transmit various types of interactive data between the internal structures of the computer device, and so on. The user interface 1002 is a medium for implementing interaction and information exchange between a user and a computer device, and may be embodied by a Display screen (Display) for outputting, a touch screen (touchscreen) for inputting, a Keyboard (Keyboard), and the like. The communication interface 1003 may optionally include a standard wired interface, a wireless interface (e.g., Wi-Fi, mobile communication interface, etc.), controlled by the processor 1001 for transmitting and receiving data. The Memory 1004(Memory) is a Memory device in the computer device for storing programs and data. It will be appreciated that the memory 1004 may comprise both internal memory of the computer device and, of course, extended memory supported by the computer device. The memory 1004 provides storage space that stores the operating system of the computer device, which may include, but is not limited to: android system, iOS system, Windows Phone system, etc., which are not limited in this application.
In an embodiment of the present application, the computer device is configured to test a resource consumption calculation mechanism in a blockchain system, where the blockchain system calculates a resource consumption of an intelligent contract through the resource consumption calculation mechanism; specifically, the processor 1001, by executing the executable program code in the memory 1004, performs the following operations:
obtaining an intelligent contract set, wherein the intelligent contract set comprises a first reference intelligent contract and a second reference intelligent contract; deploying the first reference intelligent contract and the second reference intelligent contract into the blockchain system through the communication interface 1003, and acquiring a first resource consumption amount corresponding to the first reference intelligent contract and a second resource consumption amount corresponding to the second reference intelligent contract under the blockchain system; merging the first reference intelligent contract and the second reference intelligent contract to obtain a target intelligent contract, deploying the target intelligent contract into the blockchain system through the communication interface 1003, and acquiring the target resource consumption corresponding to the target intelligent contract under the blockchain system; and determining a test result of a resource consumption calculation mechanism related to the intelligent contract in the blockchain system according to the first resource consumption, the second resource consumption and the target resource consumption.
In an embodiment, when the processor 1001 merges the first reference intelligent contract and the second reference intelligent contract to obtain a target intelligent contract, it is specifically configured to: carrying out AST (abstract syntax tree) structuralization on the first reference intelligent contract to obtain a first AST data structure; AST structuring is carried out on the second reference intelligent contract to obtain a second AST data structure; determining a target smart contract based on the first AST data structure and the second AST data structure.
In an embodiment, when the processor 1001 determines the target smart contract according to the first AST data structure and the second AST data structure, it is specifically configured to: merging the first AST data structure and the second AST data structure to form a new AST data structure; a target intelligent contract is determined based on the new AST data structure.
In an embodiment, when the processor 1001 determines the test result of the resource consumption calculation mechanism related to the intelligent contract in the blockchain system according to the first resource consumption, the second resource consumption and the target resource consumption, the method is specifically configured to: determining a sum of resource consumption amounts of the first resource consumption amount and the second resource consumption amount; comparing the total resource consumption with the target resource consumption to obtain a comparison result; and determining a test result of a resource consumption calculation mechanism related to the intelligent contract in the blockchain system according to the comparison result.
In an embodiment, when the processor 1001 determines the test result of the resource consumption calculation mechanism related to the intelligent contract in the blockchain system according to the comparison result, it is specifically configured to: if the comparison result indicates that the target resource consumption is greater than the sum of the resource consumption, determining that a test result of a resource consumption calculation mechanism related to an intelligent contract in the blockchain system is abnormal; and if the comparison result indicates that the target resource consumption is less than or equal to the sum of the resource consumption, determining that the test result of the resource consumption calculation mechanism related to the intelligent contract in the blockchain system is normal.
In an embodiment, the processor 1001 is specifically configured to: and if the comparison result indicates that the target resource consumption is less than or equal to the sum of the resource consumption and the target resource consumption is detected to be greater than or equal to a third resource consumption, determining that the test result of the resource consumption calculation mechanism related to the intelligent contract in the blockchain system is normal.
Wherein, the processor 1001 is further configured to: and if the target resource consumption is detected to be smaller than the third resource consumption, determining that the test result of a resource consumption calculation mechanism related to the intelligent contract in the blockchain system is abnormal.
In an embodiment, before the processor 1001 merges the first reference smart contract and the second reference smart contract to obtain the target smart contract, the processor is further configured to: acquiring a basic calculation rule about the resource consumption of the intelligent contract; calculating the reference resource consumption of the first benchmark intelligent contract and the reference resource consumption of the second benchmark intelligent contract according to the basic calculation rule; and if the reference resource consumption of the first benchmark intelligent contract is matched with the first resource consumption and the reference resource consumption of the second benchmark intelligent contract is matched with the second resource consumption, combining the first benchmark intelligent contract and the second benchmark intelligent contract to obtain a target intelligent contract.
In an embodiment, when the processor 1001 determines that the test result of the resource consumption calculation mechanism deployed in the blockchain system about the intelligent contract is abnormal, it may output an abnormality prompting message through the user interface 1002 to prompt a tester that the resource consumption calculation mechanism deployed in the blockchain system tested is abnormal.
In a specific implementation, the processor 1001, the user interface 1002, the communication interface 1003, and the memory 1004 described in this embodiment of the present application may execute an implementation manner of a test platform described in the test method for a blockchain system provided in this embodiment of the present application, and may also execute an implementation manner described in a test apparatus provided in this embodiment of the present application, which is not described herein again.
According to the method and the device for testing the resource consumption of the intelligent contract, the first resource consumption corresponding to the first reference intelligent contract and the second resource consumption corresponding to the second reference intelligent contract under the block chain system are obtained, the first reference intelligent contract and the second reference intelligent contract are combined into the target intelligent contract, the target resource consumption corresponding to the target intelligent contract under the block chain system is obtained, and finally the test result of the resource consumption computing mechanism of the intelligent contract in the block chain system is determined according to the first resource consumption, the second resource consumption and the target resource consumption, so that the automatic test of the resource consumption computing mechanism of the intelligent contract can be achieved, the test efficiency of the resource consumption computing mechanism of the intelligent contract is effectively improved, and the accuracy of the test result can be effectively guaranteed.
Accordingly, the present application also provides a computer-readable storage medium, which stores instructions that, when executed on a computer, cause the computer to execute the testing method for the blockchain system according to the present application. For specific implementation, reference may be made to the foregoing description, which is not repeated herein.
Accordingly, embodiments of the present application also provide a computer program product or a computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer readable storage medium, and executes the computer instructions to cause the computer device to execute the test method for the blockchain system according to the embodiment of the application. For specific implementation, reference may be made to the foregoing description, which is not repeated herein.
It should be noted that, for simplicity of description, the above-mentioned embodiments of the method are described as a series of acts or combinations, but those skilled in the art should understand that the present application is not limited by the order of acts described, as some steps may be performed in other orders or simultaneously according to the present application. Further, those skilled in the art should also appreciate that the embodiments described in the specification are preferred embodiments and that the acts and modules referred to are not necessarily required in this application.
Those skilled in the art will appreciate that all or part of the steps in the methods of the above embodiments may be implemented by associated hardware instructed by a program, which may be stored in a computer-readable storage medium, and the storage medium may include: flash disks, Read-Only memories (ROMs), Random Access Memories (RAMs), magnetic or optical disks, and the like.
The above disclosure is only a few examples of the present application, and certainly should not be taken as limiting the scope of the present application, which is therefore intended to cover all modifications that are within the scope of the present application and which are equivalent to the claims.
Claims (10)
1. A testing method for a blockchain system, the method being used for testing a resource consumption calculation mechanism in the blockchain system, the blockchain system calculating a resource consumption of an intelligent contract through the resource consumption calculation mechanism, the method comprising:
obtaining an intelligent contract set, wherein the intelligent contract set comprises a first reference intelligent contract and a second reference intelligent contract;
deploying the first reference intelligent contract and the second reference intelligent contract into the blockchain system, and acquiring a first resource consumption amount corresponding to the first reference intelligent contract and a second resource consumption amount corresponding to the second reference intelligent contract under the blockchain system;
merging the first reference intelligent contract and the second reference intelligent contract to obtain a target intelligent contract, deploying the target intelligent contract into the block chain system, and acquiring the target resource consumption corresponding to the target intelligent contract under the block chain system; the merging process comprises merging and de-duplicating the same operation of the first reference intelligent contract and the second reference intelligent contract, or the merging process comprises not merging and de-duplicating the same operation of the first reference intelligent contract and the second reference intelligent contract, but the same operation is not repeatedly executed;
and determining a test result of a resource consumption calculation mechanism related to the intelligent contract in the blockchain system according to the first resource consumption, the second resource consumption and the target resource consumption.
2. The method of claim 1, wherein said merging the first reference smart contract and the second reference smart contract to obtain a target smart contract comprises:
carrying out AST (abstract syntax tree) structuralization on the first reference intelligent contract to obtain a first AST data structure;
AST structuring is carried out on the second reference intelligent contract to obtain a second AST data structure;
determining a target smart contract based on the first AST data structure and the second AST data structure.
3. The method of claim 2, wherein said determining a target smart contract based on the first AST data structure and the second AST data structure comprises:
merging the first AST data structure and the second AST data structure to form a new AST data structure;
a target intelligent contract is determined based on the new AST data structure.
4. A method according to any one of claims 1-3, wherein said determining a test result of a resource consumption calculation mechanism for intelligent contracts in the blockchain system from the first resource consumption, the second resource consumption, and the target resource consumption comprises:
determining a sum of resource consumption amounts of the first resource consumption amount and the second resource consumption amount;
comparing the total resource consumption with the target resource consumption to obtain a comparison result;
and determining a test result of a resource consumption calculation mechanism related to the intelligent contract in the blockchain system according to the comparison result.
5. The method of claim 4, wherein determining a test result for a resource consumption calculation mechanism for intelligent contracts in the blockchain system based on the comparison comprises:
if the comparison result indicates that the target resource consumption is greater than the sum of the resource consumption, determining that a test result of a resource consumption calculation mechanism related to an intelligent contract in the blockchain system is abnormal;
and if the comparison result indicates that the target resource consumption is less than or equal to the sum of the resource consumption, determining that the test result of the resource consumption calculation mechanism related to the intelligent contract in the blockchain system is normal.
6. The method of claim 5, wherein determining that the test result of the resource consumption calculation mechanism for the intelligent contract in the blockchain system is normal if the comparison result indicates that the target resource consumption is less than or equal to the sum of the resource consumption comprises:
if the comparison result indicates that the target resource consumption is less than or equal to the sum of the resource consumption and the target resource consumption is detected to be greater than or equal to a third resource consumption, determining that a test result of a resource consumption calculation mechanism related to an intelligent contract in the blockchain system is normal;
wherein the method further comprises:
if the target resource consumption is detected to be smaller than the third resource consumption, determining that a test result of a resource consumption calculation mechanism related to an intelligent contract in the blockchain system is abnormal;
the third resource consumption amount refers to a minimum value of resource consumption amounts corresponding to any two reference intelligent contracts in the intelligent contract set after the two reference intelligent contracts are combined.
7. The method of claim 1, wherein prior to merging the first reference smart contract and the second reference smart contract to obtain a target smart contract, the method further comprises:
acquiring a basic calculation rule about the resource consumption of the intelligent contract;
calculating the reference resource consumption of the first benchmark intelligent contract and the reference resource consumption of the second benchmark intelligent contract according to the basic calculation rule;
and if the reference resource consumption of the first benchmark intelligent contract is matched with the first resource consumption and the reference resource consumption of the second benchmark intelligent contract is matched with the second resource consumption, executing the step of combining the first benchmark intelligent contract and the second benchmark intelligent contract to obtain a target intelligent contract.
8. A testing apparatus, wherein the apparatus is configured to test a resource consumption calculation mechanism in a blockchain system, and the blockchain system calculates a resource consumption of an intelligent contract through the resource consumption calculation mechanism, and the apparatus comprises:
an acquisition unit configured to acquire an intelligent contract set, the intelligent contract set including a first reference intelligent contract and a second reference intelligent contract;
the processing unit is used for deploying the first reference intelligent contract and the second reference intelligent contract into the blockchain system, and acquiring a first resource consumption amount corresponding to the first reference intelligent contract and a second resource consumption amount corresponding to the second reference intelligent contract under the blockchain system;
the merging unit is used for merging the first reference intelligent contract and the second reference intelligent contract to obtain a target intelligent contract; the merging process comprises merging and de-duplicating the same operation of the first reference intelligent contract and the second reference intelligent contract, or the merging process comprises not merging and de-duplicating the same operation of the first reference intelligent contract and the second reference intelligent contract, but the same operation is not repeatedly executed;
the processing unit is further configured to deploy the target intelligent contract to the blockchain system, and obtain a target resource consumption amount corresponding to the target intelligent contract in the blockchain system; and determining a test result of a resource consumption calculation mechanism related to the intelligent contract in the blockchain system according to the first resource consumption, the second resource consumption and the target resource consumption.
9. A computer device, comprising: a processor, a communication interface and a memory, the processor, the communication interface and the memory being interconnected, wherein the memory stores executable program code, and the processor is configured to call the executable program code to execute the testing method for the blockchain system according to any one of claims 1 to 7.
10. A computer-readable storage medium having stored therein instructions which, when run on a computer, cause the computer to perform the method of testing for a blockchain system of any one of claims 1 to 7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010877316.4A CN112035350B (en) | 2020-08-27 | 2020-08-27 | Test method and device for block chain system and computer equipment |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010877316.4A CN112035350B (en) | 2020-08-27 | 2020-08-27 | Test method and device for block chain system and computer equipment |
Publications (2)
Publication Number | Publication Date |
---|---|
CN112035350A CN112035350A (en) | 2020-12-04 |
CN112035350B true CN112035350B (en) | 2021-09-28 |
Family
ID=73580177
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010877316.4A Active CN112035350B (en) | 2020-08-27 | 2020-08-27 | Test method and device for block chain system and computer equipment |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN112035350B (en) |
Families Citing this family (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN112737862B (en) * | 2021-01-08 | 2023-12-22 | 江苏众享金联科技有限公司 | Cross-chain data sharing method based on intelligent contract |
CN113282517A (en) * | 2021-07-21 | 2021-08-20 | 支付宝(杭州)信息技术有限公司 | Quality evaluation system of intelligent contract code |
CN113835972B (en) * | 2021-11-26 | 2022-03-08 | 南京金宁汇科技有限公司 | ASM-based alliance chain intelligent contract resource consumption detection method and device |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110544113A (en) * | 2019-08-14 | 2019-12-06 | 清华大学 | Method and device for determining input of fuel charge in transaction based on intelligent contract |
CN110543407A (en) * | 2019-08-21 | 2019-12-06 | 杭州趣链科技有限公司 | Static analysis method for performance of identity intelligent contract |
Family Cites Families (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
KR102187293B1 (en) * | 2018-11-05 | 2020-12-04 | 서강대학교 산학협력단 | Apparatus and method for analyzing smart contracts being capable of saving GAS |
-
2020
- 2020-08-27 CN CN202010877316.4A patent/CN112035350B/en active Active
Patent Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110544113A (en) * | 2019-08-14 | 2019-12-06 | 清华大学 | Method and device for determining input of fuel charge in transaction based on intelligent contract |
CN110543407A (en) * | 2019-08-21 | 2019-12-06 | 杭州趣链科技有限公司 | Static analysis method for performance of identity intelligent contract |
Also Published As
Publication number | Publication date |
---|---|
CN112035350A (en) | 2020-12-04 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110597925B (en) | Cross-chain data processing method and device based on block chain | |
CN112073269B (en) | Block chain network testing method, device, server and storage medium | |
CN108200203B (en) | Block chain system based on double-layer network | |
CN112035350B (en) | Test method and device for block chain system and computer equipment | |
CN112506747B (en) | Business process monitoring method and device, electronic equipment and storage medium | |
CN112101938B (en) | Digital seal using method and device based on block chain and electronic equipment | |
CN112801658B (en) | Cross-border resource transfer authenticity auditing method and device and electronic equipment | |
CN111506511A (en) | Test case generation method and device, electronic equipment and medium | |
CN108282539A (en) | Decentralization storage system based on double-layer network | |
CN111782551B (en) | Test method and device for block chain item and computer equipment | |
CN108347483B (en) | Decentralized computing system based on double-layer network | |
CN111949531B (en) | Block chain network testing method, device, medium and electronic equipment | |
CN114070883B (en) | Test resource access method and device, electronic equipment and storage medium | |
CN112200569A (en) | Block chain-based digital seal using method and device and electronic equipment | |
CN109147918A (en) | Reserve matching process, device, electronic equipment and computer-readable medium | |
CN111640002A (en) | Block chain-based mortgage loan method and device | |
CN112100588A (en) | Block chain-based digital seal application method and device and electronic equipment | |
CN110955724A (en) | Data processing method and device based on block chain, node equipment and storage medium | |
CN112040015B (en) | Consensus node list generation method and related device | |
CN109345249A (en) | A kind of payment fail processing method and device | |
CN113095825A (en) | Asset management method and device based on block chain and electronic equipment | |
CN110225103B (en) | Service recommendation method, device and equipment | |
CN113327169B (en) | Claims settlement method and device based on block chain and electronic equipment | |
CN116955148A (en) | Service system testing method, device, equipment, storage medium and product | |
CN114925405A (en) | Block chain-based digital seal verification method and device and electronic equipment |
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 | ||
REG | Reference to a national code |
Ref country code: HK Ref legal event code: DE Ref document number: 40035326 Country of ref document: HK |
|
GR01 | Patent grant | ||
GR01 | Patent grant |