1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00

more test updates

This commit is contained in:
Matthias Kretschmann 2020-09-03 11:53:24 +02:00
parent a3a772c92e
commit 2521866e92
Signed by: m
GPG Key ID: 606EEEF3C479A91F
2 changed files with 34 additions and 28 deletions

View File

@ -10,13 +10,13 @@ import datatokensTemplate from '@oceanprotocol/contracts/artifacts/DataTokenTemp
const web3 = new Web3('http://127.0.0.1:8545') const web3 = new Web3('http://127.0.0.1:8545')
describe('DataTokens', () => { describe('DataTokens', () => {
let minter let minter: string
let spender let spender: string
let balance let balance: string
let contracts let contracts: TestContractHandler
let datatoken let datatoken: DataTokens
let tokenAddress let tokenAddress: string
const tokenAmount = 100 const tokenAmount = '100'
const blob = 'https://example.com/dataset-1' const blob = 'https://example.com/dataset-1'
describe('#test', () => { describe('#test', () => {
@ -52,18 +52,23 @@ describe('DataTokens', () => {
it('should create datatokens with fallback cap, name & symbol', async () => { it('should create datatokens with fallback cap, name & symbol', async () => {
tokenAddress = await datatoken.create(blob, minter) tokenAddress = await datatoken.create(blob, minter)
assert(tokenAddress !== null) assert(tokenAddress !== null)
const tokenName = await datatoken.getName(tokenAddress, minter)
const tokenSymbol = await datatoken.getSymbol(tokenAddress, minter)
assert(tokenName !== null || tokenName !== '')
assert(tokenSymbol !== null || tokenSymbol !== '')
}) })
it('should mint datatokens', async () => { it('should mint datatokens', async () => {
await datatoken.mint(tokenAddress, minter, tokenAmount) await datatoken.mint(tokenAddress, minter, tokenAmount)
balance = await datatoken.balance(tokenAddress, minter) balance = await datatoken.balance(tokenAddress, minter)
assert(balance.toString() === tokenAmount.toString()) assert(balance === tokenAmount)
}) })
it('should transfer datatokens', async () => { it('should transfer datatokens', async () => {
await datatoken.transfer(tokenAddress, spender, tokenAmount, minter) await datatoken.transfer(tokenAddress, spender, tokenAmount, minter)
balance = await datatoken.balance(tokenAddress, spender) balance = await datatoken.balance(tokenAddress, spender)
assert(balance.toString() === tokenAmount.toString()) assert(balance === tokenAmount)
}) })
it('should approve datatokens transfer', async () => { it('should approve datatokens transfer', async () => {
@ -73,7 +78,7 @@ describe('DataTokens', () => {
it('should transferFrom datatokens', async () => { it('should transferFrom datatokens', async () => {
await datatoken.transferFrom(tokenAddress, spender, tokenAmount, minter) await datatoken.transferFrom(tokenAddress, spender, tokenAmount, minter)
balance = await datatoken.balance(tokenAddress, minter) balance = await datatoken.balance(tokenAddress, minter)
assert(balance.toString() === tokenAmount.toString()) assert(balance === tokenAmount)
}) })
}) })
}) })

View File

@ -17,21 +17,22 @@ const web3 = new Web3('http://127.0.0.1:8545')
describe('Balancer flow', () => { describe('Balancer flow', () => {
let oceanTokenAddress let oceanTokenAddress
let OceanPoolFactoryAddress let OceanPoolFactoryAddress
let Pool let Pool: OceanPool
let oceandatatoken let oceandatatoken: DataTokens
let alicePoolAddress let alicePoolAddress
let currentDtPrice let currentDtPrice
let owner let owner: string
let bob let bob: string
let alice let alice: string
let contracts let contracts: TestContractHandler
let datatoken let datatoken: DataTokens
let tokenAddress let tokenAddress: string
let consoleDebug: false let consoleDebug: false
let greatPool let greatPool
const tokenAmount = '1000' const tokenAmount = '1000'
const transferAmount = '200' const transferAmount = '200'
const blob = 'http://localhost:8030/api/v1/services/consume' const blob = 'http://localhost:8030/api/v1/services/consume'
describe('#test', () => { describe('#test', () => {
before(async () => { before(async () => {
// deploy SFactory // deploy SFactory
@ -74,7 +75,7 @@ describe('Balancer flow', () => {
}) })
it('should create datatokens smart contract', async () => { it('should create datatokens smart contract', async () => {
tokenAddress = await datatoken.create(blob, 'AliceDT', 'DTA', '10000000000', alice) tokenAddress = await datatoken.create(blob, alice, '10000000000', 'AliceDT', 'DTA')
assert(tokenAddress !== null) assert(tokenAddress !== null)
}) })
it('Create a dummy OceanToken', async () => { it('Create a dummy OceanToken', async () => {
@ -87,10 +88,10 @@ describe('Balancer flow', () => {
) )
oceanTokenAddress = await oceandatatoken.create( oceanTokenAddress = await oceandatatoken.create(
blob, blob,
'AliceDT2', alice,
'DTA2',
'10000000000', '10000000000',
alice 'AliceDT2',
'DTA2'
) )
}) })
it('should initialize OceanPool class', async () => { it('should initialize OceanPool class', async () => {
@ -137,19 +138,19 @@ describe('Balancer flow', () => {
}) })
it('Get dtToken pool reserve ', async () => { it('Get dtToken pool reserve ', async () => {
const currentDtReserve = await Pool.getDTReserve(alice, alicePoolAddress) const currentDtReserve = await Pool.getDTReserve(alice, alicePoolAddress)
assert(currentDtReserve > 0) assert(Number(currentDtReserve) > 0)
}) })
it('Get Ocean pool reserve ', async () => { it('Get Ocean pool reserve ', async () => {
const currentOceanReserve = await Pool.getOceanReserve(alice, alicePoolAddress) const currentOceanReserve = await Pool.getOceanReserve(alice, alicePoolAddress)
assert(currentOceanReserve > 0) assert(Number(currentOceanReserve) > 0)
}) })
it('Get total supply of pool tokens', async () => { it('Get total supply of pool tokens', async () => {
const totalSupply = await Pool.totalSupply(alicePoolAddress) const totalSupply = await Pool.totalSupply(alicePoolAddress)
assert(totalSupply > 0) assert(Number(totalSupply) > 0)
}) })
it('Get amount of Ocean needed to buy 1 dtToken', async () => { it('Get amount of Ocean needed to buy 1 dtToken', async () => {
const requiredOcean = await Pool.getOceanNeeded(alice, alicePoolAddress, '1') const requiredOcean = await Pool.getOceanNeeded(alice, alicePoolAddress, '1')
assert(requiredOcean > 0) assert(Number(requiredOcean) > 0)
}) })
it('Bob should search for pools with this DT', async () => { it('Bob should search for pools with this DT', async () => {
@ -162,8 +163,8 @@ describe('Balancer flow', () => {
await Pool.buyDT(bob, greatPool, '1', '2', String(maxPrice)) await Pool.buyDT(bob, greatPool, '1', '2', String(maxPrice))
const bobDtBalance = await datatoken.balance(tokenAddress, bob) const bobDtBalance = await datatoken.balance(tokenAddress, bob)
const bobOceanBalance = await datatoken.balance(oceanTokenAddress, bob) const bobOceanBalance = await datatoken.balance(oceanTokenAddress, bob)
assert(bobDtBalance > 0) assert(Number(bobDtBalance) > 0)
assert(bobOceanBalance > 0) assert(Number(bobOceanBalance) > 0)
}) })
it('Bob should add DT liquidity to pool ', async () => { it('Bob should add DT liquidity to pool ', async () => {
const currentDtReserve = await Pool.getDTReserve(bob, greatPool) const currentDtReserve = await Pool.getDTReserve(bob, greatPool)