FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
bitcore/test/test.ScriptInterpreter.js at master · jonasbits/bitcore · GitHub
jonasbits
bitcore
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
bitcore
/
test
/
test.ScriptInterpreter.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
92 lines (81 loc) · 2.75 KB
Breadcrumbs
bitcore
/
test
/
test.ScriptInterpreter.js
Copy path
File metadata and controls
92 lines (81 loc) · 2.75 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
'use strict'
;
var
chai
=
chai
||
require
(
'chai'
)
;
var
bitcore
=
bitcore
||
require
(
'../bitcore'
)
;
var
buffertools
=
require
(
'buffertools'
)
;
var
should
=
chai
.
should
(
)
;
var
testdata
=
testdata
||
require
(
'./testdata'
)
;
var
Script
=
bitcore
.
Script
;
var
ScriptInterpreter
=
bitcore
.
ScriptInterpreter
;
describe
(
'ScriptInterpreter'
,
function
(
)
{
it
(
'should initialze the main object'
,
function
(
)
{
should
.
exist
(
ScriptInterpreter
)
;
}
)
;
it
(
'should be able to create instance'
,
function
(
)
{
var
si
=
new
ScriptInterpreter
(
)
;
should
.
exist
(
si
)
;
}
)
;
var
testScripts
=
function
(
data
,
valid
)
{
data
.
forEach
(
function
(
datum
)
{
if
(
datum
.
length
<
2
)
throw
new
Error
(
'Invalid test data'
)
;
var
scriptSig
=
datum
[
0
]
;
// script inputs
var
scriptPubKey
=
datum
[
1
]
;
// output script
var
human
=
scriptSig
+
' '
+
scriptPubKey
;
it
(
'should '
+
(
!
valid
?
'not '
:
''
)
+
'validate script '
+
human
,
function
(
done
)
{
try
{
ScriptInterpreter
.
verifyFull
(
Script
.
fromHumanReadable
(
scriptSig
)
,
// scriptSig
Script
.
fromHumanReadable
(
scriptPubKey
)
,
// scriptPubKey
null
,
0
,
0
,
// tx, output index, hashtype
{
verifyP2SH
:
!
valid
}
,
// only verify P2SH for invalid data set
function
(
err
,
result
)
{
if
(
valid
)
{
should
.
not
.
exist
(
err
)
;
}
else
{
var
failed
=
(
typeof
err
!==
'undefined'
)
||
(
result
===
false
)
;
failed
.
should
.
equal
(
true
)
;
}
if
(
typeof
result
!==
'undefined'
)
{
result
.
should
.
equal
(
valid
)
;
}
done
(
)
;
}
)
;
}
catch
(
e
)
{
if
(
valid
)
{
console
.
log
(
e
)
;
}
valid
.
should
.
equal
(
false
)
;
done
(
)
;
}
}
)
;
}
)
;
}
;
testScripts
(
testdata
.
dataScriptValid
,
true
)
;
testScripts
(
testdata
.
dataScriptInvalid
,
false
)
;
testdata
.
dataSigCanonical
.
forEach
(
function
(
datum
)
{
it
(
'should validate valid canonical signatures'
,
function
(
)
{
new
ScriptInterpreter
(
)
.
isCanonicalSignature
(
new
Buffer
(
datum
,
'hex'
)
)
.
should
.
equal
(
true
)
;
}
)
;
}
)
;
testdata
.
dataSigNonCanonical
.
forEach
(
function
(
datum
)
{
it
(
'should NOT validate invalid canonical signatures'
,
function
(
)
{
var
sig
;
var
isHex
;
//is Hex?
try
{
sig
=
new
Buffer
(
datum
,
'hex'
)
;
isHex
=
1
;
}
catch
(
e
)
{
}
// ignore non-hex strings
if
(
isHex
)
{
var
f
=
function
(
)
{
var
si
=
new
ScriptInterpreter
(
)
;
var
r
=
si
.
isCanonicalSignature
(
sig
)
;
}
;
// how this test should be
// f.should.throw();
new
ScriptInterpreter
(
)
.
isCanonicalSignature
.
bind
(
sig
)
.
should
.
throw
(
)
;
}
}
)
;
}
)
;
}
)
;
Back
|
FazBrowse Home
|
New Git URL