1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00
squid-js/test/ocean/Account.test.ts

79 lines
2.2 KiB
TypeScript
Raw Normal View History

2018-10-18 09:19:10 +02:00
import {assert} from "chai"
2018-10-16 14:56:18 +02:00
import ConfigProvider from "../../src/ConfigProvider"
2018-10-09 15:24:36 +02:00
import ContractHandler from "../../src/keeper/ContractHandler"
2018-10-16 14:56:18 +02:00
import Web3Provider from "../../src/keeper/Web3Provider"
2018-10-09 15:24:36 +02:00
import Account from "../../src/ocean/Account"
2018-10-16 14:56:18 +02:00
import Ocean from "../../src/ocean/Ocean"
import config from "../config"
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
2018-10-26 10:40:46 +02:00
describe("Account", () => {
2018-10-16 14:56:18 +02:00
2018-10-26 10:40:46 +02:00
before(async () => {
ConfigProvider.setConfig(config)
await ContractHandler.deployContracts()
ocean = await Ocean.getInstance(config)
2018-10-09 15:24:36 +02:00
2018-10-26 10:40:46 +02:00
accounts = await ocean.getAccounts()
})
2018-10-09 15:24:36 +02:00
2018-10-16 14:56:18 +02:00
describe("#getOceanBalance()", () => {
2018-10-09 15:24:36 +02:00
2018-10-16 14:56:18 +02:00
it("should get initial ocean balance", async () => {
2018-10-09 15:24:36 +02:00
const balance = await accounts[8].getOceanBalance()
2018-10-09 15:24:36 +02:00
assert(0 === balance, `Expected 0 got ${balance}`)
2018-10-09 15:24:36 +02:00
})
2018-10-16 14:56:18 +02:00
it("should get the correct balance", async () => {
2018-10-09 15:24:36 +02:00
const amount: number = 100
2018-10-16 14:56:18 +02:00
const account: Account = accounts[0]
await account.requestTokens(amount)
const balance = await account.getOceanBalance()
2018-10-09 15:24:36 +02:00
assert(amount === balance)
})
})
describe("#getEthBalance()", () => {
2018-10-17 18:24:01 +02:00
it("should get initial ether balance", async () => {
2018-10-09 15:24:36 +02:00
2018-10-17 18:24:01 +02:00
const account: Account = accounts[9]
const balance = await account.getEtherBalance()
2018-10-16 14:56:18 +02:00
const web3 = Web3Provider.getWeb3()
2018-10-09 15:24:36 +02:00
assert(Number(web3.utils.toWei("100", "ether")) === balance)
})
})
2018-10-16 14:56:18 +02:00
describe("#getBalance()", () => {
2018-10-09 15:24:36 +02:00
2018-10-16 14:56:18 +02:00
it("should get initial balance", async () => {
2018-10-09 15:24:36 +02:00
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
2018-10-16 14:56:18 +02:00
assert(Number(web3.utils.toWei("100", "ether")) === balance.eth)
assert(0 === balance.ocn)
2018-10-09 15:24:36 +02:00
})
})
describe("#requestTokens()", () => {
it("should return the amount of tokens granted", async () => {
const tokens = 500
const account: Account = accounts[0]
const tokensGranted: number = await account.requestTokens(tokens)
assert(tokensGranted === tokens)
})
})
2018-10-09 15:24:36 +02:00
})