From 0290f57bf4d35534e21f46abe432d7d21c6ff980 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Wed, 2 Sep 2020 16:23:01 +0200 Subject: [PATCH 01/10] prototype auto-generating data token name --- src/data/words.json | 133 +++++++++++++++++++++++++++++++++++ src/datatokens/Datatokens.ts | 28 ++++++++ 2 files changed, 161 insertions(+) create mode 100644 src/data/words.json diff --git a/src/data/words.json b/src/data/words.json new file mode 100644 index 00000000..7ed8ae4c --- /dev/null +++ b/src/data/words.json @@ -0,0 +1,133 @@ +{ + "nouns": [ + "Crab", + "Fish", + "Seal", + "Octopus", + "Shark", + "Seahorse", + "Walrus", + "Starfish", + "Whale", + "Orca", + "Penguin", + "Jellyfish", + "Squid", + "Lobster", + "Pelican", + "Shrimp", + "Oyster", + "Clam", + "Seagull", + "Dolphin", + "Shell", + "Cormorant", + "Otter", + "Pelican", + "Anemone", + "Turtle", + "Coral" + ], + "adjectives": [ + "adamant", + "adroit", + "amatory", + "animistic", + "antic", + "arcadian", + "baleful", + "bellicose", + "bilious", + "boorish", + "calamitous", + "caustic", + "cerulean", + "comely", + "concomitant", + "contumacious", + "corpulent", + "crapulous", + "defamatory", + "didactic", + "dilatory", + "dowdy", + "efficacious", + "effulgent", + "egregious", + "endemic", + "equanimous", + "execrable", + "fastidious", + "feckless", + "fecund", + "friable", + "fulsome", + "garrulous", + "guileless", + "gustatory", + "heuristic", + "histrionic", + "hubristic", + "incendiary", + "insidious", + "insolent", + "intransigent", + "inveterate", + "invidious", + "irksome", + "jejune", + "jocular", + "judicious", + "lachrymose", + "limpid", + "loquacious", + "luminous", + "mannered", + "mendacious", + "meretricious", + "minatory", + "mordant", + "munificent", + "nefarious", + "noxious", + "obtuse", + "parsimonious", + "pendulous", + "pernicious", + "pervasive", + "petulant", + "platitudinous", + "precipitate", + "propitious", + "puckish", + "querulous", + "quiescent", + "rebarbative", + "recalcitant", + "redolent", + "rhadamanthine", + "risible", + "ruminative", + "sagacious", + "salubrious", + "sartorial", + "sclerotic", + "serpentine", + "spasmodic", + "strident", + "taciturn", + "tenacious", + "tremulous", + "trenchant", + "turbulent", + "turgid", + "ubiquitous", + "uxorious", + "verdant", + "voluble", + "voracious", + "wheedling", + "withering", + "zealous" + ] +} diff --git a/src/datatokens/Datatokens.ts b/src/datatokens/Datatokens.ts index b033c95e..63380456 100644 --- a/src/datatokens/Datatokens.ts +++ b/src/datatokens/Datatokens.ts @@ -4,6 +4,8 @@ import { AbiItem } from 'web3-utils/types' import defaultFactoryABI from '@oceanprotocol/contracts/artifacts/DTFactory.json' import defaultDatatokensABI from '@oceanprotocol/contracts/artifacts/DataTokenTemplate.json' +import wordListDefault from '../data/words.json' + /** * Provides a interface to DataTokens */ @@ -32,6 +34,32 @@ export class DataTokens { this.web3 = web3 } + /** + * Generate new datatoken name & symbol from a word list + * @return {<{ name: String; symbol: String }>} datatoken name & symbol. Produces e.g. "Endemic Jellyfish Token" & "ENDJEL-145" + */ + public generateDtName(wordList?: { + nouns: string[] + adjectives: string[] + }): { name: string; symbol: string } { + const list = wordList || wordListDefault + const random1 = Math.floor(Math.random() * list.adjectives.length) + const random2 = Math.floor(Math.random() * list.nouns.length) + const indexNumber = Math.floor(Math.random() * 100) + + // Capitalized adjective & noun + const adjective = list.adjectives[random1].replace(/^\w/, (c) => c.toUpperCase()) + const noun = list.nouns[random2].replace(/^\w/, (c) => c.toUpperCase()) + + const name = `${adjective} ${noun} Token` + // use first 3 letters of name, uppercase it, and add random number + const symbol = `${( + adjective.substring(0, 3) + noun.substring(0, 3) + ).toUpperCase()}-${indexNumber}` + + return { name, symbol } + } + /** * Create new datatoken * @param {String} metaDataStoreURI From f834be35208574f929fc9be0748f111dcf8dc1d7 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Thu, 3 Sep 2020 11:28:50 +0200 Subject: [PATCH 02/10] move defaults into datatokens.create() --- src/datatokens/Datatokens.ts | 21 ++++++++++++++------- src/ocean/Assets.ts | 17 +++++++++-------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/datatokens/Datatokens.ts b/src/datatokens/Datatokens.ts index 63380456..e9666782 100644 --- a/src/datatokens/Datatokens.ts +++ b/src/datatokens/Datatokens.ts @@ -36,7 +36,7 @@ export class DataTokens { /** * Generate new datatoken name & symbol from a word list - * @return {<{ name: String; symbol: String }>} datatoken name & symbol. Produces e.g. "Endemic Jellyfish Token" & "ENDJEL-145" + * @return {<{ name: String; symbol: String }>} datatoken name & symbol. Produces e.g. "Endemic Jellyfish Token" & "ENDJEL-45" */ public generateDtName(wordList?: { nouns: string[] @@ -63,19 +63,26 @@ export class DataTokens { /** * Create new datatoken * @param {String} metaDataStoreURI + * @param {String} address + * @param {String} cap Maximum cap (Number) - will be converted to wei * @param {String} name Token name * @param {String} symbol Token symbol - * @param {String} cap Maximum cap (Number) - will be converted to wei - * @param {String} address * @return {Promise} datatoken address */ public async create( metaDataStoreURI: string, - name: string, - symbol: string, - cap: string, - address: string + address: string, + cap?: string, + name?: string, + symbol?: string ): Promise { + if (!cap) cap = '1410000000000000000000000000' + + // Generate name & symbol if not present + if (!name || !symbol) { + ;({ name, symbol } = this.generateDtName()) + } + // Create factory contract object const factory = new this.web3.eth.Contract(this.factoryABI, this.factoryAddress, { from: address diff --git a/src/ocean/Assets.ts b/src/ocean/Assets.ts index 491dd5b1..f6039b69 100644 --- a/src/ocean/Assets.ts +++ b/src/ocean/Assets.ts @@ -50,6 +50,10 @@ export class Assets extends Instantiable { * @param {Metadata} metadata DDO metadata. * @param {Account} publisher Publisher account. * @param {list} services list of Service description documents + * @param {String} dtAddress existing Data Token Address + * @param {String} cap Maximum cap (Number) - will be converted to wei + * @param {String} name Token name + * @param {String} symbol Token symbol * @return {Promise} */ public create( @@ -57,9 +61,9 @@ export class Assets extends Instantiable { publisher: Account, services: Service[] = [], dtAddress?: string, + cap?: string, name?: string, - symbol?: string, - cap?: string + symbol?: string ): SubscribablePromise { this.logger.log('Creating asset') return new SubscribablePromise(async (observer) => { @@ -68,19 +72,16 @@ export class Assets extends Instantiable { } if (!dtAddress) { this.logger.log('Creating datatoken') - if (!name) name = 'DataToken' - if (!symbol) symbol = 'DT' - if (!cap) cap = '1410000000000000000000000000' observer.next(CreateProgressStep.CreatingDataToken) const metadataStoreURI = this.ocean.metadatastore.getURI() const jsonBlob = { t: 1, url: metadataStoreURI } const { datatokens } = this.ocean dtAddress = await datatokens.create( JSON.stringify(jsonBlob), - name, - symbol, + publisher.getId(), cap, - publisher.getId() + name, + symbol ) this.logger.log('DataToken creted') observer.next(CreateProgressStep.DataTokenCreated) From a3a772c92ebb5585f965df3f180633f285d949c7 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Thu, 3 Sep 2020 11:40:04 +0200 Subject: [PATCH 03/10] update tests --- test/unit/Datatokens.test.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/unit/Datatokens.test.ts b/test/unit/Datatokens.test.ts index 2e1a9dfe..7ab31907 100644 --- a/test/unit/Datatokens.test.ts +++ b/test/unit/Datatokens.test.ts @@ -45,7 +45,12 @@ describe('DataTokens', () => { }) it('should create datatokens smart contract', async () => { - tokenAddress = await datatoken.create(blob, 'AliceDT', 'DTA', '10000000000', minter) + tokenAddress = await datatoken.create(blob, minter, '10000000000', 'AliceDT', 'DTA') + assert(tokenAddress !== null) + }) + + it('should create datatokens with fallback cap, name & symbol', async () => { + tokenAddress = await datatoken.create(blob, minter) assert(tokenAddress !== null) }) From 2521866e92f36e09e5dbf672fd9b15282a3d8c85 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Thu, 3 Sep 2020 11:53:24 +0200 Subject: [PATCH 04/10] more test updates --- test/unit/Datatokens.test.ts | 25 +++++++++++-------- test/unit/balancer/Balancer.test.ts | 37 +++++++++++++++-------------- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/test/unit/Datatokens.test.ts b/test/unit/Datatokens.test.ts index 7ab31907..d70cef9f 100644 --- a/test/unit/Datatokens.test.ts +++ b/test/unit/Datatokens.test.ts @@ -10,13 +10,13 @@ import datatokensTemplate from '@oceanprotocol/contracts/artifacts/DataTokenTemp const web3 = new Web3('http://127.0.0.1:8545') describe('DataTokens', () => { - let minter - let spender - let balance - let contracts - let datatoken - let tokenAddress - const tokenAmount = 100 + let minter: string + let spender: string + let balance: string + let contracts: TestContractHandler + let datatoken: DataTokens + let tokenAddress: string + const tokenAmount = '100' const blob = 'https://example.com/dataset-1' describe('#test', () => { @@ -52,18 +52,23 @@ describe('DataTokens', () => { it('should create datatokens with fallback cap, name & symbol', async () => { tokenAddress = await datatoken.create(blob, minter) 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 () => { await datatoken.mint(tokenAddress, minter, tokenAmount) balance = await datatoken.balance(tokenAddress, minter) - assert(balance.toString() === tokenAmount.toString()) + assert(balance === tokenAmount) }) it('should transfer datatokens', async () => { await datatoken.transfer(tokenAddress, spender, tokenAmount, minter) balance = await datatoken.balance(tokenAddress, spender) - assert(balance.toString() === tokenAmount.toString()) + assert(balance === tokenAmount) }) it('should approve datatokens transfer', async () => { @@ -73,7 +78,7 @@ describe('DataTokens', () => { it('should transferFrom datatokens', async () => { await datatoken.transferFrom(tokenAddress, spender, tokenAmount, minter) balance = await datatoken.balance(tokenAddress, minter) - assert(balance.toString() === tokenAmount.toString()) + assert(balance === tokenAmount) }) }) }) diff --git a/test/unit/balancer/Balancer.test.ts b/test/unit/balancer/Balancer.test.ts index 4d4a6ab5..18a2a3b2 100644 --- a/test/unit/balancer/Balancer.test.ts +++ b/test/unit/balancer/Balancer.test.ts @@ -17,21 +17,22 @@ const web3 = new Web3('http://127.0.0.1:8545') describe('Balancer flow', () => { let oceanTokenAddress let OceanPoolFactoryAddress - let Pool - let oceandatatoken + let Pool: OceanPool + let oceandatatoken: DataTokens let alicePoolAddress let currentDtPrice - let owner - let bob - let alice - let contracts - let datatoken - let tokenAddress + let owner: string + let bob: string + let alice: string + let contracts: TestContractHandler + let datatoken: DataTokens + let tokenAddress: string let consoleDebug: false let greatPool const tokenAmount = '1000' const transferAmount = '200' const blob = 'http://localhost:8030/api/v1/services/consume' + describe('#test', () => { before(async () => { // deploy SFactory @@ -74,7 +75,7 @@ describe('Balancer flow', () => { }) 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) }) it('Create a dummy OceanToken', async () => { @@ -87,10 +88,10 @@ describe('Balancer flow', () => { ) oceanTokenAddress = await oceandatatoken.create( blob, - 'AliceDT2', - 'DTA2', + alice, '10000000000', - alice + 'AliceDT2', + 'DTA2' ) }) it('should initialize OceanPool class', async () => { @@ -137,19 +138,19 @@ describe('Balancer flow', () => { }) it('Get dtToken pool reserve ', async () => { const currentDtReserve = await Pool.getDTReserve(alice, alicePoolAddress) - assert(currentDtReserve > 0) + assert(Number(currentDtReserve) > 0) }) it('Get Ocean pool reserve ', async () => { const currentOceanReserve = await Pool.getOceanReserve(alice, alicePoolAddress) - assert(currentOceanReserve > 0) + assert(Number(currentOceanReserve) > 0) }) it('Get total supply of pool tokens', async () => { const totalSupply = await Pool.totalSupply(alicePoolAddress) - assert(totalSupply > 0) + assert(Number(totalSupply) > 0) }) it('Get amount of Ocean needed to buy 1 dtToken', async () => { 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 () => { @@ -162,8 +163,8 @@ describe('Balancer flow', () => { await Pool.buyDT(bob, greatPool, '1', '2', String(maxPrice)) const bobDtBalance = await datatoken.balance(tokenAddress, bob) const bobOceanBalance = await datatoken.balance(oceanTokenAddress, bob) - assert(bobDtBalance > 0) - assert(bobOceanBalance > 0) + assert(Number(bobDtBalance) > 0) + assert(Number(bobOceanBalance) > 0) }) it('Bob should add DT liquidity to pool ', async () => { const currentDtReserve = await Pool.getDTReserve(bob, greatPool) From ca5e810eb2d0ccc8d733282c0b2d04b8cb0a1b68 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Thu, 3 Sep 2020 12:07:18 +0200 Subject: [PATCH 05/10] and some more tests --- test/integration/ComputeFlow.test.ts | 6 +++--- test/integration/Marketplaceflow.test.ts | 6 +++--- test/integration/Simpleflow.test.ts | 2 +- test/unit/exchanges/FixedPriceExchange.test.ts | 12 ++++++------ 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/test/integration/ComputeFlow.test.ts b/test/integration/ComputeFlow.test.ts index 3ae5e799..a412dbda 100644 --- a/test/integration/ComputeFlow.test.ts +++ b/test/integration/ComputeFlow.test.ts @@ -81,10 +81,10 @@ describe('Compute flow', () => { ) tokenAddress = await datatoken.create( blob, - 'AliceDT', - 'DTA', + alice.getId(), '10000000000', - alice.getId() + 'AliceDT', + 'DTA' ) assert(tokenAddress != null) }) diff --git a/test/integration/Marketplaceflow.test.ts b/test/integration/Marketplaceflow.test.ts index 480f6ece..a88bf697 100644 --- a/test/integration/Marketplaceflow.test.ts +++ b/test/integration/Marketplaceflow.test.ts @@ -59,10 +59,10 @@ describe('Marketplace flow', () => { ) tokenAddress = await datatoken.create( blob, - 'AliceDT', - 'DTA', + alice.getId(), '10000000000', - alice.getId() + 'AliceDT', + 'DTA' ) assert(tokenAddress != null) }) diff --git a/test/integration/Simpleflow.test.ts b/test/integration/Simpleflow.test.ts index bddfacc5..427a76a8 100644 --- a/test/integration/Simpleflow.test.ts +++ b/test/integration/Simpleflow.test.ts @@ -41,7 +41,7 @@ describe('Simple flow', () => { datatokensTemplate.abi as AbiItem[], web3 ) - tokenAddress = await datatoken.create(blob, 'AliceDT', 'DTA', '10000000000', alice) + tokenAddress = await datatoken.create(blob, alice, '10000000000', 'AliceDT', 'DTA') }) it('Alice mints 100 tokens', async () => { await datatoken.mint(tokenAddress, alice, tokenAmount) diff --git a/test/unit/exchanges/FixedPriceExchange.test.ts b/test/unit/exchanges/FixedPriceExchange.test.ts index 95011b03..0bfbe434 100644 --- a/test/unit/exchanges/FixedPriceExchange.test.ts +++ b/test/unit/exchanges/FixedPriceExchange.test.ts @@ -81,10 +81,10 @@ describe('FixedRateExchange flow', () => { it('should create datatokens smart contract', async () => { tokenAddress = await datatoken.create( blob, - 'AliceDT', - 'DTA', + alice, web3.utils.toWei('1000000000000000'), - alice + 'AliceDT', + 'DTA' ) assert(tokenAddress !== null) if (consoleDebug) console.log("Alice's address:" + alice) @@ -100,10 +100,10 @@ describe('FixedRateExchange flow', () => { ) oceanTokenAddress = await oceandatatoken.create( blob, - 'BobDT', - 'DTB', + bob, web3.utils.toWei('1000000000000000'), - bob + 'BobDT', + 'DTB' ) if (consoleDebug) console.log("Bob's address:" + bob) if (consoleDebug) console.log('oceanTokenAddress:' + oceanTokenAddress) From 31bec3c7afc8d975c0a5331aff4fd8c0e08958ce Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Thu, 3 Sep 2020 12:28:27 +0200 Subject: [PATCH 06/10] change glob for unit tests * this prevented test files at top of test/unit/ from running * more info: https://mochajs.org/#the-test-directory --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e5ea223e..9733091f 100644 --- a/package.json +++ b/package.json @@ -20,8 +20,8 @@ "release": "release-it --non-interactive", "changelog": "auto-changelog -p", "prepublishOnly": "npm run build", - "test:unit": "mocha --config=test/unit/.mocharc.json --node-env=test --exit test/unit/**/*.ts", - "test:integration": "mocha --config=test/integration/.mocharc.json --node-env=test --exit test/integration/*.ts", + "test:unit": "mocha --config=test/unit/.mocharc.json --node-env=test --exit 'test/unit/**/*.test.ts'", + "test:integration": "mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/**/*.test.ts'", "test:cover": "nyc --report-dir coverage/unit npm run test:unit" }, "repository": { From 1c60e115555b5f7fa93014f15628ec4cc96cec65 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Thu, 3 Sep 2020 12:52:55 +0200 Subject: [PATCH 07/10] fix previously not running tests --- test/unit/ocean/utils/SignatureUtils.test.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/unit/ocean/utils/SignatureUtils.test.ts b/test/unit/ocean/utils/SignatureUtils.test.ts index 91aaea1f..77ef79fa 100644 --- a/test/unit/ocean/utils/SignatureUtils.test.ts +++ b/test/unit/ocean/utils/SignatureUtils.test.ts @@ -1,22 +1,22 @@ import { assert, expect, spy, use } from 'chai' import spies from 'chai-spies' import Web3 from 'web3' -import config from '../../config' - -import { Ocean } from '../../../../src/ocean/Ocean' +import { SignatureUtils } from '../../../../src/ocean/utils/SignatureUtils' +import { Logger } from '../../../../src/utils' use(spies) +const web3 = new Web3('http://127.0.0.1:8545') + describe('SignatureUtils', () => { const publicKey = `0x${'a'.repeat(40)}` const text = '0123456789abcde' const signature = `0x${'a'.repeat(130)}` - let web3: Web3 - let ocean: Ocean + + let signatureUtils: SignatureUtils before(async () => { - ocean = await Ocean.getInstance(config) - web3 = (ocean as any).web3 + signatureUtils = new SignatureUtils(web3, new Logger()) }) afterEach(() => { @@ -31,14 +31,14 @@ describe('SignatureUtils', () => { }) it('should sign a text as expected', async () => { - const signed = await ocean.utils.signature.signText(text, publicKey) + const signed = await signatureUtils.signText(text, publicKey) assert.equal(signed, signature) expect(personalSignSpy).to.have.been.called.with(text, publicKey) }) it('should sign a text as expected using password', async () => { - const signed = await ocean.utils.signature.signText(text, publicKey, 'test') + const signed = await signatureUtils.signText(text, publicKey, 'test') assert.equal(signed, signature) expect(personalSignSpy).to.have.been.called.with(text, publicKey, 'test') @@ -49,7 +49,7 @@ describe('SignatureUtils', () => { it('should recover the privateKey of a signed message', async () => { const personalRecoverSpy = spy.on(web3.eth.personal, 'ecRecover', () => publicKey) - const verifiedPublicKey = await ocean.utils.signature.verifyText(text, signature) + const verifiedPublicKey = await signatureUtils.verifyText(text, signature) assert.equal(publicKey, verifiedPublicKey) expect(personalRecoverSpy).to.have.been.called.with(text, signature) From e4a8a83674947cac9150dcb0d2a4afb931e27ad5 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Thu, 3 Sep 2020 13:09:55 +0200 Subject: [PATCH 08/10] test cleanup --- test/unit/exchanges/FixedPriceExchange.test.ts | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/test/unit/exchanges/FixedPriceExchange.test.ts b/test/unit/exchanges/FixedPriceExchange.test.ts index 0bfbe434..ed59e32b 100644 --- a/test/unit/exchanges/FixedPriceExchange.test.ts +++ b/test/unit/exchanges/FixedPriceExchange.test.ts @@ -3,16 +3,12 @@ import { AbiItem } from 'web3-utils/types' import { TestContractHandler } from '../../TestContractHandler' import { FixedPricedContractHandler } from '../../FixedPriceContractHandler' import { DataTokens } from '../../../src/datatokens/Datatokens' -import { - OceanFixedRateExchange, - FixedPricedExchange -} from '../../../src/exchange/FixedRateExchange' +import { OceanFixedRateExchange } from '../../../src/exchange/FixedRateExchange' import Web3 from 'web3' import factory from '@oceanprotocol/contracts/artifacts/DTFactory.json' import datatokensTemplate from '@oceanprotocol/contracts/artifacts/DataTokenTemplate.json' -import BigNumber from 'bignumber.js' import FixedRateExchangeContract = require('@oceanprotocol/contracts/artifacts/FixedRateExchange.json') const web3 = new Web3('http://127.0.0.1:8545') @@ -27,13 +23,10 @@ describe('FixedRateExchange flow', () => { let datatoken let tokenAddress - let alicePoolAddress - let currentDtPrice let owner let contracts const consoleDebug = false - let greatPool const tokenAmount = '1000000000000000000000000000000000' const fixedPriceRate = '0.5' const updatedPriceRate = '2' @@ -82,7 +75,7 @@ describe('FixedRateExchange flow', () => { tokenAddress = await datatoken.create( blob, alice, - web3.utils.toWei('1000000000000000'), + '1000000000000000', 'AliceDT', 'DTA' ) @@ -101,7 +94,7 @@ describe('FixedRateExchange flow', () => { oceanTokenAddress = await oceandatatoken.create( blob, bob, - web3.utils.toWei('1000000000000000'), + '1000000000000000', 'BobDT', 'DTB' ) From eda950101056ae4fdfc76235ad24fa397ab7d219 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Thu, 3 Sep 2020 13:23:14 +0200 Subject: [PATCH 09/10] test fixes --- .../unit/exchanges/FixedPriceExchange.test.ts | 15 +++++++----- test/unit/ocean/Ocean.test.ts | 23 +++++++------------ 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/test/unit/exchanges/FixedPriceExchange.test.ts b/test/unit/exchanges/FixedPriceExchange.test.ts index ed59e32b..3c02e88f 100644 --- a/test/unit/exchanges/FixedPriceExchange.test.ts +++ b/test/unit/exchanges/FixedPriceExchange.test.ts @@ -16,22 +16,23 @@ describe('FixedRateExchange flow', () => { let oceanTokenAddress let FixedRateExchangeAddress let FixedRateClass - let oceandatatoken + let oceandatatoken: DataTokens let aliceExchangeId - let bob - let alice - let datatoken + let bob: string + let alice: string + let datatoken: DataTokens let tokenAddress let owner - let contracts + let contracts: TestContractHandler const consoleDebug = false - const tokenAmount = '1000000000000000000000000000000000' + const tokenAmount = '1000' const fixedPriceRate = '0.5' const updatedPriceRate = '2' const swapAmount = '1' const blob = 'http://localhost:8030/api/v1/services/consume' + describe('#test', () => { before(async () => { // deploy SFactory @@ -125,10 +126,12 @@ describe('FixedRateExchange flow', () => { it('Alice should have 1000 tokens', async () => { const balance = await datatoken.balance(tokenAddress, alice) if (consoleDebug) console.log("Alice's datatoke balance:" + balance) + assert(balance === tokenAmount) }) it('Bob should have 1000 ocean tokens', async () => { const balance = await oceandatatoken.balance(oceanTokenAddress, bob) if (consoleDebug) console.log("Bob's ocean balance:" + balance) + assert(balance === tokenAmount) }) it('Alice allows Exchange to spend 1000 data tokens', async () => { const txid = await datatoken.approve( diff --git a/test/unit/ocean/Ocean.test.ts b/test/unit/ocean/Ocean.test.ts index 7896759a..1207d541 100644 --- a/test/unit/ocean/Ocean.test.ts +++ b/test/unit/ocean/Ocean.test.ts @@ -15,26 +15,19 @@ describe('Ocean', () => { // ocean = await Ocean.getInstance(config) }) - beforeEach(async () => { - // spy.on(ocean.utils.signature, 'signText', () => `0x${'a'.repeat(130)}`) - }) - afterEach(() => { - // spy.restore() - }) - describe('#getInstance()', () => { it('should get an instance of Ocean', async () => { - // const oceanInstance: Ocean = await Ocean.getInstance(config) - // assert(oceanInstance) + const oceanInstance: Ocean = await Ocean.getInstance(config) + assert(oceanInstance) }) }) describe('#getAccounts()', () => { - it('should list accounts', async () => { - // const accs: Account[] = await ocean.accounts.list() - // assert(accs.length === 10) - // assert((await accs[5].getBalance()).ocn === 0) - // assert(typeof accs[0].getId() === 'string') - }) + // 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') + // }) }) }) From 0699792a1449799bb9cc9cb1d0f57a2775017ff0 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Fri, 4 Sep 2020 10:28:42 +0200 Subject: [PATCH 10/10] set default data token cap to 1000 --- src/datatokens/Datatokens.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/datatokens/Datatokens.ts b/src/datatokens/Datatokens.ts index e9666782..2a12f38c 100644 --- a/src/datatokens/Datatokens.ts +++ b/src/datatokens/Datatokens.ts @@ -76,7 +76,7 @@ export class DataTokens { name?: string, symbol?: string ): Promise { - if (!cap) cap = '1410000000000000000000000000' + if (!cap) cap = '1000' // Generate name & symbol if not present if (!name || !symbol) {