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

simplify constants

This commit is contained in:
Miquel A. Cabot 2022-04-28 16:50:00 +02:00
parent 962340b0db
commit 26e1cba7cb

View File

@ -30,37 +30,28 @@ describe('Nft Factory test', () => {
let dtAddress2: string let dtAddress2: string
let nftAddress: string let nftAddress: string
const VESTING_AMOUNT = '10000'
const CAP_AMOUNT = '1000000'
const DATA_TOKEN_AMOUNT = web3.utils.toWei('1') const DATA_TOKEN_AMOUNT = web3.utils.toWei('1')
const NFT_NAME = '72120Bundle'
const NFT_SYMBOL = '72Bundle'
const NFT_TOKEN_URI = 'https://oceanprotocol.com/nft/'
const ERC20_NAME = 'ERC20B1'
const ERC20_SYMBOL = 'ERC20DT1Symbol'
const RATE = '1'
const FEE = '0.001' const FEE = '0.001'
const FEE_ZERO = '0'
const NFT_DATA: NftCreateData = { const nftData: NftCreateData = {
name: NFT_NAME, name: '72120Bundle',
symbol: NFT_SYMBOL, symbol: '72Bundle',
templateIndex: 1, templateIndex: 1,
tokenURI: NFT_TOKEN_URI, tokenURI: 'https://oceanprotocol.com/nft/',
transferable: true, transferable: true,
owner: factoryOwner owner: factoryOwner
} }
const ERC_PARAMS: Erc20CreateParams = { const ercParams: Erc20CreateParams = {
templateIndex: 1, templateIndex: 1,
minter: nftOwner, minter: nftOwner,
paymentCollector: user2, paymentCollector: user2,
mpFeeAddress: user1, mpFeeAddress: user1,
feeToken: ZERO_ADDRESS, feeToken: ZERO_ADDRESS,
cap: CAP_AMOUNT, cap: '1000000',
feeAmount: FEE_ZERO, feeAmount: '0',
name: ERC20_NAME, name: 'ERC20B1',
symbol: ERC20_SYMBOL symbol: 'ERC20DT1Symbol'
} }
before(async () => { before(async () => {
@ -70,10 +61,10 @@ describe('Nft Factory test', () => {
user1 = accounts[2] user1 = accounts[2]
user2 = accounts[3] user2 = accounts[3]
NFT_DATA.owner = factoryOwner nftData.owner = factoryOwner
ERC_PARAMS.minter = nftOwner ercParams.minter = nftOwner
ERC_PARAMS.paymentCollector = user2 ercParams.paymentCollector = user2
ERC_PARAMS.mpFeeAddress = user1 ercParams.mpFeeAddress = user1
}) })
it('should deploy contracts', async () => { it('should deploy contracts', async () => {
@ -103,17 +94,17 @@ describe('Nft Factory test', () => {
it('#createNft - should create an NFT', async () => { it('#createNft - should create an NFT', async () => {
// we prepare transaction parameters objects // we prepare transaction parameters objects
const nftAddress = await nftFactory.createNFT(nftOwner, NFT_DATA) const nftAddress = await nftFactory.createNFT(nftOwner, nftData)
// we check the created nft // we check the created nft
const nftDatatoken = new Nft(web3) const nftDatatoken = new Nft(web3)
const tokenURI = await nftDatatoken.getTokenURI(nftAddress, 1) const tokenURI = await nftDatatoken.getTokenURI(nftAddress, 1)
assert(tokenURI === NFT_TOKEN_URI) assert(tokenURI === nftData.tokenURI)
}) })
it('#createNftwithErc - should create an NFT and a Datatoken', async () => { it('#createNftwithErc - should create an NFT and a Datatoken', async () => {
// we prepare transaction parameters objects // we prepare transaction parameters objects
const txReceipt = await nftFactory.createNftWithErc20(nftOwner, NFT_DATA, ERC_PARAMS) const txReceipt = await nftFactory.createNftWithErc20(nftOwner, nftData, ercParams)
// events have been emitted // events have been emitted
expect(txReceipt.events.NFTCreated.event === 'NFTCreated') expect(txReceipt.events.NFTCreated.event === 'NFTCreated')
@ -128,7 +119,7 @@ describe('Nft Factory test', () => {
const currentNFTCount = await nftFactory.getCurrentNFTCount() const currentNFTCount = await nftFactory.getCurrentNFTCount()
const currentTokenCount = await nftFactory.getCurrentTokenCount() const currentTokenCount = await nftFactory.getCurrentTokenCount()
await nftFactory.createNftWithErc20(nftOwner, NFT_DATA, ERC_PARAMS) await nftFactory.createNftWithErc20(nftOwner, nftData, ercParams)
expect((await nftFactory.getCurrentNFTCount()) === currentNFTCount + 1) expect((await nftFactory.getCurrentNFTCount()) === currentNFTCount + 1)
expect((await nftFactory.getCurrentTokenCount()) === currentTokenCount + 1) expect((await nftFactory.getCurrentTokenCount()) === currentTokenCount + 1)
@ -143,33 +134,33 @@ describe('Nft Factory test', () => {
publisherAddress: nftOwner, publisherAddress: nftOwner,
marketFeeCollector: nftOwner, marketFeeCollector: nftOwner,
poolTemplateAddress: contracts.poolTemplateAddress, poolTemplateAddress: contracts.poolTemplateAddress,
rate: RATE, rate: '1',
baseTokenDecimals: 18, baseTokenDecimals: 18,
vestingAmount: VESTING_AMOUNT, vestingAmount: '10000',
vestedBlocks: 2500000, vestedBlocks: 2500000,
initialBaseTokenLiquidity: '2000', initialBaseTokenLiquidity: '2000',
swapFeeLiquidityProvider: FEE, swapFeeLiquidityProvider: FEE,
swapFeeMarketRunner: FEE swapFeeMarketRunner: FEE
} }
// approve VESTING_AMOUNT DAI to nftFactory // approve poolParams.vestingAmount DAI to nftFactory
const daiContract = new web3.eth.Contract( const daiContract = new web3.eth.Contract(
MockERC20.abi as AbiItem[], MockERC20.abi as AbiItem[],
contracts.daiAddress contracts.daiAddress
) )
await daiContract.methods await daiContract.methods
.transfer(nftOwner, web3.utils.toWei(VESTING_AMOUNT)) .transfer(nftOwner, web3.utils.toWei(poolParams.vestingAmount))
.send({ from: factoryOwner }) .send({ from: factoryOwner })
await daiContract.methods await daiContract.methods
.approve(contracts.erc721FactoryAddress, web3.utils.toWei(VESTING_AMOUNT)) .approve(contracts.erc721FactoryAddress, web3.utils.toWei(poolParams.vestingAmount))
.send({ from: nftOwner }) .send({ from: nftOwner })
const txReceipt = await nftFactory.createNftErc20WithPool( const txReceipt = await nftFactory.createNftErc20WithPool(
nftOwner, nftOwner,
NFT_DATA, nftData,
ERC_PARAMS, ercParams,
poolParams poolParams
) )
@ -188,7 +179,7 @@ describe('Nft Factory test', () => {
marketFeeCollector: nftOwner, marketFeeCollector: nftOwner,
baseTokenDecimals: 18, baseTokenDecimals: 18,
datatokenDecimals: 18, datatokenDecimals: 18,
fixedRate: RATE, fixedRate: '1',
marketFee: FEE, marketFee: FEE,
allowedConsumer: user1, allowedConsumer: user1,
withMint: false withMint: false
@ -196,8 +187,8 @@ describe('Nft Factory test', () => {
const txReceipt = await nftFactory.createNftErc20WithFixedRate( const txReceipt = await nftFactory.createNftErc20WithFixedRate(
nftOwner, nftOwner,
NFT_DATA, nftData,
ERC_PARAMS, ercParams,
freParams freParams
) )
@ -222,8 +213,8 @@ describe('Nft Factory test', () => {
const txReceipt = await nftFactory.createNftErc20WithDispenser( const txReceipt = await nftFactory.createNftErc20WithDispenser(
nftOwner, nftOwner,
NFT_DATA, nftData,
ERC_PARAMS, ercParams,
dispenserParams dispenserParams
) )
@ -240,7 +231,7 @@ describe('Nft Factory test', () => {
const consumer = user1 // could be different user const consumer = user1 // could be different user
const serviceIndex = 1 // dummy index const serviceIndex = 1 // dummy index
const consumeFeeAddress = user2 // marketplace fee Collector const consumeFeeAddress = user2 // marketplace fee Collector
const consumeFeeAmount = FEE_ZERO // 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
@ -295,7 +286,7 @@ describe('Nft Factory test', () => {
const consumeMarketFee = { const consumeMarketFee = {
consumeMarketFeeAddress: ZERO_ADDRESS, consumeMarketFeeAddress: ZERO_ADDRESS,
consumeMarketFeeToken: ZERO_ADDRESS, consumeMarketFeeToken: ZERO_ADDRESS,
consumeMarketFeeAmount: FEE_ZERO consumeMarketFeeAmount: '0'
} }
const orders: TokenOrder[] = [ const orders: TokenOrder[] = [
{ {