mirror of
https://github.com/kaspanet/kaspad.git
synced 2026-02-20 02:33:58 +00:00
txscript: Expose AddOps on ScriptBuilder. (#734)
This exposes a new function on the ScriptBuilder type named AddOps that allows multiple opcodes to be added via a single call and adds tests to exercise the new function. Finally, it updates a couple of places in the signing code that were abusing the interface by setting its private script directly to use the new public function instead.
This commit is contained in:
@@ -38,6 +38,7 @@ func TestScriptBuilderAddOp(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
// Run tests and individually add each op via AddOp.
|
||||
builder := txscript.NewScriptBuilder()
|
||||
t.Logf("Running %d tests", len(tests))
|
||||
for i, test := range tests {
|
||||
@@ -58,6 +59,25 @@ func TestScriptBuilderAddOp(t *testing.T) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// Run tests and bulk add ops via AddOps.
|
||||
t.Logf("Running %d tests", len(tests))
|
||||
for i, test := range tests {
|
||||
builder.Reset()
|
||||
result, err := builder.AddOps(test.opcodes).Script()
|
||||
if err != nil {
|
||||
t.Errorf("ScriptBuilder.AddOps #%d (%s) unexpected "+
|
||||
"error: %v", i, test.name, err)
|
||||
continue
|
||||
}
|
||||
if !bytes.Equal(result, test.expected) {
|
||||
t.Errorf("ScriptBuilder.AddOps #%d (%s) wrong result\n"+
|
||||
"got: %x\nwant: %x", i, test.name, result,
|
||||
test.expected)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// TestScriptBuilderAddInt64 tests that pushing signed integers to a script via
|
||||
|
||||
Reference in New Issue
Block a user