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

add NFT extra tests, fix Roles type

This commit is contained in:
lacoop6tu 2021-12-16 05:41:03 -05:00
parent 7e935da179
commit 899dd34a28
3 changed files with 64 additions and 29 deletions

View File

@ -29,7 +29,7 @@
"test:pool": "mocha --config=test/unit/.mocharc.json --node-env=test --exit 'test/unit/pools/balancer/Pool.test.ts'", "test:pool": "mocha --config=test/unit/.mocharc.json --node-env=test --exit 'test/unit/pools/balancer/Pool.test.ts'",
"test:dispenser": "mocha --config=test/unit/.mocharc.json --node-env=test --exit 'test/unit/pools/dispenser/Dispenser.test.ts'", "test:dispenser": "mocha --config=test/unit/.mocharc.json --node-env=test --exit 'test/unit/pools/dispenser/Dispenser.test.ts'",
"test:dt": "mocha --config=test/unit/.mocharc.json --node-env=test --exit 'test/unit/Datatoken.test.ts'", "test:dt": "mocha --config=test/unit/.mocharc.json --node-env=test --exit 'test/unit/Datatoken.test.ts'",
"test:nftDt": "mocha --config=test/unit/.mocharc.json --node-env=test --exit 'test/unit/NFT.test.ts'", "test:nftDt": "mocha --config=test/unit/.mocharc.json --node-env=test --exit 'test/unit/tokens/Nft.test.ts'",
"test:factory": "mocha --config=test/unit/.mocharc.json --node-env=test --exit 'test/unit/NFTFactory.test.ts'", "test:factory": "mocha --config=test/unit/.mocharc.json --node-env=test --exit 'test/unit/NFTFactory.test.ts'",
"test:router": "mocha --config=test/unit/.mocharc.json --node-env=test --exit 'test/unit/pools/Router.test.ts'", "test:router": "mocha --config=test/unit/.mocharc.json --node-env=test --exit 'test/unit/pools/Router.test.ts'",
"test:unit": "mocha --config=test/unit/.mocharc.json --node-env=test --exit 'test/unit/**/*.test.ts'", "test:unit": "mocha --config=test/unit/.mocharc.json --node-env=test --exit 'test/unit/**/*.test.ts'",

View File

