Skip to content
This repository has been archived by the owner on Apr 6, 2020. It is now read-only.

Add tests for increased coverage #93

Merged
merged 1 commit into from
Feb 11, 2020
Merged

Add tests for increased coverage #93

merged 1 commit into from
Feb 11, 2020

Conversation

ryanio
Copy link
Contributor

@ryanio ryanio commented Feb 8, 2020

This PR adds tests for increased code coverage:

  • Adds BlockHeader validation test cases:
    • should validate a genesis block header
    • should validate a valid block header
    • should not validate a block header with invalid difficulty
    • should not validate a block header with invalid gas limit
    • should not validate a block header with invalid height
    • should not validate a block header with invalid timestamp
    • should not validate a block header with invalid parent
    • should not validate a header with invalid amount of extra data
  • Adds test for blockHeaderFromRpc:
    • should create a block header with the correct hash
  • Moves testdata json files to their own subdir to unclutter the parent test dir
  • Updates karma to run in both headless firefox and chrome
  • Modernizes the test and coverage command
  • Normalizes the readme badge style

st.end()
})

t.test('should validate a genesis block header', st => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new tests added in this PR start here ... sorry for diff, I renamed the files from test/*.ts to test/*.spec.ts

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know that renaming can also be done via git which should preserve the file comparison respectively did you try?

For now it's ok.

@@ -56,18 +55,19 @@
"@ethereumjs/config-prettier": "^1.1.1",
"@ethereumjs/config-tsc": "^1.1.1",
"@ethereumjs/config-tslint": "^1.1.1",
"@types/lru-cache": "^5.1.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found I had to add this type because ethereumjs-blockchain was failing to build in the browser. This might be good motivation to introduce a karma test runner for that repo to catch this and future issues.

The error encountered in karma was:

node_modules/ethereumjs-blockchain/dist/cache.d.ts:2:22 - error TS7016: Could not find a declaration file for module 'lru-cache'.

'/Users/rg/dev/ethereumjs-block/node_modules/ethereumjs-blockchain/node_modules/lru-cache/index.js' implicitly has an 'any' type.

  Try `npm install @types/lru-cache` if it exists or add a new declaration (.d.ts) file containing `declare module 'lru-cache';`

2 import * as LRU from 'lru-cache';

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think we should have karma tests along all (actively developed) libraries.

Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks Ryan for wandering with open eyes through the libraries, yes, we still have some cases with significant gaps in test coverage, good to have such a significant step up here.

Will approve and directly merge.

"karma-firefox-launcher": "^1.1.0",
"karma-tap": "^4.1.4",
"nyc": "^14.0.0",
"nyc": "^15.0.0",
"prettier": "^1.17.0",
"tape": "^4.0.3",
"ts-node": "^8.0.3",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All config-related stuff until here ok.

@@ -284,7 +284,7 @@ export class BlockHeader {
}

if (utils.bufferToInt(parentBlock.header.number) + 1 !== utils.bufferToInt(this.number)) {
throw new Error('invalid heigth')
throw new Error('invalid height')
}

if (utils.bufferToInt(this.timestamp) <= utils.bufferToInt(parentBlock.header.timestamp)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, some error message corrections.

mainnet: require('./difficultyMainNetwork.json').tests,
ropsten: require('./difficultyRopstenConstantinople.json').tests,
mainnet: require('./testdata/difficultyMainNetwork.json').tests,
ropsten: require('./testdata/difficultyRopstenConstantinople.json').tests,
}
for (const chain in chainTestData) {
const testData = chainTestData[chain]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, mainly shifts to testdata directory.

let block = blockHeaderFromRpc(blockData)
st.ok(block.hash().compare(Buffer.from(blockData.hash)))
st.end()
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

st.end()
})

t.test('should validate a genesis block header', st => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know that renaming can also be done via git which should preserve the file comparison respectively did you try?

For now it's ok.

st.fail(error)
st.end()
}
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

st.ok(true)
st.end()
}
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

st.end()
}
})
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants