Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dropping ethereumjs-testing dependency #953

Merged
merged 17 commits into from
Nov 16, 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
4 changes: 3 additions & 1 deletion .github/workflows/block-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- uses: actions/checkout@v1
- uses: actions/checkout@v2
with:
submodules: recursive

- name: Dependency cache
uses: actions/cache@v2
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/blockchain-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- uses: actions/checkout@v1
- uses: actions/checkout@v2
with:
submodules: recursive

- name: Dependency cache
uses: actions/cache@v2
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/common-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- uses: actions/checkout@v1
- uses: actions/checkout@v2
with:
submodules: recursive

- name: Dependency cache
uses: actions/cache@v2
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/ethash-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- uses: actions/checkout@v1
- uses: actions/checkout@v2
with:
submodules: recursive

- name: Dependency cache
uses: actions/cache@v2
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/tx-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- uses: actions/checkout@v1
- uses: actions/checkout@v2
with:
submodules: recursive

- name: Dependency cache
uses: actions/cache@v2
Expand Down
14 changes: 11 additions & 3 deletions .github/workflows/vm-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ jobs:
- uses: actions/setup-node@v1
with:
node-version: 12.x
- uses: actions/checkout@v1
- uses: actions/checkout@v2
with:
submodules: recursive

- name: Dependency cache
uses: actions/cache@v2
Expand Down Expand Up @@ -56,7 +58,9 @@ jobs:
- uses: actions/setup-node@v1
with:
node-version: 12.x
- uses: actions/checkout@v1
- uses: actions/checkout@v2
with:
submodules: recursive

- name: Dependency cache
uses: actions/cache@v2
Expand All @@ -83,7 +87,9 @@ jobs:
- uses: actions/setup-node@v1
with:
node-version: 12.x
- uses: actions/checkout@v1
- uses: actions/checkout@v2
with:
submodules: recursive

- name: Dependency cache
uses: actions/cache@v2
Expand Down Expand Up @@ -111,6 +117,8 @@ jobs:
with:
node-version: 12.x
- uses: actions/checkout@v2
with:
submodules: recursive

- name: Dependency cache
uses: actions/cache@v2
Expand Down
16 changes: 12 additions & 4 deletions .github/workflows/vm-nightly-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ jobs:
- uses: actions/setup-node@v1
with:
node-version: 12.x
- uses: actions/checkout@v1
- uses: actions/checkout@v2
with:
submodules: recursive

# This is specific to Nightly test 1/2.
# The job needs to run with a fresh combination of lockfiles, to warm up the cache.
Expand All @@ -42,7 +44,9 @@ jobs:
- uses: actions/setup-node@v1
with:
node-version: 12.x
- uses: actions/checkout@v1
- uses: actions/checkout@v2
with:
submodules: recursive

# This is specific to Nightly test 1/2.
# The job needs to run with a fresh combination of lockfiles, to warm up the cache.
Expand All @@ -66,7 +70,9 @@ jobs:
- uses: actions/setup-node@v1
with:
node-version: 12.x
- uses: actions/checkout@v1
- uses: actions/checkout@v2
with:
submodules: recursive

# This is specific to Nightly test 1/2.
# The job needs to run with a fresh combination of lockfiles, to warm up the cache.
Expand Down Expand Up @@ -101,7 +107,9 @@ jobs:
- uses: actions/setup-node@v1
with:
node-version: 12.x
- uses: actions/checkout@v1
- uses: actions/checkout@v2
with:
submodules: recursive

# This is specific to Nightly test 1/2.
# The job needs to run with a fresh combination of lockfiles, to warm up the cache.
Expand Down
14 changes: 11 additions & 3 deletions .github/workflows/vm-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ jobs:
- uses: actions/setup-node@v1
with:
node-version: 12.x
- uses: actions/checkout@v1
- uses: actions/checkout@v2
with:
submodules: recursive

- name: Dependency cache
uses: actions/cache@v2
Expand Down Expand Up @@ -68,7 +70,9 @@ jobs:
- uses: actions/setup-node@v1
with:
node-version: 12.x
- uses: actions/checkout@v1
- uses: actions/checkout@v2
with:
submodules: recursive

- name: Dependency cache
uses: actions/cache@v2
Expand Down Expand Up @@ -113,7 +117,9 @@ jobs:
- uses: actions/setup-node@v1
with:
node-version: 12.x
- uses: actions/checkout@v1
- uses: actions/checkout@v2
with:
submodules: recursive

- name: Dependency cache
uses: actions/cache@v2
Expand Down Expand Up @@ -141,6 +147,8 @@ jobs:
with:
node-version: 12.x
- uses: actions/checkout@v2
with:
submodules: recursive

- name: Dependency cache
uses: actions/cache@v2
Expand Down
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "ethereum-tests"]
path = ethereum-tests
url = https://github.com/ethereum/tests.git
branch = develop
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ https://mermaid-js.github.io/mermaid-live-editor/#/edit/eyJjb2RlIjoiZ3JhcGggVERc

## Development quick start

First, make sure you have the `ethereum-tests` git submodule, by running:

```sh
git submodule init
git submodule update
```

