mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
improved error detection on integration test #118
This commit is contained in:
parent
f23b146932
commit
c1c3168c64
@ -5,8 +5,9 @@ import Service from "../ddo/Service"
|
||||
import DID from "../ocean/DID"
|
||||
import {Account, Logger, Ocean, ServiceAgreement} from "../squid"
|
||||
import config from "./config"
|
||||
import {runner} from "./runner"
|
||||
|
||||
(async () => {
|
||||
async function exec() {
|
||||
const ocean: Ocean = await Ocean.getInstance(config)
|
||||
|
||||
const publisher: Account = (await ocean.getAccounts())[0]
|
||||
@ -68,6 +69,6 @@ import config from "./config"
|
||||
|
||||
const paid = await serviceAgreement.payAsset(did.getId(), metaData.base.price, consumer)
|
||||
Logger.log(`Asset paid: ${paid}`)
|
||||
}
|
||||
|
||||
process.exit(0)
|
||||
})()
|
||||
runner(exec)
|
||||
|
@ -4,8 +4,9 @@ import MetaDataBase from "../ddo/MetaDataBase"
|
||||
import Service from "../ddo/Service"
|
||||
import {Account, Logger, Ocean, ServiceAgreement} from "../squid"
|
||||
import config from "./config"
|
||||
import {runner} from "./runner"
|
||||
|
||||
(async () => {
|
||||
async function exec() {
|
||||
const ocean: Ocean = await Ocean.getInstance(config)
|
||||
|
||||
const publisher: Account = (await ocean.getAccounts())[0]
|
||||
@ -63,6 +64,6 @@ import config from "./config"
|
||||
consumer,
|
||||
publisher)
|
||||
Logger.log("ServiceAgreement Id:", serviceAgreement.getId())
|
||||
}
|
||||
|
||||
process.exit(0)
|
||||
})()
|
||||
runner(exec)
|
||||
|
@ -1,12 +1,13 @@
|
||||
import {Logger, Ocean} from "../squid"
|
||||
import config from "./config"
|
||||
import {runner} from "./runner"
|
||||
|
||||
(async () => {
|
||||
async function exec() {
|
||||
const ocean: Ocean = await Ocean.getInstance(config)
|
||||
|
||||
const accounts = await ocean.getAccounts()
|
||||
|
||||
Logger.log(JSON.stringify(accounts, null, 2))
|
||||
}
|
||||
|
||||
process.exit(0)
|
||||
})()
|
||||
runner(exec)
|
||||
|
@ -1,12 +1,13 @@
|
||||
import {Logger, Ocean} from "../squid"
|
||||
import config from "./config"
|
||||
import {runner} from "./runner"
|
||||
|
||||
(async () => {
|
||||
async function exec() {
|
||||
const ocean: Ocean = await Ocean.getInstance(config)
|
||||
|
||||
const accounts = await ocean.getAccounts()
|
||||
|
||||
Logger.log(await accounts[0].getBalance())
|
||||
}
|
||||
|
||||
process.exit(0)
|
||||
})()
|
||||
runner(exec)
|
||||
|
@ -1,12 +1,13 @@
|
||||
import {Logger, Ocean} from "../squid"
|
||||
import config from "./config"
|
||||
import {runner} from "./runner"
|
||||
|
||||
(async () => {
|
||||
async function exec() {
|
||||
const ocean: Ocean = await Ocean.getInstance(config)
|
||||
|
||||
const accounts = await ocean.getAccounts()
|
||||
|
||||
Logger.log(JSON.stringify(accounts, null, 2))
|
||||
}
|
||||
|
||||
process.exit(0)
|
||||
})()
|
||||
runner(exec)
|
||||
|
@ -5,8 +5,9 @@ import Service from "../ddo/Service"
|
||||
import DID from "../ocean/DID"
|
||||
import {Account, Logger, Ocean, ServiceAgreement} from "../squid"
|
||||
import config from "./config"
|
||||
import {runner} from "./runner"
|
||||
|
||||
(async () => {
|
||||
async function exec() {
|
||||
const ocean: Ocean = await Ocean.getInstance(config)
|
||||
|
||||
const publisher: Account = (await ocean.getAccounts())[0]
|
||||
@ -71,6 +72,6 @@ import config from "./config"
|
||||
|
||||
const accessGranted = await serviceAgreement.grantAccess(did.getId(), did.getId(), publisher)
|
||||
Logger.log(`Asset access granted: ${accessGranted}`)
|
||||
}
|
||||
|
||||
process.exit(0)
|
||||
})()
|
||||
runner(exec)
|
||||
|
@ -4,8 +4,9 @@ import MetaDataBase from "../ddo/MetaDataBase"
|
||||
import Service from "../ddo/Service"
|
||||
import {Account, Logger, Ocean} from "../squid"
|
||||
import config from "./config"
|
||||
import {runner} from "./runner"
|
||||
|
||||
(async () => {
|
||||
async function exec() {
|
||||
const ocean: Ocean = await Ocean.getInstance(config)
|
||||
|
||||
const publisher: Account = (await ocean.getAccounts())[1]
|
||||
@ -71,6 +72,6 @@ import config from "./config"
|
||||
Logger.warn("Error on initializeServiceAgreement:", e)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
process.exit(0)
|
||||
})()
|
||||
runner(exec)
|
||||
|
@ -3,8 +3,9 @@ import MetaData from "../ddo/MetaData"
|
||||
import MetaDataBase from "../ddo/MetaDataBase"
|
||||
import {Account, Logger, Ocean} from "../squid"
|
||||
import config from "./config"
|
||||
import {runner} from "./runner"
|
||||
|
||||
(async () => {
|
||||
async function exec() {
|
||||
const ocean: Ocean = await Ocean.getInstance(config)
|
||||
|
||||
const publisher: Account = (await ocean.getAccounts())[0]
|
||||
@ -41,6 +42,6 @@ import config from "./config"
|
||||
|
||||
const ddo: DDO = await ocean.registerAsset(metaData, publisher)
|
||||
Logger.log(ddo.id)
|
||||
}
|
||||
|
||||
process.exit(0)
|
||||
})()
|
||||
runner(exec)
|
||||
|
@ -1,7 +1,8 @@
|
||||
import {Account, Logger, Ocean, ServiceAgreementTemplate, Templates} from "../squid"
|
||||
import config from "./config"
|
||||
import {runner} from "./runner"
|
||||
|
||||
(async () => {
|
||||
async function exec() {
|
||||
const ocean: Ocean = await Ocean.getInstance(config)
|
||||
|
||||
const templateOwner: Account = (await ocean.getAccounts())[0]
|
||||
@ -11,6 +12,7 @@ import config from "./config"
|
||||
|
||||
Logger.log("ServiceAgreementTemplate registered:", serviceAgreementRegistered,
|
||||
"templateId:", serviceAgreementTemplate.getId())
|
||||
}
|
||||
|
||||
runner(exec)
|
||||
|
||||
process.exit(0)
|
||||
})()
|
||||
|
@ -1,8 +1,9 @@
|
||||
import DDO from "../ddo/DDO"
|
||||
import {Logger, Ocean} from "../squid"
|
||||
import config from "./config"
|
||||
import {runner} from "./runner"
|
||||
|
||||
(async () => {
|
||||
async function exec() {
|
||||
const ocean: Ocean = await Ocean.getInstance(config)
|
||||
|
||||
const result: DDO[] = await ocean.searchAssetsByText("Office Humidity")
|
||||
@ -14,6 +15,6 @@ import config from "./config"
|
||||
})
|
||||
|
||||
Logger.log(names.length, names)
|
||||
}
|
||||
|
||||
process.exit(0)
|
||||
})()
|
||||
runner(exec)
|
||||
|
@ -6,8 +6,9 @@ import MetaDataBase from "../ddo/MetaDataBase"
|
||||
import Service from "../ddo/Service"
|
||||
import {Account, Logger, Ocean} from "../squid"
|
||||
import config from "./config"
|
||||
import {runner} from "./runner"
|
||||
|
||||
(async () => {
|
||||
async function exec() {
|
||||
const ocean: Ocean = await Ocean.getInstance(config)
|
||||
|
||||
const publisher: Account = (await ocean.getAccounts())[0]
|
||||
@ -77,6 +78,6 @@ import config from "./config"
|
||||
|
||||
Logger.log("ServiceAgreement Id:", serviceAgreementResult.serviceAgreementId)
|
||||
Logger.log("ServiceAgreement Signature:", serviceAgreementResult.serviceAgreementSignature)
|
||||
}
|
||||
|
||||
process.exit(0)
|
||||
})()
|
||||
runner(exec)
|
||||
|
10
src/examples/runner.ts
Normal file
10
src/examples/runner.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import {Logger} from "../squid"
|
||||
|
||||
export function runner(fn: () => Promise<any>) {
|
||||
fn()
|
||||
.then(() => process.exit(0))
|
||||
.catch((e) => {
|
||||
Logger.warn(e)
|
||||
process.exit(1)
|
||||
})
|
||||
}
|
@ -63,8 +63,12 @@ export default abstract class ContractBase {
|
||||
value: args[i],
|
||||
}
|
||||
})
|
||||
Logger.error("-".repeat(40))
|
||||
Logger.error(`Sending transaction "${name}" on contract "${this.contractName}" failed.`)
|
||||
Logger.error(`Parameters: ${JSON.stringify(mappedArgs, null, 2)} from: ${from}`)
|
||||
Logger.error(`Error: ${err.message}`)
|
||||
Logger.error(`From: ${from}`)
|
||||
Logger.error(`Parameters: ${JSON.stringify(mappedArgs, null, 2)}`)
|
||||
Logger.error("-".repeat(40))
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
@ -58,15 +58,20 @@ export default class ServiceAgreementTemplate extends OceanBase {
|
||||
return false
|
||||
}
|
||||
|
||||
const receipt = await serviceAgreement
|
||||
.setupAgreementTemplate(
|
||||
this.template.id,
|
||||
await this.getMethodReflections(),
|
||||
dependencyMatrix,
|
||||
Web3Provider.getWeb3().utils.fromAscii(this.template.templateName),
|
||||
fulfillmentIndices,
|
||||
this.template.fulfillmentOperator,
|
||||
templateOwnerAddress)
|
||||
let receipt
|
||||
try {
|
||||
receipt = await serviceAgreement
|
||||
.setupAgreementTemplate(
|
||||
this.template.id,
|
||||
await this.getMethodReflections(),
|
||||
dependencyMatrix,
|
||||
Web3Provider.getWeb3().utils.fromAscii(this.template.templateName),
|
||||
fulfillmentIndices,
|
||||
this.template.fulfillmentOperator,
|
||||
templateOwnerAddress)
|
||||
} catch (e) {
|
||||
throw new Error(`Is not possible to setup the agreement template`)
|
||||
}
|
||||
|
||||
const {serviceTemplateId, provider} = receipt.events.SetupAgreementTemplate.returnValues
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user