- Learn Blockchain Programming with JavaScript
- Eric Traub
- 226字
- 2021-06-10 18:40:36
Testing the Blockchain constructor function
Let's test the Blockchain constructor function as follows:
- Lets make an instance of our Blockchain constructor function, so we will add the following line of code:
const bitcoin = new Blockchain();
- The bitcoin variable in the preceding line of code is just used for the purpose of an example. Then we add the following line of code:
console.log(bitcoin);
With the preceding line of code, bitcoin should be our blockchain. There is currently no data or blocks in this, but it should log out as a blockchain. Let's save the test.js file and run the test to observe the output on the terminal window.
- Now go to our terminal window. In here, we're currently in the blockchain directory, and our test.js file is in our dev folder, so type the following command in the terminal:
node dev/test.js
This preceding line of code will allow us to run the test that we have written to test our Blockchain constructor function.
- Now press Enter, and we'll get to observe the Blockchain on the terminal window, as highlighted in the following screenshot:
From the output in the preceding screenshot, we can observe that Blockchain has an empty chain and an empty transactions array. This is exactly what we expected the output to be.
推薦閱讀
- TypeScript Essentials
- Qt 5 and OpenCV 4 Computer Vision Projects
- Spring 5.0 By Example
- SoapUI Cookbook
- Machine Learning with R Cookbook(Second Edition)
- C++程序設計基礎教程
- Learning Data Mining with R
- 軟件品質之完美管理:實戰經典
- AutoCAD 2009實訓指導
- JavaScript+jQuery網頁特效設計任務驅動教程
- 分布式數據庫HBase案例教程
- Android初級應用開發
- INSTANT Lift Web Applications How-to
- R語言:邁向大數據之路
- HTML5 Game Development by Example:Beginner's Guide(Second Edition)