This blog post is based on the content of episode If you want to get a more in depth explanation, checkout the episode. CDOH #12 Mock user generation Testing your smart contracts has been always a top priority for the Convector Core development team, and because of that, this week we released some interesting features improving the capabilities for managing the identities for unit-testing. Starting with the will generate certificates for you, so you can use multiple identities to emulate correctly the identities pattern for example. Identity is a critical part of every chaincode and thus it needs to be very well tested and make sure your business logic is the one you expect it to be. Convector v1.3.6 MockControllerAdapter adapter = MockControllerAdapter(); participantCtrl = ClientFactory(ParticipantController, adapter); adapter.init([...]); adapter.addUser( ); participantModel = Participant({ id: uuid(), name: }); participantCtrl.$withUser( ).register(participantModel); savedModel = Participant.getOne(participantModel.id); expect(savedModel.identity) .to.eq(adapter.getUserFingerprint( )) // Create the mock controller adapter const new // Create the participant client const // Initialize the adapter with all the controllers await // Register an user 'MyUser1' // Create the participant model const new 'Diego' // Invoke a function using the corresponding username await 'MyUser1' // Retrieve the participant from network const await // Compare the identity assigned in the controller using `this.sender`... // ... with the fingerprint of the mocked user 'MyUser1' Two new methods in the which will generate the credentials for the mock engine to use a custom certificate. This will cause that to be different in the controllers, it will now be the fingerprint of the fake user. If you call it will then use the custom certificate you provide, this may be useful if you want to use an existing identity with attributes on it. MockControllerAdapter, addUser('username') this.sender addUser('username', 'certificate') There's also which returns the fingerprint for the specified user, previously registered. This is useful for when you want to make assertions about the assigned identity in a model, of if you're using fingerprints for parameters. adapter.getUserFingerprint('username') The helper is available in the ControllerClient. You can know more about it in the episode $withUser('username') CDOH #10 End-to-end test by default The now creates the unit-test files using a fake user with the methods shown above. It will also create E2E tests by default for each chaincode. You can use these tests to test agains Hurley. So in the tests folder you'll find a file, but now also a file, using a , instead of a . This will be configured to send the transactions to Hurley, but you can change the target to whatever Fabric Network you have. CLI v1.1.6 controller.spec.ts controller.e2e.ts FabricControllerAdapter MockControllerAdapter You can also have the ability to change the user with and it will use the user1 from the current organization specified in the adapter for current client. You can create multiple , one for each organization, and change the adapter used for each client doing $withUser('user1') FabricControllerAdapters controllerCient.adapter = adapterForCovalent Network configuration file On we now have the ability to start the network based on a configuration file. This is for advanced use cases of where you need to change the channel name, the user names, or the organization names. Create a JSON file at the root of your project and pass it as an argument to with Hurley v1.1.0 Hurley Hurley hurl new -n hurley.json { : [ , ], : { : { : [ ], : [ , ] }, : { : [ , ], : [ ] }, : { : [ , ], : [ ] } } } "channels" "public" "private" "topology" "hyperledger" "channels" "public" "users" "john" "mike" "covalent" "channels" "public" "private" "users" "diego" "linux" "channels" "public" "private" "users" "henry" If you do this, you'll need to specify the channel and one of the organizations when installing, upgrading, and invoking the chaincode. -C public -o covalent Special thanks to for the configuration file changes for Hurley. We really appreciate that. J3SR0 contributing Quick tip: how to get a fingerprint of any given user { ..., : { ..., : , } } "scripts" "user:fingerprint" "f () { node -e \"const homedir = require('os').homedir(); console.log(JSON.parse(require('fs').readFileSync('/'+homedir+'/hyperledger-fabric-network/.hfc-$2/$1', 'utf8')).enrollment.identity.certificate)\" | openssl x509 -fingerprint -noout | cut -d '=' -f2 ; }; f" Copy a function like that into your file, and you'll be able to run it with something like to read one of Hurley users. package.json npm run user:fingerprint -- user1 org1 We hope convector helps you design really valuable code for your applications. Our objective is for the developer to have all the necessary tools to create bug-free smart contracts or to reduce the risk to the minimum. If you're working with Convector, and let us know what you're building with it. We will be happy to assist you if you're having any problems. join the community