mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
more running unit tests
This commit is contained in:
parent
d558665570
commit
0355d0420d
@ -1,5 +1,5 @@
|
||||
import { assert, expect, spy, use } from 'chai'
|
||||
import spies from 'chai-spies'
|
||||
// import spies from 'chai-spies'
|
||||
|
||||
import { DDO } from '../../../src/ddo/DDO'
|
||||
import { Service } from '../../../src/ddo/interfaces/Service'
|
||||
@ -9,7 +9,7 @@ import { TestContractHandler } from '../../TestContractHandler'
|
||||
|
||||
import * as jsonDDO from '../__fixtures__/ddo.json'
|
||||
|
||||
use(spies)
|
||||
// use(spies)
|
||||
|
||||
describe('DDO', () => {
|
||||
const testDDO: DDO = new DDO({
|
||||
@ -158,76 +158,69 @@ describe('DDO', () => {
|
||||
]
|
||||
})
|
||||
|
||||
let ocean: Ocean
|
||||
|
||||
beforeEach(async () => {
|
||||
// await TestContractHandler.prepareContracts()
|
||||
// ocean = await Ocean.getInstance(Config)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
spy.restore()
|
||||
})
|
||||
// afterEach(() => {
|
||||
// spy.restore()
|
||||
// })
|
||||
|
||||
describe('#serialize()', () => {
|
||||
it('should properly serialize', async () => {
|
||||
// const ddoString = DDO.serialize(testDDO)
|
||||
// assert(ddoString)
|
||||
// assert(ddoString.startsWith('{'))
|
||||
const ddoString = DDO.serialize(testDDO)
|
||||
assert(ddoString)
|
||||
assert(ddoString.startsWith('{'))
|
||||
})
|
||||
})
|
||||
|
||||
describe('#constructor()', () => {
|
||||
it('should create an empty ddo', async () => {
|
||||
// const ddo = new DDO()
|
||||
// assert(ddo)
|
||||
// assert(ddo.service.length === 0)
|
||||
// assert(ddo.authentication.length === 0)
|
||||
// assert(ddo.publicKey.length === 0)
|
||||
const ddo = new DDO()
|
||||
assert(ddo)
|
||||
assert(ddo.service.length === 0)
|
||||
assert(ddo.authentication.length === 0)
|
||||
assert(ddo.publicKey.length === 0)
|
||||
})
|
||||
|
||||
it('should create an predefined ddo', async () => {
|
||||
// const service: Partial<Service> & any = {
|
||||
// serviceEndpoint: 'http://',
|
||||
// description: 'nice service'
|
||||
// }
|
||||
// const ddo = new DDO({
|
||||
// service: [service as any]
|
||||
// })
|
||||
// assert(ddo)
|
||||
// assert(ddo.service.length === 1)
|
||||
// assert((ddo.service[0] as any).description === service.description)
|
||||
// assert(ddo.authentication.length === 0)
|
||||
// assert(ddo.publicKey.length === 0)
|
||||
const service: Partial<Service> & any = {
|
||||
serviceEndpoint: 'http://',
|
||||
description: 'nice service'
|
||||
}
|
||||
const ddo = new DDO({
|
||||
service: [service as any]
|
||||
})
|
||||
assert(ddo)
|
||||
assert(ddo.service.length === 1)
|
||||
assert((ddo.service[0] as any).description === service.description)
|
||||
assert(ddo.authentication.length === 0)
|
||||
assert(ddo.publicKey.length === 0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('#deserialize()', () => {
|
||||
it('should properly deserialize from serialized object', async () => {
|
||||
// const ddoString = DDO.serialize(testDDO)
|
||||
// assert.typeOf(ddoString, 'string')
|
||||
// const ddo: DDO = DDO.deserialize(ddoString)
|
||||
// assert.instanceOf(ddo, DDO)
|
||||
// assert.equal(ddo.id, testDDO.id)
|
||||
// assert.equal(ddo.publicKey[0].publicKeyPem, testDDO.publicKey[0].publicKeyPem)
|
||||
const ddoString = DDO.serialize(testDDO)
|
||||
assert.typeOf(ddoString, 'string')
|
||||
const ddo: DDO = DDO.deserialize(ddoString)
|
||||
assert.instanceOf(ddo, DDO)
|
||||
assert.equal(ddo.id, testDDO.id)
|
||||
assert.equal(ddo.publicKey[0].publicKeyPem, testDDO.publicKey[0].publicKeyPem)
|
||||
})
|
||||
|
||||
it('should properly deserialize from json file', async () => {
|
||||
// const ddo: DDO = DDO.deserialize(JSON.stringify(jsonDDO))
|
||||
// assert(ddo)
|
||||
// assert.equal(ddo.id, jsonDDO.id)
|
||||
// assert.equal(ddo.publicKey[0].publicKeyPem, jsonDDO.publicKey[0].publicKeyPem)
|
||||
const ddo: DDO = DDO.deserialize(JSON.stringify(jsonDDO))
|
||||
assert(ddo)
|
||||
assert.equal(ddo.id, jsonDDO.id)
|
||||
assert.equal(ddo.publicKey[0].publicKeyPem, jsonDDO.publicKey[0].publicKeyPem)
|
||||
})
|
||||
})
|
||||
|
||||
describe('#getChecksum()', () => {
|
||||
it('should properly generate a the checksum DDO', async () => {
|
||||
// const ddo = new DDO(testDDO)
|
||||
// const checksum = ddo.getChecksum()
|
||||
// assert.equal(
|
||||
// checksum,
|
||||
// '0x15f27a7a3c7b15d2b06dec7347c6b8da168adddd7df51a8ebbbe87b59b80049b'
|
||||
// )
|
||||
const ddo = new DDO(testDDO)
|
||||
const checksum = ddo.getChecksum()
|
||||
assert.equal(
|
||||
checksum,
|
||||
'0x15f27a7a3c7b15d2b06dec7347c6b8da168adddd7df51a8ebbbe87b59b80049b'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@ -241,9 +234,9 @@ describe('DDO', () => {
|
||||
// const checksum = ddo.getChecksum()
|
||||
// const proof = await ddo.generateProof(ocean, publicKey)
|
||||
// assert.include(proof as any, {
|
||||
// creator: publicKey,
|
||||
// type: 'DDOIntegritySignature',
|
||||
// signatureValue: signature
|
||||
// creator: publicKey,
|
||||
// type: 'DDOIntegritySignature',
|
||||
// signatureValue: signature
|
||||
// })
|
||||
// expect(signTextSpy).to.have.been.called.with(checksum, publicKey)
|
||||
})
|
||||
|
@ -1,67 +1,25 @@
|
||||
import { assert } from 'chai'
|
||||
import Web3Provider from '../../../src/datatokens/Web3Provider'
|
||||
import Account from '../../../src/ocean/Account'
|
||||
import { Ocean } from '../../../src/ocean/Ocean'
|
||||
import config from '../config'
|
||||
import { TestContractHandler } from '../../TestContractHandler'
|
||||
|
||||
let ocean: Ocean
|
||||
let accounts: Account[]
|
||||
let account: Account
|
||||
|
||||
describe('Account', () => {
|
||||
before(async () => {
|
||||
// await TestContractHandler.prepareContracts()
|
||||
// ocean = await Ocean.getInstance(config)
|
||||
// accounts = await ocean.accounts.list()
|
||||
account = new Account()
|
||||
})
|
||||
|
||||
describe('#getOceanBalance()', () => {
|
||||
it('should get initial ocean balance', async () => {
|
||||
// const balance = await accounts[8].getOceanBalance()
|
||||
// assert.equal(0, balance, `Expected 0 got ${balance}`)
|
||||
})
|
||||
|
||||
it('should get the correct balance', async () => {
|
||||
// const amount = 100
|
||||
// const account: Account = accounts[0]
|
||||
// const initialBalance = await account.getOceanBalance()
|
||||
// await account.requestTokens(amount)
|
||||
// const balance = await account.getOceanBalance()
|
||||
// assert.equal(balance, initialBalance + amount)
|
||||
})
|
||||
// it('should get initial ocean balance', async () => {
|
||||
// const balance = await account.getOceanBalance()
|
||||
// assert.equal(0, Number(balance), `Expected 0, got ${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,
|
||||
// `ether did not match ${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,
|
||||
// `ether did not match ${balance.eth}`
|
||||
// )
|
||||
// assert(balance.ocn === 0, `tokens did not match ${balance.ocn}`)
|
||||
})
|
||||
})
|
||||
|
||||
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)
|
||||
})
|
||||
// it('should get initial ether balance', async () => {
|
||||
// const balance = await account.getEtherBalance()
|
||||
// // assert(balance === '100', `ether did not match ${balance}`)
|
||||
// assert.equal(0, Number(balance), `Expected 0, got ${balance}`)
|
||||
// })
|
||||
})
|
||||
})
|
||||
|
@ -11,7 +11,7 @@ let ocean: Ocean
|
||||
|
||||
describe('Ocean', () => {
|
||||
before(async () => {
|
||||
// await TestContractHandler.prepareContracts()
|
||||
// await TestContractHandler.deployContracts()
|
||||
// ocean = await Ocean.getInstance(config)
|
||||
})
|
||||
|
||||
@ -22,12 +22,12 @@ describe('Ocean', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('#getAccounts()', () => {
|
||||
// it('should list accounts', async () => {
|
||||
// const accs: Account[] = await ocean.accounts.list()
|
||||
// assert(accs.length === 10)
|
||||
// assert((await accs[5].getOceanBalance()) === '0')
|
||||
// assert(typeof accs[0].getId() === 'string')
|
||||
// })
|
||||
})
|
||||
// describe('#getAccounts()', () => {
|
||||
// it('should list accounts', async () => {
|
||||
// const accs: Account[] = await ocean.accounts.list()
|
||||
// assert(accs.length === 10)
|
||||
// assert((await accs[5].getOceanBalance()) === '0')
|
||||
// assert(typeof accs[0].getId() === 'string')
|
||||
// })
|
||||
// })
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user