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

102 lines
3.3 KiB
TypeScript
Raw Normal View History

import { assert } from "chai"
2019-03-14 16:57:28 +01:00
import * as Web3 from "web3"
import { config } from "../config"
import { Ocean, Account, DDO } from "../../src" // @oceanprotocol/squid
import ServiceAgreement from "../../src/ocean/ServiceAgreements/ServiceAgreement"
// WARN: not integration test. It has been done here because constant values
// depends on the first account on spree (only accessible from integration test)
describe("Signature", () => {
let ocean: Ocean
let web3: Web3
let consumer: Account
before(async () => {
ocean = await Ocean.getInstance({
2019-03-14 16:57:28 +01:00
...config,
2019-03-14 21:28:51 +01:00
web3Provider: new (Web3 as any).providers
.HttpProvider("http://localhost:8545", 0, "0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e", "node0"),
2019-03-14 16:57:28 +01:00
})
web3 = (ocean as any).web3
// Accounts
consumer = new Account("0x00bd138abd70e2f00903268f3db08f2d25677c9e")
consumer.setPassword("node0")
})
it("should generate the correct signature", async () => {
const templateId = `0x${"f".repeat(40)}`
const agreementId = `0x${"e".repeat(64)}`
const accessId = `0x${"a".repeat(64)}`
const lockId = `0x${"b".repeat(64)}`
const escrowId = `0x${"c".repeat(64)}`
const hash = await ServiceAgreement.hashServiceAgreement(
templateId,
agreementId,
[accessId, lockId, escrowId],
[0, 0, 0],
[0, 0, 0],
)
assert.equal(hash, "0x67901517c18a3d23e05806fff7f04235cc8ae3b1f82345b8bfb3e4b02b5800c7", "The signatuere is not correct.")
})
it("should generate the correct signature", async () => {
const templates = ocean.keeper.templates
const did = `did:op:${"c".repeat(64)}`
const templateId = `0x${"f".repeat(40)}`
const agreementId = `0x${"e".repeat(64)}`
const serviceDefinitionId = "0"
const serviceAgreementTemplate = await templates.escrowAccessSecretStoreTemplate.getServiceAgreementTemplate()
const ddo = new DDO({
id: did,
service: [
{
type: "Access",
purchaseEndpoint: undefined,
serviceEndpoint: undefined,
serviceDefinitionId,
templateId,
serviceAgreementTemplate,
} as any,
2019-03-14 16:57:28 +01:00
{
type: "Metadata",
metadata: {
base: {
price: 10,
2019-03-14 21:28:51 +01:00
},
},
2019-03-14 16:57:28 +01:00
} as any,
],
})
2019-03-14 16:57:28 +01:00
const agreementConditionIds = await templates.escrowAccessSecretStoreTemplate
.getAgreementIdsFromDDO(agreementId, ddo, consumer.getId(), consumer.getId())
const signature = await ServiceAgreement.signServiceAgreement(
web3,
ddo,
serviceDefinitionId,
agreementId,
2019-03-14 16:57:28 +01:00
agreementConditionIds,
consumer,
)
assert.equal(
signature,
// tslint:disable-next-line
2019-03-14 19:02:41 +01:00
"0x2164dd54b1df9908b3aa31a2d195c3e3a244ff62b51b0403958234f50cb313615ac5ca6660f7a76957612deeca84e6953f2ce74f56def351d9eb0f155a4eddff1c",
"The signatuere is not correct.",
)
})
})