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

88 lines
2.6 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 Web3Provider from "../../src/keeper/Web3Provider"
2018-10-09 15:24:36 +02:00
import Account from "../../src/ocean/Account"
import { Ocean } from "../../src/ocean/Ocean"
2018-10-16 14:56:18 +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
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 () => {
await TestContractHandler.prepareContracts()
2018-10-26 10:40:46 +02:00
ocean = await Ocean.getInstance(config)
accounts = await ocean.accounts.list()
2018-10-26 10:40:46 +02:00
})
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.equal(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]
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
assert.equal(balance, initialBalance + amount)
2018-10-09 15:24:36 +02:00
})
})
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-11-23 11:39:08 +01:00
assert(Number(web3.utils.toWei("100", "ether")) === balance,
`ether did not match ${balance}`)
2018-10-09 15:24:36 +02:00
})
})
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-11-23 11:39:08 +01:00
assert(Number(web3.utils.toWei("100", "ether")) === balance.eth,
`ether did not match ${balance.eth}`)
assert(0 === balance.ocn, `tokens did not match ${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-11-12 10:06:24 +01:00
describe("#getPublicKey()", () => {
it("should get the public key of an account", async () => {
const publicKey = await accounts[1].getPublicKey()
assert(publicKey)
assert(publicKey.length === 128)
})
})
2018-10-09 15:24:36 +02:00
})