test('\n\n** CryptoKeyStore tests - couchdb based store tests - use constructor argument **\n\n', function(t) {
	var couchdb = CouchdbMock.createServer();
	couchdb.listen(5985);

	// override t.end function so it'll always disconnect the event hub
	t.end = ((context, mockdb, f) => {
		return function() {
			if (mockdb) {
				console.log('Disconnecting the mock couchdb server');
				mockdb.close();
			}

			f.apply(context, arguments);
		};
	})(t, couchdb, t.end);

	CKS(CouchDBKeyValueStore, {name: dbname, url: 'http://localhost:5985'})
	.then((store) => {
		return testKeyStore(store, t);
	}).catch((err) => {
		t.fail(err.stack ? err.stack : err);
		t.end();
	}).then(() => {
		t.end();
	});
});
test('\n\n** CryptoKeyStore tests **\n\n', function(t) {
	testutil.resetDefaults();

	var keystorePath = path.join(testutil.getTempDir(), 'crypto-key-store');

	t.throws(
		() => {
			CKS();
		},
		/Must provide the path to the directory to hold files for the store/,
		'Test invalid constructor calls: missing options parameter'
	);

	t.throws(
		() => {
			CKS({something: 'useless'});
		},
		/Must provide the path to the directory to hold files for the store/,
		'Test invalid constructor calls: missing "path" property in the "options" parameter'
	);

	var store;
	CKS({path: keystorePath})
	.then((st) => {
		store = st;
		return store.putKey(testPrivKey);
	}).then((keyPEM) => {
		t.pass('Successfully saved private key in store');

		t.equal(fs.existsSync(path.join(keystorePath, testPrivKey.getSKI() + '-priv')), true,
			'Check that the private key has been saved with the proper <SKI>-priv index');

		return store.getKey(testPrivKey.getSKI());
	}).then((recoveredKey) => {
		t.notEqual(recoveredKey, null, 'Successfully read private key from store using SKI');
		t.equal(recoveredKey.isPrivate(), true, 'Test if the recovered key is a private key');

		return store.putKey(testPubKey);
	}).then((keyPEM) => {
		t.equal(fs.existsSync(path.join(keystorePath, testPrivKey.getSKI() + '-pub')), true,
			'Check that the public key has been saved with the proper <SKI>-pub index');

		return store.getKey(testPubKey.getSKI());
	}).then((recoveredKey) => {
		t.notEqual(recoveredKey, null, 'Successfully read public key from store using SKI');
		t.equal(recoveredKey.isPrivate(), true, 'Test if the recovered key is a private key');

		// delete the private key entry and test if getKey() would return the public key
		fs.unlinkSync(path.join(keystorePath, testPrivKey.getSKI() + '-priv'));
		return store.getKey(testPubKey.getSKI());
	}).then((recoveredKey) => {
		t.notEqual(recoveredKey, null, 'Successfully read public key from store using SKI');
		t.equal(recoveredKey.isPrivate(), false, 'Test if the recovered key is a public key');
		t.end();
	}).catch((err) => {
		t.fail(err.stack ? err.stack : err);
		t.end();
	});
});
 async login() {
   try {
     await this._client.setStateStore(await CKS(CouchDBKeyValueStore, {
       name: this._peerConfig.stateDBName,
       url: this._peerConfig.stateDBUrl
     }));
     var crypto_suite = hfc.newCryptoSuite();
     var crypto_store = hfc.newCryptoKeyStore(CouchDBKeyValueStore, {
       name: this._peerConfig.userKeystoreDBName,
       url: this._peerConfig.userKeystoreDBUrl
     });
     crypto_suite.setCryptoKeyStore(crypto_store);
     var client_crypto_suite = hfc.newCryptoSuite();
     var client_crypto_store = hfc.newCryptoKeyStore(CouchDBKeyValueStore, {
       name: this._peerConfig.userKeystoreDBName,
       url: this._peerConfig.userKeystoreDBUrl
     });
     client_crypto_suite.setCryptoKeyStore(client_crypto_store);
     this._client.setCryptoSuite(client_crypto_suite);
     this._ca = await new CAClient(this._caConfig.url, {
       trustedRoots: [],
       verify: false
     }, this._caConfig.caName, crypto_suite);
     console.log("CA registration complete ");
     this._adminUser = await enrollUser(this._client, "admin", "adminpw", this._ca, {
       mspId: this._caConfig.mspId,
       adminUser: null,
       affiliationOrg: this._peerConfig.org,
       noOfAttempts: 5
     });
     //await this._client.setUserContext(this._adminUser);
     //await this.createOrgAdmin();
   } catch(e) {
     console.log(`Failed to enroll user. Error: ${e.message}`);
     throw e;
   }
 }
		() => {
			CKS({something: 'useless'});
		},