diff --git a/prediction_market_agent_tooling/tools/web3_utils.py b/prediction_market_agent_tooling/tools/web3_utils.py index d61129b9..d98c7df5 100644 --- a/prediction_market_agent_tooling/tools/web3_utils.py +++ b/prediction_market_agent_tooling/tools/web3_utils.py @@ -297,12 +297,15 @@ def send_xdai_to( from_private_key: PrivateKey, to_address: ChecksumAddress, value: Wei, + data_text: Optional[str] = None, tx_params: Optional[TxParams] = None, timeout: int = 180, ) -> TxReceipt: from_address = private_key_to_public_key(from_private_key) tx_params_new: TxParams = {"value": value, "to": to_address} + if data_text is not None: + tx_params_new["data"] = Web3.to_bytes(text=data_text) if tx_params: tx_params_new.update(tx_params) tx_params_new = _prepare_tx_params(web3, from_address, tx_params=tx_params_new) diff --git a/pyproject.toml b/pyproject.toml index 7c725887..fc8209d8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "prediction-market-agent-tooling" -version = "0.57.3" +version = "0.57.4" description = "Tools to benchmark, deploy and monitor prediction market agents." authors = ["Gnosis"] readme = "README.md" diff --git a/tests_integration_with_local_chain/markets/omen/test_local_chain.py b/tests_integration_with_local_chain/markets/omen/test_local_chain.py index 2df6dcfd..16c0c4bf 100644 --- a/tests_integration_with_local_chain/markets/omen/test_local_chain.py +++ b/tests_integration_with_local_chain/markets/omen/test_local_chain.py @@ -1,5 +1,7 @@ import time +import zlib +import pytest from ape_test import TestAccount from eth_account import Account from numpy import isclose @@ -127,3 +129,37 @@ def test_now_datetime(local_web3: Web3, test_keys: APIKeys) -> None: assert ( actual_difference <= allowed_difference ), f"chain_datetime and utc_datetime differ by more than {allowed_difference} seconds: {chain_datetime=} {utc_datetime=} {actual_difference=}" + + +@pytest.mark.parametrize( + "message, value_xdai", + [ + ("Hello there!", xDai(10)), + (zlib.compress(b"Hello there!"), xDai(10)), + ("Hello there!", xDai(0)), + ("", xDai(0)), + ], +) +def test_send_xdai_with_data( + message: str, value_xdai: xDai, local_web3: Web3, accounts: list[TestAccount] +) -> None: + value = xdai_to_wei(value_xdai) + message = "Hello there!" + from_account = accounts[0] + to_account = accounts[1] + + tx_receipt = send_xdai_to( + web3=local_web3, + from_private_key=private_key_type(from_account.private_key), + to_address=to_account.address, + value=value, + data_text=message, + ) + + # Check that we can get the original message + transaction = local_web3.eth.get_transaction(tx_receipt["transactionHash"]) + transaction_message = local_web3.to_text(transaction["input"]) + assert transaction_message == message + + # Check that the value is correct + assert transaction["value"] == value