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

73 lines
2.4 KiB
TypeScript
Raw Normal View History

2019-06-20 00:20:09 +02:00
import { assert } from 'chai'
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'
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
2019-06-20 00:20:09 +02:00
describe('Account', () => {
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
2019-06-20 00:20:09 +02:00
describe('#getOceanBalance()', () => {
it('should get initial ocean balance', async () => {
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
})
2019-06-20 00:20:09 +02:00
it('should get the correct balance', async () => {
const amount = 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
})
})
2019-06-20 00:20:09 +02:00
describe('#getEthBalance()', () => {
it('should get initial ether balance', async () => {
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()
2019-06-20 00:20:09 +02:00
assert(
Number(web3.utils.toWei('100', 'ether')) === balance,
`ether did not match ${balance}`
)
2018-10-09 15:24:36 +02:00
})
})
2019-06-20 00:20:09 +02:00
describe('#getBalance()', () => {
it('should get initial balance', async () => {
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
2019-06-20 00:20:09 +02:00
assert(
Number(web3.utils.toWei('100', 'ether')) === balance.eth,
`ether did not match ${balance.eth}`
)
assert(balance.ocn === 0, `tokens did not match ${balance.ocn}`)
2018-10-09 15:24:36 +02:00
})
})
2019-06-20 00:20:09 +02:00
describe('#requestTokens()', () => {
it('should return the amount of tokens granted', async () => {
const tokens = '500'
const account: Account = accounts[0]
const tokensGranted: string = await account.requestTokens(tokens)
assert.equal(tokensGranted, tokens)
})
})
2018-10-09 15:24:36 +02:00
})