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

Support integration tests on networks without Dispenser.

This commit is contained in:
Pedro Gutiérrez 2019-06-26 20:57:50 +02:00
parent 9a6782cfa3
commit bb082f0c8a
10 changed files with 89 additions and 36 deletions

View File

@ -19,9 +19,9 @@ before_script:
- ganache-cli --port 18545 > ganache-cli.log &
- git clone https://github.com/oceanprotocol/barge
- cd barge
- export AQUARIUS_VERSION=v0.2.9
- export BRIZO_VERSION=v0.3.10
- export KEEPER_VERSION=v0.9.7
- export AQUARIUS_VERSION=v0.3.4
- export BRIZO_VERSION=v0.3.12
- export KEEPER_VERSION=v0.10.3
- export KEEPER_OWNER_ROLE_ADDRESS="0xe2DD09d719Da89e5a3D0F2549c7E24566e947260"
- bash -x start_ocean.sh --no-pleuston --local-spree-node 2>&1 > start_ocean.log &
- cd ..

View File

@ -52,6 +52,5 @@ if (process.env.SEED_WORDS) {
)
}
export const config: Config & {forceVerbose: Config} = configJson as any
(config as any).forceVerbose = {...configJson, verbose: true}
export const config: Config & { forceVerbose: Config } = configJson as any
;(config as any).forceVerbose = { ...configJson, verbose: true }

View File

