mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
added some missed methods on Ocean.accounts module
This commit is contained in:
parent
8dcdf0a851
commit
057714988a
@ -1,5 +1,5 @@
|
|||||||
import Web3Provider from "../keeper/Web3Provider"
|
import Web3Provider from "../keeper/Web3Provider"
|
||||||
|
import Balance from "../models/Balance"
|
||||||
import Account from "./Account"
|
import Account from "./Account"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,4 +36,28 @@ export default class OceanAccounts {
|
|||||||
|
|
||||||
return ethAccounts.map((address: string) => new Account(address))
|
return ethAccounts.map((address: string) => new Account(address))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return account balance.
|
||||||
|
* @param {Account} account Account instance.
|
||||||
|
* @return {Promise<Balance>} Ether and Ocean Token balance.
|
||||||
|
*/
|
||||||
|
public balance(account: Account): Promise<Balance> {
|
||||||
|
return account.getBalance()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request tokens for a account.
|
||||||
|
* @param {Account} account Account instance.
|
||||||
|
* @param {number} amount Token amount.
|
||||||
|
* @return {Promise<boolean>} Success.
|
||||||
|
*/
|
||||||
|
public async requestTokens(account: Account, amount: number): Promise<boolean> {
|
||||||
|
try {
|
||||||
|
await account.requestTokens(amount)
|
||||||
|
return true
|
||||||
|
} catch(e) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
56
test/ocean/OceanAccounts.test.ts
Normal file
56
test/ocean/OceanAccounts.test.ts
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
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 () => {
|
||||||
|
const oceanAccounts: OceanAccounts = await OceanAccounts.getInstance()
|
||||||
|
|
||||||
|
assert.instanceOf(oceanAccounts, OceanAccounts, "No returned OceanAccounts instance")
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("#list()", () => {
|
||||||
|
it("should return the list of accounts", async () => {
|
||||||
|
const accounts = await oceanAccounts.list()
|
||||||
|
|
||||||
|
accounts.map(account => assert.instanceOf(account, Account))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("#balance()", () => {
|
||||||
|
it("should return the balance of an account", async () => {
|
||||||
|
const [account] = await oceanAccounts.list()
|
||||||
|
spy.on(account, 'getBalance', () => ({eth: 1, ocn: 5}))
|
||||||
|
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()
|
||||||
|
spy.on(account, 'requestTokens', () => 10)
|
||||||
|
const success = await oceanAccounts.requestTokens(account, 10)
|
||||||
|
|
||||||
|
assert.isTrue(success)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
Loading…
x
Reference in New Issue
Block a user