2019-06-20 00:20:09 +02:00
|
|
|
import { assert } from 'chai'
|
2020-01-30 22:08:18 +01:00
|
|
|
import Web3Provider from '../../../src/keeper/Web3Provider'
|
|
|
|
import Account from '../../../src/ocean/Account'
|
|
|
|
import { Ocean } from '../../../src/ocean/Ocean'
|
2019-06-20 00:20:09 +02:00
|
|
|
import config from '../config'
|
|
|
|
import TestContractHandler from '../keeper/TestContractHandler'
|
2018-10-09 15:24:36 +02:00
|
|
|
|
2018-10-16 14:56:18 +02:00
|
|
|
let ocean: Ocean
|
|
|
|
let accounts: Account[]
|
2018-10-09 15:24:36 +02:00
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
describe('Account', () => {
|
2018-10-26 10:40:46 +02:00
|
|
|
before(async () => {
|
2018-11-07 14:33:56 +01:00
|
|
|
await TestContractHandler.prepareContracts()
|
2018-10-26 10:40:46 +02:00
|
|
|
ocean = await Ocean.getInstance(config)
|
2019-03-21 02:56:58 +01:00
|
|
|
accounts = await ocean.accounts.list()
|
2018-10-26 10:40:46 +02:00
|
|
|
})
|
2018-10-09 15:24:36 +02:00
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
describe('#getOceanBalance()', () => {
|
|
|
|
it('should get initial ocean balance', async () => {
|
2018-10-18 13:06:52 +02:00
|
|
|
const balance = await accounts[8].getOceanBalance()
|
2018-10-09 15:24:36 +02:00
|
|
|
|
2019-03-21 02:56:58 +01:00
|
|
|
assert.equal(0, balance, `Expected 0 got ${balance}`)
|
2018-10-09 15:24:36 +02:00
|
|
|
})
|
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
it('should get the correct balance', async () => {
|
|
|
|
const amount = 100
|
2018-10-16 14:56:18 +02:00
|
|
|
const account: Account = accounts[0]
|
2019-03-21 02:56:58 +01:00
|
|
|
const initialBalance = await account.getOceanBalance()
|
2018-10-16 14:56:18 +02:00
|
|
|
await account.requestTokens(amount)
|
|
|
|
const balance = await account.getOceanBalance()
|
2018-10-09 15:24:36 +02:00
|
|
|
|
2019-03-21 02:56:58 +01:00
|
|
|
assert.equal(balance, initialBalance + amount)
|
2018-10-09 15:24:36 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
describe('#getEthBalance()', () => {
|
|
|
|
it('should get initial ether balance', async () => {
|
2018-10-17 18:24:01 +02:00
|
|
|
const account: Account = accounts[9]
|
2018-10-18 13:06:52 +02:00
|
|
|
const balance = await account.getEtherBalance()
|
2018-10-16 14:56:18 +02:00
|
|
|
const web3 = Web3Provider.getWeb3()
|
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
assert(
|
|
|
|
Number(web3.utils.toWei('100', 'ether')) === balance,
|
|
|
|
`ether did not match ${balance}`
|
|
|
|
)
|
2018-10-09 15:24:36 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
describe('#getBalance()', () => {
|
|
|
|
it('should get initial balance', async () => {
|
2018-10-17 18:24:01 +02:00
|
|
|
const account: Account = accounts[9]
|
2018-10-16 14:56:18 +02:00
|
|
|
const balance = await account.getBalance()
|
|
|
|
const web3 = Web3Provider.getWeb3()
|
2018-10-09 15:24:36 +02:00
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
assert(
|
|
|
|
Number(web3.utils.toWei('100', 'ether')) === balance.eth,
|
|
|
|
`ether did not match ${balance.eth}`
|
|
|
|
)
|
|
|
|
assert(balance.ocn === 0, `tokens did not match ${balance.ocn}`)
|
2018-10-09 15:24:36 +02:00
|
|
|
})
|
|
|
|
})
|
2018-10-18 13:06:52 +02:00
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
describe('#requestTokens()', () => {
|
|
|
|
it('should return the amount of tokens granted', async () => {
|
|
|
|
const tokens = '500'
|
2018-10-18 13:06:52 +02:00
|
|
|
const account: Account = accounts[0]
|
2019-05-23 11:52:36 +02:00
|
|
|
const tokensGranted: string = await account.requestTokens(tokens)
|
2018-10-18 13:06:52 +02:00
|
|
|
|
2019-05-23 11:52:36 +02:00
|
|
|
assert.equal(tokensGranted, tokens)
|
2018-10-18 13:06:52 +02:00
|
|
|
})
|
|
|
|
})
|
2018-10-09 15:24:36 +02:00
|
|
|
})
|