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]) {
|
||||
throw new Error(`Method "${name}" is not part of contract "${this.contractName}"`)
|
||||
}
|
||||
// Logger.log(name)
|
||||
const method = this.contract.methods[name]
|
||||
try {
|
||||
const tx = method(...args)
|
||||
const estimatedGas = await tx.estimateGas(args, {
|
||||
const methodInstance = method(...args)
|
||||
const estimatedGas = await methodInstance.estimateGas(args, {
|
||||
from,
|
||||
})
|
||||
return tx.send({
|
||||
const tx = methodInstance.send({
|
||||
from,
|
||||
gas: estimatedGas,
|
||||
})
|
||||
return tx
|
||||
} catch (err) {
|
||||
const mappedArgs = this.searchMethod(name).inputs.map((input, i) => {
|
||||
return {
|
||||
@ -87,6 +89,7 @@ export default abstract class ContractBase {
|
||||
if (!this.contract.methods[name]) {
|
||||
throw new Error(`Method ${name} is not part of contract ${this.contractName}`)
|
||||
}
|
||||
// Logger.log(name)
|
||||
try {
|
||||
const method = this.contract.methods[name](...args)
|
||||
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)
|
||||
.filter((index: number) => index !== undefined)
|
||||
|
||||
Logger.log(dependencyMatrix, fulfillmentIndices, this.template.fulfillmentOperator)
|
||||
|
||||
const {serviceAgreement} = await Keeper.getInstance()
|
||||
|
||||
const methodReflections = await this.getMethodReflections()
|
||||
@ -128,18 +130,29 @@ export default class ServiceAgreementTemplate extends OceanBase {
|
||||
const mappedDependencies: number[] = dependencies.map((dep: string) => {
|
||||
return this.template.Methods.findIndex((m) => m.name === dep)
|
||||
})
|
||||
Logger.log("========================")
|
||||
|
||||
let compressedDependencyValue = 0
|
||||
const numBits = 2 // 1st for dependency, 2nd for timeout flag
|
||||
for (let i = 0; i < mappedDependencies.length; i++) {
|
||||
const dependencyIndex = mappedDependencies[i]
|
||||
const timeout = dependencyTimeoutFlags[i]
|
||||
const offset = i * numBits
|
||||
Logger.log(dependencies, mappedDependencies, dependencyTimeoutFlags)
|
||||
|
||||
let compressedDependencyValue: number = 0
|
||||
const numBits: number = 2 // 1st for dependency, 2nd for timeout flag
|
||||
mappedDependencies.forEach((d: number, i: number) => {
|
||||
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
|
||||
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
|
||||
compressedDependencyValue |= timeout * 2 ** (offset + 1) // the timeout bit
|
||||
}
|
||||
compressedDependencyValue ^= timeShift // the timeout bit
|
||||
})
|
||||
|
||||
Logger.log(compressedDependencyValue)
|
||||
|
||||
Logger.log("========================")
|
||||
|
||||
return compressedDependencyValue
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ import Condition from "../../src/ocean/ServiceAgreements/Condition"
|
||||
import ServiceAgreement from "../../src/ocean/ServiceAgreements/ServiceAgreement"
|
||||
import ServiceAgreementTemplate from "../../src/ocean/ServiceAgreements/ServiceAgreementTemplate"
|
||||
import Access from "../../src/ocean/ServiceAgreements/Templates/Access"
|
||||
import Logger from "../../src/utils/Logger"
|
||||
import WebServiceConnectorProvider from "../../src/utils/WebServiceConnectorProvider"
|
||||
import config from "../config"
|
||||
import TestContractHandler from "../keeper/TestContractHandler"
|
||||
@ -209,8 +208,6 @@ describe("ServiceAgreement", () => {
|
||||
// get funds
|
||||
await consumerAccount.requestTokens(metaDataService.metadata.base.price)
|
||||
|
||||
Logger.log(await consumerAccount.getBalance())
|
||||
|
||||
const paid: boolean = await serviceAgreement.lockPayment(assetId, metaDataService.metadata.base.price,
|
||||
consumerAccount)
|
||||
assert(paid)
|
||||
@ -218,7 +215,7 @@ describe("ServiceAgreement", () => {
|
||||
})
|
||||
|
||||
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 did: string = `did:op:${id}`
|
||||
@ -247,5 +244,28 @@ describe("ServiceAgreement", () => {
|
||||
const accessGranted: boolean = await serviceAgreement.grantAccess(assetId, IdGenerator.generateId())
|
||||
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