You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.
const{ idManager }=require('../public-channel/identity-manager/index');const{ ChaincodeMockStub, Transform }=require("@theledger/fabric-mock-stub");constidentityManager=newidManager();describe('Init chaincode',()=>{it("Should init idManager without issues",async()=>{constmockStub=newChaincodeMockStub("MyMockStub",identityManager);constresponse=awaitmockStub.mockInit("tx1",[]);expect(response.status).to.eql(200)// Your test code});
chaincode
constshim=require('fabric-shim');consterrorCodes={unknownFunction: "ERR1",incorrectNumberOfArgs: "ERR2",noRight: "ERR3",companyDiffers: "ERR4",invokeChaincodeFailed: "ERR5",queryStateNotFound: "ERR6",accessListIncorrect: "ERR7",chaincodeInitAlreadyDone: "ERR8",keyDoesNotExist: "ERR9",identityAlreadyExists: "ERR10"}varChaincode=class{/** * Function invoked during chaincode instantiation * @constructor * @param {stub} stub - The chaincode API interface * @return {Buffer} returns data as buffer */Init(stub){returnshim.success();}/** * This function is the entry point of the chaincode. EVERY function invokation will start here * @function Invoke * @param {stub} stub - The chaincode API interface * @return {Buffer} returns data as buffer */asyncInvoke(stub){letret=stub.getFunctionAndParameters();console.info(ret);letmethod=this[ret.fcn];if(!method){console.error('no function of name:'+ret.fcn+' found');thrownewError(errorCodes.incorrectNumberOfArgs);}try{letpayload=awaitmethod(stub,ret.params);returnshim.success(payload);}catch(err){console.info(err);returnshim.error(err);}}/** * Creates an identity in the identity-manager world state * @function createIdentity * @param {stub} stub - The chaincode API interface * @param {Array} args - The ID of the identity to create | The ID of the identity of the creator | The first name of the identity holder | The last name of the identity holder | The company if the identity holder | The status of the identity to create | The role of the identity to create | The email of the identity to create */asynccreateIdentity(stub,args){console.info('============= START : Create Identity ===========');if(args.length!=8){thrownewError(errorCodes.incorrectNumberOfArgs);}try{//Check if identity exists. If it does, cannot create itvaridentityToCreateAsBytes=awaitstub.getState(args[0]);if(identityToCreateAsBytes.length){console.log("Identity already exist");thrownewError(errorCodes.identityAlreadyExists);}varidentityCreatorAsBytes=awaitstub.getState(args[1]);varidentityCreatorAsJson=JSON.parse(identityCreatorAsBytes);// Only chain.administrator can create another chain.administratorif(args[6]==="chain.administrator"&&identityCreatorAsJson.role!=="chain.administrator"){console.error("Only chain administrator can create a chain administrator identity");thrownewError(errorCodes.noRight);}// checks the role of the identity creatorif(identityCreatorAsJson.role!=="org.administrator"&&identityCreatorAsJson.role!=="chain.administrator"){console.error("Identity creator does not have rights to create this new identity");thrownewError(errorCodes.noRight);}// checks the company of the identity creator and createdif(identityCreatorAsJson.company!==args[4]){console.error("The company of the creator differs from the new identity company")thrownewError(errorCodes.companyDiffers);}varidentity={"providerId": args[1],"firstName": args[2],"lastName": args[3],"company": args[4],"status": args[5],"role": args[6],"email": args[7]}vareventData={"identityId": args[0],"providerId": args[1],"company": args[4]};stub.setEvent("createIdentity",Buffer.from(JSON.stringify(eventData)));awaitstub.putState(args[0],Buffer.from(JSON.stringify(identity)));console.info('============= END : Create Identity ===========');identity['id']=args[0];returnBuffer.from(JSON.stringify(identity));}catch(error){thrownewError(error);}}//many other functionsshim.start(newChaincode());
The text was updated successfully, but these errors were encountered:
shim.start may not be called in a node context, only when running from a peer. When writing your tests, please make sure shim.start and your chaincode are in a seperate file.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Error
When running
node test.js
, obtains the following error: gistMain message:
Configuration
Yarn
package.json
test.js
chaincode
The text was updated successfully, but these errors were encountered: