CN111090581A - Intelligent contract testing method and device, computer equipment and storage medium - Google Patents

Intelligent contract testing method and device, computer equipment and storage medium Download PDF

Info

Publication number
CN111090581A
CN111090581A CN201911157165.9A CN201911157165A CN111090581A CN 111090581 A CN111090581 A CN 111090581A CN 201911157165 A CN201911157165 A CN 201911157165A CN 111090581 A CN111090581 A CN 111090581A
Authority
CN
China
Prior art keywords
contract
test
intelligent contract
account address
message
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.)
Granted
Application number
CN201911157165.9A
Other languages
Chinese (zh)
Other versions
CN111090581B (en
Inventor
刘超
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN201911157165.9A priority Critical patent/CN111090581B/en
Publication of CN111090581A publication Critical patent/CN111090581A/en
Application granted granted Critical
Publication of CN111090581B publication Critical patent/CN111090581B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

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/3688Test management for test execution, e.g. scheduling of test suites
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The application relates to an intelligent contract testing method, an intelligent contract testing device, computer equipment and a storage medium, wherein the method comprises the following steps: receiving a test contract calling message; acquiring a test intelligent contract corresponding to the test contract calling message; executing the test intelligent contract to send a test contract calling message to a corresponding test intelligent contract according to the test intelligent contract, wherein the test contract calling message carries contract execution parameters, and the test intelligent contract are deployed in a block chain; the tested intelligent contract executes a contract method according to the contract execution parameters to obtain a contract execution result; and the test intelligent contract obtains the contract execution result and obtains a contract test result of the tested intelligent contract according to the contract execution result. The method can improve the intelligent contract testing efficiency.

Description

Intelligent contract testing method and device, computer equipment and storage medium
Technical Field
The present application relates to the field of computer technologies, and in particular, to an intelligent contract testing method and apparatus, a computer device, and a storage medium.
Background
The block chain is a chain data structure formed by combining data blocks in a sequential connection mode according to a time sequence, and is a distributed account book which is guaranteed in a cryptographic mode and cannot be tampered and forged.
A smart contract is a computer protocol intended to propagate, verify or execute contracts in an informational manner, allowing trusted transactions without third parties, and in a blockchain environment, the smart contract appears as executable code. The intelligent contracts can be written into the block chain in a digital form, and transparent traceability of the intelligent contracts in storage, reading and execution of the whole process can be guaranteed. At present, the test script can be adopted to test the codes corresponding to the intelligent contracts, but the test script is often not matched with the intelligent contracts, so that the problems of incapability of detection and low intelligent contract detection efficiency are caused.
Disclosure of Invention
In view of the above, it is necessary to provide an intelligent contract testing method, apparatus, computer device and storage medium for solving the problem of inefficient intelligent contract detection.
An intelligent contract testing method, the method comprising: receiving a test contract calling message; acquiring a test intelligent contract corresponding to the test contract calling message; executing the test intelligent contract to send a test contract calling message to a corresponding test intelligent contract according to the test intelligent contract, wherein the test contract calling message carries contract execution parameters, and the test intelligent contract are deployed in a block chain; the tested intelligent contract executes a contract method according to the contract execution parameters to obtain a contract execution result; and the test intelligent contract obtains the contract execution result and obtains a contract test result of the tested intelligent contract according to the contract execution result.
An intelligent contract testing apparatus, the apparatus comprising: the calling message receiving module is used for receiving a test contract calling message; the test intelligent contract obtaining module is used for obtaining a test intelligent contract corresponding to the test contract calling message; the test module is used for executing the test intelligent contract to send a tested contract calling message to the corresponding tested intelligent contract according to the test intelligent contract, the tested contract calling message carries contract execution parameters, and the test intelligent contract and the tested intelligent contract are deployed in a block chain; the contract method execution module is used for executing a contract method by the tested intelligent contract according to the contract execution parameters to obtain a contract execution result; and the test result obtaining module is used for obtaining the contract execution result by the test intelligent contract and obtaining the contract test result of the tested intelligent contract according to the contract execution result.
In some embodiments, the test module is to: and the test intelligent contract acquires a second account address and sends a test contract calling message to the test intelligent contract corresponding to the second account address.
In some embodiments, the test module is to: extracting a second account address from the test contract calling message; or obtaining a second account address from the test smart contract.
In some embodiments, the apparatus further comprises: the first message receiving module is used for receiving a first message sent by a message sending node; the deployment module is used for extracting the tested intelligent contract in the block chain message and deploying the tested intelligent contract in the block chain when the message receiver address in the first message is determined to be null; and the account address returning module is used for returning the second account address to the message sending node, and the second account address is obtained by calculation according to the third account address of the message sending node and the message sending number of the third account address.
In some embodiments, the test result derivation module is to: the test intelligent contract obtains a standard execution result and compares the standard execution result with the contract execution result; and when the comparison is consistent, confirming that the contract test result of the tested intelligent contract is passed.
In some embodiments, the test result derivation module is to: acquiring an original resource numerical value corresponding to the second account address; and calculating to obtain a standard execution result according to the target resource transfer value and the original resource value.
In some embodiments, the contract method includes a resource transfer method, and the tested contract invoking message carries the first resource transfer value, a first account address corresponding to the test intelligent contract, and a method identifier corresponding to the resource transfer method; the contract method execution module is used for: and the tested intelligent contract determines a resource transfer method according to the method identifier, and transfers the virtual resource of the first resource transfer value to the first account address according to the resource transfer method.
In some embodiments, the test contract invocation message carries a second resource transfer value, and the test module is to: transferring the virtual resource of the second resource transfer value to the first account address corresponding to the test intelligent contract; the tested contract calling message carries the second resource transfer value, the second account address corresponding to the tested intelligent contract and the method identifier corresponding to the resource transfer method, and the contract method execution module is configured to: and the tested intelligent contract determines a resource transfer method according to the method identifier, and transfers the virtual resource of the second resource transfer value from the first account address to the second account address according to the resource transfer method.
In some embodiments, the test contract invocation message carries a message recipient account address, the message recipient account address is a first account address corresponding to the test intelligent contract, and the test intelligent contract acquisition module is configured to: and acquiring the intelligent contract corresponding to the first account address as a test intelligent contract.
In some embodiments, the test contract invoking message carries a first account address corresponding to a message sender, and the apparatus further includes a test result returning module, configured to send the contract test result to a node corresponding to the first account address.
A computer device comprising a memory and a processor, the memory having stored therein a computer program which, when executed by the processor, causes the processor to carry out the steps of the intelligent contract testing method described above.
A computer-readable storage medium having stored thereon a computer program which, when executed by a processor, causes the processor to carry out the steps of the intelligent contract testing method described above.
According to the intelligent contract testing method, the intelligent contract testing device, the computer equipment and the storage medium, the testing intelligent contract and the tested intelligent contract can be deployed in the block chain, when the testing contract is executed, the contract method of the tested intelligent contract is called to obtain the contract execution result according to the contract execution parameters, and the contract testing result is obtained according to the contract execution result. And the test is executed in the block chain environment, so that the problems of the intelligent contract can be more accurately detected, and the efficiency of testing the intelligent contract is improved.
Drawings
FIG. 1 is a diagram of an application environment for an intelligent contract testing method provided in some embodiments;
FIG. 2 is a flow diagram of a method for intelligent contract testing in some embodiments;
FIG. 3 is a flow diagram of a method for intelligent contract testing in some embodiments;
FIG. 4 is a schematic interface diagram of test results in some embodiments;
FIG. 5 is a flow diagram of a method for intelligent contract testing in some embodiments;
FIG. 6 is a schematic diagram of an interface for deploying smart contract A under test in some embodiments;
FIG. 7 is a schematic diagram of an interface on a test request sending node in some embodiments;
FIG. 8 is a timing diagram of an implementation of an intelligent contract testing method in some embodiments;
FIG. 9 is a block diagram of an intelligent contract testing apparatus in some embodiments;
FIG. 10 is a block diagram of the internal architecture of a computing device in some embodiments.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application 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 present application and are not intended to limit the present application.
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 unless otherwise specified. These terms are only used to distinguish one element from another. For example, the first account address may be referred to as a second account address, and similarly, the second account address may be referred to as a first account address, without departing from the scope of the present application.
Fig. 1 is a diagram of an application environment of an intelligent contract testing method provided in some embodiments, and as shown in fig. 1, the application environment includes a test request sending node, a block link point 1, a block link point 2, a block link point 3, and a block chain node 4 belonging to the same block chain. Each block chain node can be deployed with a test intelligent contract and a tested intelligent contract, when the tested intelligent contract needs to be tested, the test request sending node sends a test contract calling message to the block chain node 1, the test contract calling message carries an account address of the tested intelligent contract, and the block chain node 1 can execute the intelligent contract calling method provided by the embodiment of the application according to the test contract calling message to obtain a contract test result. It can be understood that, since the blockchain node 1 may broadcast the test contract invoking message, the blockchain nodes 2, 3, and 4 may also execute the intelligent contract testing method provided in the embodiment of the present application. The test request sending node may also be a node in a block chain.
The block chain nodes can be connected by using a network to perform consensus authentication, and the test request sending node and the block chain nodes can be connected by using the network. Each block link point may be an independent physical server or terminal, may also be a server cluster formed by a plurality of physical servers, and may be a cloud server providing basic cloud computing services such as a cloud server, a cloud database, a cloud storage, and a CDN. The test request sending node may be an independent physical server or terminal, may also be a server cluster formed by a plurality of physical servers, and may be a cloud server providing basic cloud computing services such as a cloud server, a cloud database, a cloud storage, a CDN, and the like.
In some embodiments, the intelligent contract testing method provided by the embodiment of the present application may be executed in a private chain, for example, may be executed in a testing environment, and thus, there may be only 1 blockchain node. The block chain node is simultaneously provided with a testing intelligent contract and a tested intelligent contract. Testing of the smart contracts may be performed, for example, through Etherhouse's web.3j. web.3j is an Application Programming Interface (API) provided by etherhouse.
A blockchain node is a data processing node in a blockchain network. A blockchain network is a carrier and organization of the operation blockchain technology. The block chain Technology (BT), also called distributed ledger Technology, is an internet database Technology, and is characterized by decentralization and public transparency, so that everyone can participate in data recording. The blockchain is a novel application mode of computer technologies such as distributed data storage, point-to-point transmission, a consensus mechanism and an encryption algorithm. A block chain (Blockchain), which is essentially a decentralized database, is a series of data blocks associated by using a cryptographic method, and each data block contains information of a batch of network transactions, so as to verify the validity (anti-counterfeiting) of the information and generate a next block. The blockchain may include a blockchain underlying platform, a platform product services layer, and an application services layer.
The block chain underlying platform can comprise processing modules such as user management, basic service, intelligent contract and operation monitoring. The user management module is responsible for identity information management of all blockchain participants, and comprises public and private key generation maintenance (account management), key management, user real identity and blockchain address corresponding relation maintenance (authority management) and the like, and under the authorization condition, the user management module supervises and audits the transaction condition of certain real identities and provides rule configuration (wind control audit) of risk control; the basic service module is deployed on all block chain node equipment and used for verifying the validity of the service request, recording the valid request after consensus is completed on storage, for a new service request (such as a contract test request), the basic service firstly performs interface adaptation analysis and authentication processing (interface adaptation), then encrypts service information (consensus management) through a consensus algorithm, and transmits the encrypted service information to a shared account book (network communication) completely and consistently, and records and stores the encrypted service information; the intelligent contract module is responsible for registering and issuing contracts, triggering the contracts and executing the contracts, developers can define contract logics through a certain programming language, issue the contract logics to a block chain (contract registration), call keys or other event triggering and executing according to the logics of contract clauses, complete the contract logics and simultaneously provide the function of upgrading and canceling the contracts; the operation monitoring module is mainly responsible for deployment, configuration modification, contract setting, cloud adaptation in the product release process and visual output of real-time states in product operation, such as: alarm, monitoring network conditions, monitoring node equipment health status, and the like.
The platform product service layer provides basic capability and an implementation framework of typical application, and developers can complete block chain implementation of business logic based on the basic capability and the characteristics of the superposed business. The application service layer provides the application service based on the block chain scheme for the business participants to use.
As shown in fig. 2, in some embodiments, an intelligent contract testing method is proposed, and this embodiment is mainly illustrated by applying this method to the block link points in fig. 1. The method specifically comprises the following steps:
step S202, receiving a test contract calling message.
Specifically, the test contract invoking message is used for requesting to invoke the test intelligent contract to test the tested intelligent contract. An intelligent contract may include code and data, which may include variables and corresponding contract methods, for example, and may implement corresponding functionality by executing the contract methods. In an ethernet, smart contracts may be stored in the form of an EVM (environmental virtual machine) bytecode. The test intelligent contract refers to an intelligent contract for testing, and a test script written according to a test case can be included in the test intelligent contract. The tested intelligent contract is the tested intelligent contract, and whether the intelligent contract has problems or not needs to be confirmed through testing. The test intelligent contracts and the tested intelligent contracts may be written in the same language, for example, in a solidity programming language, which is a high-level language oriented to intelligent contracts and may be used to write machine-level code that executes on the EVM.
The test request sending node may be installed with a corresponding block chain client, for example, an API client of an ethernet may access a block chain network, and when an intelligent contract needs to be tested, a user may send a test contract invoking message to the block chain link point by operating the API client.
In some embodiments, the test contract invoking message may carry an account address of the message sender and an account address of the message receiver, where the account address of the message receiver is an account address of a test intelligent contract that needs to be invoked, so as to indicate that the test contract invoking message is sent to a test intelligent contract corresponding to the account address. The account address of the message sender may be an external account address, for example, an account address of a user logged in an API client on the test request sending node. The account address in the etherhouse may include an external account address and a contract account address, among others. The external account address refers to an account address of the user, and the account address of the user can be obtained according to a private key of the user and is used for identifying the user. The contract account address is an account address of the intelligent contract that identifies the intelligent contract.
In some embodiments, the test contract invoking message may further carry test-related parameters, for example, an account address of the intelligent contract to be tested and contract execution parameters, so that the test intelligent contract may determine the intelligent contract to be tested according to the second account address, and may execute the tested intelligent contract according to the contract execution parameters. The contract execution parameters are determined according to the type of the intelligent contract to be tested. For example, if the tested smart contract includes a transfer method, the contract execution parameters may include a transfer amount. If the tested smart contract includes a signature authentication method, the contract execution parameters may include signature data.
In some embodiments, the test contract invocation message may also include an upper limit on the cost of executing the contract and a price for executing the contract, which may be represented by "gas," which refers to the fuel on which the EtherFang virtual machine is running. The upper limit of the contract execution fee is used to represent the maximum amount of fee that is willing to be spent in order to execute the intelligent contract. The price at which the contract executes represents the unit price of gas.
In some embodiments, the test contract invocation message may be sent in a transaction message. The test contract invocation message may also include a transaction procedure fee indicating a fee willing to be spent in order to execute the transaction.
And step S204, acquiring a test intelligent contract corresponding to the test contract calling message.
Specifically, the test contract invoking message may carry an address of a message recipient, that is, a first account address of the test intelligent contract. The test smart contract may be determined from the first account address of the test smart contract.
In some embodiments, one or more of contract execution parameters, an account address of the tested intelligent contract, test result determination policies, or contract methods to be invoked may be included in the test intelligent contract. The contract execution parameters are parameters which need to be input into the tested intelligent contract when the tested intelligent contract is tested, and the account address of the tested intelligent contract is used for determining the tested intelligent contract. The test result determining strategy is used for determining a contract test result of the tested intelligent contract. For example, when the contract execution parameter is the resource transfer amount, the test result determination policy may be: for the account of transferring out the resources, when the quantity of the resources before transferring is equal to the quantity of the transferred resources plus the quantity of the transferred resources; and for the account receiving the resources, when the quantity of the resources before the transfer is equal to the quantity of the resources after the transfer minus the quantity of the transferred resources, the test result is passed.
One intelligent contract may include one or more methods, such as a resource transfer method, a quantity calculation method, or a consensus method. By writing one or more of contract execution parameters, the account address of the tested intelligent contract, a test result determination strategy or a contract method to be called in the test intelligent contract, the written parameters can be directly acquired for testing when the test intelligent contract is executed, and the test is convenient and quick.
In some embodiments, the test contract calling message may also carry one or more of a contract execution parameter, an account address of the tested intelligent contract, a test result determination policy, or a contract method to be called, that is, the parameters may be used as parameters to be transmitted when the test intelligent contract is executed, and the parameters may be transmitted to the test intelligent contract when the test is required. For example, when the account address of the tested smart contract is entered as a parameter, the user can determine which smart contract needs to be tested as needed.
Step S206, executing the testing intelligent contract to send a tested contract calling message to the corresponding tested intelligent contract according to the testing intelligent contract, wherein the tested contract calling message carries contract execution parameters, and the testing intelligent contract and the tested intelligent contract are deployed in the block chain.
Specifically, the tested contract invoking message is used for invoking the tested intelligent contract. The tested contract invoking message may include an account address of the message sender and an account address of the message receiver. The account address of the message sender may be the account address of the test smart contract, i.e. the first account address. The account address of the message receiver is the account address of the tested intelligent contract, namely the second account address, and is used for indicating that the message is sent to the tested intelligent contract.
When executing the intelligent contract, the intelligent contract may be loaded in the ethernet virtual machine for execution. The Etherhouse virtual machine is the operating environment of the intelligent contract. The code of the intelligent contract is byte code which can be run on the EtherFang virtual machine after compiling. The test intelligent contract can obtain a second account address, namely the account address corresponding to the tested intelligent contract, and sends a tested contract calling message to the tested intelligent contract corresponding to the second account address.
The test smart contracts and the tested smart contracts may be pre-deployed in the block chain where the block link points are located. For example, a tested smart contract may be written and compiled. And sending a deployment request to the block chain nodes, wherein the deployment request carries the tested intelligent contract, the block chain nodes extract the tested intelligent contract, hash calculation is carried out according to the account address of the test deployment request sending node and the number of messages sent by the test request sending node, the obtained hash value is used as the account address of the tested intelligent contract, and the account address is sent to the test request sending node. The test request sending node can deploy the test intelligent contract in the same way to obtain the account address of the test intelligent contract.
In some embodiments, the source code of the tested intelligent contract can be introduced (import) into the test intelligent contract. By introducing the source code of the tested intelligent contract, the interface definition of the tested intelligent contract A can be provided for the testing intelligent contract, and the testing intelligent contract can call the functional interface of the tested intelligent contract for testing conveniently.
In some embodiments, the test intelligent contracts and the tested intelligent contracts are deployed in the blockchain after being compiled by the compiler. The compiler version of the test intelligent contract is not lower than the compiler version defined by the tested intelligent contract and not higher than the large compiler version defined by the tested intelligent contract, so that the test efficiency is improved. The version of the compiler can be divided into two levels of a large version and a small version, and the sequence number of the small version can represent the number of times of modification of the large version. The large version includes a plurality of small versions. For example 0.4.24 and 0.4.24 belong to the 4 th major version, but 0.4.24 represents the version resulting from the 24 th modification of the 4 th major version. 0.4.25 shows the version after the 25 th modification to the 4 th major version. For example, if tested Smart contract A uses an 0.4.24 version compiler, the compiler version used by the test Smart contract may choose 0.4.24 or 0.2.25, but not 0.5.x version.
And step S208, the tested intelligent contract executes the contract method according to the contract execution parameters to obtain a contract execution result.
In particular, a tested smart contract contains functions, i.e., contract methods, that may be invoked, and the tested smart contract may include one or more contract methods. For example, the tested contract calling message may carry a method identifier of the method to be called, and the corresponding contract method may be executed according to the method identifier.
The contract execution result refers to a result obtained by executing a contract method of the tested intelligent contract. For example, when the contract method is a resource transfer method, the contract execution result is the amount of resources in the account after the resource transfer. When the contract method is a signature verification algorithm, the contract execution result is a signature verification result, which may be a pass or a fail.
And step S210, testing the intelligent contract to obtain a contract execution result, and obtaining a contract test result of the tested intelligent contract according to the contract execution result.
Specifically, the contract test result may be a test pass or fail. Method identification of contract methods that fail testing may also be included. After the contract execution result is obtained, the test result of the contract can be determined according to the contract execution result. For example, the contract execution result may be compared to an expected test result, and if the comparison is consistent, the test is deemed to pass. If not, the test fails.
In some embodiments, obtaining the contract test result of the tested intelligent contract according to the contract execution result comprises: testing the intelligent contract to obtain a standard execution result, and comparing the standard execution result with the contract execution result; and when the comparison is consistent, confirming that the contract test result is passed.
Specifically, the standard execution result refers to an expected result after executing a correct contract method according to the contract execution parameters, and corresponds to a standard answer. That is, if there is no problem with the contract method, the result should be output by the contract method. The standard execution result may be calculated or carried in a test contract invocation message. For example, for the resource transfer method, for the account transferred out of the resource, the standard execution result is: after the resource transfer method is executed, the account balance of the account is equal to the account balance before transfer minus the amount of resource transfer. For the signature authentication algorithm, the standard execution result is carried in the test contract invoking message, the user can set the standard execution result for executing the contract method according to the contract execution parameter, and the test request sending node carries the standard execution result in the test contract invoking message.
And when the standard execution result is consistent with the contract execution result, confirming that the contract test result is passed. Otherwise, the contract test result is failed.
In some embodiments, the test contract invocation message carries a first account address corresponding to the message sender, as shown in fig. 3, the intelligent contract testing method further includes step S302: and sending a contract test result to a node corresponding to the first account address. Specifically, after the block link point obtains the contract test result, the account address of the message sender sending the test contract invoking message may be acquired, and the contract test result may be sent to the account address, that is, the block link point may return the contract test result to the test request sending node. The contract test result may be represented by a preset character, for example, if the return value is "true", it represents that the contract test result is passed. If the return value is "false", it indicates that the contract test result is failed.
FIG. 4 is a schematic interface diagram of test results in some embodiments. In fig. 4, status represents "test state", and the test state may be "test complete", "test failed", or "under test". The "Transaction hash" represents a "Transaction identifier", and the test contract invocation message may be sent in a Transaction message corresponding to the Transaction identifier. "from" represents the external account address at which the test contract invocation message was sent. "to" represents the account address of the test smart contract. "gas limit" represents the maximum upper limit of gas. "Transaction cost" represents a Transaction fee. "execution cost" represents the cost of executing the intelligent contract. "input" represents an input, which may be an account address of a smart contract under test. "Decoded input" refers to the Decoded input. "Decoded output" indicates the Decoded output, and if "true", it indicates that the contract test result is passed, and if "false", it indicates that the contract test result is not passed. "logs" represent logs of executing smart contracts under test to facilitate determining by log the reason why the contract test failed. "Value" includes a contract execution parameter, which may be, for example, a resource transfer Value.
The intelligent contract testing method can be used for deploying the testing intelligent contract and the tested intelligent contract in the block chain, when the testing contract is executed, the contract method of the tested intelligent contract is called to obtain the contract execution result according to the contract execution parameters, and then the contract testing result is obtained according to the contract execution result. And the test is executed in the block chain environment, so that the problems of the intelligent contract can be more accurately detected, and the efficiency of testing the intelligent contract is improved.
In some embodiments, the contract method comprises a resource transfer method, the contract execution parameters comprise target resource transfer values, and testing the intelligent contract acquisition criteria execution results comprises: acquiring an original resource value corresponding to the second account address; and calculating according to the target resource transfer value and the original resource value to obtain a standard execution result.
In particular, the resource may be a virtual resource, and may be electronic money, such as ethernet money or game money. The resource transfer value is the amount of resource to be transferred, and may be 3-way, for example. The original resource value refers to the amount of resources owned by the second account address before the resource transfer method is executed. The standard execution result is calculated according to the target resource transfer value and the original resource value. And when the second account address is the address of the receiving resource, the standard execution result is a value obtained by adding the target resource transfer value and the original resource value. And when the second account address is the address of the transferred-out resource, the standard execution result is the value obtained by subtracting the target resource transfer value from the original resource value.
In some embodiments, the method for obtaining the account address of the tested intelligent contract, namely the second account address, when the tested intelligent contract sends the tested contract calling message may include: extracting a second account address from the test contract calling message; or obtain the second account address from the test smart contract.
Specifically, the second account address can be written into the test intelligent contract, so that the intelligent contract can be tested directly, and the efficiency is high. For example, a global variable with the type address may be defined in the test intelligent contract, and the actual address of the tested contract is directly written into the code, as shown in code (1). A global variable of type address may also be defined: and (3) writing an address addrA, then writing a construction function, and when the test intelligent contract is deployed, assigning a value to the address addrA by transmitting the address of the tested intelligent contract, as shown in a code (2).
The test contract calling message may carry the second account address, so the second account address may be extracted from the test contract calling message, for example, the address of the tested intelligent contract may be used as a parameter to be transmitted to the method for calling the tested intelligent contract in each test case function, so the account address of the tested intelligent contract may be flexibly changed according to the test requirement, and the flexibility is high. For example, in testing an intelligent contract, the corresponding code may be represented as code (3), and the corresponding meaning is: for the test smart contract of "pay to contract (transfer to smart contract) and check _ balance", the account address of the corresponding tested smart contract is the incoming "addr" parameter. Where "TestA" represents testing an intelligent contract. "Constructor" means a Constructor. "public payable" indicates that the declaration of the constructor is payable, then the test intelligence contract may make the transfer of resources.
Figure BDA0002285107310000121
In some embodiments, the tested smart contracts are pre-deployed in the blockchain, and the tested smart contracts may be deployed by sending blockchain messages, so as shown in fig. 5, the smart contract testing method may further include the following steps:
step S502, receiving a first message sent by a message sending node.
Specifically, the message sending node may be a test request sending node, or may be a different node. The first message may be a transaction message sent by an external account. For example, a transaction message of a blockchain may be a message structure sent by one external account to other accounts. May include the account address of the recipient of the message, the signature of the sender, the transaction amount, the upper limit for gas, the price for gas, etc.
Step S504, when the message receiver address in the first message is determined to be empty, the tested intelligent contract in the block chain message is extracted, and the tested intelligent contract is deployed in the block chain.
Specifically. When the address of the receiver is empty, the message is not sent to an external account or a contract account, and an intelligent contract needs to be deployed in the block chain. Therefore, it can be determined that the first message includes the tested smart contract, the tested smart contract can be extracted from the first message, for example, from a preset position, and the tested smart contract is deployed in the block chain.
Step S506, a second account address is returned to the message sending node, and the second account address is obtained by calculation according to the third account address of the message sending node and the message sending number of the third account address.
Specifically, the message sending number of the third account address refers to the number of messages of which the third account address is the message sender. For example, assuming that the third party account address sent 8 messages, the number of messages sent is 8. The hash calculation may be performed on the third account address and the message transmission number of the third account address, and the obtained hash value is used as the second account address. In the embodiment of the application, the message with the empty message receiver address is used as the message for deploying the intelligent contract, so that the efficiency for deploying the intelligent contract can be improved. The uniqueness of the second account address can be ensured because the third party account address has uniqueness and the number of messages sent by one account address is increased.
For example, for a messaging node, when sending a message deploying a first smart contract, the number of message deliveries may be 1. When sending a message for deploying a second intelligent contract, the message sending number can be 2, so that the uniqueness of the account address of each intelligent contract can be ensured even if the message sending node needs to deploy a plurality of intelligent contracts. And for different message sending nodes, even if the message sending quantity is the same, the account addresses of the message sending nodes are different, so that the calculated hash values are also different, and the uniqueness of the address of the intelligent contract is ensured.
As shown in fig. 6, which is an interface schematic diagram of deploying smart contract a under test in some embodiments. Where 602 is a contract selection box, the name of the intelligent contract to be deployed, for example, "a" may be selected at the contract selection box, and when the "deploy" button is clicked, the node sends a deployment request to the block link point, and the block link point returns the account address "1234 abcd" of the intelligent contract "a," which is displayed in the account address display box 604.
It can be understood that, when deploying the test intelligent contract, steps S502 to S506 may also be referred to, and are not described herein again.
When a test intelligent contract and a tested intelligent contract are deployed in a block link point and then need to be tested, a test contract invoking message may be sent, as shown in fig. 7, which is an interface schematic diagram on a test request sending node in some embodiments. Wherein, the 'gas limit' represents the upper limit of the contract execution cost, and the unit can be the Ether house metering unit 'wei'. "value" indicates the number of resource transfers. As can be seen in FIG. 7, the interface may include a first input box 702 for entering "gas limit", a second input box 704 for entering a resource transfer value, a third input box 706 for entering a test intelligent contract name, and a fourth input box 708 for entering a tested intelligent contract address. It will be appreciated that the third input box 706 may also be used to input the account address of the test smart contract and the fourth input box 708 may also be used to input the name of the tested smart contract. The test request sending node can determine the account address according to the name of the contract, and after the 'start test' button is clicked, the test request sending node sends test contract calling information. As can be seen in FIG. 7, the gas limit may be 3000000wei and the resource transfer value, e.g., the number of Ethernic transfers, may be 10000. The test intelligent contract name is 'testA', and the address of the tested intelligent contract is '123 abcd'.
In some embodiments, if the tested smart contract includes a resource transfer method, the resource transfer method needs to be tested. The resource transfer can be carried out to the testing intelligent contract, so that the resource transfer can be carried out between the tested intelligent contract and the testing intelligent contract, and the testing of the resource transfer method of the tested intelligent contract is completed. The resource transfer to the test intelligent contract can be carried out in one or more of the following four ways:
the first method comprises the following steps: and adding a statement capable of transferring resources to a constructor of the test intelligent contract, and transferring the transfer to a contract account through an external account when the test intelligent contract is deployed. Wherein, the declaration of resource transferability can be represented by adding a preset keyword such as "payable". The code corresponding to the first mode may be as shown in code (5).
Constructor(address addr)public payable (5)
And the second method comprises the following steps: a fall back function can be added in the test intelligent contract and declared as resource transfer is possible. Therefore, the resource transfer can be carried out from the external account to the testing intelligent contract account at any time. A fallback function is a special function in an intelligent contract that may have no name, parameters, and return values. When the called function is not found, a fallback function is called by default. Therefore, when the backspacing function is called, the backspacing function can perform resource transfer to the account address of the test intelligent contract. The code corresponding to the second mode may be as shown in code (6). "Function" means a Function.
Function()public payable。 (6)
And the third is that: the contract execution parameter may include a first resource transfer value, and thus the tested contract invoking message may carry the first resource transfer value, the first account address corresponding to the test intelligent contract, and the method identifier corresponding to the resource transfer method. In this way, the tested intelligent contract calls the resource transfer method according to the method identification, and transfers the virtual resource of the first resource transfer value to the first account address according to the resource transfer method.
The method identifier is used for identifying the contract method, and may be, for example, the name of the contract method, and the name of the resource transfer method may be "pay", which indicates that the method is a transfer method. The first resource transfer value may be set in the test intelligent contract, or may be carried in the test contract invocation message, and the first resource transfer value is used as the target resource transfer value, that is, the number of the resources to be transferred. And the tested contract calling message is used for indicating that the address of the resource receiver is the first account address when the resource transfer method is called for resource transfer. Therefore, when executing the resource transfer method, the tested smart contract may transfer the virtual resource of the first resource transfer value from the second account address to the first account address. The code corresponding to the third mode can be shown as code (7). In the third mode, the transfer method of the tested intelligent contract is called to transfer resources to the tested intelligent contract, so that the resources of the tested intelligent contract can be transferred, the tested intelligent contract can be tested, the testing steps are reduced, and the testing efficiency is improved.
As a practical example, the tested contract calling message may include a transaction message, the resource roll-out address of the transaction message is the address of the tested intelligent contract, the transaction amount may be 1000 dollars, and the resource recipient address is the account address of the tested intelligent contract, so that the tested intelligent contract may transfer 1000 funds to the account address of the tested intelligent contract when receiving the tested contract calling message.
Function pay()public payable{}。 (7)
And fourthly: the test contract calling message can carry a second resource transfer value, so that when the test intelligent contract is executed, virtual resources of the second resource transfer value can be transferred to the first account address corresponding to the test intelligent contract; the tested contract calling message carries a second resource transfer value, a second account address corresponding to the tested intelligent contract and a method identifier corresponding to the resource transfer method, so that the tested intelligent contract can call the resource transfer method according to the method identifier, and transfer virtual resources of the second resource transfer value from the first account address to the second account address according to the resource transfer method. .
Specifically, a statement that resource transfer can be performed may be added to a test case for testing the smart contract. Therefore, when the test request sending node requests the test of the intelligent contract, the second resource transfer value is carried. This first resource transfer value is taken as the target resource transfer value, i.e. the amount of resources to be transferred. I.e., the test contract invocation message may also indicate the transfer of the virtual resource to the test intelligence contract. Therefore, when the test intelligent contract is executed, the virtual resource of the second resource transfer value can be transferred from the external account address of the user to the first account address. After the intelligent contract for testing receives the virtual resource with the second resource transfer value, the account already has the virtual resource with the second resource transfer value, so that the corresponding amount of virtual resource can be transferred to the intelligent contract for testing. Therefore, the resources of the external account can be transferred to the first account address by carrying the second resource transfer value, and then transferred from the first account address to the second account address, so that the test of the tested intelligent contract is realized. The code corresponding to the fourth mode may be as shown in code (8).
function test_pay_to_contract_and_check_balance(address addr)publicreturns(bool){MyContract MyContract=MyContract(Contractaddr) (8)
The intelligent test contract provided by the embodiment of the application can be an automatic test script developed based on the Solidity language, is compiled according to a test case, and can comprise test parameters, test steps, expected results and a result judgment strategy which need to be input when the intelligent test contract is tested. During testing, the tested intelligent contract can be instantiated in the testing function and serves as an instantiated object, and calling of the tested intelligent contract is achieved through the object, so that testing can be automatically executed. Of course, the test parameters may also be carried in the test contract invocation message.
If the intelligent contract is tested through the non-intelligent contract, other testing languages need to be learned, and the obtained testing script often does not conform to the interface definition of the intelligent contract when the interface is called. Smart contracts are generally used in blockchains to validate or execute transaction contracts, in connection with transactions, to allow trusted transactions to be conducted without third parties. In the embodiment of the application, the testing intelligent contract for testing is introduced into the block chain, and the testing intelligent contract can be obtained by integrating one or more scripts of the test case, so that the intelligent contract can be tested by using the intelligent contract, and the cost of learning a new testing language by an intelligent contract developer is reduced. In some embodiments, the code and corresponding interpretation of a test smart contract may be as follows, where the text following "//" is an interpretation of the code.
Figure BDA0002285107310000171
The intelligent contract testing method provided by the application is described below in a specific embodiment, and as shown in fig. 8, a timing diagram for executing the intelligent contract testing method in some embodiments is shown. The method comprises the following steps:
and S1, sending the tested intelligent contract deployment request.
Specifically, the measured intelligent contract deployment request carries the measured intelligent contract, wherein in the measured intelligent contract deployment request, the account address of the receiver is null.
S2: and deploying the tested intelligent contracts in the block chain.
Specifically, when the block link point detects that the account address of the receiver in the detected intelligent contract deployment request is empty, it determines that the type of the request is the contract deployment request, so that the detected intelligent contract can be stored in the block chain, and the account address of the detected intelligent contract, that is, the second account address, is generated according to the account address of the test request sending node and the message sending number of the account address.
And S3, returning the second account address.
Specifically, the block chain node returns a second account address to the test request sending node, and notifies the test request sending node that the intelligent contract has been successfully deployed.
And S4, sending a test intelligent contract deployment request.
Specifically, the test intelligent contract deployment request carries a test intelligent contract, and the test intelligent contract is a test script compiled according to a test case. Wherein the recipient account address in the test intelligent contract deployment request is null.
S5: the test intelligence contracts are deployed in a blockchain.
Specifically, when the block link point detects that the account address of the recipient of the test intelligent contract deployment request is empty, it determines that the type of the request is the contract deployment request, so that the test intelligent contract can be stored in the block chain, and the account address of the test intelligent contract, that is, the first account address, is generated according to the account address of the test request sending node and the message sending number of the account address.
And S6, returning the first account address.
Specifically, the block chain node returns the first account address to the test request sending node, and notifies the test request sending node that the intelligent contract has been successfully deployed.
It can be understood that the test intelligent contract may be deployed first, and then the tested intelligent contract may be deployed.
And S7, sending a test contract invocation message.
Specifically, the test contract invoking message carries an address of a message receiver, which is a first account address of the test intelligent contract. The message is sent to the test intelligent contract to request the test of the tested intelligent contract. The test contract calling message also carries a second account address and a resource transfer value, which indicates that the intelligent contract to be tested is the intelligent contract corresponding to the second account address, and the contract execution parameter is the resource transfer value.
S8: and determining the testing intelligent contract.
Specifically, the block link points determine corresponding test intelligent contracts according to the first account addresses.
S9: and executing the test intelligent contract to send the test intelligent contract calling message.
Specifically, the measured intelligent contract invoking message carries the resource transfer value and the method identifier of the invoked contract method.
S10: and executing the tested intelligent contract.
Specifically, after receiving the tested intelligent contract calling message, the block chain node executes a contract method in the tested intelligent contract according to the method representation to obtain a contract execution result.
S11: and determining a contract test result.
Specifically, the block link point determines whether the test passes or fails according to the contract execution result and the standard execution result.
And S12, returning a contract test result.
Specifically, the block chain node sends a contract test result to the test request sending node. If the contract test result is failure, the tester can analyze the tested intelligent contract to determine the reason of failure and modify the tested intelligent contract.
As shown in fig. 9, in some embodiments, an intelligent contract testing apparatus is provided, which may be integrated in the above block chain node, and specifically may include a call message receiving module 902, a test intelligent contract obtaining module 904, a testing module 906, a contract method executing module 908, and a test result obtaining module 910.
A calling message receiving module 902, configured to receive a test contract calling message;
a test intelligent contract obtaining module 904, configured to obtain a test intelligent contract corresponding to the test contract invoking message;
the test module 906 is configured to execute the test intelligent contract, and send a test contract invoking message to the corresponding tested intelligent contract according to the test intelligent contract, where the test contract invoking message carries contract execution parameters, and the test intelligent contract and the tested intelligent contract are deployed in the block chain;
the contract method execution module 908 is used for executing a contract method by the tested intelligent contract according to the contract execution parameters to obtain a contract execution result;
the test result obtaining module 910 is configured to test the intelligent contract to obtain a contract execution result, and obtain a contract test result of the tested intelligent contract according to the contract execution result.
In some embodiments, test module 906 is to: and the test intelligent contract acquires a second account address and sends a test contract calling message to the test intelligent contract corresponding to the second account address.
In some embodiments, test module 906 is to: extracting a second account address from the test contract calling message; or obtain the second account address from the test smart contract.
In some embodiments, the intelligent contract testing apparatus further comprises:
the first message receiving module is used for receiving a first message sent by a message sending node;
the deployment module is used for extracting the tested intelligent contract in the block chain message and deploying the tested intelligent contract in the block chain when the address of the message receiver in the first message is determined to be null;
and the account address returning module is used for returning a second account address to the message sending node, and the second account address is obtained by calculation according to a third account address of the message sending node and the message sending number of the third account address.
In some embodiments, the test result obtaining module 910 is configured to: testing the intelligent contract to obtain a standard execution result, and comparing the standard execution result with the contract execution result; and when the comparison is consistent, confirming that the contract test result of the tested intelligent contract is passed.
In some embodiments, the test result obtaining module 910 is configured to: acquiring an original resource value corresponding to the second account address; and calculating according to the target resource transfer value and the original resource value to obtain a standard execution result.
In some embodiments, the contract method includes a resource transfer method, and the contract invoking message to be tested carries a first resource transfer value, a first account address corresponding to the test intelligent contract, and a method identifier corresponding to the resource transfer method; the contract method execution module 908 is for: and the tested intelligent contract determines a resource transfer method according to the method identifier, and transfers the virtual resource with the first resource transfer value to the first account address according to the resource transfer method.
In some embodiments, the test contract invocation message carries a second resource transfer value, and the test module is to: transferring the virtual resource of the second resource transfer value to the first account address corresponding to the test intelligent contract; the measured contract invoking message carries a second resource transfer value, a second account address corresponding to the measured intelligent contract, and a method identifier corresponding to the resource transfer method, and the contract method executing module 908 is configured to: and the tested intelligent contract determines a resource transfer method according to the method identifier, and transfers the virtual resource of the second resource transfer value from the first account address to the second account address according to the resource transfer method.
In some embodiments, the test contract invocation message carries a message recipient account address, where the message recipient account address is a first account address corresponding to the test intelligent contract, and the test intelligent contract obtaining module 904 is configured to: and acquiring the intelligent contract corresponding to the first account address as a test intelligent contract.
In some embodiments, the test contract invoking message carries a first account address corresponding to the message sender, and the apparatus further includes a test result returning module, configured to send a contract test result to a node corresponding to the first account address.
FIG. 10 is a diagram illustrating an internal structure of a computer device in some embodiments. The computer device may specifically be a blockchain node in fig. 1. As shown in fig. 10, the computer device includes a processor, a memory, and a network interface connected by a system bus. Wherein the memory includes a non-volatile storage medium and an internal memory. The non-volatile storage medium of the computer device stores an operating system and may also store a computer program that, when executed by the processor, causes the processor to implement the intelligent contract testing method. The internal memory may also have a computer program stored therein that, when executed by the processor, causes the processor to perform the intelligent contract testing method.
Those skilled in the art will appreciate that the architecture shown in fig. 10 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.
In some embodiments, the intelligent contract testing apparatus provided herein may be implemented in the form of a computer program that is executable on a computer device such as that shown in fig. 10. The memory of the computer device may store various program modules constituting the intelligent contract testing apparatus, such as a call message receiving module 902, a test intelligent contract obtaining module 904, a test module 906, a contract method executing module 908 and a test result obtaining module 910 shown in fig. 9. The computer program formed by the program modules makes the processor execute the steps of the intelligent contract testing method of the embodiment of the application described in the specification.
For example, the computer device shown in fig. 10 may receive a test contract invocation message through the invocation message receiving module 902 in the intelligent contract testing apparatus shown in fig. 9; acquiring a test intelligent contract corresponding to the test contract calling message through a test intelligent contract acquisition module 904; executing the test intelligent contract through the test module 906 so as to send a test contract calling message to the corresponding test intelligent contract according to the test intelligent contract, wherein the test contract calling message carries contract execution parameters, and the test intelligent contract are deployed in a block chain; the tested intelligent contract executes the contract method according to the contract execution parameters through the contract method execution module 908 to obtain a contract execution result; the intelligent contract is tested by the test result obtaining module 910 to obtain a contract execution result, and a contract test result of the tested intelligent contract is obtained according to the contract execution result. .
In some embodiments, a computer device is provided, comprising a memory and a processor, the memory storing a computer program that, when executed by the processor, causes the processor to perform the steps of the intelligent contract testing method described above. The steps of the intelligent contract testing method may be the steps in the intelligent contract testing methods of the various embodiments described above.
In some embodiments, a computer-readable storage medium is provided, in which a computer program is stored, which, when executed by a processor, causes the processor to perform the steps of the intelligent contract testing method described above. The steps of the intelligent contract testing method may be the steps in the intelligent contract testing methods of the various embodiments described above.
It should be understood that, although the steps in the flowcharts of the embodiments of the present application are shown in sequence as indicated by the arrows, the steps are not necessarily performed in sequence as indicated by the arrows. The steps are not performed in the exact order shown and described, and may be performed in other orders, unless explicitly stated otherwise. Moreover, at least a portion of the steps in various embodiments may include multiple sub-steps or multiple stages that are not necessarily performed at the same time, but may be performed at different times, and the order of performance of the sub-steps or stages is not necessarily sequential, but may be performed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.
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 hardware related to instructions of a computer program, which can be stored in a non-volatile computer-readable storage medium, and when executed, the computer program can include the processes of the embodiments of the methods described above. Any reference to memory, storage, database, or other medium used in the embodiments provided herein may include non-volatile and/or volatile memory, among others. Non-volatile memory can include read-only memory (ROM), Programmable ROM (PROM), Electrically Programmable ROM (EPROM), Electrically Erasable Programmable ROM (EEPROM), or flash memory. Volatile memory can include Random Access Memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDRSDRAM), Enhanced SDRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), Rambus Direct RAM (RDRAM), direct bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
The technical features of the above embodiments can be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the above embodiments are not described, but should be considered as the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
The above examples only express several embodiments of the present application, and the description thereof is more specific and detailed, but not construed as limiting the scope of the present application. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the concept of the present application, which falls within the scope of protection of the present application. Therefore, the protection scope of the present patent shall be subject to the appended claims.

