davidkel / fc

0 stars 0 forks source link

All the sample network tests are wrong #103

Open davidkel opened 6 years ago

davidkel commented 6 years ago
    // In-memory card store for testing so cards are not persisted to the file system
    const cardStore = require('composer-common').NetworkCardStoreManager.getCardStore( { type: 'composer-wallet-inmemory' } );
...
adminConnection = new AdminConnection({ cardStore: cardStore });

NetworkCardStoreManager is not a documented api and the docs show this

        const connectionOptions = {
            wallet : {
                type: 'composer-wallet-inmemory'
            }
        };
        adminConnection = new AdminConnection(connectionOptions);

Also

        const credentials = CertificateUtil.generate({ commonName: 'admin' });

        // PeerAdmin identity used with the admin connection to deploy business networks
        const deployerMetadata = {
            version: 1,
            userName: 'PeerAdmin',
            roles: [ 'PeerAdmin', 'ChannelAdmin' ]
        };
        const deployerCard = new IdCard(deployerMetadata, connectionProfile);
        const deployerCardName = 'PeerAdmin';
        deployerCard.setCredentials(credentials);

but CertificateUtil is not documented and you don't need to use certs for the embedded connector

       // PeerAdmin identity used with the admin connection to deploy business networks
        const deployerMetadata = {
            version: 1,
            userName: 'admin',
            enrollmentSecret: 'adminpw',
            roles: [ 'PeerAdmin', 'ChannelAdmin' ]
        };
        const deployerCard = new IdCard(deployerMetadata, connectionProfile);
        const deployerCardName = 'PeerAdmin';

Would be the right way. CertificateUtil works because its used inside the embedded connector to generate the certs for the admin identity and so this bit of code will work

        const startOptions = {
            networkAdmins: [
                {
                    userName: adminUserName,
                    enrollmentSecret: 'adminpw'
                }
            ]
        };
        const adminCards = await adminConnection.start(businessNetworkDefinition.getName(), businessNetworkDefinition.getVersion(), startOptions);

because the issuer is the same as that used to deploy.