官术网_书友最值得收藏!

Testing the Blockchain constructor function

Let's test the Blockchain constructor function as follows: 

  1. Lets make an instance of our Blockchain constructor function, so we will add the following line of code:
const bitcoin = new Blockchain();
  1. 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.

  1. 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.

  1. 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. 

主站蜘蛛池模板: 贺兰县| 绩溪县| 双鸭山市| 宁远县| 连州市| 浦县| 雅安市| 鹰潭市| 岳池县| 凉城县| 湟中县| 福鼎市| 吉木乃县| 江津市| 永吉县| 策勒县| 寻乌县| 洞口县| 巩留县| 鄱阳县| 新和县| 平安县| 财经| 兰溪市| 利津县| 东乡县| 通许县| 惠来县| 铜山县| 翼城县| 宣武区| 江北区| 博爱县| 金坛市| 亚东县| 衡南县| 缙云县| 特克斯县| 惠水县| 余姚市| 治多县|