CN112380128A - Automatic testing method and device of intelligent contract, computer equipment and storage medium - Google Patents

Automatic testing method and device of intelligent contract, computer equipment and storage medium Download PDF

Info

Publication number
CN112380128A
CN112380128A CN202011286641.XA CN202011286641A CN112380128A CN 112380128 A CN112380128 A CN 112380128A CN 202011286641 A CN202011286641 A CN 202011286641A CN 112380128 A CN112380128 A CN 112380128A
Authority
CN
China
Prior art keywords
contract
test
tested
result
identifier
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202011286641.XA
Other languages
Chinese (zh)
Inventor
代健武
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
OneConnect Smart Technology Co Ltd
OneConnect Financial Technology Co Ltd Shanghai
Original Assignee
OneConnect Financial Technology Co Ltd Shanghai
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by OneConnect Financial Technology Co Ltd Shanghai filed Critical OneConnect Financial Technology Co Ltd Shanghai
Priority to CN202011286641.XA priority Critical patent/CN112380128A/en
Publication of CN112380128A publication Critical patent/CN112380128A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q40/00Finance; Insurance; Tax strategies; Processing of corporate or income taxes
    • G06Q40/04Trading; Exchange, e.g. stocks, commodities, derivatives or currency exchange

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Business, Economics & Management (AREA)
  • Accounting & Taxation (AREA)
  • Finance (AREA)
  • Quality & Reliability (AREA)
  • Computer Hardware Design (AREA)
  • Databases & Information Systems (AREA)
  • General Business, Economics & Management (AREA)
  • Technology Law (AREA)
  • Computing Systems (AREA)
  • Strategic Management (AREA)
  • Data Mining & Analysis (AREA)
  • Marketing (AREA)
  • Economics (AREA)
  • Development Economics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention relates to an automatic test method, a device, computer equipment and a storage medium of an intelligent contract, wherein the method comprises the following steps: acquiring a test contract corresponding to the first calling request information according to the received first calling request information; running a test contract, and sending second calling request information to a corresponding tested contract based on the test contract; the tested contract runs the contract method based on the contract running parameter to obtain a contract running result; and confirming the contract running result by the test contract, and acquiring a contract test result of the tested contract based on the contract running result. The test method can utilize the contract between the intelligent contracts to call the use information to carry out the contract test, thereby improving the matching degree between the test contract and the tested contract, carrying out the contract test in the block chain network, more efficiently and accurately testing the problems existing in the intelligent contract, and improving the contract test efficiency and the test accuracy.

Description

