Method and device for testing smart contracts deployed on blockchain nodes
By decoupling smart contract testing from business logic through a method involving scheduling, conversion, and execution, the method improves test efficiency and flexibility for smart contracts on blockchain nodes.
Patent Information
- Application Number
- CN202110299650.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-03-19
- Publication Date
- 2024-12-24
- Estimated Expiration
- 2041-03-19
AI Technical Summary
The testing efficiency of smart contracts deployed on blockchain nodes is low due to their complex nature, which is coupled with various business logics, leading to cumbersome test steps.
A method and device for testing smart contracts on blockchain nodes that decouple the test from business logic by scheduling a target test case, converting variable names to addresses, determining and initializing the smart contract, and executing it to obtain a contract execution result, simplifying the test steps and improving efficiency.
The method enhances test efficiency and flexibility by decoupling smart contract testing from business logic, allowing for simplified test steps and improved readability of test logs.
Smart Images

Figure CN112785439B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present disclosure relate to technical fields such as blockchain and computers, and more specifically, to a method, device, electronic device, computer-readable storage medium, and computer program product for testing a smart contract deployed on a blockchain node. Background Art
[0002] With the rapid development of blockchain technology, more and more decentralized applications (DAPPs) based on blockchain have emerged, which can be understood as a collection of smart contract codes and peripheral codes running on blockchain nodes. Decentralized applications based on blockchain can be implemented through smart contracts deployed on blockchain nodes. Therefore, it is necessary to run smart contracts to realize corresponding functions.
[0003] A smart contract is a computer protocol designed to disseminate, verify or execute contracts in an information-based manner, allowing trusted transactions without a third party, which are traceable and irreversible. In a blockchain system, a smart contract is represented by executable code, that is, a script that can be automatically executed on a blockchain node, which can encode any set of rules expressed in a programming language. Since smart contracts are stored in decentralized blocks, it is difficult to modify smart contracts. In addition, if there are problems with the execution efficiency of the smart contract itself or there are problems with the smart contract itself, it may cause the resources of the blockchain system to be occupied for a long time, thereby affecting the performance of the blockchain system. Therefore, it is necessary to ensure the quality of smart contracts as much as possible, and in order to ensure the quality of smart contracts, testing smart contracts is an essential link.
[0004] In the process of implementing the concept of the present disclosure, the inventors found that there are at least the following problems in the related technology: the testing efficiency of smart contracts using the related technology is not high. Summary of the invention
[0005] In view of this, the embodiments of the present disclosure provide a method, an apparatus, an electronic device, a computer-readable storage medium, and a computer program product for testing a smart contract deployed on a blockchain node.
[0006] One aspect of an embodiment of the present disclosure provides a method for testing a smart contract deployed on a blockchain node, the method comprising: scheduling a target test case from multiple test cases according to a case scheduling strategy, wherein the target test case includes a preset matching relationship, a contract address, a contract execution parameter associated with the contract address, and a variable name; converting the variable name in the target test case into a variable address corresponding to the variable name according to the preset matching relationship; determining a smart contract to be tested according to the contract address; initializing the smart contract to be tested according to the contract execution parameters to obtain an initialized smart contract to be tested; and executing the initialized smart contract to be tested to obtain a contract execution result, wherein the contract execution result includes variable information associated with the variable address.
[0007] Another aspect of the disclosed embodiments provides a device for testing a smart contract deployed on a blockchain node, the device comprising: a scheduling module, for scheduling a target test case from a plurality of test cases according to a case scheduling strategy, wherein the target test case comprises a preset matching relationship, a contract address, a contract execution parameter associated with the contract address, and a variable name; a conversion module, for converting the variable name in the target test case into a variable address corresponding to the variable name according to the preset matching relationship; a first determination module, for determining a smart contract to be tested according to the contract address; a first acquisition module, for initializing the smart contract to be tested according to the contract execution parameters to obtain an initialized smart contract to be tested; and an execution module, for executing the initialized smart contract to be tested to obtain a contract execution result, wherein the contract execution result includes variable information associated with the variable address.
[0008] Another aspect of an embodiment of the present disclosure provides an electronic device, comprising: one or more processors; and a memory for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the method described above.
[0009] Another aspect of an embodiment of the present disclosure provides a computer-readable storage medium storing computer-executable instructions, which are used to implement the method described above when executed.
[0010] Another aspect of an embodiment of the present disclosure provides a computer program product, wherein the computer program product includes computer executable instructions, and the instructions are used to implement the above method when executed.
[0011] According to an embodiment of the present disclosure, a target test case is scheduled from multiple test cases according to a case scheduling strategy, and the target test case includes a preset matching relationship, a contract address, a contract execution parameter associated with the contract address, and a variable name. According to the preset matching relationship, the variable name in the target test case is converted into a variable address corresponding to the variable name, the smart contract to be tested is determined according to the contract address, the smart contract to be tested is initialized according to the contract execution parameter, the initialized smart contract to be tested is obtained, and the initialized smart contract to be tested is executed to obtain the contract execution result. Since the smart contract to be tested is tested in the form of a target test case corresponding to the smart contract to be tested, the test on the smart contract to be tested can be completed by calling the target test case, and the test on the smart contract to be tested is decoupled from the test on each business logic. Therefore, the test steps of the smart contract to be tested are simplified, and the test efficiency of the smart contract to be tested is improved. Therefore, the technical problem of low test efficiency of testing smart contracts using related technologies is at least partially overcome. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] The above and other objects, features and advantages of the present disclosure will become more apparent through the following description of the embodiments of the present disclosure with reference to the accompanying drawings, in which:
[0013] Figure 1 An exemplary system architecture to which a method for testing a smart contract deployed on a blockchain node can be applied according to an embodiment of the present disclosure is schematically shown;
[0014] Figure 2 A flowchart of a method for testing a smart contract deployed on a blockchain node according to an embodiment of the present disclosure is schematically shown;
[0015] Figure 3 A schematic diagram showing a case scheduling strategy according to an embodiment of the present disclosure is schematically shown;
[0016] Figure 4 A flowchart schematically illustrates another method for testing a smart contract deployed on a blockchain node according to an embodiment of the present disclosure;
[0017] Figure 5 A schematic diagram schematically shows a method for testing a smart contract deployed on a blockchain node according to an embodiment of the present disclosure;
[0018] Figure 6 A block diagram schematically shows a device for testing a smart contract deployed on a blockchain node according to an embodiment of the present disclosure; and
[0019] Figure 7A block diagram of an electronic device suitable for implementing a method for testing a smart contract deployed on a blockchain node according to an embodiment of the present disclosure is schematically shown. DETAILED DESCRIPTION
[0020] Hereinafter, embodiments of the present disclosure will be described with reference to the accompanying drawings. However, it should be understood that these descriptions are exemplary only and are not intended to limit the scope of the present disclosure. In the following detailed description, for ease of explanation, many specific details are set forth to provide a comprehensive understanding of the embodiments of the present disclosure. However, it is apparent that one or more embodiments may also be implemented without these specific details. In addition, in the following description, descriptions of known structures and technologies are omitted to avoid unnecessary confusion of the concepts of the present disclosure.
[0021] The terms used herein are only for describing specific embodiments and are not intended to limit the present disclosure. The terms "comprise", "include", etc. used herein indicate the existence of the features, steps, operations and / or components, but do not exclude the existence or addition of one or more other features, steps, operations or components.
[0022] All terms (including technical and scientific terms) used herein have the meanings commonly understood by those skilled in the art, unless otherwise defined. It should be noted that the terms used herein should be interpreted as having a meaning consistent with the context of this specification, and should not be interpreted in an idealized or overly rigid manner.
[0023] In the case of using expressions such as "at least one of A, B, and C, etc.", it should generally be interpreted in accordance with the meaning of the expression generally understood by those skilled in the art (for example, "a system having at least one of A, B, and C" should include but is not limited to a system having A alone, B alone, C alone, A and B, A and C, B and C, and / or A, B, C, etc.). In the case of using expressions such as "at least one of A, B, or C, etc.", it should generally be interpreted in accordance with the meaning of the expression generally understood by those skilled in the art (for example, "a system having at least one of A, B, or C" should include but is not limited to a system having A alone, B alone, C alone, A and B, A and C, B and C, and / or A, B, C, etc.).
[0024] In the process of implementing the concept of the present disclosure, the inventors found that the blockchain network has its own unique characteristics. For example, calling a smart contract needs to be completed by initiating a transaction, and the transaction needs to wait for miners to mine. Once the block and transaction are confirmed by the miners, they cannot be modified. The above makes the decentralized application based on blockchain itself complex.
[0025] In the related art, due to the complexity of decentralized applications themselves, the test of smart contracts is usually completed simultaneously by testing the various business logics involved in the decentralized application. Among them, the various business logics involved may include front-end events, back-end logic and deep system control logic, that is, the test of smart contracts is coupled with the test of various business logics. In other words, the test of smart contracts needs to rely on the test of various business logics.
[0026] In the process of implementing the concept of the present disclosure, the inventors found that in the related art, the test for the smart contract is coupled with the test for each business logic, that is, if the test for the smart contract is to be completed, it is necessary to complete the test for each business logic together. Therefore, the test steps for the test for the smart contract are cumbersome, which leads to low test efficiency for the test for the smart contract.
[0027] In order to solve the above problems, the inventors proposed a testing scheme for individually testing smart contracts, that is, setting corresponding test cases for each smart contract, decoupling the test for the smart contract from the test for each business logic, so as to realize individual testing of the smart contract.
[0028] Specifically, the embodiments of the present disclosure provide a method, device, and electronic device capable of applying the method for testing a smart contract deployed on a blockchain node. The method, device, electronic device, computer-readable storage medium, and computer program product for testing a smart contract deployed on a blockchain node of the embodiments of the present disclosure can be applied to the blockchain field, and can also be used in any field other than the blockchain field, and the embodiments of the present disclosure are not limited to this. The method includes a scheduling process, a conversion process, a determination process, an acquisition process, and an execution process. In the scheduling process, according to the case scheduling strategy, a target test case is scheduled from a plurality of test cases, and the target test case includes a preset matching relationship, a contract address, a contract execution parameter associated with the contract address, and a variable name. In the conversion process, according to the preset matching relationship, the variable name in the target test case is converted into a variable address corresponding to the variable name. In the determination process, the smart contract to be tested is determined according to the contract address. In the acquisition process, the smart contract to be tested is initialized according to the contract execution parameter to obtain the initialized smart contract to be tested. In the execution process, the initialized smart contract to be tested is executed to obtain a contract execution result, and the contract execution result includes variable information associated with the variable address.
[0029] Figure 1 The exemplary system architecture 100 to which the method for testing a smart contract deployed on a blockchain node according to an embodiment of the present disclosure can be applied is schematically shown. It should be noted that, Figure 1What is shown is merely an example of a system architecture to which the embodiments of the present disclosure can be applied, in order to help those skilled in the art understand the technical content of the present disclosure, but it does not mean that the embodiments of the present disclosure cannot be used in other devices, systems, environments or scenarios.
[0030] like Figure 1 As shown, the system architecture 100 according to this embodiment may include terminal devices 101, 102, 103, a network 104, a server 105 and a blockchain network 106, and the blockchain network 106 includes blockchain nodes 1061, 1062, 1063, 1064, 1065, 1066. The network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105, and between the server 105 and the blockchain network 106. The network 104 may include various connection types, such as wired and / or wireless communication links, etc.
[0031] The user can use the terminal devices 101, 102, 103 to interact with the server 105 through the network 104 to receive or send messages, etc. Various communication client applications can be installed on the terminal devices 101, 102, 103, such as banking applications, shopping applications, web browser applications, search applications, instant messaging tools, email clients and / or social platform software, etc. (only as examples).
[0032] Corresponding smart contracts can be deployed on blockchain nodes 1061, 1062, 1063, 1064, 1065, and 1066.
[0033] The terminal devices 101 , 102 , and 103 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers.
[0034] The server 105 may be a server that provides various services, for example, a server that provides testing for smart contracts deployed on the blockchain nodes 1061, 1062, 1063, 1064, 1065, and 1066 (for example only). A backend management server that provides testing for test cases generated by users using the terminal devices 101, 102, and 103 (for example only).
[0035] It should be noted that the test method provided in the embodiment of the present disclosure can generally be executed by the server 105. Accordingly, the test device provided in the embodiment of the present disclosure can generally be set in the server 105. The test method provided in the embodiment of the present disclosure can also be performed by a server or server cluster that is different from the server 105 and can communicate with the terminal device 101, 102, 103 and / or the server 105. Accordingly, the test device provided in the embodiment of the present disclosure can also be set in a server or server cluster that is different from the server 105 and can communicate with the terminal device 101, 102, 103 and / or the server 105. Alternatively, the test method provided in the embodiment of the present disclosure can also be performed by the terminal device 101, 102, or 103, or it can also be performed by other terminal devices different from the terminal device 101, 102, or 103. Accordingly, the test device provided in the embodiment of the present disclosure can also be set in the terminal device 101, 102, or 103, or it can be set in other terminal devices different from the terminal device 101, 102, or 103.
[0036] It should be understood that Figure 1 The number of terminal devices, networks, servers, and blockchain nodes in the embodiment is only for illustration. Any number of terminal devices, networks, servers, and blockchain nodes may be provided as required.
[0037] Figure 2 The present invention schematically shows a flowchart of a method for testing a smart contract deployed on a blockchain node according to an embodiment of the present disclosure.
[0038] like Figure 2 As shown, the method includes operations S210 to S250.
[0039] In operation S210, a target test case is scheduled from a plurality of test cases according to a case scheduling strategy, wherein the target test case includes a preset matching relationship, a contract address, and contract execution parameters and variable names associated with the contract address.
[0040] According to an embodiment of the present disclosure, a case scheduling strategy may be a strategy for case scheduling generated according to at least one of a test time, a test number, a test method, and a dependency relationship between each test case. After obtaining the case scheduling strategy, a target test case may be determined from a plurality of test cases according to the case scheduling strategy, wherein the number of target test cases may include one or more. The target test case may include internal parameter information and external parameter information, wherein the external parameter information may include a preset matching relationship, a contract address, and a contract execution parameter associated with the contract address. The internal parameter information may include variables of the smart contract to be tested. The variables of the smart contract to be tested may include variable names.
[0041] According to an embodiment of the present disclosure, a preset matching relationship can characterize the matching relationship between the variable name and the variable address of the variable. The contract address can characterize the address of the smart contract used for testing, that is, the address of the smart contract to be tested. Based on the above, the variable name of the smart contract to be tested is the variable name associated with the contract address. The contract execution parameters associated with the contract address can characterize the parameters used to initialize the smart contract to be tested when testing the smart contract to be tested corresponding to the contract address. The content included in the contract execution parameters associated with the contract address can be determined according to the function to be implemented by the smart contract to be tested, and is not limited here. Exemplarily, if the smart contract to be tested is used to implement the transfer function, the contract execution parameters associated with the contract address may include the transfer amount. If the smart contract to be tested includes a function for implementing the signature authentication function, the contract execution parameters associated with the contract address may include signature data. The variable name associated with the contract address can characterize the variable name of the variable involved in the smart contract to be tested corresponding to the contract address.
[0042] According to an embodiment of the present disclosure, the case scheduling strategy can be executed periodically. If the number of target test cases includes multiple and each target test case is scheduled in sequence, it can be determined whether there is a target test case identical to the target test case when scheduling each target test case, and if it is determined that there is no target test case identical to the target test case, the target test case is scheduled. If the number of target test cases includes multiple and each target test case is scheduled in parallel, it can be determined whether there is an identical target test case among the multiple target test cases after scheduling, and if it is determined that there is an identical target test case, one of the identical target test cases is retained.
[0043] In operation S220 , the variable name in the target test case is converted into a variable address corresponding to the variable name according to a preset matching relationship.
[0044] In operation S230, the smart contract to be tested is determined according to the contract address.
[0045] According to an embodiment of the present disclosure, the smart contract to be tested corresponding to the contract address can be determined based on the contract address included in the target test case, and the variable name in the target test case can be converted into the variable address corresponding to the variable name based on the preset matching relationship included in the target test case to facilitate the subsequent execution of the smart contract to be tested.
[0046] In operation S240, the smart contract to be tested is initialized according to the contract execution parameters to obtain the initialized smart contract to be tested.
[0047] According to an embodiment of the present disclosure, since the contract execution parameters include parameters for initializing the smart contract to be tested, the smart contract to be tested can be initialized according to the contract execution parameters to obtain the initialized smart contract to be tested.
[0048] In operation S250, the initialized smart contract to be tested is executed to obtain a contract execution result, wherein the contract execution result includes variable information associated with the variable address.
[0049] According to an embodiment of the present disclosure, the contract execution result may include variable information associated with the variable address, and the variable information associated with the variable address may represent the information of the variable that has changed after the smart contract to be tested is executed, wherein the variable is the variable corresponding to the variable address. The contract execution result may also include information for representing the success or failure of the contract execution, the time information consumed by the execution, the input parameter information of the smart contract to be tested, the output parameter information of the smart contract to be tested, and at least one of the preset matching relationships. The contract execution result may be stored in JSON (JavaScript Object Notation, JS object notation) format.
[0050] According to the embodiment of the present disclosure, the above operations S220 to S250 are the execution process of the target test case.
[0051] According to the technical solution of the embodiment of the present disclosure, a target test case is scheduled from multiple test cases according to a case scheduling strategy, and the target test case includes a preset matching relationship, a contract address, a contract execution parameter associated with the contract address, and a variable name. According to the preset matching relationship, the variable name in the target test case is converted into a variable address corresponding to the variable name, the smart contract to be tested is determined according to the contract address, the smart contract to be tested is initialized according to the contract execution parameter, the initialized smart contract to be tested is obtained, and the initialized smart contract to be tested is executed to obtain the contract execution result. Since the smart contract to be tested is tested in the form of a target test case corresponding to the smart contract to be tested, the test on the smart contract to be tested can be completed by calling the target test case, and the test on the smart contract to be tested is decoupled from the test on each business logic. Therefore, the test steps of the smart contract to be tested are simplified, and the test efficiency of the smart contract to be tested is improved. Therefore, the technical problem of low test efficiency of testing smart contracts using related technologies is at least partially overcome.
[0052] According to an embodiment of the present disclosure, the above method for testing a smart contract deployed on a blockchain node may also include the following operations.
[0053] For each of the multiple smart contracts to be tested, determine the internal parameter information for the smart contract to be tested, wherein the internal parameter information includes variables associated with the smart contract to be tested, and the variables include variable names. Determine the external parameter information for the smart contract to be tested, wherein the external parameter information includes a preset matching relationship, a contract execution parameter, a contract address of the smart contract to be tested, and a contract execution result determination strategy. Generate a test case for the smart contract to be tested based on the internal parameter information and the external parameter information of the smart contract to be tested.
[0054] According to an embodiment of the present disclosure, the contract execution result determination strategy included in the external parameter information of the smart contract to be tested can represent a strategy for determining whether the contract execution is successful or failed. For example, when the smart contract to be tested is for the number of resource transfers, the contract execution result determination strategy can be that for the account that transfers out resources, when the number of resources before the transfer is equal to the number of resources after the transfer plus the number of resource transfers, and for the account that receives resources, when the number of resources before the transfer is equal to the number of resources after the transfer minus the number of resource transfers, the contract execution is determined to be successful.
[0055] According to an embodiment of the present disclosure, each smart contract to be tested can be obtained in the following manner: determining the contract type of the smart contract to be tested, and determining the smart contract to be tested corresponding to the contract type according to the contract type. For each smart contract to be tested among the multiple smart contracts to be tested, determining the internal parameter information for the smart contract to be tested may include determining an abstract syntax tree corresponding to the smart contract to be tested, and obtaining the internal parameter information of the smart contract to be tested according to the abstract syntax tree.
[0056] According to an embodiment of the present disclosure, since the test case is generated based on the internal parameter information and external parameter information of the smart contract to be tested, the test case may include internal parameter information and external parameter information, the internal parameter information of the test case corresponds to the internal parameter information of the corresponding smart contract to be tested, and the external parameter information of the test case corresponds to the external parameter information of the corresponding smart contract to be tested.
[0057] According to an embodiment of the present disclosure, the test case corresponding to the smart contract to be tested can be stored in XML (Extensible Markup Language) format.
[0058] According to an embodiment of the present disclosure, if the technical solution provided by the embodiment of the present disclosure is executed by a server, the test case generation process can be implemented by the server, and the server can also receive test cases sent by a terminal device, that is, the test case generation process is completed by the terminal device, that is, each test case is generated by the terminal device according to the internal parameter information and external parameter information of the smart contract to be tested.
[0059] According to an embodiment of the present disclosure, the above method for testing a smart contract deployed on a blockchain node may also include the following operations.
[0060] For each test case in the plurality of test cases, case execution information of the test case is determined, wherein the case execution information includes at least one of a test case identifier, a test time, a test number, and a test mode. Dependencies between the test cases are determined according to the business logic. A case scheduling strategy is generated according to the case execution information of the test cases and the dependencies between the test cases.
[0061] According to the embodiments of the present disclosure, in the process of realizing the concept of the present disclosure, the inventors also found that the test flexibility of using related technologies to test smart contracts is not high, and further found that the main reason for the low test flexibility is that it is difficult to uniformly schedule various test cases according to actual business needs and set the execution order between various test cases.
[0062] In order to solve the above problem, the embodiment of the present disclosure provides a solution for generating a case scheduling strategy according to the dependency relationship between various test cases and the case execution information of various test cases.
[0063] According to an embodiment of the present disclosure, a test case identifier is used to characterize a test case. The test time may include at least one of the start time of each test, a specified test date, and a time interval between each test time. The specified test date may be daily, weekly, monthly, a certain day of the week, or a certain day of the month. The test mode may include a manual test mode or an automatic test mode.
[0064] According to an embodiment of the present disclosure, the execution order between each test case can be determined according to the dependency relationship between each test case. Taking the dependency relationship between two test cases as an example to illustrate that each test case has a dependency relationship, the dependency relationship between two test cases can refer to whether one of the two tests can execute the execution result that depends on the other test case. Among them, the dependent test case can be called the predecessor test case. If there is a dependency relationship between two test cases, the execution order of the two test cases is serial execution, that is, the predecessor test case needs to be executed first. If there is no dependency relationship between the two test cases, without considering the dependency relationship between the two test cases and other test cases, the execution order of the two test cases can be parallel execution.
[0065] For example, in a shopping scenario, multiple users place orders at the same time. The target test case for each user's order contract and the target test case for the payment contract are in a serial relationship, and the target test cases for different users are in a parallel relationship.
[0066] According to an embodiment of the present disclosure, determining the dependency between each test case according to the business logic may include generating a scheduling diagram for the execution order of each test case according to the business logic. Determining the dependency between each test case according to the scheduling diagram.
[0067] According to the embodiments of the present disclosure, since the case scheduling strategy is generated based on the case execution information of each test case and the dependency relationship between each test case, the target test case to be executed can be determined according to the case scheduling strategy, and in the case of multiple target test cases, the execution order of each target test case can be determined, thereby realizing unified scheduling of multiple target test cases and setting the execution order of each target test case, thereby improving the test flexibility. When it involves joint testing between multiple business systems, the case scheduling strategy is used to realize unified scheduling for multiple test cases, saving time and improving test efficiency.
[0068] According to an embodiment of the present disclosure, the target test case includes multiple test cases. Scheduling the target test case from the multiple test cases according to the case scheduling strategy may include the following operations.
[0069] According to the case scheduling strategy, multiple target test cases and the dependencies between the target test cases are scheduled from the multiple test cases.
[0070] The above test method may further include the following operations.
[0071] According to the dependency relationship between each target test case, the execution order of each target test case is determined.
[0072] According to the preset matching relationship, converting the variable name in the target test case into the variable address corresponding to the variable name may include the following operations.
[0073] For each target test case among multiple target test cases, when it is determined that the execution order of the target test case has been reached, the variable name in the target test case is converted into a variable address corresponding to the variable name according to a preset matching relationship corresponding to the target test case.
[0074] According to an embodiment of the present disclosure, when there are multiple target test cases, for each of the multiple target test cases, when it is determined that the execution order of the target test cases has been reached, the target test case is executed.
[0075] According to an embodiment of the present disclosure, when it is determined that the execution order of the target test case has been reached, converting the variable name in the target test case into the variable address corresponding to the variable name according to the preset matching relationship corresponding to the target test case may include the following operations.
[0076] If it is determined that there is a previous test case of the target test case, determine whether the previous test case is executed successfully. If it is determined that the previous test case is executed successfully, determine that the execution sequence of the target test case is reached. If it is determined that the execution sequence of the target test case is reached, convert the variable name in the target test case into the variable address corresponding to the variable name according to the preset matching relationship corresponding to the target test case.
[0077] According to an embodiment of the present disclosure, for each target test case, since there may be a target test case that has a dependency relationship with the target test case, that is, there may be a target test case that the target test case depends on, when determining whether to execute the target test case, it is necessary to determine whether there is a target test case that the target test case depends on, wherein the dependent target test case can be referred to as a predecessor test case. In the case where it is determined that there is a predecessor test case of the target test case, it is determined whether the predecessor test case is successfully executed. If the predecessor test case is successfully executed, the target test case can be executed when the execution sequence of the target test case is reached. If the execution of the predecessor test case fails, it is necessary to continue waiting until it is determined that the predecessor test case is successfully executed, and the target test case is executed when the execution sequence of the target test case is reached.
[0078] According to an embodiment of the present disclosure, the above method for testing a smart contract deployed on a blockchain node may also include the following operations.
[0079] According to the preset matching relationship, the variable address in the contract execution result is converted into the variable name corresponding to the variable address, and the test log for the smart contract to be tested is obtained.
[0080] According to the embodiments of the present disclosure, in the process of realizing the concept of the present disclosure, the inventors also found that the readability of the test log for the smart contract to be tested generated by the relevant technology is poor, and further found that the main reason for the poor readability of the test log is that the variables in the test log are represented by variable addresses, and the readability of the variable address is poor and not easy to understand, thereby making the readability of the generated test log poor.
[0081] In order to solve the above problem, the embodiment of the present disclosure proposes a solution for obtaining a contract execution result for a smart contract to be tested, converting the variable address of the variable in the contract execution result into a variable name corresponding to the variable address according to a preset matching relationship between the variable name and the variable address, thereby generating a test log for the smart contract to be tested.
[0082] According to the embodiments of the present disclosure, since the variables involved in the test log are represented by variable names, the readability of the test log is improved.
[0083] According to an embodiment of the present disclosure, the above method for testing a smart contract deployed on a blockchain node may also include the following operations.
[0084] A result query request is obtained, wherein the result query request includes a query condition. In response to the result query request, a contract execution result corresponding to the query condition is obtained. The contract execution result corresponding to the query condition is displayed.
[0085] According to an embodiment of the present disclosure, the query condition may include content related to the case execution information, for example, the query condition may include the test time. In order to facilitate the user to intuitively see the contract execution result corresponding to the query condition, the contract execution result corresponding to the query condition may be displayed after the contract execution result corresponding to the query condition is obtained.
[0086] According to an embodiment of the present disclosure, the above method for testing a smart contract deployed on a blockchain node may also include the following operations.
[0087] Obtain a policy query request. In response to the policy query request, obtain a case scheduling policy. Display the case scheduling policy.
[0088] According to an embodiment of the present disclosure, in order to facilitate the user to intuitively see the case scheduling strategy, the case scheduling strategy may be displayed after the case scheduling strategy is obtained.
[0089] Figure 3A schematic diagram showing a case scheduling strategy according to an embodiment of the present disclosure is schematically shown. Figure 3 The display interface in shows the dependency relationships between the test cases, where test case 2 has a dependency relationship with test case 1, test case 3 has a dependency relationship with test case 1, test case 4 has a dependency relationship with test case 1, test case 5 has dependencies on test case 2, test case 3 and test case 4 respectively, and test case 2, test case 3 and test case 4 have no dependencies.
[0090] According to an embodiment of the present disclosure, converting a variable name in a target test case into a variable address corresponding to the variable name according to a preset matching relationship may include the following operations.
[0091] When it is determined that the test mode of the target test case is a manual test mode, if a test request for the target test case is obtained, in response to the test request, the variable name in the target test case is converted into a variable address corresponding to the variable name according to a preset matching relationship.
[0092] According to the embodiment of the present disclosure, since the test for certain functions can only be implemented through manual testing, the technical solution of the embodiment of the present disclosure also supports manual testing. That is, if it is determined that the test method of the target test case is a manual testing method, the target test case can be executed in response to the test request when a test request for the target test case is obtained. The test request can be generated according to a trigger operation of an operating body. The trigger operation can include a click operation or a slide operation.
[0093] Figure 4 The present invention schematically shows a flowchart of another method for testing a smart contract deployed on a blockchain node according to an embodiment of the present disclosure.
[0094] like Figure 4 As shown, the method includes operations S401 to S419.
[0095] In operation S401, for each smart contract to be tested among a plurality of smart contracts to be tested, internal parameter information for the smart contract to be tested is determined, wherein the internal parameter information includes variables and methods associated with the smart contract to be tested, and the variables include variable names.
[0096] In operation S402, external parameter information for the smart contract to be tested is determined, wherein the external parameter information includes a preset matching relationship, a contract execution parameter, a contract address of the smart contract to be tested, and a contract execution result determination strategy.
[0097] In operation S403, a test case for the smart contract to be tested is generated according to the internal parameter information and external parameter information of the smart contract to be tested.
[0098] In operation S404, for each test case in the plurality of test cases, case execution information of the test case is determined, wherein the case execution information includes at least one of a test case identifier, a test time, a test number, and a test mode.
[0099] In operation S405 , the dependency relationship between the test cases is determined according to the business logic.
[0100] In operation S406, a case scheduling strategy is generated according to the case execution information of each test case and the dependency relationship between each test case.
[0101] In operation S407, according to the case scheduling strategy, multiple target test cases and dependencies between the target test cases are scheduled from the multiple test cases, wherein the target test cases include a preset matching relationship, a contract address, and contract execution parameters and variable names associated with the contract address.
[0102] In operation S408 , the execution order of each target test case is determined according to the dependency relationship between the target test cases.
[0103] In operation S409, for each target test case among the multiple target test cases, it is determined whether the test mode of the target test case is a manual test mode; if so, operation S410 is executed; if not, operation S411 is executed.
[0104] In operation S410, it is determined whether a test request for a target test case is obtained; if so, operation S411 is performed; if not, operation S410 is continued to be performed.
[0105] In operation S411, it is determined whether the execution order of the target test case has been reached; if so, operation S412 is performed; if not, operation S411 is continued to be performed.
[0106] In operation S412, it is determined whether there is a preceding test case of the target test case; if so, operation S413 is performed; if not, operation S414 is performed.
[0107] In operation S413, determine whether the previous test case is executed successfully; if so, execute operation S414; if not, continue to execute operation S413.
[0108] In operation S414, the variable name in the target test case is converted into a variable address corresponding to the variable name according to the preset matching relationship.
[0109] In operation S415, the smart contract to be tested is determined according to the contract address.
[0110] In operation S416, the smart contract to be tested is initialized according to the contract execution parameters to obtain the initialized smart contract to be tested.
[0111] In operation S417, the initialized smart contract to be tested is executed to obtain a contract execution result, wherein the contract execution result includes variable information associated with the variable address.
[0112] In operation S418, according to the preset matching relationship, the variable address in the contract execution result is converted into a variable name corresponding to the variable address, and a test log for the smart contract to be tested is obtained.
[0113] In operation S419, a test log for the smart contract to be tested is displayed.
[0114] According to an embodiment of the present disclosure, Figure 5 A schematic diagram of a method for testing a smart contract deployed on a blockchain node according to an embodiment of the present disclosure is schematically shown. Figure 5 It includes case generation, case scheduling strategy generation and case scheduling process.
[0115] According to the technical solution of the embodiment of the present disclosure, since the case scheduling strategy is generated based on the case execution information of each test case and the dependency relationship between each test case, and the dependency relationship between each test case reflects the execution order of each test case, the multiple target test cases that need to be executed and the execution order of each target test case can be determined according to the case scheduling strategy, thereby realizing the unified scheduling of multiple target test cases and setting the execution order of each target test case, thereby improving the test flexibility. Since the corresponding test case is set for each smart contract to be tested, the test for the smart contract to be tested can be completed by calling the test case, and the test for the smart contract to be tested is decoupled from the test for each business logic, thereby simplifying the test steps of the smart contract to be tested, thereby improving the test efficiency of the smart contract to be tested. Since the variables involved in the test log are represented by variable names, the readability of the test log is improved.
[0116] Figure 6 A block diagram of an apparatus for testing a smart contract deployed on a blockchain node according to an embodiment of the present disclosure is schematically shown.
[0117] like Figure 6 As shown, the device 600 for testing a smart contract deployed on a blockchain node may include a scheduling module 610, a conversion module 620, a first determination module 630, an acquisition module 640 and an execution module 650.
[0118] The scheduling module 610 , the conversion module 620 , the first determination module 630 , the first acquisition module 640 and the execution module 650 are communicatively connected.
[0119] The scheduling module 610 is used to schedule a target test case from multiple test cases according to a case scheduling strategy, wherein the target test case includes a preset matching relationship, a contract address, and contract execution parameters and variable names associated with the contract address.
[0120] The conversion module 620 is used to convert the variable name in the target test case into a variable address corresponding to the variable name according to a preset matching relationship.
[0121] The first determination module 630 is used to determine the smart contract to be tested according to the contract address.
[0122] The first obtaining module 640 is used to initialize the smart contract to be tested according to the contract execution parameters to obtain the initialized smart contract to be tested.
[0123] The execution module 650 is used to execute the initialized smart contract to be tested and obtain the contract execution result, wherein the contract execution result includes variable information associated with the variable address.
[0124] According to the technical solution of the embodiment of the present disclosure, a target test case is scheduled from multiple test cases according to a case scheduling strategy, and the target test case includes a preset matching relationship, a contract address, a contract execution parameter associated with the contract address, and a variable name. According to the preset matching relationship, the variable name in the target test case is converted into a variable address corresponding to the variable name, the smart contract to be tested is determined according to the contract address, the smart contract to be tested is initialized according to the contract execution parameter, the initialized smart contract to be tested is obtained, and the initialized smart contract to be tested is executed to obtain the contract execution result. Since the smart contract to be tested is tested in the form of a target test case corresponding to the smart contract to be tested, the test on the smart contract to be tested can be completed by calling the target test case, and the test on the smart contract to be tested is decoupled from the test on each business logic. Therefore, the test steps of the smart contract to be tested are simplified, and the test efficiency of the smart contract to be tested is improved. Therefore, the technical problem of low test efficiency of testing smart contracts using related technologies is at least partially overcome.
[0125] According to an embodiment of the present disclosure, the above-mentioned device 600 for testing a smart contract deployed on a blockchain node may also include a second determination module, a third determination module and a first generation module.
[0126] The second determination module is used to determine internal parameter information for each smart contract to be tested among the multiple smart contracts to be tested, wherein the internal parameter information includes variables associated with the smart contract to be tested, and the variables include variable names.
[0127] The third determination module is used to determine the external parameter information for the smart contract to be tested, wherein the external parameter information includes a preset matching relationship, a contract execution parameter, a contract address of the smart contract to be tested, and a contract execution result determination strategy.
[0128] The first generation module is used to generate a test case for the smart contract to be tested based on the internal parameter information and external parameter information of the smart contract to be tested.
[0129] According to an embodiment of the present disclosure, the above-mentioned device 600 for testing a smart contract deployed on a blockchain node may also include a fourth determination module, a fifth determination module and a second generation module.
[0130] The fourth determination module is used to determine the case execution information of each test case in the multiple test cases, wherein the case execution information includes at least one of the test case identification, test time, test number and test mode.
[0131] The fifth determination module is used to determine the dependency relationship between various test cases according to business logic.
[0132] The second generating module is used to generate a case scheduling strategy according to the case execution information of each test case and the dependency relationship between each test case.
[0133] According to an embodiment of the present disclosure, the target test case includes multiple ones.
[0134] The scheduling module 610 may include a scheduling submodule.
[0135] The scheduling submodule is used to schedule multiple target test cases and the dependencies between the target test cases from multiple test cases according to the case scheduling strategy.
[0136] The testing device 600 may further include a sixth determining module.
[0137] The sixth determination module is used to determine the execution order of each target test case according to the dependency relationship between the target test cases.
[0138] The conversion module 620 may include a determination submodule.
[0139] A determination submodule is used to, for each target test case among multiple target test cases, convert the variable name in the target test case into a variable address corresponding to the variable name according to a preset matching relationship corresponding to the target test case when determining that the execution order of the target test case has been reached.
[0140] According to an embodiment of the present disclosure, the determining submodule may include a first determining unit, a second determining unit, and a first converting unit.
[0141] The first determining unit is used to determine whether the preceding test case is successfully executed when it is determined that there is a preceding test case of the target test case.
[0142] The second determining unit is used to determine that the execution order of the target test case has arrived when it is determined that the previous test case has been executed successfully.
[0143] The first conversion unit is used to convert the variable name in the target test case into the variable address corresponding to the variable name according to the preset matching relationship corresponding to the target test case when it is determined that the execution order of the target test case has arrived.
[0144] According to an embodiment of the present disclosure, the above-mentioned device 600 for testing a smart contract deployed on a blockchain node may further include a second obtaining module.
[0145] The second acquisition module is used to convert the variable address in the contract execution result into the variable name corresponding to the variable address according to the preset matching relationship, and obtain the test log for the smart contract to be tested.
[0146] According to an embodiment of the present disclosure, the above-mentioned device 600 for testing a smart contract deployed on a blockchain node may also include a first acquisition module, a first response module and a first display module.
[0147] The first acquisition module is used to acquire a result query request, wherein the result query request includes a query condition.
[0148] The first response module is used to respond to the result query request and obtain the contract execution result corresponding to the query condition.
[0149] The first display module is used to display the contract execution results corresponding to the query conditions.
[0150] According to an embodiment of the present disclosure, the above-mentioned device 600 for testing a smart contract deployed on a blockchain node may also include a second acquisition module, a second response module and a second display module.
[0151] The second acquisition module is used to acquire a policy query request.
[0152] The second response module is used to obtain the case scheduling strategy in response to the strategy query request.
[0153] The second display module is used to display the case scheduling strategy.
[0154] According to an embodiment of the present disclosure, the conversion module 620 may include a second conversion unit.
[0155] The second conversion unit is used to, when it is determined that the test method of the target test case is a manual test method, if a test request for the target test case is obtained, respond to the test request and convert the variable name in the target test case into a variable address corresponding to the variable name according to a preset matching relationship.
[0156] According to the modules, submodules, and units of the embodiments of the present disclosure, any multiple or at least part of the functions of any multiple thereof can be implemented in one module. According to the modules, submodules, and units of the embodiments of the present disclosure, any one or more thereof can be split into multiple modules for implementation. According to the modules, submodules, and units of the embodiments of the present disclosure, any one or more thereof can be at least partially implemented as a hardware circuit, such as a Field Programmable Gate Array (FPGA), a Programmable Logic Array (PLA), a System on a Chip, a System on a Substrate, a System on a Package, an Application Specific Integrated Circuit (ASIC), or can be implemented by hardware or firmware of any other reasonable way of integrating or packaging the circuit, or implemented in any one of the three implementation modes of software, hardware, and firmware or in any appropriate combination of any of them. Alternatively, according to the modules, submodules, and units of the embodiments of the present disclosure, one or more thereof can be at least partially implemented as a computer program module, and when the computer program module is run, the corresponding function can be executed.
[0157] For example, any multiple of the communication connections of the scheduling module 610, the conversion module 620, the first determination module 630, the first acquisition module 640 and the execution module 650 can be combined in one module / submodule / unit for implementation, or any one of the modules / submodules / units can be split into multiple modules / submodules / units. Alternatively, at least part of the functions of one or more modules / units in these modules / submodules / units can be combined with at least part of the functions of other modules / submodules / units and implemented in one module / submodule / unit. According to an embodiment of the present disclosure, at least one of the communication connections of the scheduling module 610, the conversion module 620, the first determination module 630, the first acquisition module 640 and the execution module 650 can be at least partially implemented as a hardware circuit, such as a field programmable gate array (FPGA), a programmable logic array (PLA), a system on a chip, a system on a substrate, a system on a package, an application specific integrated circuit (ASIC), or can be implemented by hardware or firmware such as any other reasonable way of integrating or packaging the circuit, or by any one of the three implementation methods of software, hardware and firmware or by a suitable combination of any of them. Alternatively, at least one of the communication connections among the scheduling module 610, the conversion module 620, the first determination module 630, the first acquisition module 640 and the execution module 650 may be at least partially implemented as a computer program module, which may perform corresponding functions when executed.
[0158] It should be noted that the device part of testing the smart contract deployed on the blockchain node in the embodiment of the present disclosure corresponds to the method part of testing the smart contract deployed on the blockchain node in the embodiment of the present disclosure. The description of the test device part specifically refers to the method part of testing the smart contract deployed on the blockchain node, which will not be repeated here.
[0159] Figure 7 A block diagram of an electronic device suitable for implementing the method described above according to an embodiment of the present disclosure is schematically shown. Figure 7 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0160] like Figure 7As shown, the electronic device 700 according to the embodiment of the present disclosure includes a processor 701, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 702 or the program loaded from the storage part 708 to the random access memory (RAM) 703. The processor 701 may include, for example, a general-purpose microprocessor (such as a CPU), an instruction set processor and / or a related chipset and / or a special-purpose microprocessor (for example, an application-specific integrated circuit (ASIC)), etc. The processor 701 may also include an onboard memory for caching purposes. The processor 701 may include a single processing unit or multiple processing units for performing different actions of the method flow according to the embodiment of the present disclosure.
[0161] In RAM 703, various programs and data required for the operation of electronic device 700 are stored. Processor 701, ROM 702 and RAM 703 are connected to each other via bus 704. Processor 701 performs various operations of the method flow according to the embodiment of the present disclosure by executing the program in ROM 702 and / or RAM 703. It should be noted that the program can also be stored in one or more memories other than ROM 702 and RAM 703. Processor 701 can also perform various operations of the method flow according to the embodiment of the present disclosure by executing the program stored in the one or more memories.
[0162] According to an embodiment of the present disclosure, the electronic device 700 may further include an input / output (I / O) interface 705, which is also connected to the bus 704. The electronic device 700 may further include one or more of the following components connected to the I / O interface 705: an input portion 706 including a keyboard, a mouse, etc.; an output portion 707 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage portion 708 including a hard disk, etc.; and a communication portion 709 including a network interface card such as a LAN card, a modem, etc. The communication portion 709 performs communication processing via a network such as the Internet. A drive 710 is also connected to the I / O interface 705 as needed. A removable medium 711, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 710 as needed, so that a computer program read therefrom is installed into the storage portion 708 as needed.
[0163] According to an embodiment of the present disclosure, the method flow according to an embodiment of the present disclosure can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable storage medium, and the computer program contains a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 709, and / or installed from the removable medium 711. When the computer program is executed by the processor 701, the above-mentioned functions defined in the system of the embodiment of the present disclosure are executed. According to an embodiment of the present disclosure, the system, equipment, device, module, unit, etc. described above can be implemented by a computer program module.
[0164] The present disclosure also provides a computer-readable storage medium, which may be included in the device / apparatus / system described in the above embodiments; or may exist independently without being assembled into the device / apparatus / system. The above computer-readable storage medium carries one or more programs, and when the above one or more programs are executed, the method according to the embodiment of the present disclosure is implemented.
[0165] According to an embodiment of the present disclosure, the computer-readable storage medium may be a non-volatile computer-readable storage medium. For example, it may include, but is not limited to: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, an apparatus, or a device.
[0166] For example, according to an embodiment of the present disclosure, the computer-readable storage medium may include the ROM 702 and / or the RAM 703 described above and / or one or more memories other than the ROM 702 and the RAM 703 .
[0167] An embodiment of the present disclosure also includes a computer program product, which includes a computer program, which contains program code for executing the method provided by the embodiment of the present disclosure. When the computer program product is run on an electronic device, the program code is used to enable the electronic device to implement the method provided by the embodiment of the present disclosure for testing a smart contract deployed on a blockchain node.
[0168] When the computer program is executed by the processor 701, the above functions defined in the system / device of the embodiment of the present disclosure are executed. According to the embodiment of the present disclosure, the system, device, module, unit, etc. described above can be implemented by a computer program module.
[0169] In one embodiment, the computer program may be based on a tangible storage medium such as an optical storage device, a magnetic storage device, etc. In another embodiment, the computer program may also be transmitted and distributed in the form of a signal on a network medium, and downloaded and installed through the communication part 709, and / or installed from a removable medium 711. The program code contained in the computer program may be transmitted using any appropriate network medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0170] According to an embodiment of the present disclosure, the program code for executing the computer program provided by the embodiment of the present disclosure can be written in any combination of one or more programming languages. Specifically, these computing programs can be implemented using high-level process and / or object-oriented programming languages, and / or assembly / machine languages. Programming languages include, but are not limited to, Java, C++, python, "C" language or similar programming languages. The program code can be executed entirely on the user computing device, partially on the user device, partially on the remote computing device, or entirely on the remote computing device or server. In the case of a remote computing device, the remote computing device can be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computing device (e.g., using an Internet service provider to connect through the Internet).
[0171] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each box in the flowchart or block diagram may represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of the code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box may also occur in an order different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of boxes in the block diagram or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions. It can be understood by those skilled in the art that the features recorded in the various embodiments and / or claims of the present disclosure can be combined and / or combined in a variety of ways, even if such a combination or combination is not explicitly recorded in the present disclosure. In particular, without departing from the spirit and teaching of the present disclosure, the features described in the various embodiments and / or claims of the present disclosure may be combined and / or combined in a variety of ways. All of these combinations and / or combinations fall within the scope of the present disclosure.
[0172] The embodiments of the present disclosure are described above. However, these embodiments are only for illustrative purposes and are not intended to limit the scope of the present disclosure. Although the embodiments are described above separately, this does not mean that the measures in the various embodiments cannot be used in combination to advantage. The scope of the present disclosure is defined by the attached claims and their equivalents. Without departing from the scope of the present disclosure, those skilled in the art may make a variety of substitutions and modifications, which should all fall within the scope of the present disclosure.
Claims
1. A method for testing a smart contract deployed on a blockchain node, comprising: According to the case scheduling strategy, multiple target test cases and the dependency relationship between each of the target test cases are scheduled from the multiple test cases, wherein the target test case includes a preset matching relationship, a contract address, a contract execution parameter and a variable name associated with the contract address, and the case scheduling strategy is generated according to the case execution information of each of the test cases and the dependency relationship between each of the test cases; Determining the execution order of each of the target test cases according to the dependency relationship between the test cases; For each target test case among the multiple target test cases, when it is determined that the execution order of the target test case has been reached, according to a preset matching relationship corresponding to the target test case, a variable name in the target test case is converted into a variable address corresponding to the variable name; Determine the smart contract to be tested according to the contract address; Initialize the smart contract to be tested according to the contract execution parameters to obtain an initialized smart contract to be tested; and Execute the initialized smart contract to be tested to obtain a contract execution result, wherein the contract execution result includes variable information associated with the variable address.
2. The method according to claim 1, further comprising: For each smart contract to be tested among the multiple smart contracts to be tested, determine internal parameter information for the smart contract to be tested, wherein the internal parameter information includes variables associated with the smart contract to be tested, and the variables include variable names; Determine external parameter information for the smart contract to be tested, wherein the external parameter information includes a preset matching relationship, a contract execution parameter, a contract address of the smart contract to be tested, and a contract execution result determination strategy; and Generate a test case for the smart contract to be tested based on the internal parameter information and external parameter information of the smart contract to be tested.
3. The method according to claim 2, further comprising: For each test case in the plurality of test cases, determining case execution information of the test case, wherein the case execution information includes at least one of a test case identifier, a test time, a test number, and a test mode; Determine the dependency relationship between each of the test cases according to the business logic; and The case scheduling strategy is generated according to the case execution information of each of the test cases and the dependency relationship between each of the test cases.
4. The method according to claim 1, wherein: The step of converting the variable name in the target test case into a variable address corresponding to the variable name according to a preset matching relationship corresponding to the target test case when determining that the execution order of the target test case has been reached includes: In the case where it is determined that there is a preceding test case for the target test case, determining whether the preceding test case is successfully executed; In the case where it is determined that the preceding test case is successfully executed, determining that the execution order of the target test case is reached; and When it is determined that the execution order of the target test case has been reached, the variable name in the target test case is converted into a variable address corresponding to the variable name according to a preset matching relationship corresponding to the target test case.
5. The method according to claim 1, further comprising: According to the preset matching relationship, the variable address in the contract execution result is converted into a variable name corresponding to the variable address, and a test log for the smart contract to be tested is obtained.
6. The method according to claim 1, further comprising: Obtaining a result query request, wherein the result query request includes a query condition; In response to the result query request, obtaining a contract execution result corresponding to the query condition; and Display the contract execution results corresponding to the query conditions.
7. The method according to claim 1, further comprising: Get policy query request; In response to the policy query request, obtaining the case scheduling policy; as well as Displays the case scheduling policy.
8. The method according to claim 1, wherein: The converting the variable name in the target test case into a variable address corresponding to the variable name according to a preset matching relationship corresponding to the target test case includes: When it is determined that the test method of the target test case is a manual test method, if a test request for the target test case is obtained, in response to the test request, the variable name in the target test case is converted into a variable address corresponding to the variable name according to the preset matching relationship.
9. A device for testing a smart contract deployed on a blockchain node, comprising: A scheduling module, used for scheduling multiple target test cases and the dependency relationship between each of the target test cases from multiple test cases according to a case scheduling strategy, wherein the target test case includes a preset matching relationship, a contract address, a contract execution parameter and a variable name associated with the contract address, and the case scheduling strategy is generated according to the case execution information of each of the test cases and the dependency relationship between each of the test cases; A sixth determination module, used to determine the execution order of each target test case according to the dependency relationship between the target test cases; a conversion module, for each target test case among the multiple target test cases, when it is determined that the execution order of the target test case has arrived, according to a preset matching relationship corresponding to the target test case, converting a variable name in the target test case into a variable address corresponding to the variable name according to the preset matching relationship; A first determination module, used to determine the smart contract to be tested according to the contract address; A first obtaining module is used to initialize the smart contract to be tested according to the contract execution parameters to obtain the initialized smart contract to be tested; and An execution module is used to execute the initialized smart contract to be tested to obtain a contract execution result, wherein the contract execution result includes variable information associated with the variable address.
10. An electronic device comprising: one or more processors; a memory for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 8.
11. A computer-readable storage medium having executable instructions stored thereon, which, when executed by a processor, enables the processor to implement the method according to any one of claims 1 to 8.
12. A computer program product, comprising a computer program, wherein the computer program is used to implement the method according to any one of claims 1 to 8 when executed by a processor.
Citation Information
Patent Citations
Intelligent contract test method and device, computer equipment and storage medium
CN111090581A
Test method, device and system, electronic equipment and storage medium
CN111914262A
Method and system for testing blockchain smart contract
CN112286828A
Automatic testing method and device for intelligent contract, computer equipment and storage medium
CN112380128A
Smart contract test method and device, equipment and storage medium
CN112416800A