@ -12,13 +12,17 @@ describe('Asset Owners', () => {
let account1: Account
let account2: Account
const metadata = getMetadata()
let metadata = getMetadata()
before(async () => {
ocean = await Ocean.getInstance(config)
// Accounts
;[account1, account2] = await ocean.accounts.list()
if (!ocean.keeper.dispenser) {
metadata = getMetadata(0)
}
})
it('should be set correctly the owner of a asset', async () => {
@ -59,9 +63,13 @@ describe('Asset Owners', () => {
assert.equal(finalLength1 - initialLength, 0)
// Granting access
await account2.requestTokens(
+metadata.base.price * 10 ** -(await ocean.keeper.token.decimals())
)
try {
await account2.requestTokens(
+metadata.base.price *
10 ** -(await ocean.keeper.token.decimals())
)
} catch {}
await ocean.assets.order(
ddo.id,
ddo.findServiceByType('Access').serviceDefinitionId,

View File

@ -12,7 +12,7 @@ describe('Consume Asset', () => {
let publisher: Account
let consumer: Account
const metadata = getMetadata()
let metadata = getMetadata()
let ddo: DDO
let serviceAgreementSignatureResult: {
@ -25,6 +25,10 @@ describe('Consume Asset', () => {
// Accounts
;[publisher, consumer] = await ocean.accounts.list()
if (!ocean.keeper.dispenser) {
metadata = getMetadata(0)
}
})
it('should regiester a asset', async () => {
@ -47,7 +51,10 @@ describe('Consume Asset', () => {
const initialBalance = (await consumer.getBalance()).ocn
const claimedTokens =
+metadata.base.price * 10 ** -(await ocean.keeper.token.decimals())
await consumer.requestTokens(claimedTokens)
try {
await consumer.requestTokens(claimedTokens)
} catch {}
assert.equal(
(await consumer.getBalance()).ocn,

View File

@ -15,13 +15,17 @@ describe('Consume Asset (Brizo)', () => {
let ddo: DDO
let agreementId: string
const metadata = getMetadata()
let metadata = getMetadata()
before(async () => {
ocean = await Ocean.getInstance(config)
// Accounts
;[publisher, consumer] = await ocean.accounts.list()
if (!ocean.keeper.dispenser) {
metadata = getMetadata(0)
}
})
after(() => {
@ -48,9 +52,12 @@ describe('Consume Asset (Brizo)', () => {
it('should order the asset', async () => {
const accessService = ddo.findServiceByType('Access')
await consumer.requestTokens(
+metadata.base.price * 10 ** -(await ocean.keeper.token.decimals())
)
try {
await consumer.requestTokens(
+metadata.base.price *
10 ** -(await ocean.keeper.token.decimals())
)
} catch {}
const steps = []
agreementId = await ocean.assets

View File

@ -16,24 +16,29 @@ xdescribe('Consume Asset (Large size)', () => {
let ddo: DDO
let agreementId: string
const baseMetadata = getMetadata()
const metadata = {
...baseMetadata,
base: {
...baseMetadata.base,
files: [
{
url: 'https://speed.hetzner.de/1GB.bin'
}
]
}
}
let baseMetadata = getMetadata()
let metadata = getMetadata()
before(async () => {
ocean = await Ocean.getInstance(config)
// Accounts
;[publisher, consumer] = await ocean.accounts.list()
if (!ocean.keeper.dispenser) {
baseMetadata = getMetadata(0)
}
metadata = {
...baseMetadata,
base: {
...baseMetadata.base,
files: [
{
url: 'https://speed.hetzner.de/1GB.bin'
}
]
}
}
})
it('should regiester an asset', async () => {
@ -45,7 +50,12 @@ xdescribe('Consume Asset (Large size)', () => {
it('should order the asset', async () => {
const accessService = ddo.findServiceByType('Access')
await consumer.requestTokens(metadata.base.price)
try {
await consumer.requestTokens(
+metadata.base.price *
10 ** -(await ocean.keeper.token.decimals())
)
} catch {}
agreementId = await ocean.assets.order(
ddo.id,

View File

@ -18,7 +18,7 @@ describe('Register Escrow Access Secret Store Template', () => {
const url = 'https://example.com/did/ocean/test-attr-example.txt'
const checksum = 'b'.repeat(32)
const escrowAmount = 12
let escrowAmount = 12
let templateManagerOwner: Account
let publisher: Account
@ -44,6 +44,10 @@ describe('Register Escrow Access Secret Store Template', () => {
keeper.conditions.accessSecretStoreCondition
lockRewardCondition = keeper.conditions.lockRewardCondition
escrowReward = keeper.conditions.escrowReward
if (!ocean.keeper.dispenser) {
escrowAmount = 0
}
})
describe('Propose and approve template', () => {
@ -169,7 +173,9 @@ describe('Register Escrow Access Secret Store Template', () => {
})
it('should fulfill LockRewardCondition', async () => {
await consumer.requestTokens(escrowAmount)
try {
await consumer.requestTokens(escrowAmount)
} catch {}
await keeper.token.approve(
lockRewardCondition.getAddress(),
@ -259,7 +265,9 @@ describe('Register Escrow Access Secret Store Template', () => {
})
it('should fulfill the conditions from consumer side', async () => {
await consumer.requestTokens(escrowAmount)
try {
await consumer.requestTokens(escrowAmount)
} catch {}
await ocean.agreements.conditions.lockReward(
agreementId,

View File

@ -14,8 +14,9 @@ describe('Search Asset', () => {
const testHash = Math.random()
.toString(36)
.substr(2)
let price
const metadataGenerator = (name: string) =>
generateMetadata(`${name}${testHash}`)
generateMetadata(`${name}${testHash}`, price)
let test1length
let test2length
@ -38,6 +39,10 @@ describe('Search Asset', () => {
.length
test3length = (await ocean.assets.search(`Test3${testHash}`)).results
.length
if (!ocean.keeper.dispenser) {
price = 0
}
})
it('should regiester some a asset', async () => {

View File

@ -44,12 +44,17 @@ const metadata: Partial<MetaData> = {
}
}
export const generateMetadata = (name: string): Partial<MetaData> => ({
export const generateMetadata = (
name: string,
price?: number
): Partial<MetaData> => ({
...metadata,
base: {
...metadata.base,
name
name,
price: (price || 21) + '0'.repeat(18)
}
})
export const getMetadata = () => generateMetadata('TestAsset')
export const getMetadata = (price?: number) =>
generateMetadata('TestAsset', price)

View File

@ -172,4 +172,8 @@ export class EscrowAccessSecretStoreTemplate extends AgreementTemplate {
escrowRewardId
}
}
public async getAgreementData(agreementId: string) {
return this.call<any>('getAgreementData', [zeroX(agreementId)])
}
}