Automatic testing method and device of intelligent contract, computer equipment and storage medium
Technical Field
The invention relates to the field of block chains, in particular to an automatic testing method and device of an intelligent contract, computer equipment and a storage medium.
Background
With the rapid development of blockchain technology, more and more blockchain-based decentralized applications are emerging. A blockchain-based decentralized application may be understood as a collection of contract code and peripheral code running on a blockchain. Unlike traditional software architectures, blockchain networks have their unique features: for example, invoking an intelligent contract requires completion by initiating a transaction that requires waiting for a miner to mine, which cannot be modified once the block and transaction are confirmed by the miner; and the intelligent contracts provide much less functionality than traditional programming languages, for the purpose of saving the computational power of the entire network, and so on. This presents many difficulties in the development of decentralized applications. In addition, since the blockchain application often relates to the financial field such as bitcoin and ethernet, once an application error occurs, serious consequences will be caused. Therefore, a more efficient and accurate automatic testing method of the intelligent contract needs to be found on the basis of the quality assurance of the traditional software.
Disclosure of Invention
Based on this, it is necessary to provide an automatic testing method, apparatus, computer device and storage medium for intelligent contracts, aiming at the problems of low testing efficiency and low testing accuracy of intelligent contracts.
A method for automatic testing of smart contracts, the method comprising:
acquiring a test contract corresponding to first calling request information according to the received first calling request information;
running the test contract, and sending second calling request information to a corresponding tested contract based on the test contract;
the tested contract runs a contract method based on the contract running parameter to obtain a contract running result;
and the test contract confirms the contract running result and acquires a contract test result of the tested contract based on the contract running result.
In one embodiment, the sending the second invocation request message to the corresponding contract under test based on the contract under test includes:
acquiring a second identifier associated with the test contract, wherein the second identifier is identifier information representing mutual mapping between the test contract and a corresponding tested contract;
and acquiring tested contract address information according to the second identifier, and sending second calling request information to the tested contract.
In one embodiment, the obtaining the second identifier associated with the test contract comprises:
extracting a second identifier from the first calling request information; or
A second identifier is extracted from the test contract.
In one embodiment, the obtaining a contract test result of the tested contract based on the contract running result includes:
acquiring a standard operation result of the test contract;
comparing the standard operation result with the contract operation result;
if the results are consistent, the contract test result is confirmed to pass;
if the result comparison is inconsistent, the contract test result is confirmed to be failed.
In one embodiment, the contract method includes a resource transfer method, the contract running parameter includes a target resource transfer value, and the obtaining the standard running result of the test contract includes:
acquiring an initial resource value corresponding to the second identifier; the initial resource value is the amount of resources the second identifier has before executing the resource transfer method;
and calculating to obtain a standard operation result based on the target resource transfer value and the initial resource value.
In one embodiment, the first retrieval request message includes an identifier of a request message receiver; the identification of the request information receiver is a first identification corresponding to the test contract; the obtaining of the test contract corresponding to the first invocation request information includes:
and acquiring the intelligent contract corresponding to the first identifier as a test contract.
In one embodiment, the first retrieval request message includes a first identifier corresponding to a sender of the request message; the method further comprises the following steps:
and sending a contract test result to the block chain node corresponding to the first identifier.
An apparatus for automatic testing of smart contracts, the apparatus comprising:
the first obtaining module is used for obtaining a test contract corresponding to the first calling request information according to the received first calling request information;
the sending module is used for running the test contract and sending second calling request information to the corresponding tested contract based on the test contract;
the second acquisition module is used for acquiring a contract running result obtained by running the contract method on the basis of the contract running parameters of the tested contract;
and the confirmation acquisition module is used for confirming the contract running result according to the test contract and acquiring the contract test result of the tested contract based on the contract running result.
A computer device comprising a memory and a processor, the memory having stored therein computer readable instructions which, when executed by the processor, cause the processor to perform the steps of the above-described method of automatic testing of intelligent contracts.
A storage medium having stored thereon computer-readable instructions which, when executed by one or more processors, cause the one or more processors to perform the steps of the above-described method for automatic testing of intelligent contracts.
According to the automatic test method, the automatic test device, the computer equipment and the storage medium of the intelligent contract, the test contract and the tested contract are deployed in the block chain, when the test contract is operated, the contract method using the tested contract is called to obtain the contract operation result based on the contract operation parameter, and then the contract test result is obtained based on the contract operation result. Because the tested contracts are tested by the testing contracts deployed in the block chain, the contract testing can be carried out by utilizing the contract calling use information among the intelligent contracts, and the matching degree between the testing contracts and the tested contracts is improved. Meanwhile, the contract test is carried out in the block chain network, so that the problems existing in the intelligent contract can be tested more efficiently and accurately, and the contract test efficiency and the test accuracy are improved.
Drawings
FIG. 1 is a flow diagram of a method for automatic testing of intelligent contracts provided in one embodiment;
FIG. 2 is a flowchart illustrating steps taken in a test contract to obtain a desired operation result, according to one embodiment;
FIG. 3 is a flow diagram of a method for automatic testing of intelligent contracts provided in accordance with another embodiment;
FIG. 4 is a block diagram of an apparatus for automatic testing of smart contracts, according to an embodiment;
FIG. 5 is a block diagram of an apparatus for automatic testing of smart contracts according to another embodiment;
FIG. 6 is a schematic diagram of an electronic device provided by an embodiment.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
It will be understood that, as used herein, the terms "first," "second," and the like may be used herein to describe various elements, but these elements are not limited by these terms. These terms are only used to distinguish one element from another.
As shown in fig. 1, an embodiment of the present application provides an automatic testing method for an intelligent contract, including:
step S10, according to the received first invocation request message, obtaining a test contract corresponding to the first invocation request message.
First retrieval request information is first received. In some embodiments, the intelligent contract testing service starts a testing task after receiving the intelligent contract testing request.
In some embodiments, the first invocation request information is used to request invocation of a test contract to test the tested contract using the test contract. A test contract refers to an intelligent contract used to conduct a test. The tested contract refers to an intelligent contract to be tested, and the tested contract needs to be tested through a testing contract to confirm whether the tested contract is normal or not and whether a problem exists or not.
The smart contract may include data as well as program code. The intelligent contracts may include variables and corresponding contract methods, and the corresponding functions may be implemented by running the contract methods. The test contract may contain test scripts written based on test cases. The Etherum (Etherum) is an open-source public blockchain platform with intelligent contract functions, and intelligent contracts can be compiled into the Etherum virtual machine bytecode form and stored in the Etherum (Etherum). Etherhouses handle point-to-point contracts by providing an decentralized ethernet Virtual Machine (etherum Virtual Machine) through their dedicated cryptocurrency ethernet (Ether, for short, "ETH"). The test contracts and the tested contracts may be written in the same programming language (e.g., the solid programming language). The identity programming language is a high-level programming language specially created for realizing intelligent contracts, and is suitable for running on an Etherhouse virtual machine by using c + +, python and javascript programming languages for reference.
In some embodiments, the test requester node is matched with a blockchain client. The block chain network can be accessed through an application program interface client of the Ethernet, and when a tested contract needs to be tested, a user can send first calling request information to the block chain link points by operating the application program interface client.
Accounts are an important concept in etherhouses. An etherhouse address represents an etherhouse account, and the account address is the identity of the account, and thus may also be referred to as an identity.
In some embodiments, the first retrieval request message may include an identification of a sender of the request message and an identification of a recipient of the request message. The identity of the sender of the request message may be referred to as the first identity, i.e. the identity of the test contract. The identity of the recipient of the request message may be referred to as a second identity, i.e., an identity of the contract under test, which indicates that the message was sent to the contract under test. The identification of the request information receiver is a first identification corresponding to the test contract, and the acquiring of the test contract corresponding to the first invoking request information comprises the following steps: and acquiring the intelligent contract corresponding to the first identifier as a test contract.
The identification of the request information receiver is the identification of the test contract which needs to be called for use, and the identification of the request information receiver indicates that the first calling request information is sent to the test contract corresponding to the identification.
The identification of the sender of the request message may be an external identification, for example an identification of a user logged in an application program interface client on the node of the test requester.
The first invocation request message may further include test-related parameters, such as an identifier of the tested contract and contract running parameters, so that the test contract can determine the tested contract based on the second identifier, and the tested contract can be run according to the contract running parameters. Based on the type of the contract under test, contract run parameters are determined. For example, if the tested contract includes a transfer method, the contract run parameters may include the amount of the transfer. If the tested contract includes a signature authentication method, the contract run parameters may include signature data.
The first invocation request message may be sent in a transaction message manner. The first invocation request message may also include a transaction procedure fee representing a fee that is willing to be charged for running the transaction.
In some embodiments, the first invocation request information is sent to the intelligent contract testing network in turn according to the test set.
A test contract corresponding to the first invocation request message is obtained. Specifically, the first invocation request message may include a first identifier of the test contract, that is, an address of a receiver of the request message. Determining the test contract based on the first identification of the test contract can be accomplished.
The test contract may include at least one of contract run parameters, an identification of the tested contract, a test result validation method, or a contract method to be invoked for use.
Contract run arguments refer to arguments that need to be input into a contract under test when testing the contract under test. The contract under test is determined by an identification of the contract under test.
And determining the result of testing the tested contract by a test result confirmation method.
For example, if the contract running parameter is a resource transfer amount, the test result confirmation method includes: for the account transferring the resource outwards, when the sum of the transferred resource amount and the resource transfer amount is equal to the resource amount before the transfer; for accounts with income resources, when the difference obtained by subtracting the resource transfer amount from the transferred resource amount is equal to the resource amount before the transfer, the test result is confirmed to be passed.
Generally, an intelligent contract includes at least one policy, which may be, for example, a resource transfer policy, a quantity calculation policy, or a consensus policy. At least one of the contract operation parameters, the tested contract identification, the test result confirmation method or the contract method to be called is written into the test contract, and when the test contract is operated, the written parameters can be directly obtained for testing, so that the method is simple, convenient and quick. Or, if the first invocation request information includes at least one of the contract running parameters, the identifier of the tested contract, the test result confirmation method or the contract method to be invoked, the parameters can be used as parameters required to be transmitted when the test contract is run, and the parameters are transmitted to the test contract when the test is required, so that the user can determine the specific parameters based on the test method, and the flexibility is high. For example, when the identity of a contract under test is entered as a parameter, the user can determine which intelligent contract to test based on actual demand.
And step S20, sending second calling request information to the corresponding contract to be tested based on the contract to be tested, wherein the second calling request information contains contract operation parameters.
The test contract and the tested contract are arranged in the blockchain, and specifically, the purpose of the second invoking request information is to invoke the tested contract. The second retrieval request message may carry an identifier of a sender of the request message and an identifier of a receiver of the request message. The identity of the sender of the request message may be referred to as the first identity, i.e. the identity of the test contract. The identity of the recipient of the request message may be referred to as a second identity, i.e., an identity of the contract under test, which indicates that the message was sent to the contract under test.
The intelligent contracts are run by loading the intelligent contracts into the Etherhouse virtual machine for running. An Ethernet Virtual Machine (EVM) is a lightweight virtual machine designed to run intelligent contracts on an ethernet network.
The code of the smart contract is bytecode, which, after being compiled, can be run on an ethernet virtual machine.
The second identifier is the identifier corresponding to the tested contract. Sending a second invocation request message to the corresponding contract to be tested based on the contract to be tested, including:
acquiring a second identifier associated with the test contract, wherein the second identifier is identifier information representing mutual mapping between the test contract and a corresponding tested contract;
and acquiring tested contract address information according to the second identifier, and sending second calling request information to the tested contract.
In some embodiments, obtaining the second identifier associated with the test contract comprises: extracting a second identifier from the first calling request information; or the second identifier is extracted from the test contract.
The test contracts and the tested contracts can be deployed in advance in the block chain where the block link points are located.
Specifically, a tested contract is compiled and compiled first, then a deployment request is sent to a blockchain node, the deployment request comprises the tested contract, the blockchain node extracts the tested contract from the deployment request, then hash calculation is carried out based on the identification of the testing deployment request sending node and the number of messages sent by the testing requester node, the calculated hash value is used as the identification of the tested contract, and then the identification is sent to the testing requester node.
The test requester node can deploy the test contract in the block chain by using the same method to obtain the identifier of the test contract.
In some embodiments, the test contract and the tested contract are compiled by a compiler, and the compiled test contract and the compiled tested contract are deployed in a blockchain.
And step S30, obtaining a contract running result obtained by running the contract method on the basis of the contract running parameters of the tested contract.
Generally, a tested contract carries a function that can be called, i.e., a contract method; a contract under test typically carries at least one function that can be called.
Alternatively, some or all of the contract methods may be run as needed. For example, the second invocation request message may include a feature identifier of the method to be invoked for use, and a corresponding contract method may be executed based on the feature identifier.
The result of the contract method running the tested contract is called the contract running result. Specifically, if the contract method is a resource transfer method, the contract operation result is the amount of the resource remaining in the account after the resource transfer. If the contract method is a signature authentication method, the contract execution result is a signature authentication result, which may be a pass or a fail.
And step S40, confirming the contract running result according to the test contract, and acquiring the contract test result of the tested contract based on the contract running result.
Specifically, the contract test result is either a test pass or a test fail. Feature identification of contract methods that fail testing may also be included. After obtaining the contract running result, obtaining a contract testing result based on the contract running result. Specifically, the contract running result is compared with the expected test result, if the contract running result is compared with the expected test result, the test is confirmed to be passed, and if the contract running result is not compared with the expected test result, the test is confirmed to be failed.
Obtaining a contract test result of the tested contract based on the contract running result, comprising:
acquiring a standard operation result of the test contract;
comparing the standard operation result with the contract operation result;
if the results are consistent, the contract test result is confirmed to pass;
if the result comparison is inconsistent, the contract test result is confirmed to be failed.
The standard operation result refers to an ideal result expected after the correct contract method is operated according to the contract operation parameters, and is equal to a correct answer, namely the ideal result which should be output by the contract method under the condition that no problem exists in the contract method. The standard operation result may be obtained by calculation or may be included in the first retrieval request information. Specifically, for the resource transfer method, for the account to which the resource is transferred outward, the standard operation result is: after the resource transfer method is operated, the difference obtained by subtracting the resource transfer amount from the account balance before transferring out the resource is equal to the current account balance of the account. For the signature verification algorithm, the first calling request information comprises a standard operation result, a user can set the standard operation result of operating the contract method based on the contract operation parameter, and the test requester node attaches the standard operation result to the first calling request information.
If the contract operation result is different from the standard operation result, the contract test result is determined to be failed; if the contract operation result is the same as the standard operation result, the contract test result is confirmed to be passed.
In some embodiments, the contract method may be a resource transfer method. The resource in the resource transfer may be, for example, money, game pieces, securities, vouchers, coupons, or the like. In a typical application scenario, a merchant issues vouchers or coupons and the like to consumers. For example, the merchant issues the voucher or coupon directly to the consumer's account, or provides a two-dimensional code picture or the like to facilitate the consumer to actively scan for the voucher or coupon. In a typical application scenario, a user transfers money via a red purse or transfers money to one or more friends via a social platform or other type of client software. These are all specific examples of resource transfers. The contract run parameter includes a target resource transfer value.
As shown in fig. 2, the step of obtaining the standard operation result of the test contract includes:
s401, obtaining an initial resource value corresponding to a second identifier;
s402, calculating and obtaining a standard operation result based on the target resource transfer value and the initial resource value.
The initial resource value refers to the amount of resources the second identifier has before the resource transfer method is performed. The standard operation result is calculated based on the target resource transfer value and the initial resource value. If the second identifier corresponds to an account address for the revenue resource, the standard operation result is the sum of the target resource transfer value and the initial resource value. And if the second identification corresponds to the account address of the outward transfer resource, the standard operation result is the difference of the initial resource value minus the target resource transfer value.
In some embodiments, after receiving the intelligent contract test request, the intelligent contract test service starts a test task; the intelligent contract testing service sequentially sends intelligent contract testing requests to all nodes of the intelligent contract testing network according to a testing set (related to a series of intelligent contract execution operations and intelligent contract query operations), records returned testing results, and acquires corresponding testing logs through interfaces provided by the testing network nodes.
In some embodiments, the second identifier may be written in the test contract, so that the test contract can be directly tested, and the test efficiency is improved. The first calling request information can comprise a second identifier, so that the second identifier can be obtained from the first calling request information, for example, in each test case function, the address of the tested contract is used as a parameter to be sent to a method for calling the tested contract, the identifier of the tested contract can be flexibly changed based on the actual test requirement, and the flexibility of specific operation is improved.
The first retrieval request message includes a first identifier corresponding to a sender of the request message. In some embodiments, as shown in fig. 3, the method for automatically testing the smart contract further includes step S50: and sending the contract test result to the node corresponding to the first identifier. For example, after the block link node receives the contract test result, the identifier of the request information sender sending the first invocation request information may be obtained, and the contract test result may be sent to the identifier, that is, the block link node may feed back the contract test result to the test requester node. The contract test result may be represented by a preset character, for example, the preset character "YES" may represent that the contract test result is a pass, and the preset character "NO" may represent that the contract test result is a fail.
According to the automatic test method of the intelligent contract, the test contract and the tested contract are deployed in the block chain, when the test contract is operated, the contract method using the tested contract is called to obtain a contract operation result based on the contract operation parameter, and then the contract test result is obtained based on the contract operation result. Because the tested contracts are tested by the testing contracts deployed in the block chain, the contract testing can be carried out by utilizing the contract calling use information among the intelligent contracts, and the matching degree between the testing contracts and the tested contracts is improved. Meanwhile, the contract test is carried out in the block chain network, so that the problems existing in the intelligent contract can be tested more efficiently and accurately, and the contract test efficiency and the test accuracy are improved.
As shown in fig. 4, another embodiment of the present application provides an apparatus for automatically testing an intelligent contract, the apparatus including:
a first obtaining module 100, configured to obtain, according to received first invocation request information, a test contract corresponding to the first invocation request information;
a sending module 200, configured to send a second invoking request message to a corresponding contract to be tested based on the contract to be tested;
a second obtaining module 300, configured to obtain a contract running result obtained by running the contract method on the basis of the contract running parameter for the tested contract;
the confirmation acquiring module 400 is configured to confirm the contract running result according to the test contract, and acquire a contract test result of the tested contract based on the contract running result.
In some embodiments, the sending module 200 includes a first sub-module and a second sub-module, where the first sub-module is configured to obtain a second identifier associated with the test contract, where the second identifier is identification information that characterizes a mapping between the test contract and a corresponding tested contract; and the second submodule is used for acquiring tested contract address information according to the second identifier and sending second calling request information to the tested contract.
In some embodiments, the first sub-module includes an obtaining unit and a sending unit, where the obtaining unit is specifically configured to extract the second identifier from the first invocation request information, or extract the second identifier from the test contract; the sending unit is used for sending second calling request information to the tested contract corresponding to the second identifier.
In some embodiments, the confirmation acquiring module 400 includes a first unit, a second unit, a third unit and a fourth unit, the first unit is configured to acquire the standard operation result of the test contract, the second unit is configured to compare the standard operation result with the contract operation result, and the third unit is configured to determine that the contract test result passes if the comparison is consistent; and the fourth unit is used for confirming that the contract test result is not passed if the result comparison is inconsistent.
In some embodiments, the contract method comprises a resource transfer method, the contract run parameter comprises a target resource transfer value, and the first unit is specifically configured to:
acquiring an initial resource value corresponding to the second identifier;
and calculating to obtain a standard operation result based on the target resource transfer value and the initial resource value.
In some embodiments, the first retrieval request message includes an identification of a recipient of the request message; the identification of the request information receiver is a first identification corresponding to the test contract. The first obtaining module comprises an obtaining unit, the obtaining unit is configured to obtain a test contract corresponding to the first invocation request information, and further, the obtaining unit is specifically configured to obtain an intelligent contract corresponding to the first identifier, and the intelligent contract is used as the test contract.
In some embodiments, the first retrieval request message includes a first identifier corresponding to a sender of the request message; as shown in fig. 5, the apparatus further includes a test result sending module 500, configured to send the contract test result to the node corresponding to the first identifier.
Another embodiment of the present application provides a computer device, including a memory and a processor, where the memory stores computer readable instructions, and the computer readable instructions, when executed by the processor, cause the processor to execute the steps of the above automatic testing method for intelligent contracts.
In some embodiments, the computer device includes a processor, a non-volatile storage medium, a memory, and a network interface connected by a system bus. The non-volatile storage medium of the computer device stores an operating system, a database and computer readable instructions, the database can store control information sequences, and the computer readable instructions can enable the processor to realize an automatic testing method of the intelligent contract when being executed by the processor. The processor of the computer device is used for providing calculation and control capability and supporting the operation of the whole computer device. The memory of the computer device may have stored therein computer readable instructions that, when executed by the processor, may cause the processor to perform a method for automatic testing of smart contracts. The network interface of the computer device is used for connecting and communicating with the terminal.
Please refer to fig. 6, which illustrates a schematic diagram of an electronic device according to some embodiments of the present application. As shown in fig. 6, the electronic device 20 may include: the system comprises a processor 200, a memory 201, a bus 202 and a communication interface 203, wherein the processor 200, the communication interface 203 and the memory 201 are connected through the bus 202; the memory 201 stores a computer program that can be executed on the processor 200, and the processor 200 executes the automatic testing method for the intelligent contract provided by any one of the foregoing embodiments when executing the computer program. Those skilled in the art will appreciate that the architecture shown in fig. 6 is merely a block diagram of some of the structures associated with the disclosed aspects and is not intended to limit the computing devices to which the disclosed aspects apply, as particular computing devices may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.
The Memory 201 may include a high-speed Random Access Memory (RAM), and may also include a non-volatile Memory (non-volatile Memory), such as at least one disk Memory. The communication connection between the network element of the system and at least one other network element is realized through at least one communication interface 203 (which may be wired or wireless), and the internet, a wide area network, a local network, a metropolitan area network, and the like can be used.
Bus 202 can be an ISA bus, PCI bus, EISA bus, or the like. The bus may be divided into an address bus, a data bus, a control bus, etc. The memory 201 is used for storing a program, and the processor 200 executes the program after receiving an execution instruction, and the method for automatically testing an intelligent contract disclosed in any embodiment of the foregoing application may be applied to the processor 200, or implemented by the processor 200.
The processor 200 may be an integrated circuit chip having signal processing capabilities. In implementation, the steps of the above method may be performed by integrated logic circuits of hardware or instructions in the form of software in the processor 200. The Processor 200 may be a general-purpose Processor, and may include a Central Processing Unit (CPU), a Network Processor (NP), and the like; but may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), an off-the-shelf programmable gate array (FPGA) or other programmable logic device, discrete gate or transistor logic, discrete hardware components. The various methods, steps, and logic blocks disclosed in the embodiments of the present application may be implemented or performed. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. The steps of the method disclosed in connection with the embodiments of the present application may be directly implemented by a hardware decoding processor, or implemented by a combination of hardware and software modules in the decoding processor. The software module may be located in ram, flash memory, rom, prom, or eprom, registers, etc. storage media as is well known in the art. The storage medium is located in the memory 201, and the processor 200 reads the information in the memory 201 and completes the steps of the method in combination with the hardware thereof.
The electronic equipment provided by the embodiment of the application and the automatic testing method of the intelligent contract provided by the embodiment of the application have the same beneficial effects as the method adopted, operated or realized by the electronic equipment.
Another embodiment of the present application provides a storage medium having stored thereon computer-readable instructions which, when executed by one or more processors, cause the one or more processors to perform the steps of the above-described method for automatic testing of intelligent contracts. Specifically, examples of the storage medium may include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other optical, magnetic storage media, optical disks, and the like. The storage medium provided by the above embodiment of the present application and the automatic test method of the intelligent contract provided by the embodiment of the present application have the same beneficial effects as the method adopted, operated or implemented by the application program stored in the storage medium.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by a computer program, which can be stored in a computer-readable storage medium, and can include the processes of the embodiments of the methods described above when the computer program is executed. The storage medium may be a non-volatile storage medium such as a magnetic disk, an optical disk, a Read-Only Memory (ROM), or a Random Access Memory (RAM).
The technical features of the embodiments described above may be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the embodiments described above are not described, but should be considered as being within the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
The above-mentioned embodiments only express several embodiments of the present invention, and the description thereof is more specific and detailed, but not construed as limiting the scope of the present invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the inventive concept, which falls within the scope of the present invention. Therefore, the protection scope of the present patent shall be subject to the appended claims.

