Sync Bitcoin Core tests.

This commit is contained in:
David Hill 2014-12-08 15:41:27 -05:00
parent a61c0f06cf
commit def35f2cd4
3 changed files with 803 additions and 752 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -3808,18 +3808,12 @@ func TestBitcoindInvalidTests(t *testing.T) {
} }
tx := btcwire.NewMsgTx() tx := btcwire.NewMsgTx()
for x, test := range tests { for x, test := range tests {
if len(test) < 2 && len(test) > 3 { name, err := testName(test)
if err != nil {
t.Errorf("TestBitcoindInvalidTests: invalid test #%d\n", t.Errorf("TestBitcoindInvalidTests: invalid test #%d\n",
x) x)
continue continue
} }
name := ""
if len(test) == 3 {
name = fmt.Sprintf("test (%s)", test[2])
} else {
name = fmt.Sprintf("test ([%s, %s])", test[0], test[1])
}
scriptSig, err := ParseShortForm(test[0]) scriptSig, err := ParseShortForm(test[0])
if err != nil { if err != nil {
t.Errorf("%s: can't parse scriptSig; %v", name, err) t.Errorf("%s: can't parse scriptSig; %v", name, err)
@ -3832,7 +3826,13 @@ func TestBitcoindInvalidTests(t *testing.T) {
continue continue
} }
s, err := NewScript(scriptSig, scriptPubKey, 0, tx, ScriptBip16) flags, err := parseScriptFlags(test[2])
if err != nil {
t.Errorf("%s: %v", name, err)
continue
}
s, err := NewScript(scriptSig, scriptPubKey, 0, tx, flags)
if err == nil { if err == nil {
if err := s.Execute(); err == nil { if err := s.Execute(); err == nil {
t.Errorf("%s test succeeded when it "+ t.Errorf("%s test succeeded when it "+
@ -3853,23 +3853,18 @@ func TestBitcoindValidTests(t *testing.T) {
var tests [][]string var tests [][]string
err = json.Unmarshal(file, &tests) err = json.Unmarshal(file, &tests)
if err != nil { if err != nil {
t.Errorf("TestBitcoindInvalidTests couldn't Unmarshal: %v\n", t.Errorf("TestBitcoindValidTests couldn't Unmarshal: %v\n",
err) err)
return return
} }
tx := btcwire.NewMsgTx() tx := btcwire.NewMsgTx()
for x, test := range tests { for x, test := range tests {
if len(test) < 2 && len(test) > 3 { name, err := testName(test)
t.Errorf("TestBitcoindInvalidTests: invalid test #%d\n", if err != nil {
t.Errorf("TestBitcoindValidTests: invalid test #%d\n",
x) x)
continue continue
} }
name := ""
if len(test) == 3 {
name = fmt.Sprintf("test (%s)", test[2])
} else {
name = fmt.Sprintf("test ([%s, %s])", test[0], test[1])
}
scriptSig, err := ParseShortForm(test[0]) scriptSig, err := ParseShortForm(test[0])
if err != nil { if err != nil {
@ -3883,7 +3878,13 @@ func TestBitcoindValidTests(t *testing.T) {
continue continue
} }
s, err := NewScript(scriptSig, scriptPubKey, 0, tx, ScriptBip16) flags, err := parseScriptFlags(test[2])
if err != nil {
t.Errorf("%s: %v", name, err)
continue
}
s, err := NewScript(scriptSig, scriptPubKey, 0, tx, flags)
if err != nil { if err != nil {
t.Errorf("%s failed to create script: %v", name, err) t.Errorf("%s failed to create script: %v", name, err)
continue continue
@ -3952,15 +3953,10 @@ testloop:
continue continue
} }
var flags ScriptFlags flags, err := parseScriptFlags(verifyFlags)
vFlags := strings.Split(verifyFlags, ",") if err != nil {
for _, flag := range vFlags { t.Errorf("bad test %d: %v", i, err)
switch flag { continue
case "P2SH":
flags |= ScriptBip16
case "NULLDUMMY":
flags |= ScriptStrictMultiSig
}
} }
prevOuts := make(map[btcwire.OutPoint][]byte) prevOuts := make(map[btcwire.OutPoint][]byte)
@ -4098,15 +4094,10 @@ testloop:
continue continue
} }
var flags ScriptFlags flags, err := parseScriptFlags(verifyFlags)
vFlags := strings.Split(verifyFlags, ",") if err != nil {
for _, flag := range vFlags { t.Errorf("bad test %d: %v", i, err)
switch flag { continue
case "P2SH":
flags |= ScriptBip16
case "NULLDUMMY":
flags |= ScriptStrictMultiSig
}
} }
prevOuts := make(map[btcwire.OutPoint][]byte) prevOuts := make(map[btcwire.OutPoint][]byte)
@ -4190,3 +4181,40 @@ testloop:
i, test) i, test)
} }
} }
func parseScriptFlags(flagStr string) (ScriptFlags, error) {
var flags ScriptFlags
sFlags := strings.Split(flagStr, ",")
for _, flag := range sFlags {
switch flag {
case "NONE":
// Nothing.
case "NULLDUMMY":
flags |= ScriptStrictMultiSig
case "P2SH":
flags |= ScriptBip16
case "STRICTENC":
// This is always set.
default:
return flags, fmt.Errorf("invalid flag: %s", flag)
}
}
return flags, nil
}
func testName(test []string) (string, error) {
var name string
if len(test) < 3 || len(test) > 4 {
return name, fmt.Errorf("invalid test length %d", len(test))
}
if len(test) == 4 {
name = fmt.Sprintf("test (%s)", test[3])
} else {
name = fmt.Sprintf("test ([%s, %s, %s])", test[0], test[1],
test[2])
}
return name, nil
}