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: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: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: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'",
|
||||
|
@ -108,14 +108,14 @@ export class NftFactory {
|
||||
nftData.name = name
|
||||
nftData.symbol = symbol
|
||||
}
|
||||
if ( nftData.templateIndex > await this.getCurrentNFTTemplateCount()) {
|
||||
if (nftData.templateIndex > (await this.getCurrentNFTTemplateCount())) {
|
||||
throw new Error(`Template index doesnt exist`)
|
||||
}
|
||||
|
||||
if ( nftData.templateIndex === 0) {
|
||||
if (nftData.templateIndex === 0) {
|
||||
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`)
|
||||
}
|
||||
const estGas = await this.estGasCreateNFT(address, nftData)
|
||||
@ -189,11 +189,11 @@ export class NftFactory {
|
||||
* @return {Promise<Template>} Number of Template added to this factory
|
||||
*/
|
||||
public async getNFTTemplate(index: number): Promise<Template> {
|
||||
if ( index > await this.getCurrentNFTTemplateCount()) {
|
||||
if (index > (await this.getCurrentNFTTemplateCount())) {
|
||||
throw new Error(`Template index doesnt exist`)
|
||||
}
|
||||
|
||||
if ( index === 0) {
|
||||
if (index === 0) {
|
||||
throw new Error(`Template index cannot be ZERO`)
|
||||
}
|
||||
const template = await this.factory721.methods.getNFTTemplate(index).call()
|
||||
@ -262,7 +262,7 @@ export class NftFactory {
|
||||
if ((await this.getOwner()) !== address) {
|
||||
throw new Error(`Caller is not Factory Owner`)
|
||||
}
|
||||
if ( templateAddress === addressZERO) {
|
||||
if (templateAddress === addressZERO) {
|
||||
throw new Error(`Template cannot be ZERO address`)
|
||||
}
|
||||
|
||||
@ -315,11 +315,11 @@ 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.getCurrentNFTTemplateCount())) {
|
||||
throw new Error(`Template index doesnt exist`)
|
||||
}
|
||||
|
||||
if ( templateIndex === 0) {
|
||||
if (templateIndex === 0) {
|
||||
throw new Error(`Template index cannot be ZERO`)
|
||||
}
|
||||
const estGas = await this.estGasDisableNFTTemplate(address, templateIndex)
|
||||
@ -371,11 +371,11 @@ 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.getCurrentNFTTemplateCount())) {
|
||||
throw new Error(`Template index doesnt exist`)
|
||||
}
|
||||
|
||||
if ( templateIndex === 0) {
|
||||
if (templateIndex === 0) {
|
||||
throw new Error(`Template index cannot be ZERO`)
|
||||
}
|
||||
|
||||
@ -429,7 +429,7 @@ export class NftFactory {
|
||||
if ((await this.getOwner()) !== address) {
|
||||
throw new Error(`Caller is not Factory Owner`)
|
||||
}
|
||||
if ( templateAddress === addressZERO) {
|
||||
if (templateAddress === addressZERO) {
|
||||
throw new Error(`Template cannot be address ZERO`)
|
||||
}
|
||||
|
||||
@ -482,14 +482,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.getCurrentNFTTemplateCount())) {
|
||||
throw new Error(`Template index doesnt exist`)
|
||||
}
|
||||
|
||||
if ( templateIndex === 0) {
|
||||
if (templateIndex === 0) {
|
||||
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`)
|
||||
}
|
||||
const estGas = await this.estGasDisableTokenTemplate(address, templateIndex)
|
||||
@ -541,14 +541,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.getCurrentNFTTemplateCount())) {
|
||||
throw new Error(`Template index doesnt exist`)
|
||||
}
|
||||
|
||||
if ( templateIndex === 0) {
|
||||
if (templateIndex === 0) {
|
||||
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`)
|
||||
}
|
||||
|
||||
@ -575,9 +575,6 @@ export class NftFactory {
|
||||
address: string,
|
||||
orders: TokenOrder[]
|
||||
): Promise<any> {
|
||||
|
||||
|
||||
|
||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
||||
let estGas
|
||||
try {
|
||||
@ -606,7 +603,7 @@ export class NftFactory {
|
||||
address: string,
|
||||
orders: TokenOrder[]
|
||||
): Promise<TransactionReceipt> {
|
||||
if ( orders.length > 50) {
|
||||
if (orders.length > 50) {
|
||||
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 { LoggerInstance, getFairGasPrice } from '../utils'
|
||||
import { FreOrderParams, FreCreationParams } from '../interfaces'
|
||||
//import { Nft } from "./NFT"
|
||||
import { Nft } from "./NFT"
|
||||
/**
|
||||
* ERC20 ROLES
|
||||
*/
|
||||
@ -40,7 +40,7 @@ export class Datatoken {
|
||||
public datatokensEnterpriseAbi: AbiItem | AbiItem[]
|
||||
public web3: Web3
|
||||
public startBlock: number
|
||||
// public nft: Nft
|
||||
// public nft: Nft
|
||||
|
||||
/**
|
||||
* Instantiate ERC20 DataTokens
|
||||
@ -58,7 +58,7 @@ export class Datatoken {
|
||||
this.datatokensEnterpriseAbi =
|
||||
datatokensEnterpriseAbi || (defaultDatatokensEnterpriseAbi.abi as AbiItem[])
|
||||
this.startBlock = startBlock || 0
|
||||
// this.nft = new Nft(this.web3)
|
||||
// this.nft = new Nft(this.web3)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -225,7 +225,9 @@ export class Datatoken {
|
||||
fixedRateParams: FreCreationParams
|
||||
): Promise<TransactionReceipt> {
|
||||
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)
|
||||
fixedRateParams.allowedConsumer = '0x0000000000000000000000000000000000000000'
|
||||
|
||||
@ -323,8 +325,12 @@ export class Datatoken {
|
||||
dispenserAddress: string,
|
||||
dispenserParams: DispenserParams
|
||||
): Promise<TransactionReceipt> {
|
||||
const dtContract = new this.web3.eth.Contract(this.datatokensAbi, dtAddress)
|
||||
if (!await this.isERC20Deployer(dtAddress,address)) {
|
||||
throw new Error(`User is not ERC20 Deployer`)
|
||||
}
|
||||
|
||||
const dtContract = new this.web3.eth.Contract(this.datatokensAbi, dtAddress)
|
||||
|
||||
if (!dispenserParams.allowedSwapper)
|
||||
dispenserParams.allowedSwapper = '0x0000000000000000000000000000000000000000'
|
||||
|
||||
@ -446,7 +452,7 @@ export class Datatoken {
|
||||
): Promise<TransactionReceipt> {
|
||||
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`)
|
||||
}
|
||||
// Estimate gas cost for addMinter method
|
||||
@ -511,7 +517,7 @@ export class Datatoken {
|
||||
): Promise<TransactionReceipt> {
|
||||
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`)
|
||||
}
|
||||
|
||||
@ -573,7 +579,7 @@ export class Datatoken {
|
||||
): Promise<TransactionReceipt> {
|
||||
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`)
|
||||
}
|
||||
|
||||
@ -638,7 +644,7 @@ export class Datatoken {
|
||||
): Promise<TransactionReceipt> {
|
||||
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`)
|
||||
}
|
||||
|
||||
@ -1108,6 +1114,10 @@ export class Datatoken {
|
||||
address: string,
|
||||
value: string
|
||||
): 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 estGas = await this.estGasSetData(dtAddress, address, value, dtContract)
|
||||
@ -1122,7 +1132,6 @@ export class Datatoken {
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
|
||||
/** Estimate gas for cleanPermissions method
|
||||
* @param dtAddress Datatoken address where we want to clean permissions
|
||||
* @param address User adress
|
||||
@ -1162,7 +1171,7 @@ export class Datatoken {
|
||||
address: string
|
||||
): Promise<TransactionReceipt> {
|
||||
const dtContract = new this.web3.eth.Contract(this.datatokensAbi, dtAddress)
|
||||
|
||||
|
||||
const estGas = await this.estGasCleanPermissions(dtAddress, address, dtContract)
|
||||
|
||||
// Call cleanPermissions function of the contract
|
||||
@ -1221,9 +1230,9 @@ export class Datatoken {
|
||||
* @param {String} dtAddress Datatoken adress
|
||||
* @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 isERC20Deployer = await dtContract.methods.isERC20Deployer(adddress).call()
|
||||
const isERC20Deployer = await dtContract.methods.isERC20Deployer(address).call()
|
||||
return isERC20Deployer
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,6 @@ import defaultNftAbi from '@oceanprotocol/contracts/artifacts/contracts/template
|
||||
import { LoggerInstance, getFairGasPrice, generateDtName } from '../utils'
|
||||
import { Contract } from 'web3-eth-contract'
|
||||
|
||||
|
||||
/**
|
||||
* ERC721 ROLES
|
||||
*/
|
||||
@ -23,7 +22,7 @@ export class Nft {
|
||||
public nftAbi: AbiItem | AbiItem[]
|
||||
public web3: Web3
|
||||
public startBlock: number
|
||||
|
||||
|
||||
constructor(web3: Web3, nftAbi?: AbiItem | AbiItem[], startBlock?: number) {
|
||||
this.nftAbi = nftAbi || (defaultNftAbi.abi as AbiItem[])
|
||||
this.web3 = web3
|
||||
@ -118,7 +117,6 @@ export class Nft {
|
||||
;({ name, symbol } = generateDtName())
|
||||
}
|
||||
|
||||
|
||||
// Create 721contract object
|
||||
const nftContract = new this.web3.eth.Contract(this.nftAbi, nftAddress)
|
||||
|
||||
@ -385,9 +383,12 @@ 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 || address === erc20Deployer && (await this.getNftPermissions(nftAddress, address)).deployERC20 !== true) {
|
||||
|
||||
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(
|
||||
@ -517,8 +518,11 @@ export class Nft {
|
||||
): Promise<TransactionReceipt> {
|
||||
const nftContract = new this.web3.eth.Contract(this.nftAbi, nftAddress)
|
||||
|
||||
|
||||
if ((await this.getNftPermissions(nftAddress, address)).manager !== true || address !== metadataUpdater && (await this.getNftPermissions(nftAddress, address)).updateMetadata !== 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 nor Metadata Updater`)
|
||||
}
|
||||
|
||||
@ -555,8 +559,6 @@ export class Nft {
|
||||
storeUpdater: string,
|
||||
contractInstance?: Contract
|
||||
): Promise<any> {
|
||||
|
||||
|
||||
const nftContract =
|
||||
contractInstance || new this.web3.eth.Contract(this.nftAbi, nftAddress)
|
||||
|
||||
@ -586,8 +588,7 @@ export class Nft {
|
||||
): Promise<TransactionReceipt> {
|
||||
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`)
|
||||
}
|
||||
|
||||
@ -651,8 +652,11 @@ export class Nft {
|
||||
): Promise<TransactionReceipt> {
|
||||
const nftContract = new this.web3.eth.Contract(this.nftAbi, nftAddress)
|
||||
|
||||
|
||||
if ((await this.getNftPermissions(nftAddress, address)).manager !== true || address !== storeUpdater && (await this.getNftPermissions(nftAddress, address)).store !== 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 nor storeUpdater`)
|
||||
}
|
||||
|
||||
@ -908,7 +912,7 @@ export class Nft {
|
||||
): Promise<any> {
|
||||
const nftContract =
|
||||
contractInstance || new this.web3.eth.Contract(this.nftAbi, nftAddress)
|
||||
|
||||
|
||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
||||
let estGas
|
||||
try {
|
||||
@ -921,7 +925,7 @@ export class Nft {
|
||||
data,
|
||||
metadataHash
|
||||
)
|
||||
.estimateGas({ from: metadataUpdater}, (err, estGas) =>
|
||||
.estimateGas({ from: metadataUpdater }, (err, estGas) =>
|
||||
err ? gasLimitDefault : estGas
|
||||
)
|
||||
} catch (e) {
|
||||
@ -985,7 +989,7 @@ export class Nft {
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Estimate gas cost for setMetadataState method
|
||||
* @param {String} nftAddress erc721 contract adress
|
||||
* @param {String} nftOwner Current NFT Owner adress
|
||||
@ -993,129 +997,123 @@ export class Nft {
|
||||
* @param {Contract} nftContract optional contract instance
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
public async estGasSetMetadataState(
|
||||
nftAddress: string,
|
||||
metadataUpdater: string,
|
||||
metadataState: number,
|
||||
contractInstance?: Contract
|
||||
): Promise<any> {
|
||||
const nftContract =
|
||||
contractInstance || new this.web3.eth.Contract(this.nftAbi, nftAddress)
|
||||
|
||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
||||
let estGas
|
||||
try {
|
||||
estGas = await nftContract.methods
|
||||
.setMetaDataState(
|
||||
metadataState
|
||||
)
|
||||
.estimateGas({ from: metadataUpdater }, (err, estGas) =>
|
||||
err ? gasLimitDefault : estGas
|
||||
)
|
||||
} catch (e) {
|
||||
estGas = gasLimitDefault
|
||||
}
|
||||
|
||||
return estGas
|
||||
}
|
||||
|
||||
/**
|
||||
* setMetadataState Used for updating the metadata State
|
||||
* @param {String} nftAddress erc721 contract adress
|
||||
* @param {String} address Caller address => metadata updater
|
||||
* @param {Number} metadataState new metadata state
|
||||
* @return {Promise<TransactionReceipt>} trxReceipt
|
||||
*/
|
||||
public async setMetadataState(
|
||||
nftAddress: string,
|
||||
address: string,
|
||||
metadataState: number
|
||||
): Promise<TransactionReceipt> {
|
||||
const nftContract = new this.web3.eth.Contract(this.nftAbi, nftAddress)
|
||||
|
||||
if (!(await this.getNftPermissions(nftAddress, address)).updateMetadata) {
|
||||
throw new Error(`Caller is not Metadata updater`)
|
||||
}
|
||||
|
||||
const estGas = await this.estGasSetMetadataState(
|
||||
nftAddress,
|
||||
address,
|
||||
metadataState
|
||||
)
|
||||
|
||||
// Call transferFrom function of the contract
|
||||
const trxReceipt = await nftContract.methods
|
||||
.setMetaDataState(
|
||||
metadataState
|
||||
public async estGasSetMetadataState(
|
||||
nftAddress: string,
|
||||
metadataUpdater: string,
|
||||
metadataState: number,
|
||||
contractInstance?: Contract
|
||||
): Promise<any> {
|
||||
const nftContract =
|
||||
contractInstance || new this.web3.eth.Contract(this.nftAbi, nftAddress)
|
||||
|
||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
||||
let estGas
|
||||
try {
|
||||
estGas = await nftContract.methods
|
||||
.setMetaDataState(metadataState)
|
||||
.estimateGas({ from: metadataUpdater }, (err, estGas) =>
|
||||
err ? gasLimitDefault : estGas
|
||||
)
|
||||
.send({
|
||||
from: address,
|
||||
gas: estGas + 1,
|
||||
gasPrice: await getFairGasPrice(this.web3)
|
||||
})
|
||||
|
||||
return trxReceipt
|
||||
} catch (e) {
|
||||
estGas = gasLimitDefault
|
||||
}
|
||||
|
||||
/** Estimate gas for setTokenURI method
|
||||
return estGas
|
||||
}
|
||||
|
||||
/**
|
||||
* setMetadataState Used for updating the metadata State
|
||||
* @param {String} nftAddress erc721 contract adress
|
||||
* @param {String} address Caller address => metadata updater
|
||||
* @param {Number} metadataState new metadata state
|
||||
* @return {Promise<TransactionReceipt>} trxReceipt
|
||||
*/
|
||||
public async setMetadataState(
|
||||
nftAddress: string,
|
||||
address: string,
|
||||
metadataState: number
|
||||
): Promise<TransactionReceipt> {
|
||||
const nftContract = new this.web3.eth.Contract(this.nftAbi, nftAddress)
|
||||
|
||||
if (!(await this.getNftPermissions(nftAddress, address)).updateMetadata) {
|
||||
throw new Error(`Caller is not Metadata updater`)
|
||||
}
|
||||
|
||||
const estGas = await this.estGasSetMetadataState(nftAddress, address, metadataState)
|
||||
|
||||
// Call transferFrom function of the contract
|
||||
const trxReceipt = await nftContract.methods.setMetaDataState(metadataState).send({
|
||||
from: address,
|
||||
gas: estGas + 1,
|
||||
gasPrice: await getFairGasPrice(this.web3)
|
||||
})
|
||||
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
/** Estimate gas for setTokenURI method
|
||||
* @param {String} dtAddress Datatoken address
|
||||
* @param {String} address User address
|
||||
* @param {Contract} contractInstance optional contract instance
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
public async estGasSetTokenURI(
|
||||
nftAddress: string,
|
||||
address: string,
|
||||
tokenId: number,
|
||||
tokenURI: string,
|
||||
contractInstance?: Contract
|
||||
): Promise<any> {
|
||||
const dtContract =
|
||||
contractInstance || new this.web3.eth.Contract(this.nftAbi, nftAddress)
|
||||
|
||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
||||
let estGas
|
||||
try {
|
||||
estGas = await dtContract.methods
|
||||
.setTokenURI(tokenId,tokenURI)
|
||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
||||
} catch (e) {
|
||||
estGas = gasLimitDefault
|
||||
}
|
||||
return estGas
|
||||
}
|
||||
|
||||
/** setTokenURI
|
||||
* This function allows to update the token URI
|
||||
* only NFT Owner can succeed
|
||||
* @param {String} nftAddress Datatoken address
|
||||
* @param {String} address User address
|
||||
* @return {Promise<TransactionReceipt>} transactionId
|
||||
*/
|
||||
public async setTokenURI(
|
||||
nftAddress: string,
|
||||
address: string,
|
||||
tokenURI: string
|
||||
): Promise<TransactionReceipt> {
|
||||
if (await this.getNftOwner(nftAddress) !== address) {
|
||||
throw new Error(`Caller is not NFT Owner`)
|
||||
}
|
||||
const tokenId = 1;
|
||||
|
||||
const nftContract = new this.web3.eth.Contract(this.nftAbi, nftAddress)
|
||||
const estGas = await this.estGasSetTokenURI(nftAddress, address, tokenId,tokenURI, nftContract)
|
||||
|
||||
// Call setData function of the contract
|
||||
const trxReceipt = await nftContract.methods.setTokenURI(tokenId,tokenURI).send({
|
||||
from: address,
|
||||
gas: estGas + 1,
|
||||
gasPrice: await getFairGasPrice(this.web3)
|
||||
})
|
||||
|
||||
return trxReceipt
|
||||
}
|
||||
public async estGasSetTokenURI(
|
||||
nftAddress: string,
|
||||
address: string,
|
||||
tokenId: number,
|
||||
tokenURI: string,
|
||||
contractInstance?: Contract
|
||||
): Promise<any> {
|
||||
const dtContract =
|
||||
contractInstance || new this.web3.eth.Contract(this.nftAbi, nftAddress)
|
||||
|
||||
|
||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
||||
let estGas
|
||||
try {
|
||||
estGas = await dtContract.methods
|
||||
.setTokenURI(tokenId, tokenURI)
|
||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
||||
} catch (e) {
|
||||
estGas = gasLimitDefault
|
||||
}
|
||||
return estGas
|
||||
}
|
||||
|
||||
/** setTokenURI
|
||||
* This function allows to update the token URI
|
||||
* only NFT Owner can succeed
|
||||
* @param {String} nftAddress Datatoken address
|
||||
* @param {String} address User address
|
||||
* @return {Promise<TransactionReceipt>} transactionId
|
||||
*/
|
||||
public async setTokenURI(
|
||||
nftAddress: string,
|
||||
address: string,
|
||||
tokenURI: string
|
||||
): Promise<TransactionReceipt> {
|
||||
if ((await this.getNftOwner(nftAddress)) !== address) {
|
||||
throw new Error(`Caller is not NFT Owner`)
|
||||
}
|
||||
const tokenId = 1
|
||||
|
||||
const nftContract = new this.web3.eth.Contract(this.nftAbi, nftAddress)
|
||||
const estGas = await this.estGasSetTokenURI(
|
||||
nftAddress,
|
||||
address,
|
||||
tokenId,
|
||||
tokenURI,
|
||||
nftContract
|
||||
)
|
||||
|
||||
// Call setData function of the contract
|
||||
const trxReceipt = await nftContract.methods.setTokenURI(tokenId, tokenURI).send({
|
||||
from: address,
|
||||
gas: estGas + 1,
|
||||
gasPrice: await getFairGasPrice(this.web3)
|
||||
})
|
||||
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
/** Get Owner
|
||||
* @param {String} nftAddress erc721 contract adress
|
||||
@ -1138,17 +1136,14 @@ export class Nft {
|
||||
return roles
|
||||
}
|
||||
|
||||
|
||||
/** Get users Metadata, return Metadata details
|
||||
/** Get users Metadata, return Metadata details
|
||||
* @param {String} nftAddress erc721 contract adress
|
||||
* @return {Promise<Objecta>}
|
||||
*/
|
||||
public async getMetadata(nftAddress: string): Promise<Object> {
|
||||
const nftContract = new this.web3.eth.Contract(this.nftAbi, nftAddress)
|
||||
return await nftContract.methods.getMetaData().call()
|
||||
}
|
||||
|
||||
|
||||
public async getMetadata(nftAddress: string): Promise<Object> {
|
||||
const nftContract = new this.web3.eth.Contract(this.nftAbi, nftAddress)
|
||||
return await nftContract.methods.getMetaData().call()
|
||||
}
|
||||
|
||||
/** Get users ERC20Deployer role
|
||||
* @param {String} nftAddress erc721 contract 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 datatoken.getDTPermissions(datatokenAddress, user1)).minter === false)
|
||||
|
||||
@ -136,6 +136,20 @@ describe('Datatoken', () => {
|
||||
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 () => {
|
||||
assert((await datatoken.getDTPermissions(datatokenAddress, nftOwner)).minter === true)
|
||||
await datatoken.mint(datatokenAddress, nftOwner, '10', user1)
|
||||
@ -160,6 +174,25 @@ describe('Datatoken', () => {
|
||||
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 () => {
|
||||
const dispenserParams: DispenserParams = {
|
||||
maxTokens: '10',
|
||||
@ -175,6 +208,36 @@ describe('Datatoken', () => {
|
||||
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 () => {
|
||||
assert((await nftDatatoken.isErc20Deployer(nftAddress, nftOwner)) === true)
|
||||
assert((await datatoken.getDTPermissions(datatokenAddress, user1)).minter === true)
|
||||
@ -184,7 +247,23 @@ describe('Datatoken', () => {
|
||||
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 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 datatoken.getDTPermissions(datatokenAddress, user2)).paymentManager === true
|
||||
@ -312,6 +407,31 @@ describe('Datatoken', () => {
|
||||
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 () => {
|
||||
assert((await datatoken.getDTPermissions(datatokenAddress, nftOwner)).minter === true)
|
||||
|
||||
@ -338,8 +458,9 @@ describe('Datatoken', () => {
|
||||
const address = await datatoken.getNFTAddress(datatokenAddress)
|
||||
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')
|
||||
|
||||
assert((await nftDatatoken.isErc20Deployer(nftAddress, nftOwner)) === true)
|
||||
@ -349,4 +470,17 @@ describe('Datatoken', () => {
|
||||
const key = web3.utils.keccak256(datatokenAddress)
|
||||
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 { Nft } from '../../../src/tokens/NFT'
|
||||
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')
|
||||
|
||||
@ -98,26 +98,25 @@ describe('NFT', () => {
|
||||
})
|
||||
|
||||
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) {
|
||||
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)
|
||||
@ -242,10 +241,7 @@ describe('NFT', () => {
|
||||
try {
|
||||
await nftDatatoken.removeMetadataUpdater(nftAddress, user1, user1)
|
||||
} catch (e) {
|
||||
assert(
|
||||
e.message ===
|
||||
'Caller is not Manager nor Metadata Updater'
|
||||
)
|
||||
assert(e.message === 'Caller is not Manager nor Metadata Updater')
|
||||
}
|
||||
})
|
||||
|
||||
@ -278,10 +274,7 @@ describe('NFT', () => {
|
||||
try {
|
||||
await nftDatatoken.removeStoreUpdater(nftAddress, user1, user1)
|
||||
} catch (e) {
|
||||
assert(
|
||||
e.message ===
|
||||
`Caller is not Manager nor storeUpdater`
|
||||
)
|
||||
assert(e.message === `Caller is not Manager nor storeUpdater`)
|
||||
}
|
||||
})
|
||||
|
||||
@ -332,64 +325,87 @@ describe('NFT', () => {
|
||||
it('#setMetaData - should succeed to update metadata if metadataUpdater', async () => {
|
||||
await nftDatatoken.addManager(nftAddress, user1, user1)
|
||||
await nftDatatoken.addMetadataUpdater(nftAddress, user1, user1)
|
||||
const metaDataDecryptorUrl = 'http://myprovider:8030';
|
||||
const metaDataDecryptorAddress = "0x123";
|
||||
const metaDataState = 1;
|
||||
const data = web3.utils.asciiToHex(constants.blob[0]);
|
||||
const dataHash = web3.utils.asciiToHex(constants.blob[0]);
|
||||
const flags = web3.utils.asciiToHex(constants.blob[0]);
|
||||
assert((await nftDatatoken.getNftPermissions(nftAddress,user1)).updateMetadata === true)
|
||||
await nftDatatoken.setMetadata(nftAddress, user1, metaDataState, metaDataDecryptorUrl, metaDataDecryptorAddress, flags, data, dataHash)
|
||||
// console.log((await nftDatatoken.getMetadata(nftAddress)),metaDataDecryptorUrl)
|
||||
// console.log((await nftDatatoken.getMetadata(nftAddress)).metaDataDecryptorAddress,metaDataDecryptorAddress)
|
||||
const metaDataDecryptorUrl = 'http://myprovider:8030'
|
||||
const metaDataDecryptorAddress = '0x123'
|
||||
const metaDataState = 1
|
||||
const data = web3.utils.asciiToHex(constants.blob[0])
|
||||
const dataHash = web3.utils.asciiToHex(constants.blob[0])
|
||||
const flags = web3.utils.asciiToHex(constants.blob[0])
|
||||
assert(
|
||||
(await nftDatatoken.getNftPermissions(nftAddress, user1)).updateMetadata === true
|
||||
)
|
||||
await nftDatatoken.setMetadata(
|
||||
nftAddress,
|
||||
user1,
|
||||
metaDataState,
|
||||
metaDataDecryptorUrl,
|
||||
metaDataDecryptorAddress,
|
||||
flags,
|
||||
data,
|
||||
dataHash
|
||||
)
|
||||
|
||||
const metadata = await nftDatatoken.getMetadata(nftAddress)
|
||||
assert(metadata[0] === metaDataDecryptorUrl)
|
||||
assert(metadata[0] === metaDataDecryptorUrl)
|
||||
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 () => {
|
||||
const metaDataDecryptorUrl = 'http://myprovider:8030';
|
||||
const metaDataDecryptorAddress = "0x123";
|
||||
const metaDataState = 1;
|
||||
const data = web3.utils.asciiToHex(constants.blob[0]);
|
||||
const dataHash = web3.utils.asciiToHex(constants.blob[0]);
|
||||
const flags = web3.utils.asciiToHex(constants.blob[0]);
|
||||
assert((await nftDatatoken.getNftPermissions(nftAddress,user3)).updateMetadata == false)
|
||||
try {
|
||||
await nftDatatoken.setMetadata(nftAddress, user3, metaDataState, metaDataDecryptorUrl, metaDataDecryptorAddress, flags, data, dataHash)
|
||||
} catch(e) {
|
||||
assert(e.message === 'Caller is not Metadata updater')
|
||||
}
|
||||
assert((await nftDatatoken.getNftPermissions(nftAddress,user3)).updateMetadata == false)
|
||||
const metaDataDecryptorUrl = 'http://myprovider:8030'
|
||||
const metaDataDecryptorAddress = '0x123'
|
||||
const metaDataState = 1
|
||||
const data = web3.utils.asciiToHex(constants.blob[0])
|
||||
const dataHash = web3.utils.asciiToHex(constants.blob[0])
|
||||
const flags = web3.utils.asciiToHex(constants.blob[0])
|
||||
assert(
|
||||
(await nftDatatoken.getNftPermissions(nftAddress, user3)).updateMetadata === false
|
||||
)
|
||||
try {
|
||||
await nftDatatoken.setMetadata(
|
||||
nftAddress,
|
||||
user3,
|
||||
metaDataState,
|
||||
metaDataDecryptorUrl,
|
||||
metaDataDecryptorAddress,
|
||||
flags,
|
||||
data,
|
||||
dataHash
|
||||
)
|
||||
} catch (e) {
|
||||
assert(e.message === 'Caller is not Metadata updater')
|
||||
}
|
||||
assert(
|
||||
(await nftDatatoken.getNftPermissions(nftAddress, user3)).updateMetadata === false
|
||||
)
|
||||
})
|
||||
it('#setMetaDataState - should succeed to update MetadataState if metadataUpdater', async () => {
|
||||
await nftDatatoken.addManager(nftAddress, user1, user1)
|
||||
await nftDatatoken.addMetadataUpdater(nftAddress, user1, user1)
|
||||
let metadata = await nftDatatoken.getMetadata(nftAddress)
|
||||
|
||||
assert(metadata[2] === '1')
|
||||
assert((await nftDatatoken.getNftPermissions(nftAddress,user1)).updateMetadata === true)
|
||||
|
||||
await nftDatatoken.setMetadataState(nftAddress, user1,2)
|
||||
|
||||
assert(metadata[2] === '1')
|
||||
assert(
|
||||
(await nftDatatoken.getNftPermissions(nftAddress, user1)).updateMetadata === true
|
||||
)
|
||||
|
||||
await nftDatatoken.setMetadataState(nftAddress, user1, 2)
|
||||
|
||||
metadata = await nftDatatoken.getMetadata(nftAddress)
|
||||
assert(metadata[2] === '2')
|
||||
|
||||
|
||||
assert(metadata[2] === '2')
|
||||
})
|
||||
|
||||
it('#setMetaDataState - should fail to update MetadataState if NOT metadataUpdater', async () => {
|
||||
let metadata = await nftDatatoken.getMetadata(nftAddress)
|
||||
assert(metadata[2] === '2')
|
||||
assert((await nftDatatoken.getNftPermissions(nftAddress,user3)).updateMetadata === false)
|
||||
assert(metadata[2] === '2')
|
||||
assert(
|
||||
(await nftDatatoken.getNftPermissions(nftAddress, user3)).updateMetadata === false
|
||||
)
|
||||
try {
|
||||
await nftDatatoken.setMetadataState(nftAddress, user3,1)
|
||||
} catch(e) {
|
||||
assert(e.message === 'Caller is not Metadata updater')
|
||||
}
|
||||
await nftDatatoken.setMetadataState(nftAddress, user3, 1)
|
||||
} catch (e) {
|
||||
assert(e.message === 'Caller is not Metadata updater')
|
||||
}
|
||||
metadata = await nftDatatoken.getMetadata(nftAddress)
|
||||
assert(metadata[2] === '2')
|
||||
|
||||
assert(metadata[2] === '2')
|
||||
})
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user