Fixed ending tests. Removed commented code. Brought back test suite.

This commit is contained in:
Maria Carmina 2023-04-26 00:22:41 +03:00
parent 2838822dfe
commit c24e720983
4 changed files with 121 additions and 139 deletions

View File

@ -70,9 +70,7 @@ jobs:
env:
ADDRESS_FILE: /home/runner/.ocean/ocean-contracts/artifacts/address.json
BARGE_FOLDER: /home/runner/.ocean/
- run: |
npm run test-ve
npm run test-zend
- run: npm run test-integration
env:
ADDRESS_FILE: /home/runner/.ocean/ocean-contracts/artifacts/address.json
BARGE_FOLDER: /home/runner/.ocean/

View File

@ -138,20 +138,6 @@ export function getveDelegation(
return veDelegation
}
}
// if (veDelegation === null) {
// veDelegation = new VeDelegation(id)
// veDelegation.cancelTime = BigInt.zero()
// veDelegation.expireTime = BigInt.zero()
// veDelegation.tokenId = BigInt.zero()
// veDelegation.amount = BigInt.zero()
// veDelegation.receiver = ''
// veDelegation.delegator = ''
// veDelegation.block = 0
// veDelegation.timestamp = 0
// veDelegation.tx = ''
// veDelegation.save()
// }
return null
}

View File

