-
Notifications
You must be signed in to change notification settings - Fork 515
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FABN-1397] add ts-cucumber test suite
New typescript based sceanrio test suite that: - uses CLI to create/join channels - replaces javascript 'network feature' - replaces javascript 'gateway feature' Change-Id: If4cd589afc0c81bef13d3e4a330e8c8d8159a076 Signed-off-by: [email protected] <[email protected]>
- Loading branch information
Showing
51 changed files
with
4,598 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const FabCar = require('./lib/fabcar'); | ||
|
||
module.exports.FabCar = FabCar; | ||
module.exports.contracts = [FabCar]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const {Contract} = require('fabric-contract-api'); | ||
|
||
class FabCar extends Contract { | ||
|
||
async initLedger(ctx) { | ||
console.info('============= START : Initialize Ledger ==========='); // eslint-disable-line | ||
const cars = [ | ||
{ | ||
color: 'blue', | ||
make: 'Toyota', | ||
model: 'Prius', | ||
owner: 'Tomoko', | ||
}, | ||
{ | ||
color: 'red', | ||
make: 'Ford', | ||
model: 'Mustang', | ||
owner: 'Brad', | ||
}, | ||
{ | ||
color: 'green', | ||
make: 'Hyundai', | ||
model: 'Tucson', | ||
owner: 'Jin Soo', | ||
}, | ||
{ | ||
color: 'yellow', | ||
make: 'Volkswagen', | ||
model: 'Passat', | ||
owner: 'Max', | ||
}, | ||
{ | ||
color: 'black', | ||
make: 'Tesla', | ||
model: 'S', | ||
owner: 'Adriana', | ||
}, | ||
{ | ||
color: 'purple', | ||
make: 'Peugeot', | ||
model: '205', | ||
owner: 'Michel', | ||
}, | ||
{ | ||
color: 'white', | ||
make: 'Chery', | ||
model: 'S22L', | ||
owner: 'Aarav', | ||
}, | ||
{ | ||
color: 'violet', | ||
make: 'Fiat', | ||
model: 'Punto', | ||
owner: 'Pari', | ||
}, | ||
{ | ||
color: 'indigo', | ||
make: 'Tata', | ||
model: 'Nano', | ||
owner: 'Valeria', | ||
}, | ||
{ | ||
color: 'brown', | ||
make: 'Holden', | ||
model: 'Barina', | ||
owner: 'Shotaro', | ||
}, | ||
]; | ||
|
||
for (let i = 0; i < cars.length; i++) { | ||
cars[i].docType = 'car'; | ||
await ctx.stub.putState('CAR' + i, Buffer.from(JSON.stringify(cars[i]))); | ||
console.info('Added <--> ', cars[i]); // eslint-disable-line | ||
} | ||
console.info('============= END : Initialize Ledger ==========='); // eslint-disable-line | ||
} | ||
|
||
async queryCar(ctx, carNumber) { | ||
const carAsBytes = await ctx.stub.getState(carNumber); // get the car from chaincode state | ||
if (!carAsBytes || carAsBytes.length === 0) { | ||
throw new Error(`${carNumber} does not exist`); | ||
} | ||
console.log(carAsBytes.toString()); // eslint-disable-line | ||
return carAsBytes.toString(); | ||
} | ||
|
||
async createCar(ctx, carNumber, make, model, color, owner) { | ||
console.info('============= START : Create Car ==========='); // eslint-disable-line | ||
|
||
const car = { | ||
color, | ||
docType: 'car', | ||
make, | ||
model, | ||
owner, | ||
}; | ||
|
||
await ctx.stub.putState(carNumber, Buffer.from(JSON.stringify(car))); | ||
console.info('============= END : Create Car ==========='); // eslint-disable-line | ||
} | ||
|
||
async queryAllCars(ctx) { | ||
const startKey = 'CAR0'; | ||
const endKey = 'CAR999'; | ||
|
||
const iterator = await ctx.stub.getStateByRange(startKey, endKey); | ||
|
||
const allResults = []; | ||
let collect = true; | ||
while (collect) { | ||
const res = await iterator.next(); | ||
|
||
if (res.value && res.value.value.toString()) { | ||
|
||
const Key = res.value.key; | ||
let Record; | ||
try { | ||
Record = JSON.parse(res.value.value.toString('utf8')); | ||
} catch (err) { | ||
console.log(err); // eslint-disable-line | ||
Record = res.value.value.toString('utf8'); | ||
} | ||
allResults.push({Key, Record}); | ||
} | ||
if (res.done) { | ||
await iterator.close(); | ||
collect = false; | ||
} | ||
} | ||
return JSON.stringify(allResults); | ||
} | ||
|
||
async changeCarOwner(ctx, carNumber, newOwner) { | ||
console.info('============= START : changeCarOwner ==========='); // eslint-disable-line | ||
|
||
const carAsBytes = await ctx.stub.getState(carNumber); // get the car from chaincode state | ||
if (!carAsBytes || carAsBytes.length === 0) { | ||
throw new Error(`${carNumber} does not exist`); | ||
} | ||
const car = JSON.parse(carAsBytes.toString()); | ||
car.owner = newOwner; | ||
|
||
await ctx.stub.putState(carNumber, Buffer.from(JSON.stringify(car))); | ||
console.info('============= END : changeCarOwner ==========='); // eslint-disable-line | ||
} | ||
|
||
} | ||
|
||
module.exports = FabCar; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"name": "fabcar", | ||
"version": "1.0.0", | ||
"description": "FabCar contract implemented in JavaScript", | ||
"main": "index.js", | ||
"engines": { | ||
"node": ">=8", | ||
"npm": ">=5" | ||
}, | ||
"scripts": { | ||
"lint": "eslint .", | ||
"pretest": "npm run lint", | ||
"test": "nyc mocha --recursive", | ||
"start": "fabric-chaincode-node start" | ||
}, | ||
"engineStrict": true, | ||
"author": "Hyperledger", | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"fabric-contract-api": "unstable", | ||
"fabric-shim": "unstable" | ||
}, | ||
"devDependencies": { | ||
"chai": "^4.1.2", | ||
"eslint": "^4.19.1", | ||
"mocha": "^5.2.0", | ||
"nyc": "^12.0.2", | ||
"sinon": "^6.0.0", | ||
"sinon-chai": "^3.2.0" | ||
}, | ||
"nyc": { | ||
"exclude": [ | ||
"coverage/**", | ||
"test/**" | ||
], | ||
"reporter": [ | ||
"text-summary", | ||
"html" | ||
], | ||
"all": true, | ||
"check-coverage": true, | ||
"statements": 100, | ||
"branches": 100, | ||
"functions": 100, | ||
"lines": 100 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const FabCar = require('./lib/fabcar'); | ||
|
||
module.exports.FabCar = FabCar; | ||
module.exports.contracts = [FabCar]; |
Oops, something went wrong.