mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-06 14:16:43 +00:00
gofmt
This commit is contained in:
parent
8fe24958bb
commit
53ba8fb834
1328
opcode_test.go
1328
opcode_test.go
File diff suppressed because it is too large
Load Diff
16
script.go
16
script.go
@ -718,7 +718,7 @@ func (s *Script) SetAltStack(data [][]byte) {
|
|||||||
|
|
||||||
// GetSigOpCount provides a quick count of the number of signature operations
|
// GetSigOpCount provides a quick count of the number of signature operations
|
||||||
// in a script. a CHECKSIG operations counts for 1, and a CHECK_MULTISIG for 20.
|
// in a script. a CHECKSIG operations counts for 1, and a CHECK_MULTISIG for 20.
|
||||||
func GetSigOpCount(script [] byte) (int, error) {
|
func GetSigOpCount(script []byte) (int, error) {
|
||||||
pops, err := parseScript(script)
|
pops, err := parseScript(script)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
@ -751,7 +751,7 @@ func GetPreciseSigOpCount(scriptSig, scriptPubKey []byte, bip16 bool) (int, erro
|
|||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
shScript := sigPops[len(sigPops) - 1].data
|
shScript := sigPops[len(sigPops)-1].data
|
||||||
// Means that sigPops is jus OP_1 - OP_16, no sigops there.
|
// Means that sigPops is jus OP_1 - OP_16, no sigops there.
|
||||||
if shScript == nil {
|
if shScript == nil {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
@ -774,20 +774,20 @@ func getSigOpCount(pops []parsedOpcode, precise bool) int {
|
|||||||
for i, pop := range pops {
|
for i, pop := range pops {
|
||||||
switch pop.opcode.value {
|
switch pop.opcode.value {
|
||||||
case OP_CHECKSIG:
|
case OP_CHECKSIG:
|
||||||
fallthrough;
|
fallthrough
|
||||||
case OP_CHECKSIGVERIFY:
|
case OP_CHECKSIGVERIFY:
|
||||||
nSigs++
|
nSigs++
|
||||||
case OP_CHECK_MULTISIG:
|
case OP_CHECK_MULTISIG:
|
||||||
fallthrough;
|
fallthrough
|
||||||
case OP_CHECKMULTISIGVERIFY:
|
case OP_CHECKMULTISIGVERIFY:
|
||||||
// If we are being precise then look for familiar
|
// If we are being precise then look for familiar
|
||||||
// patterns for multisig, for now all we recognise is
|
// patterns for multisig, for now all we recognise is
|
||||||
// OP_1 - OP_16 to signify the number of pubkeys.
|
// OP_1 - OP_16 to signify the number of pubkeys.
|
||||||
// Otherwise, we use the max of 20.
|
// Otherwise, we use the max of 20.
|
||||||
if precise && i > 0 &&
|
if precise && i > 0 &&
|
||||||
pops[i - 1].opcode.value >= OP_1 &&
|
pops[i-1].opcode.value >= OP_1 &&
|
||||||
pops[i - 1].opcode.value <= OP_16 {
|
pops[i-1].opcode.value <= OP_16 {
|
||||||
nSigs += int(pops[i-1].opcode.value -
|
nSigs += int(pops[i-1].opcode.value -
|
||||||
(OP_1 - 1))
|
(OP_1 - 1))
|
||||||
} else {
|
} else {
|
||||||
nSigs += MaxPubKeysPerMultiSig
|
nSigs += MaxPubKeysPerMultiSig
|
||||||
|
@ -121,7 +121,7 @@ var txTests = []txTest{
|
|||||||
0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4,
|
0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4,
|
||||||
0x12, 0xa3, btcscript.OP_CHECKSIG,
|
0x12, 0xa3, btcscript.OP_CHECKSIG,
|
||||||
},
|
},
|
||||||
idx: 0,
|
idx: 0,
|
||||||
nSigOps: 1,
|
nSigOps: 1,
|
||||||
},
|
},
|
||||||
// Previous test with the value of one output changed.
|
// Previous test with the value of one output changed.
|
||||||
@ -221,8 +221,8 @@ var txTests = []txTest{
|
|||||||
0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4,
|
0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4,
|
||||||
0x12, 0xa3, btcscript.OP_CHECKSIG,
|
0x12, 0xa3, btcscript.OP_CHECKSIG,
|
||||||
},
|
},
|
||||||
idx: 0,
|
idx: 0,
|
||||||
err: btcscript.StackErrScriptFailed,
|
err: btcscript.StackErrScriptFailed,
|
||||||
nSigOps: 1,
|
nSigOps: 1,
|
||||||
},
|
},
|
||||||
txTest{
|
txTest{
|
||||||
@ -325,7 +325,7 @@ var txTests = []txTest{
|
|||||||
},
|
},
|
||||||
idx: 0,
|
idx: 0,
|
||||||
shouldFail: true,
|
shouldFail: true,
|
||||||
nSigOps: 1,
|
nSigOps: 1,
|
||||||
},
|
},
|
||||||
txTest{
|
txTest{
|
||||||
name: "CheckSig invalid pubkey",
|
name: "CheckSig invalid pubkey",
|
||||||
@ -426,7 +426,7 @@ var txTests = []txTest{
|
|||||||
},
|
},
|
||||||
idx: 0,
|
idx: 0,
|
||||||
shouldFail: true,
|
shouldFail: true,
|
||||||
nSigOps: 1,
|
nSigOps: 1,
|
||||||
},
|
},
|
||||||
// tx 599e47a8114fe098103663029548811d2651991b62397e057f0c863c2bc9f9ea
|
// tx 599e47a8114fe098103663029548811d2651991b62397e057f0c863c2bc9f9ea
|
||||||
// uses checksig with SigHashNone.
|
// uses checksig with SigHashNone.
|
||||||
@ -526,8 +526,8 @@ var txTests = []txTest{
|
|||||||
btcscript.OP_EQUALVERIFY,
|
btcscript.OP_EQUALVERIFY,
|
||||||
btcscript.OP_CHECKSIG,
|
btcscript.OP_CHECKSIG,
|
||||||
},
|
},
|
||||||
idx: 0,
|
idx: 0,
|
||||||
bip16: true, // after threshold
|
bip16: true, // after threshold
|
||||||
nSigOps: 1,
|
nSigOps: 1,
|
||||||
},
|
},
|
||||||
// tx 51bf528ecf3c161e7c021224197dbe84f9a8564212f6207baa014c01a1668e1e
|
// tx 51bf528ecf3c161e7c021224197dbe84f9a8564212f6207baa014c01a1668e1e
|
||||||
@ -650,8 +650,8 @@ var txTests = []txTest{
|
|||||||
btcscript.OP_EQUALVERIFY,
|
btcscript.OP_EQUALVERIFY,
|
||||||
btcscript.OP_CHECKSIG,
|
btcscript.OP_CHECKSIG,
|
||||||
},
|
},
|
||||||
idx: 0,
|
idx: 0,
|
||||||
bip16: true, // after threshold
|
bip16: true, // after threshold
|
||||||
nSigOps: 1,
|
nSigOps: 1,
|
||||||
},
|
},
|
||||||
// tx 6d36bc17e947ce00bb6f12f8e7a56a1585c5a36188ffa2b05e10b4743273a74b
|
// tx 6d36bc17e947ce00bb6f12f8e7a56a1585c5a36188ffa2b05e10b4743273a74b
|
||||||
@ -773,8 +773,8 @@ var txTests = []txTest{
|
|||||||
0x4f, 0x13,
|
0x4f, 0x13,
|
||||||
btcscript.OP_NOP2, btcscript.OP_DROP,
|
btcscript.OP_NOP2, btcscript.OP_DROP,
|
||||||
},
|
},
|
||||||
idx: 1,
|
idx: 1,
|
||||||
bip16: false,
|
bip16: false,
|
||||||
nSigOps: 0, // multisig is in the pkScript!
|
nSigOps: 0, // multisig is in the pkScript!
|
||||||
},
|
},
|
||||||
// same as previous but with one byte changed to make signature fail
|
// same as previous but with one byte changed to make signature fail
|
||||||
@ -895,9 +895,9 @@ var txTests = []txTest{
|
|||||||
0x4f, 0x13,
|
0x4f, 0x13,
|
||||||
btcscript.OP_NOP2, btcscript.OP_DROP,
|
btcscript.OP_NOP2, btcscript.OP_DROP,
|
||||||
},
|
},
|
||||||
idx: 1,
|
idx: 1,
|
||||||
bip16: false,
|
bip16: false,
|
||||||
err: btcscript.StackErrScriptFailed,
|
err: btcscript.StackErrScriptFailed,
|
||||||
nSigOps: 0, // multisig is in the pkScript!
|
nSigOps: 0, // multisig is in the pkScript!
|
||||||
},
|
},
|
||||||
// tx e5779b9e78f9650debc2893fd9636d827b26b4ddfa6a8172fe8708c924f5c39d
|
// tx e5779b9e78f9650debc2893fd9636d827b26b4ddfa6a8172fe8708c924f5c39d
|
||||||
@ -955,8 +955,8 @@ var txTests = []txTest{
|
|||||||
0xae, 0x88,
|
0xae, 0x88,
|
||||||
btcscript.OP_EQUAL,
|
btcscript.OP_EQUAL,
|
||||||
},
|
},
|
||||||
idx: 0,
|
idx: 0,
|
||||||
bip16: true,
|
bip16: true,
|
||||||
nSigOps: 0, // no signature ops in the pushed script.
|
nSigOps: 0, // no signature ops in the pushed script.
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -1014,7 +1014,7 @@ func TestGetPreciseSignOps(t *testing.T) {
|
|||||||
if count != test.nSigOps {
|
if count != test.nSigOps {
|
||||||
t.Errorf("%s: expected count of %d, got %d", test.name,
|
t.Errorf("%s: expected count of %d, got %d", test.name,
|
||||||
test.nSigOps, count)
|
test.nSigOps, count)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1302,12 +1302,12 @@ func TestBadPC(t *testing.T) {
|
|||||||
}
|
}
|
||||||
pcTests := []pcTest{
|
pcTests := []pcTest{
|
||||||
pcTest{
|
pcTest{
|
||||||
script:2,
|
script: 2,
|
||||||
off:0,
|
off: 0,
|
||||||
},
|
},
|
||||||
pcTest{
|
pcTest{
|
||||||
script: 0,
|
script: 0,
|
||||||
off: 2,
|
off: 2,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
// tx with almost empty scripts.
|
// tx with almost empty scripts.
|
||||||
@ -1329,12 +1329,12 @@ func TestBadPC(t *testing.T) {
|
|||||||
Index: 0,
|
Index: 0,
|
||||||
},
|
},
|
||||||
SignatureScript: []uint8{btcscript.OP_NOP},
|
SignatureScript: []uint8{btcscript.OP_NOP},
|
||||||
Sequence: 4294967295,
|
Sequence: 4294967295,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
TxOut: []*btcwire.TxOut{
|
TxOut: []*btcwire.TxOut{
|
||||||
&btcwire.TxOut{
|
&btcwire.TxOut{
|
||||||
Value: 1000000000,
|
Value: 1000000000,
|
||||||
PkScript: []byte{},
|
PkScript: []byte{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -1343,7 +1343,7 @@ func TestBadPC(t *testing.T) {
|
|||||||
pkScript := []byte{btcscript.OP_NOP}
|
pkScript := []byte{btcscript.OP_NOP}
|
||||||
|
|
||||||
for _, test := range pcTests {
|
for _, test := range pcTests {
|
||||||
engine, err := btcscript.NewScript(tx.TxIn[0].SignatureScript,
|
engine, err := btcscript.NewScript(tx.TxIn[0].SignatureScript,
|
||||||
pkScript, 0, tx, 70001, false)
|
pkScript, 0, tx, 70001, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Failed to create script: %v", err)
|
t.Errorf("Failed to create script: %v", err)
|
||||||
@ -1388,12 +1388,12 @@ func TestCheckErrorCondition(t *testing.T) {
|
|||||||
Index: 0,
|
Index: 0,
|
||||||
},
|
},
|
||||||
SignatureScript: []uint8{},
|
SignatureScript: []uint8{},
|
||||||
Sequence: 4294967295,
|
Sequence: 4294967295,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
TxOut: []*btcwire.TxOut{
|
TxOut: []*btcwire.TxOut{
|
||||||
&btcwire.TxOut{
|
&btcwire.TxOut{
|
||||||
Value: 1000000000,
|
Value: 1000000000,
|
||||||
PkScript: []byte{},
|
PkScript: []byte{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -1419,7 +1419,7 @@ func TestCheckErrorCondition(t *testing.T) {
|
|||||||
t.Errorf("failed to create script: %v", err)
|
t.Errorf("failed to create script: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < len(pkScript) - 1; i++ {
|
for i := 0; i < len(pkScript)-1; i++ {
|
||||||
done, err := engine.Step()
|
done, err := engine.Step()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to step %dth time: %v", i, err)
|
t.Errorf("failed to step %dth time: %v", i, err)
|
||||||
@ -1452,4 +1452,3 @@ func TestCheckErrorCondition(t *testing.T) {
|
|||||||
t.Errorf("unexpected error %v on final check", err)
|
t.Errorf("unexpected error %v on final check", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,7 +235,7 @@ var stackTests = []stackTest{
|
|||||||
[][]byte{},
|
[][]byte{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"PushInt 0",
|
"PushInt 0",
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *btcscript.Stack) error {
|
||||||
stack.PushInt(big.NewInt(0))
|
stack.PushInt(big.NewInt(0))
|
||||||
@ -245,7 +245,7 @@ var stackTests = []stackTest{
|
|||||||
[][]byte{{}},
|
[][]byte{{}},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"PushInt 1",
|
"PushInt 1",
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *btcscript.Stack) error {
|
||||||
stack.PushInt(big.NewInt(1))
|
stack.PushInt(big.NewInt(1))
|
||||||
@ -255,7 +255,7 @@ var stackTests = []stackTest{
|
|||||||
[][]byte{{0x1}},
|
[][]byte{{0x1}},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"PushInt -1",
|
"PushInt -1",
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *btcscript.Stack) error {
|
||||||
stack.PushInt(big.NewInt(-1))
|
stack.PushInt(big.NewInt(-1))
|
||||||
@ -265,7 +265,7 @@ var stackTests = []stackTest{
|
|||||||
[][]byte{{0x81}},
|
[][]byte{{0x81}},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"PushInt two bytes",
|
"PushInt two bytes",
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *btcscript.Stack) error {
|
||||||
stack.PushInt(big.NewInt(256))
|
stack.PushInt(big.NewInt(256))
|
||||||
@ -276,7 +276,7 @@ var stackTests = []stackTest{
|
|||||||
[][]byte{{0x00, 0x01}},
|
[][]byte{{0x00, 0x01}},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"PushInt leading zeros",
|
"PushInt leading zeros",
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *btcscript.Stack) error {
|
||||||
// this will have the highbit set
|
// this will have the highbit set
|
||||||
@ -284,7 +284,7 @@ var stackTests = []stackTest{
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
nil,
|
nil,
|
||||||
[][]byte{{0x80, 0x00 }},
|
[][]byte{{0x80, 0x00}},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"dup",
|
"dup",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user