2019-06-20 00:20:09 +02:00
|
|
|
import { assert, spy, use } from 'chai'
|
2019-11-11 12:27:18 +01:00
|
|
|
import spies from 'chai-spies'
|
2019-02-14 13:15:50 +01:00
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
import config from '../config'
|
2020-01-30 22:08:18 +01:00
|
|
|
import Account from '../../../src/ocean/Account'
|
|
|
|
import { Ocean } from '../../../src/ocean/Ocean'
|
|
|
|
import { OceanAccounts } from '../../../src/ocean/OceanAccounts'
|
2019-02-14 13:15:50 +01:00
|
|
|
|
|
|
|
use(spies)
|
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
describe('OceanAccounts', () => {
|
2019-02-14 13:15:50 +01:00
|
|
|
let oceanAccounts: OceanAccounts
|
|
|
|
|
|
|
|
before(async () => {
|
2019-03-21 02:56:58 +01:00
|
|
|
oceanAccounts = (await Ocean.getInstance(config)).accounts
|
2019-02-14 13:15:50 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
spy.restore()
|
|
|
|
})
|
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
describe('#list()', () => {
|
|
|
|
it('should return the list of accounts', async () => {
|
2019-02-14 13:15:50 +01:00
|
|
|
const accounts = await oceanAccounts.list()
|
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
accounts.map(account => assert.instanceOf(account, Account))
|
2019-02-14 13:15:50 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
describe('#balance()', () => {
|
|
|
|
it('should return the balance of an account', async () => {
|
2019-02-14 13:15:50 +01:00
|
|
|
const [account] = await oceanAccounts.list()
|
2019-06-20 00:20:09 +02:00
|
|
|
spy.on(account, 'getBalance', () => ({ eth: 1, ocn: 5 }))
|
2019-02-14 13:15:50 +01:00
|
|
|
const balance = await oceanAccounts.balance(account)
|
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
assert.deepEqual(balance, { eth: 1, ocn: 5 })
|
2019-02-14 13:15:50 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
describe('#requestTokens()', () => {
|
|
|
|
it('should return the balance of an account', async () => {
|
2019-02-14 13:15:50 +01:00
|
|
|
const [account] = await oceanAccounts.list()
|
2019-06-20 00:20:09 +02:00
|
|
|
spy.on(account, 'requestTokens', () => 10)
|
2019-02-14 13:15:50 +01:00
|
|
|
const success = await oceanAccounts.requestTokens(account, 10)
|
|
|
|
|
|
|
|
assert.isTrue(success)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|