1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00

cleanup tests

This commit is contained in:
Bill Barman 2018-11-21 08:35:41 +08:00
parent 9eed1fe6d1
commit bdaea12c92

View File

@ -1,9 +1,8 @@
import {assert} from "chai" import {assert} from "chai"
import DDO from "../../src/libDDO/DDO" import DDO from "../../src/libDDO/DDO"
import * as jsonDDO from "../testdata/ddoSample1.json"
import * as Web3 from "web3" import * as Web3 from "web3"
import * as jsonDDO from "../testdata/ddoSample1.json"
describe("libDDO", () => { describe("libDDO", () => {
@ -17,132 +16,132 @@ describe("libDDO", () => {
}) })
}) })
describe('JSON serialization unserialization', () => { describe("JSON serialization unserialization", () => {
it("should create ddo with the sample JSON", async () => { it("should create ddo with the sample JSON", async () => {
assert(jsonDDO) assert(jsonDDO)
var ddo = new DDO(jsonDDO) const ddo = new DDO(jsonDDO)
assert(ddo) assert(ddo)
assert(ddo.validate()) assert(ddo.validate())
var jsonText = ddo.toJSON() const jsonText = ddo.toJSON()
assert(jsonText) assert(jsonText)
}) })
}) })
describe('validation', () => { describe("validation", () => {
it("should test ddo core validation", async () => { it("should test ddo core validation", async () => {
// core ddo values // core ddo values
assert(jsonDDO) assert(jsonDDO)
var ddo = new DDO(jsonDDO) const ddo = new DDO(jsonDDO)
assert(ddo) assert(ddo)
assert(ddo.validate()) assert(ddo.validate())
ddo.did = '' ddo.did = ""
assert(!ddo.validate()) assert(!ddo.validate())
}) })
it("should test ddo public key validation", async () => { it("should test ddo public key validation", async () => {
// public key // public key
var ddo = new DDO(jsonDDO) const ddo = new DDO(jsonDDO)
assert(ddo) assert(ddo)
assert(ddo.validate()) assert(ddo.validate())
ddo.publicKeys[0].id = '' ddo.publicKeys[0].id = ""
assert(!ddo.validate()) assert(!ddo.validate())
}) })
it("should test ddo authentication validation", async () => { it("should test ddo authentication validation", async () => {
// authentication // authentication
var ddo = new DDO(jsonDDO) const ddo = new DDO(jsonDDO)
assert(ddo) assert(ddo)
assert(ddo.validate()) assert(ddo.validate())
ddo.authentications[0].type = '' ddo.authentications[0].type = ""
assert(!ddo.validate()) assert(!ddo.validate())
}) })
it("should test ddo service validation", async () => { it("should test ddo service validation", async () => {
// service // service
var ddo = new DDO(jsonDDO) const ddo = new DDO(jsonDDO)
assert(ddo) assert(ddo)
assert(ddo.validate()) assert(ddo.validate())
ddo.services[0].endpoint = '' ddo.services[0].endpoint = ""
assert(!ddo.validate()) assert(!ddo.validate())
}) })
it("should test ddo proof validation", async () => { it("should test ddo proof validation", async () => {
// proof // proof
var ddo = new DDO(jsonDDO) const ddo = new DDO(jsonDDO)
assert(ddo) assert(ddo)
assert(ddo.validate()) assert(ddo.validate())
ddo.proof.signatureValue = '' ddo.proof.signatureValue = ""
assert(!ddo.validate()) assert(!ddo.validate())
}) })
}) })
describe('DDO access data', () => { describe("DDO access data", () => {
it("should find a service in the ddo", async () => { it("should find a service in the ddo", async () => {
var ddo = new DDO(jsonDDO) const ddo = new DDO(jsonDDO)
assert(ddo) assert(ddo)
assert(ddo.validate()) assert(ddo.validate())
var service = ddo.getService('Metadata') const service = ddo.getService("Metadata")
assert(service) assert(service)
var service = ddo.getService('MetadataCannotFind') const service = ddo.getService("MetadataCannotFind")
assert(service == null) assert(service == null)
// var item = ddo.findServiceKeyValue('serviceDefinitionId', 'test')
// var item = ddo.findServiceKeyValue("serviceDefinitionId", "test")
}) })
}) })
describe('DDO hashing', () => { describe("DDO hashing", () => {
it("should hash a valid ddo", async () => { it("should hash a valid ddo", async () => {
var ddo = new DDO(jsonDDO) const ddo = new DDO(jsonDDO)
assert(ddo) assert(ddo)
assert(ddo.validate()) assert(ddo.validate())
var hash = ddo.calculateHash() const hash = ddo.calculateHash()
assert(hash) assert(hash)
// console.log(hash) // console.log(hash)
}) })
}) })
describe('DDO validate proof from JSON', () => { describe("DDO validate proof from JSON", () => {
it("should have a valid ddo proof", async () => { it("should have a valid ddo proof", async () => {
var ddo = new DDO(jsonDDO) const ddo = new DDO(jsonDDO)
assert(ddo) assert(ddo)
assert(ddo.validate()) assert(ddo.validate())
ddo.validateProof() ddo.validateProof()
}) })
}) })
describe('DDO creation', () => { describe("DDO creation", () => {
it("should add a signature", async () => { it("should add a signature", async () => {
var ddo = new DDO() const ddo = new DDO()
assert(ddo) assert(ddo)
const privateKey = ddo.addSignature() const privateKey = ddo.addSignature()
assert(privateKey.match('-----BEGIN RSA PRIVATE KEY-----')) assert(privateKey.match("-----BEGIN RSA PRIVATE KEY-----"))
}) })
it("should add a service", async () => { it("should add a service", async () => {
const did = 'did:op:' + Web3.utils.randomHex(32).substr(2) const did = "did:op:" + Web3.utils.randomHex(32).substr(2)
var ddo = new DDO(did) const ddo = new DDO(did)
assert(ddo) assert(ddo)
const service = ddo.addService({type: 'metatrippy', serviceEndpoint: 'http://localhost:5000'}) const service = ddo.addService({type: "metatrippy", serviceEndpoint: "http://localhost:5000"})
assert(service) assert(service)
assert(service.id === did) assert(service.id === did)
}) })
it("should add a static proof and validate", async () => { it("should add a static proof and validate", async () => {
const did = 'did:op:' + Web3.utils.randomHex(32).substr(2) const did = "did:op:" + Web3.utils.randomHex(32).substr(2)
var ddo = new DDO(did) const ddo = new DDO(did)
assert(ddo) assert(ddo)
const privateKey = ddo.addSignature() const privateKey = ddo.addSignature()
assert(privateKey.match('-----BEGIN RSA PRIVATE KEY-----')) assert(privateKey.match("-----BEGIN RSA PRIVATE KEY-----"))
ddo.addProof(0, privateKey) ddo.addProof(0, privateKey)
console.log(ddo.toJSON())
assert(ddo.validateProof()) assert(ddo.validateProof())
}) })
}) })