@ -10,7 +10,7 @@ import { Contract } from 'web3-eth-contract'
*/ */
interface Roles { interface Roles {
manager: boolean manager: boolean
deployErc20: boolean deployERC20: boolean
updateMetadata: boolean updateMetadata: boolean
store: boolean store: boolean
} }
@ -107,6 +107,9 @@ export class Nft {
symbol?: string, symbol?: string,
templateIndex?: number templateIndex?: number
): Promise<string> { ): Promise<string> {
if ((await this.getNftPermissions(nftAddress, address)).deployERC20 !== true) {
throw new Error(`Caller is not ERC20Deployer`)
}
if (!templateIndex) templateIndex = 1 if (!templateIndex) templateIndex = 1
// Generate name & symbol if not present // Generate name & symbol if not present
@ -114,6 +117,7 @@ export class Nft {
;({ name, symbol } = generateDtName()) ;({ name, symbol } = generateDtName())
} }
// Create 721contract object // Create 721contract object
const nftContract = new this.web3.eth.Contract(this.nftAbi, nftAddress) const nftContract = new this.web3.eth.Contract(this.nftAbi, nftAddress)
@ -380,9 +384,10 @@ export class Nft {
erc20Deployer: string erc20Deployer: string
): Promise<TransactionReceipt> { ): Promise<TransactionReceipt> {
const nftContract = new this.web3.eth.Contract(this.nftAbi, nftAddress) const nftContract = new this.web3.eth.Contract(this.nftAbi, nftAddress)
if ((await this.getNftPermissions(nftAddress, address)).manager !== true) {
throw new Error(`Caller is not Manager`) if ((await this.getNftPermissions(nftAddress, address)).manager !== true || address === erc20Deployer && (await this.getNftPermissions(nftAddress, address)).deployERC20 !== true) {
throw new Error(`Caller is not Manager nor ERC20Deployer`)
} }
const estGas = await this.estGasRemoveErc20Deployer( const estGas = await this.estGasRemoveErc20Deployer(
nftAddress, nftAddress,
@ -512,8 +517,8 @@ export class Nft {
const nftContract = new this.web3.eth.Contract(this.nftAbi, nftAddress) const nftContract = new this.web3.eth.Contract(this.nftAbi, nftAddress)
if ((await this.getNftPermissions(nftAddress, address)).manager !== true) { if ((await this.getNftPermissions(nftAddress, address)).manager !== true || address !== metadataUpdater && (await this.getNftPermissions(nftAddress, address)).updateMetadata !== true) {
throw new Error(`Caller is not Manager`) throw new Error(`Caller is not Manager nor Metadata Updater`)
} }
const estGas = await this.esGasRemoveMetadataUpdater( const estGas = await this.esGasRemoveMetadataUpdater(
@ -583,7 +588,7 @@ export class Nft {
const nftContract = new this.web3.eth.Contract(this.nftAbi, nftAddress) const nftContract = new this.web3.eth.Contract(this.nftAbi, nftAddress)
if ((await this.getNftPermissions(nftAddress, address)).manager !== true) { if ((await this.getNftPermissions(nftAddress, address)).manager !== true ) {
throw new Error(`Caller is not Manager`) throw new Error(`Caller is not Manager`)
} }
@ -648,8 +653,8 @@ export class Nft {
const nftContract = new this.web3.eth.Contract(this.nftAbi, nftAddress) const nftContract = new this.web3.eth.Contract(this.nftAbi, nftAddress)
if ((await this.getNftPermissions(nftAddress, address)).manager !== true) { if ((await this.getNftPermissions(nftAddress, address)).manager !== true || address !== storeUpdater && (await this.getNftPermissions(nftAddress, address)).store !== true) {
throw new Error(`Caller is not Manager`) throw new Error(`Caller is not Manager nor storeUpdater`)
} }
const estGas = await this.estGasRemoveStoreUpdater( const estGas = await this.estGasRemoveStoreUpdater(

View File

@ -96,6 +96,27 @@ describe('NFT', () => {
assert(erc20Address !== null) assert(erc20Address !== null)
}) })
it('#createERC20 - should fail to create a new ERC20 DT if not ERC20Deployer', async () => {
try{( await nftDatatoken.createErc20(
nftAddress,
user1,
nftOwner,
user1,
user2,
'0x0000000000000000000000000000000000000000',
'0',
'10000',
nftName,
nftSymbol,
1
)) }catch(e) {
assert(e.message === 'Caller is not ERC20Deployer')
}
})
// Manager // Manager
it('#addManager - should add a new Manager', async () => { it('#addManager - should add a new Manager', async () => {
assert((await nftDatatoken.getNftPermissions(nftAddress, user1)).manager === false) assert((await nftDatatoken.getNftPermissions(nftAddress, user1)).manager === false)
@ -138,14 +159,19 @@ describe('NFT', () => {
assert((await nftDatatoken.isErc20Deployer(nftAddress, user1)) === true) assert((await nftDatatoken.isErc20Deployer(nftAddress, user1)) === true)
}) })
it('#addManager - should fail to add a new Manager, if NOT NFT Owner', async () => {
try {
await nftDatatoken.addManager(nftAddress, user1, user1)
} catch (e) {
assert(e.message === 'Caller is not NFT Owner')
}
})
it('#addERC20Deployer - should fail to add ERC20deployer if NOT Manager', async () => { it('#addERC20Deployer - should fail to add ERC20deployer if NOT Manager', async () => {
try { try {
await nftDatatoken.addErc20Deployer(nftAddress, user1, user1) await nftDatatoken.addErc20Deployer(nftAddress, user1, user1)
} catch (e) { } catch (e) {
assert( assert(e.message === 'Caller is not Manager')
e.message ===
'Returned error: VM Exception while processing transaction: revert ERC721RolesAddress: NOT MANAGER'
)
} }
}) })
@ -157,15 +183,25 @@ describe('NFT', () => {
assert((await nftDatatoken.isErc20Deployer(nftAddress, user1)) === false) assert((await nftDatatoken.isErc20Deployer(nftAddress, user1)) === false)
}) })
it('#removeERC20Deployer - should fail and remove ERC20deployer if NOT Manager', async () => { it('#removeERC20Deployer - should fail and remove ERC20deployer if NOT Manager nor himself an ERC20Deployer', async () => {
await nftDatatoken.addErc20Deployer(nftAddress, nftOwner, user1)
assert((await nftDatatoken.isErc20Deployer(nftAddress, user1)) === true)
try { try {
await nftDatatoken.removeErc20Deployer(nftAddress, user1, user1) await nftDatatoken.removeErc20Deployer(nftAddress, user1, user1)
} catch (e) { } catch (e) {
assert( assert(e.message === 'Caller is not Manager nor ERC20Deployer')
e.message ===
'Returned error: VM Exception while processing transaction: revert ERC721RolesAddress: Not enough permissions to remove from ERC20List'
)
} }
assert((await nftDatatoken.isErc20Deployer(nftAddress, user1)) === true)
})
it('#removeERC20Deployer - should fail to remove himself an ERC20Deployer', async () => {
assert((await nftDatatoken.isErc20Deployer(nftAddress, user1)) === true)
try {
await nftDatatoken.removeErc20Deployer(nftAddress, user1, user1)
} catch (e) {
assert(e.message === 'Caller is not Manager nor ERC20Deployer')
}
assert((await nftDatatoken.isErc20Deployer(nftAddress, user1)) === true)
}) })
// MetadataUpdate // MetadataUpdate
@ -185,10 +221,7 @@ describe('NFT', () => {
try { try {
await nftDatatoken.addMetadataUpdater(nftAddress, user1, user1) await nftDatatoken.addMetadataUpdater(nftAddress, user1, user1)
} catch (e) { } catch (e) {
assert( assert(e.message === 'Caller is not Manager')
e.message ===
'Returned error: VM Exception while processing transaction: revert ERC721RolesAddress: NOT MANAGER'
)
} }
}) })
@ -210,7 +243,7 @@ describe('NFT', () => {
} catch (e) { } catch (e) {
assert( assert(
e.message === e.message ===
'Returned error: VM Exception while processing transaction: revert ERC721RolesAddress: Not enough permissions to remove from metadata list' 'Caller is not Manager nor Metadata Updater'
) )
} }
}) })
@ -228,10 +261,7 @@ describe('NFT', () => {
try { try {
await nftDatatoken.addStoreUpdater(nftAddress, user1, user1) await nftDatatoken.addStoreUpdater(nftAddress, user1, user1)
} catch (e) { } catch (e) {
assert( assert(e.message === 'Caller is not Manager')
e.message ===
'Returned error: VM Exception while processing transaction: revert ERC721RolesAddress: NOT MANAGER'
)
} }
}) })
@ -249,7 +279,7 @@ describe('NFT', () => {
} catch (e) { } catch (e) {
assert( assert(
e.message === e.message ===
'Returned error: VM Exception while processing transaction: revert ERC721RolesAddress: Not enough permissions to remove from 725StoreList' `Caller is not Manager nor storeUpdater`
) )
} }
}) })