A kind of method and device for the functional test page for automatically generating intelligent contractTechnical field
The present invention relates to block chain technical field, more particularly to a kind of functional test page for automatically generating intelligent contractMethod and device.
Background technology
Block chain is the new of the computer technologies such as Distributed Storage, point-to-point transmission, common recognition mechanism, Encryption AlgorithmApplication model, block chain also have anti-tamper feature.Ether mill is a kind of block chain implementation, and intelligent contract is on ether millExecutable code, the exploitation of intelligent contract is carried out usually using truffle.Wherein truffle is a kind of exploitation frame in ether millFrame.Intelligence contract of the prior art is generally used for carrying out using order line after truffle consoles call web3 interfacesFunctional test, parameter name and parameter type need user to remember, therefore complicated, and ordinary user is difficult to grasp, so as to causeTesting efficiency is low.
The content of the invention
For above-mentioned technical problem, an embodiment of the present invention provides a kind of functional test page for automatically generating intelligent contractMethod and device, can solve that the functional test of intelligent contract development process in the prior art is complicated, and testing efficiency is lowTechnical problem.
The first aspect of the embodiment of the present invention provides a kind of method for the functional test page for automatically generating intelligent contract, bagInclude:
The corresponding intelligent contract code of intelligent contract to be tested is obtained, intelligent contract code is compiled, output compilingFile;
After analyzing compiling file, automatic generation function test page;
The parameter that user inputs on the functional test page is obtained, functional test is carried out to intelligent contract.
Alternatively, it is described to obtain the corresponding intelligent contract code of intelligent contract, intelligent contract code is compiled, is exportedBefore compiling file, including:
The web server program that a nodejs running environment is write is pre-actuated, and intelligent contract to be tested is copiedShellfish is to web server catalogue.
Alternatively, the compiling file includes the intelligent binary code of contract, the interface message of contract and contract issueAddress.
Alternatively, the compiling file is json files, it is described compiling file is analyzed after, automatic generation function surveyThe examination page includes:
Operation truffle migrate export json files after contract is published to ether mill node, use nodejs journeysSequence analyzes json files;
All json files in web server are obtained, the json files issued to all successes travel through;
One form is generated respectively to each interface of each intelligent contract, wherein interface includes several intelligent contractsParameter, form include several entries, and an entry corresponds to the parameter of an intelligent contract;
According to the corresponding functional test page of each intelligence contract of form generation of each intelligent contract.
Alternatively, after the basis generates a functional test page to each intelligent contract, further include:
The corresponding functional test page of each intelligent contract is obtained, homepage is generated according to the functional test page of acquisition,Wherein homepage includes the list of all issued intelligent contracts.
Second aspect of the embodiment of the present invention provides a kind of device for the functional test page for automatically generating intelligent contract, instituteStating device includes:Memory, processor and it is stored in the computer journey that can be run on the memory and on the processorSequence, the computer program realize following steps when being performed by the processor:
The corresponding intelligent contract code of intelligent contract to be tested is obtained, intelligent contract code is compiled, output compilingFile;
After analyzing compiling file, automatic generation function test page;
The parameter that user inputs on the functional test page is obtained, functional test is carried out to intelligent contract.
Alternatively, following steps are also realized when the computer program is performed by the processor:
The web server program that a nodejs running environment is write is pre-actuated, and intelligent contract to be tested is copiedShellfish is to web server catalogue.
Alternatively, compiling file is json files, is also realized when the computer program is performed by the processor followingStep:
Operation truffle migrate export json files after contract is published to ether mill node, use nodejs journeysSequence analyzes json files;
All json files in web server are obtained, the json files issued to all successes travel through;
One form is generated respectively to each interface of each intelligent contract, wherein interface includes several intelligent contractsParameter, form include several entries, and an entry corresponds to the parameter of an intelligent contract;
According to the corresponding functional test page of each intelligence contract of form generation of each intelligent contract.
Alternatively, following steps are also realized when the computer program is performed by the processor:
The corresponding functional test page of each intelligent contract is obtained, homepage is generated according to the functional test page of acquisition,Wherein homepage includes the list of all issued intelligent contracts.
The third aspect of the embodiment of the present invention provides a kind of non-volatile computer readable storage medium storing program for executing, it is characterised in thatThe non-volatile computer readable storage medium storing program for executing is stored with computer executable instructions, and the computer executable instructions are by oneOr multiple processors may be such that one or more of processors perform the above-mentioned function of automatically generating intelligent contract when performingThe method of test page.
In technical solution provided in an embodiment of the present invention, by by the test parameter systematic function test sheets of intelligent contractFace, obtains the parameter input by user to intelligent contract on the functional test page and tests, output test result.Therefore it is oppositeIn the prior art, the embodiment of the present invention can show intelligent contract automatic generation function test page on the functional test pageShow test parameter, facilitate user to test intelligent contract, improve the testing efficiency of the intelligent contract on ether mill.
Brief description of the drawings
Fig. 1 is an a kind of embodiment of the method for the functional test page for automatically generating intelligent contract in the embodiment of the present inventionFlow diagram;
Fig. 2 is a kind of another implementation of the device for the functional test page for automatically generating intelligent contract in the embodiment of the present inventionExample structure diagram.
Embodiment
Below in conjunction with the attached drawing in the embodiment of the present invention, the technical solution in the embodiment of the present invention is carried out clear, completeSite preparation describes, it is clear that described embodiment is only part of the embodiment of the present invention, instead of all the embodiments.It is based onEmbodiment in the present invention, the every other implementation that those skilled in the art are obtained without creative effortsExample, belongs to the scope of protection of the invention.
Referring to Fig. 1, Fig. 1 is a kind of method for the functional test page for automatically generating intelligent contract in the embodiment of the present inventionOne embodiment flow diagram.As shown in Figure 1, including:
Step S100, the corresponding intelligent contract code of intelligent contract to be tested is obtained, intelligent contract code is compiled,Export compiling file;
Step S200, after analyzing compiling file, automatic generation function test page;
Step S300, the parameter that user inputs on the functional test page is obtained, functional test is carried out to intelligent contract.
When it is implemented, obtaining the corresponding intelligent contract code of intelligent contract to be tested, intelligent contract code can export oneA compiling file, the inside include the binary code of contract, the interface details of contract, and contract issue address.AnalysisCompiling file.A functional test page is automatically generated to each compiling file, as long as user inputs in the page, parameter, is clicked onTesting button, calling interface meeting auto-returned is to user.It is easy to operate so so that test is directly perceived, even if not being professional personAlso can be easier to carry out test compiling file includes the intelligent binary code of contract, the interface message of contract and contract issueAddress.
Alternatively, further included before step S100:Pre-actuate the web server journey that a nodejs running environment is writeSequence, and copy intelligent contract to be tested to web server catalogue.
Specifically, the embodiment of the present invention needs nodejs running environment, and Node.js is a cross-platform JavaScriptDevelopment environment.A web server program write containing a nodejs is generated in nodejs running environment, the conjunction to be testedAbout copy web server catalogue to.As web server catalogue is:Solidity build contracts, then by intelligent contractCopy to solidity build contracts.
Alternatively, compiling file is json files, and step S200 is specially:
Operation truffle migrate export json files after contract is published to ether mill node, use nodejs journeysSequence analyzes json files;
All json files in web server are obtained, the json files issued to all successes travel through;
One form is generated respectively to each interface of each intelligent contract, wherein interface includes several intelligent contractsParameter, form include several entries, and an entry corresponds to the parameter of an intelligent contract;
According to the corresponding functional test page of each intelligence contract of form generation of each intelligent contract.
When it is implemented, json (JavaScript Object Notation, JS object tag) is a kind of lightweightData interchange format.It is based on a subset of ECMAScript (w3c formulate js specifications), using being totally independent of programming languageThe text formatting of speech stores and represents data.Json files are analyzed using nodejs programs, run truffle migrate handlesContract is published to ether mill node, runs web server program, travels through web server catalogue, obtains the institute in web serverThere are json files, the json files issued to all successes travel through;The variable interface of each intelligent contract is obtained, to eachEach interface of intelligent contract generates a form respectively, and wherein interface includes the parameter of several intelligent contracts, and form includesSeveral entries, an entry correspond to the parameter of an intelligent contract;According to each intelligence of form generation of each intelligent contractThe corresponding functional test page of contract.Wherein truffle is ether mill Solidity programming language Development Frameworks.truffleMigrate is that intelligent contract is issued.
Alternatively, after according to a functional test page is generated to each intelligent contract, further include:
The corresponding functional test page of each intelligent contract is obtained, homepage is generated according to the functional test page of acquisition,Wherein homepage includes the list of all issued intelligent contracts.
When it is implemented, generate homepage, homepage after being combined according to the individual feature test page of each intelligent contractComprising all issued intelligent contracts, after selecting single intelligent contract, into the corresponding functional test page.Surveyed in functionPage input test parameter is tried, web server returns to test result.
The method of the functional test page for automatically generating intelligent contract in the embodiment of the present invention is described above,The device of the functional test page for automatically generating intelligent contract in the embodiment of the present invention is described below, referring to Fig. 2,Fig. 2 is a kind of another embodiment program mould of the device for the functional test page for automatically generating intelligent contract in the embodiment of the present inventionBlock schematic diagram, including:
Device 10 includes:Memory 101, processor 102 and storage are on a memory and the meter that can run on a processorCalculation machine program, computer program realize following steps when being performed by processor 101:
The corresponding intelligent contract code of intelligent contract to be tested is obtained, intelligent contract code is compiled, output compilingFile;
After analyzing compiling file, automatic generation function test page;
The parameter that user inputs on the functional test page is obtained, functional test is carried out to intelligent contract.
Specifically, the corresponding intelligent contract code of intelligent contract to be tested is obtained, intelligent contract code can export a volumeTranslation part, the inside include the binary code of contract, the interface details of contract, and contract issue address.Analysis compilingFile.A functional test page is automatically generated to each compiling file, as long as user inputs in the page, parameter, clicks on testButton, calling interface meeting auto-returned is to user.It is easy to operate so so that test is directly perceived, even if not being that professional person also canIt is easier to carry out test compiling file with including the intelligent binary code of contract, the interface message of contract and contract issueLocation.
Alternatively, following steps are also realized when computer program is performed by processor 101:
The web server program that a nodejs running environment is write is pre-actuated, and intelligent contract to be tested is copiedShellfish is to web server catalogue.
Specifically, the embodiment of the present invention needs nodejs running environment, and Node.js is a cross-platform JavaScriptDevelopment environment.A web server program write containing a nodejs is generated in nodejs running environment, the conjunction to be testedAbout copy web server catalogue to.As web server catalogue is:Solidity build contracts, then by intelligent contractCopy to solidity build contracts.
Alternatively, compiling file is json files, and computer program also realizes following steps when being performed by processor 101:
Operation truffle migrate export json files after contract is published to ether mill node, use nodejs journeysSequence analyzes json files;
All json files in web server are obtained, the json files issued to all successes travel through;
One form is generated respectively to each interface of each intelligent contract, wherein interface includes several intelligent contractsParameter, form include several entries, and an entry corresponds to the parameter of an intelligent contract;
According to the corresponding functional test page of each intelligence contract of form generation of each intelligent contract.
Specifically, json (JavaScript Object Notation, JS object tag) is a kind of data of lightweightExchange format.It is based on a subset of ECMAScript (w3c formulate js specifications), using being totally independent of programming languageText formatting stores and represents data.Json files are analyzed using nodejs programs, truffle migrate are contract for operationEther mill node is published to, runs web server program, travels through web server catalogue, is obtained all in web serverJson files, the json files issued to all successes travel through;The variable interface of each intelligent contract is obtained, to eachEach interface of intelligent contract generates a form respectively, and wherein interface includes the parameter of several intelligent contracts, and form includesSeveral entries, an entry correspond to the parameter of an intelligent contract;According to each intelligence of form generation of each intelligent contractThe corresponding functional test page of contract.Wherein truffle is ether mill Solidity programming language Development Frameworks.truffleMigrate is that intelligent contract is issued.
Alternatively, following steps are also realized when computer program is performed by processor 101:
The corresponding functional test page of each intelligent contract is obtained, homepage is generated according to the functional test page of acquisition,Wherein homepage includes the list of all issued intelligent contracts.
When it is implemented, generate homepage, homepage after being combined according to the individual feature test page of each intelligent contractComprising all issued intelligent contracts, after selecting single intelligent contract, into the corresponding functional test page.Surveyed in functionPage input test parameter is tried, web server returns to test result.
An embodiment of the present invention provides a kind of non-volatile computer readable storage medium storing program for executing, computer-readable recording medium is depositedComputer executable instructions are contained, which is executed by one or more processors, for example, being retouched more than performingMethod and step S100 to step S300 in the Fig. 1 stated.
The above embodiments are merely illustrative of the technical solutions of the present invention, rather than its limitations;Although with reference to the foregoing embodimentsThe present invention is described in detail, it will be understood by those of ordinary skill in the art that:It still can be to foregoing each implementationTechnical solution described in example is modified, or carries out equivalent substitution to which part technical characteristic;And these modification orReplace, the essence of appropriate technical solution is departed from the spirit and scope of various embodiments of the present invention technical solution.