Skip to content

Commit

Permalink
Merge pull request #204 from dengyi9/master
Browse files Browse the repository at this point in the history
  • Loading branch information
dengyi9 authored Mar 21, 2019
2 parents d54d0d9 + 3325964 commit 9dcf4e8
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 53 deletions.
2 changes: 1 addition & 1 deletion src/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import LoadingLayout from './components/LoadingLayout';

import { getConfigDBSingleton } from './util/createDB';
// import generateYaml from './util/generateYaml';
// import getFabricClientSingleton from './util/fabric';
// import { getFabricClientSingleton } from './util/fabric';


const logger = require('electron-log');
Expand Down
1 change: 1 addition & 0 deletions src/common/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Common.LOGIN_PEER_TLS_CA_CERT = 'Peer TLS CA Cert';
Common.LOGIN_ORDERER_TLS_CA_CERT = 'Orderer TLS CA Cert';
Common.LOGIN_PEER_SSL_TARGET = 'Peer SSL Target';
Common.LOGIN_ORDERER_SSL_TARGET = 'Orderer SSL Target';
Common.LOGIN_CA_SERVER_URL = 'CA Server Url';


Common.WARN = {
Expand Down
1 change: 1 addition & 0 deletions src/common/common_cn.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Common.LOGIN_PEER_TLS_CA_CERT = '组织节点TLS证书';
Common.LOGIN_ORDERER_TLS_CA_CERT = '排序节点TLS证书';
Common.LOGIN_PEER_SSL_TARGET = '组织节点SSL域名';
Common.LOGIN_ORDERER_SSL_TARGET = '排序节点SSL域名';
Common.LOGIN_CA_SERVER_URL = 'CA节点地址';


Common.WARN = {
Expand Down
43 changes: 25 additions & 18 deletions src/components/UserLayout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// TODO: 登录页(秘钥导入页面)
import React from 'react';
import { Button, Input, Layout, Icon, message } from 'antd';
import getFabricClientSingleton from '../util/fabric';
import { getFabricClientSingleton } from '../util/fabric';
import { getConfigDBSingleton } from '../util/createDB';


Expand Down Expand Up @@ -38,6 +38,7 @@ export default class UserLayout extends React.Component {
keylabel: ' choose a private key',
tlsPeerLabel: ' choose a peer tls ca cert',
tlsOrdererLabel: 'choose a orderer tls ca cert',
caServerUrl: 'http://localhost:7054', // TODO: 待实现
Common: localStorage.getItem('language') === 'cn' ? require('../common/common_cn') : require('../common/common'),
};

Expand All @@ -53,6 +54,7 @@ export default class UserLayout extends React.Component {
this.mspidChange = this.mspidChange.bind(this);
this.peerSSLTargetChange = this.peerSSLTargetChange.bind(this);
this.ordererSSLTargetChange = this.ordererSSLTargetChange.bind(this);
this.caServerUrlChange = this.caServerUrlChange.bind(this);
this.changeLangtoEn = this.changeLangtoEn.bind(this);
this.changeLangtoCn = this.changeLangtoCn.bind(this);
}
Expand Down Expand Up @@ -94,6 +96,10 @@ export default class UserLayout extends React.Component {
this.setState({ peerEventUrl: event.target.value });
}

caServerUrlChange(event) {
this.setState({ caServerUrl: event.target.value });
}

cerImport() {
const selectedFile = document.getElementById('cerFiles').files[0];// 获取读取的File对象
this.setState({ certPath: selectedFile.path });
Expand Down Expand Up @@ -310,35 +316,36 @@ export default class UserLayout extends React.Component {

<div style={firstDivStyle}>
<span style={asteriskStyle}>*&nbsp;</span>
<span style={spanStyle}>{this.state.Common.LOGIN_PEER_GRPC_URL}:</span>
<Input type="text" style={InputStyle} value={this.state.peerGrpcUrl} onChange={this.peerGrpcUrlChange} />
</div>
<div style={divStyle}>
<span style={asteriskStyle}>*&nbsp;</span>
<span style={spanStyle}>{this.state.Common.LOGIN_PEER_EVENT_URL}:</span>
<Input type="text" style={InputStyle} value={this.state.peerEventUrl} onChange={this.peerEventUrlChange} />
<span style={spanStyle}>{this.state.Common.LOGIN_CERTIFICATE}:</span>
<input type="file" id="cerFiles" name="cerFiles" style={fileStyle}onChange={this.cerImport} />
<label htmlFor="cerFiles" style={labelStyle} ><Icon type="folder-open" theme="outlined" style={{ color: '#0083FA', padding: '0 7px 0 0' }} />&thinsp;{this.state.certlabel} </label>
</div>
<div style={divStyle}>
<span style={asteriskStyle}>*&nbsp;</span>
<span style={spanStyle}>{this.state.Common.LOGIN_ORDERER_URL}:</span>
<Input type="text" style={InputStyle} value={this.state.ordererUrl} onChange={this.ordererChange} />
<span style={spanStyle}>{this.state.Common.LOGIN_PRIVATE_KEY}:</span>
<input type="file" id="priFiles" name="priFiles" style={fileStyle} onChange={this.priImport} />
<label htmlFor="priFiles" style={labelStyle} ><Icon type="folder-open" theme="outlined" style={{ color: '#0083FA', padding: '0 7px 0 0' }} />&thinsp;{this.state.keylabel}</label>
</div>
<div style={divStyle}>
<span style={asteriskStyle}>*&nbsp;</span>
<span style={spanStyle}>{this.state.Common.LOGIN_MSP_ID}:</span>
<Input type="text" style={InputStyle} value={this.state.mspid} onChange={this.mspidChange} />
</div>
<div style={divStyle}>
<span style={asteriskStyle}>*&nbsp;</span>
<span style={spanStyle}>{this.state.Common.LOGIN_CERTIFICATE}:</span>
<input type="file" id="cerFiles" name="cerFiles" style={fileStyle}onChange={this.cerImport} />
<label htmlFor="cerFiles" style={labelStyle} ><Icon type="folder-open" theme="outlined" style={{ color: '#0083FA', padding: '0 7px 0 0' }} />&thinsp;{this.state.certlabel} </label>
<span style={spanStyle}>&nbsp; {this.state.Common.LOGIN_PEER_GRPC_URL}:</span>
<Input type="text" style={InputStyle} value={this.state.peerGrpcUrl} onChange={this.peerGrpcUrlChange} />
</div>
<div style={divStyle}>
<span style={asteriskStyle}>*&nbsp;</span>
<span style={spanStyle}>{this.state.Common.LOGIN_PRIVATE_KEY}:</span>
<input type="file" id="priFiles" name="priFiles" style={fileStyle} onChange={this.priImport} />
<label htmlFor="priFiles" style={labelStyle} ><Icon type="folder-open" theme="outlined" style={{ color: '#0083FA', padding: '0 7px 0 0' }} />&thinsp;{this.state.keylabel}</label>
<span style={spanStyle}>&nbsp; {this.state.Common.LOGIN_PEER_EVENT_URL}:</span>
<Input type="text" style={InputStyle} value={this.state.peerEventUrl} onChange={this.peerEventUrlChange} />
</div>
<div style={divStyle}>
<span style={spanStyle}>&nbsp; {this.state.Common.LOGIN_ORDERER_URL}:</span>
<Input type="text" style={InputStyle} value={this.state.ordererUrl} onChange={this.ordererChange} />
</div>
<div style={divStyle}>
<span style={spanStyle}>&nbsp; {this.state.Common.LOGIN_CA_SERVER_URL}:</span>
<Input type="text" style={InputStyle} value={this.state.caServerUrl} onChange={this.caServerUrlChange} />
</div>
<div style={divStyle}>
<span style={spanStyle}>&nbsp; {this.state.Common.LOGIN_PEER_TLS_CA_CERT}:</span>
Expand Down
2 changes: 1 addition & 1 deletion src/components/content/ChaincodeInstallContent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import React from 'react';
import { Button, Form, Input, Modal, Menu, Dropdown, Icon, Select, Tag, message } from 'antd';
import getFabricClientSingleton from '../../util/fabric';
import { getFabricClientSingleton } from '../../util/fabric';

const logger = require('electron-log');

Expand Down
2 changes: 1 addition & 1 deletion src/components/content/ChaincodeInvokeContent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import React from 'react';
import { Button, Input, Select, Radio, message, Modal, Icon, Tag, Tooltip } from 'antd';
import getFabricClientSingleton from '../../util/fabric';
import { getFabricClientSingleton } from '../../util/fabric';

const logger = require('electron-log');
const path = require('path');
Expand Down
2 changes: 1 addition & 1 deletion src/components/content/ChannelManangeContent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { Button, message, Input, Icon, Tooltip } from 'antd';
import getFabricClientSingleton from '../../util/fabric';
import { getFabricClientSingleton } from '../../util/fabric';
import { copyDir, copyFile, deleteDir } from '../../util/tools';

const path = require('path');
Expand Down
2 changes: 1 addition & 1 deletion src/components/content/DataContent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import React from 'react';
import { Col, Row, Table, Modal, Select, message } from 'antd';
import { getQueryBlockSingleton, deleteQueryBlockSingleton } from '../../util/queryBlock';
import getFabricClientSingleton from '../../util/fabric';
import { getFabricClientSingleton } from '../../util/fabric';

const logger = require('electron-log');

Expand Down
40 changes: 19 additions & 21 deletions src/util/fabric.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@ class FabricClient {
return new Promise((resolve) => {
logger.info('config:', config);

if (config.tlsPeerPath === '' || config.tlsOrdererPath === '') {
logger.info('+++++++++++++++++');
self.isTlsEnabled = false;
self.peer = fabricClient.newPeer(config.peerGrpcUrl);
self.order = fabricClient.newOrderer(config.ordererUrl);
} else {
logger.info('------------------');
self.peerCert = fs.readFileSync(config.tlsPeerPath);
self.ordererCert = fs.readFileSync(config.tlsOrdererPath);
self.isTlsEnabled = true;
self.peer = fabricClient.newPeer(config.peerGrpcUrl,
{ pem: Buffer.from(this.peerCert).toString(), 'ssl-target-name-override': config.peerSSLTarget });
self.order = fabricClient.newOrderer(config.ordererUrl,
{ pem: Buffer.from(this.ordererCert).toString(), 'ssl-target-name-override': config.ordererSSLTarget });
if (config.peerGrpcUrl) {
if (config.tlsPeerPath === '' || config.tlsOrdererPath === '') {
self.isTlsEnabled = false;
self.peer = fabricClient.newPeer(config.peerGrpcUrl);
self.order = fabricClient.newOrderer(config.ordererUrl);
} else {
self.peerCert = fs.readFileSync(config.tlsPeerPath);
self.ordererCert = fs.readFileSync(config.tlsOrdererPath);
self.isTlsEnabled = true;
self.peer = fabricClient.newPeer(config.peerGrpcUrl,
{ pem: Buffer.from(this.peerCert).toString(), 'ssl-target-name-override': config.peerSSLTarget });
self.order = fabricClient.newOrderer(config.ordererUrl,
{ pem: Buffer.from(this.ordererCert).toString(), 'ssl-target-name-override': config.ordererSSLTarget });
}
}

// TODO: 考虑 ca管理 与 peer管理,分别维护两套用户
Expand Down Expand Up @@ -100,7 +100,6 @@ class FabricClient {
logger.info('almost done');
return self.fabricClient.getUserContext(usrName, true) // FIXME: usernaem和mspid可能要分开
.then((user) => {
logger.info('loginUser: ', user.toString());
self.user = user;
return Promise.resolve(user);
});
Expand Down Expand Up @@ -835,15 +834,14 @@ export function getFabricClientSingletonHelper(dbConfig) {
return Promise.resolve(__fabricClient);
}

// TODO: 考虑是否去除export default,全部使用export。
// 由此保证import无需再区分 import something from 'lib' 与 import {something} from 'lib'

// FabricClient单例模式。后续考虑优化为多套身份,多个client
export default function getFabricClientSingleton() {
export function getFabricClientSingleton() {
return getFabricClientSingletonHelper(db);
}

export function deleteFabricClientSingleton() {
__fabricClient.close();
__fabricClient = null;
if (__fabricClient) {
__fabricClient.close();
__fabricClient = null;
}
}
2 changes: 1 addition & 1 deletion src/util/queryBlock.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2018 The hyperledger-fabric-desktop Authors. All rights reserved.

import { getBlockDBSingleton } from './createDB';
import getFabricClientSingleton from './fabric';
import { getFabricClientSingleton } from './fabric';

const db = getBlockDBSingleton();

Expand Down
5 changes: 5 additions & 0 deletions test/components/content/chaincodeInstallContent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import React from 'react';
import TestUtils from 'react-dom/test-utils';
import ChaincodeInstallContent from '../../../src/components/content/ChaincodeInstallContent.jsx';

// TODO: 待测试内容
// 1. 按钮对 内容显示的影响
// 2. 功能成功后,对显示的影响
// 3. 功能失败后,显示如何处理

// Required: Test if click on `add contract` button,a new modal will be poped up or not.
describe('DOM rendering', () => {
it('Click on add contract button,the contract item should be added.', () => {
Expand Down
13 changes: 11 additions & 2 deletions test/components/userLayout.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function shallowRender(Component) {
}

describe('title', () => {
it('UserLayout\\\'s title should be Fabric Desktop', () => {
it('UserLayout\'s title should be Fabric Desktop', () => {
const userLayout = shallowRender(UserLayout);
expect(userLayout.props.children[1].props.children.props.children[0].type).toBe('div');
expect(userLayout.props.children[1].props.children.props.children[0].props.children.props.children).toBe('Fabric Desktop');
Expand All @@ -18,7 +18,8 @@ describe('title', () => {

describe('Some variable should change with the value of the input box', () => {
const userLayout = TestUtils.renderIntoDocument(<UserLayout />);
const inputItem = TestUtils.scryRenderedDOMComponentsWithTag(userLayout, 'input');
let inputItem = TestUtils.scryRenderedDOMComponentsWithTag(userLayout, 'input');
inputItem = inputItem.slice(1, inputItem.length);

it('peerGrpcUrl', () => {
const input = inputItem[0];
Expand Down Expand Up @@ -67,3 +68,11 @@ describe('Some variable should be the file path selected by the selector', () =>
expect(input.files.path).toBe('/home/hjs/admin/a05e3c5fc2c10dee7f20a2750a4397c456918526284608ca5f7a12eda496e1e1_sk');
});
});

describe('fill inputs by config file', () => {
const userLayout = TestUtils.renderIntoDocument(<UserLayout />);

it('import config file', () => {

});
});
2 changes: 1 addition & 1 deletion test/resources/persistence/config.db
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"id":0,"isSign":1,"_id":"0RYjfGm5ZQNGBcxV","peerGrpcUrl":"grpc://localhost:7051","peerEventUrl":"grpc://localhost:7053","ordererUrl":"grpc://localhost:7050","mspid":"Org1MSP","tlsPeerPath":"","tlsOrdererPath":"","path":"test/resources/key/users/","caServerUrl":"http://localhost:7054"}
{"id":0,"isSign":1,"_id":"0RYjfGm5ZQNGBcxV","peerGrpcUrl":"grpc://localhost:7051","peerEventUrl":"grpc://localhost:7053","ordererUrl":"grpc://localhost:7050","mspid":"Org1MSP","tlsPeerPath":"","tlsOrdererPath":"","path":"test/resources/key/users/","caServerUrl":""}i
9 changes: 4 additions & 5 deletions test/util/fabric.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2019 The hyperledger-fabric-desktop Authors. All rights reserved.
import { getFabricClientSingletonHelper, deleteFabricClientSingleton} from '../../src/util/fabric';
import { getFabricClientSingletonHelper, deleteFabricClientSingleton } from '../../src/util/fabric';

const { execSync } = require('child_process');
const logger = require('electron-log');
Expand Down Expand Up @@ -68,7 +68,6 @@ describe('fabric v1.1 basic-network', () => {

describe('Fabric Client Advanced', () => {
describe('invoke chaincode', () => {
// FIXME: invoke 后测试进程无法正常结束,可能存在连接或其他调用未断开。待查因解决
it('invoke for one peer', () => getFabricClientSingletonHelper(configDbForTest)
.then(client => client.invokeCc('fabcar',
'changeCarOwner',
Expand Down Expand Up @@ -221,7 +220,7 @@ describe('fabric v1.1 basic-network', () => {

describe('fabric CA management', () => {
// TODO: configDbForTest的持久化数据参数,包含admin证书登入过程。 目前由fabricClient类的外部维护,考虑是否内部维护。
// FIXME: 因CA每次重新启动,将重新生成admin证书。所以不能在git中静态存储证书私钥,而需要在测试中动态生成处理。
// FIXME: 待修复register测试失败。因CA每次重新启动,将重新生成admin证书。所以不能在git中静态存储证书私钥,而需要在测试中动态生成处理。
const configDbForCATest = new Datastore({
filename: path.join(__dirname, '../resources/persistence/configCAAdmin.db'),
autoload: true,
Expand Down Expand Up @@ -252,13 +251,13 @@ describe('fabric v1.1 basic-network', () => {
const req = {
enrollmentID: 'admin',
enrollmentSecret: 'adminpw',
// profile: // TODO:
profile: 'tls',
};
throw Error('not implemented');

return getFabricClientSingletonHelper(configDbForCATest)
.then(client => client.enroll(req))
.then((enrollment) => {
logger.info('enroll user TLS cert, get enrollment: ', enrollment);
expect(enrollment).not.toBeNull();
})
.catch((err) => {
Expand Down

0 comments on commit 9dcf4e8

Please sign in to comment.