github.com/kaleido-io/firefly@v0.0.0-20210622132723-8b4b6aacb971/kat/src/test/ethereum/assets/unauthored/private/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 22 export const testUnauthoredPrivateUnstructured = () => { 23 24 describe('Asset definitions: unauthored - unstructured', async () => { 25 26 const assetDefinitionID = '2a624ed6-7d71-4b44-94a8-faea64537036'; 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 nock('https://ipfs.kaleido.io') 40 .get('/ipfs/QmVB7euGyrkSZPTaoBEZB4rou3A7Za48GNKidL1hSK2bsA') 41 .reply(200, { 42 assetDefinitionID: assetDefinitionID, 43 name: 'unauthored - private - unstructured', 44 isContentPrivate: true, 45 isContentUnique: true 46 }); 47 48 const data: IEventAssetDefinitionCreated = { 49 author: '0x0000000000000000000000000000000000000002', 50 assetDefinitionHash: '0x65907788050862e3317097ac1b1b7dc6cd9c7b35ea11dcccbcef727aae01450d', 51 timestamp: timestamp.toString() 52 }; 53 mockEventStreamWebSocket.emit('message', JSON.stringify([{ 54 signature: utils.contractEventSignatures.ASSET_DEFINITION_CREATED, 55 data, 56 blockNumber: '123', 57 transactionHash: '0x0000000000000000000000000000000000000000000000000000000000000000' 58 }])); 59 await eventPromise; 60 }); 61 62 it('Checks that the asset definition is confirmed', async () => { 63 const getAssetDefinitionsResponse = await request(app) 64 .get('/api/v1/assets/definitions') 65 .expect(200); 66 const assetDefinition = getAssetDefinitionsResponse.body.find((assetDefinition: IDBAssetDefinition) => assetDefinition.name === 'unauthored - private - unstructured'); 67 assert.strictEqual(assetDefinition.assetDefinitionID, assetDefinitionID); 68 assert.strictEqual(assetDefinition.author, '0x0000000000000000000000000000000000000002'); 69 assert.strictEqual(assetDefinition.isContentPrivate, true); 70 assert.strictEqual(assetDefinition.name, 'unauthored - private - unstructured'); 71 assert.strictEqual(assetDefinition.timestamp, timestamp); 72 assert.strictEqual(assetDefinition.submitted, undefined); 73 assert.strictEqual(assetDefinition.receipt, undefined); 74 assert.strictEqual(assetDefinition.blockNumber, 123); 75 assert.strictEqual(assetDefinition.transactionHash, '0x0000000000000000000000000000000000000000000000000000000000000000'); 76 77 const getAssetDefinitionResponse = await request(app) 78 .get(`/api/v1/assets/definitions/${assetDefinitionID}`) 79 .expect(200); 80 assert.deepStrictEqual(assetDefinition, getAssetDefinitionResponse.body); 81 }); 82 83 }); 84 85 }); 86 87 };