Claims (15)

1. An intelligent contract testing method, the method comprising:
receiving a test contract calling message;
acquiring a test intelligent contract corresponding to the test contract calling message;
executing the test intelligent contract to send a test contract calling message to a corresponding test intelligent contract according to the test intelligent contract, wherein the test contract calling message carries contract execution parameters, and the test intelligent contract are deployed in a block chain;
the tested intelligent contract executes a contract method according to the contract execution parameters to obtain a contract execution result;
and the test intelligent contract obtains the contract execution result and obtains a contract test result of the tested intelligent contract according to the contract execution result.
2. The method of claim 1, wherein sending a tested contract invocation message to a corresponding tested smart contract according to the testing smart contract comprises:
and the test intelligent contract acquires a second account address and sends a test contract calling message to the test intelligent contract corresponding to the second account address.
3. The method of claim 2, wherein testing the smart contract to obtain the second account address comprises:
extracting a second account address from the test contract calling message; or
And acquiring a second account address from the test intelligent contract.
4. The method of claim 2, further comprising:
receiving a first message sent by a message sending node;
when the message receiver address in the first message is determined to be null, extracting the tested intelligent contract in the block chain message, and deploying the tested intelligent contract in a block chain;
and returning the second account address to the message sending node, wherein the second account address is obtained by calculation according to a third account address of the message sending node and the message sending number of the third account address.
5. The method of claim 1, wherein obtaining the contract test result of the tested smart contract according to the contract execution result comprises:
the test intelligent contract obtains a standard execution result and compares the standard execution result with the contract execution result;
and when the comparison is consistent, confirming that the contract test result of the tested intelligent contract is passed.
6. The method of claim 5, wherein the contract method comprises a resource transfer method, wherein the contract execution parameters comprise target resource transfer values, and wherein testing intelligent contracts to obtain standard execution results comprises:
acquiring an original resource numerical value corresponding to the second account address;
and calculating to obtain a standard execution result according to the target resource transfer value and the original resource value.
7. The method according to claim 1, wherein the contract method comprises a resource transfer method, and the tested contract invoking message carries the first resource transfer value, a first account address corresponding to the test intelligent contract, and a method identifier corresponding to the resource transfer method;
the tested intelligent contract executes a contract method according to the contract execution parameters, and the contract execution result is obtained by the following steps:
and the tested intelligent contract determines a resource transfer method according to the method identifier, and transfers the virtual resource of the first resource transfer value to the first account address according to the resource transfer method.
8. The method of claim 1, wherein the test contract invocation message carries a second resource transfer value, and wherein executing the test smart contract further comprises:
transferring the virtual resource of the second resource transfer value to the first account address corresponding to the test intelligent contract;
the measured contract calling message carries the second resource transfer value, the second account address corresponding to the measured intelligent contract and the method identifier corresponding to the resource transfer method, and the executing of the contract method by the measured intelligent contract according to the contract execution parameter includes:
and the tested intelligent contract determines a resource transfer method according to the method identifier, and transfers the virtual resource of the second resource transfer value from the first account address to the second account address according to the resource transfer method.
9. The method according to claim 1, wherein the test contract invocation message carries a message recipient account address, the message recipient account address is a first account address corresponding to the test intelligent contract, and the obtaining of the test intelligent contract corresponding to the test contract invocation message comprises:
and acquiring the intelligent contract corresponding to the first account address as a test intelligent contract.
10. The method of claim 1, wherein the test contract invocation message carries a first account address corresponding to a sender of the message, the method further comprising:
and sending the contract test result to a node corresponding to the first account address.
11. An intelligent contract testing apparatus, the apparatus comprising:
the calling message receiving module is used for receiving a test contract calling message;
the test intelligent contract obtaining module is used for obtaining a test intelligent contract corresponding to the test contract calling message;
the test module is used for executing the test intelligent contract to send a tested contract calling message to the corresponding tested intelligent contract according to the test intelligent contract, the tested contract calling message carries contract execution parameters, and the test intelligent contract and the tested intelligent contract are deployed in a block chain;
the contract method execution module is used for executing a contract method by the tested intelligent contract according to the contract execution parameters to obtain a contract execution result;
and the test result obtaining module is used for obtaining the contract execution result by the test intelligent contract and obtaining the contract test result of the tested intelligent contract according to the contract execution result.
12. The apparatus of claim 11, wherein the testing module is configured to:
and the test intelligent contract acquires a second account address and sends a test contract calling message to the test intelligent contract corresponding to the second account address.
13. The apparatus of claim 12, wherein the testing module is configured to:
extracting a second account address from the test contract calling message; or
And acquiring a second account address from the test intelligent contract.
14. A computer arrangement comprising a memory and a processor, the memory having stored thereon a computer program that, when executed by the processor, causes the processor to carry out the steps of the intelligent contract testing method according to any one of claims 1 to 10.
15. A computer-readable storage medium, having stored thereon, a computer program which, when executed by a processor, causes the processor to perform the steps of the intelligent contract testing method of any of claims 1 to 10.
CN201911157165.9A 2019-11-22 2019-11-22 Intelligent contract testing method, intelligent contract testing device, computer equipment and storage medium Active CN111090581B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911157165.9A CN111090581B (en) 2019-11-22 2019-11-22 Intelligent contract testing method, intelligent contract testing device, computer equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911157165.9A CN111090581B (en) 2019-11-22 2019-11-22 Intelligent contract testing method, intelligent contract testing device, computer equipment and storage medium

