mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
updated registerAttribute method
This commit is contained in:
parent
5f225ceff3
commit
d51e3f3dbf
2210
package-lock.json
generated
2210
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -55,7 +55,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/oceanprotocol/squid-js#readme",
|
||||
"dependencies": {
|
||||
"@oceanprotocol/keeper-contracts": "^0.6.11",
|
||||
"@oceanprotocol/keeper-contracts": "^0.6.12",
|
||||
"@oceanprotocol/secret-store-client": "~0.0.14",
|
||||
"@types/node-fetch": "^2.1.4",
|
||||
"bignumber.js": "^8.0.1",
|
||||
|
@ -1,4 +1,5 @@
|
||||
import Web3Provider from "../keeper/Web3Provider"
|
||||
import Logger from "../utils/Logger"
|
||||
import * as signatureHelpers from "../utils/SignatureHelpers"
|
||||
import { Authentication } from "./Authentication"
|
||||
import { Proof } from "./Proof"
|
||||
@ -127,7 +128,8 @@ export class DDO {
|
||||
public addChecksum(): void {
|
||||
const metadataService = this.findServiceByType("Metadata")
|
||||
if (metadataService.metadata.base.checksum) {
|
||||
throw new Error("Checksum already exists")
|
||||
Logger.log("Checksum already exists")
|
||||
return
|
||||
}
|
||||
metadataService.metadata.base.checksum = this.getChecksum()
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
import {Receipt} from "web3-utils"
|
||||
import ValueType from "../../models/ValueType"
|
||||
import Web3Provider from "../Web3Provider"
|
||||
import ContractBase from "./ContractBase"
|
||||
|
||||
@ -11,28 +10,17 @@ export default class DIDRegistry extends ContractBase {
|
||||
return didRegistry
|
||||
}
|
||||
|
||||
public async registerAttribute(did: string, type: ValueType, key: string,
|
||||
value: string, ownerAddress: string): Promise<Receipt> {
|
||||
|
||||
return this.send("registerAttribute",
|
||||
ownerAddress, ["0x" + did, type, Web3Provider.getWeb3().utils.fromAscii(key), value],
|
||||
)
|
||||
public async registerAttribute(did: string, checksum: string, value: string, ownerAddress: string): Promise<Receipt> {
|
||||
return this.send("registerAttribute", ownerAddress, ["0x" + did, Web3Provider.getWeb3().utils.fromAscii(checksum), value])
|
||||
}
|
||||
|
||||
public async getOwner(did: string): Promise<string> {
|
||||
|
||||
return this.call("getOwner",
|
||||
["0x" + did],
|
||||
)
|
||||
return this.call("getOwner", ["0x" + did])
|
||||
}
|
||||
|
||||
public async getUpdateAt(did: string): Promise<number> {
|
||||
|
||||
const blockNum = await this.call("getUpdateAt",
|
||||
["0x" + did],
|
||||
)
|
||||
const blockNum = await this.call("getUpdateAt", ["0x" + did])
|
||||
|
||||
return parseInt(blockNum, 10)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import { Service } from "../ddo/Service"
|
||||
import ContractEvent from "../keeper/Event"
|
||||
import EventListener from "../keeper/EventListener"
|
||||
import Keeper from "../keeper/Keeper"
|
||||
import ValueType from "../models/ValueType"
|
||||
import SecretStoreProvider from "../secretstore/SecretStoreProvider"
|
||||
import Logger from "../utils/Logger"
|
||||
import Account from "./Account"
|
||||
@ -156,8 +155,7 @@ export default class OceanAssets {
|
||||
|
||||
await didRegistry.registerAttribute(
|
||||
did.getId(),
|
||||
ValueType.URL,
|
||||
"Metadata",
|
||||
ddo.getChecksum().substr(0, 32), // TODO: checksum
|
||||
serviceEndpoint,
|
||||
publisher.getId())
|
||||
|
||||
|
@ -7,8 +7,8 @@ export async function signText(text: string, publicKey: string, password?: strin
|
||||
try {
|
||||
return await web3.eth.personal.sign(text, publicKey, password)
|
||||
} catch (e) {
|
||||
Logger.error(e.message)
|
||||
throw new Error("Error execution personal sign")
|
||||
Logger.error(e)
|
||||
throw new Error("Error executing personal sign")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,6 @@
|
||||
import {assert} from "chai"
|
||||
import ConfigProvider from "../../src/ConfigProvider"
|
||||
import DIDRegistry from "../../src/keeper/contracts/DIDRegistry"
|
||||
import Web3Provider from "../../src/keeper/Web3Provider"
|
||||
import ValueType from "../../src/models/ValueType"
|
||||
import Account from "../../src/ocean/Account"
|
||||
import IdGenerator from "../../src/ocean/IdGenerator"
|
||||
import Ocean from "../../src/ocean/Ocean"
|
||||
@ -27,10 +25,8 @@ describe("DIDRegistry", () => {
|
||||
it("should register an attribute in a new did", async () => {
|
||||
const ownerAccount: Account = (await ocean.getAccounts())[0]
|
||||
const did = IdGenerator.generateId()
|
||||
const providerKey = Web3Provider.getWeb3().utils.fromAscii("provider")
|
||||
const data = "my nice provider, is nice"
|
||||
const receipt = await didRegistry.registerAttribute(did, ValueType.DID, providerKey,
|
||||
data, ownerAccount.getId())
|
||||
const receipt = await didRegistry.registerAttribute(did, `0123456789abcdef`, data, ownerAccount.getId())
|
||||
assert(receipt.status)
|
||||
assert(receipt.events.DIDAttributeRegistered)
|
||||
})
|
||||
@ -40,17 +36,13 @@ describe("DIDRegistry", () => {
|
||||
const did = IdGenerator.generateId()
|
||||
{
|
||||
// register the first attribute
|
||||
const providerKey = Web3Provider.getWeb3().utils.fromAscii("provider")
|
||||
const data = "my nice provider, is nice"
|
||||
await didRegistry.registerAttribute(did, ValueType.DID, providerKey,
|
||||
data, ownerAccount.getId())
|
||||
await didRegistry.registerAttribute(did, "0123456789abcdef", data, ownerAccount.getId())
|
||||
}
|
||||
{
|
||||
// register the second attribute with the same did
|
||||
const providerKey = Web3Provider.getWeb3().utils.fromAscii("provider2")
|
||||
const data = "asdsad"
|
||||
const receipt = await didRegistry.registerAttribute(did, ValueType.DID, providerKey,
|
||||
data, ownerAccount.getId())
|
||||
const receipt = await didRegistry.registerAttribute(did, "0123456789abcdef", data, ownerAccount.getId())
|
||||
assert(receipt.status)
|
||||
assert(receipt.events.DIDAttributeRegistered)
|
||||
}
|
||||
@ -63,10 +55,8 @@ describe("DIDRegistry", () => {
|
||||
it("should get the owner of a did properly", async () => {
|
||||
const ownerAccount: Account = (await ocean.getAccounts())[0]
|
||||
const did = IdGenerator.generateId()
|
||||
const providerKey = Web3Provider.getWeb3().utils.fromAscii("provider")
|
||||
const data = "my nice provider, is nice"
|
||||
await didRegistry.registerAttribute(did, ValueType.DID, providerKey,
|
||||
data, ownerAccount.getId())
|
||||
await didRegistry.registerAttribute(did, "0123456789abcdef", data, ownerAccount.getId())
|
||||
|
||||
const owner = await didRegistry.getOwner(did)
|
||||
|
||||
@ -85,10 +75,8 @@ describe("DIDRegistry", () => {
|
||||
it("should the block number of the last update of the did attribute", async () => {
|
||||
const ownerAccount: Account = (await ocean.getAccounts())[0]
|
||||
const did = IdGenerator.generateId()
|
||||
const providerKey = Web3Provider.getWeb3().utils.fromAscii("provider")
|
||||
const data = "my nice provider, is nice"
|
||||
await didRegistry.registerAttribute(did, ValueType.DID, providerKey,
|
||||
data, ownerAccount.getId())
|
||||
await didRegistry.registerAttribute(did, "0123456789abcdef", data, ownerAccount.getId())
|
||||
|
||||
const updatedAt: number = await didRegistry.getUpdateAt(did)
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
import {assert} from "chai"
|
||||
import { assert, spy, use } from "chai"
|
||||
import * as spies from "chai-spies"
|
||||
|
||||
import AquariusProvider from "../../src/aquarius/AquariusProvider"
|
||||
import SearchQuery from "../../src/aquarius/query/SearchQuery"
|
||||
import BrizoProvider from "../../src/brizo/BrizoProvider"
|
||||
@ -9,6 +11,7 @@ import Account from "../../src/ocean/Account"
|
||||
import Ocean from "../../src/ocean/Ocean"
|
||||
import ServiceAgreement from "../../src/ocean/ServiceAgreements/ServiceAgreement"
|
||||
import SecretStoreProvider from "../../src/secretstore/SecretStoreProvider"
|
||||
import * as signatureHelpers from "../../src/utils/SignatureHelpers"
|
||||
import WebServiceConnectorProvider from "../../src/utils/WebServiceConnectorProvider"
|
||||
import config from "../config"
|
||||
import TestContractHandler from "../keeper/TestContractHandler"
|
||||
@ -18,6 +21,8 @@ import SecretStoreMock from "../mocks/SecretStore.mock"
|
||||
import WebServiceConnectorMock from "../mocks/WebServiceConnector.mock"
|
||||
import { metadataMock } from "../testdata/MetaData"
|
||||
|
||||
use(spies)
|
||||
|
||||
let ocean: Ocean
|
||||
let accounts: Account[]
|
||||
let testPublisher: Account
|
||||
@ -26,6 +31,17 @@ describe("Ocean", () => {
|
||||
|
||||
const metadata = metadataMock
|
||||
|
||||
before(async () => {
|
||||
ConfigProvider.setConfig(config)
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
spy.on(signatureHelpers, "signText", () => `0x${"a".repeat(130)}`)
|
||||
})
|
||||
afterEach(() => {
|
||||
spy.restore()
|
||||
})
|
||||
|
||||
before(async () => {
|
||||
ConfigProvider.setConfig(config)
|
||||
AquariusProvider.setAquarius(new AquariusMock(config))
|
||||
@ -58,6 +74,7 @@ describe("Ocean", () => {
|
||||
})
|
||||
})
|
||||
|
||||
// TODO: ensure if it should fail or not
|
||||
describe("#resolveDID()", () => {
|
||||
it("should resolve a did to a ddo", async () => {
|
||||
const ddo: DDO = await ocean.registerAsset(metadata, testPublisher)
|
||||
@ -69,6 +86,7 @@ describe("Ocean", () => {
|
||||
})
|
||||
})
|
||||
|
||||
// TODO: ensure if it should fail or not
|
||||
describe("#registerAsset()", () => {
|
||||
it("should register an asset", async () => {
|
||||
const ddo: DDO = await ocean.registerAsset(metadata, testPublisher)
|
||||
|
Loading…
x
Reference in New Issue
Block a user