From 0355d0420d53786eb8d4259f642190157736d486 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Fri, 4 Sep 2020 12:53:00 +0200 Subject: [PATCH] more running unit tests --- test/unit/ddo/DDO.test.ts | 95 +++++++++---------- test/unit/ocean/Account.test.ts | 64 +++---------- .../ocean/{Assets.Test.ts => Assets.test.ts} | 0 test/unit/ocean/Ocean.test.ts | 18 ++-- 4 files changed, 64 insertions(+), 113 deletions(-) rename test/unit/ocean/{Assets.Test.ts => Assets.test.ts} (100%) diff --git a/test/unit/ddo/DDO.test.ts b/test/unit/ddo/DDO.test.ts index 74e9f5d4..a1b0f65b 100644 --- a/test/unit/ddo/DDO.test.ts +++ b/test/unit/ddo/DDO.test.ts @@ -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 & 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 & 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) }) diff --git a/test/unit/ocean/Account.test.ts b/test/unit/ocean/Account.test.ts index d0c1064a..475bf83a 100644 --- a/test/unit/ocean/Account.test.ts +++ b/test/unit/ocean/Account.test.ts @@ -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}`) + // }) }) }) diff --git a/test/unit/ocean/Assets.Test.ts b/test/unit/ocean/Assets.test.ts similarity index 100% rename from test/unit/ocean/Assets.Test.ts rename to test/unit/ocean/Assets.test.ts diff --git a/test/unit/ocean/Ocean.test.ts b/test/unit/ocean/Ocean.test.ts index 1207d541..f35d2774 100644 --- a/test/unit/ocean/Ocean.test.ts +++ b/test/unit/ocean/Ocean.test.ts @@ -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') + // }) + // }) })