- 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.
推薦閱讀
- Getting Started with ResearchKit
- Mastering Objectoriented Python
- 編程卓越之道(卷3):軟件工程化
- Learning Linux Binary Analysis
- UML 基礎(chǔ)與 Rose 建模案例(第3版)
- 軟件供應(yīng)鏈安全:源代碼缺陷實例剖析
- Android移動開發(fā)案例教程:基于Android Studio開發(fā)環(huán)境
- QGIS 2 Cookbook
- Visual Basic程序設(shè)計全程指南
- PHP 8從入門到精通(視頻教學(xué)版)
- Python Social Media Analytics
- Clojure Web Development Essentials
- Laravel Design Patterns and Best Practices
- Elasticsearch搜索引擎構(gòu)建入門與實戰(zhàn)
- Java面試一戰(zhàn)到底(基礎(chǔ)卷)