2018-10-29 10:53:22 +01:00
|
|
|
import {assert} from "chai"
|
|
|
|
import ConfigProvider from "../../src/ConfigProvider"
|
|
|
|
import DIDRegistry from "../../src/keeper/contracts/DIDRegistry"
|
|
|
|
import Account from "../../src/ocean/Account"
|
2019-03-19 13:01:28 +01:00
|
|
|
import { Ocean } from "../../src/ocean/Ocean"
|
2019-02-21 18:14:07 +01:00
|
|
|
import { generateId } from "../../src/utils/GeneratorHelpers"
|
2018-10-29 10:53:22 +01:00
|
|
|
import Logger from "../../src/utils/Logger"
|
|
|
|
import config from "../config"
|
2018-11-07 14:33:56 +01:00
|
|
|
import TestContractHandler from "./TestContractHandler"
|
2018-10-29 10:53:22 +01:00
|
|
|
|
|
|
|
let ocean: Ocean
|
|
|
|
let didRegistry: DIDRegistry
|
|
|
|
|
|
|
|
describe("DIDRegistry", () => {
|
|
|
|
|
|
|
|
before(async () => {
|
|
|
|
ConfigProvider.setConfig(config)
|
2018-11-07 14:33:56 +01:00
|
|
|
await TestContractHandler.prepareContracts()
|
2018-10-29 10:53:22 +01:00
|
|
|
ocean = await Ocean.getInstance(config)
|
|
|
|
didRegistry = await DIDRegistry.getInstance()
|
|
|
|
})
|
|
|
|
|
|
|
|
describe("#registerAttribute()", () => {
|
|
|
|
|
|
|
|
it("should register an attribute in a new did", async () => {
|
|
|
|
const ownerAccount: Account = (await ocean.getAccounts())[0]
|
2019-02-14 12:37:52 +01:00
|
|
|
const did = generateId()
|
2018-10-29 10:53:22 +01:00
|
|
|
const data = "my nice provider, is nice"
|
2019-02-06 00:38:54 +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)
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should register another attribute in the same did", async () => {
|
|
|
|
const ownerAccount: Account = (await ocean.getAccounts())[0]
|
2019-02-14 12:37:52 +01:00
|
|
|
const did = generateId()
|
2018-10-29 10:53:22 +01:00
|
|
|
{
|
|
|
|
// register the first attribute
|
|
|
|
const data = "my nice provider, is nice"
|
2019-02-06 00:38:54 +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
|
|
|
|
const data = "asdsad"
|
2019-02-06 00:38:54 +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-03-07 15:52:40 +01:00
|
|
|
// describe("#getOwner()", () => {
|
2018-10-29 10:53:22 +01:00
|
|
|
|
2019-03-07 15:52:40 +01:00
|
|
|
// it("should get the owner of a did properly", async () => {
|
|
|
|
// const ownerAccount: Account = (await ocean.getAccounts())[0]
|
|
|
|
// const did = generateId()
|
|
|
|
// const data = "my nice provider, is nice"
|
|
|
|
// await didRegistry.registerAttribute(did, "0123456789abcdef", data, ownerAccount.getId())
|
2018-10-29 10:53:22 +01:00
|
|
|
|
2019-03-07 15:52:40 +01:00
|
|
|
// const owner = await didRegistry.getOwner(did)
|
2018-10-29 10:53:22 +01:00
|
|
|
|
2019-03-07 15:52:40 +01:00
|
|
|
// assert(owner === ownerAccount.getId(), `Got ${owner} but expected ${ownerAccount.getId()}`)
|
|
|
|
// })
|
2018-10-29 10:53:22 +01:00
|
|
|
|
2019-03-07 15:52:40 +01:00
|
|
|
// it("should get 0x00.. for a not registered did", async () => {
|
|
|
|
// const owner = await didRegistry.getOwner("1234")
|
|
|
|
// assert(owner === "0x0000000000000000000000000000000000000000")
|
|
|
|
// })
|
2018-10-29 10:53:22 +01:00
|
|
|
|
2019-03-07 15:52:40 +01:00
|
|
|
// })
|
2018-10-29 10:53:22 +01:00
|
|
|
|
2019-03-07 15:52:40 +01:00
|
|
|
// describe("#getUpdateAt()", () => {
|
2018-10-29 10:53:22 +01:00
|
|
|
|
2019-03-07 15:52:40 +01:00
|
|
|
// it("should the block number of the last update of the did attribute", async () => {
|
|
|
|
// const ownerAccount: Account = (await ocean.getAccounts())[0]
|
|
|
|
// const did = generateId()
|
|
|
|
// const data = "my nice provider, is nice"
|
|
|
|
// await didRegistry.registerAttribute(did, "0123456789abcdef", data, ownerAccount.getId())
|
2018-10-29 10:53:22 +01:00
|
|
|
|
2019-03-07 15:52:40 +01:00
|
|
|
// const updatedAt: number = await didRegistry.getUpdateAt(did)
|
2018-10-29 10:53:22 +01:00
|
|
|
|
2019-03-07 15:52:40 +01:00
|
|
|
// assert(updatedAt > 0)
|
|
|
|
// Logger.log(typeof updatedAt)
|
|
|
|
// })
|
2018-10-29 10:53:22 +01:00
|
|
|
|
2019-03-07 15:52:40 +01:00
|
|
|
// })
|
2018-10-29 10:53:22 +01:00
|
|
|
|
|
|
|
})
|