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

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. 

主站蜘蛛池模板: 通渭县| 新竹县| 丁青县| 漳州市| 鄂托克前旗| 凉山| 轮台县| 辛集市| 共和县| 金乡县| 肇州县| 商南县| 阿克陶县| 望城县| 芜湖县| 石渠县| 鄯善县| 龙里县| 申扎县| 昌都县| 蒙自县| 库伦旗| 屏南县| 兴安县| 高陵县| 衡阳市| 任丘市| 高尔夫| 阳东县| 海盐县| 买车| 郑州市| 体育| 栖霞市| 洞口县| 邵武市| 吴旗县| 邹城市| 社旗县| 南漳县| 茂名市|