Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extracts identities from a wallet and stores in the in memory wallet #1051

Closed
wants to merge 4 commits into from

Conversation

RosieMurphy0
Copy link
Contributor

Signed-off-by: RosieMurphy0 [email protected]

Implemented the _extractIdentitiesFromWallet method in the identity manager and the associated tests for the method. Takes identities from a wallet and stores them in the in memory wallet using an existing method.

contributes to #940

@@ -184,7 +184,14 @@ class IdentityManager {
* @private
*/
async _extractIdentitiesFromWallet(mspId, wallet) {
// TODO: To be implemented
const walletFacade = await this.walletFacadeFactory.create(wallet.path);
const allIDNames = await walletFacade.getAllIdentityNames();
Copy link
Contributor

@davidkel davidkel Oct 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allIDNames --> allIdentityNames for this line and the next line

// TODO: To be implemented
const walletFacade = await this.walletFacadeFactory.create(wallet.path);
const allIDNames = await walletFacade.getAllIdentityNames();
for (const identityNames in allIDNames){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

identityNames --> identityName

const allIDNames = await walletFacade.getAllIdentityNames();
for (const identityNames in allIDNames){
const identity = await walletFacade.export(identityNames);
if (identity){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can remove this check as we should expect something to be returned as the wallet has given the list of all available identity names

const walletFacade = await this.walletFacadeFactory.create(wallet.path);
const allIDNames = await walletFacade.getAllIdentityNames();
for (const identityNames in allIDNames){
const identity = await walletFacade.export(identityNames);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

identityNames --> identityName

@@ -386,4 +405,56 @@ describe('An Identity Manager', () => {
const identityManager = await identityManagerFactory.create(stubWalletFacadeFactory, [org1MSP, org2MSP]);
await identityManager.getWallet().should.equal('IamAwallet');
});

describe('when extracting identities from a specific wallet and store in the in memory wallet', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can just say when extracting identities from a specific wallet


describe('when extracting identities from a specific wallet and store in the in memory wallet', () => {

it('if not identities available should not add anything to wallet', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should not add anything to the wallet when no identities are available

const stubWalletFacadeFactory = sinon.createStubInstance(IWalletFacadeFactory);
const spyWalletFacade = sinon.createStubInstance(IWalletFacade);
stubWalletFacadeFactory.create.resolves(spyWalletFacade);
spyWalletFacade.getAllIdentityNames.resolves([]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a spy, it's a stub

const identityManagerFactory = new IdentityManagerFactory();

const identityManager = await identityManagerFactory.create(stubWalletFacadeFactory, [org4MSP]);
await identityManager._extractIdentitiesFromWallet(org4MSP, spyWalletFacade);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately the _ indicates a private method so the tests should not be calling that method directly but it should be driven through the use of appropriate external configurations.

const identityManagerFactory = new IdentityManagerFactory();

const identityManager = await identityManagerFactory.create(stubWalletFacadeFactory, [org4MSP]);
await identityManager._extractIdentitiesFromWallet(org4MSP, stubWalletFacade);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, this method should not be called directly by the test

const stubAddToWallet = sinon.stub();
identityManager._addToWallet = stubAddToWallet;

await identityManager._extractIdentitiesFromWallet(org4MSP, stubWalletFacade);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not be called directly

Copy link
Contributor

@davidkel davidkel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry the tests will need to remove the use of _extractIdentitiesFromWallet and the code driven using appropriate configurations and stubs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants