1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00
ocean.js/test/unit/DFRewards.test.ts
Alex Coseru 9bf71ba4f0
Features/ethers (#1696)
* add ethers

* global updates

* ve updates

* ve tests

* contract updates

* first test passing

* downgrade to ethers 5.7.2

* add log

* add tx wait

* full NftFactory.test

* add wait

* add Router tests

* fix dispenser

* Nft test

* add dispenser tests

* add fre tests part 1

* WIP datatoken unit tests

* add DFRewards test

* increase gas estimate

* increase gas estimate

* Work datatoken unit tests

* datatoken test more tests

* finished datatoken tests

* fix nft get data

* fix nft transfer tests

* Provider int tests

* Updating CodeExamples.md

* update provider & fix publish flow int test

* wip publish edit consume integration test

* more work on  publish edit consume integration test

* fix edit  publish edit consume integration test

* add 3 int tests

* Updating ComputeExamples.md

* fix signature and download

* fix compute flow integration test

* udapte handleComputeOrder helper

* update datatoken instance

* update datatoken global variable

* mint ocean tokens to consumer as well and added logs

* update compute exammples

* Updating ComputeExamples.md

* wip code examples readme

* update code examples readme

* Updating CodeExamples.md

* run all tests

* update dep in readme

* update readme

* code examples update metadata flags

* update dt instance in code examples md

* set metadata updates

* Updating CodeExamples.md

* update code examples readme structure

* Updating CodeExamples.md

* update readmes table links

* Updating CodeExamples.md

* Updating ComputeExamples.md

* clean-up

* Updating CodeExamples.md

* added missing unit tests for usdc fixed rate exchange tests

* more cleanup and jsdoc updates

* more  jsdoc updates

* donw with jsdoc updates

* handle provider errors

* add missing error handling file

* adds most of the provider errors

* update get compute env return type

* Release 3.0.0-next.0

* adding Typedoc to ethers branch

* update provider signature message

* fix lint

* Release 3.0.0-next.1

* fix lint

* adding Typedoc to ethers branch

* Updating CI to build and commit the documentation

* Updating documentation

* Updating script permissions

* fix todos add missing logic to send tx

* npm package cleanups

* Release 3.0.0-next.2

* update log messages for errors

* Release 3.0.0-next.3

* fix gasFee issue on sendTx

* Release 3.0.0-next.4

* add consume params typings (#1731)

* fix gas fee estimate

* remove comments

* add some delays before resolving datasets

* adds delay to Publish flow tests

* Release 3.0.0-next.5

---------

Co-authored-by: Bogdan Fazakas <bogdan.fazakas@gmail.com>
Co-authored-by: GitHub Actions Bot <>
Co-authored-by: Jamie Hewitt <jamie.hewitt15@gmail.com>
Co-authored-by: Jamie Hewitt <jamie@oceanprotocol.com>
2023-05-29 11:20:38 +03:00

153 lines
4.6 KiB
TypeScript

import { assert } from 'chai'
import { getTestConfig, provider, getAddresses } from '../config'
import { ethers, Signer } from 'ethers'
import {
Config,
approve,
DfRewards,
DfStrategyV1,
sendTx,
amountToUnits,
unitsToAmount
} from '../../src'
describe('veOcean tests', async () => {
let config: Config
let addresses: any
let dfRewards: DfRewards
let dfStrategy: DfStrategyV1
let ownerAccount: Signer
let Alice: Signer
let Bob: Signer
let tokenContract
before(async () => {
ownerAccount = (await provider.getSigner(0)) as Signer
Alice = (await provider.getSigner(1)) as Signer
Bob = (await provider.getSigner(2)) as Signer
config = await getTestConfig(ownerAccount as Signer)
addresses = await getAddresses()
})
it('initialize accounts', async () => {
addresses = getAddresses()
const minAbi = [
{
constant: false,
inputs: [
{ name: 'to', type: 'address' },
{ name: 'value', type: 'uint256' }
],
name: 'mint',
outputs: [{ name: '', type: 'bool' }],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
},
{
constant: true,
inputs: [{ name: 'owner', type: 'address' }],
name: 'balanceOf',
outputs: [{ name: '', type: 'uint256' }],
payable: false,
stateMutability: 'view',
type: 'function'
}
]
tokenContract = new ethers.Contract(addresses.Ocean, minAbi, ownerAccount)
const estGas = await tokenContract.estimateGas.mint(
await ownerAccount.getAddress(),
amountToUnits(null, null, '10000', 18)
)
// mint some Oceans
await sendTx(
estGas,
ownerAccount,
1,
tokenContract.mint,
await ownerAccount.getAddress(),
amountToUnits(null, null, '1000', 18)
)
dfRewards = new DfRewards(addresses.DFRewards, ownerAccount)
dfStrategy = new DfStrategyV1(addresses.DFStrategyV1, ownerAccount)
})
it('Generous owner should allocate some DF Rewards', async () => {
const dfOceanBalance = await unitsToAmount(
ownerAccount,
addresses.Ocean,
await tokenContract.balanceOf(addresses.DFRewards)
)
// approve 500 tokens
await approve(
ownerAccount,
config,
await ownerAccount.getAddress(),
addresses.Ocean,
addresses.DFRewards,
'300'
)
// fund DFRewards
await dfRewards.allocateRewards(
[await Alice.getAddress(), await Bob.getAddress()],
['100', '200'],
addresses.Ocean
)
const newDfOceanBalance = await unitsToAmount(
ownerAccount,
addresses.Ocean,
await tokenContract.balanceOf(addresses.DFRewards)
)
const expected = parseInt(dfOceanBalance) + 300
assert(parseInt(newDfOceanBalance) === expected, 'DFRewards allocate failed')
})
it('Alice should check for rewards', async () => {
const rewards = await dfRewards.getAvailableRewards(
await Alice.getAddress(),
addresses.Ocean
)
assert(parseInt(rewards) >= 100, 'Alice reward missmatch, got only ' + rewards)
const multipleRewards = await dfStrategy.getMultipleAvailableRewards(
await Alice.getAddress(),
[addresses.Ocean]
)
assert(parseInt(multipleRewards[0]) >= 100, 'Alice reward missmatch')
})
it('Alice should claim the rewards using DFRewards claim', async () => {
const aliceOceanBalance = await unitsToAmount(
ownerAccount,
addresses.Ocean,
await tokenContract.balanceOf(await Alice.getAddress())
)
dfRewards = new DfRewards(addresses.DFRewards, Alice)
await dfRewards.claimRewards(await Alice.getAddress(), addresses.Ocean)
const newAliceOceanBalance = await unitsToAmount(
ownerAccount,
addresses.Ocean,
await tokenContract.balanceOf(await Alice.getAddress())
)
const expected = parseInt(aliceOceanBalance) + 100
assert(parseInt(newAliceOceanBalance) >= expected, 'Alice failed to claim')
})
it('Bob should claim the rewards using DFStrategy claim', async () => {
dfRewards = new DfRewards(addresses.DFRewards, Bob)
const bobOceanBalance = await unitsToAmount(
ownerAccount,
addresses.Ocean,
await tokenContract.balanceOf(await Bob.getAddress())
)
await dfStrategy.claimMultipleRewards(await Bob.getAddress(), [addresses.Ocean])
const newBobOceanBalance = await unitsToAmount(
ownerAccount,
addresses.Ocean,
await tokenContract.balanceOf(await Bob.getAddress())
)
const expected = parseInt(bobOceanBalance) + 200
assert(parseInt(newBobOceanBalance) >= expected, 'Bob failed to claim')
})
})