github.com/kaleido-io/firefly@v0.0.0-20210622132723-8b4b6aacb971/kat/src/test/ethereum/assets/unauthored/public/described-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 { testDescription } from '../../../../samples';
    17  import nock from 'nock';
    18  import request from 'supertest';
    19  import assert from 'assert';
    20  import { IEventAssetDefinitionCreated, IDBAssetDefinition } from '../../../../../lib/interfaces';
    21  import * as utils from '../../../../../lib/utils';
    22  
    23  export const testUnauthoredPublicDescribedUnstructured = () => {
    24    describe('Assets: unauthored - public - described - unstructured', async () => {
    25  
    26    const assetDefinitionID = 'f832ea06-71e4-43e3-b0fb-61cb8f9a9631';
    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  
    34        nock('https://ipfs.kaleido.io')
    35          .get('/ipfs/QmXNQHuaQ9odf4dw7CrvZuQXQ8iyizwaWHV4pUZorQKFrS')
    36          .reply(200, {
    37            assetDefinitionID: assetDefinitionID,
    38            name: 'unauthored - public - described - unstructured',
    39            isContentPrivate: false,
    40            isContentUnique: true,
    41            descriptionSchema: testDescription.schema.object
    42          });
    43  
    44        const eventPromise = new Promise<void>((resolve) => {
    45          mockEventStreamWebSocket.once('send', message => {
    46            assert.strictEqual(message, '{"type":"ack","topic":"dev"}');
    47            resolve();
    48          })
    49        });
    50        const data: IEventAssetDefinitionCreated = {
    51          author: '0x0000000000000000000000000000000000000002',
    52          assetDefinitionHash: '0x862c0ad6e169fc23a45c7c9d4b09ba9ce22344a5b4242843a3549c4ea0d8668b',
    53          timestamp: timestamp.toString()
    54        };
    55        mockEventStreamWebSocket.emit('message', JSON.stringify([{
    56          signature: utils.contractEventSignatures.ASSET_DEFINITION_CREATED,
    57          data,
    58          blockNumber: '123',
    59          transactionHash: '0x0000000000000000000000000000000000000000000000000000000000000000'
    60        }]));
    61        await eventPromise;
    62      });
    63  
    64      it('Checks that the asset definition is confirmed', async () => {
    65        const getAssetDefinitionsResponse = await request(app)
    66          .get('/api/v1/assets/definitions')
    67          .expect(200);
    68        const assetDefinition = getAssetDefinitionsResponse.body.find((assetDefinition: IDBAssetDefinition) => assetDefinition.name === 'unauthored - public - described - unstructured');
    69        assert.strictEqual(assetDefinition.assetDefinitionID, assetDefinitionID);
    70        assert.strictEqual(assetDefinition.author, '0x0000000000000000000000000000000000000002');
    71        assert.strictEqual(assetDefinition.isContentPrivate, false);
    72        assert.deepStrictEqual(assetDefinition.descriptionSchema, testDescription.schema.object);
    73        assert.strictEqual(assetDefinition.name, 'unauthored - public - described - unstructured');
    74        assert.strictEqual(assetDefinition.timestamp, timestamp);
    75        assert.strictEqual(assetDefinition.submitted, undefined);
    76        assert.strictEqual(assetDefinition.receipt, undefined);
    77        assert.strictEqual(assetDefinition.blockNumber, 123);
    78        assert.strictEqual(assetDefinition.transactionHash, '0x0000000000000000000000000000000000000000000000000000000000000000');
    79  
    80        const getAssetDefinitionResponse = await request(app)
    81        .get(`/api/v1/assets/definitions/${assetDefinitionID}`)
    82        .expect(200);
    83        assert.deepStrictEqual(assetDefinition, getAssetDefinitionResponse.body);
    84      });
    85  
    86    });
    87  
    88  });
    89  };