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:
parent
7e935da179
commit
899dd34a28
@ -29,7 +29,7 @@
|
||||
"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: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: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'",
|
||||
|
@ -10,7 +10,7 @@ import { Contract } from 'web3-eth-contract'
|
||||
*/
|
||||
interface Roles {
|
||||
manager: boolean
|
||||
deployErc20: boolean
|
||||
deployERC20: boolean
|
||||
updateMetadata: boolean
|
||||
store: boolean
|
||||
}
|
||||
@ -107,6 +107,9 @@ export class Nft {
|
||||
symbol?: string,
|
||||
templateIndex?: number
|
||||
): Promise<string> {
|
||||
if ((await this.getNftPermissions(nftAddress, address)).deployERC20 !== true) {
|
||||
throw new Error(`Caller is not ERC20Deployer`)
|
||||
}
|
||||
if (!templateIndex) templateIndex = 1
|
||||
|
||||
// Generate name & symbol if not present
|
||||
@ -114,6 +117,7 @@ export class Nft {
|
||||
;({ name, symbol } = generateDtName())
|
||||
}
|
||||
|
||||
|
||||
// Create 721contract object
|
||||
const nftContract = new this.web3.eth.Contract(this.nftAbi, nftAddress)
|
||||
|
||||
@ -380,9 +384,10 @@ export class Nft {
|
||||
erc20Deployer: string
|
||||
): Promise<TransactionReceipt> {
|
||||
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(
|
||||
nftAddress,
|
||||
@ -512,8 +517,8 @@ export class Nft {
|
||||
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 !== metadataUpdater && (await this.getNftPermissions(nftAddress, address)).updateMetadata !== true) {
|
||||
throw new Error(`Caller is not Manager nor Metadata Updater`)
|
||||
}
|
||||
|
||||
const estGas = await this.esGasRemoveMetadataUpdater(
|
||||
@ -583,7 +588,7 @@ export class Nft {
|
||||
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`)
|
||||
}
|
||||
|
||||
@ -648,8 +653,8 @@ export class Nft {
|
||||
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 !== storeUpdater && (await this.getNftPermissions(nftAddress, address)).store !== true) {
|
||||
throw new Error(`Caller is not Manager nor storeUpdater`)
|
||||
}
|
||||
|
||||
const estGas = await this.estGasRemoveStoreUpdater(
|
||||
|
@ -96,6 +96,27 @@ describe('NFT', () => {
|
||||
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
|
||||
it('#addManager - should add a new Manager', async () => {
|
||||
assert((await nftDatatoken.getNftPermissions(nftAddress, user1)).manager === false)
|
||||
@ -138,14 +159,19 @@ describe('NFT', () => {
|
||||
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 () => {
|
||||
try {
|
||||
await nftDatatoken.addErc20Deployer(nftAddress, user1, user1)
|
||||
} catch (e) {
|
||||
assert(
|
||||
e.message ===
|
||||
'Returned error: VM Exception while processing transaction: revert ERC721RolesAddress: NOT MANAGER'
|
||||
)
|
||||
assert(e.message === 'Caller is not Manager')
|
||||
}
|
||||
})
|
||||
|
||||
@ -157,15 +183,25 @@ describe('NFT', () => {
|
||||
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 {
|
||||
await nftDatatoken.removeErc20Deployer(nftAddress, user1, user1)
|
||||
} catch (e) {
|
||||
assert(
|
||||
e.message ===
|
||||
'Returned error: VM Exception while processing transaction: revert ERC721RolesAddress: Not enough permissions to remove from ERC20List'
|
||||
)
|
||||
assert(e.message === 'Caller is not Manager nor ERC20Deployer')
|
||||
}
|
||||
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
|
||||
@ -185,10 +221,7 @@ describe('NFT', () => {
|
||||
try {
|
||||
await nftDatatoken.addMetadataUpdater(nftAddress, user1, user1)
|
||||
} catch (e) {
|
||||
assert(
|
||||
e.message ===
|
||||
'Returned error: VM Exception while processing transaction: revert ERC721RolesAddress: NOT MANAGER'
|
||||
)
|
||||
assert(e.message === 'Caller is not Manager')
|
||||
}
|
||||
})
|
||||
|
||||
@ -210,7 +243,7 @@ describe('NFT', () => {
|
||||
} catch (e) {
|
||||
assert(
|
||||
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 {
|
||||
await nftDatatoken.addStoreUpdater(nftAddress, user1, user1)
|
||||
} catch (e) {
|
||||
assert(
|
||||
e.message ===
|
||||
'Returned error: VM Exception while processing transaction: revert ERC721RolesAddress: NOT MANAGER'
|
||||
)
|
||||
assert(e.message === 'Caller is not Manager')
|
||||
}
|
||||
})
|
||||
|
||||
@ -249,7 +279,7 @@ describe('NFT', () => {
|
||||
} catch (e) {
|
||||
assert(
|
||||
e.message ===
|
||||
'Returned error: VM Exception while processing transaction: revert ERC721RolesAddress: Not enough permissions to remove from 725StoreList'
|
||||
`Caller is not Manager nor storeUpdater`
|
||||
)
|
||||
}
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user