mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
68 lines
2.6 KiB
TypeScript
68 lines
2.6 KiB
TypeScript
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"
|
|
|
|
let ocean: Ocean
|
|
let didRegistry: DIDRegistry
|
|
|
|
describe("DIDRegistry", () => {
|
|
|
|
before(async () => {
|
|
await TestContractHandler.prepareContracts()
|
|
ocean = await Ocean.getInstance(config)
|
|
didRegistry = ocean.keeper.didRegistry
|
|
})
|
|
|
|
describe("#registerAttribute()", () => {
|
|
|
|
it("should register an attribute in a new did", async () => {
|
|
const ownerAccount: Account = (await ocean.accounts.list())[0]
|
|
const did = generateId()
|
|
const data = "my nice provider, is nice"
|
|
const receipt = await didRegistry.registerAttribute(did, `0123456789abcdef`, [], data, ownerAccount.getId())
|
|
assert(receipt.status)
|
|
assert(receipt.events.DIDAttributeRegistered)
|
|
})
|
|
|
|
it("should register another attribute in the same did", async () => {
|
|
const ownerAccount: Account = (await ocean.accounts.list())[0]
|
|
const did = generateId()
|
|
{
|
|
// register the first attribute
|
|
const data = "my nice provider, is nice"
|
|
await didRegistry.registerAttribute(did, "0123456789abcdef", [], data, ownerAccount.getId())
|
|
}
|
|
{
|
|
// register the second attribute with the same did
|
|
const data = "asdsad"
|
|
const receipt = await didRegistry.registerAttribute(did, "0123456789abcdef", [], data, ownerAccount.getId())
|
|
assert.isTrue(receipt.status)
|
|
assert.isDefined(receipt.events.DIDAttributeRegistered)
|
|
}
|
|
})
|
|
|
|
})
|
|
|
|
describe("#getDIDOwner()", () => {
|
|
it("should get the owner of a did properly", async () => {
|
|
const ownerAccount: Account = (await ocean.accounts.list())[0]
|
|
const did = generateId()
|
|
const data = "my nice provider, is nice"
|
|
await didRegistry.registerAttribute(did, "0123456789abcdef", [], data, ownerAccount.getId())
|
|
|
|
const owner = await didRegistry.getDIDOwner(did)
|
|
|
|
assert.equal(owner, ownerAccount.getId(), `Got ${owner} but expected ${ownerAccount.getId()}`)
|
|
})
|
|
|
|
it("should get 0x0 for a not registered did", async () => {
|
|
const owner = await didRegistry.getDIDOwner("1234")
|
|
assert.equal(owner, `0x${"0".repeat(40)}`)
|
|
})
|
|
})
|
|
})
|