mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
fixed rest of dispenser unit tests
This commit is contained in:
parent
54e198c30a
commit
aa9c02af3f
@ -338,8 +338,6 @@ export class Datatoken {
|
|||||||
dtContract
|
dtContract
|
||||||
)
|
)
|
||||||
|
|
||||||
console.log('dispenserParams', dispenserParams)
|
|
||||||
|
|
||||||
// Call createFixedRate contract method
|
// Call createFixedRate contract method
|
||||||
const trxReceipt = await dtContract.methods
|
const trxReceipt = await dtContract.methods
|
||||||
.createDispenser(
|
.createDispenser(
|
||||||
|
@ -13,8 +13,7 @@ export interface DispenserToken {
|
|||||||
maxTokens: string
|
maxTokens: string
|
||||||
maxBalance: string
|
maxBalance: string
|
||||||
balance: string
|
balance: string
|
||||||
minterApproved: boolean
|
isMinter: boolean
|
||||||
isTrueMinter: boolean
|
|
||||||
allowedSwapper: string
|
allowedSwapper: string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -436,7 +435,7 @@ export class Dispenser {
|
|||||||
if (new Decimal(String(amount)).greaterThan(status.maxTokens)) return false
|
if (new Decimal(String(amount)).greaterThan(status.maxTokens)) return false
|
||||||
// check dispenser balance
|
// check dispenser balance
|
||||||
const contractBalance = new Decimal(status.balance)
|
const contractBalance = new Decimal(status.balance)
|
||||||
if (contractBalance.greaterThanOrEqualTo(amount) || status.isTrueMinter === true)
|
if (contractBalance.greaterThanOrEqualTo(amount) || status.isMinter === true)
|
||||||
return true
|
return true
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -140,39 +140,49 @@ describe('Dispenser flow', () => {
|
|||||||
const status = await DispenserClass.status(dtAddress)
|
const status = await DispenserClass.status(dtAddress)
|
||||||
assert(status.active === true, 'Dispenser not active')
|
assert(status.active === true, 'Dispenser not active')
|
||||||
assert(status.owner === contracts.accounts[0], 'Dispenser owner is not alice')
|
assert(status.owner === contracts.accounts[0], 'Dispenser owner is not alice')
|
||||||
assert(status.minterApproved === true, 'Dispenser is not a minter')
|
assert(status.isMinter === true, 'Dispenser is not a minter')
|
||||||
})
|
})
|
||||||
|
|
||||||
// it('user2 deactivates the dispenser', async () => {
|
it('user2 deactivates the dispenser', async () => {
|
||||||
// const tx = await DispenserClass.deactivate(dtAddress, user2)
|
const tx = await DispenserClass.deactivate(dtAddress, contracts.accounts[0])
|
||||||
// assert(tx, 'Cannot deactivate dispenser')
|
assert(tx, 'Cannot deactivate dispenser')
|
||||||
// const status = await DispenserClass.status(dtAddress)
|
const status = await DispenserClass.status(dtAddress)
|
||||||
// assert(status.active === false, 'Dispenser is still active')
|
assert(status.active === false, 'Dispenser is still active')
|
||||||
// })
|
})
|
||||||
|
|
||||||
// it('user2 sets user3 as an AllowedSwapper for the dispenser', async () => {
|
it('user2 sets user3 as an AllowedSwapper for the dispenser', async () => {
|
||||||
// const tx = await DispenserClass.setAllowedSwapper(dtAddress, user2, user3)
|
const tx = await DispenserClass.setAllowedSwapper(
|
||||||
// assert(tx, 'Cannot deactivate dispenser')
|
dtAddress,
|
||||||
// const status = await DispenserClass.status(dtAddress)
|
contracts.accounts[0],
|
||||||
// assert(status.allowedSwapper === user3, 'Dispenser is still active')
|
user3
|
||||||
// })
|
)
|
||||||
|
assert(tx, 'Cannot set Allowed Swapper')
|
||||||
|
const status = await DispenserClass.status(dtAddress)
|
||||||
|
assert(status.allowedSwapper === user3, 'user3 is Allowed Swapper')
|
||||||
|
})
|
||||||
|
|
||||||
// it('User3 requests datatokens', async () => {
|
it('User3 requests datatokens', async () => {
|
||||||
// const check = await DispenserClass.isDispensable(dtAddress, datatoken, user3, '1')
|
const activate = await DispenserClass.activate(
|
||||||
// assert(check === true, 'isDispensable should return true')
|
dtAddress,
|
||||||
// const tx = await DispenserClass.dispense(dtAddress, user3, '1', user3)
|
'10',
|
||||||
// assert(tx, 'user3 failed to get 1DT')
|
'10',
|
||||||
// })
|
contracts.accounts[0]
|
||||||
|
)
|
||||||
|
const check = await DispenserClass.isDispensable(dtAddress, datatoken, user3, '1')
|
||||||
|
assert(check === true, 'isDispensable should return true')
|
||||||
|
const tx = await DispenserClass.dispense(dtAddress, user3, '1', user3)
|
||||||
|
assert(tx, 'user3 failed to get 1DT')
|
||||||
|
})
|
||||||
|
|
||||||
// it('tries to withdraw all datatokens', async () => {
|
it('tries to withdraw all datatokens', async () => {
|
||||||
// const tx = await DispenserClass.ownerWithdraw(dtAddress, user3)
|
const tx = await DispenserClass.ownerWithdraw(dtAddress, user3)
|
||||||
// assert(tx === null, 'Request should fail')
|
assert(tx === null, 'Request should fail')
|
||||||
// })
|
})
|
||||||
|
|
||||||
// it('user2 withdraws all datatokens', async () => {
|
it('user2 withdraws all datatokens', async () => {
|
||||||
// const tx = await DispenserClass.ownerWithdraw(dtAddress, user2)
|
const tx = await DispenserClass.ownerWithdraw(dtAddress, contracts.accounts[0])
|
||||||
// assert(tx, 'user2 failed to withdraw all her tokens')
|
assert(tx, 'user2 failed to withdraw all her tokens')
|
||||||
// const status = await DispenserClass.status(dtAddress)
|
const status = await DispenserClass.status(dtAddress)
|
||||||
// assert(status.balance === '0', 'Balance > 0')
|
assert(status.balance === '0', 'Balance > 0')
|
||||||
// })
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user