npm 测试在查询函数上失败(Hyperledger Composer)
npm test fails on the query function (Hyperledger Composer)
我在 Hyperledger Composer 上对我的事务函数代码成功调用了命名查询。问题是,当我尝试 运行 带有 npm test
的测试集时,出现以下错误:
error 'query' is not defined no-undef
为了演示目的,我生成了一个带有 yo hyperledger-composer:businessnetwork
的新业务网络框架,我向其中添加了一个 queries.qry 文件,其中包含以下查询:
query getParticipant{
description: "Get participants with given first name"
statement:
SELECT org.acme.mynetwork.SampleParticipant WHERE (firstName == _$firstName)
}
我还修改了 lib/logic.js 文件以包含一个将调用先前查询的事务,代码如下:
async function sampleTransaction(tx) {
let participant = await query('getParticipant', { firstName: 'Alice' });
console.log(participant);
}
此代码在部署的网络上按预期工作。当提交一个虚拟的 sampleTransaction 时,我可以看到参与者 Alice 打印在 docker 日志上。但是,npm test
失败并出现前面提到的错误。
也许 .eslintrc.yml 文件中缺少一些东西,由 yeoman 自动生成...我真的不知道...
有谁知道如何解决这个问题?在将新代码部署到业务网络之前能够正确地 运行 所有测试将真正简化开发过程。
作为参考,我在 Internet 上找到的关于该问题的唯一信息是这个未解决的问题,对 Hyperledger Composer 没有任何评论 github:
https://github.com/hyperledger/composer/issues/3775
谢谢!
在 composer-sample-networks 存储库的测试中定义了查询 -> https://github.com/hyperledger/composer-sample-networks
示例:
这是 eslint 抱怨你的 TP 功能。您需要告诉 eslint 它不知道的全局函数。如果您在这里以贸易网络为例
https://github.com/hyperledger/composer-sample-networks/blob/master/packages/trade-network/lib/logic.js#L15
您将看到如何通知 eslint 全局函数声明。
我在这里包含了这一行,因为它是一行评论
/* global getAssetRegistry getFactory emit query */
我在 Hyperledger Composer 上对我的事务函数代码成功调用了命名查询。问题是,当我尝试 运行 带有 npm test
的测试集时,出现以下错误:
error 'query' is not defined no-undef
为了演示目的,我生成了一个带有 yo hyperledger-composer:businessnetwork
的新业务网络框架,我向其中添加了一个 queries.qry 文件,其中包含以下查询:
query getParticipant{
description: "Get participants with given first name"
statement:
SELECT org.acme.mynetwork.SampleParticipant WHERE (firstName == _$firstName)
}
我还修改了 lib/logic.js 文件以包含一个将调用先前查询的事务,代码如下:
async function sampleTransaction(tx) {
let participant = await query('getParticipant', { firstName: 'Alice' });
console.log(participant);
}
此代码在部署的网络上按预期工作。当提交一个虚拟的 sampleTransaction 时,我可以看到参与者 Alice 打印在 docker 日志上。但是,npm test
失败并出现前面提到的错误。
也许 .eslintrc.yml 文件中缺少一些东西,由 yeoman 自动生成...我真的不知道...
有谁知道如何解决这个问题?在将新代码部署到业务网络之前能够正确地 运行 所有测试将真正简化开发过程。
作为参考,我在 Internet 上找到的关于该问题的唯一信息是这个未解决的问题,对 Hyperledger Composer 没有任何评论 github: https://github.com/hyperledger/composer/issues/3775
谢谢!
在 composer-sample-networks 存储库的测试中定义了查询 -> https://github.com/hyperledger/composer-sample-networks
示例:
这是 eslint 抱怨你的 TP 功能。您需要告诉 eslint 它不知道的全局函数。如果您在这里以贸易网络为例
https://github.com/hyperledger/composer-sample-networks/blob/master/packages/trade-network/lib/logic.js#L15
您将看到如何通知 eslint 全局函数声明。
我在这里包含了这一行,因为它是一行评论
/* global getAssetRegistry getFactory emit query */