MCPcopy Create free account
hub / github.com/copernet/copernicus / TestScriptCHECKMULTISIG12

Function TestScriptCHECKMULTISIG12

logic/lscript/lscript_test.go:415–450  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

413}
414
415func TestScriptCHECKMULTISIG12(t *testing.T) {
416 var flag uint32 = script.ScriptVerifyP2SH | script.ScriptVerifyStrictEnc
417 key1 := NewPrivateKey()
418 key2 := NewPrivateKey()
419 key3 := NewPrivateKey()
420 scriptPubKey12 := script.NewEmptyScript()
421 scriptPubKey12.PushOpCode(opcodes.OP_1)
422 scriptPubKey12.PushSingleData(key1.PubKey().ToBytes())
423 scriptPubKey12.PushSingleData(key2.PubKey().ToBytes())
424 scriptPubKey12.PushOpCode(opcodes.OP_2)
425 scriptPubKey12.PushOpCode(opcodes.OP_CHECKMULTISIG)
426
427 var txFrom12, txTo12 tx.Tx
428 txFrom12.AddTxOut(txout.NewTxOut(0, scriptPubKey12))
429 txTo12.AddTxIn(txin.NewTxIn(outpoint.NewOutPoint(txFrom12.GetHash(), 0),
430 script.NewEmptyScript(), script.SequenceFinal))
431 goodsig1 := signMultisig(scriptPubKey12, []crypto.PrivateKey{key1}, &txTo12)
432 if err := VerifyScript(&txTo12, goodsig1, scriptPubKey12, 0, 0, flag, NewScriptRealChecker()); err != nil {
433 t.Errorf("checkMultiSig fail, sk = key1, pk = key12")
434 }
435
436 txTo12.AddTxOut(txout.NewTxOut(0, script.NewEmptyScript()))
437 if err := VerifyScript(&txTo12, goodsig1, scriptPubKey12, 0, 0, flag, NewScriptRealChecker()); err == nil {
438 t.Errorf("checkMultiSig should fail, sk = key1, pk = key12, bug sig damaged")
439 }
440
441 goodsig2 := signMultisig(scriptPubKey12, []crypto.PrivateKey{key2}, &txTo12)
442 if err := VerifyScript(&txTo12, goodsig2, scriptPubKey12, 0, 0, flag, NewScriptRealChecker()); err != nil {
443 t.Errorf("checkMultiSig fail, sk = key2, pk = key12")
444 }
445
446 badsig1 := signMultisig(scriptPubKey12, []crypto.PrivateKey{key3}, &txTo12)
447 if err := VerifyScript(&txTo12, badsig1, scriptPubKey12, 0, 0, flag, NewScriptRealChecker()); err == nil {
448 t.Errorf("checkMultiSig should fail, sk = key3, pk = key12")
449 }
450}
451
452func TestScriptCHECKMULTISIG23(t *testing.T) {
453 var flag uint32 = script.ScriptVerifyP2SH | script.ScriptVerifyStrictEnc

Callers

nothing calls this directly

Calls 11

PubKeyMethod · 0.95
AddTxOutMethod · 0.95
AddTxInMethod · 0.95
GetHashMethod · 0.95
signMultisigFunction · 0.85
VerifyScriptFunction · 0.85
NewScriptRealCheckerFunction · 0.85
PushOpCodeMethod · 0.80
PushSingleDataMethod · 0.80
ToBytesMethod · 0.80
NewPrivateKeyFunction · 0.70

Tested by

no test coverage detected