我试图测试nodejs链代码而不将其部署到超级边缘的fabic网络。有一个名为@theledger / fabric-mock-stub的流行nodejs库。以下是我的单元测试
const Chaincode = require('./index.js');
// import { ChaincodeMockStub, Transform } from "@theledger/fabric-mock-stub";
const ChaincodeMockStub = require("@theledger/fabric-mock-stub")
// You always need your chaincode so it knows which chaincode to invoke on
const chaincode = new Chaincode();
describe('Test MyChaincode', () => {
it("Should init without issues", async () => {
const mockStub = new ChaincodeMockStub("MyMockStub", chaincode);
const response = await mockStub.mockInit("tx1", []);
expect(response.status).to.eql(200)
});
});
运行此测试时,会收到以下错误
2019-04-08T18:34:55.530Z ERROR [lib/chaincode.js] uncaughtException: Missing required argument peer.address
有谁知道如何使用这个测试库? https://github.com/wearetheledger/fabric-mock-stub
非常感谢任何帮助。
我有同样的问题,我注意到我的链码js文件的底部
shim.start(new Chaincode())
如果将此行移动到另一个文件或在进行测试之前将其注释掉,测试应该可以正常工作。