Debugging Transaction Code

2019-05-23 00:38发布

问题:

I've been asking myself whether there is an easy way of debugging the JavaScript code of the transactions. JS already has mature debuggers, it is only a question of how to easily bind it to the code running in the container. Does anyone have a clue? -- Thx.

回答1:

One of the easiest ways to debug your transaction code is to deploy your business network into an embedded fabric which basically means that your code is run as any other NodeJS app is and you can use the node debugger to step through your code or even simple console.log statements if that suffices.

To get an insight into how to achieve this, have a look at the code here: UPDATED LINK https://github.com/hyperledger/composer-sample-networks/blob/master/packages/carauction-network/test/CarAuction.js#L31-L49

This is the beforeEach method of a unit test for the sample network and as you'll see, it deploys the network to the 'embedded' fabric.

The code then goes on to perform tests that include calling the submitTransaction API on the embedded businessNetworkConnection which then causes the Transaction script code to be eval'ed by the embedded fabric.

So it's all happening within a single Node app and is much easier to debug.

HTH