This commit is contained in:
alexcos20 2023-04-13 20:13:54 +03:00
parent 7aa49fefca
commit bbd940070c
2 changed files with 25 additions and 5 deletions

View File

@ -35,11 +35,7 @@ export function getOPC(): OPC {
}
export function getTotalOceanLocked(): BigDecimal {
let globalStats = OPC.load(GLOBAL_ID)
if (!globalStats) {
globalStats = new OPC(GLOBAL_ID)
globalStats.save()
}
const globalStats = getGlobalStats()
return globalStats.totalOceanLocked
}

View File

@ -70,6 +70,23 @@ function evmIncreaseTime(seconds) {
})
}
async function getTotalLockedOcean() {
const initialQuery = {
query: `query{
globalStatistics{
totalOceanLocked
}
}`
}
const initialResponse = await fetch(subgraphUrl, {
method: 'POST',
body: JSON.stringify(initialQuery)
})
const data = (await initialResponse.json()).data.globalStatistics
if (data.length == 0) return 0
return data[0].totalOceanLocked
}
const minAbi = [
{
constant: false,
@ -144,6 +161,7 @@ describe('veOcean tests', async () => {
it('Alice should lock 100 Ocean', async () => {
// since we can only lock once, we test if tx fails or not
// so if there is already a lock, skip it
const totalOceanLockedBefore = await getTotalLockedOcean()
let currentBalance = await veOcean.getLockedAmount(Alice)
let currentLock = await veOcean.lockEnd(Alice)
const amount = '100'
@ -169,6 +187,9 @@ describe('veOcean tests', async () => {
} else {
await veOcean.lockTokens(Alice, amount, unlockTime)
}
const totalOceanLockedAfter = await getTotalLockedOcean()
assert(totalOceanLockedAfter > totalOceanLockedBefore)
assert(totalOceanLockedAfter == parseFloat(totalOceanLockedBefore + amount))
currentBalance = await veOcean.getLockedAmount(Alice)
currentLock = await veOcean.lockEnd(Alice)
await sleep(2000)
@ -550,7 +571,10 @@ describe('veOcean tests', async () => {
})
it('Alice should withdraw locked tokens', async () => {
await evmIncreaseTime(60 * 60 * 24 * 7)
const totalOceanLockedBefore = await getTotalLockedOcean()
await veOcean.withdraw(Alice)
const totalOceanLockedAfter = await getTotalLockedOcean()
assert(totalOceanLockedAfter < totalOceanLockedBefore)
})
it('Alice should lock 100 Ocean and Delegate them to Bob', async () => {