def test_encode_decode(self): channel="proofnet" message_type="proofnet:text" message="My UTF-8 text message." pm=proofnet.proof_message() pm.set_channel(channel) pm.set_message_type(message_type) pm.set_message(message.encode()) pm.do_work() pm2=proofnet.proof_message() pm2.decode_from_bytes(pm.get_bytes()) self.assertEqual(pm2.message.decode('utf-8'),message) self.assertEqual(pm2.channel,channel) self.assertEqual(pm2.message_type,message_type)
def test_encode_decode(self): channel = "proofnet" message_type = "proofnet:text" message = "My UTF-8 text message." pm = proofnet.proof_message() pm.set_channel(channel) pm.set_message_type(message_type) pm.set_message(message.encode()) pm.do_work() pm2 = proofnet.proof_message() pm2.decode_from_bytes(pm.get_bytes()) self.assertEqual(pm2.message.decode('utf-8'), message) self.assertEqual(pm2.channel, channel) self.assertEqual(pm2.message_type, message_type)
def test_set_target_nzeros(self): pn = proofnet.proof_message() pn.set_target_nzeros(8) self.assertEqual( pn.target, b'\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff' ) pn.set_target_nzeros(16) self.assertEqual( pn.target, b'\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff' ) pn.set_target_nzeros(4) self.assertEqual( pn.target, b'\x0f\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff' ) pn.set_target_nzeros(48) self.assertEqual( pn.target, b'\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff' ) pn.set_target_nzeros(7) self.assertEqual( pn.target, b'\x01\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff' )
def test_set_target_nzeros(self): pn=proofnet.proof_message() pn.set_target_nzeros(8) self.assertEqual(pn.target, b'\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff') pn.set_target_nzeros(16) self.assertEqual(pn.target, b'\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff') pn.set_target_nzeros(4) self.assertEqual(pn.target, b'\x0f\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff') pn.set_target_nzeros(48) self.assertEqual(pn.target,b'\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff') pn.set_target_nzeros(7) self.assertEqual(pn.target, b'\x01\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff')
def test_set_and_get_target_nzeros(self): pn=proofnet.proof_message() pn.set_target_nzeros(8) self.assertEqual(pn.get_target_nzeros(),8) pn.set_target_nzeros(50) self.assertEqual(pn.get_target_nzeros(),50) pn.set_target_nzeros(4) self.assertEqual(pn.get_target_nzeros(),4) pn.set_target_nzeros(32) self.assertEqual(pn.get_target_nzeros(),32) pn.set_target(b'\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff') self.assertEqual(pn.get_target_nzeros(),8) pn.set_target(b'\x00\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff') self.assertEqual(pn.get_target_nzeros(),8)
def test_set_and_get_target_nzeros(self): pn = proofnet.proof_message() pn.set_target_nzeros(8) self.assertEqual(pn.get_target_nzeros(), 8) pn.set_target_nzeros(50) self.assertEqual(pn.get_target_nzeros(), 50) pn.set_target_nzeros(4) self.assertEqual(pn.get_target_nzeros(), 4) pn.set_target_nzeros(32) self.assertEqual(pn.get_target_nzeros(), 32) pn.set_target( b'\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff' ) self.assertEqual(pn.get_target_nzeros(), 8) pn.set_target( b'\x00\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff' ) self.assertEqual(pn.get_target_nzeros(), 8)
import proofnet import base64 target = b"\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" channel = "proofnet" message_type = "proofnet:text" message = "My UTF-8 text message." pm = proofnet.proof_message() pm.set_target(target) pm.set_channel(channel) pm.set_message_type(message_type) pm.set_message(message.encode()) pm.do_work() print("target: %s" % base64.b16encode(target)) print("proof: %s" % base64.b16encode(pm.proof_hash)) print("nonce: %s" % pm.nonce) print("utc time: %s" % pm.utc_time) print("channel: %s" % pm.channel) print("message type: %s" % pm.message_type) print("message bytes: %s" % pm.message) print("base16 encoded proofnet message: %s" % base64.b16encode(pm.get_bytes()))