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