2019-02-14 13:15:50 +01:00
|
|
|
import { assert, /*expect,*/ spy, use } from "chai"
|
|
|
|
import * as spies from "chai-spies"
|
|
|
|
|
|
|
|
import Account from "../../src/ocean/Account"
|
|
|
|
import OceanAccounts from "../../src/ocean/OceanAccounts"
|
|
|
|
|
|
|
|
use(spies)
|
|
|
|
|
|
|
|
describe("OceanAccounts", () => {
|
|
|
|
|
|
|
|
let oceanAccounts: OceanAccounts
|
|
|
|
|
|
|
|
before(async () => {
|
|
|
|
oceanAccounts = await OceanAccounts.getInstance()
|
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
spy.restore()
|
|
|
|
})
|
|
|
|
|
|
|
|
describe("#getInstance()", () => {
|
|
|
|
it("should get an instance of OceanAccounts", async () => {
|
2019-02-21 18:14:07 +01:00
|
|
|
const oceanAccountsInstance: OceanAccounts = await OceanAccounts.getInstance()
|
2019-02-14 13:15:50 +01:00
|
|
|
|
2019-02-21 18:14:07 +01:00
|
|
|
assert.instanceOf(oceanAccountsInstance, OceanAccounts, "No returned OceanAccounts instance")
|
2019-02-14 13:15:50 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe("#list()", () => {
|
|
|
|
it("should return the list of accounts", async () => {
|
|
|
|
const accounts = await oceanAccounts.list()
|
|
|
|
|
2019-02-21 18:14:07 +01:00
|
|
|
accounts.map((account) => assert.instanceOf(account, Account))
|
2019-02-14 13:15:50 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe("#balance()", () => {
|
|
|
|
it("should return the balance of an account", async () => {
|
|
|
|
const [account] = await oceanAccounts.list()
|
2019-02-21 18:14:07 +01:00
|
|
|
spy.on(account, "getBalance", () => ({eth: 1, ocn: 5}))
|
2019-02-14 13:15:50 +01:00
|
|
|
const balance = await oceanAccounts.balance(account)
|
|
|
|
|
|
|
|
assert.deepEqual(balance, {eth: 1, ocn: 5})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe("#requestTokens()", () => {
|
|
|
|
it("should return the balance of an account", async () => {
|
|
|
|
const [account] = await oceanAccounts.list()
|
2019-02-21 18:14:07 +01:00
|
|
|
spy.on(account, "requestTokens", () => 10)
|
2019-02-14 13:15:50 +01:00
|
|
|
const success = await oceanAccounts.requestTokens(account, 10)
|
|
|
|
|
|
|
|
assert.isTrue(success)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|