mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
setPaymentCollector apply same checking as contract (#1396)
* setPaymentCollector apply same checking as contract * unit test for setPaymentCollector for owner and erc20 deployer * setPaymentCollector amend redundent truth check on boolean value Co-authored-by: Soon Huat <soon_huat.phan@daimler.com>
This commit is contained in:
parent
58ced6cb61
commit
628c2fc1fc
@ -782,8 +782,15 @@ export class Datatoken {
|
||||
new this.web3.eth.Contract(this.datatokensAbi, dtAddress),
|
||||
this.config
|
||||
)
|
||||
if ((await this.getDTPermissions(dtAddress, address)).paymentManager !== true) {
|
||||
throw new Error(`Caller is not Fee Manager`)
|
||||
const isPaymentManager = (await this.getDTPermissions(dtAddress, address))
|
||||
.paymentManager
|
||||
const nftAddress = !isPaymentManager && (await this.getNFTAddress(dtAddress))
|
||||
const isNftOwner = nftAddress && (await this.nft.getNftOwner(nftAddress)) === address
|
||||
const nftPermissions =
|
||||
nftAddress && !isNftOwner && (await this.nft.getNftPermissions(nftAddress, address))
|
||||
const isErc20Deployer = nftPermissions?.deployERC20
|
||||
if (!isPaymentManager && !isNftOwner && !isErc20Deployer) {
|
||||
throw new Error(`Caller is not Fee Manager, owner or erc20 Deployer`)
|
||||
}
|
||||
|
||||
const estGas = await this.estGasSetPaymentCollector(
|
||||
|
@ -24,6 +24,7 @@ describe('Datatoken', () => {
|
||||
let user1: string
|
||||
let user2: string
|
||||
let user3: string
|
||||
let erc20DeployerUser: string
|
||||
let contracts: Addresses
|
||||
let nftDatatoken: Nft
|
||||
let datatoken: Datatoken
|
||||
@ -42,6 +43,7 @@ describe('Datatoken', () => {
|
||||
user1 = accounts[1]
|
||||
user2 = accounts[2]
|
||||
user3 = accounts[3]
|
||||
erc20DeployerUser = accounts[4]
|
||||
})
|
||||
|
||||
it('should deploy contracts', async () => {
|
||||
@ -76,7 +78,7 @@ describe('Datatoken', () => {
|
||||
})
|
||||
|
||||
it('#createERC20 - should create a new ERC20 DT from NFT contract', async () => {
|
||||
// await nftDatatoken.addERC20Deployer(nftAddress, nftOwner, nftOwner)
|
||||
await nftDatatoken.addErc20Deployer(nftAddress, nftOwner, erc20DeployerUser)
|
||||
datatokenAddress = await nftDatatoken.createErc20(
|
||||
nftAddress,
|
||||
nftOwner,
|
||||
@ -287,7 +289,7 @@ describe('Datatoken', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('#setPaymentCollector - should fail to set a new paymentCollector, if NOT PAYMENT Manager', async () => {
|
||||
it('#setPaymentCollector - should fail to set a new paymentCollector, if NOT PAYMENT Manager, NFT OWNER OR ERC 20 DEPLOYER', async () => {
|
||||
assert(
|
||||
(await datatoken.getDTPermissions(datatokenAddress, user2)).paymentManager === false
|
||||
)
|
||||
@ -295,7 +297,7 @@ describe('Datatoken', () => {
|
||||
try {
|
||||
await datatoken.setPaymentCollector(datatokenAddress, user1, user2)
|
||||
} catch (e) {
|
||||
assert(e.message === 'Caller is not Fee Manager')
|
||||
assert(e.message === 'Caller is not Fee Manager, owner or erc20 Deployer')
|
||||
}
|
||||
})
|
||||
|
||||
@ -313,6 +315,25 @@ describe('Datatoken', () => {
|
||||
assert((await datatoken.getPaymentCollector(datatokenAddress)) === user3)
|
||||
})
|
||||
|
||||
it('#setPaymentCollector - should set a new paymentCollector, if NFT OWNER', async () => {
|
||||
assert((await nftDatatoken.getNftOwner(nftAddress)) === nftOwner)
|
||||
|
||||
await datatoken.setPaymentCollector(datatokenAddress, nftOwner, user2)
|
||||
|
||||
assert((await datatoken.getPaymentCollector(datatokenAddress)) === user2)
|
||||
})
|
||||
|
||||
it('#setPaymentCollector - should set a new paymentCollector, if ERC 20 DEPLOYER', async () => {
|
||||
assert(
|
||||
(await nftDatatoken.getNftPermissions(nftAddress, erc20DeployerUser))
|
||||
.deployERC20 === true
|
||||
)
|
||||
|
||||
await datatoken.setPaymentCollector(datatokenAddress, erc20DeployerUser, user3)
|
||||
|
||||
assert((await datatoken.getPaymentCollector(datatokenAddress)) === user3)
|
||||
})
|
||||
|
||||
it('#startOrder- user2 should create an order for DT ', async () => {
|
||||
assert(
|
||||
(await datatoken.balance(datatokenAddress, user1)) === '10',
|
||||
|
Loading…
x
Reference in New Issue
Block a user