Claims (10)

1. A method for automatic testing of smart contracts, the method comprising:
acquiring a test contract corresponding to first calling request information according to the received first calling request information;
sending second calling request information to a corresponding contract to be tested based on the contract to be tested;
obtaining a contract running result obtained by running a contract method on the basis of the contract running parameters of the tested contract;
and confirming the contract running result according to the test contract, and acquiring a contract test result of the tested contract based on the contract running result.
2. The method of claim 1, wherein sending second invocation-request information to a corresponding contract under test based on the test contract comprises:
acquiring a second identifier associated with the test contract, wherein the second identifier is identifier information representing mutual mapping between the test contract and a corresponding tested contract;
and acquiring tested contract address information according to the second identifier, and sending second calling request information to the tested contract.
3. The method of claim 2, wherein obtaining the second identifier associated with the test contract comprises:
extracting a second identifier from the first calling request information; or
A second identifier is extracted from the test contract.
4. The method of claim 1, wherein obtaining the contract test result for the tested contract based on the contract run result comprises:
acquiring a standard operation result of the test contract;
comparing the standard operation result with the contract operation result;
if the results are consistent, the contract test result is confirmed to pass;
if the result comparison is inconsistent, the contract test result is confirmed to be failed.
5. The method of claim 4, wherein the contract method comprises a resource transfer method, wherein the contract run parameter comprises a target resource transfer value, and wherein obtaining the standard run result for the test contract comprises:
acquiring an initial resource value corresponding to the second identifier; the initial resource value is the amount of resources the second identifier has before executing the resource transfer method;
and calculating to obtain a standard operation result based on the target resource transfer value and the initial resource value.
6. The method according to claim 1, wherein the first retrieval request message includes an identification of a recipient of the request message; the identification of the request information receiver is a first identification corresponding to the test contract; the obtaining of the test contract corresponding to the first invocation request information includes:
and acquiring the intelligent contract corresponding to the first identifier as a test contract.
7. The method of claim 6, wherein the retrieval request message includes a first identifier corresponding to a sender of the request message; the method further comprises the following steps:
and sending a contract test result to the block chain node corresponding to the first identifier.
8. An apparatus for automatic testing of smart contracts, the apparatus comprising:
the first obtaining module is used for obtaining a test contract corresponding to the first calling request information according to the received first calling request information;
the sending module is used for sending second calling request information to a corresponding contract to be tested based on the contract to be tested;
the second acquisition module is used for acquiring a contract running result obtained by running the contract method on the basis of the contract running parameters of the tested contract;
and the confirmation acquisition module is used for confirming the contract running result according to the test contract and acquiring the contract test result of the tested contract based on the contract running result.
9. A computer device comprising a memory and a processor, the memory having stored therein computer readable instructions which, when executed by the processor, cause the processor to carry out the steps of the method of automatic testing of intelligent contracts of any of claims 1 to 7.
10. A storage medium having stored thereon computer-readable instructions which, when executed by one or more processors, cause the one or more processors to perform the steps of the method for automatic testing of intelligent contracts of any of claims 1 to 7.
CN202011286641.XA 2020-11-17 2020-11-17 Automatic testing method and device of intelligent contract, computer equipment and storage medium Pending CN112380128A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011286641.XA CN112380128A (en) 2020-11-17 2020-11-17 Automatic testing method and device of intelligent contract, computer equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011286641.XA CN112380128A (en) 2020-11-17 2020-11-17 Automatic testing method and device of intelligent contract, computer equipment and storage medium

