|
1 | 1 | # -*- coding: utf-8 -*-
|
2 | 2 | # ------------------------------------------------------------------------------
|
3 | 3 | #
|
4 |
| -# Copyright 2021-2023 Valory AG |
| 4 | +# Copyright 2021-2024 Valory AG |
5 | 5 | # Copyright 2018-2019 Fetch.AI Limited
|
6 | 6 | #
|
7 | 7 | # Licensed under the Apache License, Version 2.0 (the "License");
|
|
36 | 36 | DEFAULT_GANACHE_CHAIN_ID,
|
37 | 37 | ganache,
|
38 | 38 | )
|
| 39 | +from eth_typing import BlockNumber |
39 | 40 | from web3.eth import Eth
|
| 41 | +from web3.types import FeeHistory, Wei |
40 | 42 |
|
41 | 43 | from aea.common import Address
|
42 | 44 | from aea.configurations.data_types import PublicId
|
|
85 | 87 | ],
|
86 | 88 | )
|
87 | 89 | # TODO: uncomment gas station strategy config after the gasstation API start
|
88 |
| -gas_strategies = pytest.mark.parametrize( |
| 90 | +gas_strategies_parametrization = pytest.mark.parametrize( |
89 | 91 | "gas_strategies",
|
90 | 92 | [
|
91 | 93 | {"gas_price_strategy": None},
|
|
98 | 100 | ],
|
99 | 101 | )
|
100 | 102 |
|
| 103 | +fee_history_mock = patch("web3.eth.Eth.fee_history") |
| 104 | + |
| 105 | +fee_history_parametrization = pytest.mark.parametrize( |
| 106 | + "fee_history", |
| 107 | + ( |
| 108 | + FeeHistory( |
| 109 | + baseFeePerGas=[Wei(0)], |
| 110 | + gasUsedRatio=[0], |
| 111 | + oldestBlock=BlockNumber(0), |
| 112 | + reward=[[Wei(0)]], |
| 113 | + ), |
| 114 | + FeeHistory( |
| 115 | + baseFeePerGas=[ |
| 116 | + Wei(int("0x180b5d502", 16)), |
| 117 | + Wei(int("0x18f9534de", 16)), |
| 118 | + Wei(int("0x18367e3a6", 16)), |
| 119 | + Wei(int("0x17e4519ed", 16)), |
| 120 | + Wei(int("0x179eb57e1", 16)), |
| 121 | + Wei(int("0x178ac8e88", 16)), |
| 122 | + Wei(int("0x177434776", 16)), |
| 123 | + Wei(int("0x17b4c8c2d", 16)), |
| 124 | + Wei(int("0x173695e84", 16)), |
| 125 | + Wei(int("0x1706c1f66", 16)), |
| 126 | + Wei(int("0x155600bc6", 16)), |
| 127 | + ], |
| 128 | + gasUsedRatio=[ |
| 129 | + 0.6546364333333333, |
| 130 | + 0.37810266666666664, |
| 131 | + 0.44697146666666665, |
| 132 | + 0.4544759666666667, |
| 133 | + 0.48681983333333334, |
| 134 | + 0.4850136666666667, |
| 135 | + 0.5430227, |
| 136 | + 0.4168211333333333, |
| 137 | + 0.46780666666666665, |
| 138 | + 0.206346, |
| 139 | + ], |
| 140 | + oldestBlock=BlockNumber(int("0x13cd298", 16)), |
| 141 | + reward=[ |
| 142 | + [Wei(int("0xf4240", 16))], |
| 143 | + [Wei(int("0xf4240", 16))], |
| 144 | + [Wei(int("0xf4240", 16))], |
| 145 | + [Wei(int("0x0", 16))], |
| 146 | + [Wei(int("0xf4240", 16))], |
| 147 | + [Wei(int("0xf4240", 16))], |
| 148 | + [Wei(int("0xf4240", 16))], |
| 149 | + [Wei(int("0x124f80", 16))], |
| 150 | + [Wei(int("0x919f8", 16))], |
| 151 | + [Wei(int("0xf4240", 16))], |
| 152 | + ], |
| 153 | + ), |
| 154 | + FeeHistory( |
| 155 | + baseFeePerGas=[], |
| 156 | + gasUsedRatio=[], |
| 157 | + oldestBlock=BlockNumber(0), |
| 158 | + reward=[], |
| 159 | + ), |
| 160 | + ), |
| 161 | +) |
| 162 | + |
101 | 163 |
|
102 | 164 | class LedgerApiDialogues(BaseLedgerApiDialogues):
|
103 | 165 | """The dialogues class keeps track of all ledger_api dialogues."""
|
@@ -220,17 +282,23 @@ async def test_get_state(
|
220 | 282 | )
|
221 | 283 | assert actual_block == expected_block
|
222 | 284 |
|
| 285 | + @fee_history_mock |
223 | 286 | @pytest.mark.asyncio
|
224 |
| - @gas_strategies |
| 287 | + @gas_strategies_parametrization |
| 288 | + @fee_history_parametrization |
225 | 289 | async def test_get_raw_transaction(
|
226 | 290 | self,
|
| 291 | + fee_history_mock_: Mock, |
227 | 292 | gas_strategies: Dict,
|
| 293 | + fee_history: FeeHistory, |
228 | 294 | ledger_apis_connection: Connection,
|
229 | 295 | update_default_ethereum_ledger_api: None,
|
230 | 296 | ) -> None:
|
231 | 297 | """Test get raw transaction with Ethereum APIs."""
|
232 | 298 | import aea # noqa # to load registries
|
233 | 299 |
|
| 300 | + fee_history_mock_.return_value = fee_history |
| 301 | + |
234 | 302 | crypto1 = make_crypto(
|
235 | 303 | EthereumCrypto.identifier, private_key_path=ETHEREUM_PRIVATE_KEY_PATH
|
236 | 304 | )
|
@@ -281,12 +349,19 @@ async def test_get_raw_transaction(
|
281 | 349 | assert isinstance(response_message.raw_transaction, RawTransaction)
|
282 | 350 | assert response_message.raw_transaction.ledger_id == request.terms.ledger_id
|
283 | 351 |
|
| 352 | + @fee_history_mock |
284 | 353 | @pytest.mark.asyncio
|
285 |
| - @gas_strategies |
| 354 | + @gas_strategies_parametrization |
| 355 | + @fee_history_parametrization |
286 | 356 | async def test_send_signed_transaction_ethereum(
|
287 |
| - self, gas_strategies: Dict, ledger_apis_connection: LedgerConnection |
| 357 | + self, |
| 358 | + fee_history_mock_: Mock, |
| 359 | + gas_strategies: Dict, |
| 360 | + fee_history: FeeHistory, |
| 361 | + ledger_apis_connection: LedgerConnection, |
288 | 362 | ) -> None:
|
289 | 363 | """Test send signed transaction with Ethereum APIs."""
|
| 364 | + fee_history_mock_.return_value = fee_history |
290 | 365 | ledger_api_dialogues = LedgerApiDialogues(SOME_SKILL_ID)
|
291 | 366 |
|
292 | 367 | crypto1 = make_crypto(
|
|
0 commit comments