I test ctx.stub.createCompositeKey(objectType, attributes) ,but return undefined. I coded according to the requirements of the document, but it still can't be used normally.
my package.json
{
"name": "vppcc",
"version": "0.0.1",
"description": "My Smart Contract",
"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": "John Doe",
"license": "Apache-2.0",
"dependencies": {
"fabric-contract-api": "^2.2.0",
"fabric-shim": "^2.2.0"
},
"devDependencies": {
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"eslint": "^6.8.0",
"mocha": "^7.1.1",
"nyc": "^15.0.0",
"sinon": "^9.0.1",
"sinon-chai": "^3.5.0",
"winston": "^3.2.1"
},
"nyc": {
"exclude": [
".eslintrc.js",
"coverage/**",
"test/**"
],
"reporter": [
"text-summary",
"html"
],
"all": true,
"check-coverage": true,
"statements": 100,
"branches": 100,
"functions": 100,
"lines": 100
}
}
'use strict';
const { ChaincodeStub, ClientIdentity } = require('fabric-shim');
const { VppccContract } = require('..');
const winston = require('winston');
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
const sinon = require('sinon');
const sinonChai = require('sinon-chai');
chai.should();
chai.use(chaiAsPromised);
chai.use(sinonChai);
class TestContext {
constructor() {
this.stub = sinon.createStubInstance(ChaincodeStub);
this.clientIdentity = sinon.createStubInstance(ClientIdentity);
this.logger = {
getLogger: sinon.stub().returns(sinon.createStubInstance(winston.createLogger().constructor)),
setLevel: sinon.stub(),
};
}
}
describe('VppccContract', () => {
let contract;
let ctx;
beforeEach(() => {
contract = new VppccContract();
ctx = new TestContext();
ctx.stub.getState.withArgs('1001').resolves(Buffer.from('{"value":"vppcc 1001 value"}'));
ctx.stub.getState.withArgs('1002').resolves(Buffer.from('{"value":"vppcc 1002 value"}'));
});
describe('#vppccExists', () => {
it('should return true for a vppcc', async () => {
await contract.vppccExists(ctx, '1001').should.eventually.be.true;
});
it('should return false for a vppcc that does not exist', async () => {
await contract.vppccExists(ctx, '1003').should.eventually.be.false;
});
console.log('ctx.stub.createCompositeKey return value:', ctx.stub.createCompositeKey('test', ['1001']));
});
});
ctx.stub.createCompositeKey return value: undefined
let colorNameIndexKey = await ctx.stub.createCompositeKey(indexName, [asset.color, asset.assetID]);