Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Upgrade test suite to TS #106

Merged
merged 3 commits into from
Mar 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 0 additions & 52 deletions benchmarks/checkpointing.js

This file was deleted.

60 changes: 60 additions & 0 deletions benchmarks/checkpointing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import * as async from 'async'
import * as crypto from 'crypto'
const Trie = require('../dist/index.js').CheckpointTrie

let iterations = 500
let samples = 20
let i = 0

function iterTest(numOfIter: number, cb: Function) {
let vals = [] as any
let keys = [] as any

for (i = 0; i <= numOfIter; i++) {
vals.push(crypto.pseudoRandomBytes(32))
keys.push(crypto.pseudoRandomBytes(32))
}

let hrstart = process.hrtime()
let numOfOps = 0
let trie = new Trie()

for (i = 0; i < numOfIter; i++) {
trie.put(vals[i], keys[i], function () {
trie.checkpoint()
trie.get(Buffer.from('test'), function () {
numOfOps++
if (numOfOps === numOfIter) {
const hrend = process.hrtime(hrstart)
cb(hrend)
}
})
})
}
}

i = 0
let avg = [0, 0]

async.whilst(
function () {
i++
return i <= samples
},
function (done) {
iterTest(iterations, function (hrend: Array<number>) {
avg[0] += hrend[0]
avg[1] += hrend[1]

console.info('Execution time (hr): %ds %dms', hrend[0], hrend[1] / 1000000)
done()
})
},
function () {
console.info(
'Average Execution time (hr): %ds %dms',
avg[0] / samples,
avg[1] / 1000000 / samples,
)
},
)
holgerd77 marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions benchmarks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require('./checkpointing')
require('./random')
15 changes: 8 additions & 7 deletions benchmarks/random.js → benchmarks/random.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
// https://github.com/ethereum/wiki/wiki/Benchmarks
'use strict'
const Trie = require('../')
const ethUtil = require('ethereumjs-util')
const async = require('async')
import * as async from 'async'
import * as ethUtil from 'ethereumjs-util'
const Trie = require('../dist/index.js').BaseTrie

const ROUNDS = 1000
const SYMMETRIC = true
const ERA_SIZE = 1000

let trie = new Trie()
let seed = new Buffer(32).fill(0)
let seed = Buffer.alloc(32).fill(0)

let testName = 'rounds ' + ROUNDS + ' ' + ERA_SIZE + ' ' + SYMMETRIC ? 'sys' : 'rand'
console.time(testName)
run(() => {
console.timeEnd(testName)
})