Publications (2)

Publication Number Publication Date
CN111090581A true CN111090581A (en) 2020-05-01
CN111090581B CN111090581B (en) 2024-02-09

Family

ID=70393827

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911157165.9A Active CN111090581B (en) 2019-11-22 2019-11-22 Intelligent contract testing method, intelligent contract testing device, computer equipment and storage medium

Country Status (1)

Country Link
CN (1) CN111090581B (en)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111865907A (en) * 2020-06-08 2020-10-30 深圳前海益链网络科技有限公司 Single-point execution single-point verification block chain intelligent contract system, realization method and device
CN111986029A (en) * 2020-08-28 2020-11-24 数网金融有限公司 Data processing method and device and electronic equipment
CN113010409A (en) * 2020-09-16 2021-06-22 腾讯科技(深圳)有限公司 Intelligent contract testing method and device, electronic equipment and storage medium
CN113282501A (en) * 2021-06-03 2021-08-20 网易(杭州)网络有限公司 Block chain testing method and device and electronic equipment
WO2022171275A1 (en) * 2021-02-10 2022-08-18 Telefonaktiebolaget Lm Ericsson (Publ) Method and system for testing smart contracts

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107943691A (en) * 2017-11-17 2018-04-20 深圳圣马歌科技有限公司 A kind of method and device for the functional test page for automatically generating intelligent contract
CN109408373A (en) * 2018-09-26 2019-03-01 深圳壹账通智能科技有限公司 Test method, computer readable storage medium and the test terminal of intelligent contract
CN109543457A (en) * 2018-11-07 2019-03-29 泰康保险集团股份有限公司 The method and device called between control intelligent contract
CN109829013A (en) * 2018-12-27 2019-05-31 上海点融信息科技有限责任公司 For running the method for intelligent contract in block chain network, storage medium, calculating equipment
US20190317936A1 (en) * 2018-11-09 2019-10-17 Innoplexus Ag System and method for interoperability of blockchains

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107943691A (en) * 2017-11-17 2018-04-20 深圳圣马歌科技有限公司 A kind of method and device for the functional test page for automatically generating intelligent contract
CN109408373A (en) * 2018-09-26 2019-03-01 深圳壹账通智能科技有限公司 Test method, computer readable storage medium and the test terminal of intelligent contract
CN109543457A (en) * 2018-11-07 2019-03-29 泰康保险集团股份有限公司 The method and device called between control intelligent contract
US20190317936A1 (en) * 2018-11-09 2019-10-17 Innoplexus Ag System and method for interoperability of blockchains
CN109829013A (en) * 2018-12-27 2019-05-31 上海点融信息科技有限责任公司 For running the method for intelligent contract in block chain network, storage medium, calculating equipment

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111865907A (en) * 2020-06-08 2020-10-30 深圳前海益链网络科技有限公司 Single-point execution single-point verification block chain intelligent contract system, realization method and device
CN111986029A (en) * 2020-08-28 2020-11-24 数网金融有限公司 Data processing method and device and electronic equipment
CN113010409A (en) * 2020-09-16 2021-06-22 腾讯科技(深圳)有限公司 Intelligent contract testing method and device, electronic equipment and storage medium
CN113010409B (en) * 2020-09-16 2023-09-15 腾讯科技(深圳)有限公司 Intelligent contract testing method and device, electronic equipment and storage medium
WO2022171275A1 (en) * 2021-02-10 2022-08-18 Telefonaktiebolaget Lm Ericsson (Publ) Method and system for testing smart contracts
CN113282501A (en) * 2021-06-03 2021-08-20 网易(杭州)网络有限公司 Block chain testing method and device and electronic equipment

