2019-06-20 00:20:09 +02:00
|
|
|
import { assert } from 'chai'
|
|
|
|
import DIDRegistry from '../../src/keeper/contracts/DIDRegistry'
|
|
|
|
import Account from '../../src/ocean/Account'
|
|
|
|
import { Ocean } from '../../src/ocean/Ocean'
|
|
|
|
import { generateId } from '../../src/utils/GeneratorHelpers'
|
|
|
|
import config from '../config'
|
|
|
|
import TestContractHandler from './TestContractHandler'
|
2018-10-29 10:53:22 +01:00
|
|
|
|
|
|
|
let ocean: Ocean
|
|
|
|
let didRegistry: DIDRegistry
|
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
describe('DIDRegistry', () => {
|
2018-10-29 10:53:22 +01:00
|
|
|
before(async () => {
|
2018-11-07 14:33:56 +01:00
|
|
|
await TestContractHandler.prepareContracts()
|
2018-10-29 10:53:22 +01:00
|
|
|
ocean = await Ocean.getInstance(config)
|
2019-11-13 15:37:03 +01:00
|
|
|
;({ didRegistry } = ocean.keeper)
|
2018-10-29 10:53:22 +01:00
|
|
|
})
|
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
describe('#registerAttribute()', () => {
|
|
|
|
it('should register an attribute in a new did', async () => {
|
2019-03-21 02:56:58 +01:00
|
|
|
const ownerAccount: Account = (await ocean.accounts.list())[0]
|
2019-02-14 12:37:52 +01:00
|
|
|
const did = generateId()
|
2019-06-20 00:20:09 +02:00
|
|
|
const data = 'my nice provider, is nice'
|
2019-11-15 00:00:10 +01:00
|
|
|
const receipt = await didRegistry.registerAttribute(
|
|
|
|
did,
|
|
|
|
`0123456789abcdef`,
|
|
|
|
[],
|
|
|
|
data,
|
|
|
|
ownerAccount.getId()
|
|
|
|
)
|
2018-10-29 10:53:22 +01:00
|
|
|
assert(receipt.status)
|
|
|
|
assert(receipt.events.DIDAttributeRegistered)
|
|
|
|
})
|
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
it('should register another attribute in the same did', async () => {
|
2019-03-21 02:56:58 +01:00
|
|
|
const ownerAccount: Account = (await ocean.accounts.list())[0]
|
2019-02-14 12:37:52 +01:00
|
|
|
const did = generateId()
|
2018-10-29 10:53:22 +01:00
|
|
|
{
|
|
|
|
// register the first attribute
|
2019-06-20 00:20:09 +02:00
|
|
|
const data = 'my nice provider, is nice'
|
2019-11-15 00:00:10 +01:00
|
|
|
await didRegistry.registerAttribute(
|
|
|
|
did,
|
|
|
|
'0123456789abcdef',
|
|
|
|
[],
|
|
|
|
data,
|
|
|
|
ownerAccount.getId()
|
|
|
|
)
|
2018-10-29 10:53:22 +01:00
|
|
|
}
|
|
|
|
{
|
|
|
|
// register the second attribute with the same did
|
2019-06-20 00:20:09 +02:00
|
|
|
const data = 'asdsad'
|
|
|
|
const receipt = await didRegistry.registerAttribute(
|
|
|
|
did,
|
|
|
|
'0123456789abcdef',
|
|
|
|
[],
|
|
|
|
data,
|
|
|
|
ownerAccount.getId()
|
|
|
|
)
|
2019-04-01 12:40:45 +02:00
|
|
|
assert.isTrue(receipt.status)
|
|
|
|
assert.isDefined(receipt.events.DIDAttributeRegistered)
|
2018-10-29 10:53:22 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
describe('#getDIDOwner()', () => {
|
|
|
|
it('should get the owner of a did properly', async () => {
|
2019-04-01 12:40:45 +02:00
|
|
|
const ownerAccount: Account = (await ocean.accounts.list())[0]
|
|
|
|
const did = generateId()
|
2019-06-20 00:20:09 +02:00
|
|
|
const data = 'my nice provider, is nice'
|
2019-11-15 00:00:10 +01:00
|
|
|
await didRegistry.registerAttribute(
|
|
|
|
did,
|
|
|
|
'0123456789abcdef',
|
|
|
|
[],
|
|
|
|
data,
|
|
|
|
ownerAccount.getId()
|
|
|
|
)
|
2018-10-29 10:53:22 +01:00
|
|
|
|
2019-04-01 12:40:45 +02:00
|
|
|
const owner = await didRegistry.getDIDOwner(did)
|
2018-10-29 10:53:22 +01:00
|
|
|
|
2019-11-15 00:00:10 +01:00
|
|
|
assert.equal(
|
|
|
|
owner,
|
|
|
|
ownerAccount.getId(),
|
|
|
|
`Got ${owner} but expected ${ownerAccount.getId()}`
|
|
|
|
)
|
2019-04-01 12:40:45 +02:00
|
|
|
})
|
2018-10-29 10:53:22 +01:00
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
it('should get 0x0 for a not registered did', async () => {
|
|
|
|
const owner = await didRegistry.getDIDOwner('1234')
|
|
|
|
assert.equal(owner, `0x${'0'.repeat(40)}`)
|
2019-04-01 12:40:45 +02:00
|
|
|
})
|
|
|
|
})
|
2019-11-13 15:37:03 +01:00
|
|
|
|
|
|
|
describe('#transferDIDOwnership()', () => {
|
|
|
|
it('should be able to transfer ownership', async () => {
|
|
|
|
// create and register DID
|
|
|
|
const ownerAccount: Account = (await ocean.accounts.list())[0]
|
|
|
|
const did = generateId()
|
|
|
|
const data = 'my nice provider, is nice'
|
2019-11-15 00:00:10 +01:00
|
|
|
await didRegistry.registerAttribute(
|
|
|
|
did,
|
|
|
|
'0123456789abcdef',
|
|
|
|
[],
|
|
|
|
data,
|
|
|
|
ownerAccount.getId()
|
|
|
|
)
|
2019-11-13 15:37:03 +01:00
|
|
|
|
|
|
|
// transfer
|
|
|
|
const newOwnerAccount: Account = (await ocean.accounts.list())[1]
|
2019-11-15 00:00:10 +01:00
|
|
|
await didRegistry.transferDIDOwnership(
|
|
|
|
did,
|
|
|
|
newOwnerAccount.getId(),
|
|
|
|
ownerAccount.getId()
|
|
|
|
)
|
2019-11-13 15:37:03 +01:00
|
|
|
|
|
|
|
// check
|
|
|
|
const newOwner = await didRegistry.getDIDOwner(did)
|
2019-11-15 00:00:10 +01:00
|
|
|
assert.equal(
|
|
|
|
newOwner,
|
|
|
|
newOwnerAccount.getId(),
|
|
|
|
`Got ${newOwner} but expected ${newOwnerAccount.getId()}`
|
|
|
|
)
|
2019-11-13 15:37:03 +01:00
|
|
|
})
|
|
|
|
})
|
2018-10-29 10:53:22 +01:00
|
|
|
})
|