Skip to content

Commit

Permalink
feat: support for system tx
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Feb 16, 2024
1 parent b9cf4ec commit 2ff8c8c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ape_optimism/ecosystem.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from typing import cast

from ape.api import TransactionAPI
from ape.exceptions import ApeException
from ape_ethereum.ecosystem import (
BaseEthereumConfig,
DynamicFeeTransaction,
Ethereum,
NetworkConfig,
create_network_config,
Expand All @@ -14,6 +16,7 @@
"goerli": (420, 420),
"sepolia": (11155420, 11155420),
}
SYSTEM_TRANSACTION = 126


class ApeOptimismError(ApeException):
Expand All @@ -29,7 +32,17 @@ class OptimismConfig(BaseEthereumConfig):
sepolia: NetworkConfig = create_network_config(block_time=2)


class SystemTransaction(DynamicFeeTransaction):
type: int = SYSTEM_TRANSACTION


class Optimism(Ethereum):
@property
def config(self) -> OptimismConfig: # type: ignore
return cast(OptimismConfig, self.config_manager.get_config("optimism"))

def create_transaction(self, **kwargs) -> TransactionAPI:
if kwargs.get("type") == SYSTEM_TRANSACTION:
return SystemTransaction.model_validate(kwargs)

return super().create_transaction(**kwargs)
19 changes: 19 additions & 0 deletions tests/test_ecosystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from ape_ethereum.transactions import TransactionType
from ethpm_types.abi import MethodABI

from ape_optimism.ecosystem import SYSTEM_TRANSACTION, SystemTransaction


def test_gas_limit(optimism):
assert optimism.config.local.gas_limit == "max"
Expand Down Expand Up @@ -42,6 +44,23 @@ def test_create_transaction_type_2(optimism, tx_kwargs):
assert txn.type == TransactionType.DYNAMIC.value


def test_create_transaction_type_126(optimism):
data = {
"chainId": 0,
"to": "0x4200000000000000000000000000000000000015",
"from": "0xDeaDDEaDDeAdDeAdDEAdDEaddeAddEAdDEAd0001",
"gas": 1000000,
"nonce": 11021459,
"value": 0,
"data": "0x",
"type": 126,
"accessList": [],
}
actual = optimism.create_transaction(**data)
assert isinstance(actual, SystemTransaction)
assert actual.type == SYSTEM_TRANSACTION


@pytest.mark.parametrize(
"tx_type",
(TransactionType.STATIC.value, TransactionType.DYNAMIC.value),
Expand Down

0 comments on commit 2ff8c8c

Please sign in to comment.