This monorepo uses [Lerna](https://lerna.js.org/). It links the local packages together, making development a lot easier.

TLDR: Setup
Expand Down
1 change: 1 addition & 0 deletions ethereum-tests
Submodule ethereum-tests added at bfcd07
2 changes: 1 addition & 1 deletion packages/tx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-implicit-dependencies": "^1.0.4",
"ethereumjs-testing": "git+https://github.com/ethereumjs/ethereumjs-testing.git#v1.3.3",
"istanbul": "^0.4.1",
"karma": "^5.2.1",
"karma-browserify": "^7.0.0",
"karma-chrome-launcher": "^3.1.0",
"karma-firefox-launcher": "^1.3.0",
"karma-tap": "^4.2.0",
"minimist": "^1.2.0",
"node-dir": "^0.1.17",
"nyc": "^14.0.0",
"prettier": "^2.0.5",
"tape": "^4.10.1",
Expand Down
166 changes: 166 additions & 0 deletions packages/tx/test/testLoader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
const fs = require('fs')
const dir = require('node-dir')
const path = require('path')

const falsePredicate = () => false
// Load tests from git submodule
const defaultTestsPath = path.resolve('../../ethereum-tests')
/**
* Returns the list of test files matching the given parameters
* @param testType the test type (path segment)
* @param onFile a callback for each file
* @param fileFilter a {@code RegExp} or array to specify filenames to operate on
* @param skipPredicate a filtering function for test names
* @param testDir the directory inside the {@code tests/} directory to use
* @param excludeDir a {@code RegExp} or array to specify directories to ignore
* @param testsPath the path to the {@code tests/} directory
* @return The list of test files
*/
const getTests = (exports.getTests = (
testType: string,
onFile: Function,
fileFilter: RegExp | string[] = /.json$/,
skipPredicate: Function = falsePredicate,
testDir: string = '',
excludeDir: RegExp | string[] = [],
testsPath: string = defaultTestsPath
): Promise<string[]> => {
const directory = path.join(testsPath, testType, testDir)
const options = {
match: fileFilter,
excludeDir: excludeDir,
}

return new Promise((resolve, reject) => {
const finishedCallback = (err: Error | undefined, files: string[]) => {
if (err) {
reject(err)
return
}

resolve(files)
}

const fileCallback = async (
err: Error | undefined,
content: string,
fileName: string,
next: Function
) => {
if (err) {
reject(err)
return
}

const parsedFileName = path.parse(fileName).name
const testsByName = JSON.parse(content)
const testNames = Object.keys(testsByName)
for (const testName of testNames) {
if (!skipPredicate(testName, testsByName[testName])) {
await onFile(parsedFileName, testName, testsByName[testName])
}
}

next()
}

dir.readFiles(directory, options, fileCallback, finishedCallback)
})
})

function skipTest(testName: string, skipList = []) {
return skipList
.map((skipName) => new RegExp(`^${skipName}`).test(testName))
.some((isMatch) => isMatch)
}

/**
* Loads a single test specified in a file
* @method getTestFromSource
* @param file or path to load a single test from
* @param Callback function which is invoked, and passed the contents of the specified file (or an error message)
*/
const getTestFromSource = (exports.getTestFromSource = function (file: string, onFile: Function) {
const stream = fs.createReadStream(file)
let contents = ''
let test: any = null

stream
.on('data', function (data: string) {
contents += data
})
.on('error', function (err: Error) {
// eslint-disable-next-line no-console
console.warn('♦︎ [WARN] Please check if submodule `ethereum-tests` is properly loaded.')
onFile(err)
})
.on('end', function () {
try {
test = JSON.parse(contents)
} catch (e) {
onFile(e)
}

const testName = Object.keys(test)[0]
const testData = test[testName]
testData.testName = testName

onFile(null, testData)
})
})

exports.getTestsFromArgs = function (testType: string, onFile: Function, args: any = {}) {
let testsPath, testDir, fileFilter, excludeDir, skipFn

skipFn = (name: string) => {
return skipTest(name, args.skipTests)
}
if (new RegExp(`BlockchainTests`).test(testType)) {
const forkFilter = new RegExp(`${args.forkConfig}$`)
skipFn = (name: string, test: any) => {
return forkFilter.test(test.network) === false || skipTest(name, args.skipTests)
}
}
if (new RegExp(`GeneralStateTests`).test(testType)) {
const forkFilter = new RegExp(`${args.forkConfig}$`)
skipFn = (name: string, test: any) => {
return (
Object.keys(test['post'])
.map((key) => forkFilter.test(key))
.every((e) => !e) || skipTest(name, args.skipTests)
)
}
}

if (args.singleSource) {
return getTestFromSource(args.singleSource, onFile)
}

if (args.dir) {
testDir = args.dir
}

if (args.file) {
fileFilter = new RegExp(args.file)
}

if (args.excludeDir) {
excludeDir = new RegExp(args.excludeDir)
}

if (args.test) {
skipFn = (testName: string) => {
return testName !== args.test
}
}

if (args.testsPath) {
testsPath = args.testsPath
}

return getTests(testType, onFile, fileFilter, skipFn, testDir, excludeDir, testsPath)
}

exports.getSingleFile = (file: string) => {
return require(path.join(defaultTestsPath, file))
}
3 changes: 1 addition & 2 deletions packages/tx/test/transactionRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import Common from '@ethereumjs/common'
import Transaction from '../src/transaction'
import { ForkName, ForkNamesMap, OfficialTransactionTestData } from './types'

// We use require here because this module doesn't have types and this works better with ts-node.
const testing = require('ethereumjs-testing')
const testing = require('./testLoader')

const argv = minimist(process.argv.slice(2))
const file: string | undefined = argv.file
Expand Down
Loading