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

Function TestScriptCHECKMULTISIG23

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

Source from the content-addressed store, hash-verified

450}
451
452func TestScriptCHECKMULTISIG23(t *testing.T) {
453 var flag uint32 = script.ScriptVerifyP2SH | script.ScriptVerifyStrictEnc
454 key1 := NewPrivateKey()
455 key2 := NewPrivateKey()
456 key3 := NewPrivateKey()
457 key4 := NewPrivateKey()
458 scriptPubKey23 := script.NewEmptyScript()
459 scriptPubKey23.PushOpCode(opcodes.OP_2)
460 scriptPubKey23.PushSingleData(key1.PubKey().ToBytes())
461 scriptPubKey23.PushSingleData(key2.PubKey().ToBytes())
462 scriptPubKey23.PushSingleData(key3.PubKey().ToBytes())
463 scriptPubKey23.PushOpCode(opcodes.OP_3)
464 scriptPubKey23.PushOpCode(opcodes.OP_CHECKMULTISIG)
465 var txFrom23, txTo23 tx.Tx
466 txFrom23.AddTxOut(txout.NewTxOut(0, scriptPubKey23))
467 txTo23.AddTxIn(txin.NewTxIn(outpoint.NewOutPoint(txFrom23.GetHash(), 0),
468 script.NewEmptyScript(), script.SequenceFinal))
469 goodsig1 := signMultisig(scriptPubKey23, []crypto.PrivateKey{key1, key2}, &txTo23)
470 if err := VerifyScript(&txTo23, goodsig1, scriptPubKey23, 0, 0, flag, NewScriptRealChecker()); err != nil {
471 t.Errorf("checkMultiSig fail, sk = key12, pk = key123")
472 }
473 goodsig2 := signMultisig(scriptPubKey23, []crypto.PrivateKey{key1, key3}, &txTo23)
474 if err := VerifyScript(&txTo23, goodsig2, scriptPubKey23, 0, 0, flag, NewScriptRealChecker()); err != nil {
475 t.Errorf("checkMultiSig fail, sk = key13, pk = key123")
476 }
477 goodsig3 := signMultisig(scriptPubKey23, []crypto.PrivateKey{key2, key3}, &txTo23)
478 if err := VerifyScript(&txTo23, goodsig3, scriptPubKey23, 0, 0, flag, NewScriptRealChecker()); err != nil {
479 t.Errorf("checkMultiSig fail, sk = key23, pk = key123")
480 }
481 badsig1 := signMultisig(scriptPubKey23, []crypto.PrivateKey{key2, key2}, &txTo23)
482 if err := VerifyScript(&txTo23, badsig1, scriptPubKey23, 0, 0, flag, NewScriptRealChecker()); err == nil {
483 t.Errorf("checkMultiSig should fail, sk = key22, pk = key123")
484 }
485 badsig2 := signMultisig(scriptPubKey23, []crypto.PrivateKey{key2, key1}, &txTo23)
486 if err := VerifyScript(&txTo23, badsig2, scriptPubKey23, 0, 0, flag, NewScriptRealChecker()); err == nil {
487 t.Errorf("checkMultiSig should fail, sk = key21, pk = key123")
488 }
489 badsig3 := signMultisig(scriptPubKey23, []crypto.PrivateKey{key3, key2}, &txTo23)
490 if err := VerifyScript(&txTo23, badsig3, scriptPubKey23, 0, 0, flag, NewScriptRealChecker()); err == nil {
491 t.Errorf("checkMultiSig should fail, sk = key32, pk = key123")
492 }
493 badsig4 := signMultisig(scriptPubKey23, []crypto.PrivateKey{key4, key2}, &txTo23)
494 if err := VerifyScript(&txTo23, badsig4, scriptPubKey23, 0, 0, flag, NewScriptRealChecker()); err == nil {
495 t.Errorf("checkMultiSig should fail, sk = key42, pk = key123")
496 }
497 badsig5 := signMultisig(scriptPubKey23, []crypto.PrivateKey{key1, key4}, &txTo23)
498 if err := VerifyScript(&txTo23, badsig5, scriptPubKey23, 0, 0, flag, NewScriptRealChecker()); err == nil {
499 t.Errorf("checkMultiSig should fail, sk = key14, pk = key123")
500 }
501 badsig6 := signMultisig(scriptPubKey23, []crypto.PrivateKey{}, &txTo23)
502 if err := VerifyScript(&txTo23, badsig6, scriptPubKey23, 0, 0, flag, NewScriptRealChecker()); err == nil {
503 t.Errorf("checkMultiSig should fail, sk = key{empty}, pk = key123")
504 }
505}
506
507func TestScriptPushData(t *testing.T) {
508 direct := []byte{1, 0x5a}

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