Publications (1)

Publication Number Publication Date
CN112380128A true CN112380128A (en) 2021-02-19

Family

ID=74585806

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011286641.XA Pending CN112380128A (en) 2020-11-17 2020-11-17 Automatic testing method and device of intelligent contract, computer equipment and storage medium

Country Status (1)

Country Link
CN (1) CN112380128A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112785439A (en) * 2021-03-19 2021-05-11 中国工商银行股份有限公司 Method and device for testing intelligent contracts deployed on block link points

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112785439A (en) * 2021-03-19 2021-05-11 中国工商银行股份有限公司 Method and device for testing intelligent contracts deployed on block link points

Similar Documents

Publication Publication Date Title
CN111163129B (en) Resource processing method and device based on cross-link network
CN111177005B (en) Service application testing method, device, server and storage medium
US11443307B2 (en) Cross-border resource transfer authenticity verification method, device and electronic equipment
CN108427613B (en) Abnormal interface positioning method and device, computer equipment and storage medium
CN111090581B (en) Intelligent contract testing method, intelligent contract testing device, computer equipment and storage medium
CN109886689B (en) Data evidence storing and obtaining method and device based on block chain
CN109308263B (en) Applet testing method, device and equipment
CN110780870A (en) Service execution method, device, equipment and storage medium
CN111597120B (en) Interface test apparatus, method, electronic device, and computer-readable storage medium
CN110968437A (en) Method, device, equipment and medium for parallel execution of single contract based on Java intelligent contract
CN110764996A (en) Contract testing method, system, storage medium and terminal equipment
CN112446786A (en) Abnormal transaction processing method and device, electronic equipment and readable storage medium
CN112380128A (en) Automatic testing method and device of intelligent contract, computer equipment and storage medium
CN116483888A (en) Program evaluation method and device, electronic equipment and computer readable storage medium
CN112613967B (en) Business transaction data processing method and device, computer equipment and storage medium
CN116266328A (en) Account data checking method and device and electronic equipment
CN113704123A (en) Interface test method, device, equipment and storage medium
CN110532186B (en) Method, device, electronic equipment and storage medium for testing by using verification code
CN110852864A (en) Method and device for processing digital resource amount and storage medium
CN110990278A (en) Test method and device
CN110740062A (en) Breakpoint resume method and device
US11790360B1 (en) Multi-actor transaction simulation in a blockchain network
CN114666256B (en) Gray scale test method, device, equipment and medium
CN110020670B (en) Model iteration method, device and equipment
CN115048198A (en) Service processing method, device, equipment and medium based on distributed interactive system

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination