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

Add basic API tests for re-exports #235

Merged
merged 1 commit into from
Feb 5, 2020
Merged

Add basic API tests for re-exports #235

merged 1 commit into from
Feb 5, 2020

Conversation

ryanio
Copy link
Contributor

@ryanio ryanio commented Feb 4, 2020

This PR adds some basic tests for the re-exports in the new test file externals.spec.ts:

  External BN export
    ✓ should export `BN`
    ✓ should use a BN function correctly
    ✓ should throw on exceptions

  External rlp export
    ✓ should export `rlp`
    ✓ should use a rlp function correctly
    ✓ should throw on exceptions

  External secp256k1 export
    ✓ should export `secp256k1`
    ✓ should use a secp256k1 function correctly
    ✓ should throw on exceptions

  External ethjsUtil export
    ✓ should have all ethjsUtil methods
    ✓ should use ethjsUtil functions correctly
    ✓ should handle exceptions and invalid inputs

Closes #234.

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.

Really nice selection of test cases, thanks, will approve and merge.

@@ -14,7 +14,7 @@ import { toBuffer, baToJSON, stripZeros } from './bytes'
* @param data data to be validated against the definitions
* @deprecated
*/
export const defineProperties = function(self: any, fields: any, data: any) {
export const defineProperties = function(self: any, fields: any, data?: any) {
Copy link
Member

Choose a reason for hiding this comment

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

For reference: if I understand correctly this is a correction of the API regarding the currently existing optionality of the data param within the function code. It can be regarded as a bug fix, but should be pointed out in the next release notes.

@@ -13,8 +14,7 @@ const {
isValidChecksumAddress,
isValidAddress,
toChecksumAddress,
} = require('../src')
import BN = require('bn.js')
} from '../src'
Copy link
Member

Choose a reason for hiding this comment

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

Some unrelated import improvements, nice, and justifiable since only touching the tests.

assert.equal(buf.toString('hex'), '5b9ac8')
})
})

Copy link
Member

Choose a reason for hiding this comment

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

These tests moved to the externals.spec.ts file, ok.

assert.throws(function() {
new src.BN(0).iaddn(0x4000000)
}, /^Error: Assertion failed$/)
})
Copy link
Member

Choose a reason for hiding this comment

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

Nice selection, ok.

For my understanding: what is this 0x4000000 case?

} catch (e) {}
assert.equal(res, undefined)
})
})
Copy link
Member

Choose a reason for hiding this comment

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

Ok.

For my understanding, assume some valid reasoning for it: the error cases can't be addressed with assert.throws?

src.secp256k1.privateKeyImport(buffer)
})
})
})
Copy link
Member

Choose a reason for hiding this comment

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

Ok.

assert.throws(() => (src as any).getKeys([], 3289), Error)

// should detect invalid length hex string
assert.equal((src as any).isHexString('0x0', 2), false)
Copy link
Member

Choose a reason for hiding this comment

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

Ok.

@holgerd77 holgerd77 merged commit 5553757 into master Feb 5, 2020
@holgerd77 holgerd77 deleted the externalTests branch February 5, 2020 11:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add basic API tests for re-exports
2 participants