Also Published As

Publication number Publication date
CN111090581B (en) 2024-02-09

Similar Documents

Publication Publication Date Title
CN111090581B (en) Intelligent contract testing method, intelligent contract testing device, computer equipment and storage medium
Al-Bassam et al. Chainspace: A sharded smart contracts platform
CN110443075B (en) Method and device for verifying and deploying block chain intelligent contracts
CN110598446A (en) Block chain based test method and device, storage medium and computer equipment
CN109656778B (en) Data acquisition method and device, computer equipment and storage medium
CN112801658B (en) Cross-border resource transfer authenticity auditing method and device and electronic equipment
CN112527912B (en) Data processing method and device based on block chain network and computer equipment
CN110633963A (en) Electronic bill processing method, electronic bill processing device, computer-readable storage medium and equipment
CN111445333A (en) Block generation method and device, computer equipment and storage medium
CN110597541B (en) Interface updating processing method, device, equipment and storage medium based on block chain
CN112700246B (en) Block chain-based data processing method, device, equipment and readable storage medium
CN111770198A (en) Information sharing method, device and equipment
CN113609219A (en) Method, system, device and storage medium for verifying file based on block chain
CN113315828A (en) Traffic recording method and device, traffic recording equipment and storage medium
CN110908812A (en) Business data processing method and device, readable storage medium and computer equipment
CN112364059A (en) Correlation matching method, device, equipment and storage medium under multi-rule scene
CN115730319A (en) Data processing method, data processing device, computer equipment and storage medium
CN110602051B (en) Information processing method based on consensus protocol and related device
Mourouzis et al. Introduction to decentralization and smart contracts
CN115913734A (en) User authority management method, device and equipment applied to alliance chain
CN111814193B (en) Information sharing method, device and equipment
CN112015826B (en) Intelligent contract security detection method based on block chain and related equipment
CN116070191A (en) Information processing method and device, storage medium, and program product
CN115701078A (en) Cross-chain transaction processing method and device, electronic equipment and storage medium
CN113469811A (en) Block chain transaction processing method and device

Legal Events

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