1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00

Merge branch 'issue-1356-rewrite-testcontracthandler-helper-class' into issue-1346-rewrite-datatoken-test

This commit is contained in:
Miquel A. Cabot 2022-03-29 23:13:02 +02:00
commit 623261d548
19 changed files with 1519 additions and 1428 deletions

File diff suppressed because it is too large Load Diff

2
package-lock.json generated
View File

@ -31068,4 +31068,4 @@
"dev": true "dev": true
} }
} }
} }

View File

@ -1,7 +1,7 @@
{ {
"name": "@oceanprotocol/lib", "name": "@oceanprotocol/lib",
"source": "./src/index.ts", "source": "./src/index.ts",
"version": "1.0.0-next.29", "version": "1.0.0-next.32",
"description": "JavaScript client library for Ocean Protocol", "description": "JavaScript client library for Ocean Protocol",
"main": "./dist/lib.js", "main": "./dist/lib.js",
"umd:main": "dist/lib.umd.js", "umd:main": "dist/lib.umd.js",
@ -90,7 +90,7 @@
"mock-local-storage": "^1.1.20", "mock-local-storage": "^1.1.20",
"nyc": "^15.1.0", "nyc": "^15.1.0",
"ora": "5.4.1", "ora": "5.4.1",
"prettier": "^2.6.0", "prettier": "^2.6.1",
"release-it": "^14.13.1", "release-it": "^14.13.1",
"source-map-support": "^0.5.19", "source-map-support": "^0.5.19",
"ts-node": "^10.7.0", "ts-node": "^10.7.0",

View File

@ -12,7 +12,7 @@ const { description, version } = libJsPackage
// Setup our paths, relative to project root // Setup our paths, relative to project root
const outPath = './dist/lib.json' const outPath = './dist/lib.json'
const files = ['./src/lib.ts'] const files = ['./src/index.ts']
// specifically point to tsconfig, otherwise TypeDoc fails // specifically point to tsconfig, otherwise TypeDoc fails
const config = typescript.findConfigFile('./tsconfig.js', typescript.sys.fileExists) const config = typescript.findConfigFile('./tsconfig.js', typescript.sys.fileExists)
@ -30,8 +30,8 @@ const generateJson = async () => {
entryPoints: files entryPoints: files
}) })
const src = app.expandInputFiles(files) const src = app.getEntryPoints()
const project = app.convert(src) const project = app.converter.convert(src)
// Generate the JSON file // Generate the JSON file
await app.generateJson(project, outPath) await app.generateJson(project, outPath)

View File

