ECSignature: add tests for scriptSignature
This commit is contained in:
parent
eb3d9a25f7
commit
626f8fb220
2 changed files with 65 additions and 0 deletions
test
|
@ -79,4 +79,41 @@ describe('ECSignature', function() {
|
|||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('toScriptSignature', function() {
|
||||
it('encodes a script signature', function() {
|
||||
fixtures.valid.forEach(function(f) {
|
||||
var signature = new ECSignature(
|
||||
new BigInteger(f.signature.r),
|
||||
new BigInteger(f.signature.s)
|
||||
)
|
||||
|
||||
var scriptSignature = signature.toScriptSignature(f.scriptSignature.hashType)
|
||||
assert.equal(scriptSignature.toString('hex'), f.scriptSignature.hex)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('fromScriptSignature', function() {
|
||||
it('decodes the correct signature', function() {
|
||||
fixtures.valid.forEach(function(f) {
|
||||
var buffer = new Buffer(f.scriptSignature.hex, 'hex')
|
||||
var parsed = ECSignature.fromScriptSignature(buffer)
|
||||
|
||||
assert.equal(parsed.signature.r.toString(), f.signature.r)
|
||||
assert.equal(parsed.signature.s.toString(), f.signature.s)
|
||||
assert.equal(parsed.hashType, f.scriptSignature.hashType)
|
||||
})
|
||||
})
|
||||
|
||||
fixtures.invalid.DER.forEach(function(f) {
|
||||
it('throws on ' + f.hex, function() {
|
||||
var buffer = new Buffer(f.hex + '01', 'hex')
|
||||
|
||||
assert.throws(function() {
|
||||
ECSignature.fromScriptSignature(buffer)
|
||||
}, new RegExp(f.exception))
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue