node.js - 如何使用 ChainCodeMockStub 测试 nodejs 链代码
问题描述
我正在尝试测试 nodejs 链代码而不将其部署到超级账本Fabic 网络。有一个流行的 nodejs 库,称为 @theledger/fabric-mock-stub。下面是我的单元测试
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())
如果您将此行移至另一个文件或在进行测试之前将其注释掉,则测试应该可以正常工作。
推荐阅读
- python - 如何自动编辑 x,y 路径
- python - 无法使用日志记录控制 structlog
- javascript - 为什么我的代码只在未附加调试器时抛出错误?
- arrays - 数组的 OpenAPI 3.0 参考
- python - 我不能使用 bazel 来构建 tensorflow,因为我用 bazelisk 安装了 bazel?
- html - 如何将切换按钮移动到水平线?
- xaml - 一次点击执行多个点击事件
- while-loop - 为什么这个 Arduino while 循环永远不会结束?
- php - 替代 Wordpress REST API 中的 wp_update_post()
- reactjs - VS Code eslint 强调错误的错误