mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
added more logging
This commit is contained in:
parent
43fe8634d2
commit
920ae0dc35
@ -60,16 +60,18 @@ export default abstract class ContractBase {
|
|||||||
if (!this.contract.methods[name]) {
|
if (!this.contract.methods[name]) {
|
||||||
throw new Error(`Method "${name}" is not part of contract "${this.contractName}"`)
|
throw new Error(`Method "${name}" is not part of contract "${this.contractName}"`)
|
||||||
}
|
}
|
||||||
|
// Logger.log(name)
|
||||||
const method = this.contract.methods[name]
|
const method = this.contract.methods[name]
|
||||||
try {
|
try {
|
||||||
const tx = method(...args)
|
const methodInstance = method(...args)
|
||||||
const estimatedGas = await tx.estimateGas(args, {
|
const estimatedGas = await methodInstance.estimateGas(args, {
|
||||||
from,
|
from,
|
||||||
})
|
})
|
||||||
return tx.send({
|
const tx = methodInstance.send({
|
||||||
from,
|
from,
|
||||||
gas: estimatedGas,
|
gas: estimatedGas,
|
||||||
})
|
})
|
||||||
|
return tx
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const mappedArgs = this.searchMethod(name).inputs.map((input, i) => {
|
const mappedArgs = this.searchMethod(name).inputs.map((input, i) => {
|
||||||
return {
|
return {
|
||||||
@ -87,6 +89,7 @@ export default abstract class ContractBase {
|
|||||||
if (!this.contract.methods[name]) {
|
if (!this.contract.methods[name]) {
|
||||||
throw new Error(`Method ${name} is not part of contract ${this.contractName}`)
|
throw new Error(`Method ${name} is not part of contract ${this.contractName}`)
|
||||||
}
|
}
|
||||||
|
// Logger.log(name)
|
||||||
try {
|
try {
|
||||||
const method = this.contract.methods[name](...args)
|
const method = this.contract.methods[name](...args)
|
||||||
return method.call(from ? {from} : null)
|
return method.call(from ? {from} : null)
|
||||||
|
@ -38,6 +38,8 @@ export default class ServiceAgreementTemplate extends OceanBase {
|
|||||||
.map((method: Method, i: number) => method.isTerminalCondition ? i : undefined)
|
.map((method: Method, i: number) => method.isTerminalCondition ? i : undefined)
|
||||||
.filter((index: number) => index !== undefined)
|
.filter((index: number) => index !== undefined)
|
||||||
|
|
||||||
|
Logger.log(dependencyMatrix, fulfillmentIndices, this.template.fulfillmentOperator)
|
||||||
|
|
||||||
const {serviceAgreement} = await Keeper.getInstance()
|
const {serviceAgreement} = await Keeper.getInstance()
|
||||||
|
|
||||||
const methodReflections = await this.getMethodReflections()
|
const methodReflections = await this.getMethodReflections()
|
||||||
@ -128,18 +130,29 @@ export default class ServiceAgreementTemplate extends OceanBase {
|
|||||||
const mappedDependencies: number[] = dependencies.map((dep: string) => {
|
const mappedDependencies: number[] = dependencies.map((dep: string) => {
|
||||||
return this.template.Methods.findIndex((m) => m.name === dep)
|
return this.template.Methods.findIndex((m) => m.name === dep)
|
||||||
})
|
})
|
||||||
|
Logger.log("========================")
|
||||||
|
|
||||||
let compressedDependencyValue = 0
|
Logger.log(dependencies, mappedDependencies, dependencyTimeoutFlags)
|
||||||
const numBits = 2 // 1st for dependency, 2nd for timeout flag
|
|
||||||
for (let i = 0; i < mappedDependencies.length; i++) {
|
let compressedDependencyValue: number = 0
|
||||||
const dependencyIndex = mappedDependencies[i]
|
const numBits: number = 2 // 1st for dependency, 2nd for timeout flag
|
||||||
const timeout = dependencyTimeoutFlags[i]
|
mappedDependencies.forEach((d: number, i: number) => {
|
||||||
const offset = i * numBits
|
const timeout: number = dependencyTimeoutFlags[i]
|
||||||
|
const offset: number = i * numBits
|
||||||
|
Logger.log("index", i, "offset", offset)
|
||||||
|
const depShift: number = d * 2 ** (offset + 0)
|
||||||
|
Logger.log("ds", depShift)
|
||||||
// tslint:disable-next-line
|
// tslint:disable-next-line
|
||||||
compressedDependencyValue |= dependencyIndex * 2 ** (offset + 0) // the dependency bit
|
compressedDependencyValue ^= depShift // the dependency bit
|
||||||
|
const timeShift: number = timeout * 2 ** (offset + 1)
|
||||||
|
Logger.log("ts", timeShift)
|
||||||
// tslint:disable-next-line
|
// tslint:disable-next-line
|
||||||
compressedDependencyValue |= timeout * 2 ** (offset + 1) // the timeout bit
|
compressedDependencyValue ^= timeShift // the timeout bit
|
||||||
}
|
})
|
||||||
|
|
||||||
|
Logger.log(compressedDependencyValue)
|
||||||
|
|
||||||
|
Logger.log("========================")
|
||||||
|
|
||||||
return compressedDependencyValue
|
return compressedDependencyValue
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ import Condition from "../../src/ocean/ServiceAgreements/Condition"
|
|||||||
import ServiceAgreement from "../../src/ocean/ServiceAgreements/ServiceAgreement"
|
import ServiceAgreement from "../../src/ocean/ServiceAgreements/ServiceAgreement"
|
||||||
import ServiceAgreementTemplate from "../../src/ocean/ServiceAgreements/ServiceAgreementTemplate"
|
import ServiceAgreementTemplate from "../../src/ocean/ServiceAgreements/ServiceAgreementTemplate"
|
||||||
import Access from "../../src/ocean/ServiceAgreements/Templates/Access"
|
import Access from "../../src/ocean/ServiceAgreements/Templates/Access"
|
||||||
import Logger from "../../src/utils/Logger"
|
|
||||||
import WebServiceConnectorProvider from "../../src/utils/WebServiceConnectorProvider"
|
import WebServiceConnectorProvider from "../../src/utils/WebServiceConnectorProvider"
|
||||||
import config from "../config"
|
import config from "../config"
|
||||||
import TestContractHandler from "../keeper/TestContractHandler"
|
import TestContractHandler from "../keeper/TestContractHandler"
|
||||||
@ -209,8 +208,6 @@ describe("ServiceAgreement", () => {
|
|||||||
// get funds
|
// get funds
|
||||||
await consumerAccount.requestTokens(metaDataService.metadata.base.price)
|
await consumerAccount.requestTokens(metaDataService.metadata.base.price)
|
||||||
|
|
||||||
Logger.log(await consumerAccount.getBalance())
|
|
||||||
|
|
||||||
const paid: boolean = await serviceAgreement.lockPayment(assetId, metaDataService.metadata.base.price,
|
const paid: boolean = await serviceAgreement.lockPayment(assetId, metaDataService.metadata.base.price,
|
||||||
consumerAccount)
|
consumerAccount)
|
||||||
assert(paid)
|
assert(paid)
|
||||||
@ -218,7 +215,7 @@ describe("ServiceAgreement", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe("#grantAccess()", () => {
|
describe("#grantAccess()", () => {
|
||||||
xit("should grant access in that service agreement", async () => {
|
it("should grant access in that service agreement", async () => {
|
||||||
|
|
||||||
const id: string = IdGenerator.generateId()
|
const id: string = IdGenerator.generateId()
|
||||||
const did: string = `did:op:${id}`
|
const did: string = `did:op:${id}`
|
||||||
@ -247,5 +244,28 @@ describe("ServiceAgreement", () => {
|
|||||||
const accessGranted: boolean = await serviceAgreement.grantAccess(assetId, IdGenerator.generateId())
|
const accessGranted: boolean = await serviceAgreement.grantAccess(assetId, IdGenerator.generateId())
|
||||||
assert(accessGranted)
|
assert(accessGranted)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
xit("should fail to grant grant access if there is no payment", async () => {
|
||||||
|
|
||||||
|
const id: string = IdGenerator.generateId()
|
||||||
|
const did: string = `did:op:${id}`
|
||||||
|
const ddo = new DDO({id: did, service: [accessService]})
|
||||||
|
const serviceAgreementId: string = IdGenerator.generateId()
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
WebServiceConnectorProvider.setConnector(new WebServiceConnectorMock(ddo))
|
||||||
|
const serviceAgreementSignature: string =
|
||||||
|
await ServiceAgreement.signServiceAgreement(assetId, ddo, accessService.serviceDefinitionId,
|
||||||
|
serviceAgreementId, consumerAccount)
|
||||||
|
assert(serviceAgreementSignature)
|
||||||
|
|
||||||
|
const serviceAgreement: ServiceAgreement =
|
||||||
|
await ServiceAgreement.executeServiceAgreement(assetId, ddo, accessService.serviceDefinitionId,
|
||||||
|
serviceAgreementId, serviceAgreementSignature, consumerAccount, publisherAccount)
|
||||||
|
assert(serviceAgreement)
|
||||||
|
|
||||||
|
const accessGranted: boolean = await serviceAgreement.grantAccess(assetId, IdGenerator.generateId())
|
||||||
|
assert(!accessGranted)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user