
上QQ阅读APP看书,第一时间看更新
Testing the createNewBlock method
Now lets test the createNewBlock method that we created in the preceding section:
- The first thing that we need to do is export our Blockchain constructor function because we are going to use this function in our test.js file. So, to export the constructor function, we will go to the bottom of the blockchain.js file, type the following line of code, and then save the file:
module.exports = Blockchain;
- Next, go to the dev/test.js file, as this is where we will be testing our createNewBlock method. Now, the first thing that we want to do in our dev/test.js file is import our Blockchain constructor function, so type the following:
const Blockchain = require('./blockchain');
This preceding line of code simply requires or calls the blockchain.js file.