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"
|
2019-03-19 13:01:28 +01:00
|
|
|
import { Ocean } from "../../src/ocean/Ocean"
|
2018-10-16 14:56:18 +02:00
|
|
|
import config from "../config"
|
2018-11-07 14:33:56 +01:00
|
|
|
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 () => {
|
2018-11-07 14:33:56 +01:00
|
|
|
await TestContractHandler.prepareContracts()
|
2018-10-26 10:40:46 +02:00
|
|
|
ocean = await Ocean.getInstance(config)
|
2019-03-21 02:56:58 +01:00
|
|
|
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
|
|
|
|
2018-10-18 13:06:52 +02:00
|
|
|
const balance = await accounts[8].getOceanBalance()
|
2018-10-09 15:24:36 +02:00
|
|
|
|
2019-03-21 02:56:58 +01: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]
|
2019-03-21 02:56:58 +01:00
|
|
|
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
|
|
|
|
2019-03-21 02:56:58 +01: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]
|
2018-10-18 13:06:52 +02:00
|
|
|
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
|
|
|
})
|
|
|
|
})
|
2018-10-18 13:06:52 +02:00
|
|
|
|
|
|
|
describe("#requestTokens()", () => {
|
|
|
|
|
|
|
|
it("should return the amount of tokens granted", async () => {
|
|
|
|
|
2019-05-23 11:52:36 +02:00
|
|
|
const tokens = "500"
|
2018-10-18 13:06:52 +02:00
|
|
|
const account: Account = accounts[0]
|
2019-05-23 11:52:36 +02:00
|
|
|
const tokensGranted: string = await account.requestTokens(tokens)
|
2018-10-18 13:06:52 +02:00
|
|
|
|
2019-05-23 11:52:36 +02:00
|
|
|
assert.equal(tokensGranted, tokens)
|
2018-10-18 13:06:52 +02:00
|
|
|
})
|
|
|
|
})
|
2018-11-12 10:06:24 +01:00
|
|
|
|
2018-10-09 15:24:36 +02:00
|
|
|
})
|