Skip to content

Commit

Permalink
Metadata generate updated [FABCN-447] (#276)
Browse files Browse the repository at this point in the history
Signed-off-by: Kestutis Gudynas <44440041+kemi04@users.noreply.github.com>
  • Loading branch information
kemi04 authored May 5, 2021
1 parent 2bd68fd commit 556f32a
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 9 deletions.
2 changes: 0 additions & 2 deletions apis/fabric-contract-api/lib/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ class Contract {
} else {
this.name = name.trim();
}

logger.info('Creating new Contract', name);
}

/**
Expand Down
1 change: 0 additions & 1 deletion libraries/fabric-shim/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const results = require('yargs')

if (typeof(results.thePromise) !== 'undefined') {
results.thePromise.then(() => {
logger.info('\nCommand succeeded\n');
}).catch((error) => {
logger.info(error + '\nCommand failed\n');
process.exit(1);
Expand Down
2 changes: 1 addition & 1 deletion libraries/fabric-shim/lib/cmds/metadata/lib/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Generate {
await fs.writeFile(filePath, JSON.stringify(chaincode.metadata, null, 4));
logger.info(`File containing metadata has been saved to ${filePath}`);
} else {
logger.info('Metadata is : \n', JSON.stringify(chaincode.metadata, null, 4));
logger.info(JSON.stringify(chaincode.metadata, null, 4));
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions libraries/fabric-shim/lib/contract-spi/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ class Bootstrap {

if (pathCheck) {
metadata = Bootstrap.loadAndValidateMetadata(metadataPath);
logger.info('Metadata file has been located');
logger.debug('Loaded metadata', metadata);
} else {
logger.info('No metadata file supplied in contract, introspection will generate all the data');
}
return metadata;
}

static noop() {}

static loadAndValidateMetadata(metadataPath) {
const rootPath = path.dirname(__dirname);
Expand All @@ -134,13 +134,12 @@ class Bootstrap {

const metadata = JSON.parse(metadataString);

const ajv = new Ajv({schemaId: 'id'});
const onlyErrors = {log: Bootstrap.noop, warn: Bootstrap.noop, error: console.error}; // eslint-disable-line no-console
const ajv = new Ajv({schemaId: 'id', logger: onlyErrors});
ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json'));
const valid = ajv.validate(JSON.parse(schemaString), metadata);
if (!valid) {
throw new Error('Contract metadata does not match the schema: ' + JSON.stringify(ajv.errors));
} else {
logger.info('Metadata validated against schema correctly');
}
return metadata;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ describe('generate', () => {
sinon.assert.calledOnce(getInfoFromContractStub);
sinon.assert.calledOnce(getMetadataStub);
sinon.assert.calledOnce(infoStub);
infoStub.getCall(0).args.should.deep.equal(['Metadata is : \n', JSON.stringify(
infoStub.getCall(0).args.should.deep.equal([JSON.stringify(
{
info: {
title: 'some title',
Expand Down
5 changes: 5 additions & 0 deletions libraries/fabric-shim/test/unit/contract-spi/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,11 @@ describe('bootstrap.js', () => {
expect(metadata).to.deep.equal(JSON.parse(json));
});

it('Coverage', () => {
const noop = require(path.join(pathToRoot, 'fabric-shim/lib/contract-spi/bootstrap.js')).noop;
noop();
});

});

});

0 comments on commit 556f32a

Please sign in to comment.