def test_multiple_transfers(self): EXPECTED_DIGEST = "35c19ceff72218a36f9807c370e5625efc36e43ce4e9f2047f1b820162b8b3d9" EXPECTED_PAYLOAD = \ "a1660000532398dd883d1990f7dad3fde6a53a53347afc2680a04748f7f15ad03cadc4d4014235130ac5aab442e3" \ "9f9aa27118956695229212dd2f1ab5b714e9f6bd581511c1010020f478c7f74b50c187bf9a8836f382bd62977bae" \ "eaf19625608e7e912aa60098c10200da2e9c3191e3768d1c59ea43f6318367ed9b21e6974f46a60d0dd8976740af" \ "6dc2000186a000000000000000000000000418c2a33af8bd2cba7fa714a840a308a217aa4483880b1ef14b4fdffe" \ "08ab956e3f4b921cec33be7c258cfd7025a2b9a942770e5b17758bcc4961bbdc75a0251c" # build the payload bytes for the transaction with mock.patch('random.getrandbits') as mock_counter: mock_counter.side_effect = [0] payload = Transaction() payload.from_address = IDENTITIES[0] payload.add_transfer(IDENTITIES[1], 256) payload.add_transfer(IDENTITIES[2], 512) payload.add_transfer(IDENTITIES[3], 100000) payload.add_signer(IDENTITIES[0]) # sign the final transaction payload.sign(ENTITIES[0]) transaction_bytes = transaction.encode_transaction(payload) self.assertIsExpectedTx(payload, transaction_bytes, EXPECTED_PAYLOAD) # attempt to decode a transaction from the generated bytes buffer = io.BytesIO(transaction_bytes) success, tx = transaction.decode_transaction(buffer) self.assertTrue(success) self.assertTxAreEqual(payload, tx) # Check payload digest self.assertEqual(sha256_hex(payload.encode_payload()), EXPECTED_DIGEST)
def test_smart_contract(self): EXPECTED_DIGEST = "9ea094e71cbe846192429db3d7e8b02b649730c8b525c3268eb9ff5633c27130" EXPECTED_PAYLOAD = \ "a1604000532398dd883d1990f7dad3fde6a53a53347afc2680a04748f7f15ad03cadc4d400c103e8c2000f424080" \ "e6672a9d98da667e5dc25b2bca8acf9644a7ac0797f01cb5968abf39de011df2066c61756e636802676f00000000" \ "000000000418c2a33af8bd2cba7fa714a840a308a217aa4483880b1ef14b4fdffe08ab956e3f4b921cec33be7c25" \ "8cfd7025a2b9a942770e5b17758bcc4961bbdc75a0251c" # build the payload bytes for the transaction with mock.patch('random.getrandbits') as mock_counter: mock_counter.side_effect = [0] payload = Transaction() payload.from_address = IDENTITIES[0] payload.add_signer(IDENTITIES[0]) payload.charge_rate = 1000 payload.charge_limit = 1000000 payload.target_contract(Address(IDENTITIES[4]), BitVector()) payload.action = 'launch' payload.data = 'go'.encode('ascii') # sign the final transaction payload.sign(ENTITIES[0]) transaction_bytes = transaction.encode_transaction(payload) self.assertIsExpectedTx(payload, transaction_bytes, EXPECTED_PAYLOAD) # attempt to decode a transaction from the generated bytes buffer = io.BytesIO(transaction_bytes) success, tx = transaction.decode_transaction(buffer) self.assertTrue(success) self.assertTxAreEqual(payload, tx) # Check payload digest self.assertEqual(sha256_hex(payload.encode_payload()), EXPECTED_DIGEST)
def test_simple_transfer(self): EXPECTED_DIGEST = "257c5e1de3a0a895d66d57792f1a44425336bb05bc6c8479be83b4572e1b4d45" EXPECTED_PAYLOAD = \ "a1640000532398dd883d1990f7dad3fde6a53a53347afc2680a04748f7f15ad03cadc4d44235130ac5aab442e39f" \ "9aa27118956695229212dd2f1ab5b714e9f6bd581511c1010000000000000000000000000418c2a33af8bd2cba7f" \ "a714a840a308a217aa4483880b1ef14b4fdffe08ab956e3f4b921cec33be7c258cfd7025a2b9a942770e5b17758b" \ "cc4961bbdc75a0251c" # build the payload bytes for the transaction with mock.patch('random.getrandbits') as mock_counter: mock_counter.side_effect = [0] payload = Transaction() payload.from_address = IDENTITIES[0] payload.add_transfer(IDENTITIES[1], 256) payload.add_signer(IDENTITIES[0]) # sign the final transaction payload.sign(ENTITIES[0]) transaction_bytes = transaction.encode_transaction(payload) self.assertIsExpectedTx(payload, transaction_bytes, EXPECTED_PAYLOAD) # attempt to decode a transaction from the generated bytes buffer = io.BytesIO(transaction_bytes) success, tx = transaction.decode_transaction(buffer) self.assertTrue(success) self.assertTxAreEqual(payload, tx) # Check payload digest self.assertEqual(sha256_hex(payload.encode_payload()), EXPECTED_DIGEST)
def test_contract_with_large_shard_mask(self): EXPECTED_DIGEST = "86a1c9e380fe5154243af3d50603aadb75327513373c0e2917b8319d3391b3ae" EXPECTED_PAYLOAD = \ "a1618000532398dd883d1990f7dad3fde6a53a53347afc2680a04748f7f15ad03cadc4d464c0c8c103e8c2000f42" \ "4041eaab0b666f6f2e6261722e62617a066c61756e63680000000000000000000418c2a33af8bd2cba7fa714a840" \ "a308a217aa4483880b1ef14b4fdffe08ab956e3f4b921cec33be7c258cfd7025a2b9a942770e5b17758bcc4961bb" \ "dc75a0251c" mask = BitVector(16) mask.set(15, 1) mask.set(14, 1) mask.set(13, 1) mask.set(11, 1) mask.set(9, 1) mask.set(7, 1) mask.set(5, 1) mask.set(3, 1) mask.set(1, 1) mask.set(0, 1) # build the payload bytes for the transaction with mock.patch('random.getrandbits') as mock_counter: mock_counter.side_effect = [0] payload = Transaction() payload.from_address = IDENTITIES[0] payload.add_signer(IDENTITIES[0]) payload.charge_rate = 1000 payload.charge_limit = 1000000 payload.valid_from = 100 payload.valid_until = 200 payload.target_chain_code('foo.bar.baz', mask) payload.action = 'launch' # sign the final transaction payload.sign(ENTITIES[0]) transaction_bytes = transaction.encode_transaction(payload) self.assertIsExpectedTx(payload, transaction_bytes, EXPECTED_PAYLOAD) # attempt to decode a transaction from the generated bytes buffer = io.BytesIO(transaction_bytes) success, tx = transaction.decode_transaction(buffer) self.assertTrue(success) self.assertTxAreEqual(payload, tx) # Check payload digest self.assertEqual(sha256_hex(payload.encode_payload()), EXPECTED_DIGEST)
def test_contract_with_4bit_shard_mask(self): EXPECTED_DIGEST = "e1ac018356792e492aaac92bf6928af1e47ed987761b81cafb51f1106f403eee" EXPECTED_PAYLOAD = \ "a1618000532398dd883d1990f7dad3fde6a53a53347afc2680a04748f7f15ad03cadc4d464c0c8c103e8c2000f42" \ "401c0b666f6f2e6261722e62617a066c61756e63680000000000000000000418c2a33af8bd2cba7fa714a840a308" \ "a217aa4483880b1ef14b4fdffe08ab956e3f4b921cec33be7c258cfd7025a2b9a942770e5b17758bcc4961bbdc75" \ "a0251c" mask = BitVector(4) mask.set(3, 1) mask.set(2, 1) # build the payload bytes for the transaction with mock.patch('random.getrandbits') as mock_counter: mock_counter.side_effect = [0] payload = Transaction() payload.from_address = IDENTITIES[0] payload.add_signer(IDENTITIES[0]) payload.charge_rate = 1000 payload.charge_limit = 1000000 payload.valid_from = 100 payload.valid_until = 200 payload.target_chain_code('foo.bar.baz', mask) payload.action = 'launch' # sign the final transaction payload.sign(ENTITIES[0]) transaction_bytes = transaction.encode_transaction(payload) self.assertIsExpectedTx(payload, transaction_bytes, EXPECTED_PAYLOAD) # attempt to decode a transaction from the generated bytes buffer = io.BytesIO(transaction_bytes) success, tx = transaction.decode_transaction(buffer) self.assertTrue(success) self.assertTxAreEqual(payload, tx) # Check payload digest self.assertEqual(sha256_hex(payload.encode_payload()), EXPECTED_DIGEST)
def test_validity_ranges(self): EXPECTED_DIGEST = "5451e302ba1fd323b623c1c9a0fc626b9c9249bb5d91ec60be1bb924efa3f1ac" EXPECTED_PAYLOAD = \ "a1670000532398dd883d1990f7dad3fde6a53a53347afc2680a04748f7f15ad03cadc4d4024235130ac5aab442e3" \ "9f9aa27118956695229212dd2f1ab5b714e9f6bd581511c103e820f478c7f74b50c187bf9a8836f382bd62977bae" \ "eaf19625608e7e912aa60098c103e8da2e9c3191e3768d1c59ea43f6318367ed9b21e6974f46a60d0dd8976740af" \ "6dc103e8e6672a9d98da667e5dc25b2bca8acf9644a7ac0797f01cb5968abf39de011df2c103e864c0c8c103e8c2" \ "000f424000000000000000000418c2a33af8bd2cba7fa714a840a308a217aa4483880b1ef14b4fdffe08ab956e3f" \ "4b921cec33be7c258cfd7025a2b9a942770e5b17758bcc4961bbdc75a0251c" # build the payload bytes for the transaction with mock.patch('random.getrandbits') as mock_counter: mock_counter.side_effect = [0] payload = Transaction() payload.from_address = IDENTITIES[0] payload.add_transfer(IDENTITIES[1], 1000) payload.add_transfer(IDENTITIES[2], 1000) payload.add_transfer(IDENTITIES[3], 1000) payload.add_transfer(IDENTITIES[4], 1000) payload.add_signer(IDENTITIES[0]) payload.charge_rate = 1000 payload.charge_limit = 1000000 payload.valid_from = 100 payload.valid_until = 200 # sign the final transaction payload.sign(ENTITIES[0]) transaction_bytes = transaction.encode_transaction(payload) self.assertIsExpectedTx(payload, transaction_bytes, EXPECTED_PAYLOAD) # attempt to decode a transaction from the generated bytes buffer = io.BytesIO(transaction_bytes) success, tx = transaction.decode_transaction(buffer) self.assertTrue(success) self.assertTxAreEqual(tx, tx) # Check payload digest self.assertEqual(sha256_hex(payload.encode_payload()), EXPECTED_DIGEST)
def test_chain_code(self): EXPECTED_DIGEST = "25cc72ca7d4871aaaabd027af129ecd4327adde5ec0c9977bfe11018d4bab64a" EXPECTED_PAYLOAD = \ "a1608000532398dd883d1990f7dad3fde6a53a53347afc2680a04748f7f15ad03cadc4d400c103e8c2000f424080" \ "0b666f6f2e6261722e62617a066c61756e636802676f00000000000000000418c2a33af8bd2cba7fa714a840a308" \ "a217aa4483880b1ef14b4fdffe08ab956e3f4b921cec33be7c258cfd7025a2b9a942770e5b17758bcc4961bbdc75" \ "a0251c" # build the payload bytes for the transaction with mock.patch('random.getrandbits') as mock_counter: mock_counter.side_effect = [0] payload = Transaction() payload.from_address = IDENTITIES[0] payload.add_signer(IDENTITIES[0]) payload.charge_rate = 1000 payload.charge_limit = 1000000 payload.target_chain_code('foo.bar.baz', BitVector()) payload.action = 'launch' payload.data = 'go'.encode('ascii') # sign the final transaction payload.sign(ENTITIES[0]) transaction_bytes = transaction.encode_transaction(payload) self.assertIsExpectedTx(payload, transaction_bytes, EXPECTED_PAYLOAD) # attempt to decode a transaction from the generated bytes buffer = io.BytesIO(transaction_bytes) success, tx = transaction.decode_transaction(buffer) self.assertTrue(success) self.assertTxAreEqual(payload, tx) # Check payload digest self.assertEqual(sha256_hex(payload.encode_payload()), EXPECTED_DIGEST)
def test_synergetic_data_submission(self): EXPECTED_DIGEST = "261ba516c9b7b4d3ecb39f349dbb0a35db0d9fc362f2b9cc81c7d844be4d0081" EXPECTED_PAYLOAD = \ "a160c000532398dd883d1990f7dad3fde6a53a53347afc2680a04748f7f15ad03cadc4d4c1271001c3000000e8d4" \ "a5100080e6672a9d98da667e5dc25b2bca8acf9644a7ac0797f01cb5968abf39de011df204646174610f7b227661" \ "6c7565223a20313233347d00000000000000000418c2a33af8bd2cba7fa714a840a308a217aa4483880b1ef14b4f" \ "dffe08ab956e3f4b921cec33be7c258cfd7025a2b9a942770e5b17758bcc4961bbdc75a0251c" # build the payload bytes for the transaction with mock.patch('random.getrandbits') as mock_counter: mock_counter.side_effect = [0] payload = Transaction() payload.from_address = IDENTITIES[0] payload.valid_until = 10000 payload.target_synergetic_data(Address(IDENTITIES[4]), BitVector()) payload.charge_rate = 1 payload.charge_limit = 1000000000000 payload.action = 'data' payload.data = json.dumps({'value': 1234}).encode('ascii') payload.add_signer(IDENTITIES[0]) # sign the final transaction payload.sign(ENTITIES[0]) transaction_bytes = transaction.encode_transaction(payload) self.assertIsExpectedTx(payload, transaction_bytes, EXPECTED_PAYLOAD) # attempt to decode a transaction from the generated bytes buffer = io.BytesIO(transaction_bytes) success, tx = transaction.decode_transaction(buffer) self.assertTrue(success) self.assertTxAreEqual(payload, tx) # Check payload digest self.assertEqual(sha256_hex(payload.encode_payload()), EXPECTED_DIGEST)