@ -105,7 +105,7 @@ const minAbi = [
describe('veOcean tests', async () => {
let nftFactory
let veOcean: VeOcean
// let delegateContract
let delegateContract
let veAllocate: VeAllocate
let veFeeDistributor: VeFeeDistributor
let ownerAccount: string
@ -122,10 +122,10 @@ describe('veOcean tests', async () => {
ownerAccount = accounts[0]
Alice = accounts[1]
Bob = accounts[2]
// delegateContract = new web3.eth.Contract(
// veDelegation.abi as AbiItem[],
// addresses.veDelegation
// )
delegateContract = new web3.eth.Contract(
veDelegation.abi as AbiItem[],
addresses.veDelegation
)
const tokenContract = new web3.eth.Contract(minAbi, addresses.Ocean)
const estGas = await calculateEstimatedGas(
@ -602,128 +602,128 @@ describe('veOcean tests', async () => {
)
})
// it('Alice should lock 100 Ocean and Delegate them to Bob', async () => {
// // since we can only lock once, we test if tx fails or not
// // so if there is already a lock, skip it
// let currentBalance = await veOcean.getLockedAmount(Alice)
// let currentLock = await veOcean.lockEnd(Alice)
// const amount = '100'
// await approve(
// web3,
// config,
// Alice,
// addresses.Ocean,
// addresses.veOCEAN,
// amount
// )
// const timestamp = Math.floor(Date.now() / 1000)
// const unlockTime = timestamp + 30 * 86400
it('Alice should lock 100 Ocean and Delegate them to Bob', async () => {
// since we can only lock once, we test if tx fails or not
// so if there is already a lock, skip it
let currentBalance = await veOcean.getLockedAmount(Alice)
let currentLock = await veOcean.lockEnd(Alice)
const amount = '100'
await approve(
web3,
config,
Alice,
addresses.Ocean,
addresses.veOCEAN,
amount
)
const timestamp = Math.floor(Date.now() / 1000)
const unlockTime = timestamp + 30 * 86400
// if (parseInt(currentBalance) > 0 || currentLock > 0) {
// // we already have some locked tokens, so our transaction should fail
// try {
// await veOcean.lockTokens(Alice, amount, unlockTime)
// assert(false, 'This should fail!')
// } catch (e) {
// // do nothing
// }
// } else {
// await veOcean.lockTokens(Alice, amount, unlockTime)
// }
// currentBalance = await veOcean.getLockedAmount(Alice)
// currentLock = await veOcean.lockEnd(Alice)
// await sleep(2000)
// const initialQuery = {
// query: `query {
// veOCEANs(id:"${Alice.toLowerCase()}"){
// id,
// lockedAmount,
// unlockTime
// }
// }`
// }
// await sleep(2000)
if (parseInt(currentBalance) > 0 || currentLock > 0) {
// we already have some locked tokens, so our transaction should fail
try {
await veOcean.lockTokens(Alice, amount, unlockTime)
assert(false, 'This should fail!')
} catch (e) {
// do nothing
}
} else {
await veOcean.lockTokens(Alice, amount, unlockTime)
}
currentBalance = await veOcean.getLockedAmount(Alice)
currentLock = await veOcean.lockEnd(Alice)
await sleep(2000)
const initialQuery = {
query: `query {
veOCEANs(id:"${Alice.toLowerCase()}"){
id,
lockedAmount,
unlockTime
}
}`
}
await sleep(2000)
// const initialResponse = await fetch(subgraphUrl, {
// method: 'POST',
// body: JSON.stringify(initialQuery)
// })
// await sleep(2000)
// const info = (await initialResponse.json()).data.veOCEANs
// assert(info[0].id === Alice.toLowerCase(), 'ID is incorrect')
// assert(info[0].lockedAmount === currentBalance, 'LockedAmount is incorrect')
// assert(info[0].unlockTime === currentLock, 'Unlock time is not correct')
const initialResponse = await fetch(subgraphUrl, {
method: 'POST',
body: JSON.stringify(initialQuery)
})
await sleep(2000)
const info = (await initialResponse.json()).data.veOCEANs
assert(info[0].id === Alice.toLowerCase(), 'ID is incorrect')
assert(info[0].lockedAmount === currentBalance, 'LockedAmount is incorrect')
assert(info[0].unlockTime === currentLock, 'Unlock time is not correct')
// const lockTime = await veOcean.lockEnd(Alice)
// const extLockTime = Number(lockTime) + 31556926
const lockTime = await veOcean.lockEnd(Alice)
const extLockTime = Number(lockTime) + 31556926
// await delegateContract.methods.setApprovalForAll(Alice, true).send({
// from: Alice
// })
await delegateContract.methods.setApprovalForAll(Alice, true).send({
from: Alice
})
// await veOcean.increaseUnlockTime(Alice, extLockTime)
await veOcean.increaseUnlockTime(Alice, extLockTime)
// const estGas = await calculateEstimatedGas(
// Alice,
// delegateContract.methods.create_boost,
// Alice,
// Bob,
// 10000,
// 0,
// extLockTime,
// 0
// )
const estGas = await calculateEstimatedGas(
Alice,
delegateContract.methods.create_boost,
Alice,
Bob,
10000,
0,
extLockTime,
0
)
// const tx3 = await sendTx(
// Alice,
// estGas,
// web3,
// 1,
// delegateContract.methods.create_boost,
// Alice,
// Bob,
// 10000,
// 0,
// extLockTime,
// 0
// )
const tx3 = await sendTx(
Alice,
estGas,
web3,
1,
delegateContract.methods.create_boost,
Alice,
Bob,
10000,
0,
extLockTime,
0
)
// assert(tx3, 'Transaction failed')
// assert(tx3.events.DelegateBoost, 'No Delegate boost event')
assert(tx3, 'Transaction failed')
assert(tx3.events.DelegateBoost, 'No Delegate boost event')
// sleep(4000)
// const delegateQuery = {
// query: `query {
// veDelegations{
// id,
// delegator {
// id
// },
// receiver {
// id
// },
// tokenId,
// amount,
// cancelTime,
// expireTime,
// eventIndex
// }
// }`
// }
sleep(4000)
const delegateQuery = {
query: `query {
veDelegations{
id,
delegator {
id
},
receiver {
id
},
tokenId,
amount,
cancelTime,
expireTime,
eventIndex
}
}`
}
// const delegateResponse = await fetch(subgraphUrl, {
// method: 'POST',
// body: JSON.stringify(delegateQuery)
// })
// const json = await delegateResponse.json()
// assert(json?.data?.veDelegations, 'No veDelegations')
// assert(
// json?.data?.veDelegations.eventIndex !== null,
// 'Invalid eventIndex for veDelegation'
// )
// assert(
// json?.data?.veDelegations.id !== null,
// 'Invalid eventIndex for veDelegation'
// )
// })
const delegateResponse = await fetch(subgraphUrl, {
method: 'POST',
body: JSON.stringify(delegateQuery)
})
const json = await delegateResponse.json()
assert(json?.data?.veDelegations, 'No veDelegations')
assert(
json?.data?.veDelegations.eventIndex !== null,
'Invalid eventIndex for veDelegation'
)
assert(
json?.data?.veDelegations.id !== null,
'Invalid eventIndex for veDelegation'
)
})
})

View File

@ -40,8 +40,6 @@ describe('Ending tests', () => {
assert(result.data._meta.hasIndexingErrors == false)
})
it('Make sure that graph has synced to last block', async () => {
console.log('meta.block: ', result.data._meta.block.number)
console.log('lastBlock: ', lastblock)
assert(result.data._meta.block.number >= lastblock)
assert(result.data._meta.block.number >= lastblock - 1)
})
})