@ -1,7 +1,7 @@
export interface Erc20CreateParams { export interface Erc20CreateParams {
templateIndex: number templateIndex: number
minter: string minter: string
feeManager: string paymentCollector: string
mpFeeAddress: string mpFeeAddress: string
feeToken: string feeToken: string
feeAmount: string feeAmount: string

View File

@ -492,14 +492,14 @@ export class NftFactory {
if ((await this.getOwner()) !== address) { if ((await this.getOwner()) !== address) {
throw new Error(`Caller is not Factory Owner`) throw new Error(`Caller is not Factory Owner`)
} }
if (templateIndex > (await this.getCurrentNFTTemplateCount())) { if (templateIndex > (await this.getCurrentTokenTemplateCount())) {
throw new Error(`Template index doesnt exist`) throw new Error(`Template index doesnt exist`)
} }
if (templateIndex === 0) { if (templateIndex === 0) {
throw new Error(`Template index cannot be ZERO`) throw new Error(`Template index cannot be ZERO`)
} }
if ((await this.getNFTTemplate(templateIndex)).isActive === false) { if ((await this.getTokenTemplate(templateIndex)).isActive === false) {
throw new Error(`Template is already disabled`) throw new Error(`Template is already disabled`)
} }
const estGas = await this.estGasDisableTokenTemplate(address, templateIndex) const estGas = await this.estGasDisableTokenTemplate(address, templateIndex)
@ -551,7 +551,7 @@ export class NftFactory {
if ((await this.getOwner()) !== address) { if ((await this.getOwner()) !== address) {
throw new Error(`Caller is not Factory Owner`) throw new Error(`Caller is not Factory Owner`)
} }
if (templateIndex > (await this.getCurrentNFTTemplateCount())) { if (templateIndex > (await this.getCurrentTokenTemplateCount())) {
throw new Error(`Template index doesnt exist`) throw new Error(`Template index doesnt exist`)
} }

View File

@ -156,7 +156,7 @@ export class FixedRateExchange {
* @param {String} maxBaseTokenAmount max amount of baseToken we want to pay for datatokenAmount * @param {String} maxBaseTokenAmount max amount of baseToken we want to pay for datatokenAmount
* @param {String} address User address * @param {String} address User address
* @param {String} consumeMarketAddress consumeMarketAddress * @param {String} consumeMarketAddress consumeMarketAddress
* @param {String} consumeMarketFee consumeMarketFee * @param {String} consumeMarketFee consumeMarketFee in fraction
* @return {Promise<TransactionReceipt>} transaction receipt * @return {Promise<TransactionReceipt>} transaction receipt
*/ */
public async buyDT( public async buyDT(
@ -168,10 +168,7 @@ export class FixedRateExchange {
consumeMarketFee: string = '0' consumeMarketFee: string = '0'
): Promise<TransactionReceipt> { ): Promise<TransactionReceipt> {
const exchange = await this.getExchange(exchangeId) const exchange = await this.getExchange(exchangeId)
const consumeMarketFeeFormatted = await this.amountToUnits( const consumeMarketFeeFormatted = this.web3.utils.toWei(consumeMarketFee)
exchange.baseToken,
consumeMarketFee
)
const dtAmountFormatted = await this.amountToUnits( const dtAmountFormatted = await this.amountToUnits(
exchange.datatoken, exchange.datatoken,
datatokenAmount datatokenAmount
@ -255,7 +252,7 @@ export class FixedRateExchange {
* @param {String} minBaseTokenAmount min amount of baseToken we want to receive back * @param {String} minBaseTokenAmount min amount of baseToken we want to receive back
* @param {String} address User address * @param {String} address User address
* @param {String} consumeMarketAddress consumeMarketAddress * @param {String} consumeMarketAddress consumeMarketAddress
* @param {String} consumeMarketFee consumeMarketFee * @param {String} consumeMarketFee consumeMarketFee in fraction
* @return {Promise<TransactionReceipt>} transaction receipt * @return {Promise<TransactionReceipt>} transaction receipt
*/ */
public async sellDT( public async sellDT(
@ -267,10 +264,7 @@ export class FixedRateExchange {
consumeMarketFee: string = '0' consumeMarketFee: string = '0'
): Promise<TransactionReceipt> { ): Promise<TransactionReceipt> {
const exchange = await this.getExchange(exchangeId) const exchange = await this.getExchange(exchangeId)
const consumeMarketFeeFormatted = await this.amountToUnits( const consumeMarketFeeFormatted = this.web3.utils.toWei(consumeMarketFee)
exchange.baseToken,
consumeMarketFee
)
const dtAmountFormatted = await this.amountToUnits( const dtAmountFormatted = await this.amountToUnits(
exchange.datatoken, exchange.datatoken,
datatokenAmount datatokenAmount
@ -571,7 +565,7 @@ export class FixedRateExchange {
* calcBaseInGivenOutDT - Calculates how many base tokens are needed to get specified amount of datatokens * calcBaseInGivenOutDT - Calculates how many base tokens are needed to get specified amount of datatokens
* @param {String} exchangeId ExchangeId * @param {String} exchangeId ExchangeId
* @param {string} datatokenAmount Amount of datatokens user wants to buy * @param {string} datatokenAmount Amount of datatokens user wants to buy
* @param {String} consumeMarketFee consumeMarketFee * @param {String} consumeMarketFee consumeMarketFee in fraction
* @return {Promise<PriceAndFees>} how many base tokens are needed and fees * @return {Promise<PriceAndFees>} how many base tokens are needed and fees
*/ */
public async calcBaseInGivenOutDT( public async calcBaseInGivenOutDT(
@ -584,7 +578,7 @@ export class FixedRateExchange {
.calcBaseInGivenOutDT( .calcBaseInGivenOutDT(
exchangeId, exchangeId,
await this.amountToUnits(fixedRateExchange.datatoken, datatokenAmount), await this.amountToUnits(fixedRateExchange.datatoken, datatokenAmount),
await this.amountToUnits(fixedRateExchange.baseToken, consumeMarketFee) this.web3.utils.toWei(consumeMarketFee)
) )
.call() .call()
@ -613,7 +607,7 @@ export class FixedRateExchange {
* getBTOut - returns amount in baseToken that user will receive for datatokenAmount sold * getBTOut - returns amount in baseToken that user will receive for datatokenAmount sold
* @param {String} exchangeId ExchangeId * @param {String} exchangeId ExchangeId
* @param {Number} datatokenAmount Amount of datatokens * @param {Number} datatokenAmount Amount of datatokens
* @param {String} consumeMarketFee consumeMarketFee * @param {String} consumeMarketFee consumeMarketFee in fraction
* @return {Promise<string>} Amount of baseTokens user will receive * @return {Promise<string>} Amount of baseTokens user will receive
*/ */
public async getAmountBTOut( public async getAmountBTOut(
@ -626,7 +620,7 @@ export class FixedRateExchange {
.calcBaseOutGivenInDT( .calcBaseOutGivenInDT(
exchangeId, exchangeId,
await this.amountToUnits(exchange.datatoken, datatokenAmount), await this.amountToUnits(exchange.datatoken, datatokenAmount),
await this.amountToUnits(exchange.baseToken, consumeMarketFee) this.web3.utils.toWei(consumeMarketFee)
) )
.call() .call()

View File

@ -528,26 +528,21 @@ export class Provider {
} }
} }
/** Get status for a specific jobId/documentId/owner. /** Get compute status for a specific jobId/documentId/owner.
* @param {string} did * @param {string} providerUri The URI of the provider we want to query
* @param {string} consumerAddress * @param {string} consumerAddress The consumer ethereum address
* @param {string} providerUri * @param {string} jobId The ID of a compute job.
* @param {Web3} web3 * @param {string} did The ID of the asset
* @param {AbortSignal} signal abort signal * @param {AbortSignal} signal abort signal
* @param {string} jobId
* @return {Promise<ComputeJob | ComputeJob[]>} * @return {Promise<ComputeJob | ComputeJob[]>}
*/ */
public async computeStatus( public async computeStatus(
providerUri: string, providerUri: string,
signal?: AbortSignal, consumerAddress: string,
jobId?: string, jobId?: string,
did?: string, did?: string,
consumerAddress?: string signal?: AbortSignal
): Promise<ComputeJob | ComputeJob[]> { ): Promise<ComputeJob | ComputeJob[]> {
if (!jobId && !did && !consumerAddress) {
throw new Error('You need at least one of jobId, did, consumerAddress')
}
const providerEndpoints = await this.getEndpoints(providerUri) const providerEndpoints = await this.getEndpoints(providerUri)
const serviceEndpoints = await this.getServiceEndpoints( const serviceEndpoints = await this.getServiceEndpoints(
providerUri, providerUri,
@ -557,8 +552,8 @@ export class Provider {
? this.getEndpointURL(serviceEndpoints, 'computeStatus').urlPath ? this.getEndpointURL(serviceEndpoints, 'computeStatus').urlPath
: null : null
let url = '?documentId=' + noZeroX(did) let url = `?consumerAddress=${consumerAddress}`
url += (consumerAddress && `&consumerAddress=${consumerAddress}`) || '' url += (did && `&documentId=${noZeroX(did)}`) || ''
url += (jobId && `&jobId=${jobId}`) || '' url += (jobId && `&jobId=${jobId}`) || ''
if (!computeStatusUrl) return null if (!computeStatusUrl) return null

View File

@ -44,7 +44,7 @@ export class Nft {
* @param {String} nftAddress ERC721 addreess * @param {String} nftAddress ERC721 addreess
* @param {String} address User address * @param {String} address User address
* @param {String} minter User set as initial minter for the ERC20 * @param {String} minter User set as initial minter for the ERC20
* @param {String} feeManager initial feeManager for this DT * @param {String} paymentCollector initial paymentCollector for this DT
* @param {String} mpFeeAddress Consume marketplace fee address * @param {String} mpFeeAddress Consume marketplace fee address
* @param {String} feeToken address of the token marketplace wants to add fee on top * @param {String} feeToken address of the token marketplace wants to add fee on top
* @param {String} feeAmount amount of feeToken to be transferred to mpFeeAddress on top, will be converted to WEI * @param {String} feeAmount amount of feeToken to be transferred to mpFeeAddress on top, will be converted to WEI
@ -59,7 +59,7 @@ export class Nft {
nftAddress: string, nftAddress: string,
address: string, address: string,
minter: string, minter: string,
feeManager: string, paymentCollector: string,
mpFeeAddress: string, mpFeeAddress: string,
feeToken: string, feeToken: string,
feeAmount: string, feeAmount: string,
@ -82,7 +82,7 @@ export class Nft {
.createERC20( .createERC20(
templateIndex, templateIndex,
[name, symbol], [name, symbol],
[minter, feeManager, mpFeeAddress, feeToken], [minter, paymentCollector, mpFeeAddress, feeToken],
[this.web3.utils.toWei(cap), this.web3.utils.toWei(feeAmount)], [this.web3.utils.toWei(cap), this.web3.utils.toWei(feeAmount)],
[] []
) )
@ -98,7 +98,7 @@ export class Nft {
* @param {String} nftAddress ERC721 addreess * @param {String} nftAddress ERC721 addreess
* @param {String} address User address * @param {String} address User address
* @param {String} minter User set as initial minter for the ERC20 * @param {String} minter User set as initial minter for the ERC20
* @param {String} feeManager initial feeManager for this DT * @param {String} paymentCollector initial paymentCollector for this DT
* @param {String} mpFeeAddress Consume marketplace fee address * @param {String} mpFeeAddress Consume marketplace fee address
* @param {String} feeToken address of the token marketplace wants to add fee on top * @param {String} feeToken address of the token marketplace wants to add fee on top
* @param {String} feeAmount amount of feeToken to be transferred to mpFeeAddress on top, will be converted to WEI * @param {String} feeAmount amount of feeToken to be transferred to mpFeeAddress on top, will be converted to WEI
@ -112,7 +112,7 @@ export class Nft {
nftAddress: string, nftAddress: string,
address: string, address: string,
minter: string, minter: string,
feeManager: string, paymentCollector: string,
mpFeeAddress: string, mpFeeAddress: string,
feeToken: string, feeToken: string,
feeAmount: string, feeAmount: string,
@ -141,7 +141,7 @@ export class Nft {
nftAddress, nftAddress,
address, address,
minter, minter,
feeManager, paymentCollector,
mpFeeAddress, mpFeeAddress,
feeToken, feeToken,
feeAmount, feeAmount,
@ -157,7 +157,7 @@ export class Nft {
.createERC20( .createERC20(
templateIndex, templateIndex,
[name, symbol], [name, symbol],
[minter, feeManager, mpFeeAddress, feeToken], [minter, paymentCollector, mpFeeAddress, feeToken],
[this.web3.utils.toWei(cap), this.web3.utils.toWei(feeAmount)], [this.web3.utils.toWei(cap), this.web3.utils.toWei(feeAmount)],
[] []
) )

View File

@ -45,7 +45,7 @@ export function getErcCreationParams(ercParams: Erc20CreateParams): any {
strings: [ercParams.name || name, ercParams.symbol || symbol], strings: [ercParams.name || name, ercParams.symbol || symbol],
addresses: [ addresses: [
ercParams.minter, ercParams.minter,
ercParams.feeManager, ercParams.paymentCollector,
ercParams.mpFeeAddress, ercParams.mpFeeAddress,
ercParams.feeToken ercParams.feeToken
], ],

View File

@ -142,7 +142,7 @@ describe('Simple compute tests', async () => {
templateIndex: 1, templateIndex: 1,
cap: '100000', cap: '100000',
feeAmount: '0', feeAmount: '0',
feeManager: '0x0000000000000000000000000000000000000000', paymentCollector: '0x0000000000000000000000000000000000000000',
feeToken: '0x0000000000000000000000000000000000000000', feeToken: '0x0000000000000000000000000000000000000000',
minter: publisherAccount, minter: publisherAccount,
mpFeeAddress: '0x0000000000000000000000000000000000000000' mpFeeAddress: '0x0000000000000000000000000000000000000000'
@ -191,7 +191,7 @@ describe('Simple compute tests', async () => {
templateIndex: 1, templateIndex: 1,
cap: '100000', cap: '100000',
feeAmount: '0', feeAmount: '0',
feeManager: '0x0000000000000000000000000000000000000000', paymentCollector: '0x0000000000000000000000000000000000000000',
feeToken: '0x0000000000000000000000000000000000000000', feeToken: '0x0000000000000000000000000000000000000000',
minter: publisherAccount, minter: publisherAccount,
mpFeeAddress: '0x0000000000000000000000000000000000000000' mpFeeAddress: '0x0000000000000000000000000000000000000000'
@ -338,10 +338,9 @@ describe('Simple compute tests', async () => {
assert(computeJobs, 'Cannot start compute job') assert(computeJobs, 'Cannot start compute job')
const jobStatus = await ProviderInstance.computeStatus( const jobStatus = await ProviderInstance.computeStatus(
providerUrl, providerUrl,
null, consumerAccount,
computeJobs[0].jobId, computeJobs[0].jobId,
resolvedDDOAsset.id, resolvedDDOAsset.id
consumerAccount
) )
assert(jobStatus) assert(jobStatus)
}) })

View File

@ -102,7 +102,7 @@ describe('Publish tests', async () => {
templateIndex: 1, templateIndex: 1,
cap: '100000', cap: '100000',
feeAmount: '0', feeAmount: '0',
feeManager: ZERO_ADDRESS, paymentCollector: ZERO_ADDRESS,
feeToken: ZERO_ADDRESS, feeToken: ZERO_ADDRESS,
minter: accounts[0], minter: accounts[0],
mpFeeAddress: ZERO_ADDRESS mpFeeAddress: ZERO_ADDRESS
@ -181,7 +181,7 @@ describe('Publish tests', async () => {
templateIndex: 1, templateIndex: 1,
cap: '100000', cap: '100000',
feeAmount: '0', feeAmount: '0',
feeManager: ZERO_ADDRESS, paymentCollector: ZERO_ADDRESS,
feeToken: ZERO_ADDRESS, feeToken: ZERO_ADDRESS,
minter: accounts[0], minter: accounts[0],
mpFeeAddress: ZERO_ADDRESS mpFeeAddress: ZERO_ADDRESS
@ -257,7 +257,7 @@ describe('Publish tests', async () => {
templateIndex: 1, templateIndex: 1,
cap: '100000', cap: '100000',
feeAmount: '0', feeAmount: '0',
feeManager: ZERO_ADDRESS, paymentCollector: ZERO_ADDRESS,
feeToken: ZERO_ADDRESS, feeToken: ZERO_ADDRESS,
minter: accounts[0], minter: accounts[0],
mpFeeAddress: ZERO_ADDRESS mpFeeAddress: ZERO_ADDRESS

View File

@ -82,7 +82,7 @@ describe('Simple Publish & consume test', async () => {
templateIndex: 1, templateIndex: 1,
cap: '100000', cap: '100000',
feeAmount: '0', feeAmount: '0',
feeManager: '0x0000000000000000000000000000000000000000', paymentCollector: '0x0000000000000000000000000000000000000000',
feeToken: '0x0000000000000000000000000000000000000000', feeToken: '0x0000000000000000000000000000000000000000',
minter: publisherAccount, minter: publisherAccount,
mpFeeAddress: '0x0000000000000000000000000000000000000000' mpFeeAddress: '0x0000000000000000000000000000000000000000'

View File

@ -77,7 +77,7 @@ describe('Nft Factory test', () => {
const ercParams: Erc20CreateParams = { const ercParams: Erc20CreateParams = {
templateIndex: 1, templateIndex: 1,
minter: factoryOwner, minter: factoryOwner,
feeManager: user3, paymentCollector: user3,
mpFeeAddress: user2, mpFeeAddress: user2,
feeToken: '0x0000000000000000000000000000000000000000', feeToken: '0x0000000000000000000000000000000000000000',
cap: '10000', cap: '10000',
@ -113,7 +113,7 @@ describe('Nft Factory test', () => {
const ercParams: Erc20CreateParams = { const ercParams: Erc20CreateParams = {
templateIndex: 1, templateIndex: 1,
minter: user2, minter: user2,
feeManager: user3, paymentCollector: user3,
mpFeeAddress: user2, mpFeeAddress: user2,
feeToken: '0x0000000000000000000000000000000000000000', feeToken: '0x0000000000000000000000000000000000000000',
cap: '1000000', cap: '1000000',
@ -163,7 +163,7 @@ describe('Nft Factory test', () => {
const ercParams: Erc20CreateParams = { const ercParams: Erc20CreateParams = {
templateIndex: 1, templateIndex: 1,
minter: factoryOwner, minter: factoryOwner,
feeManager: user3, paymentCollector: user3,
mpFeeAddress: user2, mpFeeAddress: user2,
feeToken: '0x0000000000000000000000000000000000000000', feeToken: '0x0000000000000000000000000000000000000000',
cap: '1000000', cap: '1000000',
@ -213,7 +213,7 @@ describe('Nft Factory test', () => {
const ercParams: Erc20CreateParams = { const ercParams: Erc20CreateParams = {
templateIndex: 1, templateIndex: 1,
minter: factoryOwner, minter: factoryOwner,
feeManager: user3, paymentCollector: user3,
mpFeeAddress: user2, mpFeeAddress: user2,
feeToken: '0x0000000000000000000000000000000000000000', feeToken: '0x0000000000000000000000000000000000000000',
cap: '1000000', cap: '1000000',
@ -344,4 +344,72 @@ describe('Nft Factory test', () => {
) )
assert((await nftFactory.checkNFT(nftAddress)) === nftAddress) assert((await nftFactory.checkNFT(nftAddress)) === nftAddress)
}) })
it('#addNFTTemplate - should add a new erc721 token template', async () => {
const currentNFTTemplateCount = await nftFactory.getCurrentNFTTemplateCount()
await nftFactory.addNFTTemplate(factoryOwner, contracts.erc721TemplateAddress)
expect(
(await nftFactory.getCurrentNFTTemplateCount()) === currentNFTTemplateCount + 1
)
})
it('#disableNFTTemplate - should disable an erc721 token template', async () => {
const currentNFTTemplateCount = await nftFactory.getCurrentNFTTemplateCount()
let nftTemplate = await nftFactory.getNFTTemplate(currentNFTTemplateCount)
assert(nftTemplate.isActive === true)
await nftFactory.disableNFTTemplate(factoryOwner, currentNFTTemplateCount)
nftTemplate = await nftFactory.getNFTTemplate(currentNFTTemplateCount)
assert(nftTemplate.isActive === false)
})
it('#reactivateNFTTemplate - should reactivate an erc721 previously disabled token template', async () => {
const currentNFTTemplateCount = await nftFactory.getCurrentNFTTemplateCount()
let nftTemplate = await nftFactory.getNFTTemplate(currentNFTTemplateCount)
assert(nftTemplate.isActive === false)
await nftFactory.reactivateNFTTemplate(factoryOwner, currentNFTTemplateCount)
nftTemplate = await nftFactory.getNFTTemplate(currentNFTTemplateCount)
assert(nftTemplate.isActive === true)
})
it('#addTokenTemplate - should add a new erc20 token template', async () => {
const currentTokenTemplateCount = await nftFactory.getCurrentTokenTemplateCount()
await nftFactory.addTokenTemplate(factoryOwner, contracts.erc20TemplateAddress)
expect(
(await nftFactory.getCurrentTokenTemplateCount()) === currentTokenTemplateCount + 1
)
})
it('#disableTokenTemplate - should disable an erc20 token template', async () => {
const currentTokenTemplateCount = await nftFactory.getCurrentTokenTemplateCount()
let tokenTemplate = await nftFactory.getTokenTemplate(currentTokenTemplateCount)
assert(tokenTemplate.isActive === true)
await nftFactory.disableTokenTemplate(factoryOwner, currentTokenTemplateCount)
tokenTemplate = await nftFactory.getTokenTemplate(currentTokenTemplateCount)
assert(tokenTemplate.isActive === false)
})
it('#reactivateTokenTemplate - should reactivate an previously disabled erc20 token template', async () => {
const currentTokenTemplateCount = await nftFactory.getCurrentTokenTemplateCount()
let tokenTemplate = await nftFactory.getTokenTemplate(currentTokenTemplateCount)
assert(tokenTemplate.isActive === false)
await nftFactory.reactivateTokenTemplate(factoryOwner, currentTokenTemplateCount)
tokenTemplate = await nftFactory.getTokenTemplate(currentTokenTemplateCount)
assert(tokenTemplate.isActive === true)
})
}) })

View File

@ -101,7 +101,7 @@ describe('Router unit test', () => {
const ercParams: Erc20CreateParams = { const ercParams: Erc20CreateParams = {
templateIndex: 1, templateIndex: 1,
minter: factoryOwner, minter: factoryOwner,
feeManager: user3, paymentCollector: user3,
mpFeeAddress: factoryOwner, mpFeeAddress: factoryOwner,
feeToken: '0x0000000000000000000000000000000000000000', feeToken: '0x0000000000000000000000000000000000000000',
cap: '1000000', cap: '1000000',
@ -154,7 +154,7 @@ describe('Router unit test', () => {
const ercParams2: Erc20CreateParams = { const ercParams2: Erc20CreateParams = {
templateIndex: 1, templateIndex: 1,
minter: factoryOwner, minter: factoryOwner,
feeManager: user3, paymentCollector: user3,
mpFeeAddress: factoryOwner, mpFeeAddress: factoryOwner,
feeToken: '0x0000000000000000000000000000000000000000', feeToken: '0x0000000000000000000000000000000000000000',
cap: '1000000', cap: '1000000',

View File

@ -111,7 +111,7 @@ describe('Pool unit test', () => {
const ercParams: Erc20CreateParams = { const ercParams: Erc20CreateParams = {
templateIndex: 1, templateIndex: 1,
minter: factoryOwner, minter: factoryOwner,
feeManager: user3, paymentCollector: user3,
mpFeeAddress: factoryOwner, mpFeeAddress: factoryOwner,
feeToken: '0x0000000000000000000000000000000000000000', feeToken: '0x0000000000000000000000000000000000000000',
cap: '1000000', cap: '1000000',
@ -159,11 +159,11 @@ describe('Pool unit test', () => {
expect(await erc20Contract.methods.balanceOf(user2).call()).to.equal('0') expect(await erc20Contract.methods.balanceOf(user2).call()).to.equal('0')
}) })
it('#sharesBalance - should return user shares balance (datatoken balance, LPT balance, etc) ', async () => { // it('#sharesBalance - should return user shares balance (datatoken balance, LPT balance, etc) ', async () => {
expect(await daiContract.methods.balanceOf(user2).call()).to.equal( // expect(await daiContract.methods.balanceOf(user2).call()).to.equal(
web3.utils.toWei(await pool.sharesBalance(user2, contracts.daiAddress)) // web3.utils.toWei(await pool.sharesBalance(user2, contracts.daiAddress))
) // )
}) // })
it('#getNumTokens - should return num of tokens in pool (2)', async () => { it('#getNumTokens - should return num of tokens in pool (2)', async () => {
expect(await pool.getNumTokens(poolAddress)).to.equal('2') expect(await pool.getNumTokens(poolAddress)).to.equal('2')
@ -566,7 +566,7 @@ describe('Pool unit test', () => {
const ercParams: Erc20CreateParams = { const ercParams: Erc20CreateParams = {
templateIndex: 1, templateIndex: 1,
minter: factoryOwner, minter: factoryOwner,
feeManager: user3, paymentCollector: user3,
mpFeeAddress: factoryOwner, mpFeeAddress: factoryOwner,
feeToken: '0x0000000000000000000000000000000000000000', feeToken: '0x0000000000000000000000000000000000000000',
cap: '1000000', cap: '1000000',
@ -687,11 +687,11 @@ describe('Pool unit test', () => {
) )
}) })
it('#sharesBalance - should return user shares balance (datatoken balance, LPT balance, etc) ', async () => { // it('#sharesBalance - should return user shares balance (datatoken balance, LPT balance, etc) ', async () => {
expect(await usdcContract.methods.balanceOf(user2).call()).to.equal( // expect(await usdcContract.methods.balanceOf(user2).call()).to.equal(
await pool.sharesBalance(user2, contracts.usdcAddress) // await pool.sharesBalance(user2, contracts.usdcAddress)
) // )
}) // })
it('#getNumTokens - should return num of tokens in pool (2)', async () => { it('#getNumTokens - should return num of tokens in pool (2)', async () => {
expect(await pool.getNumTokens(poolAddress)).to.equal('2') expect(await pool.getNumTokens(poolAddress)).to.equal('2')

View File

@ -62,7 +62,7 @@ describe('Dispenser flow', () => {
const ercParams: Erc20CreateParams = { const ercParams: Erc20CreateParams = {
templateIndex: 1, templateIndex: 1,
minter: factoryOwner, minter: factoryOwner,
feeManager: user3, paymentCollector: user3,
mpFeeAddress: user2, mpFeeAddress: user2,
feeToken: '0x0000000000000000000000000000000000000000', feeToken: '0x0000000000000000000000000000000000000000',
cap: '10000', cap: '10000',

View File

@ -75,7 +75,7 @@ describe('Fixed Rate unit test', () => {
const ercParams: Erc20CreateParams = { const ercParams: Erc20CreateParams = {
templateIndex: 1, templateIndex: 1,
minter: factoryOwner, minter: factoryOwner,
feeManager: user3, paymentCollector: user3,
mpFeeAddress: factoryOwner, mpFeeAddress: factoryOwner,
feeToken: ADDRESS_ZERO, feeToken: ADDRESS_ZERO,
cap: '1000000', cap: '1000000',
@ -339,26 +339,26 @@ describe('Fixed Rate unit test', () => {
// Only allowance left since dt is ZERO // Only allowance left since dt is ZERO
expect(result2.dtSupply).to.equal('990') expect(result2.dtSupply).to.equal('990')
}) })
it('#collectMarketFee- should collect marketFee and send it to marketFeeCollector, anyone can call it', async () => { // it('#collectMarketFee- should collect marketFee and send it to marketFeeCollector, anyone can call it', async () => {
let result = await fixedRate.getFeesInfo(exchangeId) // let result = await fixedRate.getFeesInfo(exchangeId)
// we made 2 swaps for 10 DT at rate 1, the fee is 0.1% for market and always in baseToken so it's 0.01 DAI // // we made 2 swaps for 10 DT at rate 1, the fee is 0.1% for market and always in baseToken so it's 0.01 DAI
// plus another swap for 1 DT // // plus another swap for 1 DT
expect(result.marketFeeAvailable).to.equal('0.021') // formatted for baseToken decimals // expect(result.marketFeeAvailable).to.equal('0.021') // formatted for baseToken decimals
// same for ocean fee // // same for ocean fee
expect(result.oceanFeeAvailable).to.equal('0.042') // formatted for baseToken decimals // expect(result.oceanFeeAvailable).to.equal('0.042') // formatted for baseToken decimals
expect(result.marketFeeCollector).to.equal(user3) // expect(result.marketFeeCollector).to.equal(user3)
// user4 calls collectMarketFee // // user4 calls collectMarketFee
await fixedRate.collectMarketFee(user4, exchangeId) // await fixedRate.collectMarketFee(user4, exchangeId)
result = await fixedRate.getFeesInfo(exchangeId) // result = await fixedRate.getFeesInfo(exchangeId)
expect(result.marketFeeAvailable).to.equal('0') // expect(result.marketFeeAvailable).to.equal('0')
// ocean fee still available // // ocean fee still available
expect(result.oceanFeeAvailable).to.equal('0.042') // expect(result.oceanFeeAvailable).to.equal('0.042')
// user3 is the marketFeeCollector // // user3 is the marketFeeCollector
expect(await daiContract.methods.balanceOf(user3).call()).to.equal( // expect(await daiContract.methods.balanceOf(user3).call()).to.equal(
web3.utils.toWei('1.021') // web3.utils.toWei('1.021')
) // )
}) // })
it('#updateMarketFee- should update Market fee if market fee collector', async () => { it('#updateMarketFee- should update Market fee if market fee collector', async () => {
expect((await fixedRate.getFeesInfo(exchangeId)).marketFee).to.equal('0.001') expect((await fixedRate.getFeesInfo(exchangeId)).marketFee).to.equal('0.001')
@ -393,7 +393,7 @@ describe('Fixed Rate unit test', () => {
const ercParams: Erc20CreateParams = { const ercParams: Erc20CreateParams = {
templateIndex: 1, templateIndex: 1,
minter: factoryOwner, minter: factoryOwner,
feeManager: user3, paymentCollector: user3,
mpFeeAddress: factoryOwner, mpFeeAddress: factoryOwner,
feeToken: ADDRESS_ZERO, feeToken: ADDRESS_ZERO,
cap: '1000000', cap: '1000000',

View File

@ -125,7 +125,7 @@ describe('SideStaking unit test', () => {
const ercParams: Erc20CreateParams = { const ercParams: Erc20CreateParams = {
templateIndex: 1, templateIndex: 1,
minter: factoryOwner, minter: factoryOwner,
feeManager: user3, paymentCollector: user3,
mpFeeAddress: factoryOwner, mpFeeAddress: factoryOwner,
feeToken: '0x0000000000000000000000000000000000000000', feeToken: '0x0000000000000000000000000000000000000000',
cap: '1000000', cap: '1000000',
@ -209,11 +209,11 @@ describe('SideStaking unit test', () => {
await sideStaking.getBaseTokenBalance(sideStakingAddress, erc20Token) await sideStaking.getBaseTokenBalance(sideStakingAddress, erc20Token)
).to.equal('0') ).to.equal('0')
}) })
it('#getDatatokenBalance ', async () => { // it('#getDatatokenBalance ', async () => {
expect( // expect(
await sideStaking.getDatatokenBalance(sideStakingAddress, erc20Token) // await sideStaking.getDatatokenBalance(sideStakingAddress, erc20Token)
).to.equal('997999.9999999999') // ).to.equal('997999.9999999999')
}) // })
it('#getvestingAmount ', async () => { it('#getvestingAmount ', async () => {
expect(await sideStaking.getvestingAmount(sideStakingAddress, erc20Token)).to.equal( expect(await sideStaking.getvestingAmount(sideStakingAddress, erc20Token)).to.equal(
@ -366,7 +366,7 @@ describe('SideStaking unit test', () => {
const ercParams: Erc20CreateParams = { const ercParams: Erc20CreateParams = {
templateIndex: 1, templateIndex: 1,
minter: factoryOwner, minter: factoryOwner,
feeManager: user3, paymentCollector: user3,
mpFeeAddress: factoryOwner, mpFeeAddress: factoryOwner,
feeToken: '0x0000000000000000000000000000000000000000', feeToken: '0x0000000000000000000000000000000000000000',
cap: '1000000', cap: '1000000',
@ -416,11 +416,11 @@ describe('SideStaking unit test', () => {
await sideStaking.getBaseTokenBalance(sideStakingAddress, erc20Token) await sideStaking.getBaseTokenBalance(sideStakingAddress, erc20Token)
).to.equal('0') ).to.equal('0')
}) })
it('#getDatatokenBalance ', async () => { // it('#getDatatokenBalance ', async () => {
expect( // expect(
await sideStaking.getDatatokenBalance(sideStakingAddress, erc20Token) // await sideStaking.getDatatokenBalance(sideStakingAddress, erc20Token)
).to.equal('997999.9999999999') // ).to.equal('997999.9999999999')
}) // })
it('#getvestingAmount ', async () => { it('#getvestingAmount ', async () => {
expect(await sideStaking.getvestingAmount(sideStakingAddress, erc20Token)).to.equal( expect(await sideStaking.getvestingAmount(sideStakingAddress, erc20Token)).to.equal(