Skip to content

Commit

Permalink
FABN-1496 NodeSDK use fabric-shim 2.0.0 (#133)
Browse files Browse the repository at this point in the history
Update tests to use fabric-shim 2.0.0.

Signed-off-by: Bret Harrison <[email protected]>
  • Loading branch information
harrisob authored Feb 18, 2020
1 parent c66e1ed commit 45cf6f5
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 25 deletions.
2 changes: 1 addition & 1 deletion test/fixtures/chaincode/node_cc/example_cc/chaincode.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ const Chaincode = class {
transientMap.forEach((value, key) => {
result[key] = value.toString('utf8');
});
const payload = Buffer.from(JSON.stringify(result));
const payload = Buffer.from(result);
return shim.success(payload);
}

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/chaincode/node_cc/example_cc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"author": "",
"license": "Apache-2.0",
"dependencies": {
"fabric-shim": "unstable"
"fabric-shim": "^2.0.0"
}
}
4 changes: 2 additions & 2 deletions test/scenario/chaincode/fabcar/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"author": "Hyperledger",
"license": "Apache-2.0",
"dependencies": {
"fabric-contract-api": "unstable",
"fabric-shim": "unstable"
"fabric-contract-api": "^2.0.0",
"fabric-shim": "^2.0.0"
},
"devDependencies": {
"chai": "^4.1.2",
Expand Down
4 changes: 2 additions & 2 deletions test/scenario/features/steps/base_steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -925,8 +925,8 @@ module.exports = function () {
testUtil.logMsg(format('\n\n%s - Successfully endorsed with transient data\n', step));
for (const endorsement_result of endorse_results.responses) {
const transient_return = endorsement_result.response.payload.toString('utf8');
if (transient_return === '"extra info"') {
testUtil.logMsg('Successfully returned transient data');
if (transient_return === 'extra info') {
testUtil.logMsg('Successfully returned transient data as sent');
} else {
throw Error('Failed - Transient data was not handled correctly we got back ==>' + transient_return + '<==');
}
Expand Down
4 changes: 2 additions & 2 deletions test/ts-fixtures/chaincode/node/events/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"engine-strict": true,
"license": "Apache-2.0",
"dependencies": {
"fabric-contract-api": "unstable",
"fabric-shim": "unstable"
"fabric-contract-api": "^2.0.0",
"fabric-shim": "^2.0.0"
}
}
4 changes: 2 additions & 2 deletions test/ts-fixtures/chaincode/node/fabcar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"author": "Hyperledger",
"license": "Apache-2.0",
"dependencies": {
"fabric-contract-api": "unstable",
"fabric-shim": "unstable"
"fabric-contract-api": "^2.0.0",
"fabric-shim": "^2.0.0"
},
"devDependencies": {
"chai": "^4.1.2",
Expand Down
4 changes: 2 additions & 2 deletions test/ts-fixtures/chaincode/node/fabcarUpgrade/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"author": "Hyperledger",
"license": "Apache-2.0",
"dependencies": {
"fabric-contract-api": "unstable",
"fabric-shim": "unstable"
"fabric-contract-api": "^2.0.0",
"fabric-shim": "^2.0.0"
},
"devDependencies": {
"chai": "^4.1.2",
Expand Down
2 changes: 1 addition & 1 deletion test/ts-fixtures/chaincode/node/legacyNode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"author": "",
"license": "Apache-2.0",
"dependencies": {
"fabric-shim": "unstable"
"fabric-shim": "^2.0.0"
}
}
10 changes: 5 additions & 5 deletions test/ts-scenario/features/base_api.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ Scenario: Using only fabric-base I can propose, endorse and commit a transaction
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\"}"
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\"}"
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"}
17 changes: 13 additions & 4 deletions test/ts-scenario/steps/lib/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export async function performGatewayTransaction(gatewayName: string, contractNam
BaseUtils.logMsg(`Successfully submitted transaction [${func}] with result [${result}]`);
// some functions do not return anything
if (result.length > 0) {
gatewayObj.result = {type: 'submit', response: JSON.parse(result)};
gatewayObj.result = {type: 'submit', response: result};
} else {
gatewayObj.result = {type: 'submit', response: ''};
}
Expand All @@ -240,7 +240,7 @@ export async function performGatewayTransaction(gatewayName: string, contractNam
const resultBuffer: Buffer = await contract.evaluateTransaction(func, ...funcArgs);
const result: string = resultBuffer.toString('utf8');
BaseUtils.logMsg(`Successfully evaluated transaction [${func}] with result [${result}]`);
gatewayObj.result = {type: 'evaluate', response: JSON.parse(result)};
gatewayObj.result = {type: 'evaluate', response: result};
}
} catch (err) {
gatewayObj.result = {type: 'error', response: err.toString()};
Expand Down Expand Up @@ -501,10 +501,19 @@ export function getLastTransactionResult(gatewayName: string): any {
export function lastTransactionResponseCompare(gatewayName: string, msg: string, exactMatch: boolean): boolean {
const gatewayObj: any = getGatewayObject(gatewayName);

let result: string;
if (typeof gatewayObj.result.response === 'string') {
result = gatewayObj.result.response;
} else { // must be and object
result = JSON.stringify(gatewayObj.result.response);
}

BaseUtils.logMsg(`Comparing gatewayObj.result.response ${result} to msg ${msg}`);

if (exactMatch) {
return (gatewayObj.result.response.localeCompare(msg) === 0);
return (result.localeCompare(msg) === 0);
} else {
return gatewayObj.result.response.includes(msg);
return result.includes(msg);
}
}

Expand Down
21 changes: 18 additions & 3 deletions test/ts-scenario/steps/lib/utility/clientUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,13 +492,28 @@ export function validateChannelRequestResponse(clientName: string, isRequest: bo
}

if (results) {
const actualResult: string = results[fieldName];
const isMatch: boolean = (actualResult.localeCompare(JSON.parse(expectedResult)) === 0);
const savedResult: any = results[fieldName];
BaseUtils.logMsg(`clientUtils - raw results of query = ${savedResult}`);

let stringResult: string;
if (savedResult instanceof Buffer) {
stringResult = savedResult.toString('utf8');
BaseUtils.logMsg(`clientUtils - results of query was a Buffer = ${stringResult}`);
} else if (typeof savedResult === 'string') {
stringResult = savedResult.toString();
BaseUtils.logMsg(`clientUtils - results of query was a string = ${stringResult}`);
} else { // must be an object
stringResult = JSON.stringify(savedResult);
BaseUtils.logMsg(`clientUtils - results of query was a object = ${stringResult}`);
}

const isMatch: boolean = (stringResult.localeCompare(expectedResult) === 0);
if (isMatch) {
BaseUtils.logMsg(`Validated response ${requestName} of type ${fieldName}`, {});
} else {
BaseUtils.logAndThrow(`Unexpected response for ${requestName} and type ${fieldName}. Expected ${expectedResult} but had ${actualResult}`);
BaseUtils.logAndThrow(`Unexpected response for ${requestName} and type ${fieldName}. Expected ${expectedResult} but had ${stringResult}`);
}

} else {
BaseUtils.logAndThrow(`Response for ${requestName} does not have a results object for validation`);
}
Expand Down

0 comments on commit 45cf6f5

Please sign in to comment.