Skip to content

Commit

Permalink
feat: Add code coverage for:
Browse files Browse the repository at this point in the history
* Invalid signature case
* No signature case
  • Loading branch information
rodolfopietro97 committed Jul 4, 2023
1 parent b35914b commit 52eadf4
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/cert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,17 @@ describe('cert', () => {
})

it('verify', () => {
// Valid signature
const sig = '0x' + secp256k1.sign(blake2b256(Certificate.encode(cert)), privKey).toString('hex')
expect(() => Certificate.verify({ ...cert, signature: sig, signer: '0x' })).to.throw()
expect(() => Certificate.verify({ ...cert, signature: sig })).not.to.throw()
expect(() => Certificate.verify({ ...cert, signature: sig.toUpperCase() })).not.to.throw()

// Invalid signature
const invalidSignature = '0xBAD' + secp256k1.sign(blake2b256(Certificate.encode(cert)), privKey).toString('hex')
expect(() => Certificate.verify({ ...cert, signature: invalidSignature, signer: '0x' })).to.throw()

// No signature
expect(() => Certificate.verify({ ...cert, signer: '0x' })).to.throw()
})
})

0 comments on commit 52eadf4

Please sign in to comment.