function run (cb) {
function run(cb: any) {
let i = 0
async.whilst(
() => {
Expand All @@ -33,12 +33,13 @@ function run (cb) {
trie.put(seed, val, genRoot)
}

function genRoot () {
function genRoot() {
if (i % ERA_SIZE === 0) {
seed = trie.root
}
done()
}
}, cb
},
cb,
)
}
20 changes: 10 additions & 10 deletions docs/classes/_basetrie_.trie.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ ___

### del

▸ **del**(`key`: Buffer, `cb`: Function): *void*
▸ **del**(`key`: Buffer, `cb`: ErrorCallback): *void*

*Defined in [baseTrie.ts:183](https://github.com/ethereumjs/merkle-patricia-tree/blob/master/src/baseTrie.ts#L183)*

Expand All @@ -406,7 +406,7 @@ deletes a value given a `key`
Name | Type |
------ | ------ |
`key` | Buffer |
`cb` | Function |
`cb` | ErrorCallback |

**Returns:** *void*

Expand Down Expand Up @@ -459,7 +459,7 @@ ___

### get

▸ **get**(`key`: Buffer, `cb`: Function): *void*
▸ **get**(`key`: Buffer, `cb`: BufferCallback): *void*

*Defined in [baseTrie.ts:125](https://github.com/ethereumjs/merkle-patricia-tree/blob/master/src/baseTrie.ts#L125)*

Expand All @@ -474,15 +474,15 @@ Gets a value given a `key`
Name | Type | Description |
------ | ------ | ------ |
`key` | Buffer | the key to search for |
`cb` | Function | A callback `Function` which is given the arguments `err` - for errors that may have occured and `value` - the found value in a `Buffer` or if no value was found `null` |
`cb` | BufferCallback | A callback `Function` which is given the arguments `err` - for errors that may have occured and `value` - the found value in a `Buffer` or if no value was found `null` |

**Returns:** *void*

___

### getRaw

▸ **getRaw**(`key`: Buffer, `cb`: Function): *void*
▸ **getRaw**(`key`: Buffer, `cb`: BufferCallback): *void*

*Defined in [baseTrie.ts:208](https://github.com/ethereumjs/merkle-patricia-tree/blob/master/src/baseTrie.ts#L208)*

Expand All @@ -495,7 +495,7 @@ Retrieves a value directly from key/value db.
Name | Type |
------ | ------ |
`key` | Buffer |
`cb` | Function |
`cb` | BufferCallback |

**Returns:** *void*

Expand Down Expand Up @@ -584,7 +584,7 @@ ___

### `Static` prove

▸ **prove**(`trie`: [Trie](_basetrie_.trie.md), `key`: Buffer, `cb`: Function): *void*
▸ **prove**(`trie`: [Trie](_basetrie_.trie.md), `key`: Buffer, `cb`: ProveCallback): *void*

*Defined in [baseTrie.ts:70](https://github.com/ethereumjs/merkle-patricia-tree/blob/master/src/baseTrie.ts#L70)*

Expand All @@ -594,15 +594,15 @@ Name | Type |
------ | ------ |
`trie` | [Trie](_basetrie_.trie.md) |
`key` | Buffer |
`cb` | Function |
`cb` | ProveCallback |

**Returns:** *void*

___

### `Static` verifyProof

▸ **verifyProof**(`rootHash`: Buffer, `key`: Buffer, `proofNodes`: Buffer[], `cb`: Function): *void*
▸ **verifyProof**(`rootHash`: Buffer, `key`: Buffer, `proofNodes`: Buffer[], `cb`: BufferCallback): *void*

*Defined in [baseTrie.ts:85](https://github.com/ethereumjs/merkle-patricia-tree/blob/master/src/baseTrie.ts#L85)*

Expand All @@ -613,6 +613,6 @@ Name | Type |
`rootHash` | Buffer |
`key` | Buffer |
`proofNodes` | Buffer[] |
`cb` | Function |
`cb` | BufferCallback |

**Returns:** *void*
24 changes: 12 additions & 12 deletions docs/classes/_checkpointtrie_.checkpointtrie.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ ___

▸ **_createScratchReadStream**(`scratch`: ScratchDB): *ScratchReadStream‹›*

*Defined in [checkpointTrie.ts:154](https://github.com/ethereumjs/merkle-patricia-tree/blob/master/src/checkpointTrie.ts#L154)*
*Defined in [checkpointTrie.ts:152](https://github.com/ethereumjs/merkle-patricia-tree/blob/master/src/checkpointTrie.ts#L152)*

Returns a `ScratchReadStream` based on the state updates
since checkpoint.
Expand Down Expand Up @@ -301,7 +301,7 @@ ___

*Overrides [Trie](_basetrie_.trie.md).[_formatNode](_basetrie_.trie.md#_formatnode)*

*Defined in [checkpointTrie.ts:163](https://github.com/ethereumjs/merkle-patricia-tree/blob/master/src/checkpointTrie.ts#L163)*
*Defined in [checkpointTrie.ts:161](https://github.com/ethereumjs/merkle-patricia-tree/blob/master/src/checkpointTrie.ts#L161)*

**Parameters:**

Expand Down Expand Up @@ -563,7 +563,7 @@ ___

### del

▸ **del**(`key`: Buffer, `cb`: Function): *void*
▸ **del**(`key`: Buffer, `cb`: ErrorCallback): *void*

*Inherited from [Trie](_basetrie_.trie.md).[del](_basetrie_.trie.md#del)*

Expand All @@ -580,7 +580,7 @@ deletes a value given a `key`
Name | Type |
------ | ------ |
`key` | Buffer |
`cb` | Function |
`cb` | ErrorCallback |

**Returns:** *void*

Expand Down Expand Up @@ -637,7 +637,7 @@ ___

### get

▸ **get**(`key`: Buffer, `cb`: Function): *void*
▸ **get**(`key`: Buffer, `cb`: BufferCallback): *void*

*Inherited from [Trie](_basetrie_.trie.md).[get](_basetrie_.trie.md#get)*

Expand All @@ -654,15 +654,15 @@ Gets a value given a `key`
Name | Type | Description |
------ | ------ | ------ |
`key` | Buffer | the key to search for |
`cb` | Function | A callback `Function` which is given the arguments `err` - for errors that may have occured and `value` - the found value in a `Buffer` or if no value was found `null` |
`cb` | BufferCallback | A callback `Function` which is given the arguments `err` - for errors that may have occured and `value` - the found value in a `Buffer` or if no value was found `null` |

**Returns:** *void*

___

### getRaw

▸ **getRaw**(`key`: Buffer, `cb`: Function): *void*
▸ **getRaw**(`key`: Buffer, `cb`: BufferCallback): *void*

*Inherited from [Trie](_basetrie_.trie.md).[getRaw](_basetrie_.trie.md#getraw)*

Expand All @@ -677,7 +677,7 @@ Retrieves a value directly from key/value db.
Name | Type |
------ | ------ |
`key` | Buffer |
`cb` | Function |
`cb` | BufferCallback |

**Returns:** *void*

Expand Down Expand Up @@ -794,7 +794,7 @@ ___

### `Static` prove

▸ **prove**(`trie`: [Trie](_basetrie_.trie.md), `key`: Buffer, `cb`: Function): *void*
▸ **prove**(`trie`: [Trie](_basetrie_.trie.md), `key`: Buffer, `cb`: ProveCallback): *void*

*Inherited from [Trie](_basetrie_.trie.md).[prove](_basetrie_.trie.md#static-prove)*

Expand All @@ -806,15 +806,15 @@ Name | Type |
------ | ------ |
`trie` | [Trie](_basetrie_.trie.md) |
`key` | Buffer |
`cb` | Function |
`cb` | ProveCallback |

**Returns:** *void*

___

### `Static` verifyProof

▸ **verifyProof**(`rootHash`: Buffer, `key`: Buffer, `proofNodes`: Buffer[], `cb`: Function): *void*
▸ **verifyProof**(`rootHash`: Buffer, `key`: Buffer, `proofNodes`: Buffer[], `cb`: BufferCallback): *void*

*Inherited from [Trie](_basetrie_.trie.md).[verifyProof](_basetrie_.trie.md#static-verifyproof)*

Expand All @@ -827,6 +827,6 @@ Name | Type |
`rootHash` | Buffer |
`key` | Buffer |
`proofNodes` | Buffer[] |
`cb` | Function |
`cb` | BufferCallback |

**Returns:** *void*
Loading