From c07a528dbe65019eea11a12fcdb7803a0a85f392 Mon Sep 17 00:00:00 2001 From: "Miquel A. Cabot" Date: Mon, 21 Mar 2022 15:22:24 +0100 Subject: [PATCH 01/47] change NftFactory test directory --- package.json | 2 +- test/unit/{ => factories}/NftFactory.test.ts | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) rename test/unit/{ => factories}/NftFactory.test.ts (97%) diff --git a/package.json b/package.json index 477128a1..4379c494 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "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:factory": "npm run mocha -- 'test/unit/factories/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:unit": "npm run mocha -- 'test/unit/**/*.test.ts'", diff --git a/test/unit/NftFactory.test.ts b/test/unit/factories/NftFactory.test.ts similarity index 97% rename from test/unit/NftFactory.test.ts rename to test/unit/factories/NftFactory.test.ts index d60d0c3a..7f1d0f2e 100644 --- a/test/unit/NftFactory.test.ts +++ b/test/unit/factories/NftFactory.test.ts @@ -1,16 +1,22 @@ import { assert, expect } from 'chai' 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 MockERC20 from '@oceanprotocol/contracts/artifacts/contracts/utils/mock/MockERC20Decimals.sol/MockERC20Decimals.json' -import { web3 } from '../config' -import { NftFactory, NftCreateData, TokenOrder, ZERO_ADDRESS, signHash } from '../../src' +import { web3 } from '../../config' +import { + NftFactory, + NftCreateData, + TokenOrder, + ZERO_ADDRESS, + signHash +} from '../../../src' import { ProviderFees, FreCreationParams, Erc20CreateParams, PoolCreationParams -} from '../../src/@types' +} from '../../../src/@types' describe('Nft Factory test', () => { let factoryOwner: string From 352b52afb3eb65bef4fa57ff3ea42e8ce847eb92 Mon Sep 17 00:00:00 2001 From: "Miquel A. Cabot" Date: Wed, 23 Mar 2022 13:10:45 +0100 Subject: [PATCH 02/47] remove unused accounts --- test/unit/factories/NftFactory.test.ts | 66 ++++++++++++-------------- 1 file changed, 31 insertions(+), 35 deletions(-) diff --git a/test/unit/factories/NftFactory.test.ts b/test/unit/factories/NftFactory.test.ts index 7f1d0f2e..59726fe1 100644 --- a/test/unit/factories/NftFactory.test.ts +++ b/test/unit/factories/NftFactory.test.ts @@ -20,10 +20,8 @@ import { describe('Nft Factory test', () => { let factoryOwner: string - let nftOwner: string let user1: string let user2: string - let user3: string let contracts: Addresses let nftFactory: NftFactory let dtAddress: string @@ -33,10 +31,8 @@ describe('Nft Factory test', () => { before(async () => { const accounts = await web3.eth.getAccounts() factoryOwner = accounts[0] - nftOwner = accounts[1] - user1 = accounts[2] - user2 = accounts[3] - user3 = accounts[4] + user1 = accounts[1] + user2 = accounts[2] }) it('should deploy contracts', async () => { @@ -83,8 +79,8 @@ describe('Nft Factory test', () => { const ercParams: Erc20CreateParams = { templateIndex: 1, minter: factoryOwner, - feeManager: user3, - mpFeeAddress: user2, + feeManager: user2, + mpFeeAddress: user1, feeToken: '0x0000000000000000000000000000000000000000', cap: '10000', feeAmount: '0', @@ -118,9 +114,9 @@ describe('Nft Factory test', () => { const ercParams: Erc20CreateParams = { templateIndex: 1, - minter: user2, - feeManager: user3, - mpFeeAddress: user2, + minter: user1, + feeManager: user2, + mpFeeAddress: user1, feeToken: '0x0000000000000000000000000000000000000000', cap: '1000000', feeAmount: '0', @@ -169,8 +165,8 @@ describe('Nft Factory test', () => { const ercParams: Erc20CreateParams = { templateIndex: 1, minter: factoryOwner, - feeManager: user3, - mpFeeAddress: user2, + feeManager: user2, + mpFeeAddress: user1, feeToken: '0x0000000000000000000000000000000000000000', cap: '1000000', feeAmount: '0', @@ -219,8 +215,8 @@ describe('Nft Factory test', () => { const ercParams: Erc20CreateParams = { templateIndex: 1, minter: factoryOwner, - feeManager: user3, - mpFeeAddress: user2, + feeManager: user2, + mpFeeAddress: user1, feeToken: '0x0000000000000000000000000000000000000000', cap: '1000000', feeAmount: '0', @@ -253,39 +249,39 @@ describe('Nft Factory test', () => { }) 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 consumeFeeAddress = user3 // marketplace fee Collector + const consumeFeeAddress = user2 // marketplace fee Collector const consumeFeeAmount = '0' // fee to be collected on top, requires approval const consumeFeeToken = contracts.daiAddress // token address for the feeAmount, in this case DAI // we reuse a DT created in a previous test 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 - await dtContract.methods.mint(user2, dtAmount).send({ from: factoryOwner }) + // dt owner mint dtAmount to user1 + await dtContract.methods.mint(user1, dtAmount).send({ from: factoryOwner }) - // user2 approves NFTFactory to move his dtAmount + // user1 approves NFTFactory to move his dtAmount await dtContract.methods .approve(contracts.erc721FactoryAddress, dtAmount) - .send({ from: user2 }) + .send({ from: user1 }) // we reuse another DT created in a previous test 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 - await dtContract2.methods.mint(user2, dtAmount).send({ from: factoryOwner }) - // user2 approves NFTFactory to move his dtAmount + // dt owner mint dtAmount to user1 + await dtContract2.methods.mint(user1, dtAmount).send({ from: factoryOwner }) + // user1 approves NFTFactory to move his dtAmount await dtContract2.methods .approve(contracts.erc721FactoryAddress, dtAmount) - .send({ from: user2 }) + .send({ from: user1 }) - // we check user2 has enought DTs - expect(await dtContract.methods.balanceOf(user2).call()).to.equal(dtAmount) - expect(await dtContract2.methods.balanceOf(user2).call()).to.equal(dtAmount) + // we check user1 has enought DTs + expect(await dtContract.methods.balanceOf(user1).call()).to.equal(dtAmount) + expect(await dtContract2.methods.balanceOf(user1).call()).to.equal(dtAmount) const providerData = JSON.stringify({ timeout: 0 }) const providerValidUntil = '0' @@ -330,16 +326,16 @@ describe('Nft Factory test', () => { _consumeMarketFee: consumeMarketFee } ] - await nftFactory.startMultipleTokenOrder(user2, orders) - // we check user2 has no more DTs - expect(await dtContract.methods.balanceOf(user2).call()).to.equal('0') - expect(await dtContract2.methods.balanceOf(user2).call()).to.equal('0') + await nftFactory.startMultipleTokenOrder(user1, orders) + // we check user1 has no more DTs + expect(await dtContract.methods.balanceOf(user1).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 () => { assert((await nftFactory.checkDatatoken(dtAddress)) === 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) }) From 4614833ce0ba79a2eeddf257832bf1d5969f6839 Mon Sep 17 00:00:00 2001 From: "Miquel A. Cabot" Date: Wed, 23 Mar 2022 15:45:58 +0100 Subject: [PATCH 03/47] add constants --- test/unit/factories/NftFactory.test.ts | 117 ++++++++++++++----------- 1 file changed, 64 insertions(+), 53 deletions(-) diff --git a/test/unit/factories/NftFactory.test.ts b/test/unit/factories/NftFactory.test.ts index 59726fe1..00201e12 100644 --- a/test/unit/factories/NftFactory.test.ts +++ b/test/unit/factories/NftFactory.test.ts @@ -18,6 +18,17 @@ import { PoolCreationParams } from '../../../src/@types' +const VESTING_AMOUNT = '10000' +const CAP_AMOUNT = '1000000' +const NFT_NAME = '72120Bundle' +const NFT_SYMBOL = '72Bundle' +const TOKEN_URI = 'https://oceanprotocol.com/nft/' +const ERC20_NAME = 'ERC20B1' +const ERC20_SYMBOL = 'ERC20DT1Symbol' +const RATE = '1' +const FEE = '0.001' +const FEE_ZERO = '0' + describe('Nft Factory test', () => { let factoryOwner: string let user1: string @@ -37,14 +48,6 @@ describe('Nft Factory test', () => { it('should deploy contracts', async () => { 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 () => { @@ -61,6 +64,7 @@ describe('Nft Factory test', () => { assert(nftTemplate.isActive === true) assert(nftTemplate.templateAddress === contracts.erc721TemplateAddress) }) + it('#getTokenTemplate - should return Token template struct', async () => { const tokenTemplate = await nftFactory.getTokenTemplate(1) assert(tokenTemplate.isActive === true) @@ -70,10 +74,10 @@ describe('Nft Factory test', () => { it('#createNftwithErc - should create an NFT and a Datatoken ', async () => { // we prepare transaction parameters objects const nftData: NftCreateData = { - name: '72120Bundle', - symbol: '72Bundle', + name: NFT_NAME, + symbol: NFT_SYMBOL, templateIndex: 1, - tokenURI: 'https://oceanprotocol.com/nft/' + tokenURI: TOKEN_URI } const ercParams: Erc20CreateParams = { @@ -81,11 +85,11 @@ describe('Nft Factory test', () => { minter: factoryOwner, feeManager: user2, mpFeeAddress: user1, - feeToken: '0x0000000000000000000000000000000000000000', - cap: '10000', - feeAmount: '0', - name: 'ERC20B1', - symbol: 'ERC20DT1Symbol' + feeToken: ZERO_ADDRESS, + cap: CAP_AMOUNT, + feeAmount: FEE_ZERO, + name: ERC20_NAME, + symbol: ERC20_SYMBOL } const txReceipt = await nftFactory.createNftWithErc20( @@ -106,10 +110,10 @@ describe('Nft Factory test', () => { it('#createNftErcWithPool- should create an NFT, a Datatoken and a pool DT/DAI', async () => { // we prepare transaction parameters objects const nftData: NftCreateData = { - name: '72120Bundle', - symbol: '72Bundle', + name: NFT_NAME, + symbol: NFT_SYMBOL, templateIndex: 1, - tokenURI: 'https://oceanprotocol.com/nft/' + tokenURI: TOKEN_URI } const ercParams: Erc20CreateParams = { @@ -117,11 +121,11 @@ describe('Nft Factory test', () => { minter: user1, feeManager: user2, mpFeeAddress: user1, - feeToken: '0x0000000000000000000000000000000000000000', - cap: '1000000', - feeAmount: '0', - name: 'ERC20B1', - symbol: 'ERC20DT1Symbol' + feeToken: ZERO_ADDRESS, + cap: CAP_AMOUNT, + feeAmount: FEE_ZERO, + name: ERC20_NAME, + symbol: ERC20_SYMBOL } const poolParams: PoolCreationParams = { @@ -131,15 +135,25 @@ describe('Nft Factory test', () => { publisherAddress: factoryOwner, marketFeeCollector: factoryOwner, poolTemplateAddress: contracts.poolTemplateAddress, - rate: '1', + rate: RATE, baseTokenDecimals: 18, - vestingAmount: '10000', + vestingAmount: VESTING_AMOUNT, vestedBlocks: 2500000, initialBaseTokenLiquidity: '2000', - swapFeeLiquidityProvider: '0.001', - swapFeeMarketRunner: '0.001' + swapFeeLiquidityProvider: FEE, + swapFeeMarketRunner: FEE } + // approve VESTING_AMOUNT DAI to nftFactory + const daiContract = new web3.eth.Contract( + MockERC20.abi as AbiItem[], + contracts.daiAddress + ) + + await daiContract.methods + .approve(contracts.erc721FactoryAddress, web3.utils.toWei(VESTING_AMOUNT)) + .send({ from: factoryOwner }) + const txReceipt = await nftFactory.createNftErc20WithPool( factoryOwner, nftData, @@ -156,10 +170,10 @@ describe('Nft Factory test', () => { it('#createNftErcWithFixedRate- should create an NFT, a datatoken and create a Fixed Rate Exchange', async () => { // we prepare transaction parameters objects const nftData: NftCreateData = { - name: '72120Bundle', - symbol: '72Bundle', + name: NFT_NAME, + symbol: NFT_SYMBOL, templateIndex: 1, - tokenURI: 'https://oceanprotocol.com/nft/' + tokenURI: TOKEN_URI } const ercParams: Erc20CreateParams = { @@ -167,11 +181,11 @@ describe('Nft Factory test', () => { minter: factoryOwner, feeManager: user2, mpFeeAddress: user1, - feeToken: '0x0000000000000000000000000000000000000000', - cap: '1000000', - feeAmount: '0', - name: 'ERC20B1', - symbol: 'ERC20DT1Symbol' + feeToken: ZERO_ADDRESS, + cap: CAP_AMOUNT, + feeAmount: FEE_ZERO, + name: ERC20_NAME, + symbol: ERC20_SYMBOL } const freParams: FreCreationParams = { @@ -181,8 +195,8 @@ describe('Nft Factory test', () => { marketFeeCollector: factoryOwner, baseTokenDecimals: 18, datatokenDecimals: 18, - fixedRate: '1', - marketFee: '0.001', + fixedRate: RATE, + marketFee: FEE, allowedConsumer: factoryOwner, withMint: false } @@ -206,10 +220,10 @@ describe('Nft Factory test', () => { it('#createNftErcWithDispenser- should create an NFT, a datatoken and create a Dispenser', async () => { // we prepare transaction parameters objects const nftData: NftCreateData = { - name: '72120Bundle', - symbol: '72Bundle', + name: NFT_NAME, + symbol: NFT_SYMBOL, templateIndex: 1, - tokenURI: 'https://oceanprotocol.com/nft/' + tokenURI: TOKEN_URI } const ercParams: Erc20CreateParams = { @@ -217,11 +231,11 @@ describe('Nft Factory test', () => { minter: factoryOwner, feeManager: user2, mpFeeAddress: user1, - feeToken: '0x0000000000000000000000000000000000000000', - cap: '1000000', - feeAmount: '0', - name: 'ERC20B1', - symbol: 'ERC20DT1Symbol' + feeToken: ZERO_ADDRESS, + cap: CAP_AMOUNT, + feeAmount: FEE_ZERO, + name: ERC20_NAME, + symbol: ERC20_SYMBOL } const dispenserParams = { @@ -306,9 +320,9 @@ describe('Nft Factory test', () => { validUntil: providerValidUntil } const consumeMarketFee = { - consumeMarketFeeAddress: '0x0000000000000000000000000000000000000000', - consumeMarketFeeToken: '0x0000000000000000000000000000000000000000', - consumeMarketFeeAmount: '0' + consumeMarketFeeAddress: ZERO_ADDRESS, + consumeMarketFeeToken: ZERO_ADDRESS, + consumeMarketFeeAmount: FEE_ZERO } const orders: TokenOrder[] = [ { @@ -340,10 +354,7 @@ describe('Nft Factory test', () => { }) it('#checkNFT - should return nftAddress if from the factory, or address(0) if not', async () => { - assert( - (await nftFactory.checkNFT(dtAddress)) === - '0x0000000000000000000000000000000000000000' - ) + assert((await nftFactory.checkNFT(dtAddress)) === ZERO_ADDRESS) assert((await nftFactory.checkNFT(nftAddress)) === nftAddress) }) }) From a72c510b9e6bbe87c24c76a565119d2de8df9c6b Mon Sep 17 00:00:00 2001 From: "Miquel A. Cabot" Date: Wed, 23 Mar 2022 15:54:38 +0100 Subject: [PATCH 04/47] add DATA_TOKEN_AMOUNT constant --- test/unit/factories/NftFactory.test.ts | 34 +++++++++++++------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/test/unit/factories/NftFactory.test.ts b/test/unit/factories/NftFactory.test.ts index 00201e12..0b2abd9c 100644 --- a/test/unit/factories/NftFactory.test.ts +++ b/test/unit/factories/NftFactory.test.ts @@ -20,9 +20,10 @@ import { const VESTING_AMOUNT = '10000' const CAP_AMOUNT = '1000000' +const DATA_TOKEN_AMOUNT = web3.utils.toWei('1') const NFT_NAME = '72120Bundle' const NFT_SYMBOL = '72Bundle' -const TOKEN_URI = 'https://oceanprotocol.com/nft/' +const NFT_TOKEN_URI = 'https://oceanprotocol.com/nft/' const ERC20_NAME = 'ERC20B1' const ERC20_SYMBOL = 'ERC20DT1Symbol' const RATE = '1' @@ -77,7 +78,7 @@ describe('Nft Factory test', () => { name: NFT_NAME, symbol: NFT_SYMBOL, templateIndex: 1, - tokenURI: TOKEN_URI + tokenURI: NFT_TOKEN_URI } const ercParams: Erc20CreateParams = { @@ -113,7 +114,7 @@ describe('Nft Factory test', () => { name: NFT_NAME, symbol: NFT_SYMBOL, templateIndex: 1, - tokenURI: TOKEN_URI + tokenURI: NFT_TOKEN_URI } const ercParams: Erc20CreateParams = { @@ -173,7 +174,7 @@ describe('Nft Factory test', () => { name: NFT_NAME, symbol: NFT_SYMBOL, templateIndex: 1, - tokenURI: TOKEN_URI + tokenURI: NFT_TOKEN_URI } const ercParams: Erc20CreateParams = { @@ -223,7 +224,7 @@ describe('Nft Factory test', () => { name: NFT_NAME, symbol: NFT_SYMBOL, templateIndex: 1, - tokenURI: TOKEN_URI + tokenURI: NFT_TOKEN_URI } const ercParams: Erc20CreateParams = { @@ -264,38 +265,37 @@ describe('Nft Factory test', () => { it('#startMultipleTokenOrder- should succed to start multiple orders', async () => { const consumer = user1 // could be different user - const dtAmount = web3.utils.toWei('1') const serviceIndex = 1 // dummy index const consumeFeeAddress = user2 // marketplace fee Collector - const consumeFeeAmount = '0' // fee to be collected on top, requires approval + const consumeFeeAmount = FEE_ZERO // fee to be collected on top, requires approval const consumeFeeToken = contracts.daiAddress // token address for the feeAmount, in this case DAI // we reuse a DT created in a previous test const dtContract = new web3.eth.Contract(ERC20Template.abi as AbiItem[], dtAddress) expect(await dtContract.methods.balanceOf(user1).call()).to.equal('0') - // dt owner mint dtAmount to user1 - await dtContract.methods.mint(user1, dtAmount).send({ from: factoryOwner }) + // dt owner mint DATA_TOKEN_AMOUNT to user1 + await dtContract.methods.mint(user1, DATA_TOKEN_AMOUNT).send({ from: factoryOwner }) - // user1 approves NFTFactory to move his dtAmount + // user1 approves NFTFactory to move his DATA_TOKEN_AMOUNT await dtContract.methods - .approve(contracts.erc721FactoryAddress, dtAmount) + .approve(contracts.erc721FactoryAddress, DATA_TOKEN_AMOUNT) .send({ from: user1 }) // we reuse another DT created in a previous test const dtContract2 = new web3.eth.Contract(ERC20Template.abi as AbiItem[], dtAddress2) expect(await dtContract2.methods.balanceOf(user1).call()).to.equal('0') - // dt owner mint dtAmount to user1 - await dtContract2.methods.mint(user1, dtAmount).send({ from: factoryOwner }) - // user1 approves NFTFactory to move his dtAmount + // dt owner mint DATA_TOKEN_AMOUNT to user1 + await dtContract2.methods.mint(user1, DATA_TOKEN_AMOUNT).send({ from: factoryOwner }) + // user1 approves NFTFactory to move his DATA_TOKEN_AMOUNT await dtContract2.methods - .approve(contracts.erc721FactoryAddress, dtAmount) + .approve(contracts.erc721FactoryAddress, DATA_TOKEN_AMOUNT) .send({ from: user1 }) // we check user1 has enought DTs - expect(await dtContract.methods.balanceOf(user1).call()).to.equal(dtAmount) - expect(await dtContract2.methods.balanceOf(user1).call()).to.equal(dtAmount) + expect(await dtContract.methods.balanceOf(user1).call()).to.equal(DATA_TOKEN_AMOUNT) + expect(await dtContract2.methods.balanceOf(user1).call()).to.equal(DATA_TOKEN_AMOUNT) const providerData = JSON.stringify({ timeout: 0 }) const providerValidUntil = '0' From 054351b88a562dd3658260023fec394b5600247f Mon Sep 17 00:00:00 2001 From: "Miquel A. Cabot" Date: Wed, 23 Mar 2022 16:43:20 +0100 Subject: [PATCH 05/47] refactor nft and dt parameters --- test/unit/factories/NftFactory.test.ts | 154 +++++++++---------------- 1 file changed, 56 insertions(+), 98 deletions(-) diff --git a/test/unit/factories/NftFactory.test.ts b/test/unit/factories/NftFactory.test.ts index 0b2abd9c..0e347648 100644 --- a/test/unit/factories/NftFactory.test.ts +++ b/test/unit/factories/NftFactory.test.ts @@ -2,6 +2,7 @@ import { assert, expect } from 'chai' import { AbiItem } from 'web3-utils/types' import { deployContracts, Addresses } from '../../TestContractHandler' import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json' +import ERC721Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC721Template.sol/ERC721Template.json' import MockERC20 from '@oceanprotocol/contracts/artifacts/contracts/utils/mock/MockERC20Decimals.sol/MockERC20Decimals.json' import { web3 } from '../../config' import { @@ -9,7 +10,8 @@ import { NftCreateData, TokenOrder, ZERO_ADDRESS, - signHash + signHash, + Nft } from '../../../src' import { ProviderFees, @@ -30,8 +32,16 @@ const RATE = '1' const FEE = '0.001' const FEE_ZERO = '0' +const NFT_DATA: NftCreateData = { + name: NFT_NAME, + symbol: NFT_SYMBOL, + templateIndex: 1, + tokenURI: NFT_TOKEN_URI +} + describe('Nft Factory test', () => { let factoryOwner: string + let nftOwner: string let user1: string let user2: string let contracts: Addresses @@ -39,12 +49,26 @@ describe('Nft Factory test', () => { let dtAddress: string let dtAddress2: string let nftAddress: string + let ercParams: Erc20CreateParams before(async () => { const accounts = await web3.eth.getAccounts() factoryOwner = accounts[0] - user1 = accounts[1] - user2 = accounts[2] + nftOwner = accounts[1] + user1 = accounts[2] + user2 = accounts[3] + + ercParams = { + templateIndex: 1, + minter: nftOwner, + feeManager: user2, + mpFeeAddress: user1, + feeToken: ZERO_ADDRESS, + cap: CAP_AMOUNT, + feeAmount: FEE_ZERO, + name: ERC20_NAME, + symbol: ERC20_SYMBOL + } }) it('should deploy contracts', async () => { @@ -72,32 +96,19 @@ describe('Nft Factory test', () => { assert(tokenTemplate.templateAddress === contracts.erc20TemplateAddress) }) + it('#createNft - should create an NFT', async () => { + // we prepare transaction parameters objects + const nftAddress = await nftFactory.createNFT(nftOwner, NFT_DATA) + + // we check the created nft + const nftDatatoken = new Nft(web3, ERC721Template.abi as AbiItem[]) + const tokenURI = await nftDatatoken.getTokenURI(nftAddress, 1) + assert(tokenURI === NFT_TOKEN_URI) + }) + it('#createNftwithErc - should create an NFT and a Datatoken ', async () => { // we prepare transaction parameters objects - const nftData: NftCreateData = { - name: NFT_NAME, - symbol: NFT_SYMBOL, - templateIndex: 1, - tokenURI: NFT_TOKEN_URI - } - - const ercParams: Erc20CreateParams = { - templateIndex: 1, - minter: factoryOwner, - feeManager: user2, - mpFeeAddress: user1, - feeToken: ZERO_ADDRESS, - cap: CAP_AMOUNT, - feeAmount: FEE_ZERO, - name: ERC20_NAME, - symbol: ERC20_SYMBOL - } - - const txReceipt = await nftFactory.createNftWithErc20( - factoryOwner, - nftData, - ercParams - ) + const txReceipt = await nftFactory.createNftWithErc20(nftOwner, NFT_DATA, ercParams) // EVENTS HAVE BEEN EMITTED expect(txReceipt.events.NFTCreated.event === 'NFTCreated') @@ -110,31 +121,12 @@ describe('Nft Factory test', () => { it('#createNftErcWithPool- should create an NFT, a Datatoken and a pool DT/DAI', async () => { // we prepare transaction parameters objects - const nftData: NftCreateData = { - name: NFT_NAME, - symbol: NFT_SYMBOL, - templateIndex: 1, - tokenURI: NFT_TOKEN_URI - } - - const ercParams: Erc20CreateParams = { - templateIndex: 1, - minter: user1, - feeManager: user2, - mpFeeAddress: user1, - feeToken: ZERO_ADDRESS, - cap: CAP_AMOUNT, - feeAmount: FEE_ZERO, - name: ERC20_NAME, - symbol: ERC20_SYMBOL - } - const poolParams: PoolCreationParams = { ssContract: contracts.sideStakingAddress, baseTokenAddress: contracts.daiAddress, baseTokenSender: contracts.erc721FactoryAddress, - publisherAddress: factoryOwner, - marketFeeCollector: factoryOwner, + publisherAddress: nftOwner, + marketFeeCollector: nftOwner, poolTemplateAddress: contracts.poolTemplateAddress, rate: RATE, baseTokenDecimals: 18, @@ -152,12 +144,16 @@ describe('Nft Factory test', () => { ) await daiContract.methods - .approve(contracts.erc721FactoryAddress, web3.utils.toWei(VESTING_AMOUNT)) + .transfer(nftOwner, web3.utils.toWei(VESTING_AMOUNT)) .send({ from: factoryOwner }) + await daiContract.methods + .approve(contracts.erc721FactoryAddress, web3.utils.toWei(VESTING_AMOUNT)) + .send({ from: nftOwner }) + const txReceipt = await nftFactory.createNftErc20WithPool( - factoryOwner, - nftData, + nftOwner, + NFT_DATA, ercParams, poolParams ) @@ -170,41 +166,22 @@ describe('Nft Factory test', () => { it('#createNftErcWithFixedRate- should create an NFT, a datatoken and create a Fixed Rate Exchange', async () => { // we prepare transaction parameters objects - const nftData: NftCreateData = { - name: NFT_NAME, - symbol: NFT_SYMBOL, - templateIndex: 1, - tokenURI: NFT_TOKEN_URI - } - - const ercParams: Erc20CreateParams = { - templateIndex: 1, - minter: factoryOwner, - feeManager: user2, - mpFeeAddress: user1, - feeToken: ZERO_ADDRESS, - cap: CAP_AMOUNT, - feeAmount: FEE_ZERO, - name: ERC20_NAME, - symbol: ERC20_SYMBOL - } - const freParams: FreCreationParams = { fixedRateAddress: contracts.fixedRateAddress, baseTokenAddress: contracts.daiAddress, - owner: factoryOwner, - marketFeeCollector: factoryOwner, + owner: nftOwner, + marketFeeCollector: nftOwner, baseTokenDecimals: 18, datatokenDecimals: 18, fixedRate: RATE, marketFee: FEE, - allowedConsumer: factoryOwner, + allowedConsumer: user1, withMint: false } const txReceipt = await nftFactory.createNftErc20WithFixedRate( - factoryOwner, - nftData, + nftOwner, + NFT_DATA, ercParams, freParams ) @@ -220,25 +197,6 @@ describe('Nft Factory test', () => { it('#createNftErcWithDispenser- should create an NFT, a datatoken and create a Dispenser', async () => { // we prepare transaction parameters objects - const nftData: NftCreateData = { - name: NFT_NAME, - symbol: NFT_SYMBOL, - templateIndex: 1, - tokenURI: NFT_TOKEN_URI - } - - const ercParams: Erc20CreateParams = { - templateIndex: 1, - minter: factoryOwner, - feeManager: user2, - mpFeeAddress: user1, - feeToken: ZERO_ADDRESS, - cap: CAP_AMOUNT, - feeAmount: FEE_ZERO, - name: ERC20_NAME, - symbol: ERC20_SYMBOL - } - const dispenserParams = { dispenserAddress: contracts.dispenserAddress, maxTokens: '1', @@ -248,8 +206,8 @@ describe('Nft Factory test', () => { } const txReceipt = await nftFactory.createNftErc20WithDispenser( - factoryOwner, - nftData, + nftOwner, + NFT_DATA, ercParams, dispenserParams ) @@ -275,7 +233,7 @@ describe('Nft Factory test', () => { expect(await dtContract.methods.balanceOf(user1).call()).to.equal('0') // dt owner mint DATA_TOKEN_AMOUNT to user1 - await dtContract.methods.mint(user1, DATA_TOKEN_AMOUNT).send({ from: factoryOwner }) + await dtContract.methods.mint(user1, DATA_TOKEN_AMOUNT).send({ from: nftOwner }) // user1 approves NFTFactory to move his DATA_TOKEN_AMOUNT await dtContract.methods @@ -287,7 +245,7 @@ describe('Nft Factory test', () => { expect(await dtContract2.methods.balanceOf(user1).call()).to.equal('0') // dt owner mint DATA_TOKEN_AMOUNT to user1 - await dtContract2.methods.mint(user1, DATA_TOKEN_AMOUNT).send({ from: factoryOwner }) + await dtContract2.methods.mint(user1, DATA_TOKEN_AMOUNT).send({ from: nftOwner }) // user1 approves NFTFactory to move his DATA_TOKEN_AMOUNT await dtContract2.methods .approve(contracts.erc721FactoryAddress, DATA_TOKEN_AMOUNT) From c7608ea6b8a79980e5e3ef25921df60aa4abc09f Mon Sep 17 00:00:00 2001 From: "Miquel A. Cabot" Date: Wed, 23 Mar 2022 17:11:34 +0100 Subject: [PATCH 06/47] #createNftwithErc - should increment nft and token count --- test/unit/factories/NftFactory.test.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/test/unit/factories/NftFactory.test.ts b/test/unit/factories/NftFactory.test.ts index 0e347648..4591595e 100644 --- a/test/unit/factories/NftFactory.test.ts +++ b/test/unit/factories/NftFactory.test.ts @@ -106,7 +106,7 @@ describe('Nft Factory test', () => { assert(tokenURI === NFT_TOKEN_URI) }) - 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 const txReceipt = await nftFactory.createNftWithErc20(nftOwner, NFT_DATA, ercParams) @@ -119,6 +119,16 @@ describe('Nft Factory test', () => { 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, NFT_DATA, 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 () => { // we prepare transaction parameters objects const poolParams: PoolCreationParams = { From ed2c725ac2f13b1277e7e8dee7aad5ebe619dab6 Mon Sep 17 00:00:00 2001 From: "Miquel A. Cabot" Date: Wed, 23 Mar 2022 17:11:41 +0100 Subject: [PATCH 07/47] refactor comments --- test/unit/factories/NftFactory.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/unit/factories/NftFactory.test.ts b/test/unit/factories/NftFactory.test.ts index 4591595e..a9bfa9e0 100644 --- a/test/unit/factories/NftFactory.test.ts +++ b/test/unit/factories/NftFactory.test.ts @@ -110,7 +110,7 @@ describe('Nft Factory test', () => { // we prepare transaction parameters objects const txReceipt = await nftFactory.createNftWithErc20(nftOwner, NFT_DATA, ercParams) - // EVENTS HAVE BEEN EMITTED + // events have been emitted expect(txReceipt.events.NFTCreated.event === 'NFTCreated') expect(txReceipt.events.TokenCreated.event === 'TokenCreated') @@ -168,7 +168,7 @@ describe('Nft Factory test', () => { poolParams ) - // EVENTS HAVE BEEN EMITTED + // events have been emitted expect(txReceipt.events.NFTCreated.event === 'NFTCreated') expect(txReceipt.events.TokenCreated.event === 'TokenCreated') expect(txReceipt.events.NewPool.event === 'NewPool') @@ -196,7 +196,7 @@ describe('Nft Factory test', () => { freParams ) - // EVENTS HAVE BEEN EMITTED + // events have been emitted expect(txReceipt.events.NFTCreated.event === 'NFTCreated') expect(txReceipt.events.TokenCreated.event === 'TokenCreated') expect(txReceipt.events.NewFixedRate.event === 'NewFixedRate') @@ -222,7 +222,7 @@ describe('Nft Factory test', () => { dispenserParams ) - // EVENTS HAVE BEEN EMITTED + // events have been emitted expect(txReceipt.events.NFTCreated.event === 'NFTCreated') expect(txReceipt.events.TokenCreated.event === 'TokenCreated') expect(txReceipt.events.DispenserCreated.event === 'DispenserCreated') From 5e9f99752c0411c2f2e96bd517827eb725256ebd Mon Sep 17 00:00:00 2001 From: "Miquel A. Cabot" Date: Wed, 23 Mar 2022 19:19:33 +0100 Subject: [PATCH 08/47] test adding disabling and reactivating templates --- test/unit/factories/NftFactory.test.ts | 68 ++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/test/unit/factories/NftFactory.test.ts b/test/unit/factories/NftFactory.test.ts index a9bfa9e0..b694c723 100644 --- a/test/unit/factories/NftFactory.test.ts +++ b/test/unit/factories/NftFactory.test.ts @@ -325,4 +325,72 @@ describe('Nft Factory test', () => { assert((await nftFactory.checkNFT(dtAddress)) === ZERO_ADDRESS) 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) + }) }) From 0e876edadf4e2571c17457d71ff12e94ed703e5f Mon Sep 17 00:00:00 2001 From: "Miquel A. Cabot" Date: Thu, 24 Mar 2022 09:55:27 +0100 Subject: [PATCH 09/47] fix error in NftFactory.disableTokenTemplate() and NftFactory.reactivateTokenTemplate() --- src/factories/NFTFactory.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/factories/NFTFactory.ts b/src/factories/NFTFactory.ts index 5af4822f..ce3e97da 100644 --- a/src/factories/NFTFactory.ts +++ b/src/factories/NFTFactory.ts @@ -492,14 +492,14 @@ export class NftFactory { if ((await this.getOwner()) !== address) { 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`) } if (templateIndex === 0) { 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`) } const estGas = await this.estGasDisableTokenTemplate(address, templateIndex) @@ -551,7 +551,7 @@ export class NftFactory { if ((await this.getOwner()) !== address) { 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`) } From db4d22b5bbd8f3cccd538ade16d45ed75f5b8d64 Mon Sep 17 00:00:00 2001 From: "Miquel A. Cabot" Date: Thu, 24 Mar 2022 11:09:07 +0100 Subject: [PATCH 10/47] check correct allowance amount --- test/unit/pools/balancer/Pool.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/pools/balancer/Pool.test.ts b/test/unit/pools/balancer/Pool.test.ts index fb78cd36..3f503083 100644 --- a/test/unit/pools/balancer/Pool.test.ts +++ b/test/unit/pools/balancer/Pool.test.ts @@ -85,7 +85,7 @@ describe('Pool unit test', () => { contracts.erc721FactoryAddress ) - assert(parseInt(allowCheck) >= 8000) + assert(parseInt(allowCheck) >= 2000) allowCheck = await allowance( web3, contracts.usdcAddress, From adb8138e8906344924a73141ef6e00ca4f8e66d2 Mon Sep 17 00:00:00 2001 From: "Miquel A. Cabot" Date: Thu, 24 Mar 2022 12:29:24 +0100 Subject: [PATCH 11/47] refactor script names in package.json --- package.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 725c5e77..ca3ab828 100644 --- a/package.json +++ b/package.json @@ -27,19 +27,19 @@ "changelog": "auto-changelog -p", "prepublishOnly": "npm run build", "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:ss": "npm run mocha -- 'test/unit/pools/ssContracts/SideStaking.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: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/factories/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:provider": "npm run mocha -- 'test/integration/Provider.test.ts'", "test:unit": "npm run mocha -- 'test/unit/**/*.test.ts'", "test:unit:cover": "nyc --report-dir coverage/unit npm run test:unit", "test:integration": "npm run mocha -- 'test/integration/**/*.test.ts'", - "test:provider": "npm run mocha -- 'test/integration/Provider.test.ts'", "test:integration:cover": "nyc --report-dir coverage/integration --no-clean npm run test:integration" }, "repository": { From 71e21f56e4169ddac9cf48bef617d62b195a175f Mon Sep 17 00:00:00 2001 From: "Miquel A. Cabot" Date: Thu, 24 Mar 2022 12:45:37 +0100 Subject: [PATCH 12/47] put constants inside test function --- test/unit/factories/NftFactory.test.ts | 38 +++++++++++++------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/test/unit/factories/NftFactory.test.ts b/test/unit/factories/NftFactory.test.ts index b694c723..cb47b2ae 100644 --- a/test/unit/factories/NftFactory.test.ts +++ b/test/unit/factories/NftFactory.test.ts @@ -20,25 +20,6 @@ import { PoolCreationParams } from '../../../src/@types' -const VESTING_AMOUNT = '10000' -const CAP_AMOUNT = '1000000' -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_ZERO = '0' - -const NFT_DATA: NftCreateData = { - name: NFT_NAME, - symbol: NFT_SYMBOL, - templateIndex: 1, - tokenURI: NFT_TOKEN_URI -} - describe('Nft Factory test', () => { let factoryOwner: string let nftOwner: string @@ -51,6 +32,25 @@ describe('Nft Factory test', () => { let nftAddress: string let ercParams: Erc20CreateParams + const VESTING_AMOUNT = '10000' + const CAP_AMOUNT = '1000000' + 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_ZERO = '0' + + const NFT_DATA: NftCreateData = { + name: NFT_NAME, + symbol: NFT_SYMBOL, + templateIndex: 1, + tokenURI: NFT_TOKEN_URI + } + before(async () => { const accounts = await web3.eth.getAccounts() factoryOwner = accounts[0] From e49a94c0cb06bee6103ac3eb3a47166ff8d9b996 Mon Sep 17 00:00:00 2001 From: "Miquel A. Cabot" Date: Wed, 30 Mar 2022 17:36:54 +0200 Subject: [PATCH 13/47] remove abi import --- test/unit/factories/NftFactory.test.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/unit/factories/NftFactory.test.ts b/test/unit/factories/NftFactory.test.ts index 9bab3ec8..07aaf094 100644 --- a/test/unit/factories/NftFactory.test.ts +++ b/test/unit/factories/NftFactory.test.ts @@ -2,7 +2,6 @@ import { assert, expect } from 'chai' import { AbiItem } from 'web3-utils/types' import { deployContracts, Addresses } from '../../TestContractHandler' import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json' -import ERC721Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC721Template.sol/ERC721Template.json' import MockERC20 from '@oceanprotocol/contracts/artifacts/contracts/utils/mock/MockERC20Decimals.sol/MockERC20Decimals.json' import { web3 } from '../../config' import { @@ -101,7 +100,7 @@ describe('Nft Factory test', () => { const nftAddress = await nftFactory.createNFT(nftOwner, NFT_DATA) // we check the created nft - const nftDatatoken = new Nft(web3, ERC721Template.abi as AbiItem[]) + const nftDatatoken = new Nft(web3) const tokenURI = await nftDatatoken.getTokenURI(nftAddress, 1) assert(tokenURI === NFT_TOKEN_URI) }) From 4e1a79ac216b4e4c36d19fabb759572dacb41547 Mon Sep 17 00:00:00 2001 From: "Miquel A. Cabot" Date: Wed, 6 Apr 2022 17:03:50 +0200 Subject: [PATCH 14/47] solve problem with NftCreateData constant --- test/unit/factories/NftFactory.test.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/unit/factories/NftFactory.test.ts b/test/unit/factories/NftFactory.test.ts index 07aaf094..4525bbbc 100644 --- a/test/unit/factories/NftFactory.test.ts +++ b/test/unit/factories/NftFactory.test.ts @@ -47,7 +47,9 @@ describe('Nft Factory test', () => { name: NFT_NAME, symbol: NFT_SYMBOL, templateIndex: 1, - tokenURI: NFT_TOKEN_URI + tokenURI: NFT_TOKEN_URI, + transferable: true, + owner: factoryOwner } before(async () => { @@ -57,6 +59,8 @@ describe('Nft Factory test', () => { user1 = accounts[2] user2 = accounts[3] + NFT_DATA.owner = factoryOwner + ercParams = { templateIndex: 1, minter: nftOwner, From 3e2efc0ef62c237795483b0eb6bc4b22bab08456 Mon Sep 17 00:00:00 2001 From: "Miquel A. Cabot" Date: Thu, 7 Apr 2022 20:43:00 +0200 Subject: [PATCH 15/47] refactor ercParams const --- test/unit/factories/NftFactory.test.ts | 38 ++++++++++++++------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/test/unit/factories/NftFactory.test.ts b/test/unit/factories/NftFactory.test.ts index 4525bbbc..b746e791 100644 --- a/test/unit/factories/NftFactory.test.ts +++ b/test/unit/factories/NftFactory.test.ts @@ -29,7 +29,6 @@ describe('Nft Factory test', () => { let dtAddress: string let dtAddress2: string let nftAddress: string - let ercParams: Erc20CreateParams const VESTING_AMOUNT = '10000' const CAP_AMOUNT = '1000000' @@ -52,6 +51,18 @@ describe('Nft Factory test', () => { owner: factoryOwner } + const ERC_PARAMS: Erc20CreateParams = { + templateIndex: 1, + minter: nftOwner, + paymentCollector: user2, + mpFeeAddress: user1, + feeToken: ZERO_ADDRESS, + cap: CAP_AMOUNT, + feeAmount: FEE_ZERO, + name: ERC20_NAME, + symbol: ERC20_SYMBOL + } + before(async () => { const accounts = await web3.eth.getAccounts() factoryOwner = accounts[0] @@ -60,18 +71,9 @@ describe('Nft Factory test', () => { user2 = accounts[3] NFT_DATA.owner = factoryOwner - - ercParams = { - templateIndex: 1, - minter: nftOwner, - paymentCollector: user2, - mpFeeAddress: user1, - feeToken: ZERO_ADDRESS, - cap: CAP_AMOUNT, - feeAmount: FEE_ZERO, - name: ERC20_NAME, - symbol: ERC20_SYMBOL - } + ERC_PARAMS.minter = nftOwner + ERC_PARAMS.paymentCollector = user2 + ERC_PARAMS.mpFeeAddress = user1 }) it('should deploy contracts', async () => { @@ -111,7 +113,7 @@ describe('Nft Factory test', () => { it('#createNftwithErc - should create an NFT and a Datatoken', async () => { // we prepare transaction parameters objects - const txReceipt = await nftFactory.createNftWithErc20(nftOwner, NFT_DATA, ercParams) + const txReceipt = await nftFactory.createNftWithErc20(nftOwner, NFT_DATA, ERC_PARAMS) // events have been emitted expect(txReceipt.events.NFTCreated.event === 'NFTCreated') @@ -126,7 +128,7 @@ describe('Nft Factory test', () => { const currentNFTCount = await nftFactory.getCurrentNFTCount() const currentTokenCount = await nftFactory.getCurrentTokenCount() - await nftFactory.createNftWithErc20(nftOwner, NFT_DATA, ercParams) + await nftFactory.createNftWithErc20(nftOwner, NFT_DATA, ERC_PARAMS) expect((await nftFactory.getCurrentNFTCount()) === currentNFTCount + 1) expect((await nftFactory.getCurrentTokenCount()) === currentTokenCount + 1) @@ -167,7 +169,7 @@ describe('Nft Factory test', () => { const txReceipt = await nftFactory.createNftErc20WithPool( nftOwner, NFT_DATA, - ercParams, + ERC_PARAMS, poolParams ) @@ -195,7 +197,7 @@ describe('Nft Factory test', () => { const txReceipt = await nftFactory.createNftErc20WithFixedRate( nftOwner, NFT_DATA, - ercParams, + ERC_PARAMS, freParams ) @@ -221,7 +223,7 @@ describe('Nft Factory test', () => { const txReceipt = await nftFactory.createNftErc20WithDispenser( nftOwner, NFT_DATA, - ercParams, + ERC_PARAMS, dispenserParams ) From c169007f1251ed4447fe8c273d20d0b70df21145 Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Tue, 19 Apr 2022 18:41:32 +0200 Subject: [PATCH 16/47] Creating initial setPublishingMarketFee function --- src/tokens/Datatoken.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/tokens/Datatoken.ts b/src/tokens/Datatoken.ts index 701bb302..93f49f2b 100644 --- a/src/tokens/Datatoken.ts +++ b/src/tokens/Datatoken.ts @@ -1357,4 +1357,24 @@ export class Datatoken { const balance = await dtContract.methods.balanceOf(address).call() return this.web3.utils.fromWei(balance) } + + /** + * @dev setPublishingMarketFee + * Only publishMarketFeeAddress can call it + * This function allows to set the fee required by the publisherMarket + * @param _publishMarketFeeAddress new _publishMarketFeeAddress + * @param _publishMarketFeeToken new _publishMarketFeeToken + * @param _publishMarketFeeAmount new fee amount + */ + public async setPublishingMarketFee( + publishMarketFeeAddress: string, + publishMarketFeeToken: string, + publishMarketFeeAmount: number + ): Promise { + const dtContract = new this.web3.eth.Contract(this.datatokensAbi, datatokenAddress, { + from: address + }) + const balance = await dtContract.methods.setPublishingMarketFee(address).call() + return this.web3.utils.fromWei(balance) + } } From 518dc6715eb0f28a00d956a5f68382affbc9f75d Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Wed, 20 Apr 2022 12:59:27 +0200 Subject: [PATCH 17/47] Updating parameters for setPublishingMarketFee function --- src/tokens/Datatoken.ts | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/tokens/Datatoken.ts b/src/tokens/Datatoken.ts index 93f49f2b..7e724ea6 100644 --- a/src/tokens/Datatoken.ts +++ b/src/tokens/Datatoken.ts @@ -1362,19 +1362,28 @@ export class Datatoken { * @dev setPublishingMarketFee * Only publishMarketFeeAddress can call it * This function allows to set the fee required by the publisherMarket - * @param _publishMarketFeeAddress new _publishMarketFeeAddress - * @param _publishMarketFeeToken new _publishMarketFeeToken - * @param _publishMarketFeeAmount new fee amount + * @param {String} datatokenAddress Datatoken adress + * @param publishMarketFeeAddress new publish Market Fee Address + * @param publishMarketFeeToken new publish Market Fee Token + * @param publishMarketFeeAmount new fee amount + * @param {String} address user adress */ public async setPublishingMarketFee( + datatokenAddress: string, publishMarketFeeAddress: string, - publishMarketFeeToken: string, - publishMarketFeeAmount: number - ): Promise { + publishMarketFeeToken: string, + publishMarketFeeAmount: number, + address: string + ) { const dtContract = new this.web3.eth.Contract(this.datatokensAbi, datatokenAddress, { from: address }) - const balance = await dtContract.methods.setPublishingMarketFee(address).call() - return this.web3.utils.fromWei(balance) + await dtContract.methods + .setPublishingMarketFee( + publishMarketFeeAddress, + publishMarketFeeToken, + publishMarketFeeAmount + ) + .call() } } From edcb01090de823cd7212979495e66afcf332e9a1 Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Wed, 20 Apr 2022 13:29:12 +0200 Subject: [PATCH 18/47] Adding getPublishingMarketFee function --- src/tokens/Datatoken.ts | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/tokens/Datatoken.ts b/src/tokens/Datatoken.ts index 7e724ea6..7a956b52 100644 --- a/src/tokens/Datatoken.ts +++ b/src/tokens/Datatoken.ts @@ -44,6 +44,12 @@ export interface DispenserParams { allowedSwapper?: string // only account that can ask tokens. set address(0) if not required } +export interface PublishingMarketFee { + publishMarketFeeAddress: string + publishMarketFeeToken: string + publishMarketFeeAmount: number +} + export class Datatoken { public GASLIMIT_DEFAULT = 1000000 public factoryAddress: string @@ -1362,10 +1368,10 @@ export class Datatoken { * @dev setPublishingMarketFee * Only publishMarketFeeAddress can call it * This function allows to set the fee required by the publisherMarket - * @param {String} datatokenAddress Datatoken adress - * @param publishMarketFeeAddress new publish Market Fee Address - * @param publishMarketFeeToken new publish Market Fee Token - * @param publishMarketFeeAmount new fee amount + * @param {string} datatokenAddress Datatoken adress + * @param {string} publishMarketFeeAddress new publish Market Fee Address + * @param {string} publishMarketFeeToken new publish Market Fee Token + * @param {number} publishMarketFeeAmount new fee amount * @param {String} address user adress */ public async setPublishingMarketFee( @@ -1386,4 +1392,24 @@ export class Datatoken { ) .call() } + + /** + * @dev getPublishingMarketFee + * Get publishingMarket Fee + * This function allows to get the current fee set by the publishing market + * @param {String} datatokenAddress Datatoken adress + * @param {String} address user adress + * @return {Promise} Current fee set by the publishing market + */ + public async getPublishingMarketFee( + datatokenAddress: string, + address: string + ): Promise { + const dtContract = new this.web3.eth.Contract(this.datatokensAbi, datatokenAddress, { + from: address + }) + + const publishingMarketFee = await dtContract.methods.getPublishingMarketFee().call() + return publishingMarketFee + } } From 44db9db5a4a1c44c752d02c7ef91d827d9f72c1c Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Wed, 20 Apr 2022 14:42:51 +0200 Subject: [PATCH 19/47] Writting tests for setPublishingMarketFee --- src/tokens/Datatoken.ts | 6 +++--- test/unit/tokens/Datatoken.test.ts | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/tokens/Datatoken.ts b/src/tokens/Datatoken.ts index 7a956b52..a9c69f02 100644 --- a/src/tokens/Datatoken.ts +++ b/src/tokens/Datatoken.ts @@ -47,7 +47,7 @@ export interface DispenserParams { export interface PublishingMarketFee { publishMarketFeeAddress: string publishMarketFeeToken: string - publishMarketFeeAmount: number + publishMarketFeeAmount: string } export class Datatoken { @@ -1371,14 +1371,14 @@ export class Datatoken { * @param {string} datatokenAddress Datatoken adress * @param {string} publishMarketFeeAddress new publish Market Fee Address * @param {string} publishMarketFeeToken new publish Market Fee Token - * @param {number} publishMarketFeeAmount new fee amount + * @param {string} publishMarketFeeAmount new fee amount * @param {String} address user adress */ public async setPublishingMarketFee( datatokenAddress: string, publishMarketFeeAddress: string, publishMarketFeeToken: string, - publishMarketFeeAmount: number, + publishMarketFeeAmount: string, address: string ) { const dtContract = new this.web3.eth.Contract(this.datatokensAbi, datatokenAddress, { diff --git a/test/unit/tokens/Datatoken.test.ts b/test/unit/tokens/Datatoken.test.ts index 8c84e8b0..9e8eea2b 100644 --- a/test/unit/tokens/Datatoken.test.ts +++ b/test/unit/tokens/Datatoken.test.ts @@ -552,4 +552,30 @@ describe('Datatoken', () => { const key = web3.utils.keccak256(datatokenAddress) assert((await nftDatatoken.getData(nftAddress, key)) === OldData) }) + + it('#setPublishingMarketFee - nftOwner should be able to set the Publishing Market Fee', async () => { + const originalPublishingMarketFee = await datatoken.getPublishingMarketFee( + datatokenAddress, + nftOwner + ) + try { + await datatoken.setPublishingMarketFee( + datatokenAddress, + nftOwner, + contracts.daiAddress, + web3.utils.toWei('10'), + nftOwner + ) + } catch (e) { + console.log('Error', e) + } + const newPublishingMarketFee = await datatoken.getPublishingMarketFee( + datatokenAddress, + nftOwner + ) + assert(newPublishingMarketFee !== originalPublishingMarketFee) + assert(newPublishingMarketFee.publishMarketFeeAddress === nftOwner) + assert(newPublishingMarketFee.publishMarketFeeToken === contracts.daiAddress) + assert(newPublishingMarketFee.publishMarketFeeAmount === web3.utils.toWei('10')) + }) }) From ee90d58cdef749e71381ebd1374df2581431d928 Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Wed, 20 Apr 2022 15:24:33 +0200 Subject: [PATCH 20/47] Fix linting --- test/unit/tokens/Datatoken.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/tokens/Datatoken.test.ts b/test/unit/tokens/Datatoken.test.ts index 9e8eea2b..889ab46f 100644 --- a/test/unit/tokens/Datatoken.test.ts +++ b/test/unit/tokens/Datatoken.test.ts @@ -552,7 +552,7 @@ describe('Datatoken', () => { const key = web3.utils.keccak256(datatokenAddress) assert((await nftDatatoken.getData(nftAddress, key)) === OldData) }) - + it('#setPublishingMarketFee - nftOwner should be able to set the Publishing Market Fee', async () => { const originalPublishingMarketFee = await datatoken.getPublishingMarketFee( datatokenAddress, From 257d1aeeead876922b526f7e70f415794ec3bc9c Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Wed, 20 Apr 2022 16:44:15 +0200 Subject: [PATCH 21/47] Adding extra test --- test/unit/tokens/Datatoken.test.ts | 44 ++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/test/unit/tokens/Datatoken.test.ts b/test/unit/tokens/Datatoken.test.ts index 889ab46f..8c0cbc9f 100644 --- a/test/unit/tokens/Datatoken.test.ts +++ b/test/unit/tokens/Datatoken.test.ts @@ -553,11 +553,34 @@ describe('Datatoken', () => { assert((await nftDatatoken.getData(nftAddress, key)) === OldData) }) + it('#setPublishingMarketFee - User should not be able to set the Publishing Market Fee', async () => { + const originalPublishingMarketFee = await datatoken.getPublishingMarketFee( + datatokenAddress, + user2 + ) + try { + await datatoken.setPublishingMarketFee( + datatokenAddress, + user2, + contracts.daiAddress, + web3.utils.toWei('10'), + user2 + ) + } catch (e) { + console.log('Error', e) + } + const newPublishingMarketFee = await datatoken.getPublishingMarketFee( + datatokenAddress, + user2 + ) + assert(newPublishingMarketFee === originalPublishingMarketFee) + }) it('#setPublishingMarketFee - nftOwner should be able to set the Publishing Market Fee', async () => { const originalPublishingMarketFee = await datatoken.getPublishingMarketFee( datatokenAddress, nftOwner ) + console.log('originalPublishingMarketFee', originalPublishingMarketFee) try { await datatoken.setPublishingMarketFee( datatokenAddress, @@ -573,9 +596,24 @@ describe('Datatoken', () => { datatokenAddress, nftOwner ) + + console.log('newPublishingMarketFee', newPublishingMarketFee) + console.log( + newPublishingMarketFee.publishMarketFeeAddress, + originalPublishingMarketFee.publishMarketFeeAddress, + nftOwner + ) + console.log( + newPublishingMarketFee.publishMarketFeeToken, + originalPublishingMarketFee.publishMarketFeeToken, + contracts.daiAddress + ) + console.log( + newPublishingMarketFee.publishMarketFeeAmount, + originalPublishingMarketFee.publishMarketFeeAmount, + web3.utils.toWei('10') + ) + assert(newPublishingMarketFee !== originalPublishingMarketFee) - assert(newPublishingMarketFee.publishMarketFeeAddress === nftOwner) - assert(newPublishingMarketFee.publishMarketFeeToken === contracts.daiAddress) - assert(newPublishingMarketFee.publishMarketFeeAmount === web3.utils.toWei('10')) }) }) From 5cedb37d80267c30f9608bafdd701ad472e387b5 Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Thu, 21 Apr 2022 11:18:45 +0200 Subject: [PATCH 22/47] Adding additional assert to tests --- test/unit/tokens/Datatoken.test.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/unit/tokens/Datatoken.test.ts b/test/unit/tokens/Datatoken.test.ts index 8c0cbc9f..a109ba2c 100644 --- a/test/unit/tokens/Datatoken.test.ts +++ b/test/unit/tokens/Datatoken.test.ts @@ -558,6 +558,7 @@ describe('Datatoken', () => { datatokenAddress, user2 ) + console.log('originalPublishingMarketFee', originalPublishingMarketFee) try { await datatoken.setPublishingMarketFee( datatokenAddress, @@ -568,11 +569,13 @@ describe('Datatoken', () => { ) } catch (e) { console.log('Error', e) + assert(e.message === 'ERC20Template: not publishMarketFeeAddress') } const newPublishingMarketFee = await datatoken.getPublishingMarketFee( datatokenAddress, user2 ) + console.log('newPublishingMarketFee', newPublishingMarketFee) assert(newPublishingMarketFee === originalPublishingMarketFee) }) it('#setPublishingMarketFee - nftOwner should be able to set the Publishing Market Fee', async () => { From d99662580954a7831207be5355a050aa2bfac0be Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Thu, 21 Apr 2022 11:47:47 +0200 Subject: [PATCH 23/47] Updating assert statements --- test/unit/tokens/Datatoken.test.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test/unit/tokens/Datatoken.test.ts b/test/unit/tokens/Datatoken.test.ts index a109ba2c..476256c7 100644 --- a/test/unit/tokens/Datatoken.test.ts +++ b/test/unit/tokens/Datatoken.test.ts @@ -576,7 +576,18 @@ describe('Datatoken', () => { user2 ) console.log('newPublishingMarketFee', newPublishingMarketFee) - assert(newPublishingMarketFee === originalPublishingMarketFee) + assert( + newPublishingMarketFee.publishMarketFeeAddress === + originalPublishingMarketFee.publishMarketFeeAddress + ) + assert( + newPublishingMarketFee.publishMarketFeeAmount === + originalPublishingMarketFee.publishMarketFeeAmount + ) + assert( + newPublishingMarketFee.publishMarketFeeToken === + originalPublishingMarketFee.publishMarketFeeToken + ) }) it('#setPublishingMarketFee - nftOwner should be able to set the Publishing Market Fee', async () => { const originalPublishingMarketFee = await datatoken.getPublishingMarketFee( From 74f4642ad0899816d8d20bf438c5851755efb4ec Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Thu, 21 Apr 2022 12:22:31 +0200 Subject: [PATCH 24/47] Adding additional assert statements --- test/unit/tokens/Datatoken.test.ts | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/test/unit/tokens/Datatoken.test.ts b/test/unit/tokens/Datatoken.test.ts index 476256c7..4e7a59e6 100644 --- a/test/unit/tokens/Datatoken.test.ts +++ b/test/unit/tokens/Datatoken.test.ts @@ -558,7 +558,6 @@ describe('Datatoken', () => { datatokenAddress, user2 ) - console.log('originalPublishingMarketFee', originalPublishingMarketFee) try { await datatoken.setPublishingMarketFee( datatokenAddress, @@ -568,14 +567,12 @@ describe('Datatoken', () => { user2 ) } catch (e) { - console.log('Error', e) assert(e.message === 'ERC20Template: not publishMarketFeeAddress') } const newPublishingMarketFee = await datatoken.getPublishingMarketFee( datatokenAddress, user2 ) - console.log('newPublishingMarketFee', newPublishingMarketFee) assert( newPublishingMarketFee.publishMarketFeeAddress === originalPublishingMarketFee.publishMarketFeeAddress @@ -612,22 +609,13 @@ describe('Datatoken', () => { ) console.log('newPublishingMarketFee', newPublishingMarketFee) - console.log( - newPublishingMarketFee.publishMarketFeeAddress, - originalPublishingMarketFee.publishMarketFeeAddress, - nftOwner - ) - console.log( - newPublishingMarketFee.publishMarketFeeToken, - originalPublishingMarketFee.publishMarketFeeToken, - contracts.daiAddress - ) - console.log( - newPublishingMarketFee.publishMarketFeeAmount, - originalPublishingMarketFee.publishMarketFeeAmount, - web3.utils.toWei('10') - ) + console.log(newPublishingMarketFee.publishMarketFeeAddress, nftOwner) + console.log(newPublishingMarketFee.publishMarketFeeToken, contracts.daiAddress) + console.log(newPublishingMarketFee.publishMarketFeeAmount, web3.utils.toWei('10')) assert(newPublishingMarketFee !== originalPublishingMarketFee) + assert(newPublishingMarketFee.publishMarketFeeAddress === nftOwner) + assert(newPublishingMarketFee.publishMarketFeeAmount === web3.utils.toWei('10')) + assert(newPublishingMarketFee.publishMarketFeeToken === contracts.daiAddress) }) }) From c6ddaa094a27d536e2b7f1717a71f2db6a8fbf0a Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Thu, 21 Apr 2022 12:40:27 +0200 Subject: [PATCH 25/47] Updating return values --- src/tokens/Datatoken.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/tokens/Datatoken.ts b/src/tokens/Datatoken.ts index a9c69f02..7b499dda 100644 --- a/src/tokens/Datatoken.ts +++ b/src/tokens/Datatoken.ts @@ -1410,6 +1410,11 @@ export class Datatoken { }) const publishingMarketFee = await dtContract.methods.getPublishingMarketFee().call() - return publishingMarketFee + const returnValues = { + publishMarketFeeAddress: publishingMarketFee[0], + publishMarketFeeToken: publishingMarketFee[1], + publishMarketFeeAmount: publishingMarketFee[2] + } + return returnValues } } From a81cdddc30935771f821186bb6facd7f9adef7f7 Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Thu, 21 Apr 2022 12:48:28 +0200 Subject: [PATCH 26/47] Updating tests --- src/tokens/Datatoken.ts | 2 ++ test/unit/tokens/Datatoken.test.ts | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/tokens/Datatoken.ts b/src/tokens/Datatoken.ts index 7b499dda..9048fe2d 100644 --- a/src/tokens/Datatoken.ts +++ b/src/tokens/Datatoken.ts @@ -1410,11 +1410,13 @@ export class Datatoken { }) const publishingMarketFee = await dtContract.methods.getPublishingMarketFee().call() + console.log('publishingMarketFee', publishingMarketFee) const returnValues = { publishMarketFeeAddress: publishingMarketFee[0], publishMarketFeeToken: publishingMarketFee[1], publishMarketFeeAmount: publishingMarketFee[2] } + console.log('returnValues', returnValues) return returnValues } } diff --git a/test/unit/tokens/Datatoken.test.ts b/test/unit/tokens/Datatoken.test.ts index 4e7a59e6..d933aab5 100644 --- a/test/unit/tokens/Datatoken.test.ts +++ b/test/unit/tokens/Datatoken.test.ts @@ -586,19 +586,20 @@ describe('Datatoken', () => { originalPublishingMarketFee.publishMarketFeeToken ) }) - it('#setPublishingMarketFee - nftOwner should be able to set the Publishing Market Fee', async () => { + it('#setPublishingMarketFee - Marketplace fee address should be able to set the Publishing Market Fee', async () => { + console.log('users: ', user1, user2, user3, nftOwner, erc20DeployerUser) const originalPublishingMarketFee = await datatoken.getPublishingMarketFee( datatokenAddress, - nftOwner + user1 ) console.log('originalPublishingMarketFee', originalPublishingMarketFee) try { await datatoken.setPublishingMarketFee( datatokenAddress, - nftOwner, + user1, contracts.daiAddress, web3.utils.toWei('10'), - nftOwner + user1 ) } catch (e) { console.log('Error', e) From 4eefc083e2a96d5302be5426b913e85df4a7ce68 Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Thu, 21 Apr 2022 12:58:31 +0200 Subject: [PATCH 27/47] Updating user addresses --- test/unit/tokens/Datatoken.test.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/unit/tokens/Datatoken.test.ts b/test/unit/tokens/Datatoken.test.ts index d933aab5..03bd4f47 100644 --- a/test/unit/tokens/Datatoken.test.ts +++ b/test/unit/tokens/Datatoken.test.ts @@ -556,22 +556,22 @@ describe('Datatoken', () => { it('#setPublishingMarketFee - User should not be able to set the Publishing Market Fee', async () => { const originalPublishingMarketFee = await datatoken.getPublishingMarketFee( datatokenAddress, - user2 + user3 ) try { await datatoken.setPublishingMarketFee( datatokenAddress, - user2, + user3, contracts.daiAddress, web3.utils.toWei('10'), - user2 + user3 ) } catch (e) { assert(e.message === 'ERC20Template: not publishMarketFeeAddress') } const newPublishingMarketFee = await datatoken.getPublishingMarketFee( datatokenAddress, - user2 + user3 ) assert( newPublishingMarketFee.publishMarketFeeAddress === @@ -590,23 +590,23 @@ describe('Datatoken', () => { console.log('users: ', user1, user2, user3, nftOwner, erc20DeployerUser) const originalPublishingMarketFee = await datatoken.getPublishingMarketFee( datatokenAddress, - user1 + user2 ) console.log('originalPublishingMarketFee', originalPublishingMarketFee) try { await datatoken.setPublishingMarketFee( datatokenAddress, - user1, + user2, contracts.daiAddress, web3.utils.toWei('10'), - user1 + user2 ) } catch (e) { console.log('Error', e) } const newPublishingMarketFee = await datatoken.getPublishingMarketFee( datatokenAddress, - nftOwner + user2 ) console.log('newPublishingMarketFee', newPublishingMarketFee) @@ -615,7 +615,7 @@ describe('Datatoken', () => { console.log(newPublishingMarketFee.publishMarketFeeAmount, web3.utils.toWei('10')) assert(newPublishingMarketFee !== originalPublishingMarketFee) - assert(newPublishingMarketFee.publishMarketFeeAddress === nftOwner) + assert(newPublishingMarketFee.publishMarketFeeAddress === user2) assert(newPublishingMarketFee.publishMarketFeeAmount === web3.utils.toWei('10')) assert(newPublishingMarketFee.publishMarketFeeToken === contracts.daiAddress) }) From 8c9e46a8ddea90b672272a27a6cb51159434b873 Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Thu, 21 Apr 2022 15:14:32 +0200 Subject: [PATCH 28/47] Adding estimate gas method and fixing tests --- src/tokens/Datatoken.ts | 51 ++++++++++++++++++++++++++++-- test/unit/tokens/Datatoken.test.ts | 22 ++++++------- 2 files changed, 58 insertions(+), 15 deletions(-) diff --git a/src/tokens/Datatoken.ts b/src/tokens/Datatoken.ts index 9048fe2d..59e13fe9 100644 --- a/src/tokens/Datatoken.ts +++ b/src/tokens/Datatoken.ts @@ -1364,6 +1364,42 @@ export class Datatoken { return this.web3.utils.fromWei(balance) } + /** + * @dev estGasSetPublishingMarketFee + * Estimating gas for publishMarketFeeAddress method + * @param {string} datatokenAddress Datatoken adress + * @param {string} publishMarketFeeAddress new publish Market Fee Address + * @param {string} publishMarketFeeToken new publish Market Fee Token + * @param {string} publishMarketFeeAmount new fee amount + * @param {String} address user adress + */ + public async estGasSetPublishingMarketFee( + datatokenAddress: string, + publishMarketFeeAddress: string, + publishMarketFeeToken: string, + publishMarketFeeAmount: string, + address: string + ): Promise { + // Estimate gas cost for publishMarketFeeAddress method + const gasLimitDefault = this.GASLIMIT_DEFAULT + const dtContract = new this.web3.eth.Contract(this.datatokensAbi, datatokenAddress, { + from: address + }) + let estGas + try { + estGas = await dtContract.methods + .setPublishingMarketFee( + publishMarketFeeAddress, + publishMarketFeeToken, + publishMarketFeeAmount + ) + .estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas)) + } catch (error) { + estGas = gasLimitDefault + } + return estGas + } + /** * @dev setPublishingMarketFee * Only publishMarketFeeAddress can call it @@ -1384,13 +1420,24 @@ export class Datatoken { const dtContract = new this.web3.eth.Contract(this.datatokensAbi, datatokenAddress, { from: address }) + const estGas = await this.estGasSetPublishingMarketFee( + datatokenAddress, + publishMarketFeeAddress, + publishMarketFeeToken, + publishMarketFeeAmount, + address + ) await dtContract.methods .setPublishingMarketFee( publishMarketFeeAddress, publishMarketFeeToken, publishMarketFeeAmount ) - .call() + .send({ + from: address, + gas: estGas + 1, + gasPrice: await getFairGasPrice(this.web3, this.config) + }) } /** @@ -1410,13 +1457,11 @@ export class Datatoken { }) const publishingMarketFee = await dtContract.methods.getPublishingMarketFee().call() - console.log('publishingMarketFee', publishingMarketFee) const returnValues = { publishMarketFeeAddress: publishingMarketFee[0], publishMarketFeeToken: publishingMarketFee[1], publishMarketFeeAmount: publishingMarketFee[2] } - console.log('returnValues', returnValues) return returnValues } } diff --git a/test/unit/tokens/Datatoken.test.ts b/test/unit/tokens/Datatoken.test.ts index 03bd4f47..48e45f9c 100644 --- a/test/unit/tokens/Datatoken.test.ts +++ b/test/unit/tokens/Datatoken.test.ts @@ -556,23 +556,28 @@ describe('Datatoken', () => { it('#setPublishingMarketFee - User should not be able to set the Publishing Market Fee', async () => { const originalPublishingMarketFee = await datatoken.getPublishingMarketFee( datatokenAddress, - user3 + user1 ) try { await datatoken.setPublishingMarketFee( datatokenAddress, - user3, + user1, contracts.daiAddress, web3.utils.toWei('10'), - user3 + user1 ) } catch (e) { - assert(e.message === 'ERC20Template: not publishMarketFeeAddress') + console.log('Message:', e.message) + assert( + e.message === + 'Returned error: VM Exception while processing transaction: revert ERC20Template: not publishMarketFeeAddress' + ) } const newPublishingMarketFee = await datatoken.getPublishingMarketFee( datatokenAddress, user3 ) + assert( newPublishingMarketFee.publishMarketFeeAddress === originalPublishingMarketFee.publishMarketFeeAddress @@ -587,12 +592,10 @@ describe('Datatoken', () => { ) }) it('#setPublishingMarketFee - Marketplace fee address should be able to set the Publishing Market Fee', async () => { - console.log('users: ', user1, user2, user3, nftOwner, erc20DeployerUser) const originalPublishingMarketFee = await datatoken.getPublishingMarketFee( datatokenAddress, user2 ) - console.log('originalPublishingMarketFee', originalPublishingMarketFee) try { await datatoken.setPublishingMarketFee( datatokenAddress, @@ -602,18 +605,13 @@ describe('Datatoken', () => { user2 ) } catch (e) { - console.log('Error', e) + console.log('Error:', e) } const newPublishingMarketFee = await datatoken.getPublishingMarketFee( datatokenAddress, user2 ) - console.log('newPublishingMarketFee', newPublishingMarketFee) - console.log(newPublishingMarketFee.publishMarketFeeAddress, nftOwner) - console.log(newPublishingMarketFee.publishMarketFeeToken, contracts.daiAddress) - console.log(newPublishingMarketFee.publishMarketFeeAmount, web3.utils.toWei('10')) - assert(newPublishingMarketFee !== originalPublishingMarketFee) assert(newPublishingMarketFee.publishMarketFeeAddress === user2) assert(newPublishingMarketFee.publishMarketFeeAmount === web3.utils.toWei('10')) From 26e1cba7cb57a22e44990084503dcb7b6f61e822 Mon Sep 17 00:00:00 2001 From: "Miquel A. Cabot" Date: Thu, 28 Apr 2022 16:50:00 +0200 Subject: [PATCH 29/47] simplify constants --- test/unit/factories/NftFactory.test.ts | 71 +++++++++++--------------- 1 file changed, 31 insertions(+), 40 deletions(-) diff --git a/test/unit/factories/NftFactory.test.ts b/test/unit/factories/NftFactory.test.ts index b746e791..61a01bae 100644 --- a/test/unit/factories/NftFactory.test.ts +++ b/test/unit/factories/NftFactory.test.ts @@ -30,37 +30,28 @@ describe('Nft Factory test', () => { let dtAddress2: string let nftAddress: string - const VESTING_AMOUNT = '10000' - const CAP_AMOUNT = '1000000' 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_ZERO = '0' - const NFT_DATA: NftCreateData = { - name: NFT_NAME, - symbol: NFT_SYMBOL, + const nftData: NftCreateData = { + name: '72120Bundle', + symbol: '72Bundle', templateIndex: 1, - tokenURI: NFT_TOKEN_URI, + tokenURI: 'https://oceanprotocol.com/nft/', transferable: true, owner: factoryOwner } - const ERC_PARAMS: Erc20CreateParams = { + const ercParams: Erc20CreateParams = { templateIndex: 1, minter: nftOwner, paymentCollector: user2, mpFeeAddress: user1, feeToken: ZERO_ADDRESS, - cap: CAP_AMOUNT, - feeAmount: FEE_ZERO, - name: ERC20_NAME, - symbol: ERC20_SYMBOL + cap: '1000000', + feeAmount: '0', + name: 'ERC20B1', + symbol: 'ERC20DT1Symbol' } before(async () => { @@ -70,10 +61,10 @@ describe('Nft Factory test', () => { user1 = accounts[2] user2 = accounts[3] - NFT_DATA.owner = factoryOwner - ERC_PARAMS.minter = nftOwner - ERC_PARAMS.paymentCollector = user2 - ERC_PARAMS.mpFeeAddress = user1 + nftData.owner = factoryOwner + ercParams.minter = nftOwner + ercParams.paymentCollector = user2 + ercParams.mpFeeAddress = user1 }) it('should deploy contracts', async () => { @@ -103,17 +94,17 @@ describe('Nft Factory test', () => { it('#createNft - should create an NFT', async () => { // 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 const nftDatatoken = new Nft(web3) 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 () => { // 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 expect(txReceipt.events.NFTCreated.event === 'NFTCreated') @@ -128,7 +119,7 @@ describe('Nft Factory test', () => { const currentNFTCount = await nftFactory.getCurrentNFTCount() 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.getCurrentTokenCount()) === currentTokenCount + 1) @@ -143,33 +134,33 @@ describe('Nft Factory test', () => { publisherAddress: nftOwner, marketFeeCollector: nftOwner, poolTemplateAddress: contracts.poolTemplateAddress, - rate: RATE, + rate: '1', baseTokenDecimals: 18, - vestingAmount: VESTING_AMOUNT, + vestingAmount: '10000', vestedBlocks: 2500000, initialBaseTokenLiquidity: '2000', swapFeeLiquidityProvider: FEE, swapFeeMarketRunner: FEE } - // approve VESTING_AMOUNT DAI to nftFactory + // approve poolParams.vestingAmount DAI to nftFactory const daiContract = new web3.eth.Contract( MockERC20.abi as AbiItem[], contracts.daiAddress ) await daiContract.methods - .transfer(nftOwner, web3.utils.toWei(VESTING_AMOUNT)) + .transfer(nftOwner, web3.utils.toWei(poolParams.vestingAmount)) .send({ from: factoryOwner }) await daiContract.methods - .approve(contracts.erc721FactoryAddress, web3.utils.toWei(VESTING_AMOUNT)) + .approve(contracts.erc721FactoryAddress, web3.utils.toWei(poolParams.vestingAmount)) .send({ from: nftOwner }) const txReceipt = await nftFactory.createNftErc20WithPool( nftOwner, - NFT_DATA, - ERC_PARAMS, + nftData, + ercParams, poolParams ) @@ -188,7 +179,7 @@ describe('Nft Factory test', () => { marketFeeCollector: nftOwner, baseTokenDecimals: 18, datatokenDecimals: 18, - fixedRate: RATE, + fixedRate: '1', marketFee: FEE, allowedConsumer: user1, withMint: false @@ -196,8 +187,8 @@ describe('Nft Factory test', () => { const txReceipt = await nftFactory.createNftErc20WithFixedRate( nftOwner, - NFT_DATA, - ERC_PARAMS, + nftData, + ercParams, freParams ) @@ -222,8 +213,8 @@ describe('Nft Factory test', () => { const txReceipt = await nftFactory.createNftErc20WithDispenser( nftOwner, - NFT_DATA, - ERC_PARAMS, + nftData, + ercParams, dispenserParams ) @@ -240,7 +231,7 @@ describe('Nft Factory test', () => { const consumer = user1 // could be different user const serviceIndex = 1 // dummy index 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 // we reuse a DT created in a previous test @@ -295,7 +286,7 @@ describe('Nft Factory test', () => { const consumeMarketFee = { consumeMarketFeeAddress: ZERO_ADDRESS, consumeMarketFeeToken: ZERO_ADDRESS, - consumeMarketFeeAmount: FEE_ZERO + consumeMarketFeeAmount: '0' } const orders: TokenOrder[] = [ { From c97f7503133986c4a6165c4ddcb7f54e5afdc2fe Mon Sep 17 00:00:00 2001 From: "Miquel A. Cabot" Date: Thu, 5 May 2022 13:39:41 +0200 Subject: [PATCH 30/47] refactor SimplePublishConsumeFlow.test.ts file --- .../SimplePublishConsumeFlow.test.ts | 135 ++++++++++-------- 1 file changed, 74 insertions(+), 61 deletions(-) diff --git a/test/integration/SimplePublishConsumeFlow.test.ts b/test/integration/SimplePublishConsumeFlow.test.ts index 99b4e87f..1e5b324c 100644 --- a/test/integration/SimplePublishConsumeFlow.test.ts +++ b/test/integration/SimplePublishConsumeFlow.test.ts @@ -1,6 +1,6 @@ import { assert } from 'chai' import { SHA256 } from 'crypto-js' -import { web3, getTestConfig, getAddresses } from '../config' +import { web3, getTestConfig } from '../config' import { Config, ProviderInstance, @@ -10,92 +10,98 @@ import { Datatoken, getHash, Nft, - downloadFile + downloadFile, + ZERO_ADDRESS } from '../../src' import { ProviderFees, Erc20CreateParams } from '../../src/@types' - -const assetUrl = [ - { - type: 'url', - url: 'https://raw.githubusercontent.com/oceanprotocol/testdatasets/main/shs_dataset_test.txt', - method: 'GET' - } -] -const ddo = { - '@context': ['https://w3id.org/did/v1'], - id: 'did:op:efba17455c127a885ec7830d687a8f6e64f5ba559f8506f8723c1f10f05c049c', - version: '4.0.0', - chainId: 4, - nftAddress: '0x0', - metadata: { - created: '2021-12-20T14:35:20Z', - updated: '2021-12-20T14:35:20Z', - type: 'dataset', - name: 'dfgdfgdg', - description: 'd dfgd fgd dfg dfgdfgd dfgdf', - tags: [''], - author: 'dd', - license: 'https://market.oceanprotocol.com/terms', - additionalInformation: { - termsAndConditions: true - } - }, - services: [ - { - id: 'notAnId', - type: 'access', - files: '', - datatokenAddress: '0xa15024b732A8f2146423D14209eFd074e61964F3', - serviceEndpoint: 'https://providerv4.rinkeby.oceanprotocol.com', - timeout: 0 - } - ] -} +import { Addresses, deployContracts } from '../TestContractHandler' describe('Simple Publish & consume test', async () => { let config: Config - let addresses: any + let contracts: Addresses let aquarius: Aquarius let providerUrl: any + let publisherAccount: string + let consumerAccount: string + + const assetUrl = [ + { + type: 'url', + url: 'https://raw.githubusercontent.com/oceanprotocol/testdatasets/main/shs_dataset_test.txt', + method: 'GET' + } + ] + + const ddo = { + '@context': ['https://w3id.org/did/v1'], + id: '', + version: '4.0.0', + chainId: 4, + nftAddress: '0x0', + metadata: { + created: '2021-12-20T14:35:20Z', + updated: '2021-12-20T14:35:20Z', + type: 'dataset', + name: 'dataset-name', + description: 'Ocean protocol test dataset description', + author: 'oceanprotocol-team', + license: 'MIT' + }, + services: [ + { + id: 'testFakeId', + type: 'access', + files: '', + datatokenAddress: '0x0', + serviceEndpoint: 'https://providerv4.rinkeby.oceanprotocol.com', + timeout: 0 + } + ] + } before(async () => { config = await getTestConfig(web3) - addresses = getAddresses() aquarius = new Aquarius(config.metadataCacheUri) providerUrl = config.providerUri }) + it('Initialize accounts', async () => { + const accounts = await web3.eth.getAccounts() + publisherAccount = accounts[0] + consumerAccount = accounts[1] + }) + + it('Deploy contracts', async () => { + contracts = await deployContracts(web3, publisherAccount) + }) + it('should publish a dataset (create NFT + ERC20)', async () => { const nft = new Nft(web3) const datatoken = new Datatoken(web3) - const Factory = new NftFactory(addresses.ERC721Factory, web3) - const accounts = await web3.eth.getAccounts() - const publisherAccount = accounts[0] - const consumerAccount = accounts[1] + const Factory = new NftFactory(contracts.erc721FactoryAddress, web3) + const nftParams: NftCreateData = { - name: 'testNFT', - symbol: 'TST', + name: '72120Bundle', + symbol: '72Bundle', templateIndex: 1, - tokenURI: '', + tokenURI: 'https://oceanprotocol.com/nft/', transferable: true, owner: publisherAccount } + const erc20Params: Erc20CreateParams = { templateIndex: 1, cap: '100000', feeAmount: '0', - paymentCollector: '0x0000000000000000000000000000000000000000', - feeToken: '0x0000000000000000000000000000000000000000', + paymentCollector: ZERO_ADDRESS, + feeToken: ZERO_ADDRESS, minter: publisherAccount, - mpFeeAddress: '0x0000000000000000000000000000000000000000' + mpFeeAddress: ZERO_ADDRESS } - const result = await Factory.createNftWithErc20( - publisherAccount, - nftParams, - erc20Params - ) - const erc721Address = result.events.NFTCreated.returnValues[0] - const datatokenAddress = result.events.TokenCreated.returnValues[0] + + const tx = await Factory.createNftWithErc20(publisherAccount, nftParams, erc20Params) + const erc721Address = tx.events.NFTCreated.returnValues[0] + const datatokenAddress = tx.events.TokenCreated.returnValues[0] // create the files encrypted string let providerResponse = await ProviderInstance.encrypt(assetUrl, providerUrl) @@ -110,7 +116,7 @@ describe('Simple Publish & consume test', async () => { providerResponse = await ProviderInstance.encrypt(ddo, providerUrl) const encryptedResponse = await providerResponse const metadataHash = getHash(JSON.stringify(ddo)) - const res = await nft.setMetadata( + await nft.setMetadata( erc721Address, publisherAccount, 0, @@ -120,10 +126,13 @@ describe('Simple Publish & consume test', async () => { encryptedResponse, '0x' + metadataHash ) + const resolvedDDO = await aquarius.waitForAqua(ddo.id) assert(resolvedDDO, 'Cannot fetch DDO from Aquarius') + // mint 1 ERC20 and send it to the consumer await datatoken.mint(datatokenAddress, publisherAccount, '1', consumerAccount) + // initialize provider const initializeData = await ProviderInstance.initialize( resolvedDDO.id, @@ -132,6 +141,7 @@ describe('Simple Publish & consume test', async () => { consumerAccount, providerUrl ) + const providerFees: ProviderFees = { providerFeeAddress: initializeData.providerFee.providerFeeAddress, providerFeeToken: initializeData.providerFee.providerFeeToken, @@ -142,6 +152,7 @@ describe('Simple Publish & consume test', async () => { providerData: initializeData.providerFee.providerData, validUntil: initializeData.providerFee.validUntil } + // make the payment const txid = await datatoken.startOrder( datatokenAddress, @@ -150,6 +161,7 @@ describe('Simple Publish & consume test', async () => { 0, providerFees ) + // get the url const downloadURL = await ProviderInstance.getDownloadUrl( ddo.id, @@ -160,9 +172,10 @@ describe('Simple Publish & consume test', async () => { providerUrl, web3 ) + assert(downloadURL, 'Provider getDownloadUrl failed') try { - const fileData = await downloadFile(downloadURL) + await downloadFile(downloadURL) } catch (e) { assert.fail('Download failed') } From a75ca34e9e5245cfdbb670f1c23c91d96c57ec30 Mon Sep 17 00:00:00 2001 From: "Miquel A. Cabot" Date: Fri, 6 May 2022 10:43:44 +0200 Subject: [PATCH 31/47] don't deploy smart contracts --- test/integration/SimplePublishConsumeFlow.test.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/test/integration/SimplePublishConsumeFlow.test.ts b/test/integration/SimplePublishConsumeFlow.test.ts index 1e5b324c..9f4feedc 100644 --- a/test/integration/SimplePublishConsumeFlow.test.ts +++ b/test/integration/SimplePublishConsumeFlow.test.ts @@ -1,6 +1,6 @@ import { assert } from 'chai' import { SHA256 } from 'crypto-js' -import { web3, getTestConfig } from '../config' +import { web3, getTestConfig, getAddresses } from '../config' import { Config, ProviderInstance, @@ -14,11 +14,10 @@ import { ZERO_ADDRESS } from '../../src' import { ProviderFees, Erc20CreateParams } from '../../src/@types' -import { Addresses, deployContracts } from '../TestContractHandler' describe('Simple Publish & consume test', async () => { let config: Config - let contracts: Addresses + let addresses: any let aquarius: Aquarius let providerUrl: any let publisherAccount: string @@ -63,6 +62,8 @@ describe('Simple Publish & consume test', async () => { config = await getTestConfig(web3) aquarius = new Aquarius(config.metadataCacheUri) providerUrl = config.providerUri + + addresses = getAddresses() }) it('Initialize accounts', async () => { @@ -71,14 +72,10 @@ describe('Simple Publish & consume test', async () => { consumerAccount = accounts[1] }) - it('Deploy contracts', async () => { - contracts = await deployContracts(web3, publisherAccount) - }) - it('should publish a dataset (create NFT + ERC20)', async () => { const nft = new Nft(web3) const datatoken = new Datatoken(web3) - const Factory = new NftFactory(contracts.erc721FactoryAddress, web3) + const Factory = new NftFactory(addresses.ERC721Factory, web3) const nftParams: NftCreateData = { name: '72120Bundle', From 11508b7794048dc5f81fc4aba4c3a5b551c9e18c Mon Sep 17 00:00:00 2001 From: "Miquel A. Cabot" Date: Fri, 6 May 2022 11:14:39 +0200 Subject: [PATCH 32/47] add DDO type --- test/integration/SimplePublishConsumeFlow.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integration/SimplePublishConsumeFlow.test.ts b/test/integration/SimplePublishConsumeFlow.test.ts index 9f4feedc..1036ed69 100644 --- a/test/integration/SimplePublishConsumeFlow.test.ts +++ b/test/integration/SimplePublishConsumeFlow.test.ts @@ -13,7 +13,7 @@ import { downloadFile, ZERO_ADDRESS } from '../../src' -import { ProviderFees, Erc20CreateParams } from '../../src/@types' +import { ProviderFees, Erc20CreateParams, DDO } from '../../src/@types' describe('Simple Publish & consume test', async () => { let config: Config @@ -31,7 +31,7 @@ describe('Simple Publish & consume test', async () => { } ] - const ddo = { + const ddo: DDO = { '@context': ['https://w3id.org/did/v1'], id: '', version: '4.0.0', From caf83190b69a8582478312a8c3fc5e54135f7f49 Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Thu, 12 May 2022 14:51:52 +0300 Subject: [PATCH 33/47] Fixing fixedRateContract undefined --- src/pools/fixedRate/FixedRateExchange.ts | 136 +++++++++++++---------- 1 file changed, 77 insertions(+), 59 deletions(-) diff --git a/src/pools/fixedRate/FixedRateExchange.ts b/src/pools/fixedRate/FixedRateExchange.ts index e1bdcf56..c2847d2f 100644 --- a/src/pools/fixedRate/FixedRateExchange.ts +++ b/src/pools/fixedRate/FixedRateExchange.ts @@ -60,9 +60,8 @@ export class FixedRateExchange { public oceanAddress: string = null public fixedRateAddress: string public fixedRateExchangeAbi: AbiItem | AbiItem[] - public fixedRateContract: Contract public web3: Web3 - public contract: Contract = null + public fixedRateContract: Contract = null public config: Config public ssAbi: AbiItem | AbiItem[] @@ -86,7 +85,7 @@ export class FixedRateExchange { fixedRateExchangeAbi || (defaultFixedRateExchangeAbi.abi as AbiItem[]) this.oceanAddress = oceanAddress this.fixedRateAddress = fixedRateAddress - this.contract = setContractDefaults( + this.fixedRateContract = setContractDefaults( new this.web3.eth.Contract(this.fixedRateExchangeAbi, this.fixedRateAddress), this.config ) @@ -115,7 +114,7 @@ export class FixedRateExchange { * @return {Promise} exchangeId */ public async generateExchangeId(baseToken: string, datatoken: string): Promise { - const exchangeId = await this.contract.methods + const exchangeId = await this.fixedRateContract.methods .generateExchangeId(baseToken, datatoken) .call() return exchangeId @@ -199,7 +198,7 @@ export class FixedRateExchange { consumeMarketFeeFormatted ) try { - const trxReceipt = await this.contract.methods + const trxReceipt = await this.fixedRateContract.methods .buyDT( exchangeId, dtAmountFormatted, @@ -296,7 +295,7 @@ export class FixedRateExchange { consumeMarketFeeFormatted ) try { - const trxReceipt = await this.contract.methods + const trxReceipt = await this.fixedRateContract.methods .sellDT( exchangeId, dtAmountFormatted, @@ -323,7 +322,9 @@ export class FixedRateExchange { * @return {Promise} no of available exchanges */ public async getNumberOfExchanges(): Promise { - const numExchanges = await this.contract.methods.getNumberOfExchanges().call() + const numExchanges = await this.fixedRateContract.methods + .getNumberOfExchanges() + .call() return numExchanges } @@ -342,13 +343,16 @@ export class FixedRateExchange { contractInstance?: Contract ): Promise { const fixedRate = contractInstance || this.fixedRateContract + console.log('### fixedRate', fixedRate) const gasLimitDefault = this.GASLIMIT_DEFAULT let estGas try { estGas = await fixedRate.methods .setRate(exchangeId, await this.web3.utils.toWei(newRate)) .estimateGas({ from: account }, (err, estGas) => (err ? gasLimitDefault : estGas)) + console.log('estGas', estGas) } catch (e) { + console.log('### ERROR: ', e) estGas = gasLimitDefault } return estGas @@ -367,7 +371,7 @@ export class FixedRateExchange { newRate: string ): Promise { const estGas = await this.estSetRate(address, exchangeId, newRate) - const trxReceipt = await this.contract.methods + const trxReceipt = await this.fixedRateContract.methods .setRate(exchangeId, this.web3.utils.toWei(newRate)) .send({ from: address, @@ -417,7 +421,7 @@ export class FixedRateExchange { newAllowedSwapper: string ): Promise { const estGas = await this.estSetAllowedSwapper(address, exchangeId, newAllowedSwapper) - const trxReceipt = await this.contract.methods + const trxReceipt = await this.fixedRateContract.methods .setAllowedSwapper(exchangeId, newAllowedSwapper) .send({ from: address, @@ -467,11 +471,13 @@ export class FixedRateExchange { if (exchange.active === true) return null const estGas = await this.estActivate(address, exchangeId) - const trxReceipt = await this.contract.methods.toggleExchangeState(exchangeId).send({ - from: address, - gas: estGas + 1, - gasPrice: await getFairGasPrice(this.web3, this.config) - }) + const trxReceipt = await this.fixedRateContract.methods + .toggleExchangeState(exchangeId) + .send({ + from: address, + gas: estGas + 1, + gasPrice: await getFairGasPrice(this.web3, this.config) + }) return trxReceipt } @@ -516,11 +522,13 @@ export class FixedRateExchange { const estGas = await this.estDeactivate(address, exchangeId) - const trxReceipt = await this.contract.methods.toggleExchangeState(exchangeId).send({ - from: address, - gas: estGas + 1, - gasPrice: await getFairGasPrice(this.web3, this.config) - }) + const trxReceipt = await this.fixedRateContract.methods + .toggleExchangeState(exchangeId) + .send({ + from: address, + gas: estGas + 1, + gasPrice: await getFairGasPrice(this.web3, this.config) + }) return trxReceipt } @@ -531,7 +539,7 @@ export class FixedRateExchange { * @return {Promise} Rate (converted from wei) */ public async getRate(exchangeId: string): Promise { - const weiRate = await this.contract.methods.getRate(exchangeId).call() + const weiRate = await this.fixedRateContract.methods.getRate(exchangeId).call() const rate = await this.web3.utils.fromWei(weiRate) return rate } @@ -542,7 +550,7 @@ export class FixedRateExchange { * @return {Promise} dt supply formatted */ public async getDTSupply(exchangeId: string): Promise { - const dtSupply = await this.contract.methods.getDTSupply(exchangeId).call() + const dtSupply = await this.fixedRateContract.methods.getDTSupply(exchangeId).call() const exchange = await this.getExchange(exchangeId) return await this.unitsToAmount(exchange.datatoken, dtSupply, +exchange.dtDecimals) } @@ -553,7 +561,7 @@ export class FixedRateExchange { * @return {Promise} dt supply formatted */ public async getBTSupply(exchangeId: string): Promise { - const btSupply = await this.contract.methods.getBTSupply(exchangeId).call() + const btSupply = await this.fixedRateContract.methods.getBTSupply(exchangeId).call() const exchange = await this.getExchange(exchangeId) return await this.unitsToAmount(exchange.baseToken, btSupply, +exchange.btDecimals) } @@ -564,7 +572,7 @@ export class FixedRateExchange { * @return {Promise} address of allowedSwapper */ public async getAllowedSwapper(exchangeId: string): Promise { - return await this.contract.methods.getAllowedSwapper(exchangeId).call() + return await this.fixedRateContract.methods.getAllowedSwapper(exchangeId).call() } /** @@ -580,7 +588,7 @@ export class FixedRateExchange { consumeMarketFee: string = '0' ): Promise { const fixedRateExchange = await this.getExchange(exchangeId) - const result = await this.contract.methods + const result = await this.fixedRateContract.methods .calcBaseInGivenOutDT( exchangeId, await this.amountToUnits( @@ -630,7 +638,7 @@ export class FixedRateExchange { consumeMarketFee: string = '0' ): Promise { const exchange = await this.getExchange(exchangeId) - const result = await this.contract.methods + const result = await this.fixedRateContract.methods .calcBaseOutGivenInDT( exchangeId, await this.amountToUnits( @@ -651,7 +659,7 @@ export class FixedRateExchange { * @return {Promise} Exchange details */ public async getExchange(exchangeId: string): Promise { - const result: FixedPriceExchange = await this.contract.methods + const result: FixedPriceExchange = await this.fixedRateContract.methods .getExchange(exchangeId) .call() result.dtDecimals = result.dtDecimals.toString() @@ -687,7 +695,9 @@ export class FixedRateExchange { * @return {Promise} Exchange details */ public async getFeesInfo(exchangeId: string): Promise { - const result: FeesInfo = await this.contract.methods.getFeesInfo(exchangeId).call() + const result: FeesInfo = await this.fixedRateContract.methods + .getFeesInfo(exchangeId) + .call() result.opcFee = this.web3.utils.fromWei(result.opcFee.toString()) result.marketFee = this.web3.utils.fromWei(result.marketFee.toString()) @@ -713,7 +723,7 @@ export class FixedRateExchange { * @return {Promise} Exchanges list */ public async getExchanges(): Promise { - return await this.contract.methods.getExchanges().call() + return await this.fixedRateContract.methods.getExchanges().call() } /** @@ -722,7 +732,7 @@ export class FixedRateExchange { * @return {Promise} Result */ public async isActive(exchangeId: string): Promise { - const result = await this.contract.methods.isActive(exchangeId).call() + const result = await this.fixedRateContract.methods.isActive(exchangeId).call() return result } @@ -766,7 +776,7 @@ export class FixedRateExchange { if (exchange.withMint === true) return null const estGas = await this.estActivateMint(address, exchangeId) - const trxReceipt = await this.contract.methods + const trxReceipt = await this.fixedRateContract.methods .toggleMintState(exchangeId, true) .send({ from: address, @@ -817,7 +827,7 @@ export class FixedRateExchange { const estGas = await this.estDeactivate(address, exchangeId) - const trxReceipt = await this.contract.methods + const trxReceipt = await this.fixedRateContract.methods .toggleMintState(exchangeId, false) .send({ from: address, @@ -845,7 +855,7 @@ export class FixedRateExchange { const fixedRate = contractInstance || this.fixedRateContract const gasLimitDefault = this.GASLIMIT_DEFAULT let estGas - const fixedrate: FixedPriceExchange = await this.contract.methods + const fixedrate: FixedPriceExchange = await this.fixedRateContract.methods .getExchange(exchangeId) .call() const amountWei = await this.amountToUnits( @@ -879,7 +889,7 @@ export class FixedRateExchange { if (!exchange) return null const estGas = await this.estCollectBT(address, exchangeId, amount) - const fixedrate: FixedPriceExchange = await this.contract.methods + const fixedrate: FixedPriceExchange = await this.fixedRateContract.methods .getExchange(exchangeId) .call() const amountWei = await this.amountToUnits( @@ -887,11 +897,13 @@ export class FixedRateExchange { amount, +fixedrate.btDecimals ) - const trxReceipt = await this.contract.methods.collectBT(exchangeId, amountWei).send({ - from: address, - gas: estGas + 1, - gasPrice: await getFairGasPrice(this.web3, this.config) - }) + const trxReceipt = await this.fixedRateContract.methods + .collectBT(exchangeId, amountWei) + .send({ + from: address, + gas: estGas + 1, + gasPrice: await getFairGasPrice(this.web3, this.config) + }) return trxReceipt } @@ -912,7 +924,7 @@ export class FixedRateExchange { const fixedRate = contractInstance || this.fixedRateContract const gasLimitDefault = this.GASLIMIT_DEFAULT let estGas - const fixedrate: FixedPriceExchange = await this.contract.methods + const fixedrate: FixedPriceExchange = await this.fixedRateContract.methods .getExchange(exchangeId) .call() const amountWei = await this.amountToUnits( @@ -946,7 +958,7 @@ export class FixedRateExchange { if (!exchange) return null const estGas = await this.estCollectDT(address, exchangeId, amount) - const fixedrate: FixedPriceExchange = await this.contract.methods + const fixedrate: FixedPriceExchange = await this.fixedRateContract.methods .getExchange(exchangeId) .call() const amountWei = await this.amountToUnits( @@ -954,11 +966,13 @@ export class FixedRateExchange { amount, +fixedrate.dtDecimals ) - const trxReceipt = await this.contract.methods.collectDT(exchangeId, amountWei).send({ - from: address, - gas: estGas + 1, - gasPrice: await getFairGasPrice(this.web3, this.config) - }) + const trxReceipt = await this.fixedRateContract.methods + .collectDT(exchangeId, amountWei) + .send({ + from: address, + gas: estGas + 1, + gasPrice: await getFairGasPrice(this.web3, this.config) + }) return trxReceipt } @@ -1001,11 +1015,13 @@ export class FixedRateExchange { if (!exchange) return null const estGas = await this.estCollectMarketFee(address, exchangeId) - const trxReceipt = await this.contract.methods.collectMarketFee(exchangeId).send({ - from: address, - gas: estGas + 1, - gasPrice: await getFairGasPrice(this.web3, this.config) - }) + const trxReceipt = await this.fixedRateContract.methods + .collectMarketFee(exchangeId) + .send({ + from: address, + gas: estGas + 1, + gasPrice: await getFairGasPrice(this.web3, this.config) + }) return trxReceipt } @@ -1048,11 +1064,13 @@ export class FixedRateExchange { if (!exchange) return null const estGas = await this.estCollectOceanFee(address, exchangeId) - const trxReceipt = await this.contract.methods.collectOceanFee(exchangeId).send({ - from: address, - gas: estGas + 1, - gasPrice: await getFairGasPrice(this.web3, this.config) - }) + const trxReceipt = await this.fixedRateContract.methods + .collectOceanFee(exchangeId) + .send({ + from: address, + gas: estGas + 1, + gasPrice: await getFairGasPrice(this.web3, this.config) + }) return trxReceipt } @@ -1063,7 +1081,7 @@ export class FixedRateExchange { async getOPCCollector(): Promise { let result = null try { - result = await this.contract.methods.opcCollector().call() + result = await this.fixedRateContract.methods.opcCollector().call() } catch (e) { LoggerInstance.error(`ERROR: Failed to get OPC Collector address: ${e.message}`) } @@ -1077,7 +1095,7 @@ export class FixedRateExchange { async getRouter(): Promise { let result = null try { - result = await this.contract.methods.router().call() + result = await this.fixedRateContract.methods.router().call() } catch (e) { LoggerInstance.error(`ERROR: Failed to get Router address: ${e.message}`) } @@ -1143,7 +1161,7 @@ export class FixedRateExchange { exchangeId, this.web3.utils.toWei(newMarketFee) ) - const trxReceipt = await this.contract.methods + const trxReceipt = await this.fixedRateContract.methods .updateMarketFee(exchangeId, this.web3.utils.toWei(newMarketFee)) .send({ from: address, @@ -1197,7 +1215,7 @@ export class FixedRateExchange { exchangeId, newMarketFeeCollector ) - const trxReceipt = await this.contract.methods + const trxReceipt = await this.fixedRateContract.methods .updateMarketFeeCollector(exchangeId, newMarketFeeCollector) .send({ from: address, From b9e89bb335bfac54bef87fe9cabee97b08a23c7c Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Thu, 12 May 2022 17:34:45 +0300 Subject: [PATCH 34/47] Fixing estSetAllowedSwapper --- src/pools/fixedRate/FixedRateExchange.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/pools/fixedRate/FixedRateExchange.ts b/src/pools/fixedRate/FixedRateExchange.ts index c2847d2f..31d06994 100644 --- a/src/pools/fixedRate/FixedRateExchange.ts +++ b/src/pools/fixedRate/FixedRateExchange.ts @@ -197,6 +197,7 @@ export class FixedRateExchange { consumeMarketAddress, consumeMarketFeeFormatted ) + console.log('estGas', estGas) try { const trxReceipt = await this.fixedRateContract.methods .buyDT( @@ -294,6 +295,7 @@ export class FixedRateExchange { consumeMarketAddress, consumeMarketFeeFormatted ) + console.log('estGas', estGas) try { const trxReceipt = await this.fixedRateContract.methods .sellDT( @@ -371,6 +373,7 @@ export class FixedRateExchange { newRate: string ): Promise { const estGas = await this.estSetRate(address, exchangeId, newRate) + console.log('estGas', estGas) const trxReceipt = await this.fixedRateContract.methods .setRate(exchangeId, this.web3.utils.toWei(newRate)) .send({ @@ -400,7 +403,7 @@ export class FixedRateExchange { let estGas try { estGas = await fixedRate.methods - .setRate(exchangeId, newAllowedSwapper) + .setAllowedSwapper(exchangeId, newAllowedSwapper) .estimateGas({ from: account }, (err, estGas) => (err ? gasLimitDefault : estGas)) } catch (e) { estGas = gasLimitDefault @@ -421,6 +424,7 @@ export class FixedRateExchange { newAllowedSwapper: string ): Promise { const estGas = await this.estSetAllowedSwapper(address, exchangeId, newAllowedSwapper) + console.log('estGas', estGas) const trxReceipt = await this.fixedRateContract.methods .setAllowedSwapper(exchangeId, newAllowedSwapper) .send({ @@ -471,6 +475,7 @@ export class FixedRateExchange { if (exchange.active === true) return null const estGas = await this.estActivate(address, exchangeId) + console.log('estGas', estGas) const trxReceipt = await this.fixedRateContract.methods .toggleExchangeState(exchangeId) .send({ @@ -521,6 +526,7 @@ export class FixedRateExchange { if (exchange.active === false) return null const estGas = await this.estDeactivate(address, exchangeId) + console.log('estGas', estGas) const trxReceipt = await this.fixedRateContract.methods .toggleExchangeState(exchangeId) @@ -776,6 +782,7 @@ export class FixedRateExchange { if (exchange.withMint === true) return null const estGas = await this.estActivateMint(address, exchangeId) + console.log('estGas', estGas) const trxReceipt = await this.fixedRateContract.methods .toggleMintState(exchangeId, true) .send({ @@ -805,7 +812,9 @@ export class FixedRateExchange { estGas = await fixedRate.methods .toggleMintState(exchangeId) .estimateGas({ from: account }, (err, estGas) => (err ? gasLimitDefault : estGas)) + console.log('### estGas', estGas) } catch (e) { + console.log('e', e) estGas = gasLimitDefault } return estGas @@ -826,6 +835,7 @@ export class FixedRateExchange { if (exchange.withMint === false) return null const estGas = await this.estDeactivate(address, exchangeId) + console.log('estGas', estGas) const trxReceipt = await this.fixedRateContract.methods .toggleMintState(exchangeId, false) @@ -889,6 +899,7 @@ export class FixedRateExchange { if (!exchange) return null const estGas = await this.estCollectBT(address, exchangeId, amount) + console.log('estGas', estGas) const fixedrate: FixedPriceExchange = await this.fixedRateContract.methods .getExchange(exchangeId) .call() @@ -958,6 +969,7 @@ export class FixedRateExchange { if (!exchange) return null const estGas = await this.estCollectDT(address, exchangeId, amount) + console.log('estGas', estGas) const fixedrate: FixedPriceExchange = await this.fixedRateContract.methods .getExchange(exchangeId) .call() @@ -1015,6 +1027,7 @@ export class FixedRateExchange { if (!exchange) return null const estGas = await this.estCollectMarketFee(address, exchangeId) + console.log('estGas', estGas) const trxReceipt = await this.fixedRateContract.methods .collectMarketFee(exchangeId) .send({ @@ -1064,6 +1077,7 @@ export class FixedRateExchange { if (!exchange) return null const estGas = await this.estCollectOceanFee(address, exchangeId) + console.log('estGas', estGas) const trxReceipt = await this.fixedRateContract.methods .collectOceanFee(exchangeId) .send({ @@ -1161,6 +1175,7 @@ export class FixedRateExchange { exchangeId, this.web3.utils.toWei(newMarketFee) ) + console.log('estGas', estGas) const trxReceipt = await this.fixedRateContract.methods .updateMarketFee(exchangeId, this.web3.utils.toWei(newMarketFee)) .send({ @@ -1215,6 +1230,7 @@ export class FixedRateExchange { exchangeId, newMarketFeeCollector ) + console.log('estGas', estGas) const trxReceipt = await this.fixedRateContract.methods .updateMarketFeeCollector(exchangeId, newMarketFeeCollector) .send({ From 1de19f8e2b2c39aa0ef9fb003fdfa32d4265e88b Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Thu, 12 May 2022 17:39:08 +0300 Subject: [PATCH 35/47] Fixing deactivateMint estimate gas cost --- src/pools/fixedRate/FixedRateExchange.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pools/fixedRate/FixedRateExchange.ts b/src/pools/fixedRate/FixedRateExchange.ts index 31d06994..d9774b36 100644 --- a/src/pools/fixedRate/FixedRateExchange.ts +++ b/src/pools/fixedRate/FixedRateExchange.ts @@ -810,7 +810,7 @@ export class FixedRateExchange { let estGas try { estGas = await fixedRate.methods - .toggleMintState(exchangeId) + .toggleMintState(exchangeId, false) .estimateGas({ from: account }, (err, estGas) => (err ? gasLimitDefault : estGas)) console.log('### estGas', estGas) } catch (e) { @@ -834,7 +834,7 @@ export class FixedRateExchange { if (!exchange) return null if (exchange.withMint === false) return null - const estGas = await this.estDeactivate(address, exchangeId) + const estGas = await this.estDeactivateMint(address, exchangeId) console.log('estGas', estGas) const trxReceipt = await this.fixedRateContract.methods From c9b297a85833b965e14cf534118dce10f9263a0d Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Thu, 12 May 2022 18:10:02 +0300 Subject: [PATCH 36/47] Removing console.logs --- src/pools/fixedRate/FixedRateExchange.ts | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/src/pools/fixedRate/FixedRateExchange.ts b/src/pools/fixedRate/FixedRateExchange.ts index d9774b36..22dfff87 100644 --- a/src/pools/fixedRate/FixedRateExchange.ts +++ b/src/pools/fixedRate/FixedRateExchange.ts @@ -197,7 +197,6 @@ export class FixedRateExchange { consumeMarketAddress, consumeMarketFeeFormatted ) - console.log('estGas', estGas) try { const trxReceipt = await this.fixedRateContract.methods .buyDT( @@ -295,7 +294,6 @@ export class FixedRateExchange { consumeMarketAddress, consumeMarketFeeFormatted ) - console.log('estGas', estGas) try { const trxReceipt = await this.fixedRateContract.methods .sellDT( @@ -345,16 +343,13 @@ export class FixedRateExchange { contractInstance?: Contract ): Promise { const fixedRate = contractInstance || this.fixedRateContract - console.log('### fixedRate', fixedRate) const gasLimitDefault = this.GASLIMIT_DEFAULT let estGas try { estGas = await fixedRate.methods .setRate(exchangeId, await this.web3.utils.toWei(newRate)) .estimateGas({ from: account }, (err, estGas) => (err ? gasLimitDefault : estGas)) - console.log('estGas', estGas) } catch (e) { - console.log('### ERROR: ', e) estGas = gasLimitDefault } return estGas @@ -373,7 +368,6 @@ export class FixedRateExchange { newRate: string ): Promise { const estGas = await this.estSetRate(address, exchangeId, newRate) - console.log('estGas', estGas) const trxReceipt = await this.fixedRateContract.methods .setRate(exchangeId, this.web3.utils.toWei(newRate)) .send({ @@ -424,7 +418,6 @@ export class FixedRateExchange { newAllowedSwapper: string ): Promise { const estGas = await this.estSetAllowedSwapper(address, exchangeId, newAllowedSwapper) - console.log('estGas', estGas) const trxReceipt = await this.fixedRateContract.methods .setAllowedSwapper(exchangeId, newAllowedSwapper) .send({ @@ -475,7 +468,6 @@ export class FixedRateExchange { if (exchange.active === true) return null const estGas = await this.estActivate(address, exchangeId) - console.log('estGas', estGas) const trxReceipt = await this.fixedRateContract.methods .toggleExchangeState(exchangeId) .send({ @@ -526,7 +518,6 @@ export class FixedRateExchange { if (exchange.active === false) return null const estGas = await this.estDeactivate(address, exchangeId) - console.log('estGas', estGas) const trxReceipt = await this.fixedRateContract.methods .toggleExchangeState(exchangeId) @@ -782,7 +773,6 @@ export class FixedRateExchange { if (exchange.withMint === true) return null const estGas = await this.estActivateMint(address, exchangeId) - console.log('estGas', estGas) const trxReceipt = await this.fixedRateContract.methods .toggleMintState(exchangeId, true) .send({ @@ -812,9 +802,7 @@ export class FixedRateExchange { estGas = await fixedRate.methods .toggleMintState(exchangeId, false) .estimateGas({ from: account }, (err, estGas) => (err ? gasLimitDefault : estGas)) - console.log('### estGas', estGas) } catch (e) { - console.log('e', e) estGas = gasLimitDefault } return estGas @@ -835,7 +823,6 @@ export class FixedRateExchange { if (exchange.withMint === false) return null const estGas = await this.estDeactivateMint(address, exchangeId) - console.log('estGas', estGas) const trxReceipt = await this.fixedRateContract.methods .toggleMintState(exchangeId, false) @@ -899,7 +886,6 @@ export class FixedRateExchange { if (!exchange) return null const estGas = await this.estCollectBT(address, exchangeId, amount) - console.log('estGas', estGas) const fixedrate: FixedPriceExchange = await this.fixedRateContract.methods .getExchange(exchangeId) .call() @@ -969,7 +955,6 @@ export class FixedRateExchange { if (!exchange) return null const estGas = await this.estCollectDT(address, exchangeId, amount) - console.log('estGas', estGas) const fixedrate: FixedPriceExchange = await this.fixedRateContract.methods .getExchange(exchangeId) .call() @@ -1027,7 +1012,6 @@ export class FixedRateExchange { if (!exchange) return null const estGas = await this.estCollectMarketFee(address, exchangeId) - console.log('estGas', estGas) const trxReceipt = await this.fixedRateContract.methods .collectMarketFee(exchangeId) .send({ @@ -1077,7 +1061,6 @@ export class FixedRateExchange { if (!exchange) return null const estGas = await this.estCollectOceanFee(address, exchangeId) - console.log('estGas', estGas) const trxReceipt = await this.fixedRateContract.methods .collectOceanFee(exchangeId) .send({ @@ -1175,7 +1158,6 @@ export class FixedRateExchange { exchangeId, this.web3.utils.toWei(newMarketFee) ) - console.log('estGas', estGas) const trxReceipt = await this.fixedRateContract.methods .updateMarketFee(exchangeId, this.web3.utils.toWei(newMarketFee)) .send({ @@ -1230,7 +1212,6 @@ export class FixedRateExchange { exchangeId, newMarketFeeCollector ) - console.log('estGas', estGas) const trxReceipt = await this.fixedRateContract.methods .updateMarketFeeCollector(exchangeId, newMarketFeeCollector) .send({ From 4cfc5ad567f2bf3a74812d23001295b845855a1d Mon Sep 17 00:00:00 2001 From: "Miquel A. Cabot" Date: Mon, 16 May 2022 17:48:35 +0200 Subject: [PATCH 37/47] Use transfer() and approve() functions --- test/unit/factories/NftFactory.test.ts | 29 ++++++++++++++------------ 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/test/unit/factories/NftFactory.test.ts b/test/unit/factories/NftFactory.test.ts index 61a01bae..bf62acbb 100644 --- a/test/unit/factories/NftFactory.test.ts +++ b/test/unit/factories/NftFactory.test.ts @@ -2,7 +2,6 @@ import { assert, expect } from 'chai' import { AbiItem } from 'web3-utils/types' import { deployContracts, Addresses } from '../../TestContractHandler' 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 { NftFactory, @@ -10,7 +9,9 @@ import { TokenOrder, ZERO_ADDRESS, signHash, - Nft + Nft, + transfer, + approve } from '../../../src' import { ProviderFees, @@ -143,19 +144,21 @@ describe('Nft Factory test', () => { swapFeeMarketRunner: FEE } - // approve poolParams.vestingAmount DAI to nftFactory - const daiContract = new web3.eth.Contract( - MockERC20.abi as AbiItem[], - contracts.daiAddress + await transfer( + web3, + factoryOwner, + contracts.daiAddress, + nftOwner, + poolParams.vestingAmount ) - await daiContract.methods - .transfer(nftOwner, web3.utils.toWei(poolParams.vestingAmount)) - .send({ from: factoryOwner }) - - await daiContract.methods - .approve(contracts.erc721FactoryAddress, web3.utils.toWei(poolParams.vestingAmount)) - .send({ from: nftOwner }) + await approve( + web3, + nftOwner, + contracts.daiAddress, + contracts.erc721FactoryAddress, + poolParams.vestingAmount + ) const txReceipt = await nftFactory.createNftErc20WithPool( nftOwner, From 471e3e503dc79f4f52fbbe0984cb2ac53311ab8d Mon Sep 17 00:00:00 2001 From: mihaisc Date: Tue, 17 May 2022 12:34:09 -0700 Subject: [PATCH 38/47] update max out (#1475) Signed-off-by: mihaisc --- src/utils/PoolHelpers.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/PoolHelpers.ts b/src/utils/PoolHelpers.ts index c817d64d..dc93b0a7 100644 --- a/src/utils/PoolHelpers.ts +++ b/src/utils/PoolHelpers.ts @@ -2,11 +2,11 @@ import Decimal from 'decimal.js' import { Pool } from '..' export function calcMaxExactOut(balance: string): Decimal { - return new Decimal(balance).div(3.01) + return new Decimal(balance).div(2) } export function calcMaxExactIn(balance: string): Decimal { - return new Decimal(balance).div(2.01) + return new Decimal(balance).div(2) } export async function getMaxSwapExactOut( poolInstance: Pool, From 73193d187838798c4cfce2d8664a7d31c6c5ed84 Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Wed, 18 May 2022 02:26:25 +0300 Subject: [PATCH 39/47] bump to contracts 34 (#1476) --- package-lock.json | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 32efbef6..b8205741 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "1.0.0-next.43", "license": "Apache-2.0", "dependencies": { - "@oceanprotocol/contracts": "^1.0.0-alpha.33", + "@oceanprotocol/contracts": "^1.0.0-alpha.34", "bignumber.js": "^9.0.2", "cross-fetch": "^3.1.5", "crypto-js": "^4.1.1", @@ -2471,9 +2471,9 @@ } }, "node_modules/@oceanprotocol/contracts": { - "version": "1.0.0-alpha.33", - "resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-1.0.0-alpha.33.tgz", - "integrity": "sha512-jx8fg9src7fjeqMXB2ZYLdp0BoJA0G5vau6pa48YOjasDuPekJtPdT0oRy0PVkyJ2HtkYjAwKVyiFfAbZcug6A==" + "version": "1.0.0-alpha.34", + "resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-1.0.0-alpha.34.tgz", + "integrity": "sha512-ZhNCakYbUpXrffpS98Hj0r5K70IzzTXNoYKBX4Ks3Qqc2T7mhXIxtakzygkM0lEk038ImWuzS2PAZKTATz+X2w==" }, "node_modules/@octokit/auth-token": { "version": "2.5.0", @@ -19610,9 +19610,9 @@ } }, "@oceanprotocol/contracts": { - "version": "1.0.0-alpha.33", - "resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-1.0.0-alpha.33.tgz", - "integrity": "sha512-jx8fg9src7fjeqMXB2ZYLdp0BoJA0G5vau6pa48YOjasDuPekJtPdT0oRy0PVkyJ2HtkYjAwKVyiFfAbZcug6A==" + "version": "1.0.0-alpha.34", + "resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-1.0.0-alpha.34.tgz", + "integrity": "sha512-ZhNCakYbUpXrffpS98Hj0r5K70IzzTXNoYKBX4Ks3Qqc2T7mhXIxtakzygkM0lEk038ImWuzS2PAZKTATz+X2w==" }, "@octokit/auth-token": { "version": "2.5.0", diff --git a/package.json b/package.json index 7e2405d3..d572fded 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "web3": "^1.7.3" }, "dependencies": { - "@oceanprotocol/contracts": "^1.0.0-alpha.33", + "@oceanprotocol/contracts": "^1.0.0-alpha.34", "bignumber.js": "^9.0.2", "cross-fetch": "^3.1.5", "crypto-js": "^4.1.1", From 620b5d3a24e3d76a7b9ac1fc78a370add76f549a Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Tue, 17 May 2022 16:27:57 -0700 Subject: [PATCH 40/47] Release 1.0.0-next.44 --- CHANGELOG.md | 11 +++++++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4d4d10b..f5a906fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,19 @@ All notable changes to this project will be documented in this file. Dates are d Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). +#### [v1.0.0-next.44](https://github.com/oceanprotocol/ocean.js/compare/v1.0.0-next.43...v1.0.0-next.44) + +- bump to contracts 34 [`#1476`](https://github.com/oceanprotocol/ocean.js/pull/1476) +- update max out [`#1475`](https://github.com/oceanprotocol/ocean.js/pull/1475) +- Issue-#1343: Rewrite simple publish consume flow test [`#1454`](https://github.com/oceanprotocol/ocean.js/pull/1454) +- refactor SimplePublishConsumeFlow.test.ts file [`c97f750`](https://github.com/oceanprotocol/ocean.js/commit/c97f7503133986c4a6165c4ddcb7f54e5afdc2fe) +- don't deploy smart contracts [`a75ca34`](https://github.com/oceanprotocol/ocean.js/commit/a75ca34e9e5245cfdbb670f1c23c91d96c57ec30) +- add DDO type [`11508b7`](https://github.com/oceanprotocol/ocean.js/commit/11508b7794048dc5f81fc4aba4c3a5b551c9e18c) + #### [v1.0.0-next.43](https://github.com/oceanprotocol/ocean.js/compare/v1.0.0-next.42...v1.0.0-next.43) +> 17 May 2022 + - bump contracts to alpha.33 [`#1472`](https://github.com/oceanprotocol/ocean.js/pull/1472) - Bump @types/node from 17.0.32 to 17.0.34 [`#1471`](https://github.com/oceanprotocol/ocean.js/pull/1471) - Add transfer() function to TokenUtils [`#1387`](https://github.com/oceanprotocol/ocean.js/pull/1387) diff --git a/package-lock.json b/package-lock.json index b8205741..21e270d5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@oceanprotocol/lib", - "version": "1.0.0-next.43", + "version": "1.0.0-next.44", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@oceanprotocol/lib", - "version": "1.0.0-next.43", + "version": "1.0.0-next.44", "license": "Apache-2.0", "dependencies": { "@oceanprotocol/contracts": "^1.0.0-alpha.34", diff --git a/package.json b/package.json index d572fded..3aebdc5a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@oceanprotocol/lib", "source": "./src/index.ts", - "version": "1.0.0-next.43", + "version": "1.0.0-next.44", "description": "JavaScript client library for Ocean Protocol", "main": "./dist/lib.js", "umd:main": "dist/lib.umd.js", From 5979f97e6bd37ee95a94069be1d311b1d00c2237 Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Wed, 18 May 2022 15:33:21 +0300 Subject: [PATCH 41/47] Moving PublishingMarketFee to @types/erc20.ts --- src/@types/Erc20.ts | 6 ++++++ src/tokens/Datatoken.ts | 9 ++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/@types/Erc20.ts b/src/@types/Erc20.ts index 9c133ff7..19643b47 100644 --- a/src/@types/Erc20.ts +++ b/src/@types/Erc20.ts @@ -15,3 +15,9 @@ export interface ConsumeMarketFee { consumeMarketFeeToken: string // address of the token marketplace wants to add fee on top consumeMarketFeeAmount: string } + +export interface PublishingMarketFee { + publishMarketFeeAddress: string + publishMarketFeeToken: string + publishMarketFeeAmount: string +} diff --git a/src/tokens/Datatoken.ts b/src/tokens/Datatoken.ts index 59e13fe9..6ccc803c 100644 --- a/src/tokens/Datatoken.ts +++ b/src/tokens/Datatoken.ts @@ -17,7 +17,8 @@ import { ConsumeMarketFee, FreOrderParams, FreCreationParams, - ProviderFees + ProviderFees, + PublishingMarketFee } from '../@types' import { Nft } from './NFT' import { Config } from '../models/index.js' @@ -44,12 +45,6 @@ export interface DispenserParams { allowedSwapper?: string // only account that can ask tokens. set address(0) if not required } -export interface PublishingMarketFee { - publishMarketFeeAddress: string - publishMarketFeeToken: string - publishMarketFeeAmount: string -} - export class Datatoken { public GASLIMIT_DEFAULT = 1000000 public factoryAddress: string From cd8f892d3806c3b5ed61eaed7d255416fc7fefa5 Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Wed, 18 May 2022 16:28:32 +0300 Subject: [PATCH 42/47] Using new generic gas estimate function --- src/tokens/Datatoken.ts | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/tokens/Datatoken.ts b/src/tokens/Datatoken.ts index 0a89d052..1e7143a9 100644 --- a/src/tokens/Datatoken.ts +++ b/src/tokens/Datatoken.ts @@ -1330,23 +1330,16 @@ export class Datatoken { address: string ): Promise { // Estimate gas cost for publishMarketFeeAddress method - const gasLimitDefault = this.GASLIMIT_DEFAULT const dtContract = new this.web3.eth.Contract(this.datatokensAbi, datatokenAddress, { from: address }) - let estGas - try { - estGas = await dtContract.methods - .setPublishingMarketFee( - publishMarketFeeAddress, - publishMarketFeeToken, - publishMarketFeeAmount - ) - .estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas)) - } catch (error) { - estGas = gasLimitDefault - } - return estGas + return estimateGas( + address, + dtContract.methods.setPublishingMarketFee, + publishMarketFeeAddress, + publishMarketFeeToken, + publishMarketFeeAmount + ) } /** From 4b9f6c9c004494a225116f29f2bbdff4e2f1aa70 Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Wed, 18 May 2022 17:01:05 +0300 Subject: [PATCH 43/47] Checking if the caller is Publishing Market Fee Address before calling the smart contract --- src/tokens/Datatoken.ts | 6 ++++++ test/unit/tokens/Datatoken.test.ts | 5 +---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/tokens/Datatoken.ts b/src/tokens/Datatoken.ts index 1e7143a9..8ab3588e 100644 --- a/src/tokens/Datatoken.ts +++ b/src/tokens/Datatoken.ts @@ -1362,6 +1362,12 @@ export class Datatoken { const dtContract = new this.web3.eth.Contract(this.datatokensAbi, datatokenAddress, { from: address }) + const publishingMarketFeeAddress = ( + await dtContract.methods.getPublishingMarketFee().call() + )[0] + if (publishingMarketFeeAddress !== address) { + throw new Error(`Caller is not the Publishing Market Fee Address`) + } const estGas = await this.estGasSetPublishingMarketFee( datatokenAddress, publishMarketFeeAddress, diff --git a/test/unit/tokens/Datatoken.test.ts b/test/unit/tokens/Datatoken.test.ts index 709bf869..261c237b 100644 --- a/test/unit/tokens/Datatoken.test.ts +++ b/test/unit/tokens/Datatoken.test.ts @@ -611,10 +611,7 @@ describe('Datatoken', () => { ) } catch (e) { console.log('Message:', e.message) - assert( - e.message === - 'Returned error: VM Exception while processing transaction: revert ERC20Template: not publishMarketFeeAddress' - ) + assert(e.message === 'Caller is not the Publishing Market Fee Address') } const newPublishingMarketFee = await datatoken.getPublishingMarketFee( datatokenAddress, From 729a60f9a97c8effa2ee08411a1e20b9dca30ab5 Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Wed, 18 May 2022 17:07:53 +0300 Subject: [PATCH 44/47] Fixing codeclimate issue --- src/tokens/Datatoken.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/tokens/Datatoken.ts b/src/tokens/Datatoken.ts index 8ab3588e..5c155d5d 100644 --- a/src/tokens/Datatoken.ts +++ b/src/tokens/Datatoken.ts @@ -1362,10 +1362,8 @@ export class Datatoken { const dtContract = new this.web3.eth.Contract(this.datatokensAbi, datatokenAddress, { from: address }) - const publishingMarketFeeAddress = ( - await dtContract.methods.getPublishingMarketFee().call() - )[0] - if (publishingMarketFeeAddress !== address) { + const mktFeeAddress = (await dtContract.methods.getPublishingMarketFee().call())[0] + if (mktFeeAddress !== address) { throw new Error(`Caller is not the Publishing Market Fee Address`) } const estGas = await this.estGasSetPublishingMarketFee( From 01e646c10fc3672e0f29f166d3ed5addea68c8cf Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Fri, 20 May 2022 14:07:50 +0300 Subject: [PATCH 45/47] Fixing bug in deactivateMint gas estimation --- src/pools/fixedRate/FixedRateExchange.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pools/fixedRate/FixedRateExchange.ts b/src/pools/fixedRate/FixedRateExchange.ts index 9d98c479..ca3e5bd9 100644 --- a/src/pools/fixedRate/FixedRateExchange.ts +++ b/src/pools/fixedRate/FixedRateExchange.ts @@ -803,7 +803,7 @@ export class FixedRateExchange { const estGas = await estimateGas( address, - this.fixedRateContract.methods.methods.toggleMintState, + this.fixedRateContract.methods.toggleMintState, exchangeId, false ) From 9cd63445111fd942553f666097bc2a942371a798 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 May 2022 08:00:52 +0300 Subject: [PATCH 46/47] Bump ts-node from 10.7.0 to 10.8.0 (#1478) Bumps [ts-node](https://github.com/TypeStrong/ts-node) from 10.7.0 to 10.8.0. - [Release notes](https://github.com/TypeStrong/ts-node/releases) - [Commits](https://github.com/TypeStrong/ts-node/compare/v10.7.0...v10.8.0) --- updated-dependencies: - dependency-name: ts-node dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package-lock.json | 112 +++++++++++++++++++++++++++++----------------- package.json | 2 +- 2 files changed, 73 insertions(+), 41 deletions(-) diff --git a/package-lock.json b/package-lock.json index 21e270d5..f87392f3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -45,7 +45,7 @@ "prettier": "^2.6.2", "release-it": "^15.0.0", "source-map-support": "^0.5.19", - "ts-node": "^10.7.0", + "ts-node": "^10.8.0", "ts-node-register": "^1.0.0", "typedoc": "0.22.15", "typescript": "^4.6.4" @@ -1911,22 +1911,13 @@ "node": ">=6.9.0" } }, - "node_modules/@cspotcode/source-map-consumer": { - "version": "0.8.0", - "resolved": "https://registry.npmjs.org/@cspotcode/source-map-consumer/-/source-map-consumer-0.8.0.tgz", - "integrity": "sha512-41qniHzTU8yAGbCp04ohlmSrZf8bkf/iJsl3V0dRGsQN/5GFfx+LbCSsCpp2gqrqjTVg/K6O8ycoV35JIwAzAg==", - "dev": true, - "engines": { - "node": ">= 12" - } - }, "node_modules/@cspotcode/source-map-support": { - "version": "0.7.0", - "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.7.0.tgz", - "integrity": "sha512-X4xqRHqN8ACt2aHVe51OxeA2HjbcL4MqFqXkrmQszJ1NOUuUu5u6Vqx/0lZSVNku7velL5FC/s5uEAj1lsBMhA==", + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", + "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", "dev": true, "dependencies": { - "@cspotcode/source-map-consumer": "0.8.0" + "@jridgewell/trace-mapping": "0.3.9" }, "engines": { "node": ">=12" @@ -2411,6 +2402,31 @@ "node": ">=8" } }, + "node_modules/@jridgewell/resolve-uri": { + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.0.7.tgz", + "integrity": "sha512-8cXDaBBHOr2pQ7j77Y6Vp5VDT2sIqWyWQ56TjEq4ih/a4iST3dItRe8Q9fp0rrIl9DoKhWQtUQz/YpOxLkXbNA==", + "dev": true, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.4.13", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.13.tgz", + "integrity": "sha512-GryiOJmNcWbovBxTfZSF71V/mXbgcV3MewDe3kIMCLyIh5e7SKAeUZs+rMnJ8jkMolZ/4/VsdBmMrw3l+VdZ3w==", + "dev": true + }, + "node_modules/@jridgewell/trace-mapping": { + "version": "0.3.9", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", + "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", + "dev": true, + "dependencies": { + "@jridgewell/resolve-uri": "^3.0.3", + "@jridgewell/sourcemap-codec": "^1.4.10" + } + }, "node_modules/@metamask/safe-event-emitter": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@metamask/safe-event-emitter/-/safe-event-emitter-2.0.0.tgz", @@ -16285,12 +16301,12 @@ "integrity": "sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=" }, "node_modules/ts-node": { - "version": "10.7.0", - "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.7.0.tgz", - "integrity": "sha512-TbIGS4xgJoX2i3do417KSaep1uRAW/Lu+WAL2doDHC0D6ummjirVOXU5/7aiZotbQ5p1Zp9tP7U6cYhA0O7M8A==", + "version": "10.8.0", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.8.0.tgz", + "integrity": "sha512-/fNd5Qh+zTt8Vt1KbYZjRHCE9sI5i7nqfD/dzBBRDeVXZXS6kToW6R7tTU6Nd4XavFs0mAVCg29Q//ML7WsZYA==", "dev": true, "dependencies": { - "@cspotcode/source-map-support": "0.7.0", + "@cspotcode/source-map-support": "^0.8.0", "@tsconfig/node10": "^1.0.7", "@tsconfig/node12": "^1.0.7", "@tsconfig/node14": "^1.0.0", @@ -16301,7 +16317,7 @@ "create-require": "^1.1.0", "diff": "^4.0.1", "make-error": "^1.1.1", - "v8-compile-cache-lib": "^3.0.0", + "v8-compile-cache-lib": "^3.0.1", "yn": "3.1.1" }, "bin": { @@ -16885,9 +16901,9 @@ "dev": true }, "node_modules/v8-compile-cache-lib": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.0.tgz", - "integrity": "sha512-mpSYqfsFvASnSn5qMiwrr4VKfumbPyONLCOPmsR3A6pTY/r0+tSaVbgPWSAIuzbk3lCTa+FForeTiO+wBQGkjA==", + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", + "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", "dev": true }, "node_modules/varint": { @@ -19258,19 +19274,13 @@ "to-fast-properties": "^2.0.0" } }, - "@cspotcode/source-map-consumer": { - "version": "0.8.0", - "resolved": "https://registry.npmjs.org/@cspotcode/source-map-consumer/-/source-map-consumer-0.8.0.tgz", - "integrity": "sha512-41qniHzTU8yAGbCp04ohlmSrZf8bkf/iJsl3V0dRGsQN/5GFfx+LbCSsCpp2gqrqjTVg/K6O8ycoV35JIwAzAg==", - "dev": true - }, "@cspotcode/source-map-support": { - "version": "0.7.0", - "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.7.0.tgz", - "integrity": "sha512-X4xqRHqN8ACt2aHVe51OxeA2HjbcL4MqFqXkrmQszJ1NOUuUu5u6Vqx/0lZSVNku7velL5FC/s5uEAj1lsBMhA==", + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", + "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", "dev": true, "requires": { - "@cspotcode/source-map-consumer": "0.8.0" + "@jridgewell/trace-mapping": "0.3.9" } }, "@eslint/eslintrc": { @@ -19565,6 +19575,28 @@ "integrity": "sha512-ZXRY4jNvVgSVQ8DL3LTcakaAtXwTVUxE81hslsyD2AtoXW/wVob10HkOJ1X/pAlcI7D+2YoZKg5do8G/w6RYgA==", "dev": true }, + "@jridgewell/resolve-uri": { + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.0.7.tgz", + "integrity": "sha512-8cXDaBBHOr2pQ7j77Y6Vp5VDT2sIqWyWQ56TjEq4ih/a4iST3dItRe8Q9fp0rrIl9DoKhWQtUQz/YpOxLkXbNA==", + "dev": true + }, + "@jridgewell/sourcemap-codec": { + "version": "1.4.13", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.13.tgz", + "integrity": "sha512-GryiOJmNcWbovBxTfZSF71V/mXbgcV3MewDe3kIMCLyIh5e7SKAeUZs+rMnJ8jkMolZ/4/VsdBmMrw3l+VdZ3w==", + "dev": true + }, + "@jridgewell/trace-mapping": { + "version": "0.3.9", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", + "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", + "dev": true, + "requires": { + "@jridgewell/resolve-uri": "^3.0.3", + "@jridgewell/sourcemap-codec": "^1.4.10" + } + }, "@metamask/safe-event-emitter": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@metamask/safe-event-emitter/-/safe-event-emitter-2.0.0.tgz", @@ -30239,12 +30271,12 @@ "integrity": "sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=" }, "ts-node": { - "version": "10.7.0", - "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.7.0.tgz", - "integrity": "sha512-TbIGS4xgJoX2i3do417KSaep1uRAW/Lu+WAL2doDHC0D6ummjirVOXU5/7aiZotbQ5p1Zp9tP7U6cYhA0O7M8A==", + "version": "10.8.0", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.8.0.tgz", + "integrity": "sha512-/fNd5Qh+zTt8Vt1KbYZjRHCE9sI5i7nqfD/dzBBRDeVXZXS6kToW6R7tTU6Nd4XavFs0mAVCg29Q//ML7WsZYA==", "dev": true, "requires": { - "@cspotcode/source-map-support": "0.7.0", + "@cspotcode/source-map-support": "^0.8.0", "@tsconfig/node10": "^1.0.7", "@tsconfig/node12": "^1.0.7", "@tsconfig/node14": "^1.0.0", @@ -30255,7 +30287,7 @@ "create-require": "^1.1.0", "diff": "^4.0.1", "make-error": "^1.1.1", - "v8-compile-cache-lib": "^3.0.0", + "v8-compile-cache-lib": "^3.0.1", "yn": "3.1.1" }, "dependencies": { @@ -30684,9 +30716,9 @@ "dev": true }, "v8-compile-cache-lib": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.0.tgz", - "integrity": "sha512-mpSYqfsFvASnSn5qMiwrr4VKfumbPyONLCOPmsR3A6pTY/r0+tSaVbgPWSAIuzbk3lCTa+FForeTiO+wBQGkjA==", + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", + "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", "dev": true }, "varint": { diff --git a/package.json b/package.json index b865eb6a..e55d71f6 100644 --- a/package.json +++ b/package.json @@ -94,7 +94,7 @@ "prettier": "^2.6.2", "release-it": "^15.0.0", "source-map-support": "^0.5.19", - "ts-node": "^10.7.0", + "ts-node": "^10.8.0", "ts-node-register": "^1.0.0", "typedoc": "0.22.15", "typescript": "^4.6.4" From 00003072455c8ce8051cddee6660e91ece1954fd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 May 2022 08:01:05 +0300 Subject: [PATCH 47/47] Bump @types/node from 17.0.34 to 17.0.35 (#1477) Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 17.0.34 to 17.0.35. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) --- updated-dependencies: - dependency-name: "@types/node" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package-lock.json | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index f87392f3..089ee98e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,7 +24,7 @@ "@types/chai-spies": "^1.0.3", "@types/crypto-js": "^4.1.1", "@types/mocha": "^9.1.1", - "@types/node": "^17.0.34", + "@types/node": "^17.0.35", "@types/node-fetch": "^3.0.3", "@typescript-eslint/eslint-plugin": "^4.33.0", "@typescript-eslint/parser": "^4.33.0", @@ -3037,9 +3037,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "17.0.34", - "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.34.tgz", - "integrity": "sha512-XImEz7XwTvDBtzlTnm8YvMqGW/ErMWBsKZ+hMTvnDIjGCKxwK5Xpc+c/oQjOauwq8M4OS11hEkpjX8rrI/eEgA==" + "version": "17.0.35", + "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.35.tgz", + "integrity": "sha512-vu1SrqBjbbZ3J6vwY17jBs8Sr/BKA+/a/WtjRG+whKg1iuLFOosq872EXS0eXWILdO36DHQQeku/ZcL6hz2fpg==" }, "node_modules/@types/node-fetch": { "version": "3.0.3", @@ -20111,9 +20111,9 @@ "dev": true }, "@types/node": { - "version": "17.0.34", - "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.34.tgz", - "integrity": "sha512-XImEz7XwTvDBtzlTnm8YvMqGW/ErMWBsKZ+hMTvnDIjGCKxwK5Xpc+c/oQjOauwq8M4OS11hEkpjX8rrI/eEgA==" + "version": "17.0.35", + "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.35.tgz", + "integrity": "sha512-vu1SrqBjbbZ3J6vwY17jBs8Sr/BKA+/a/WtjRG+whKg1iuLFOosq872EXS0eXWILdO36DHQQeku/ZcL6hz2fpg==" }, "@types/node-fetch": { "version": "3.0.3", diff --git a/package.json b/package.json index e55d71f6..0ced12c6 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,7 @@ "@types/chai-spies": "^1.0.3", "@types/crypto-js": "^4.1.1", "@types/mocha": "^9.1.1", - "@types/node": "^17.0.34", + "@types/node": "^17.0.35", "@types/node-fetch": "^3.0.3", "@typescript-eslint/eslint-plugin": "^4.33.0", "@typescript-eslint/parser": "^4.33.0",