-
Notifications
You must be signed in to change notification settings - Fork 778
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Vitest/ESM: VM File Path Additions and Ethash Transition (#2786)
* VM: fix linting * VM: add .js path references * Ethash: tape -> vitest transition * Ethash: ad .js file path references
- Loading branch information
Showing
17 changed files
with
209 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
}, | ||
"license": "MPL-2.0", | ||
"author": "mjbecze <[email protected]>", | ||
"type": "module", | ||
"main": "dist/cjs/index.js", | ||
"module": "dist/esm/index.js", | ||
"exports": { | ||
|
@@ -32,14 +33,13 @@ | |
"scripts": { | ||
"build": "../../config/cli/ts-build.sh", | ||
"clean": "../../config/cli/clean-package.sh", | ||
"coverage": "../../config/cli/coverage.sh", | ||
"coverage": "npx vitest run --coverage.enabled --coverage.reporter=lcov", | ||
"docs:build": "typedoc --options typedoc.js", | ||
"lint": "../../config/cli/lint.sh", | ||
"lint:diff": "../../config/cli/lint-diff.sh", | ||
"lint:fix": "../../config/cli/lint-fix.sh", | ||
"prepublishOnly": "../../config/cli/prepublish.sh", | ||
"tape": "tape -r ts-node/register", | ||
"test": "tape -r ts-node/register test/*.spec.ts", | ||
"test": "npx vitest run --testTimeout=30000", | ||
"tsc": "../../config/cli/ts-compile.sh" | ||
}, | ||
"dependencies": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,37 @@ | ||
import { BlockHeader } from '@ethereumjs/block' | ||
import { Chain, Common, Hardfork } from '@ethereumjs/common' | ||
import { bytesToHex } from '@ethereumjs/util' | ||
import { hexToBytes } from 'ethereum-cryptography/utils' | ||
import * as tape from 'tape' | ||
import { hexToBytes } from 'ethereum-cryptography/utils.js' | ||
import { assert, describe, it } from 'vitest' | ||
|
||
import { Ethash } from '../src' | ||
import { getCacheSize, getEpoc, getFullSize } from '../src/util' | ||
import { Ethash } from '../src/index.js' | ||
import { getCacheSize, getEpoc, getFullSize } from '../src/util.js' | ||
|
||
const powTests = require('./ethash_tests.json') | ||
|
||
const ethash = new Ethash() | ||
const tests = Object.keys(powTests) | ||
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul }) | ||
|
||
tape('POW tests', async function (t) { | ||
for (const key of tests) { | ||
const test = powTests[key] | ||
const header = BlockHeader.fromRLPSerializedHeader(hexToBytes(test.header), { common }) | ||
describe('POW tests', () => { | ||
it('should work', async () => { | ||
for (const key of tests) { | ||
const test = powTests[key] | ||
const header = BlockHeader.fromRLPSerializedHeader(hexToBytes(test.header), { common }) | ||
|
||
const headerHash = ethash.headerHash(header.raw()) | ||
t.equal(bytesToHex(headerHash), test.header_hash, 'generate header hash') | ||
const headerHash = ethash.headerHash(header.raw()) | ||
assert.equal(bytesToHex(headerHash), test.header_hash, 'generate header hash') | ||
|
||
const epoc = getEpoc(header.number) | ||
t.equal(await getCacheSize(epoc), test.cache_size, 'generate cache size') | ||
t.equal(await getFullSize(epoc), test.full_size, 'generate full cache size') | ||
const epoc = getEpoc(header.number) | ||
assert.equal(await getCacheSize(epoc), test.cache_size, 'generate cache size') | ||
assert.equal(await getFullSize(epoc), test.full_size, 'generate full cache size') | ||
|
||
ethash.mkcache(test.cache_size, hexToBytes(test.seed)) | ||
t.equal(bytesToHex(ethash.cacheHash()), test.cache_hash, 'generate cache') | ||
ethash.mkcache(test.cache_size, hexToBytes(test.seed)) | ||
assert.equal(bytesToHex(ethash.cacheHash()), test.cache_hash, 'generate cache') | ||
|
||
const r = ethash.run(headerHash, hexToBytes(test.nonce), test.full_size) | ||
t.equal(bytesToHex(r.hash), test.result, 'generate result') | ||
t.equal(bytesToHex(r.mix), test.mixHash, 'generate mix hash') | ||
} | ||
const r = ethash.run(headerHash, hexToBytes(test.nonce), test.full_size) | ||
assert.equal(bytesToHex(r.hash), test.result, 'generate result') | ||
assert.equal(bytesToHex(r.mix), test.mixHash, 'generate mix hash') | ||
} | ||
}) | ||
}) |
Oops, something went wrong.