Skip to content

Commit

Permalink
Send data along with xDai (#566)
Browse files Browse the repository at this point in the history
  • Loading branch information
kongzii authored Dec 4, 2024
1 parent 666dba7 commit 5d466c4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
3 changes: 3 additions & 0 deletions prediction_market_agent_tooling/tools/web3_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import time
import zlib

import pytest
from ape_test import TestAccount
from eth_account import Account
from numpy import isclose
Expand Down Expand Up @@ -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

0 comments on commit 5d466c4

Please sign in to comment.