Пример #1
0
 def test_nulldata(self):
     OP_RETURN = BitcoinScriptTools.compile("OP_RETURN")
     for sample in [b'test', b'me', b'a', b'39qEwuwyb2cAX38MFtrNzvq3KV9hSNov3q', b'', b'0'*80]:
         sample_script = OP_RETURN + sample
         sc = script_for_nulldata(sample)
         info = script_info_for_script(sc)
         self.assertEqual(info.get("data"), sample)
         self.assertEqual(sc, sample_script)
         out = Tx.TxOut(1, sc)
         # ensure we can create a tx
         Tx(0, [], [out])
Пример #2
0
 def test_solve_pay_to_public_pair(self):
     for se in range(1, 10):
         key = Key(secret_exponent=se, generator=secp256k1_generator)
         for b in [True, False]:
             addr = key.address(use_uncompressed=b)
             script = script_for_p2pk(key.sec(use_uncompressed=b))
             afs_address = address_for_script(script)
             self.assertEqual(afs_address, addr)
             hl = build_hash160_lookup([se], [secp256k1_generator])
             tx = Tx(1, [], [Tx.TxOut(100, script)])
             tx.sign(hash160_lookup=hl)
             afs_address = address_for_script(tx.txs_out[0].puzzle_script())
             self.assertEqual(afs_address, addr)
Пример #3
0
 def test_nulldata_push(self):
     OP_RETURN = BitcoinScriptTools.compile("OP_RETURN")
     for sample in [b'test', b'me', b'a', b'39qEwuwyb2cAX38MFtrNzvq3KV9hSNov3q', b'', b'0'*80]:
         sample_push = BitcoinScriptTools.compile_push_data_list([sample])
         sample_script = OP_RETURN + sample_push
         sc = script_for_nulldata_push(sample)
         info = script_info_for_script(sc)
         self.assertEqual(info.get("data"), sample_push)
         self.assertEqual(sc, sample_script)
         out = Tx.TxOut(1, sc)
         # ensure we can create a tx
         Tx(0, [], [out])
         # convert between asm and back to ensure no bugs with compilation
         self.assertEqual(sc, BitcoinScriptTools.compile(BitcoinScriptTools.disassemble(sc)))
Пример #4
0
 def multisig_M_of_N_individually(self, M, N):
     keys = [
         Key(secret_exponent=i, generator=secp256k1_generator)
         for i in range(1, N + 2)
     ]
     tx_in = Tx.TxIn.coinbase_tx_in(script=b'')
     script = script_for_multisig(m=M,
                                  sec_keys=[key.sec() for key in keys[:N]])
     tx_out = Tx.TxOut(1000000, script)
     tx1 = Tx(version=1, txs_in=[tx_in], txs_out=[tx_out])
     for partial_key_list in itertools.permutations(keys[:N], M):
         tx2 = create_tx(tx1.tx_outs_as_spendable(), [keys[-1].address()])
         for key in partial_key_list:
             self.assertEqual(tx2.bad_signature_count(), 1)
             hash160_lookup = build_hash160_lookup([key.secret_exponent()],
                                                   [secp256k1_generator])
             tx2.sign(hash160_lookup=hash160_lookup)
         self.assertEqual(tx2.bad_signature_count(), 0)
Пример #5
0
 def test_issue_225(self):
     script = script_for_nulldata(b"foobar")
     tx_out = Tx.TxOut(1, script)
     address = address_for_script(tx_out.puzzle_script())
     self.assertEqual(address, "(nulldata 666f6f626172)")