mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
add ERC20Deployer checks and tests in Datatoken Class
This commit is contained in:
parent
96cfa952e4
commit
e64e0b61b1
@ -28,7 +28,7 @@
|
|||||||
"test:fixed": "mocha --config=test/unit/.mocharc.json --node-env=test --exit 'test/unit/pools/fixedRate/FixedRateExchange.test.ts'",
|
"test:fixed": "mocha --config=test/unit/.mocharc.json --node-env=test --exit 'test/unit/pools/fixedRate/FixedRateExchange.test.ts'",
|
||||||
"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/tokens/Datatoken.test.ts'",
|
||||||
"test:nftDt": "mocha --config=test/unit/.mocharc.json --node-env=test --exit 'test/unit/tokens/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'",
|
||||||
|
@ -108,14 +108,14 @@ export class NftFactory {
|
|||||||
nftData.name = name
|
nftData.name = name
|
||||||
nftData.symbol = symbol
|
nftData.symbol = symbol
|
||||||
}
|
}
|
||||||
if ( nftData.templateIndex > await this.getCurrentNFTTemplateCount()) {
|
if (nftData.templateIndex > (await this.getCurrentNFTTemplateCount())) {
|
||||||
throw new Error(`Template index doesnt exist`)
|
throw new Error(`Template index doesnt exist`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( nftData.templateIndex === 0) {
|
if (nftData.templateIndex === 0) {
|
||||||
throw new Error(`Template index cannot be ZERO`)
|
throw new Error(`Template index cannot be ZERO`)
|
||||||
}
|
}
|
||||||
if((await this.getNFTTemplate(nftData.templateIndex)).isActive === false) {
|
if ((await this.getNFTTemplate(nftData.templateIndex)).isActive === false) {
|
||||||
throw new Error(`Template is not active`)
|
throw new Error(`Template is not active`)
|
||||||
}
|
}
|
||||||
const estGas = await this.estGasCreateNFT(address, nftData)
|
const estGas = await this.estGasCreateNFT(address, nftData)
|
||||||
@ -189,11 +189,11 @@ export class NftFactory {
|
|||||||
* @return {Promise<Template>} Number of Template added to this factory
|
* @return {Promise<Template>} Number of Template added to this factory
|
||||||
*/
|
*/
|
||||||
public async getNFTTemplate(index: number): Promise<Template> {
|
public async getNFTTemplate(index: number): Promise<Template> {
|
||||||
if ( index > await this.getCurrentNFTTemplateCount()) {
|
if (index > (await this.getCurrentNFTTemplateCount())) {
|
||||||
throw new Error(`Template index doesnt exist`)
|
throw new Error(`Template index doesnt exist`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( index === 0) {
|
if (index === 0) {
|
||||||
throw new Error(`Template index cannot be ZERO`)
|
throw new Error(`Template index cannot be ZERO`)
|
||||||
}
|
}
|
||||||
const template = await this.factory721.methods.getNFTTemplate(index).call()
|
const template = await this.factory721.methods.getNFTTemplate(index).call()
|
||||||
@ -262,7 +262,7 @@ export class NftFactory {
|
|||||||
if ((await this.getOwner()) !== address) {
|
if ((await this.getOwner()) !== address) {
|
||||||
throw new Error(`Caller is not Factory Owner`)
|
throw new Error(`Caller is not Factory Owner`)
|
||||||
}
|
}
|
||||||
if ( templateAddress === addressZERO) {
|
if (templateAddress === addressZERO) {
|
||||||
throw new Error(`Template cannot be ZERO address`)
|
throw new Error(`Template cannot be ZERO address`)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -315,11 +315,11 @@ export class NftFactory {
|
|||||||
if ((await this.getOwner()) !== address) {
|
if ((await this.getOwner()) !== address) {
|
||||||
throw new Error(`Caller is not Factory Owner`)
|
throw new Error(`Caller is not Factory Owner`)
|
||||||
}
|
}
|
||||||
if ( templateIndex > await this.getCurrentNFTTemplateCount()) {
|
if (templateIndex > (await this.getCurrentNFTTemplateCount())) {
|
||||||
throw new Error(`Template index doesnt exist`)
|
throw new Error(`Template index doesnt exist`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( templateIndex === 0) {
|
if (templateIndex === 0) {
|
||||||
throw new Error(`Template index cannot be ZERO`)
|
throw new Error(`Template index cannot be ZERO`)
|
||||||
}
|
}
|
||||||
const estGas = await this.estGasDisableNFTTemplate(address, templateIndex)
|
const estGas = await this.estGasDisableNFTTemplate(address, templateIndex)
|
||||||
@ -371,11 +371,11 @@ export class NftFactory {
|
|||||||
if ((await this.getOwner()) !== address) {
|
if ((await this.getOwner()) !== address) {
|
||||||
throw new Error(`Caller is not Factory Owner`)
|
throw new Error(`Caller is not Factory Owner`)
|
||||||
}
|
}
|
||||||
if ( templateIndex > await this.getCurrentNFTTemplateCount()) {
|
if (templateIndex > (await this.getCurrentNFTTemplateCount())) {
|
||||||
throw new Error(`Template index doesnt exist`)
|
throw new Error(`Template index doesnt exist`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( templateIndex === 0) {
|
if (templateIndex === 0) {
|
||||||
throw new Error(`Template index cannot be ZERO`)
|
throw new Error(`Template index cannot be ZERO`)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -429,7 +429,7 @@ export class NftFactory {
|
|||||||
if ((await this.getOwner()) !== address) {
|
if ((await this.getOwner()) !== address) {
|
||||||
throw new Error(`Caller is not Factory Owner`)
|
throw new Error(`Caller is not Factory Owner`)
|
||||||
}
|
}
|
||||||
if ( templateAddress === addressZERO) {
|
if (templateAddress === addressZERO) {
|
||||||
throw new Error(`Template cannot be address ZERO`)
|
throw new Error(`Template cannot be address ZERO`)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -482,14 +482,14 @@ export class NftFactory {
|
|||||||
if ((await this.getOwner()) !== address) {
|
if ((await this.getOwner()) !== address) {
|
||||||
throw new Error(`Caller is not Factory Owner`)
|
throw new Error(`Caller is not Factory Owner`)
|
||||||
}
|
}
|
||||||
if ( templateIndex > await this.getCurrentNFTTemplateCount()) {
|
if (templateIndex > (await this.getCurrentNFTTemplateCount())) {
|
||||||
throw new Error(`Template index doesnt exist`)
|
throw new Error(`Template index doesnt exist`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( templateIndex === 0) {
|
if (templateIndex === 0) {
|
||||||
throw new Error(`Template index cannot be ZERO`)
|
throw new Error(`Template index cannot be ZERO`)
|
||||||
}
|
}
|
||||||
if((await this.getNFTTemplate(templateIndex)).isActive === false) {
|
if ((await this.getNFTTemplate(templateIndex)).isActive === false) {
|
||||||
throw new Error(`Template is already disabled`)
|
throw new Error(`Template is already disabled`)
|
||||||
}
|
}
|
||||||
const estGas = await this.estGasDisableTokenTemplate(address, templateIndex)
|
const estGas = await this.estGasDisableTokenTemplate(address, templateIndex)
|
||||||
@ -541,14 +541,14 @@ export class NftFactory {
|
|||||||
if ((await this.getOwner()) !== address) {
|
if ((await this.getOwner()) !== address) {
|
||||||
throw new Error(`Caller is not Factory Owner`)
|
throw new Error(`Caller is not Factory Owner`)
|
||||||
}
|
}
|
||||||
if ( templateIndex > await this.getCurrentNFTTemplateCount()) {
|
if (templateIndex > (await this.getCurrentNFTTemplateCount())) {
|
||||||
throw new Error(`Template index doesnt exist`)
|
throw new Error(`Template index doesnt exist`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( templateIndex === 0) {
|
if (templateIndex === 0) {
|
||||||
throw new Error(`Template index cannot be ZERO`)
|
throw new Error(`Template index cannot be ZERO`)
|
||||||
}
|
}
|
||||||
if((await this.getNFTTemplate(templateIndex)).isActive === true) {
|
if ((await this.getNFTTemplate(templateIndex)).isActive === true) {
|
||||||
throw new Error(`Template is already active`)
|
throw new Error(`Template is already active`)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -575,9 +575,6 @@ export class NftFactory {
|
|||||||
address: string,
|
address: string,
|
||||||
orders: TokenOrder[]
|
orders: TokenOrder[]
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
||||||
let estGas
|
let estGas
|
||||||
try {
|
try {
|
||||||
@ -606,7 +603,7 @@ export class NftFactory {
|
|||||||
address: string,
|
address: string,
|
||||||
orders: TokenOrder[]
|
orders: TokenOrder[]
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
if ( orders.length > 50) {
|
if (orders.length > 50) {
|
||||||
throw new Error(`Too many orders`)
|
throw new Error(`Too many orders`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import defaultDatatokensAbi from '@oceanprotocol/contracts/artifacts/contracts/t
|
|||||||
import defaultDatatokensEnterpriseAbi from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20TemplateEnterprise.sol/ERC20TemplateEnterprise.json'
|
import defaultDatatokensEnterpriseAbi from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20TemplateEnterprise.sol/ERC20TemplateEnterprise.json'
|
||||||
import { LoggerInstance, getFairGasPrice } from '../utils'
|
import { LoggerInstance, getFairGasPrice } from '../utils'
|
||||||
import { FreOrderParams, FreCreationParams } from '../interfaces'
|
import { FreOrderParams, FreCreationParams } from '../interfaces'
|
||||||
//import { Nft } from "./NFT"
|
import { Nft } from "./NFT"
|
||||||
/**
|
/**
|
||||||
* ERC20 ROLES
|
* ERC20 ROLES
|
||||||
*/
|
*/
|
||||||
@ -225,7 +225,9 @@ export class Datatoken {
|
|||||||
fixedRateParams: FreCreationParams
|
fixedRateParams: FreCreationParams
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const dtContract = new this.web3.eth.Contract(this.datatokensAbi, dtAddress)
|
const dtContract = new this.web3.eth.Contract(this.datatokensAbi, dtAddress)
|
||||||
|
if (!await this.isERC20Deployer(dtAddress,address)) {
|
||||||
|
throw new Error(`User is not ERC20 Deployer`)
|
||||||
|
}
|
||||||
if (!fixedRateParams.allowedConsumer)
|
if (!fixedRateParams.allowedConsumer)
|
||||||
fixedRateParams.allowedConsumer = '0x0000000000000000000000000000000000000000'
|
fixedRateParams.allowedConsumer = '0x0000000000000000000000000000000000000000'
|
||||||
|
|
||||||
@ -323,6 +325,10 @@ export class Datatoken {
|
|||||||
dispenserAddress: string,
|
dispenserAddress: string,
|
||||||
dispenserParams: DispenserParams
|
dispenserParams: DispenserParams
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
|
if (!await this.isERC20Deployer(dtAddress,address)) {
|
||||||
|
throw new Error(`User is not ERC20 Deployer`)
|
||||||
|
}
|
||||||
|
|
||||||
const dtContract = new this.web3.eth.Contract(this.datatokensAbi, dtAddress)
|
const dtContract = new this.web3.eth.Contract(this.datatokensAbi, dtAddress)
|
||||||
|
|
||||||
if (!dispenserParams.allowedSwapper)
|
if (!dispenserParams.allowedSwapper)
|
||||||
@ -446,7 +452,7 @@ export class Datatoken {
|
|||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const dtContract = new this.web3.eth.Contract(this.datatokensAbi, dtAddress)
|
const dtContract = new this.web3.eth.Contract(this.datatokensAbi, dtAddress)
|
||||||
|
|
||||||
if (await this.isERC20Deployer(dtAddress,address) !== true) {
|
if ((await this.isERC20Deployer(dtAddress, address)) !== true) {
|
||||||
throw new Error(`Caller is not ERC20Deployer`)
|
throw new Error(`Caller is not ERC20Deployer`)
|
||||||
}
|
}
|
||||||
// Estimate gas cost for addMinter method
|
// Estimate gas cost for addMinter method
|
||||||
@ -511,7 +517,7 @@ export class Datatoken {
|
|||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const dtContract = new this.web3.eth.Contract(this.datatokensAbi, dtAddress)
|
const dtContract = new this.web3.eth.Contract(this.datatokensAbi, dtAddress)
|
||||||
|
|
||||||
if (await this.isERC20Deployer(dtAddress,address) !== true) {
|
if ((await this.isERC20Deployer(dtAddress, address)) !== true) {
|
||||||
throw new Error(`Caller is not ERC20Deployer`)
|
throw new Error(`Caller is not ERC20Deployer`)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -573,7 +579,7 @@ export class Datatoken {
|
|||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const dtContract = new this.web3.eth.Contract(this.datatokensAbi, dtAddress)
|
const dtContract = new this.web3.eth.Contract(this.datatokensAbi, dtAddress)
|
||||||
|
|
||||||
if (await this.isERC20Deployer(dtAddress,address) !== true) {
|
if ((await this.isERC20Deployer(dtAddress, address)) !== true) {
|
||||||
throw new Error(`Caller is not ERC20Deployer`)
|
throw new Error(`Caller is not ERC20Deployer`)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -638,7 +644,7 @@ export class Datatoken {
|
|||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const dtContract = new this.web3.eth.Contract(this.datatokensAbi, dtAddress)
|
const dtContract = new this.web3.eth.Contract(this.datatokensAbi, dtAddress)
|
||||||
|
|
||||||
if (await this.isERC20Deployer(dtAddress,address) !== true) {
|
if ((await this.isERC20Deployer(dtAddress, address)) !== true) {
|
||||||
throw new Error(`Caller is not ERC20Deployer`)
|
throw new Error(`Caller is not ERC20Deployer`)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1108,6 +1114,10 @@ export class Datatoken {
|
|||||||
address: string,
|
address: string,
|
||||||
value: string
|
value: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
|
if (!await this.isERC20Deployer(dtAddress,address)) {
|
||||||
|
throw new Error(`User is not ERC20 Deployer`)
|
||||||
|
}
|
||||||
|
|
||||||
const dtContract = new this.web3.eth.Contract(this.datatokensAbi, dtAddress)
|
const dtContract = new this.web3.eth.Contract(this.datatokensAbi, dtAddress)
|
||||||
|
|
||||||
const estGas = await this.estGasSetData(dtAddress, address, value, dtContract)
|
const estGas = await this.estGasSetData(dtAddress, address, value, dtContract)
|
||||||
@ -1122,7 +1132,6 @@ export class Datatoken {
|
|||||||
return trxReceipt
|
return trxReceipt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Estimate gas for cleanPermissions method
|
/** Estimate gas for cleanPermissions method
|
||||||
* @param dtAddress Datatoken address where we want to clean permissions
|
* @param dtAddress Datatoken address where we want to clean permissions
|
||||||
* @param address User adress
|
* @param address User adress
|
||||||
@ -1221,9 +1230,9 @@ export class Datatoken {
|
|||||||
* @param {String} dtAddress Datatoken adress
|
* @param {String} dtAddress Datatoken adress
|
||||||
* @return {Promise<boolean>}
|
* @return {Promise<boolean>}
|
||||||
*/
|
*/
|
||||||
public async isERC20Deployer(dtAddress: string, adddress: string): Promise<boolean> {
|
public async isERC20Deployer(dtAddress: string, address: string): Promise<boolean> {
|
||||||
const dtContract = new this.web3.eth.Contract(this.datatokensAbi, dtAddress)
|
const dtContract = new this.web3.eth.Contract(this.datatokensAbi, dtAddress)
|
||||||
const isERC20Deployer = await dtContract.methods.isERC20Deployer(adddress).call()
|
const isERC20Deployer = await dtContract.methods.isERC20Deployer(address).call()
|
||||||
return isERC20Deployer
|
return isERC20Deployer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@ import defaultNftAbi from '@oceanprotocol/contracts/artifacts/contracts/template
|
|||||||
import { LoggerInstance, getFairGasPrice, generateDtName } from '../utils'
|
import { LoggerInstance, getFairGasPrice, generateDtName } from '../utils'
|
||||||
import { Contract } from 'web3-eth-contract'
|
import { Contract } from 'web3-eth-contract'
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ERC721 ROLES
|
* ERC721 ROLES
|
||||||
*/
|
*/
|
||||||
@ -118,7 +117,6 @@ 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)
|
||||||
|
|
||||||
@ -386,8 +384,11 @@ export class Nft {
|
|||||||
): 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 (
|
||||||
if ((await this.getNftPermissions(nftAddress, address)).manager !== true || address === erc20Deployer && (await this.getNftPermissions(nftAddress, address)).deployERC20 !== true) {
|
(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`)
|
throw new Error(`Caller is not Manager nor ERC20Deployer`)
|
||||||
}
|
}
|
||||||
const estGas = await this.estGasRemoveErc20Deployer(
|
const estGas = await this.estGasRemoveErc20Deployer(
|
||||||
@ -517,8 +518,11 @@ export class Nft {
|
|||||||
): 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 (
|
||||||
if ((await this.getNftPermissions(nftAddress, address)).manager !== true || address !== metadataUpdater && (await this.getNftPermissions(nftAddress, address)).updateMetadata !== true) {
|
(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`)
|
throw new Error(`Caller is not Manager nor Metadata Updater`)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -555,8 +559,6 @@ export class Nft {
|
|||||||
storeUpdater: string,
|
storeUpdater: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
|
|
||||||
|
|
||||||
const nftContract =
|
const nftContract =
|
||||||
contractInstance || new this.web3.eth.Contract(this.nftAbi, nftAddress)
|
contractInstance || new this.web3.eth.Contract(this.nftAbi, nftAddress)
|
||||||
|
|
||||||
@ -586,8 +588,7 @@ export class Nft {
|
|||||||
): 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) {
|
||||||
if ((await this.getNftPermissions(nftAddress, address)).manager !== true ) {
|
|
||||||
throw new Error(`Caller is not Manager`)
|
throw new Error(`Caller is not Manager`)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -651,8 +652,11 @@ export class Nft {
|
|||||||
): 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 (
|
||||||
if ((await this.getNftPermissions(nftAddress, address)).manager !== true || address !== storeUpdater && (await this.getNftPermissions(nftAddress, address)).store !== true) {
|
(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`)
|
throw new Error(`Caller is not Manager nor storeUpdater`)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -921,7 +925,7 @@ export class Nft {
|
|||||||
data,
|
data,
|
||||||
metadataHash
|
metadataHash
|
||||||
)
|
)
|
||||||
.estimateGas({ from: metadataUpdater}, (err, estGas) =>
|
.estimateGas({ from: metadataUpdater }, (err, estGas) =>
|
||||||
err ? gasLimitDefault : estGas
|
err ? gasLimitDefault : estGas
|
||||||
)
|
)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -1006,9 +1010,7 @@ export class Nft {
|
|||||||
let estGas
|
let estGas
|
||||||
try {
|
try {
|
||||||
estGas = await nftContract.methods
|
estGas = await nftContract.methods
|
||||||
.setMetaDataState(
|
.setMetaDataState(metadataState)
|
||||||
metadataState
|
|
||||||
)
|
|
||||||
.estimateGas({ from: metadataUpdater }, (err, estGas) =>
|
.estimateGas({ from: metadataUpdater }, (err, estGas) =>
|
||||||
err ? gasLimitDefault : estGas
|
err ? gasLimitDefault : estGas
|
||||||
)
|
)
|
||||||
@ -1037,18 +1039,10 @@ export class Nft {
|
|||||||
throw new Error(`Caller is not Metadata updater`)
|
throw new Error(`Caller is not Metadata updater`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const estGas = await this.estGasSetMetadataState(
|
const estGas = await this.estGasSetMetadataState(nftAddress, address, metadataState)
|
||||||
nftAddress,
|
|
||||||
address,
|
|
||||||
metadataState
|
|
||||||
)
|
|
||||||
|
|
||||||
// Call transferFrom function of the contract
|
// Call transferFrom function of the contract
|
||||||
const trxReceipt = await nftContract.methods
|
const trxReceipt = await nftContract.methods.setMetaDataState(metadataState).send({
|
||||||
.setMetaDataState(
|
|
||||||
metadataState
|
|
||||||
)
|
|
||||||
.send({
|
|
||||||
from: address,
|
from: address,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
gasPrice: await getFairGasPrice(this.web3)
|
gasPrice: await getFairGasPrice(this.web3)
|
||||||
@ -1077,7 +1071,7 @@ export class Nft {
|
|||||||
let estGas
|
let estGas
|
||||||
try {
|
try {
|
||||||
estGas = await dtContract.methods
|
estGas = await dtContract.methods
|
||||||
.setTokenURI(tokenId,tokenURI)
|
.setTokenURI(tokenId, tokenURI)
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
estGas = gasLimitDefault
|
estGas = gasLimitDefault
|
||||||
@ -1097,16 +1091,22 @@ export class Nft {
|
|||||||
address: string,
|
address: string,
|
||||||
tokenURI: string
|
tokenURI: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
if (await this.getNftOwner(nftAddress) !== address) {
|
if ((await this.getNftOwner(nftAddress)) !== address) {
|
||||||
throw new Error(`Caller is not NFT Owner`)
|
throw new Error(`Caller is not NFT Owner`)
|
||||||
}
|
}
|
||||||
const tokenId = 1;
|
const tokenId = 1
|
||||||
|
|
||||||
const nftContract = new this.web3.eth.Contract(this.nftAbi, nftAddress)
|
const nftContract = new this.web3.eth.Contract(this.nftAbi, nftAddress)
|
||||||
const estGas = await this.estGasSetTokenURI(nftAddress, address, tokenId,tokenURI, nftContract)
|
const estGas = await this.estGasSetTokenURI(
|
||||||
|
nftAddress,
|
||||||
|
address,
|
||||||
|
tokenId,
|
||||||
|
tokenURI,
|
||||||
|
nftContract
|
||||||
|
)
|
||||||
|
|
||||||
// Call setData function of the contract
|
// Call setData function of the contract
|
||||||
const trxReceipt = await nftContract.methods.setTokenURI(tokenId,tokenURI).send({
|
const trxReceipt = await nftContract.methods.setTokenURI(tokenId, tokenURI).send({
|
||||||
from: address,
|
from: address,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
gasPrice: await getFairGasPrice(this.web3)
|
gasPrice: await getFairGasPrice(this.web3)
|
||||||
@ -1115,8 +1115,6 @@ export class Nft {
|
|||||||
return trxReceipt
|
return trxReceipt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** Get Owner
|
/** Get Owner
|
||||||
* @param {String} nftAddress erc721 contract adress
|
* @param {String} nftAddress erc721 contract adress
|
||||||
* @return {Promise<string>} string
|
* @return {Promise<string>} string
|
||||||
@ -1138,7 +1136,6 @@ export class Nft {
|
|||||||
return roles
|
return roles
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Get users Metadata, return Metadata details
|
/** Get users Metadata, return Metadata details
|
||||||
* @param {String} nftAddress erc721 contract adress
|
* @param {String} nftAddress erc721 contract adress
|
||||||
* @return {Promise<Objecta>}
|
* @return {Promise<Objecta>}
|
||||||
@ -1148,8 +1145,6 @@ export class Nft {
|
|||||||
return await nftContract.methods.getMetaData().call()
|
return await nftContract.methods.getMetaData().call()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** Get users ERC20Deployer role
|
/** Get users ERC20Deployer role
|
||||||
* @param {String} nftAddress erc721 contract adress
|
* @param {String} nftAddress erc721 contract adress
|
||||||
* @param {String} address user adress
|
* @param {String} address user adress
|
||||||
|
@ -127,7 +127,7 @@ describe('Datatoken', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#addMinter - should add user1 as minter, if nftDatatoken has ERC20Deployer permission', async () => {
|
it('#addMinter - should add user1 as minter, if user has ERC20Deployer permission', async () => {
|
||||||
assert((await nftDatatoken.isErc20Deployer(nftAddress, nftOwner)) === true)
|
assert((await nftDatatoken.isErc20Deployer(nftAddress, nftOwner)) === true)
|
||||||
assert((await datatoken.getDTPermissions(datatokenAddress, user1)).minter === false)
|
assert((await datatoken.getDTPermissions(datatokenAddress, user1)).minter === false)
|
||||||
|
|
||||||
@ -136,6 +136,20 @@ describe('Datatoken', () => {
|
|||||||
assert((await datatoken.getDTPermissions(datatokenAddress, user1)).minter === true)
|
assert((await datatoken.getDTPermissions(datatokenAddress, user1)).minter === true)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
it('#addMinter - should FAIL TO add user1 as minter, if user has ERC20Deployer permission', async () => {
|
||||||
|
assert((await nftDatatoken.isErc20Deployer(nftAddress,user3)) === false)
|
||||||
|
assert((await datatoken.getDTPermissions(datatokenAddress, user2)).minter === false)
|
||||||
|
|
||||||
|
try {
|
||||||
|
await datatoken.addMinter(datatokenAddress, user3, user2)
|
||||||
|
} catch(e) {
|
||||||
|
assert(e.message === 'Caller is not ERC20Deployer')
|
||||||
|
}
|
||||||
|
|
||||||
|
assert((await datatoken.getDTPermissions(datatokenAddress, user2)).minter === false)
|
||||||
|
})
|
||||||
|
|
||||||
it('#mint - should mint ERC20 datatoken to user1, if Minter', async () => {
|
it('#mint - should mint ERC20 datatoken to user1, if Minter', async () => {
|
||||||
assert((await datatoken.getDTPermissions(datatokenAddress, nftOwner)).minter === true)
|
assert((await datatoken.getDTPermissions(datatokenAddress, nftOwner)).minter === true)
|
||||||
await datatoken.mint(datatokenAddress, nftOwner, '10', user1)
|
await datatoken.mint(datatokenAddress, nftOwner, '10', user1)
|
||||||
@ -160,6 +174,25 @@ describe('Datatoken', () => {
|
|||||||
exchangeId = fre.events.NewFixedRate.returnValues[0]
|
exchangeId = fre.events.NewFixedRate.returnValues[0]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('#createFixedRate - should FAIL create FRE if NOT ERC20Deployer', async () => {
|
||||||
|
assert((await nftDatatoken.isErc20Deployer(nftAddress,user3)) === false)
|
||||||
|
const freParams: FreCreationParams = {
|
||||||
|
fixedRateAddress: contractHandler.fixedRateAddress,
|
||||||
|
baseTokenAddress: contractHandler.daiAddress,
|
||||||
|
owner: nftOwner,
|
||||||
|
marketFeeCollector: nftOwner,
|
||||||
|
baseTokenDecimals: 18,
|
||||||
|
dataTokenDecimals: 18,
|
||||||
|
fixedRate: web3.utils.toWei('1'),
|
||||||
|
marketFee: 1e15
|
||||||
|
}
|
||||||
|
try {await datatoken.createFixedRate(datatokenAddress, user3, freParams)}
|
||||||
|
catch(e) {
|
||||||
|
assert(e.message === 'User is not ERC20 Deployer')
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
it('#createDispenser - method creates a dispenser for the erc20DT', async () => {
|
it('#createDispenser - method creates a dispenser for the erc20DT', async () => {
|
||||||
const dispenserParams: DispenserParams = {
|
const dispenserParams: DispenserParams = {
|
||||||
maxTokens: '10',
|
maxTokens: '10',
|
||||||
@ -175,6 +208,36 @@ describe('Datatoken', () => {
|
|||||||
assert(dispenser !== null)
|
assert(dispenser !== null)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('#createDispenser - should FAIL to create a Dispenser if not ERC20 Deployer', async () => {
|
||||||
|
const dispenserParams: DispenserParams = {
|
||||||
|
maxTokens: '10',
|
||||||
|
maxBalance: '100'
|
||||||
|
}
|
||||||
|
assert((await nftDatatoken.isErc20Deployer(nftAddress,user3)) === false)
|
||||||
|
try {await datatoken.createDispenser(
|
||||||
|
datatokenAddress,
|
||||||
|
user2,
|
||||||
|
contractHandler.dispenserAddress,
|
||||||
|
dispenserParams
|
||||||
|
)} catch(e){
|
||||||
|
assert(e.message === 'User is not ERC20 Deployer')
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
it('#removeMinter - should FAIL to remove user1 as minter, if caller is NOT ERC20Deployer', async () => {
|
||||||
|
assert((await nftDatatoken.isErc20Deployer(nftAddress, user2)) === false)
|
||||||
|
assert((await datatoken.getDTPermissions(datatokenAddress, user1)).minter === true)
|
||||||
|
|
||||||
|
try{
|
||||||
|
await datatoken.removeMinter(datatokenAddress, user2, user1)
|
||||||
|
|
||||||
|
} catch(e) {
|
||||||
|
assert(e.message === 'Caller is not ERC20Deployer')
|
||||||
|
}
|
||||||
|
assert((await datatoken.getDTPermissions(datatokenAddress, user1)).minter === true)
|
||||||
|
})
|
||||||
|
|
||||||
it('#removeMinter - should remove user1 as minter, if nftDatatoken has ERC20Deployer permission', async () => {
|
it('#removeMinter - should remove user1 as minter, if nftDatatoken has ERC20Deployer permission', async () => {
|
||||||
assert((await nftDatatoken.isErc20Deployer(nftAddress, nftOwner)) === true)
|
assert((await nftDatatoken.isErc20Deployer(nftAddress, nftOwner)) === true)
|
||||||
assert((await datatoken.getDTPermissions(datatokenAddress, user1)).minter === true)
|
assert((await datatoken.getDTPermissions(datatokenAddress, user1)).minter === true)
|
||||||
@ -184,7 +247,23 @@ describe('Datatoken', () => {
|
|||||||
assert((await datatoken.getDTPermissions(datatokenAddress, user1)).minter === false)
|
assert((await datatoken.getDTPermissions(datatokenAddress, user1)).minter === false)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#addPaymentManager - should add user2 as paymentManager, if nftDatatoken has ERC20Deployer permission', async () => {
|
it('#addPaymentManager - should FAIL TO add user2 as paymentManager, if caller is NOT ERC20Deployer', async () => {
|
||||||
|
assert((await nftDatatoken.isErc20Deployer(nftAddress, user1)) === false)
|
||||||
|
assert(
|
||||||
|
(await datatoken.getDTPermissions(datatokenAddress, user2)).paymentManager === false
|
||||||
|
)
|
||||||
|
|
||||||
|
try {await datatoken.addPaymentManager(datatokenAddress, user1, user2)}
|
||||||
|
catch(e){
|
||||||
|
assert(e.message === 'Caller is not ERC20Deployer')
|
||||||
|
}
|
||||||
|
assert(
|
||||||
|
(await datatoken.getDTPermissions(datatokenAddress, user2)).paymentManager === false
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
it('#addPaymentManager - should add user2 as paymentManager, if caller has ERC20Deployer permission', async () => {
|
||||||
assert((await nftDatatoken.isErc20Deployer(nftAddress, nftOwner)) === true)
|
assert((await nftDatatoken.isErc20Deployer(nftAddress, nftOwner)) === true)
|
||||||
assert(
|
assert(
|
||||||
(await datatoken.getDTPermissions(datatokenAddress, user2)).paymentManager === false
|
(await datatoken.getDTPermissions(datatokenAddress, user2)).paymentManager === false
|
||||||
@ -197,7 +276,23 @@ describe('Datatoken', () => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#removePaymentManager - should remove user2 as paymentManager, if nftDatatoken has ERC20Deployer permission', async () => {
|
it('#removePaymentManager - should FAIL TO remove user2 as paymentManager, if nftDatatoken has ERC20Deployer permission', async () => {
|
||||||
|
assert((await nftDatatoken.isErc20Deployer(nftAddress, user1)) === false)
|
||||||
|
assert(
|
||||||
|
(await datatoken.getDTPermissions(datatokenAddress, user2)).paymentManager === true
|
||||||
|
)
|
||||||
|
try {await datatoken.removePaymentManager(datatokenAddress, user1, user2)} catch(e){
|
||||||
|
assert(e.message === 'Caller is not ERC20Deployer')
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
assert(
|
||||||
|
(await datatoken.getDTPermissions(datatokenAddress, user2)).paymentManager === true
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
it('#removePaymentManager - should remove user2 as paymentManager, if Caller has ERC20Deployer permission', async () => {
|
||||||
assert((await nftDatatoken.isErc20Deployer(nftAddress, nftOwner)) === true)
|
assert((await nftDatatoken.isErc20Deployer(nftAddress, nftOwner)) === true)
|
||||||
assert(
|
assert(
|
||||||
(await datatoken.getDTPermissions(datatokenAddress, user2)).paymentManager === true
|
(await datatoken.getDTPermissions(datatokenAddress, user2)).paymentManager === true
|
||||||
@ -312,6 +407,31 @@ describe('Datatoken', () => {
|
|||||||
assert(buyTx !== null)
|
assert(buyTx !== null)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// it('#cleanPermissions - should FAIL to clean permissions at ERC20 level, if NOT NFT Owner', async () => {
|
||||||
|
// assert((await datatoken.getDTPermissions(datatokenAddress, nftOwner)).minter === true)
|
||||||
|
|
||||||
|
// assert((await datatoken.getPaymentCollector(datatokenAddress)) === user3)
|
||||||
|
|
||||||
|
// assert(
|
||||||
|
// (await datatoken.getDTPermissions(datatokenAddress, user1)).paymentManager === true
|
||||||
|
// )
|
||||||
|
|
||||||
|
// try {await datatoken.cleanPermissions(datatokenAddress, nftOwner)} catch(e){
|
||||||
|
// assert(e.message === 'Caller is not NFTOwner')
|
||||||
|
// }
|
||||||
|
|
||||||
|
// assert((await datatoken.getPaymentCollector(datatokenAddress)) === nftOwner)
|
||||||
|
|
||||||
|
// assert(
|
||||||
|
// (await datatoken.getDTPermissions(datatokenAddress, nftOwner)).minter === false
|
||||||
|
// )
|
||||||
|
|
||||||
|
// assert(
|
||||||
|
// (await datatoken.getDTPermissions(datatokenAddress, user1)).paymentManager === false
|
||||||
|
// )
|
||||||
|
// })
|
||||||
|
|
||||||
|
|
||||||
it('#cleanPermissions - should clean permissions at ERC20 level', async () => {
|
it('#cleanPermissions - should clean permissions at ERC20 level', async () => {
|
||||||
assert((await datatoken.getDTPermissions(datatokenAddress, nftOwner)).minter === true)
|
assert((await datatoken.getDTPermissions(datatokenAddress, nftOwner)).minter === true)
|
||||||
|
|
||||||
@ -339,7 +459,8 @@ describe('Datatoken', () => {
|
|||||||
assert(address, 'Not able to get the parent ERC721 address')
|
assert(address, 'Not able to get the parent ERC721 address')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#setData - should set a value into 725Y standard, if nftDatatoken has ERC20Deployer permission', async () => {
|
|
||||||
|
it('#setData - should set a value into 725Y standard, if Caller has ERC20Deployer permission', async () => {
|
||||||
const data = web3.utils.asciiToHex('SomeData')
|
const data = web3.utils.asciiToHex('SomeData')
|
||||||
|
|
||||||
assert((await nftDatatoken.isErc20Deployer(nftAddress, nftOwner)) === true)
|
assert((await nftDatatoken.isErc20Deployer(nftAddress, nftOwner)) === true)
|
||||||
@ -349,4 +470,17 @@ describe('Datatoken', () => {
|
|||||||
const key = web3.utils.keccak256(datatokenAddress)
|
const key = web3.utils.keccak256(datatokenAddress)
|
||||||
assert((await nftDatatoken.getData(nftAddress, key)) === data)
|
assert((await nftDatatoken.getData(nftAddress, key)) === data)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('#setData - should FAIL to set a value into 725Y standard, if Caller has NOT ERC20Deployer permission', async () => {
|
||||||
|
const data = web3.utils.asciiToHex('NewData')
|
||||||
|
const OldData = web3.utils.asciiToHex('SomeData')
|
||||||
|
assert((await nftDatatoken.isErc20Deployer(nftAddress, user1)) === false)
|
||||||
|
|
||||||
|
try { await datatoken.setData(datatokenAddress, user1, data)} catch(e){
|
||||||
|
assert(e.message === 'User is not ERC20 Deployer')
|
||||||
|
}
|
||||||
|
const key = web3.utils.keccak256(datatokenAddress)
|
||||||
|
assert((await nftDatatoken.getData(nftAddress, key)) === OldData)
|
||||||
|
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@ -13,7 +13,7 @@ import { TestContractHandler } from '../../TestContractHandler'
|
|||||||
import { NftFactory, NftCreateData } from '../../../src/factories/NFTFactory'
|
import { NftFactory, NftCreateData } from '../../../src/factories/NFTFactory'
|
||||||
import { Nft } from '../../../src/tokens/NFT'
|
import { Nft } from '../../../src/tokens/NFT'
|
||||||
import { AbiItem } from 'web3-utils'
|
import { AbiItem } from 'web3-utils'
|
||||||
const constants = require("../../helpers/constants");
|
const constants = require('../../helpers/constants')
|
||||||
|
|
||||||
const web3 = new Web3('http://127.0.0.1:8545')
|
const web3 = new Web3('http://127.0.0.1:8545')
|
||||||
|
|
||||||
@ -98,7 +98,8 @@ describe('NFT', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('#createERC20 - should fail to create a new ERC20 DT if not ERC20Deployer', async () => {
|
it('#createERC20 - should fail to create a new ERC20 DT if not ERC20Deployer', async () => {
|
||||||
try{( await nftDatatoken.createErc20(
|
try {
|
||||||
|
await nftDatatoken.createErc20(
|
||||||
nftAddress,
|
nftAddress,
|
||||||
user1,
|
user1,
|
||||||
nftOwner,
|
nftOwner,
|
||||||
@ -110,14 +111,12 @@ describe('NFT', () => {
|
|||||||
nftName,
|
nftName,
|
||||||
nftSymbol,
|
nftSymbol,
|
||||||
1
|
1
|
||||||
)) }catch(e) {
|
)
|
||||||
|
} catch (e) {
|
||||||
assert(e.message === 'Caller is not ERC20Deployer')
|
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)
|
||||||
@ -242,10 +241,7 @@ describe('NFT', () => {
|
|||||||
try {
|
try {
|
||||||
await nftDatatoken.removeMetadataUpdater(nftAddress, user1, user1)
|
await nftDatatoken.removeMetadataUpdater(nftAddress, user1, user1)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
assert(
|
assert(e.message === 'Caller is not Manager nor Metadata Updater')
|
||||||
e.message ===
|
|
||||||
'Caller is not Manager nor Metadata Updater'
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -278,10 +274,7 @@ describe('NFT', () => {
|
|||||||
try {
|
try {
|
||||||
await nftDatatoken.removeStoreUpdater(nftAddress, user1, user1)
|
await nftDatatoken.removeStoreUpdater(nftAddress, user1, user1)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
assert(
|
assert(e.message === `Caller is not Manager nor storeUpdater`)
|
||||||
e.message ===
|
|
||||||
`Caller is not Manager nor storeUpdater`
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -332,36 +325,58 @@ describe('NFT', () => {
|
|||||||
it('#setMetaData - should succeed to update metadata if metadataUpdater', async () => {
|
it('#setMetaData - should succeed to update metadata if metadataUpdater', async () => {
|
||||||
await nftDatatoken.addManager(nftAddress, user1, user1)
|
await nftDatatoken.addManager(nftAddress, user1, user1)
|
||||||
await nftDatatoken.addMetadataUpdater(nftAddress, user1, user1)
|
await nftDatatoken.addMetadataUpdater(nftAddress, user1, user1)
|
||||||
const metaDataDecryptorUrl = 'http://myprovider:8030';
|
const metaDataDecryptorUrl = 'http://myprovider:8030'
|
||||||
const metaDataDecryptorAddress = "0x123";
|
const metaDataDecryptorAddress = '0x123'
|
||||||
const metaDataState = 1;
|
const metaDataState = 1
|
||||||
const data = web3.utils.asciiToHex(constants.blob[0]);
|
const data = web3.utils.asciiToHex(constants.blob[0])
|
||||||
const dataHash = web3.utils.asciiToHex(constants.blob[0]);
|
const dataHash = web3.utils.asciiToHex(constants.blob[0])
|
||||||
const flags = web3.utils.asciiToHex(constants.blob[0]);
|
const flags = web3.utils.asciiToHex(constants.blob[0])
|
||||||
assert((await nftDatatoken.getNftPermissions(nftAddress,user1)).updateMetadata === true)
|
assert(
|
||||||
await nftDatatoken.setMetadata(nftAddress, user1, metaDataState, metaDataDecryptorUrl, metaDataDecryptorAddress, flags, data, dataHash)
|
(await nftDatatoken.getNftPermissions(nftAddress, user1)).updateMetadata === true
|
||||||
// console.log((await nftDatatoken.getMetadata(nftAddress)),metaDataDecryptorUrl)
|
)
|
||||||
// console.log((await nftDatatoken.getMetadata(nftAddress)).metaDataDecryptorAddress,metaDataDecryptorAddress)
|
await nftDatatoken.setMetadata(
|
||||||
|
nftAddress,
|
||||||
|
user1,
|
||||||
|
metaDataState,
|
||||||
|
metaDataDecryptorUrl,
|
||||||
|
metaDataDecryptorAddress,
|
||||||
|
flags,
|
||||||
|
data,
|
||||||
|
dataHash
|
||||||
|
)
|
||||||
|
|
||||||
const metadata = await nftDatatoken.getMetadata(nftAddress)
|
const metadata = await nftDatatoken.getMetadata(nftAddress)
|
||||||
assert(metadata[0] === metaDataDecryptorUrl)
|
assert(metadata[0] === metaDataDecryptorUrl)
|
||||||
assert(metadata[1] === metaDataDecryptorAddress)
|
assert(metadata[1] === metaDataDecryptorAddress)
|
||||||
// assert((await nftDatatoken.getMetadata(nftAddress)).metaDataDecryptorAddress === metaDataDecryptorAddress)
|
// assert((await nftDatatoken.getMetadata(nftAddress)).metaDataDecryptorAddress === metaDataDecryptorAddress)
|
||||||
|
|
||||||
})
|
})
|
||||||
it('#setMetaData - should fail to update metadata if NOT metadataUpdater', async () => {
|
it('#setMetaData - should fail to update metadata if NOT metadataUpdater', async () => {
|
||||||
const metaDataDecryptorUrl = 'http://myprovider:8030';
|
const metaDataDecryptorUrl = 'http://myprovider:8030'
|
||||||
const metaDataDecryptorAddress = "0x123";
|
const metaDataDecryptorAddress = '0x123'
|
||||||
const metaDataState = 1;
|
const metaDataState = 1
|
||||||
const data = web3.utils.asciiToHex(constants.blob[0]);
|
const data = web3.utils.asciiToHex(constants.blob[0])
|
||||||
const dataHash = web3.utils.asciiToHex(constants.blob[0]);
|
const dataHash = web3.utils.asciiToHex(constants.blob[0])
|
||||||
const flags = web3.utils.asciiToHex(constants.blob[0]);
|
const flags = web3.utils.asciiToHex(constants.blob[0])
|
||||||
assert((await nftDatatoken.getNftPermissions(nftAddress,user3)).updateMetadata == false)
|
assert(
|
||||||
|
(await nftDatatoken.getNftPermissions(nftAddress, user3)).updateMetadata === false
|
||||||
|
)
|
||||||
try {
|
try {
|
||||||
await nftDatatoken.setMetadata(nftAddress, user3, metaDataState, metaDataDecryptorUrl, metaDataDecryptorAddress, flags, data, dataHash)
|
await nftDatatoken.setMetadata(
|
||||||
} catch(e) {
|
nftAddress,
|
||||||
|
user3,
|
||||||
|
metaDataState,
|
||||||
|
metaDataDecryptorUrl,
|
||||||
|
metaDataDecryptorAddress,
|
||||||
|
flags,
|
||||||
|
data,
|
||||||
|
dataHash
|
||||||
|
)
|
||||||
|
} catch (e) {
|
||||||
assert(e.message === 'Caller is not Metadata updater')
|
assert(e.message === 'Caller is not Metadata updater')
|
||||||
}
|
}
|
||||||
assert((await nftDatatoken.getNftPermissions(nftAddress,user3)).updateMetadata == false)
|
assert(
|
||||||
|
(await nftDatatoken.getNftPermissions(nftAddress, user3)).updateMetadata === false
|
||||||
|
)
|
||||||
})
|
})
|
||||||
it('#setMetaDataState - should succeed to update MetadataState if metadataUpdater', async () => {
|
it('#setMetaDataState - should succeed to update MetadataState if metadataUpdater', async () => {
|
||||||
await nftDatatoken.addManager(nftAddress, user1, user1)
|
await nftDatatoken.addManager(nftAddress, user1, user1)
|
||||||
@ -369,27 +384,28 @@ describe('NFT', () => {
|
|||||||
let metadata = await nftDatatoken.getMetadata(nftAddress)
|
let metadata = await nftDatatoken.getMetadata(nftAddress)
|
||||||
|
|
||||||
assert(metadata[2] === '1')
|
assert(metadata[2] === '1')
|
||||||
assert((await nftDatatoken.getNftPermissions(nftAddress,user1)).updateMetadata === true)
|
assert(
|
||||||
|
(await nftDatatoken.getNftPermissions(nftAddress, user1)).updateMetadata === true
|
||||||
|
)
|
||||||
|
|
||||||
await nftDatatoken.setMetadataState(nftAddress, user1,2)
|
await nftDatatoken.setMetadataState(nftAddress, user1, 2)
|
||||||
|
|
||||||
metadata = await nftDatatoken.getMetadata(nftAddress)
|
metadata = await nftDatatoken.getMetadata(nftAddress)
|
||||||
assert(metadata[2] === '2')
|
assert(metadata[2] === '2')
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#setMetaDataState - should fail to update MetadataState if NOT metadataUpdater', async () => {
|
it('#setMetaDataState - should fail to update MetadataState if NOT metadataUpdater', async () => {
|
||||||
let metadata = await nftDatatoken.getMetadata(nftAddress)
|
let metadata = await nftDatatoken.getMetadata(nftAddress)
|
||||||
assert(metadata[2] === '2')
|
assert(metadata[2] === '2')
|
||||||
assert((await nftDatatoken.getNftPermissions(nftAddress,user3)).updateMetadata === false)
|
assert(
|
||||||
|
(await nftDatatoken.getNftPermissions(nftAddress, user3)).updateMetadata === false
|
||||||
|
)
|
||||||
try {
|
try {
|
||||||
await nftDatatoken.setMetadataState(nftAddress, user3,1)
|
await nftDatatoken.setMetadataState(nftAddress, user3, 1)
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
assert(e.message === 'Caller is not Metadata updater')
|
assert(e.message === 'Caller is not Metadata updater')
|
||||||
}
|
}
|
||||||
metadata = await nftDatatoken.getMetadata(nftAddress)
|
metadata = await nftDatatoken.getMetadata(nftAddress)
|
||||||
assert(metadata[2] === '2')
|
assert(metadata[2] === '2')
|
||||||
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user