Skip to content

Commit

Permalink
[FABN-1396] convert base endorse scenario test
Browse files Browse the repository at this point in the history
- convert js-cucmber endorse sceanrio test
- update typedefs

Change-Id: I1ae84acd4a751a3a1409ce00e60b5951f008b6a6
Signed-off-by: [email protected] <[email protected]>
  • Loading branch information
nklincoln committed Nov 1, 2019
1 parent 463c8ee commit 07c2a18
Show file tree
Hide file tree
Showing 18 changed files with 682 additions and 30 deletions.
19 changes: 4 additions & 15 deletions fabric-ca-client/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
/*
Copyright 2018 IBM All Rights Reserved.
/**
* SPDX-License-Identifier: Apache-2.0
*/

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import { ICryptoSuite, ICryptoKeyStore, IKeyValueStore, User } from "fabric-client";
import { BaseClient } from 'fabric-client/types/base';
Expand All @@ -35,7 +24,7 @@ export = FabricCAServices;

declare namespace FabricCAServices {
export interface TLSOptions {
trustedRoots: Buffer;
trustedRoots: Buffer | string[];
verify: boolean;
}

Expand Down
2 changes: 0 additions & 2 deletions fabric-client/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/**
* Copyright 2017 Kapil Sachdeva All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/

Expand Down
1 change: 1 addition & 0 deletions fabric-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"node": "^8.9.0 || ^10.15.3",
"npm": "^5.5.1 || ^6.4.1"
},
"types": "./types/index.d.ts",
"dependencies": {
"elliptic": "^6.2.3",
"js-sha3": "^0.7.0",
Expand Down
5 changes: 2 additions & 3 deletions fabric-common/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/**
* Copyright 2017 Kapil Sachdeva All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/

Expand Down Expand Up @@ -57,7 +55,7 @@ export interface UserConfig {
export interface ProposalResponse {
errors: Error[],
responses: EndorsementResponse[],
queryResponses: Buffer[]
queryResults: Buffer[]
}

export interface EndorsementResponse {
Expand All @@ -83,6 +81,7 @@ export class User {
public setRoles(roles: string[]): void;
public getAffiliation(): string;
public setAffiliation(affiliation: string): void;
public getEnrollmentSecret() : string;
public getIdentity(): IIdentity;
public getSigningIdentity(): ISigningIdentity;
public setSigningIdentity(signingIdentity: ISigningIdentity): void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
}
},
"files": [
"types/index.d.ts"
"index.d.ts"
],
"formatCodeOptions": {
"indentSize": 4,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"test:protos": "npm run coverage -- 'fabric-protos/test/**/*.{js,ts}",
"test:cucumber": "cucumber-js ./test/scenario/features/*.feature",
"test:ts-cucumber": "cucumber-js ./test/ts-scenario/features/*.feature --require './test/ts-scenario/steps/**/*.ts' --require './test/ts-scenario/support/**/*.ts' --require-module ts-node/register",
"test:ts-cucumber-tagged": "cucumber-js ./test/ts-scenario/features/*.feature --require './test/ts-scenario/steps/**/*.ts' --require './test/ts-scenario/support/**/*.ts' --require-module ts-node/register --tags @discovery",
"test:ts-cucumber-tagged": "cucumber-js ./test/ts-scenario/features/*.feature --require './test/ts-scenario/steps/**/*.ts' --require './test/ts-scenario/support/**/*.ts' --require-module ts-node/register --tags @base_api",
"test:all": "nyc npm run unit-test:all",
"unit-test:all": "npm run unit-test -- 'fabric-common/test/**/*.{js,ts}' && npm run unit-test -- 'fabric-ca-client/test/**/*.{js,ts}' && npm run unit-test -- 'fabric-client/test/**/*.{js,ts}' && npm run unit-test -- 'fabric-network/test/**/*.{js,ts}'",
"unit-test": "mocha --require ts-node/register --exclude 'fabric-client/test/data/**'",
Expand Down
1 change: 0 additions & 1 deletion test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ test
- `fixtures` holds all the configuration files used by the integration and scenario tests
- `integration` contains the integration test suite
- `ts-scenario` contains the typescripts scenario test suite
- `unit` contains the deprecated unit test suite

## Configuring and running Hardware Security Module tests

Expand Down
21 changes: 21 additions & 0 deletions test/ts-scenario/config/Org1.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,27 @@
}
},
"channels":{
"baseapichannel":{
"orderers":[
"orderer.example.com"
],
"peers":{
"peer0.org1.example.com":{
"endorsingPeer":true,
"chaincodeQuery":true,
"ledgerQuery":true,
"eventSource":true
},
"peer0.org2.example.com":{
"endorsingPeer":true,
"chaincodeQuery":false,
"ledgerQuery":true,
"eventSource":false
}
},
"chaincodes":[
]
},
"channelopschannel":{
"orderers":[
"orderer.example.com"
Expand Down
21 changes: 21 additions & 0 deletions test/ts-scenario/config/Org2.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,27 @@
}
},
"channels":{
"baseapichannel":{
"orderers":[
"orderer.example.com"
],
"peers":{
"peer0.org1.example.com":{
"endorsingPeer":true,
"chaincodeQuery":true,
"ledgerQuery":true,
"eventSource":true
},
"peer0.org2.example.com":{
"endorsingPeer":true,
"chaincodeQuery":false,
"ledgerQuery":true,
"eventSource":false
}
},
"chaincodes":[
]
},
"channelopschannel":{
"orderers":[
"orderer.example.com"
Expand Down
21 changes: 21 additions & 0 deletions test/ts-scenario/config/ccp-tls.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,27 @@
}
},
"channels":{
"baseapichannel":{
"orderers":[
"orderer.example.com"
],
"peers":{
"peer0.org1.example.com":{
"endorsingPeer":true,
"chaincodeQuery":true,
"ledgerQuery":true,
"eventSource":true
},
"peer0.org2.example.com":{
"endorsingPeer":true,
"chaincodeQuery":false,
"ledgerQuery":true,
"eventSource":false
}
},
"chaincodes":[
]
},
"channelopschannel":{
"orderers":[
"orderer.example.com"
Expand Down
21 changes: 21 additions & 0 deletions test/ts-scenario/config/ccp.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,27 @@
}
},
"channels":{
"baseapichannel": {
"orderers":[
"orderer.example.com"
],
"peers":{
"peer0.org1.example.com":{
"endorsingPeer":true,
"chaincodeQuery":true,
"ledgerQuery":true,
"eventSource":true
},
"peer0.org2.example.com":{
"endorsingPeer":true,
"chaincodeQuery":false,
"ledgerQuery":true,
"eventSource":false
}
},
"chaincodes":[
]
},
"channelopschannel":{
"orderers":[
"orderer.example.com"
Expand Down
28 changes: 28 additions & 0 deletions test/ts-scenario/features/base_api.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# SPDX-License-Identifier: Apache-2.0
#

@base_api
Feature: Use base API to perform core operations

Background:
Given I place a scenario start message BASE API FEATURE
Given I deploy a tls Fabric network
And I use the cli to create and join the channel named baseapichannel on the deployed network
And I use the cli to deploy a node smart contract named fabcar at version 1.0.0 for all organizations on channel baseapichannel with endorsement policy 1of and arguments ["initLedger"]

Scenario: Using only fabric-base I can propose, endorse and commit a transaction on instantiated node chaincode
Given I have created a client named leon based on information in profile ccp-tls under organization Org1
And I have used the client named leon to create a channel object for the channel named baseapichannel
When I build a new endorsement request named myFirstRequest for smart contract named fabcar with arguments [createCar, 2000, GMC, Savana, grey, Jones] as client leon on channel baseapichannel
And I commit the endorsement request named myFirstRequest as client leon on channel baseapichannel
Then the request named myFirstRequest for client leon has a general result matching "{\"result\":\"SUCCESS\"}"
And the request named myFirstRequest for client leon has a event result matching "{\"result\":\"Commit success\"}"
And the request named myFirstRequest for client leon has a commit result matching "{\"status\":\"SUCCESS\"}"

Scenario: Using only fabric-base I can send a query request to peers and recieve a valid result
Given I have created a client named leon based on information in profile ccp-tls under organization Org1
And I have used the client named leon to create a channel object for the channel named baseapichannel
When I submit a query named myFirstQuery with args [queryCar,CAR0] for contract fabcar as client leon on channel baseapichannel
Then the query named myFirstQuery for client leon has a general result matching "{\"result\":\"SUCCESS\"}"
And the query named myFirstQuery for client leon has a peer0 result matching "{\"color\":\"blue\",\"docType\":\"car\",\"make\":\"Toyota\",\"model\":\"Prius\",\"owner\":\"Tomoko\"}"
43 changes: 43 additions & 0 deletions test/ts-scenario/steps/base_api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* SPDX-License-Identifier: Apache-2.0
*/

'use strict';

import * as BaseUtils from './lib/utility/baseUtils';
import * as ClientHelper from './lib/utility/clientUtils';
import { Constants } from './constants';
import { CommonConnectionProfileHelper } from './lib/utility/commonConnectionProfileHelper';

import * as path from 'path';
import { Given, When, Then } from 'cucumber';

Given(/^I have created a client named (.+?) based on information in profile (.+?) under organization (.+?)$/, { timeout: Constants.HUGE_TIME as number }, async (clientName: string, ccpName: string, userOrg: string) => {

// Get a CCP Helper
const profilePath: string = path.join(__dirname, '../config', ccpName);
const ccp: CommonConnectionProfileHelper = new CommonConnectionProfileHelper(profilePath, true);

// Create the user
await ClientHelper.createAdminClient(clientName, ccp, userOrg);
});

Given(/^I have used the client named (.+?) to create a channel object for the channel named (.+?)$/, { timeout: Constants.HUGE_TIME as number }, async (clientName: string, channelName: string) => {
await ClientHelper.createChannelWithClient(clientName, channelName);
});

When(/^I build a new endorsement request named (.+?) for smart contract named (.+?) with arguments (.+?) as client (.+?) on channel (.+?)$/, { timeout: Constants.HUGE_TIME as number }, async (requestName: string, contractName: string, requestArgs: string, clientName: string, channelName: string) => {
await ClientHelper.buildChannelRequest(requestName, contractName, requestArgs, clientName, channelName);
});

When(/^I commit the endorsement request named (.+?) as client (.+?) on channel (.+?)$/, { timeout: Constants.HUGE_TIME as number }, async (requestName: string, clientName: string, channelName: string) => {
await ClientHelper.commitChannelRequest(requestName, clientName, channelName);
});

When(/^I submit a query named (.+?) with args (.+?) for contract (.+?) as client (.+?) on channel (.+?)$/, { timeout: Constants.HUGE_TIME as number }, async (queryName: string, queryArgs: string, contractName: string, clientName: string, channelName: string) => {
await ClientHelper.submitChannelRequest(clientName, channelName, contractName, queryArgs, queryName);
});

Then(/^the (request|query) named (.+?) for client (.+?) has a (.+?) result matching (.+?)$/, { timeout: Constants.HUGE_TIME as number }, (responseType: string, requestName: string, clientName: string, fieldName: string, expectedResult: string) => {
ClientHelper.validateChannelRequestResponse(clientName, responseType === 'request', requestName, fieldName, expectedResult);
});
18 changes: 14 additions & 4 deletions test/ts-scenario/steps/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

'use strict';

// State store items (just in case you don't want to look at the code)
// - Users Map<userName: string, user: User>

export enum Constants {
// Timeouts and steps
HUGE_TIME = 1200000,
Expand Down Expand Up @@ -52,11 +55,12 @@ export enum Constants {
CLI_VERBOSITY = 'false',
CLI_TIMEOUT = '120s',

// Constants for network model actions
WALLET = 'WALLET', // StateStore key to retrieve a wallet that contains users
GATEWAYS = 'GATEWAYS', // StateStore key to retrieve a Map(gatewayName, Gateway) of gateways that may be re-used
// State store items
WALLET = 'WALLET', // StateStore key to retrieve a wallet that contains users
GATEWAYS = 'GATEWAYS', // StateStore key to retrieve a Map<gatewayName: string, GatewayObject> of gateways that may be re-used
LISTENERS = 'LISTENERS',
TRANSACTIONS = 'TRANSACTIONS',
CLIENTS = 'CLIENTS', // Map<clientName: string, { client: Client, user: User, ccp: CommonConnectionProfileHelper, clientOrg: string, channels: Map<channelName: string, channel: Channel> } >

// Wallet types
MEMORY_WALLET = 'memory',
Expand Down Expand Up @@ -88,6 +92,12 @@ export enum Constants {

// CLI Policies
ENDORSEMENT_POLICY_1OF_ANY = '"OR (\'Org1MSP.member\',\'Org2MSP.member\')"',
ENDORSEMENT_POLICY_2OF_ANY = '"AND (\'Org1MSP.member\',\'Org2MSP.member\')"'
ENDORSEMENT_POLICY_2OF_ANY = '"AND (\'Org1MSP.member\',\'Org2MSP.member\')"',

// Admin name
ADMIN_NAME = 'admin',
ADMIN_PW = 'adminpw',

// Default Naming
EVENT_HUB_DEFAULT_NAME = 'myHub',
}
3 changes: 2 additions & 1 deletion test/ts-scenario/steps/lib/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,8 @@ export function getLastTransactionResult(gatewayName: string): any {
/**
* Compare the last gateway transaction response with a passed value
* @param {String} gatewayName the gateway to get the response from
* @param {*} msg the message to compare against
* @param {String} msg the message to compare against
* @param {boolean} exactMatch boolean flag to indicate if an exact match is being performed
*/
export function lastTransactionResponseCompare(gatewayName: string, msg: string, exactMatch: boolean): boolean {
const gatewayObj: any = getGatewayObject(gatewayName);
Expand Down
Loading

0 comments on commit 07c2a18

Please sign in to comment.