2019-03-11 22:52:53 +01:00
|
|
|
import { assert } from "chai"
|
2019-03-14 16:57:28 +01:00
|
|
|
import * as Web3 from "web3"
|
2019-03-11 22:52:53 +01:00
|
|
|
|
|
|
|
import { config } from "../config"
|
|
|
|
|
2019-03-21 03:02:05 +01:00
|
|
|
import { Ocean, Account, DDO } from "../../src" // @oceanprotocol/squid
|
2019-03-11 22:52:53 +01:00
|
|
|
|
|
|
|
// 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", () => {
|
|
|
|
|
2019-03-21 03:02:05 +01:00
|
|
|
let ocean: Ocean
|
2019-03-11 22:52:53 +01:00
|
|
|
let consumer: Account
|
|
|
|
|
|
|
|
before(async () => {
|
2019-03-21 03:02:05 +01:00
|
|
|
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
|
|
|
})
|
2019-03-11 22:52:53 +01:00
|
|
|
|
|
|
|
// 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)}`
|
|
|
|
|
2019-03-28 12:20:22 +01:00
|
|
|
const hash = await ocean.utils.agreements.hashServiceAgreement(
|
2019-03-11 22:52:53 +01:00
|
|
|
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 () => {
|
2019-03-21 03:02:05 +01:00
|
|
|
const templates = ocean.keeper.templates
|
2019-03-11 22:52:53 +01:00
|
|
|
|
|
|
|
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-11 22:52:53 +01:00
|
|
|
],
|
|
|
|
})
|
|
|
|
|
2019-03-14 16:57:28 +01:00
|
|
|
const agreementConditionIds = await templates.escrowAccessSecretStoreTemplate
|
|
|
|
.getAgreementIdsFromDDO(agreementId, ddo, consumer.getId(), consumer.getId())
|
2019-03-11 22:52:53 +01:00
|
|
|
|
2019-03-28 12:20:22 +01:00
|
|
|
const signature = await ocean.utils.agreements.signServiceAgreement(
|
2019-03-11 22:52:53 +01:00
|
|
|
ddo,
|
|
|
|
serviceDefinitionId,
|
|
|
|
agreementId,
|
2019-03-25 13:47:21 +01:00
|
|
|
[`0x${"1".repeat(64)}`, `0x${"2".repeat(64)}`, `0x${"3".repeat(64)}`],
|
2019-03-11 22:52:53 +01:00
|
|
|
consumer,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
signature,
|
|
|
|
// tslint:disable-next-line
|
2019-03-25 13:47:21 +01:00
|
|
|
"0xc12b8773a330fd01c7fc057e31475e5fc849eba1896cffb102881a6a45aac5fd7342069e578bbe0e1c8c95aa33a53451ac03ae1433f96928cd614c986742578e1b",
|
2019-03-11 22:52:53 +01:00
|
|
|
"The signatuere is not correct.",
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|