github.com/kaleido-io/firefly@v0.0.0-20210622132723-8b4b6aacb971/kat/src/test/ethereum/assets/unauthored/public/unstructured.ts (about)

     1  // Copyright © 2021 Kaleido, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  import { app, mockEventStreamWebSocket } from '../../../../common';
    16  import request from 'supertest';
    17  import assert from 'assert';
    18  import nock from 'nock'
    19  import { IEventAssetDefinitionCreated, IDBAssetDefinition } from '../../../../../lib/interfaces';
    20  import * as utils from '../../../../../lib/utils';
    21  
    22  export const testUnauthoredPublicUnstructured = () => {
    23  
    24  describe('Assets: unauthored - public - unstructured', async () => {
    25  
    26    const assetDefinitionID = 'c4ecf059-67be-4e61-900f-352876604a7f';
    27  
    28    describe('Asset definition', async () => {
    29  
    30      const timestamp = utils.getTimestamp();
    31  
    32      it('Checks that the event stream notification for confirming the asset definition creation is handled', async () => {
    33        const eventPromise = new Promise<void>((resolve) => {
    34          mockEventStreamWebSocket.once('send', message => {
    35            assert.strictEqual(message, '{"type":"ack","topic":"dev"}');
    36            resolve();
    37          })
    38        });
    39  
    40        nock('https://ipfs.kaleido.io')
    41          .get('/ipfs/Qmc6W97aTfV8QuBMkYYygRBakJZ93ZjadtGPNi3KbYALTh')
    42          .reply(200, {
    43            assetDefinitionID: assetDefinitionID,
    44            name: 'unauthored - public - unstructured',
    45            isContentPrivate: false,
    46            isContentUnique: true
    47          });
    48  
    49        const data: IEventAssetDefinitionCreated = {
    50          author: '0x0000000000000000000000000000000000000002',
    51          assetDefinitionHash: '0xcc63cbfd00dc7c62c1265a42074afb19531e67b10f85b7f5170b836655a10fd0',
    52          timestamp: timestamp.toString()
    53        };
    54        mockEventStreamWebSocket.emit('message', JSON.stringify([{
    55          signature: utils.contractEventSignatures.ASSET_DEFINITION_CREATED,
    56          data,
    57          blockNumber: '123',
    58          transactionHash: '0x0000000000000000000000000000000000000000000000000000000000000000'
    59        }]));
    60        await eventPromise;
    61      });
    62  
    63      it('Checks that the asset definition is confirmed', async () => {
    64        const getAssetDefinitionsResponse = await request(app)
    65          .get('/api/v1/assets/definitions')
    66          .expect(200);
    67        const assetDefinition = getAssetDefinitionsResponse.body.find((assetDefinition: IDBAssetDefinition) => assetDefinition.name === 'unauthored - public - unstructured');
    68        assert.strictEqual(assetDefinition.assetDefinitionID, assetDefinitionID);
    69        assert.strictEqual(assetDefinition.author, '0x0000000000000000000000000000000000000002');
    70        assert.strictEqual(assetDefinition.isContentPrivate, false);
    71        assert.strictEqual(assetDefinition.name, 'unauthored - public - unstructured');
    72        assert.strictEqual(assetDefinition.timestamp, timestamp);
    73        assert.strictEqual(assetDefinition.submitted, undefined);
    74        assert.strictEqual(assetDefinition.receipt, undefined);
    75        assert.strictEqual(assetDefinition.blockNumber, 123);
    76        assert.strictEqual(assetDefinition.transactionHash, '0x0000000000000000000000000000000000000000000000000000000000000000');
    77  
    78        const getAssetDefinitionResponse = await request(app)
    79        .get(`/api/v1/assets/definitions/${assetDefinitionID}`)
    80        .expect(200);
    81        assert.deepStrictEqual(assetDefinition, getAssetDefinitionResponse.body);
    82      });
    83  
    84    });
    85  
    86  });
    87  };