-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: move checkDidFiles to provider utils * fix: correctly continue resolving * test: add aquarius and provider mocks * test: add trusted algorithms unit test * chore: remove console log * chore: remove only from unit test
- Loading branch information
1 parent
94c0fbc
commit ee97319
Showing
6 changed files
with
123 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import * as aquarius from '../../src/utils/aquarius' | ||
import * as AquariusAsset from '../fixtures/AquariusAsset.json' | ||
import sinon from 'sinon' | ||
|
||
const RETURNED_ASSET = AquariusAsset | ||
const RETURNED_ASSET_ARRAY = [AquariusAsset, AquariusAsset] | ||
|
||
export function mockAquarius(): sinon.SinonMock { | ||
const aquariusMock = sinon.mock(aquarius) | ||
|
||
aquariusMock.expects('getAsset').returns(Promise.resolve(RETURNED_ASSET)) | ||
aquariusMock | ||
.expects('getAssets') | ||
.returns(Promise.resolve(RETURNED_ASSET_ARRAY)) | ||
|
||
return aquariusMock | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import sinon from 'sinon' | ||
import * as provider from '../../src/utils/provider' | ||
|
||
export function mockProvider(): sinon.SinonMock { | ||
const providerMock = sinon.mock(provider) | ||
|
||
return providerMock | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { Asset, LogLevel, LoggerInstance, getHash } from '@oceanprotocol/lib' | ||
import { ServiceBuilder } from '../../src' | ||
import { resolvePublisherTrustedAlgorithms } from '../../src/utils/helpers/trusted-algorithms' | ||
import * as AquariusAsset from '../fixtures/AquariusAsset.json' | ||
import { expect } from 'chai' | ||
import sinon from 'sinon' | ||
import { mockAquarius } from '../mocks/aquarius' | ||
import { mockProvider } from '../mocks/provider' | ||
|
||
describe('Utils', () => { | ||
let aquariusMock: sinon.SinonMock | ||
let providerMock: sinon.SinonMock | ||
|
||
before(() => { | ||
LoggerInstance.setLevel(LogLevel.Verbose) | ||
aquariusMock = mockAquarius() | ||
providerMock = mockProvider() | ||
}) | ||
|
||
after(() => { | ||
aquariusMock.restore() | ||
providerMock.restore() | ||
}) | ||
|
||
describe('Trusted Algorithms', async () => { | ||
const containerChecksum = getHash( | ||
AquariusAsset.metadata.algorithm.container.entrypoint + | ||
AquariusAsset.metadata.algorithm.container.checksum | ||
) | ||
const trustedAlgorithms = { | ||
did: AquariusAsset.id, | ||
filesChecksum: 'filesChecksum', | ||
containerSectionChecksum: containerChecksum | ||
} | ||
|
||
beforeEach(() => { | ||
providerMock | ||
.expects('checkDidFiles') | ||
.returns( | ||
Promise.resolve([ | ||
{ type: '', valid: true, checksum: trustedAlgorithms.filesChecksum } | ||
]) | ||
) | ||
}) | ||
|
||
it('should resolve publisherTrustedAlgorithms correctly', async () => { | ||
const serviceBuilder = new ServiceBuilder({ | ||
aquariusAsset: AquariusAsset as Asset, | ||
serviceId: AquariusAsset.services[0].id | ||
}) | ||
|
||
const service = serviceBuilder | ||
.addTrustedAlgorithms([ | ||
{ | ||
did: AquariusAsset.id | ||
} | ||
]) | ||
.build() | ||
|
||
await resolvePublisherTrustedAlgorithms( | ||
[service], | ||
'https://dummy.metadatacache' | ||
) | ||
|
||
expect(service) | ||
.to.have.property('compute') | ||
.to.have.property('publisherTrustedAlgorithms') | ||
.to.have.lengthOf.above(0) | ||
.to.deep.include(trustedAlgorithms) | ||
}) | ||
}) | ||
}) |