def test_synergetic_data_submission(self): EXPECTED_PAYLOAD = "a120c0532398dd883d1990f7dad3fde6a53a53347afc2680a04748f7f15ad03cadc4d4c1271001c3000000e8d4a5100080da2e9c3191e3768d1c59ea43f6318367ed9b21e6974f46a60d0dd8976740af6de6672a9d98da667e5dc25b2bca8acf9644a7ac0797f01cb5968abf39de011df204646174610f7b2276616c7565223a20313233347d0418c2a33af8bd2cba7fa714a840a308a217aa4483880b1ef14b4fdffe08ab956e3f4b921cec33be7c258cfd7025a2b9a942770e5b17758bcc4961bbdc75a0251c" # build the payload bytes for the transaction payload = Transaction() payload.from_address = IDENTITIES[0] payload.valid_until = 10000 payload.target_contract(IDENTITIES[3], IDENTITIES[4], BitVector()) payload.charge_rate = 1 payload.charge_limit = 1000000000000 payload.action = 'data' payload.synergetic_data_submission = True payload.data = json.dumps({'value': 1234}).encode('ascii') payload.add_signer(IDENTITIES[0]) # sign the final transaction transaction_bytes = encode_transaction(payload, [ENTITIES[0]]) self.assertIsExpectedTx(payload, transaction_bytes, EXPECTED_PAYLOAD) # attempt to decode a transaction from the generated bytes buffer = io.BytesIO(transaction_bytes) success, tx = decode_transaction(buffer) self.assertTrue(success) self.assertTxAreEqual(payload, tx)
def submit_data(self, entity: Entity, digest: Address, **kwargs): # build up the basic transaction information tx = Transaction() tx.from_address = Address(entity) tx.valid_until = 10000 tx.target_contract(digest, Address(entity), BitVector()) tx.charge_rate = 1 tx.charge_limit = 1000000000000 tx.action = 'data' tx.synergetic_data_submission = True tx.data = self._encode_json(dict(**kwargs)) tx.add_signer(entity) # encode the transaction encoded_tx = encode_transaction(tx, [entity]) # submit the transaction to the catch-all endpoint return self._post_tx_json(encoded_tx, None)
def test_synergetic_data_submission(self): EXPECTED_DIGEST = "9397fd490b60a394ea0af5526435608a1e853e2cb6b09bc7cafec8f6a0aa2cf6" EXPECTED_PAYLOAD = \ "a140c000532398dd883d1990f7dad3fde6a53a53347afc2680a04748f7f15ad03cadc4d4c1271001c3000000e8d4" \ "a5100080da2e9c3191e3768d1c59ea43f6318367ed9b21e6974f46a60d0dd8976740af6de6672a9d98da667e5dc2" \ "5b2bca8acf9644a7ac0797f01cb5968abf39de011df204646174610f7b2276616c7565223a20313233347d000000" \ "00000000000418c2a33af8bd2cba7fa714a840a308a217aa4483880b1ef14b4fdffe08ab956e3f4b921cec33be7c" \ "258cfd7025a2b9a942770e5b17758bcc4961bbdc75a0251c" # 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_contract(IDENTITIES[3], IDENTITIES[4], BitVector()) payload.charge_rate = 1 payload.charge_limit = 1000000000000 payload.action = 'data' payload.synergetic_data_submission = True payload.data = json.dumps({'value': 1234}).encode('ascii') payload.add_signer(IDENTITIES[0]) # sign the final transaction transaction_bytes = encode_transaction(payload, [ENTITIES[0]]) self.assertIsExpectedTx(payload, transaction_bytes, EXPECTED_PAYLOAD) # attempt to decode a transaction from the generated bytes buffer = io.BytesIO(transaction_bytes) success, tx = decode_transaction(buffer) self.assertTrue(success) self.assertTxAreEqual(payload, tx) # Check payload digest buffer = io.BytesIO() encode_payload(buffer, payload) self.assertEqual(sha256_hash(buffer.getvalue()), EXPECTED_DIGEST)