mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
89 lines
2.5 KiB
TypeScript
89 lines
2.5 KiB
TypeScript
import {assert} from "chai"
|
|
import ConfigProvider from "../../src/ConfigProvider"
|
|
import Web3Provider from "../../src/keeper/Web3Provider"
|
|
import Account from "../../src/ocean/Account"
|
|
import Ocean from "../../src/ocean/Ocean"
|
|
import config from "../config"
|
|
import TestContractHandler from "../keeper/TestContractHandler"
|
|
|
|
let ocean: Ocean
|
|
let accounts: Account[]
|
|
|
|
describe("Account", () => {
|
|
|
|
before(async () => {
|
|
ConfigProvider.setConfig(config)
|
|
await TestContractHandler.prepareContracts()
|
|
ocean = await Ocean.getInstance(config)
|
|
|
|
accounts = await ocean.getAccounts()
|
|
})
|
|
|
|
describe("#getOceanBalance()", () => {
|
|
|
|
it("should get initial ocean balance", async () => {
|
|
|
|
const balance = await accounts[8].getOceanBalance()
|
|
|
|
assert(0 === balance, `Expected 0 got ${balance}`)
|
|
})
|
|
|
|
it("should get the correct balance", async () => {
|
|
|
|
const amount: number = 100
|
|
const account: Account = accounts[0]
|
|
await account.requestTokens(amount)
|
|
const balance = await account.getOceanBalance()
|
|
|
|
assert(amount === balance)
|
|
})
|
|
})
|
|
|
|
describe("#getEthBalance()", () => {
|
|
|
|
it("should get initial ether balance", async () => {
|
|
|
|
const account: Account = accounts[9]
|
|
const balance = await account.getEtherBalance()
|
|
const web3 = Web3Provider.getWeb3()
|
|
|
|
assert(Number(web3.utils.toWei("100", "ether")) === balance)
|
|
})
|
|
})
|
|
|
|
describe("#getBalance()", () => {
|
|
|
|
it("should get initial balance", async () => {
|
|
|
|
const account: Account = accounts[9]
|
|
const balance = await account.getBalance()
|
|
const web3 = Web3Provider.getWeb3()
|
|
|
|
assert(Number(web3.utils.toWei("100", "ether")) === balance.eth)
|
|
assert(0 === balance.ocn)
|
|
})
|
|
})
|
|
|
|
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)
|
|
})
|
|
})
|
|
|
|
describe("#getPublicKey()", () => {
|
|
|
|
it("should get the public key of an account", async () => {
|
|
const publicKey = await accounts[1].getPublicKey()
|
|
assert(publicKey)
|
|
|
|
assert(publicKey.length === 128)
|
|
})
|
|
})
|
|
})
|