mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
Merge branch 'v4main' into issue-1437-marketplace-flow-integration-test-for-v4
This commit is contained in:
commit
4c72799bef
12
package.json
12
package.json
@ -27,20 +27,20 @@
|
|||||||
"changelog": "auto-changelog -p",
|
"changelog": "auto-changelog -p",
|
||||||
"prepublishOnly": "npm run build",
|
"prepublishOnly": "npm run build",
|
||||||
"mocha": "TS_NODE_PROJECT='./test/tsconfig.json' mocha --config=test/.mocharc.json --node-env=test --exit",
|
"mocha": "TS_NODE_PROJECT='./test/tsconfig.json' mocha --config=test/.mocharc.json --node-env=test --exit",
|
||||||
"test:ss": "npm run mocha -- 'test/unit/pools/ssContracts/SideStaking.test.ts'",
|
"test:nftfactory": "npm run mocha -- 'test/unit/factories/NftFactory.test.ts'",
|
||||||
|
"test:nft": "npm run mocha -- 'test/unit/tokens/Nft.test.ts'",
|
||||||
|
"test:datatoken": "npm run mocha -- 'test/unit/tokens/Datatoken.test.ts'",
|
||||||
|
"test:router": "npm run mocha -- 'test/unit/pools/Router.test.ts'",
|
||||||
"test:fixed": "npm run mocha -- 'test/unit/pools/fixedRate/FixedRateExchange.test.ts'",
|
"test:fixed": "npm run mocha -- 'test/unit/pools/fixedRate/FixedRateExchange.test.ts'",
|
||||||
|
"test:ss": "npm run mocha -- 'test/unit/pools/ssContracts/SideStaking.test.ts'",
|
||||||
"test:pool": "npm run mocha -- 'test/unit/pools/balancer/Pool.test.ts'",
|
"test:pool": "npm run mocha -- 'test/unit/pools/balancer/Pool.test.ts'",
|
||||||
"test:dispenser": "npm run mocha -- 'test/unit/pools/dispenser/Dispenser.test.ts'",
|
"test:dispenser": "npm run mocha -- 'test/unit/pools/dispenser/Dispenser.test.ts'",
|
||||||
"test:dt": "npm run mocha -- 'test/unit/tokens/Datatoken.test.ts'",
|
|
||||||
"test:nftDt": "npm run mocha -- 'test/unit/tokens/Nft.test.ts'",
|
|
||||||
"test:factory": "npm run mocha -- 'test/unit/NftFactory.test.ts'",
|
|
||||||
"test:router": "npm run mocha -- 'test/unit/pools/Router.test.ts'",
|
|
||||||
"test:publishAll": "npm run mocha -- 'test/integration/PublishFlows.test.ts'",
|
"test:publishAll": "npm run mocha -- 'test/integration/PublishFlows.test.ts'",
|
||||||
"test:examples": "npm run mocha -- 'test/integration/CodeExamples.test.ts'",
|
"test:examples": "npm run mocha -- 'test/integration/CodeExamples.test.ts'",
|
||||||
|
"test:provider": "npm run mocha -- 'test/integration/Provider.test.ts'",
|
||||||
"test:unit": "npm run mocha -- 'test/unit/**/*.test.ts'",
|
"test:unit": "npm run mocha -- 'test/unit/**/*.test.ts'",
|
||||||
"test:unit:cover": "nyc --report-dir coverage/unit npm run test:unit",
|
"test:unit:cover": "nyc --report-dir coverage/unit npm run test:unit",
|
||||||
"test:integration": "npm run mocha -- 'test/integration/**/*.test.ts'",
|
"test:integration": "npm run mocha -- 'test/integration/**/*.test.ts'",
|
||||||
"test:provider": "npm run mocha -- 'test/integration/Provider.test.ts'",
|
|
||||||
"test:compute": "npm run mocha -- 'test/integration/ComputeFlow.test.ts'",
|
"test:compute": "npm run mocha -- 'test/integration/ComputeFlow.test.ts'",
|
||||||
"test:integration:cover": "nyc --report-dir coverage/integration --no-clean npm run test:integration",
|
"test:integration:cover": "nyc --report-dir coverage/integration --no-clean npm run test:integration",
|
||||||
"create:guide": "chmod +x ./scripts/createCodeExamples.sh && ./scripts/createCodeExamples.sh",
|
"create:guide": "chmod +x ./scripts/createCodeExamples.sh && ./scripts/createCodeExamples.sh",
|
||||||
|
@ -1,48 +1,75 @@
|
|||||||
import { assert, expect } from 'chai'
|
import { assert, expect } from 'chai'
|
||||||
import { AbiItem } from 'web3-utils/types'
|
import { AbiItem } from 'web3-utils/types'
|
||||||
import { deployContracts, Addresses } from '../TestContractHandler'
|
import { deployContracts, Addresses } from '../../TestContractHandler'
|
||||||
import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json'
|
import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json'
|
||||||
import MockERC20 from '@oceanprotocol/contracts/artifacts/contracts/utils/mock/MockERC20Decimals.sol/MockERC20Decimals.json'
|
import { web3 } from '../../config'
|
||||||
import { web3 } from '../config'
|
import {
|
||||||
import { NftFactory, NftCreateData, TokenOrder, ZERO_ADDRESS, signHash } from '../../src'
|
NftFactory,
|
||||||
|
NftCreateData,
|
||||||
|
TokenOrder,
|
||||||
|
ZERO_ADDRESS,
|
||||||
|
signHash,
|
||||||
|
Nft,
|
||||||
|
transfer,
|
||||||
|
approve
|
||||||
|
} from '../../../src'
|
||||||
import {
|
import {
|
||||||
ProviderFees,
|
ProviderFees,
|
||||||
FreCreationParams,
|
FreCreationParams,
|
||||||
Erc20CreateParams,
|
Erc20CreateParams,
|
||||||
PoolCreationParams
|
PoolCreationParams
|
||||||
} from '../../src/@types'
|
} from '../../../src/@types'
|
||||||
|
|
||||||
describe('Nft Factory test', () => {
|
describe('Nft Factory test', () => {
|
||||||
let factoryOwner: string
|
let factoryOwner: string
|
||||||
let nftOwner: string
|
let nftOwner: string
|
||||||
let user1: string
|
let user1: string
|
||||||
let user2: string
|
let user2: string
|
||||||
let user3: string
|
|
||||||
let contracts: Addresses
|
let contracts: Addresses
|
||||||
let nftFactory: NftFactory
|
let nftFactory: NftFactory
|
||||||
let dtAddress: string
|
let dtAddress: string
|
||||||
let dtAddress2: string
|
let dtAddress2: string
|
||||||
let nftAddress: string
|
let nftAddress: string
|
||||||
|
|
||||||
|
const DATA_TOKEN_AMOUNT = web3.utils.toWei('1')
|
||||||
|
const FEE = '0.001'
|
||||||
|
|
||||||
|
const nftData: NftCreateData = {
|
||||||
|
name: '72120Bundle',
|
||||||
|
symbol: '72Bundle',
|
||||||
|
templateIndex: 1,
|
||||||
|
tokenURI: 'https://oceanprotocol.com/nft/',
|
||||||
|
transferable: true,
|
||||||
|
owner: factoryOwner
|
||||||
|
}
|
||||||
|
|
||||||
|
const ercParams: Erc20CreateParams = {
|
||||||
|
templateIndex: 1,
|
||||||
|
minter: nftOwner,
|
||||||
|
paymentCollector: user2,
|
||||||
|
mpFeeAddress: user1,
|
||||||
|
feeToken: ZERO_ADDRESS,
|
||||||
|
cap: '1000000',
|
||||||
|
feeAmount: '0',
|
||||||
|
name: 'ERC20B1',
|
||||||
|
symbol: 'ERC20DT1Symbol'
|
||||||
|
}
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
const accounts = await web3.eth.getAccounts()
|
const accounts = await web3.eth.getAccounts()
|
||||||
factoryOwner = accounts[0]
|
factoryOwner = accounts[0]
|
||||||
nftOwner = accounts[1]
|
nftOwner = accounts[1]
|
||||||
user1 = accounts[2]
|
user1 = accounts[2]
|
||||||
user2 = accounts[3]
|
user2 = accounts[3]
|
||||||
user3 = accounts[4]
|
|
||||||
|
nftData.owner = factoryOwner
|
||||||
|
ercParams.minter = nftOwner
|
||||||
|
ercParams.paymentCollector = user2
|
||||||
|
ercParams.mpFeeAddress = user1
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should deploy contracts', async () => {
|
it('should deploy contracts', async () => {
|
||||||
contracts = await deployContracts(web3, factoryOwner)
|
contracts = await deployContracts(web3, factoryOwner)
|
||||||
|
|
||||||
const daiContract = new web3.eth.Contract(
|
|
||||||
MockERC20.abi as AbiItem[],
|
|
||||||
contracts.daiAddress
|
|
||||||
)
|
|
||||||
await daiContract.methods
|
|
||||||
.approve(contracts.erc721FactoryAddress, web3.utils.toWei('10000'))
|
|
||||||
.send({ from: factoryOwner })
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should initiate NFTFactory instance', async () => {
|
it('should initiate NFTFactory instance', async () => {
|
||||||
@ -59,42 +86,28 @@ describe('Nft Factory test', () => {
|
|||||||
assert(nftTemplate.isActive === true)
|
assert(nftTemplate.isActive === true)
|
||||||
assert(nftTemplate.templateAddress === contracts.erc721TemplateAddress)
|
assert(nftTemplate.templateAddress === contracts.erc721TemplateAddress)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getTokenTemplate - should return Token template struct', async () => {
|
it('#getTokenTemplate - should return Token template struct', async () => {
|
||||||
const tokenTemplate = await nftFactory.getTokenTemplate(1)
|
const tokenTemplate = await nftFactory.getTokenTemplate(1)
|
||||||
assert(tokenTemplate.isActive === true)
|
assert(tokenTemplate.isActive === true)
|
||||||
assert(tokenTemplate.templateAddress === contracts.erc20TemplateAddress)
|
assert(tokenTemplate.templateAddress === contracts.erc20TemplateAddress)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#createNftwithErc - should create an NFT and a Datatoken ', async () => {
|
it('#createNft - should create an NFT', async () => {
|
||||||
// we prepare transaction parameters objects
|
// we prepare transaction parameters objects
|
||||||
const nftData: NftCreateData = {
|
const nftAddress = await nftFactory.createNFT(nftOwner, nftData)
|
||||||
name: '72120Bundle',
|
|
||||||
symbol: '72Bundle',
|
|
||||||
templateIndex: 1,
|
|
||||||
tokenURI: 'https://oceanprotocol.com/nft/',
|
|
||||||
transferable: true,
|
|
||||||
owner: factoryOwner
|
|
||||||
}
|
|
||||||
|
|
||||||
const ercParams: Erc20CreateParams = {
|
// we check the created nft
|
||||||
templateIndex: 1,
|
const nftDatatoken = new Nft(web3)
|
||||||
minter: factoryOwner,
|
const tokenURI = await nftDatatoken.getTokenURI(nftAddress, 1)
|
||||||
paymentCollector: user3,
|
assert(tokenURI === nftData.tokenURI)
|
||||||
mpFeeAddress: user2,
|
})
|
||||||
feeToken: '0x0000000000000000000000000000000000000000',
|
|
||||||
cap: '10000',
|
|
||||||
feeAmount: '0',
|
|
||||||
name: 'ERC20B1',
|
|
||||||
symbol: 'ERC20DT1Symbol'
|
|
||||||
}
|
|
||||||
|
|
||||||
const txReceipt = await nftFactory.createNftWithErc20(
|
it('#createNftwithErc - should create an NFT and a Datatoken', async () => {
|
||||||
factoryOwner,
|
// we prepare transaction parameters objects
|
||||||
nftData,
|
const txReceipt = await nftFactory.createNftWithErc20(nftOwner, nftData, ercParams)
|
||||||
ercParams
|
|
||||||
)
|
|
||||||
|
|
||||||
// EVENTS HAVE BEEN EMITTED
|
// events have been emitted
|
||||||
expect(txReceipt.events.NFTCreated.event === 'NFTCreated')
|
expect(txReceipt.events.NFTCreated.event === 'NFTCreated')
|
||||||
expect(txReceipt.events.TokenCreated.event === 'TokenCreated')
|
expect(txReceipt.events.TokenCreated.event === 'TokenCreated')
|
||||||
|
|
||||||
@ -103,53 +116,58 @@ describe('Nft Factory test', () => {
|
|||||||
dtAddress = txReceipt.events.TokenCreated.returnValues.newTokenAddress
|
dtAddress = txReceipt.events.TokenCreated.returnValues.newTokenAddress
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('#createNftwithErc - should increment nft and token count', async () => {
|
||||||
|
const currentNFTCount = await nftFactory.getCurrentNFTCount()
|
||||||
|
const currentTokenCount = await nftFactory.getCurrentTokenCount()
|
||||||
|
|
||||||
|
await nftFactory.createNftWithErc20(nftOwner, nftData, ercParams)
|
||||||
|
|
||||||
|
expect((await nftFactory.getCurrentNFTCount()) === currentNFTCount + 1)
|
||||||
|
expect((await nftFactory.getCurrentTokenCount()) === currentTokenCount + 1)
|
||||||
|
})
|
||||||
|
|
||||||
it('#createNftErcWithPool- should create an NFT, a Datatoken and a pool DT/DAI', async () => {
|
it('#createNftErcWithPool- should create an NFT, a Datatoken and a pool DT/DAI', async () => {
|
||||||
// we prepare transaction parameters objects
|
// we prepare transaction parameters objects
|
||||||
const nftData: NftCreateData = {
|
|
||||||
name: '72120Bundle',
|
|
||||||
symbol: '72Bundle',
|
|
||||||
templateIndex: 1,
|
|
||||||
tokenURI: 'https://oceanprotocol.com/nft/',
|
|
||||||
transferable: true,
|
|
||||||
owner: factoryOwner
|
|
||||||
}
|
|
||||||
|
|
||||||
const ercParams: Erc20CreateParams = {
|
|
||||||
templateIndex: 1,
|
|
||||||
minter: user2,
|
|
||||||
paymentCollector: user3,
|
|
||||||
mpFeeAddress: user2,
|
|
||||||
feeToken: '0x0000000000000000000000000000000000000000',
|
|
||||||
cap: '1000000',
|
|
||||||
feeAmount: '0',
|
|
||||||
name: 'ERC20B1',
|
|
||||||
symbol: 'ERC20DT1Symbol'
|
|
||||||
}
|
|
||||||
|
|
||||||
const poolParams: PoolCreationParams = {
|
const poolParams: PoolCreationParams = {
|
||||||
ssContract: contracts.sideStakingAddress,
|
ssContract: contracts.sideStakingAddress,
|
||||||
baseTokenAddress: contracts.daiAddress,
|
baseTokenAddress: contracts.daiAddress,
|
||||||
baseTokenSender: contracts.erc721FactoryAddress,
|
baseTokenSender: contracts.erc721FactoryAddress,
|
||||||
publisherAddress: factoryOwner,
|
publisherAddress: nftOwner,
|
||||||
marketFeeCollector: factoryOwner,
|
marketFeeCollector: nftOwner,
|
||||||
poolTemplateAddress: contracts.poolTemplateAddress,
|
poolTemplateAddress: contracts.poolTemplateAddress,
|
||||||
rate: '1',
|
rate: '1',
|
||||||
baseTokenDecimals: 18,
|
baseTokenDecimals: 18,
|
||||||
vestingAmount: '10000',
|
vestingAmount: '10000',
|
||||||
vestedBlocks: 2500000,
|
vestedBlocks: 2500000,
|
||||||
initialBaseTokenLiquidity: '2000',
|
initialBaseTokenLiquidity: '2000',
|
||||||
swapFeeLiquidityProvider: '0.001',
|
swapFeeLiquidityProvider: FEE,
|
||||||
swapFeeMarketRunner: '0.001'
|
swapFeeMarketRunner: FEE
|
||||||
}
|
}
|
||||||
|
|
||||||
const txReceipt = await nftFactory.createNftErc20WithPool(
|
await transfer(
|
||||||
|
web3,
|
||||||
factoryOwner,
|
factoryOwner,
|
||||||
|
contracts.daiAddress,
|
||||||
|
nftOwner,
|
||||||
|
poolParams.vestingAmount
|
||||||
|
)
|
||||||
|
|
||||||
|
await approve(
|
||||||
|
web3,
|
||||||
|
nftOwner,
|
||||||
|
contracts.daiAddress,
|
||||||
|
contracts.erc721FactoryAddress,
|
||||||
|
poolParams.vestingAmount
|
||||||
|
)
|
||||||
|
|
||||||
|
const txReceipt = await nftFactory.createNftErc20WithPool(
|
||||||
|
nftOwner,
|
||||||
nftData,
|
nftData,
|
||||||
ercParams,
|
ercParams,
|
||||||
poolParams
|
poolParams
|
||||||
)
|
)
|
||||||
|
|
||||||
// EVENTS HAVE BEEN EMITTED
|
// events have been emitted
|
||||||
expect(txReceipt.events.NFTCreated.event === 'NFTCreated')
|
expect(txReceipt.events.NFTCreated.event === 'NFTCreated')
|
||||||
expect(txReceipt.events.TokenCreated.event === 'TokenCreated')
|
expect(txReceipt.events.TokenCreated.event === 'TokenCreated')
|
||||||
expect(txReceipt.events.NewPool.event === 'NewPool')
|
expect(txReceipt.events.NewPool.event === 'NewPool')
|
||||||
@ -157,48 +175,27 @@ describe('Nft Factory test', () => {
|
|||||||
|
|
||||||
it('#createNftErcWithFixedRate- should create an NFT, a datatoken and create a Fixed Rate Exchange', async () => {
|
it('#createNftErcWithFixedRate- should create an NFT, a datatoken and create a Fixed Rate Exchange', async () => {
|
||||||
// we prepare transaction parameters objects
|
// we prepare transaction parameters objects
|
||||||
const nftData: NftCreateData = {
|
|
||||||
name: '72120Bundle',
|
|
||||||
symbol: '72Bundle',
|
|
||||||
templateIndex: 1,
|
|
||||||
tokenURI: 'https://oceanprotocol.com/nft/',
|
|
||||||
transferable: true,
|
|
||||||
owner: factoryOwner
|
|
||||||
}
|
|
||||||
|
|
||||||
const ercParams: Erc20CreateParams = {
|
|
||||||
templateIndex: 1,
|
|
||||||
minter: factoryOwner,
|
|
||||||
paymentCollector: user3,
|
|
||||||
mpFeeAddress: user2,
|
|
||||||
feeToken: '0x0000000000000000000000000000000000000000',
|
|
||||||
cap: '1000000',
|
|
||||||
feeAmount: '0',
|
|
||||||
name: 'ERC20B1',
|
|
||||||
symbol: 'ERC20DT1Symbol'
|
|
||||||
}
|
|
||||||
|
|
||||||
const freParams: FreCreationParams = {
|
const freParams: FreCreationParams = {
|
||||||
fixedRateAddress: contracts.fixedRateAddress,
|
fixedRateAddress: contracts.fixedRateAddress,
|
||||||
baseTokenAddress: contracts.daiAddress,
|
baseTokenAddress: contracts.daiAddress,
|
||||||
owner: factoryOwner,
|
owner: nftOwner,
|
||||||
marketFeeCollector: factoryOwner,
|
marketFeeCollector: nftOwner,
|
||||||
baseTokenDecimals: 18,
|
baseTokenDecimals: 18,
|
||||||
datatokenDecimals: 18,
|
datatokenDecimals: 18,
|
||||||
fixedRate: '1',
|
fixedRate: '1',
|
||||||
marketFee: '0.001',
|
marketFee: FEE,
|
||||||
allowedConsumer: factoryOwner,
|
allowedConsumer: user1,
|
||||||
withMint: false
|
withMint: false
|
||||||
}
|
}
|
||||||
|
|
||||||
const txReceipt = await nftFactory.createNftErc20WithFixedRate(
|
const txReceipt = await nftFactory.createNftErc20WithFixedRate(
|
||||||
factoryOwner,
|
nftOwner,
|
||||||
nftData,
|
nftData,
|
||||||
ercParams,
|
ercParams,
|
||||||
freParams
|
freParams
|
||||||
)
|
)
|
||||||
|
|
||||||
// EVENTS HAVE BEEN EMITTED
|
// events have been emitted
|
||||||
expect(txReceipt.events.NFTCreated.event === 'NFTCreated')
|
expect(txReceipt.events.NFTCreated.event === 'NFTCreated')
|
||||||
expect(txReceipt.events.TokenCreated.event === 'TokenCreated')
|
expect(txReceipt.events.TokenCreated.event === 'TokenCreated')
|
||||||
expect(txReceipt.events.NewFixedRate.event === 'NewFixedRate')
|
expect(txReceipt.events.NewFixedRate.event === 'NewFixedRate')
|
||||||
@ -209,27 +206,6 @@ describe('Nft Factory test', () => {
|
|||||||
|
|
||||||
it('#createNftErcWithDispenser- should create an NFT, a datatoken and create a Dispenser', async () => {
|
it('#createNftErcWithDispenser- should create an NFT, a datatoken and create a Dispenser', async () => {
|
||||||
// we prepare transaction parameters objects
|
// we prepare transaction parameters objects
|
||||||
const nftData: NftCreateData = {
|
|
||||||
name: '72120Bundle',
|
|
||||||
symbol: '72Bundle',
|
|
||||||
templateIndex: 1,
|
|
||||||
tokenURI: 'https://oceanprotocol.com/nft/',
|
|
||||||
transferable: true,
|
|
||||||
owner: factoryOwner
|
|
||||||
}
|
|
||||||
|
|
||||||
const ercParams: Erc20CreateParams = {
|
|
||||||
templateIndex: 1,
|
|
||||||
minter: factoryOwner,
|
|
||||||
paymentCollector: user3,
|
|
||||||
mpFeeAddress: user2,
|
|
||||||
feeToken: '0x0000000000000000000000000000000000000000',
|
|
||||||
cap: '1000000',
|
|
||||||
feeAmount: '0',
|
|
||||||
name: 'ERC20B1',
|
|
||||||
symbol: 'ERC20DT1Symbol'
|
|
||||||
}
|
|
||||||
|
|
||||||
const dispenserParams = {
|
const dispenserParams = {
|
||||||
dispenserAddress: contracts.dispenserAddress,
|
dispenserAddress: contracts.dispenserAddress,
|
||||||
maxTokens: '1',
|
maxTokens: '1',
|
||||||
@ -239,13 +215,13 @@ describe('Nft Factory test', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const txReceipt = await nftFactory.createNftErc20WithDispenser(
|
const txReceipt = await nftFactory.createNftErc20WithDispenser(
|
||||||
factoryOwner,
|
nftOwner,
|
||||||
nftData,
|
nftData,
|
||||||
ercParams,
|
ercParams,
|
||||||
dispenserParams
|
dispenserParams
|
||||||
)
|
)
|
||||||
|
|
||||||
// EVENTS HAVE BEEN EMITTED
|
// events have been emitted
|
||||||
expect(txReceipt.events.NFTCreated.event === 'NFTCreated')
|
expect(txReceipt.events.NFTCreated.event === 'NFTCreated')
|
||||||
expect(txReceipt.events.TokenCreated.event === 'TokenCreated')
|
expect(txReceipt.events.TokenCreated.event === 'TokenCreated')
|
||||||
expect(txReceipt.events.DispenserCreated.event === 'DispenserCreated')
|
expect(txReceipt.events.DispenserCreated.event === 'DispenserCreated')
|
||||||
@ -255,39 +231,38 @@ describe('Nft Factory test', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('#startMultipleTokenOrder- should succed to start multiple orders', async () => {
|
it('#startMultipleTokenOrder- should succed to start multiple orders', async () => {
|
||||||
const consumer = user2 // could be different user
|
const consumer = user1 // could be different user
|
||||||
const dtAmount = web3.utils.toWei('1')
|
|
||||||
const serviceIndex = 1 // dummy index
|
const serviceIndex = 1 // dummy index
|
||||||
const consumeFeeAddress = user3 // marketplace fee Collector
|
const consumeFeeAddress = user2 // marketplace fee Collector
|
||||||
const consumeFeeAmount = '0' // fee to be collected on top, requires approval
|
const consumeFeeAmount = '0' // fee to be collected on top, requires approval
|
||||||
const consumeFeeToken = contracts.daiAddress // token address for the feeAmount, in this case DAI
|
const consumeFeeToken = contracts.daiAddress // token address for the feeAmount, in this case DAI
|
||||||
|
|
||||||
// we reuse a DT created in a previous test
|
// we reuse a DT created in a previous test
|
||||||
const dtContract = new web3.eth.Contract(ERC20Template.abi as AbiItem[], dtAddress)
|
const dtContract = new web3.eth.Contract(ERC20Template.abi as AbiItem[], dtAddress)
|
||||||
expect(await dtContract.methods.balanceOf(user2).call()).to.equal('0')
|
expect(await dtContract.methods.balanceOf(user1).call()).to.equal('0')
|
||||||
|
|
||||||
// dt owner mint dtAmount to user2
|
// dt owner mint DATA_TOKEN_AMOUNT to user1
|
||||||
await dtContract.methods.mint(user2, dtAmount).send({ from: factoryOwner })
|
await dtContract.methods.mint(user1, DATA_TOKEN_AMOUNT).send({ from: nftOwner })
|
||||||
|
|
||||||
// user2 approves NFTFactory to move his dtAmount
|
// user1 approves NFTFactory to move his DATA_TOKEN_AMOUNT
|
||||||
await dtContract.methods
|
await dtContract.methods
|
||||||
.approve(contracts.erc721FactoryAddress, dtAmount)
|
.approve(contracts.erc721FactoryAddress, DATA_TOKEN_AMOUNT)
|
||||||
.send({ from: user2 })
|
.send({ from: user1 })
|
||||||
|
|
||||||
// we reuse another DT created in a previous test
|
// we reuse another DT created in a previous test
|
||||||
const dtContract2 = new web3.eth.Contract(ERC20Template.abi as AbiItem[], dtAddress2)
|
const dtContract2 = new web3.eth.Contract(ERC20Template.abi as AbiItem[], dtAddress2)
|
||||||
expect(await dtContract2.methods.balanceOf(user2).call()).to.equal('0')
|
expect(await dtContract2.methods.balanceOf(user1).call()).to.equal('0')
|
||||||
|
|
||||||
// dt owner mint dtAmount to user2
|
// dt owner mint DATA_TOKEN_AMOUNT to user1
|
||||||
await dtContract2.methods.mint(user2, dtAmount).send({ from: factoryOwner })
|
await dtContract2.methods.mint(user1, DATA_TOKEN_AMOUNT).send({ from: nftOwner })
|
||||||
// user2 approves NFTFactory to move his dtAmount
|
// user1 approves NFTFactory to move his DATA_TOKEN_AMOUNT
|
||||||
await dtContract2.methods
|
await dtContract2.methods
|
||||||
.approve(contracts.erc721FactoryAddress, dtAmount)
|
.approve(contracts.erc721FactoryAddress, DATA_TOKEN_AMOUNT)
|
||||||
.send({ from: user2 })
|
.send({ from: user1 })
|
||||||
|
|
||||||
// we check user2 has enought DTs
|
// we check user1 has enought DTs
|
||||||
expect(await dtContract.methods.balanceOf(user2).call()).to.equal(dtAmount)
|
expect(await dtContract.methods.balanceOf(user1).call()).to.equal(DATA_TOKEN_AMOUNT)
|
||||||
expect(await dtContract2.methods.balanceOf(user2).call()).to.equal(dtAmount)
|
expect(await dtContract2.methods.balanceOf(user1).call()).to.equal(DATA_TOKEN_AMOUNT)
|
||||||
|
|
||||||
const providerData = JSON.stringify({ timeout: 0 })
|
const providerData = JSON.stringify({ timeout: 0 })
|
||||||
const providerValidUntil = '0'
|
const providerValidUntil = '0'
|
||||||
@ -312,8 +287,8 @@ describe('Nft Factory test', () => {
|
|||||||
validUntil: providerValidUntil
|
validUntil: providerValidUntil
|
||||||
}
|
}
|
||||||
const consumeMarketFee = {
|
const consumeMarketFee = {
|
||||||
consumeMarketFeeAddress: '0x0000000000000000000000000000000000000000',
|
consumeMarketFeeAddress: ZERO_ADDRESS,
|
||||||
consumeMarketFeeToken: '0x0000000000000000000000000000000000000000',
|
consumeMarketFeeToken: ZERO_ADDRESS,
|
||||||
consumeMarketFeeAmount: '0'
|
consumeMarketFeeAmount: '0'
|
||||||
}
|
}
|
||||||
const orders: TokenOrder[] = [
|
const orders: TokenOrder[] = [
|
||||||
@ -332,24 +307,21 @@ describe('Nft Factory test', () => {
|
|||||||
_consumeMarketFee: consumeMarketFee
|
_consumeMarketFee: consumeMarketFee
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
await nftFactory.startMultipleTokenOrder(user2, orders)
|
await nftFactory.startMultipleTokenOrder(user1, orders)
|
||||||
// we check user2 has no more DTs
|
// we check user1 has no more DTs
|
||||||
expect(await dtContract.methods.balanceOf(user2).call()).to.equal('0')
|
expect(await dtContract.methods.balanceOf(user1).call()).to.equal('0')
|
||||||
expect(await dtContract2.methods.balanceOf(user2).call()).to.equal('0')
|
expect(await dtContract2.methods.balanceOf(user1).call()).to.equal('0')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#checkDatatoken - should confirm if DT is from the factory', async () => {
|
it('#checkDatatoken - should confirm if DT is from the factory', async () => {
|
||||||
assert((await nftFactory.checkDatatoken(dtAddress)) === true)
|
assert((await nftFactory.checkDatatoken(dtAddress)) === true)
|
||||||
assert((await nftFactory.checkDatatoken(dtAddress2)) === true)
|
assert((await nftFactory.checkDatatoken(dtAddress2)) === true)
|
||||||
assert((await nftFactory.checkDatatoken(user2)) === false)
|
assert((await nftFactory.checkDatatoken(user1)) === false)
|
||||||
assert((await nftFactory.checkDatatoken(nftAddress)) === false)
|
assert((await nftFactory.checkDatatoken(nftAddress)) === false)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#checkNFT - should return nftAddress if from the factory, or address(0) if not', async () => {
|
it('#checkNFT - should return nftAddress if from the factory, or address(0) if not', async () => {
|
||||||
assert(
|
assert((await nftFactory.checkNFT(dtAddress)) === ZERO_ADDRESS)
|
||||||
(await nftFactory.checkNFT(dtAddress)) ===
|
|
||||||
'0x0000000000000000000000000000000000000000'
|
|
||||||
)
|
|
||||||
assert((await nftFactory.checkNFT(nftAddress)) === nftAddress)
|
assert((await nftFactory.checkNFT(nftAddress)) === nftAddress)
|
||||||
})
|
})
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user