Load blocks from cache in tests
This commit is contained in:
parent
a3bcc7e3bb
commit
07763e0e3c
BIN
home/gh/Downloads/131.tar.gz
Normal file
BIN
home/gh/Downloads/131.tar.gz
Normal file
Binary file not shown.
@ -23,6 +23,8 @@ AAVE_CONTRACT_ADDRESSES: List[str] = [
|
||||
"0x3dfd23a6c5e8bbcfc9581d2e864a68feb6a076d3",
|
||||
# AAVE V2 WETH
|
||||
"0x030ba81f1c18d280636f32af80b9aad02cf0854e",
|
||||
# AAVE AMM Market DAI
|
||||
"0x79bE75FFC64DD58e66787E4Eae470c8a1FD08ba4",
|
||||
]
|
||||
|
||||
|
||||
@ -60,8 +62,6 @@ def get_liquidations(
|
||||
debt_purchase_amount=trace.inputs["_purchaseAmount"],
|
||||
protocol=Protocol.aave,
|
||||
received_amount=received_amount,
|
||||
# aToken lookup is out of scope for now, WIP
|
||||
received_token_address=trace.inputs["_collateral"],
|
||||
transaction_hash=trace.transaction_hash,
|
||||
block_number=trace.block_number,
|
||||
)
|
||||
|
@ -78,6 +78,7 @@ def inspect_block(
|
||||
|
||||
liquidations = get_liquidations(classified_traces)
|
||||
logger.info(f"Found {len(liquidations)} liquidations")
|
||||
print(liquidations)
|
||||
|
||||
miner_payments = get_miner_payments(
|
||||
block.miner, block.base_fee_per_gas, classified_traces, block.receipts
|
||||
|
@ -8,7 +8,6 @@ class Liquidation(BaseModel):
|
||||
collateral_token_address: str
|
||||
debt_token_address: str
|
||||
debt_purchase_amount: int
|
||||
received_token_address: str
|
||||
received_amount: int
|
||||
protocol: Protocol
|
||||
transaction_hash: str
|
||||
|
1
tests/blocks/10921991.json
Normal file
1
tests/blocks/10921991.json
Normal file
File diff suppressed because one or more lines are too long
1
tests/blocks/13179291.json
Normal file
1
tests/blocks/13179291.json
Normal file
File diff suppressed because one or more lines are too long
1
tests/blocks/13244807.json
Normal file
1
tests/blocks/13244807.json
Normal file
File diff suppressed because one or more lines are too long
@ -1,23 +1,19 @@
|
||||
import unittest
|
||||
from web3 import Web3
|
||||
|
||||
from mev_inspect.aave_liquidations import get_liquidations
|
||||
from mev_inspect.schemas.liquidations import Liquidation
|
||||
from mev_inspect.schemas.classified_traces import Protocol
|
||||
from mev_inspect.classifiers.trace import TraceClassifier
|
||||
from mev_inspect.block import create_from_block_number
|
||||
from tests.utils import load_test_block
|
||||
|
||||
|
||||
class TestAaveLiquidations(unittest.TestCase):
|
||||
def test_single_weth_liquidation(self):
|
||||
|
||||
base_provider = Web3.HTTPProvider("http://")
|
||||
w3 = Web3(base_provider)
|
||||
transaction_hash = (
|
||||
"0xb7575eedc9d8cfe82c4a11cd1a851221f2eafb93d738301995ac7103ffe877f7"
|
||||
)
|
||||
block_number = 13244807
|
||||
should_cache = False
|
||||
|
||||
liquidation = Liquidation(
|
||||
liquidated_user="0xd16404ca0a74a15e66d8ad7c925592fb02422ffe",
|
||||
@ -25,29 +21,26 @@ class TestAaveLiquidations(unittest.TestCase):
|
||||
collateral_token_address="0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
|
||||
debt_token_address="0xdac17f958d2ee523a2206206994597c13d831ec7",
|
||||
debt_purchase_amount=26503300291,
|
||||
received_token_address="0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
|
||||
received_amount=8182733924513576561,
|
||||
protocol=Protocol.aave,
|
||||
transaction_hash=transaction_hash,
|
||||
block_number=block_number,
|
||||
)
|
||||
|
||||
block = create_from_block_number(base_provider, w3, block_number, should_cache)
|
||||
block = load_test_block(block_number)
|
||||
trace_classifier = TraceClassifier()
|
||||
classified_traces = trace_classifier.classify(block.traces)
|
||||
result = get_liquidations(classified_traces)
|
||||
|
||||
self.assertEqual(result[0], liquidation)
|
||||
self.assertEqual(len(result), 1)
|
||||
|
||||
def test_single_liquidation(self):
|
||||
|
||||
base_provider = Web3.HTTPProvider("http://")
|
||||
w3 = Web3(base_provider)
|
||||
transaction_hash = (
|
||||
"0xe6c0e3ef0436cb032e1ef292141f4fc4dcd47a75a2559602133114952190e76b"
|
||||
)
|
||||
block_number = 10921991
|
||||
should_cache = False
|
||||
|
||||
liquidation = Liquidation(
|
||||
liquidated_user="0x8d8d912fe4db5917da92d14fea05225b803c359c",
|
||||
@ -55,38 +48,46 @@ class TestAaveLiquidations(unittest.TestCase):
|
||||
collateral_token_address="0x80fb784b7ed66730e8b1dbd9820afd29931aab03",
|
||||
debt_token_address="0xdac17f958d2ee523a2206206994597c13d831ec7",
|
||||
debt_purchase_amount=1069206535,
|
||||
received_token_address="0x80fb784b7ed66730e8b1dbd9820afd29931aab03",
|
||||
received_amount=2657946947610159065393,
|
||||
protocol=Protocol.aave,
|
||||
transaction_hash=transaction_hash,
|
||||
block_number=block_number,
|
||||
)
|
||||
|
||||
block = create_from_block_number(base_provider, w3, block_number, should_cache)
|
||||
block = load_test_block(block_number)
|
||||
trace_classifier = TraceClassifier()
|
||||
classified_traces = trace_classifier.classify(block.traces)
|
||||
result = get_liquidations(classified_traces)
|
||||
|
||||
self.assertEqual(result[0], liquidation)
|
||||
self.assertEqual(len(result), 1)
|
||||
|
||||
def test_single_liquidation_2(self):
|
||||
|
||||
# Fails precommit because these inspectors don't exist yet
|
||||
# from mev_inspect import inspector_compound
|
||||
# from mev_inspect import inspector_aave
|
||||
#
|
||||
#
|
||||
# class TestLiquidations(unittest.TestCase):
|
||||
# def test_compound_liquidation(self):
|
||||
# tx_hash = "0x0ec6d5044a47feb3ceb647bf7ea4ffc87d09244d629eeced82ba17ec66605012"
|
||||
# block_no = 11338848
|
||||
# res = inspector_compound.get_profit(tx_hash, block_no)
|
||||
# # self.assertEqual(res['profit'], 0)
|
||||
#
|
||||
# def test_aave_liquidation(self):
|
||||
# tx_hash = "0xc8d2501d28800b1557eb64c5d0e08fd6070c15b6c04c39ca05631f641d19ffb2"
|
||||
# block_no = 10803840
|
||||
# res = inspector_aave.get_profit(tx_hash, block_no)
|
||||
# # self.assertEqual(res['profit'], 0)
|
||||
transaction_hash = (
|
||||
"0x7369b6c1e1b15a761cad3e618b4df2eb84747c58fa34230e752cc2eaf241c493"
|
||||
)
|
||||
block_number = 13179291
|
||||
|
||||
liquidation = Liquidation(
|
||||
liquidated_user="0xbec69dfce4c1fa8b7843fee1ca85788d84a86b06",
|
||||
liquidator_user="0x19256c009781bc2d1545db745af6dfd30c7e9cfa",
|
||||
collateral_token_address="0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
|
||||
debt_token_address="0x6b175474e89094c44da98b954eedeac495271d0f",
|
||||
debt_purchase_amount=128362984518555820706221,
|
||||
received_amount=37818925894787751803,
|
||||
protocol=Protocol.aave,
|
||||
transaction_hash=transaction_hash,
|
||||
block_number=block_number,
|
||||
)
|
||||
|
||||
block = load_test_block(block_number)
|
||||
trace_classifier = TraceClassifier()
|
||||
classified_traces = trace_classifier.classify(block.traces)
|
||||
result = get_liquidations(classified_traces)
|
||||
|
||||
self.assertEqual(result[1], liquidation)
|
||||
self.assertEqual(len(result), 2)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Loading…
x
Reference in New Issue
Block a user