Block chain construction function test method and system, and computer equipment
The proposed method and system for testing block chain construction functionality address existing challenges by automating the testing process, ensuring isolation and stability, and improving test coverage and reliability, thereby enhancing the efficiency and quality of block chain construction.
Patent Information
- Application Number
- CN202411569714.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-05
- Publication Date
- 2025-03-18
AI Technical Summary
Current methods for testing block chain construction functionality in blockchain networks face challenges such as high deployment and maintenance costs, inadequate comprehensive testing libraries, difficulty in replicating complex scenarios, and lack of automated continuous integration processes, leading to low test coverage and reliability.
A method and system for testing block chain construction functionality that involves a testing server receiving code, obtaining environment configuration parameters and test cases, deploying a test environment with a test block chain, executing test cases, and replicating transaction scenarios to determine test results, ensuring isolation and stability, and enabling automated continuous integration and delivery.
This approach reduces testing costs and enhances efficiency, reliability, and coverage, ensuring the stability and quality of block chain construction functionality by providing a comprehensive and automated testing framework.
Smart Images

Figure CN119645832A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of blockchain technology, and in particular, relates to a testing method, system and computer equipment for blockchain construction functions. Background Art
[0002] Block building is a crucial part of the blockchain network. The quality of block building directly affects the security, stability and performance of the entire blockchain system. The Builder in the blockchain is an entity or role that is specifically responsible for building blocks. The block builder can package transactions into blocks according to certain rules and publish these blocks to validators or verifiers, so that transactions can participate in the consensus process of the blockchain network. In actual applications, the block building process involves multiple links, including transaction packaging, block generation, verification and synchronization, and each link may have potential security vulnerabilities or performance bottlenecks.
[0003] Therefore, after the block building function is developed or updated, it needs to be tested before it can be put into use in the blockchain. At present, when testing the block building function, transaction scenarios are generally constructed manually. However, manually constructing transaction scenarios takes a long time and is difficult to achieve comprehensive testing, resulting in low test coverage. Summary of the invention
[0004] In view of this, the embodiments of the present application provide a testing method, system and computer device for blockchain construction function, so as to improve the coverage of blockchain construction function testing.
[0005] A first aspect of an embodiment of the present application provides a method for testing a blockchain construction function, including:
[0006] Based on the code of the blockchain building function to be tested, obtain the environment configuration parameters and multiple test cases;
[0007] Deploy a test environment in a test server according to the environment configuration parameters, wherein the test environment includes a test blockchain;
[0008] In the test environment, executing each of the test cases through the test blockchain to obtain execution results of each of the test cases;
[0009] Reproduce the transaction scenarios for the test cases with abnormal execution results to obtain the block construction results under various transaction scenarios;
[0010] Based on the block construction result and the target function of the code, a test result of the code is determined.
[0011] A second aspect of an embodiment of the present application provides a test system for a block construction function, including a test server and a test platform, wherein the test platform is deployed with a central configuration library, a test case library, and a version control module, wherein:
[0012] The version control module is used to send the code of the blockchain construction function to be tested to the test server when receiving the code;
[0013] The test server is used to obtain environment configuration parameters and multiple test cases based on the code; deploy a test environment in the test server according to the environment configuration parameters, wherein the test environment includes a test blockchain; in the test environment, execute each of the test cases through the test blockchain to obtain an execution result of each of the test cases; reproduce the transaction scenario for the test case with an abnormal execution result to obtain a block construction result under each transaction scenario; and determine the test result of the code based on the block construction result and the target function of the code.
[0014] A third aspect of an embodiment of the present application provides a testing device for a block construction function, which is applied to a testing server, and the device includes:
[0015] The data acquisition module is used to obtain the environment configuration parameters and multiple test cases based on the code of the blockchain function to be tested;
[0016] An environment deployment module, used to deploy a test environment in a test server according to the environment configuration parameters, wherein the test environment includes a test blockchain;
[0017] A test execution module, used to execute each of the test cases through the test blockchain in the test environment to obtain an execution result of each of the test cases;
[0018] A transaction reproduction module is used to reproduce the transaction scenario of the test case with abnormal execution results to obtain the block construction results under each transaction scenario;
[0019] A result generation module is used to determine a test result of the code based on the block construction result and the target function of the code.
[0020] A fourth aspect of an embodiment of the present application provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method described in the first aspect when executing the computer program.
[0021] A fifth aspect of an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method described in the first aspect above is implemented.
[0022] A sixth aspect of the embodiments of the present application provides a computer program product. When the computer program product is run on a computer device, the computer device executes the method described in the first aspect.
[0023] Compared with the prior art, the embodiments of the present application have the following advantages:
[0024] The method in the embodiment of the present application can be used to test the code of the blockchain construction function. After the code of the blockchain construction function is newly developed or updated, the code can be tested. When testing, the test server can receive the code to be tested. According to the code to be tested, the test server can obtain environment configuration parameters and test cases. The test server can deploy the test environment based on the environment configuration parameters, and the test environment can include a test blockchain, which can be consistent with the target blockchain to which the code will be applied, so that the test server can provide a stable test environment. At the same time, testing in the test server can avoid interference from the external environment during the test process, ensuring the isolation of the test. In an isolated and stable test environment, the test blockchain can be used to execute each test case, thereby obtaining the execution results of each test case. If the execution result of the test case is normal, the test case can be processed without further processing. If the execution result of the test case is abnormal, the code can be judged by reproducing the transaction scenario to achieve the target function. The test server can reproduce the transaction scenario for the test case with an abnormal execution result, thereby obtaining the block construction results under each transaction scenario. Based on the block construction result, the test server can determine whether the code can achieve the target function, thereby obtaining the test result. The method in the embodiment of the present application can automatically test the code when the blockchain construction function is developed or updated, ensure the stability and isolation during the test process, and improve the test coverage. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art.
[0026] Figure 1 This is a schematic diagram of the steps of a method for testing a blockchain construction function provided in an embodiment of the present application;
[0027] Figure 2 This is a schematic diagram of the steps of another method for testing a blockchain construction function provided in an embodiment of the present application;
[0028] Figure 3 It is a schematic diagram of a test system for a blockchain construction function provided in an embodiment of the present application;
[0029] Figure 4 It is a test flow diagram of a test system provided in an embodiment of the present application;
[0030] Figure 5 It is a schematic diagram of a testing device for a blockchain construction function provided in an embodiment of the present application;
[0031] Figure 6 It is a schematic diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0032] In the following description, specific details such as specific system structures, technologies, etc. are proposed for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application can also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from hindering the description of the present application.
[0033] Block builders usually exist in the Proposer-Builder Separation (PBS) model of the Ethereum blockchain. They obtain pending transactions from the unconfirmed transaction pool (Mempool) and perform highly optimized block construction tasks off-chain.
[0034] After the block building function is developed or updated, it needs to be tested. Only after the test is passed can the block building function be widely used. In the testing of blockchain building functions, the manual transaction construction method is usually relied on to verify the blockchain building function under development, and there is still a lack of a complete automated system solution. The current testing method has the following problems.
[0035] The current testing methods require high deployment and maintenance costs. During the current testing, the manual deployment of the test chain and the compatibility issues of different blockchain environments make the construction and maintenance of the test environment consume a lot of time and resources.
[0036] There is currently a lack of a comprehensive test library when testing. Currently, there is no complete and systematic test library to support comprehensive testing of block building functions, resulting in insufficient test coverage and inability to effectively evaluate the stability and reliability of block building functions.
[0037] In addition, the testing of blockchain building functions also has the problem of high difficulty in reproducing complex scenarios. In the process of manual testing, scenarios involving complex transactions are often difficult to reproduce accurately, and the accuracy and consistency of the test are difficult to ensure, which can easily lead to potential problems being missed.
[0038] In addition, there is still a lack of a complete continuous integration testing process. The existing testing process lacks a continuous integration mechanism combined with product version management, making it difficult to achieve automated version control and regression testing, resulting in low development efficiency and the inability to effectively guarantee the stability and quality of product releases.
[0039] In summary, developing an automated testing system specifically for the block building function can significantly reduce testing costs, improve testing efficiency and coverage, and enhance the reliability and consistency of test results, which is of great significance for improving R&D efficiency and product quality. Based on this, the present application embodiment provides a testing method and testing system for the blockchain building function.
[0040] The technical solution of the present application is described below through specific embodiments.
[0041] Reference Figure 1 , shows a schematic diagram of the steps of a method for testing a blockchain construction function provided in an embodiment of the present application, which may specifically include the following steps:
[0042] S101, based on the code of the blockchain function to be tested, obtain environment configuration parameters and multiple test cases.
[0043] The execution subject of this embodiment may be a test server. The test server may be deployed in a test system. The test system may include a test platform and a test server, wherein the test platform may receive the code to be tested, and after receiving the code to be tested, may automatically trigger the test process for the code. The test platform may send the code to the test server, and the independent test server may perform the test on the code. It should be noted that the test platform may receive multiple codes to be tested, and send each code to be tested to each independent test server for test execution. In this embodiment, the test method in this application is described by taking the test process of a code as an example.
[0044] The test server is an independent server, that is, it is not affected by the external environment, thus ensuring stability during the test. The test server can ensure that the network status and memory status during the test are sufficient, thereby reducing the impact of the test environment on the test results.
[0045] Each code to be tested can have a targeted target blockchain for implementing the target function in the target blockchain. The target blockchain is the blockchain where the code is deployed in actual applications. The code can be used to add a new target function in the target blockchain, or it can be used to update the target function in the target blockchain. The code can be new code that is tested for the first time, or it can be a modified code based on the last test. Exemplarily, the code can be used to sort transactions in the target blockchain by value, that is, if the code is added to the target blockchain, then after the target blockchain builds a block, the transactions in the block can be sorted in order of value.
[0046] When testing the code in an independent test server, you need to deploy the environment in the test server. When deploying the environment, you need to obtain the test environment data corresponding to the code so that you can deploy the corresponding test environment in the test server.
[0047] The test platform may include a central configuration library, which can be used to store test environment parameters. The environment configuration parameters in the central configuration library can be stored in the form of files. In the central configuration library, test environment parameters can be stored according to the version of the target blockchain, the template function of the code, the application scenario of the code, etc.
[0048] After receiving the code, the test server can obtain the environment configuration parameters from the central configuration library according to the code. The environment configuration parameters may include the environment parameters corresponding to the target blockchain and the parameters of the target blockchain, so that the environment configuration of the test server can be performed to test the configuration of the blockchain. The configuration parameters are stored in the form of files, including but not limited to: the startup parameters of the blockchain node and the module parameters that need to be specified to execute this round of testing. The test environment parameters are stored in the form of cfg.toml files. The following is an example of test environment parameters:
[0049] [test]\n modules = ["mq"]\n The execution module is mq
[0050] level="p0"\nExecutes the use case with priority P0
[0051] log = "FAILED" \nOnly keep the log of failed cases
[0052] data=true\nRetain test data
[0053] repeat=1\nNumber of repetitions
[0054] pytest="-v --alluredir=report --clean-alluredir"\nInitialize the test report folder
[0055] branch="ljx / tracelog"\nTest code branch
[0056] [testcase]\n
[0057] mq = ["message_push / test_01"]\nExecute all test cases in the test_01 test suite under the message_push folder
[0058] When testing, test cases are required so that the test server can conduct comprehensive tests on the code. A test case library can be deployed in the test platform, which can include a large number of test cases. The test cases in the test case library can be classified according to functional modules, scenario types, etc. The test cases included in the test case library can cover different versions of functions and various transaction scenarios. The test server can obtain test cases from the test platform according to the code.
[0059] The code has version information, which can be used to characterize the version of the target blockchain corresponding to the code. Since the target blockchain can be continuously updated, it can have a corresponding version after each update, and each version uses different test cases. When the template functions implemented by the code are different, the test cases required for testing may also be different. For example, when the target function is to enable transactions to be sorted according to the transaction volume when the block is constructed, the test case needs to ensure that there are differences in the transaction volume of the constructed transactions, so that the corresponding function can be determined based on the results.
[0060] The test server can determine the test case set corresponding to the code from the test case library according to the version information of the code, and then determine multiple test cases from the test case set according to the target function of the code.
[0061] S102, deploying a test environment in a test server according to the environment configuration parameters, wherein the test environment includes a test blockchain.
[0062] When testing, the code needs to be integrated into the target blockchain for testing. Therefore, the test environment can include a test blockchain that is consistent with the target blockchain. When deploying the environment, the test server can automatically configure the test environment based on the obtained environment configuration parameters, so that the test server includes a test blockchain that is consistent with the target blockchain, and configures all necessary environment variables and dependencies on the independent server to ensure that the test environment is consistent with the actual production environment.
[0063] In a possible implementation, the environment configuration parameters in the central configuration library may be container data, and the test server may directly use the container for environment configuration.
[0064] S103: In the test environment, each of the test cases is executed through the test blockchain to obtain an execution result of each of the test cases.
[0065] The test server can call the test blockchain to execute each test case, and then obtain the execution result of each test case. If the execution result of the test case is consistent with the expected result, it is determined that the execution result of the test case is normal. If the execution result of the test case is inconsistent with the expected result, it is determined that the execution result of the test case is abnormal.
[0066] S104, reproducing the transaction scenario for the test case with abnormal execution result, and obtaining the block construction result under each transaction scenario.
[0067] When the execution result of a test case is abnormal, the transaction scenario can be reproduced based on each test case, so as to continue testing based on each test case.
[0068] For each test case with an abnormal execution result, the test server can generate a test script for simulating transactions based on pre-defined transaction scenarios; then construct multiple transactions under each transaction scenario; based on the constructed multiple transactions, execute the test script to obtain the block construction results under each transaction scenario.
[0069] The above-mentioned predefined transaction scenarios can be relatively complex transaction scenarios, such as arbitrage attacks on blockchains, sandwich attacks, etc. For example, in a sandwich attack scenario, an attacker inserts his own transactions into blockchain transactions one after another, with the purpose of profiting from the price changes caused by the victim's transactions.
[0070] Automated testing tools can be deployed in the test server to batch construct multiple transactions under various transaction scenarios based on specified transaction scenarios and users, so that tests can be performed based on multiple transactions.
[0071] S105: Determine a test result of the code based on the block construction result and the target function of the code.
[0072] The block building function of the test blockchain is used to package transactions to build blocks. Therefore, the above block building results can include individual transactions. Based on whether each transaction meets expectations, it can be determined whether the test has passed.
[0073] The test server can detect whether the construction results of each block match the target function of the code, thereby determining the test result of the code. If the construction results of each block match the target function of the code, the test result can be determined as a passed test. If there is a mismatch between the construction results of a block and the target function of the code, the test result can be determined as a failed test.
[0074] The block construction result may include the arrangement, storage, verification, and synchronization methods of transactions. Based on the target function of the code, the test server can obtain the corresponding information from the block construction result to determine whether it matches the target function. For example, if the target function is to sort transactions from large to small in terms of transaction volume, the test server can obtain the order of transactions in the constructed block. If the transactions in the block are sorted from large to small in terms of transaction volume, it can be determined that the block construction result matches the target function, that is, the code can achieve its expected target function, and the test result is a pass.
[0075] In this embodiment, after the code is submitted, an automatic testing process can be triggered, and the test platform can send the code to an independent test server for testing. When the test server is testing, it can automatically obtain environmental parameters from the central configuration library, so as to deploy the same test scenario as the actual production environment to ensure the effectiveness of the test. Testing in an independent test server can avoid interference from other systems or applications during the test process, and provide a pure test environment, thereby ensuring the stability and isolation of the test environment. During testing, a test case library uniformly managed and maintained by the test platform can be used, thereby simplifying the organization and version control of test cases. Unified management can reduce duplication of work and ensure the consistency and integrity of test cases. During the test process, testing can be performed based on test cases first, and when the execution result of the test case is abnormal, a transaction scenario can be automatically constructed to continue testing, thereby making the test more comprehensive and improving the test coverage.
[0076] Reference Figure 2 , shows a schematic diagram of the steps of another method for testing a blockchain construction function provided in an embodiment of the present application, which may specifically include the following steps:
[0077] S201, based on the code of the blockchain function to be tested, obtain environment configuration parameters and multiple test cases.
[0078] The execution subject of this embodiment may be the above-mentioned test server.
[0079] S202, deploying a test environment in a test server according to the environment configuration parameters, wherein the test environment includes a test blockchain.
[0080] S203: In the test environment, each of the test cases is executed through the test blockchain to obtain an execution result of each of the test cases.
[0081] S204, reproducing the transaction scenario for the test case with abnormal execution result, and obtaining the block construction result under each transaction scenario.
[0082] S205: Determine a test result of the code based on the block construction result and the target function of the code.
[0083] S201 - S205 in this embodiment may refer to S101 - S105 in the previous embodiment, and will not be described in detail here.
[0084] S206: If the test result is that the test passes, the code is deployed to the target blockchain to implement the target function in the target blockchain.
[0085] Once the test passes, it means that the code can be applied to actual production, so it can be deployed to the target blockchain.
[0086] Before the code is deployed to the target blockchain, in order to ensure that the code will not affect the stable operation and existing functions of the target blockchain after being applied to the target blockchain, the code can be subjected to smoke testing and regression testing before being deployed to the target blockchain, thereby achieving a comprehensive test of the code. If both the smoke test and regression test pass, the code can be deployed to the target blockchain. If the smoke test and regression test fail, it can indicate that there is a fault in the code and the test fails.
[0087] In one possible implementation, the test server used for regression testing and smoke testing can be different from the test server used for testing based on test cases. That is, the test environment can be automatically deployed by another test server, and then the code is sent to the test server before it is deployed to the target blockchain, so that the test server performs continuous integration and continuous delivery (CICD) feedback. The CICD process supports the designated development branch for smoke testing to ensure that the core functions can run normally after each code change. Smoke testing can identify and fix potential major defects at an early stage, reducing the risks of subsequent development and testing stages. Through integrated continuous testing and automated build processes, the system can automatically detect and report newly introduced defects. In this way, developers can find and fix problems in a timely manner, avoiding new defects introduced by code modifications that affect the stability and quality of the system.
[0088] In addition, the test case library in this embodiment can be automatically updated. After the code is deployed to the target blockchain through testing, the test platform can update the version information of the target blockchain; based on the updated version information of the target blockchain, the test case library can be updated.
[0089] S207: If the test result is that the test fails, a feedback report is generated based on the data generated during the test process and the environment deployment process.
[0090] When a test fails, a feedback report containing a detailed description of the problem can be generated. The automatically generated feedback report can include the specific results of the test case execution, performance data, analysis of the cause of failure, and possible optimization suggestions. Developers can optimize the code based on the feedback report.
[0091] In addition, during the test process, the test platform can continuously monitor the test environment to ensure the stability and availability of the test environment. At preset intervals, the test environment in the test server can be backed up. In real work scenarios, network disconnection, insufficient memory, and blockchain node crashes may cause the test chain to be unavailable. Therefore, the test environment can be monitored to determine whether the test server has network disconnection, insufficient memory, and blockchain node crashes during the test process, so as to determine whether the test environment is stable.
[0092] In the embodiment of the present application, continuous integration and continuous delivery of code can be achieved. After the test environment is deployed and the test cases are executed, smoke testing can be used to avoid the introduction of major defects. Through comprehensive regression testing, the test coverage of all functional modules and scenarios is ensured. The code can be deployed to the target blockchain only after all tests pass. When the test fails, a feedback report can be generated, which can be used to optimize the subsequent test process and code quality.
[0093] Reference Figure 3 , which shows a schematic diagram of a test system for a blockchain construction function provided by an embodiment of the present application, such as Figure 3 As shown, the test system may specifically include: a test platform and a test server. Figure 3 As shown, the version control module, central configuration library and test case library can be deployed in the test platform. The test platform can be connected to multiple independent test servers. Among them:
[0094] A version control module can be used to send the code to the test server when receiving the code of the blockchain construction function to be tested;
[0095] The test server can be used to obtain environment configuration parameters and multiple test cases based on the code; deploy the test environment in the test server according to the environment configuration parameters, and the test environment includes a test blockchain; in the test environment, execute each test case through the test blockchain to obtain the execution result of each test case; reproduce the transaction scenario for the test case with abnormal execution result to obtain the block construction result under each transaction scenario; determine the test result of the code based on the block construction result and the target function of the code.
[0096] Exemplarily, the test platform can be Gitlab. The version control module, central configuration library and test case library can all be deployed in Gitlab and managed independently in different warehouses. The test environment can be deployed on an independent test server, which can be maintained by management personnel.
[0097] The above-mentioned test system can start with the submission of the code to be tested, and through the process of automated environment deployment, dynamic use case management, complex scenario reproduction, and continuous integration and delivery, it can achieve all-round automated testing of blockchain construction functions. Figure 4 The test process based on the above test system is shown as follows:
[0098] After developers have completed the development or modification of the code for blockchain building functions, they can push the code to the version control module. This submission operation can automatically trigger the continuous integration and delivery process of the test system.
[0099] The version control module can send the code to a test server for testing. The test server can obtain the environment configuration parameters from the central configuration library; based on the obtained environment configuration parameters, the test chain can be automatically deployed and all necessary environment variables and dependencies can be configured on the independent test server to ensure that the test environment is consistent with the production environment. In addition, the test platform can automatically back up the test environment data regularly and continuously monitor the environment status to ensure the stability and availability of the test environment.
[0100] The test case library managed by the test platform can dynamically adjust the test cases according to the functional requirements of the blockchain. The test system can automatically select applicable test cases from the centrally managed test case library by functional module, scenario type, etc. to cover different versions of functions and various transaction scenarios. If there is a need to update the test case, the test system can dynamically update and optimize the test case according to the latest functional changes to ensure the integrity and timeliness of the test case library.
[0101] The test server can obtain multiple test cases from the test case library to perform tests and obtain execution results.
[0102] Afterwards, the test system can automatically generate test scripts or smart contracts based on the defined complex transaction scenarios through the automated scenario reproduction tool module, thereby simulating various transactions and operations. The test system can execute test scripts or smart contracts to reproduce the predetermined transaction scenarios, ensuring the stability and correctness of the blockchain construction function in various complex scenarios.
[0103] During the test execution process, the test system can monitor the operation in real time and record the execution log and results for subsequent analysis and debugging.
[0104] After the scenario is built, the continuous integration and continuous delivery process can be executed. After the test environment is deployed and the test cases are executed, the test system can enter the continuous integration and continuous delivery process. First, the test system performs smoke testing to quickly verify whether the core functions are running normally and avoid the introduction of major defects. The test system performs comprehensive regression testing to ensure the test coverage of all functional modules and scenarios.
[0105] If all tests pass, the test system can automatically deploy the new version of the target blockchain corresponding to the code to the test or production environment and generate a release report. If defects are detected in the code, the test system can automatically notify the developer to fix it.
[0106] The testing system can continuously collect and analyze data generated during the testing and deployment process, and generate feedback reports for optimizing subsequent testing processes and code quality.
[0107] The test system can provide continuous feedback and optimization. The test system centralizes all test results, performance data, and feedback information on a data analysis platform. Through data analysis and machine learning models, the system identifies common problems and improvement points and provides code optimization suggestions. The optimized suggestions will be directly fed back to developers or automatically applied to the test process to further improve system stability and test efficiency.
[0108] The test system can work together through multiple modules to ensure the stability of the test environment, comprehensive coverage of test cases, accuracy of scenario reproduction, and efficiency of version release. Ultimately, the system provides an efficient and reliable automated testing framework, which significantly improves the efficiency of development and testing, and ensures product quality and update speed.
[0109] The present application scheme is described below with a specific example. For example, the target function that the code can achieve is that the transaction sorting algorithm puts transactions with large value at the front. During testing, it can be verified whether the transaction sorting algorithm constructed by the blockchain correctly puts transactions with large value at the front. Specifically, it can include the following process:
[0110] After developers develop or modify the transaction sorting algorithm, they can push the code to the version control module. The action of submitting the code can trigger the continuous integration and delivery process, thereby starting the test of the code by the automated testing system.
[0111] The test system can obtain the required environmental parameters from the central configuration library, automatically deploy the blockchain test chain on an independent server, and configure all necessary environmental variables and dependencies to ensure that the environment is consistent with the production environment. The test system can perform basic checks to ensure that all nodes and components are running normally, and perform automated backups of the environment to ensure data security.
[0112] The test case library module managed uniformly in the test system automatically selects test cases related to the "transaction sorting algorithm". These test cases will focus on verifying the ordering of transactions of different values within the block. The test system automatically selects applicable test cases based on the current version of the blockchain construction algorithm to ensure that all possible scenarios are covered, such as test cases that can contain different numbers of transactions, different value distributions, etc.
[0113] The test system can use the automated scenario reproduction tool module to generate test scripts to simulate a series of transaction inputs. The test scripts include transaction combinations of different values, such as high-value, low-value, and medium-value transactions. These test scripts are executed to reproduce specific transaction sorting scenarios to ensure that transactions of different values are sorted according to the expected rules, that is, transactions with large values are ranked first.
[0114] The test system executes the generated script and monitors the process of each block generation. The system checks the order of transactions in the block to verify whether it complies with the algorithm rules, that is, transactions with large value are ranked first.
[0115] The test system records the logs and results of test execution in real time, including key information such as the order of transaction sorting, value, and algorithm execution time.
[0116] The test system analyzes the test results to check whether the sorting is as expected. If all test cases pass, it means that the transaction sorting algorithm works as expected; if there are any non-compliance cases, the test system will generate a report containing a detailed description of the problem.
[0117] Automatically generated test reports can include detailed results of test case execution, performance data, failure cause analysis, and possible optimization suggestions.
[0118] If the test passes, the system will trigger the next stage of automated deployment and advance to the release process.
[0119] If a test fails, the system will automatically notify the relevant developers and provide a detailed test report so that they can fix the problem and resubmit the code to re-trigger the testing process.
[0120] In this embodiment, the test system can provide an independent operating environment. The test blockchain can be run on a dedicated independent server, thereby avoiding interference with other systems or applications, providing a pure test environment, and ensuring the isolation and stability of the test environment.
[0121] The test system can automatically back up data. The test system can automatically perform backup operations regularly to ensure the security and durability of test data. Regular backup helps prevent potential risks caused by data loss and system failures, and supports rapid recovery to a stable state when problems occur.
[0122] The test system can provide a unified test case library. The test case library is maintained and updated through a unified management platform, which simplifies the organization and version control of the test cases. Unified management can reduce duplication of work and ensure the consistency and integrity of test cases. The test case library is maintainable. Centralized management makes the maintenance and expansion of test cases more efficient. When adding, modifying or deleting test cases, there is no need to manually adjust multiple scattered test case sets, reducing management complexity and error risks.
[0123] The test system can dynamically manage test cases, thereby reducing code redundancy. According to the functions of different versions of block builders, the test system can dynamically adjust and manage test cases, thereby ensuring that test cases can adapt to different functional requirements without the need to repeatedly write redundant code. By dynamically managing and selecting applicable test cases, the test system effectively reduces redundant test scripts and codes, optimizes the use of test resources, and improves test coverage and efficiency.
[0124] The test system has established a continuous integration and continuous delivery process. The continuous integration and continuous delivery process supports designated development branches for smoke testing to ensure that the core functions can operate normally after each code change. Smoke testing can identify and fix potential major defects in the early stages, reducing the risks in the subsequent development and testing stages. The continuous integration and continuous delivery process can prevent the introduction of new defects. Through integrated continuous testing and automated build processes, the test system can automatically detect and report newly introduced defects. In this way, developers can find and fix problems in a timely manner, avoiding new defects introduced by code modifications that affect the stability and quality of the system.
[0125] It should be noted that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0126] Reference Figure 5 , shows a schematic diagram of a test device for a blockchain construction function provided in an embodiment of the present application, which can be applied to a test server, and specifically may include a data acquisition module 51, an environment deployment module 52, a test execution module 53, a transaction reproduction module 54, and a result generation module 55, wherein:
[0127] A data acquisition module 51 is used to acquire environment configuration parameters and multiple test cases based on the code of the blockchain construction function to be tested;
[0128] An environment deployment module 52, configured to deploy a test environment in a test server according to the environment configuration parameters, wherein the test environment includes a test blockchain;
[0129] A test execution module 53 is used to execute each of the test cases through the test blockchain in the test environment to obtain the execution results of each of the test cases;
[0130] The transaction reproducing module 54 is used to reproduce the transaction scenario of the test case with abnormal execution result, and obtain the block construction result under each transaction scenario;
[0131] The result generation module 55 is used to determine the test result of the code based on the block construction result and the target function of the code.
[0132] In a possible implementation, the data acquisition module 51 includes:
[0133] A code receiving submodule, used for receiving the code issued by a test platform, wherein the test platform is deployed with a central configuration library and a test case library;
[0134] An environment configuration parameter acquisition submodule, used to acquire the environment configuration parameters from the central configuration library according to the code;
[0135] The test case acquisition submodule is used to acquire multiple test cases from the test case library according to the code.
[0136] In a possible implementation, the test case acquisition submodule includes:
[0137] A test case set acquisition unit, configured to determine a test case set corresponding to the code from the test case library according to version information of the code, wherein the version information is used to characterize a version of a target blockchain corresponding to the code;
[0138] A test case determination unit is used to determine a plurality of test cases from the test case set according to the target function of the code.
[0139] In a possible implementation, the transaction reproduction module 54 includes:
[0140] A test script generation submodule, for generating a test script for simulating a transaction according to a predefined transaction scenario for each of the test cases with abnormal execution results;
[0141] A transaction construction submodule, used to construct multiple transactions under each of the transaction scenarios;
[0142] The block construction result acquisition submodule is used to execute the test script based on the constructed multiple transactions to obtain the block construction results under each transaction scenario.
[0143] In a possible implementation manner, the device further includes:
[0144] A deployment module, configured to deploy the code to a target blockchain if the test result is a pass, so as to implement the target function in the target blockchain;
[0145] The feedback report generation module is used to generate a feedback report based on the data generated during the test process and the environment deployment process if the test result is that the test fails.
[0146] In a possible implementation manner, the device further includes:
[0147] A version information updating module, used to update the version information of the target blockchain after the code is deployed to the target blockchain;
[0148] The test case library update module is used to update the test case library based on the updated version information of the target blockchain.
[0149] In a possible implementation manner, the device further includes:
[0150] A test submodule for performing smoke testing and regression testing on the code;
[0151] The judgment submodule is used to execute the step of deploying the code to the target blockchain if both the smoke test and the regression test are passed.
[0152] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the description of the method embodiment part.
[0153] Figure 6 This is a schematic diagram of the structure of a computer device provided in an embodiment of the present application. Figure 6 As shown, the computer device 6 of this embodiment includes: at least one processor 60 ( Figure 6Only one is shown in the figure), a memory 61, and a computer program 62 stored in the memory 61 and executable on the at least one processor 60, wherein the processor 60 implements the steps of any of the above-mentioned method embodiments when executing the computer program 62.
[0154] The computer device 6 may be a server. The computer device may include, but is not limited to, a processor 60 and a memory 61. Those skilled in the art will appreciate that Figure 6 It is only an example of the computer device 6 and does not constitute a limitation on the computer device 6. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, it may also include input and output devices, network access devices, etc.
[0155] The processor 60 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0156] In some embodiments, the memory 61 may be an internal storage unit of the computer device 6, such as a hard disk or memory of the computer device 6. In other embodiments, the memory 61 may also be an external storage device of the computer device 6, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the computer device 6. Further, the memory 61 may also include both an internal storage unit of the computer device 6 and an external storage device. The memory 61 is used to store an operating system, an application program, a boot loader (BootLoader), data, and other programs, such as the program code of the computer program, etc. The memory 61 may also be used to temporarily store data that has been output or is to be output.
[0157] An embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in the above-mentioned method embodiments can be implemented.
[0158] An embodiment of the present application provides a computer program product. When the computer program product is run on a computer device, the computer device can implement the steps in the above-mentioned method embodiments when executing the computer device.
[0159] The above-described embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application is described in detail with reference to the above-mentioned embodiments, a person skilled in the art should understand that the technical solutions described in the above-mentioned embodiments can still be modified, or some of the technical features can be replaced by equivalents; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be included in the protection scope of the present application.
Claims
1. A method for testing a blockchain construction function, characterized in that: include: Based on the code of the blockchain building function to be tested, obtain the environment configuration parameters and multiple test cases; Deploy a test environment in a test server according to the environment configuration parameters, wherein the test environment includes a test blockchain; In the test environment, executing each of the test cases through the test blockchain to obtain execution results of each of the test cases; Reproduce the transaction scenarios for the test cases with abnormal execution results to obtain the block construction results under various transaction scenarios; Based on the block construction result and the target function of the code, a test result of the code is determined.
2. The method according to claim 1, characterized in that The code for building the function based on the blockchain to be tested obtains environment configuration parameters and multiple test cases, including: Receiving the code issued by a test platform, wherein the test platform is deployed with a central configuration library and a test case library; According to the code, obtaining the environment configuration parameters from the central configuration library; According to the code, a plurality of test cases are obtained from the test case library.
3. The method according to claim 2, characterized in that The obtaining of a plurality of test cases from the test case library according to the code comprises: Determining a test case set corresponding to the code from the test case library according to the version information of the code, wherein the version information is used to characterize the version of the target blockchain corresponding to the code; According to the target function of the code, a plurality of test cases are determined from the test case set.
4. The method according to claim 1, characterized in that The transaction scenario is reproduced for the test case with abnormal execution result to obtain the block construction results under each transaction scenario, including: For each of the test cases with abnormal execution results, generating a test script for simulating transactions according to a predefined transaction scenario; Constructing multiple transactions under each of the transaction scenarios; Based on the constructed multiple transactions, the test script is executed to obtain the block construction results under each transaction scenario.
5. The method according to any one of claims 1 to 4, characterized in that: The method further comprises: If the test result is that the test passes, the code is deployed to the target blockchain to implement the target function in the target blockchain; If the test result is that the test fails, a feedback report is generated based on the data generated during the test process and the environment deployment process.
6. The method according to claim 5, characterized in that Before deploying the code to the target blockchain to implement the target function in the target blockchain, the method further includes: Perform smoke and regression testing on said code; If both the smoke test and the regression test pass, the step of deploying the code to the target blockchain is executed.
7. A block building function testing system, characterized in that: It includes a test server and a test platform, wherein the test platform is deployed with a central configuration library, a test case library and a version control module, wherein: The version control module is used to send the code of the blockchain construction function to be tested to the test server when receiving the code; The test server is used to obtain environment configuration parameters and multiple test cases based on the code; deploy a test environment in the test server according to the environment configuration parameters, wherein the test environment includes a test blockchain; in the test environment, execute each of the test cases through the test blockchain to obtain an execution result of each of the test cases; reproduce the transaction scenario for the test case with an abnormal execution result to obtain a block construction result under each transaction scenario; and determine the test result of the code based on the block construction result and the target function of the code.
8. The system according to claim 7, characterized in that The test platform is also used to: After the code is deployed to the target blockchain, updating the version information of the target blockchain; Based on the updated version information of the target blockchain, the test case library is updated.
9. The system according to claim 7 or 8, characterized in that The test platform is also used to: At preset time intervals, data backup is performed on the test environment in the test server.
10. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Block chain system stability testing methods, device and equipment and memory medium
CN109617759A
Block chain testing method and device
CN110162470A
Automatic testing method and device, terminal and storage medium
CN115481030A
Block chain automatic deployment and chaos testing method and device based on Go language and Chaos Blade
CN116974649A
General blockchain performance evaluation method based on dynamic proxy and smart contract
US20240220404A1