本文整理汇总了Python中btctxstore.BtcTxStore.add_data_blob方法的典型用法代码示例。如果您正苦于以下问题:Python BtcTxStore.add_data_blob方法的具体用法?Python BtcTxStore.add_data_blob怎么用?Python BtcTxStore.add_data_blob使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类btctxstore.BtcTxStore
的用法示例。
在下文中一共展示了BtcTxStore.add_data_blob方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestIO
# 需要导入模块: from btctxstore import BtcTxStore [as 别名]
# 或者: from btctxstore.BtcTxStore import add_data_blob [as 别名]
class TestIO(unittest.TestCase):
def setUp(self):
self.api = BtcTxStore(dryrun=True, testnet=True)
def test_readwrite_nulldata(self):
rawtx = self.api.create_tx()
rawtx = self.api.add_nulldata(rawtx, "f483")
data = self.api.get_nulldata(rawtx)
self.assertEqual(data, "f483")
def test_readwrite_hash160data(self):
rawtx = self.api.create_tx()
rawtx = self.api.add_hash160data(rawtx, 10 * "f483")
data = self.api.get_hash160data(rawtx, 0)
self.assertEqual(data, 10 * "f483")
def test_readwrite_data_blob(self):
rawtx = self.api.create_tx()
data_in = "f483" * 30 + "beef" * 30
rawtx = self.api.add_data_blob(rawtx, data_in)
data_out = self.api.get_data_blob(rawtx)
self.assertEqual(data_in, data_out)
def test_readwrite_broadcast_message(self):
message = u"Ünicode test massage"
sender_wif = fixtures["wallet"]["wif"]
sender_address = fixtures["wallet"]["address"]
sender_hash160hex = fixtures["wallet"]["hash160hex"]
# create broadcast message tx
rawtx = self.api.create_tx()
rawtx = self.api.add_broadcast_message(rawtx, message, sender_wif)
# check that sender address is aligned so its visible in history
hash160hex = self.api.get_hash160data(rawtx, 3)
self.assertEqual(hash160hex, sender_hash160hex)
# get broadcast message from tx
result = self.api.get_broadcast_message(rawtx)
self.assertEqual(result["address"], sender_address)
self.assertEqual(result["message"], message)
# check signature is valid
hex_message = binascii.hexlify(result["message"].encode('utf-8'))
valid_signature = self.api.verify_signature(result["address"],
result["signature"],
hex_message)
self.assertTrue(valid_signature)
def test_only_one_nulldata_output(self):
def callback():
rawtx = self.api.create_tx()
rawtx = self.api.add_nulldata(rawtx, "f483")
self.api.add_nulldata(rawtx, "f483") # writing second fails
self.assertRaises(exceptions.ExistingNulldataOutput, callback)