Skip to content

Commit

Permalink
tests: more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
moritzkirstein committed Apr 4, 2023
1 parent baafd2a commit 3a2a32d
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 44 deletions.
45 changes: 45 additions & 0 deletions test/asset/asset.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import assert from 'assert'
import { NautilusAsset } from '../../src/nautilus/asset/asset'
import {
datasetMetadata,
datasetService,
fixedPricing
} from '../fixtures/AssetConfig'
import { freParams } from '../fixtures/FixedRateExchangeParams'
import { getWeb3 } from '../fixtures/Web3'

describe('NautilusAsset', () => {
const web3 = getWeb3()
const owner = web3.defaultAccount

it('configures owner correctly', () => {
const asset = new NautilusAsset()
asset.metadata = datasetMetadata
asset.services.push(datasetService)
asset.pricing = { ...fixedPricing, freCreationParams: freParams as any }
asset.owner = owner

const config = asset.getConfig()

assert.equal(
config.tokenParamaters.datatokenParams.paymentCollector,
owner,
'datatokenParams.paymentCollector != owner'
)
assert.equal(
config.tokenParamaters.datatokenParams.minter,
owner,
'datatokenParams.minter != owner'
)
assert.equal(
config.tokenParamaters.nftParams.owner,
owner,
'nftParams.owner != owner'
)
assert.equal(
config.pricing.freCreationParams.owner,
owner,
'nftParams.owner != owner'
)
})
})
125 changes: 125 additions & 0 deletions test/asset/builder.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import { ZERO_ADDRESS } from '@oceanprotocol/lib'
import assert from 'assert'
import { AssetBuilder } from '../../src'
import {
algorithmMetadata,
datasetService,
fixedPricing
} from '../fixtures/AssetConfig'
import { datatokenParams } from '../fixtures/DatatokenParams'
import { nftParams } from '../fixtures/NftCreateData'

describe('AssetBuilder', () => {
it('builds asset.metadata correctly', async () => {
const builder = new AssetBuilder()

const { type, name, author, description, license, algorithm } =
algorithmMetadata

const asset = builder
.setType(type)
.setName(name)
.setAuthor(author)
.setDescription(description)
.setLicense(license)
.setAlgorithm(algorithm)
.build()

assert.deepEqual(
asset.metadata,
algorithmMetadata,
`asset.metadata does not equal the given input metadata`
)
})

it('builds asset.pricing correctly', async () => {
const builder = new AssetBuilder()

const asset = builder.setPricing(fixedPricing).build()

assert.deepEqual(
asset.pricing,
fixedPricing,
`asset.pricing does not equal the given input pricing schema`
)
})

it('builds asset.services correctly', async () => {
const builder = new AssetBuilder()

const asset = builder.addService(datasetService).build()

assert.ok(
asset.services.includes(datasetService),
`asset.services does not contain the given input service`
)
})

it('builds asset.datatokenCreateParams correctly', async () => {
const builder = new AssetBuilder()

const { name, symbol, ...params } = datatokenParams

const asset = builder
.setDatatokenData(params)
.setDatatokenNameAndSymbol(name, symbol)
.build()

assert.deepEqual(
asset.datatokenCreateParams,
datatokenParams,
`asset.datatokenCreateParams does not equal the given input datatokenParams`
)
})

it('builds asset.nftCreateData correctly', async () => {
const builder = new AssetBuilder()

const asset = builder.setNftData(nftParams).build()

assert.deepEqual(
asset.nftCreateData,
nftParams,
`asset.nftCreateData does not equal the given input nftParams`
)
})

it('builds asset.owner correctly', async () => {
const builder = new AssetBuilder()

const owner = 'owner'

const asset = builder.setOwner(owner).build()

assert.equal(
asset.owner,
owner,
'asset.owner does not match the given input owner'
)
})

it('builds with default values', async () => {
const builder = new AssetBuilder()

const asset = builder.build()

const { nftCreateData, datatokenCreateParams } = asset

// Default NftCreateData
assert.ok(typeof nftCreateData.name === 'string')
assert.ok(typeof nftCreateData.symbol === 'string')
assert.ok(typeof nftCreateData.templateIndex === 'number')
assert.ok(typeof nftCreateData.tokenURI === 'string')
assert.ok(typeof nftCreateData.transferable === 'boolean')

// Default DatatokenCreateParams
assert.ok(typeof datatokenCreateParams.cap === 'string')
assert.ok(typeof datatokenCreateParams.feeAmount === 'string')
assert.ok(datatokenCreateParams.feeToken === ZERO_ADDRESS)
assert.ok(datatokenCreateParams.mpFeeAddress === ZERO_ADDRESS)
assert.ok(typeof datatokenCreateParams.templateIndex === 'number')
// Datatoken name and symbol are undefined by default
assert.ok(typeof datatokenCreateParams.name === 'undefined')
assert.ok(typeof datatokenCreateParams.symbol === 'undefined')
})
})
44 changes: 0 additions & 44 deletions test/publishbuilder.test.ts

This file was deleted.

0 comments on commit 3a2a32d

Please sign in to comment.