加入收藏 | 设为首页 | 会员中心 | 我要投稿 牡丹江站长网 (https://www.0453zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长资讯 > 传媒 > 正文

使用Hyperledger Fabric和Composer实现区块链应用程序

发布时间:2019-07-27 04:19:43 所属栏目:传媒 来源:佚名
导读:目前无法绕过技术领域的是区块链话题。但除了加密货币之外,还有更多有趣的应用程序可以带来许多激动人心的软件生态系统。这也适用于Hyperledger项目,该项目提供了一个非常模块化的区块链框架。让我们看看使用Hyperledger Fabric和Composer实现区块链应用

功能本身的单元测试相对简单,如果我们有经验,我们不需要了解更多。只有对此所需的对象的boostrapping仍然有点超载样板代码。测试首先启动内存中的Fabric网络,在其上安装业务网络,然后以默认管理员身份对其进行身份验证。因为这个Composer提供了库composer-admincomposer-clientcomposer-commoncomposer-connector-embedded。在测试设置之后,我们现在可以针对嵌入式网络编写测试用例。由于其长度,设置代码未包含在列表中,但可以在test/EngineSupplychainSpec.js中的主分支上查看和测试。

用于测试交易类型的单元测试用例通常具有类似的模式。他们使用其属性和关系重新创建交易,针对网络执行交易,然后检查所涉及的资产和参与者的数据状态。我们来看看createEngineAsset的现有测试用例。

  1. describe(‘EngineSupplychainSpec’, () => { 
  2.   
  3.    // setup is done in the before and beforeEach hook 
  4.    // results are the bnc (BusinessNetworkConnection), target namespace 
  5.    // as well as test assets, participants and required registries 
  6.    describe('createEngineAsset', () => { 
  7.        it('should create an Engine by submitting a valid EngineCreation transaction', async () => { 
  8.            const factory = bnc.getBusinessNetwork().getFactory() 
  9.   
  10.            const engineCreationTrans = factory.newTransaction(namespace, 'EngineCreation') 
  11.            engineCreationTrans.data = factory.newConcept(namespace, 'EngineProperties') 
  12.            engineCreationTrans.data.brand = 'Audi' 
  13.            engineCreationTrans.data.model = 'Fancy engine model' 
  14.            engineCreationTrans.data.horsePower = 400 
  15.            engineCreationTrans.data.cubicCapacity = 4000 
  16.            engineCreationTrans.data.cylindersAmount = 10 
  17.   
  18.            const manufacturerRegistry = await bnc.getParticipantRegistry(namespace + '.Manufacturer') 
  19.            await manufacturerRegistry.addAll([]) 
  20.            engineCreationTrans.manufacturer = factory.newRelationship(namespace, 'Manufacturer', testManufacturer.$identifier) 
  21.   
  22.            await bnc.submitTransaction(engineCreationTrans) 
  23.   
  24.            const allEngines = await engineRegistry.getAll() 
  25.            allEngines.length.should.equal(2) 
  26.        }) 
  27.    }) 
  28. }) 

(编辑:牡丹江站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读