Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Commit

Permalink
[CIP-20] Fix Integer Types (#32)
Browse files Browse the repository at this point in the history
Before (with scientific notation): https://jsonblob.com/1087344842706796544

After (with Pure WEI Integers): https://jsonblob.com/1087342979563405312
  • Loading branch information
bh2smith authored Mar 20, 2023
1 parent edffd47 commit 4aac035
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 50 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ check:
make lint
make types

test-unit:
python -m pytest tests/unit

test-integration:
python -m pytest tests/integration

test:
python -m pytest tests

Expand Down
14 changes: 7 additions & 7 deletions src/models/batch_rewards_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ def from_pdf_to_dune_records(cls, rewards_df: DataFrame) -> list[dict[str, Any]]
"block_deadline": int(row["block_deadline"]),
"data": {
# All the following values are in WEI.
"uncapped_payment_eth": str(row["uncapped_payment_eth"]),
"capped_payment": str(row["capped_payment"]),
"execution_cost": str(row["execution_cost"]),
"surplus": str(row["surplus"]),
"fee": str(row["fee"]),
"winning_score": str(row["winning_score"]),
"reference_score": str(row["reference_score"]),
"uncapped_payment_eth": int(row["uncapped_payment_eth"]),
"capped_payment": int(row["capped_payment"]),
"execution_cost": int(row["execution_cost"]),
"surplus": int(row["surplus"]),
"fee": int(row["fee"]),
"winning_score": int(row["winning_score"]),
"reference_score": int(row["reference_score"]),
"participating_solvers": row["participating_solvers"],
},
}
Expand Down
14 changes: 7 additions & 7 deletions src/sql/orderbook/batch_rewards.sql
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ SELECT settlement_block as block_number,
else concat('0x', encode(tx_hash, 'hex'))
end as tx_hash,
concat('0x', encode(solver, 'hex')) as solver,
execution_cost,
surplus,
fee,
uncapped_payment_eth,
capped_payment,
winning_score,
reference_score,
execution_cost::text as execution_cost,
surplus::text as surplus,
fee::text as fee,
uncapped_payment_eth::text as uncapped_payment_eth,
capped_payment::text as capped_payment,
winning_score::text as winning_score,
reference_score::text as reference_score,
participating_solvers
FROM reward_per_auction
42 changes: 21 additions & 21 deletions tests/integration/test_fetch_orderbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,39 +59,39 @@ def test_get_batch_rewards(self):
"0x55a37a2e5e5973510ac9d9c723aec213fa161919",
],
"execution_cost": [
5417013431615490.0,
14681404168612460.0,
0.0,
5417013431615490,
14681404168612460,
0,
],
"surplus": [
5867838023808109.0,
104011002982952096.0,
0.0,
5867838023808109,
104011002982952096,
0,
],
"fee": [
7751978767036064.0,
10350680045815652.0,
0.0,
7751978767036064,
10350680045815652,
0,
],
"uncapped_payment_eth": [
7232682540629268.0,
82825156151734416.0,
-3527106002507021.0,
7232682540629268,
82825156151734416,
-3527106002507021,
],
"capped_payment": [
7232682540629268.0,
24681404168612460.0,
-3527106002507021.0,
7232682540629268,
24681404168612460,
-3527106002507021,
],
"winning_score": [
6537976145828389.0,
95640781782532192.0,
3527282436747751.0,
6537976145828389,
95640781782532192,
3527282436747751,
],
"reference_score": [
6387134250214905.0,
31536526877033328.0,
3527106002507021.0,
6387134250214905,
31536526877033328,
3527106002507021,
],
"participating_solvers": [
[
Expand Down
31 changes: 16 additions & 15 deletions tests/unit/test_batch_rewards_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

class TestModelBatchRewards(unittest.TestCase):
def test_order_rewards_transformation(self):
max_uint = 115792089237316195423570985008687907853269984665640564039457584007913129639936
sample_df = pd.DataFrame(
{
"block_number": pd.Series([123, pandas.NA], dtype="Int64"),
Expand All @@ -26,7 +27,7 @@ def test_order_rewards_transformation(self):
"surplus": [2 * ONE_ETH, 3 * ONE_ETH],
"fee": [
1000000000000000,
0,
max_uint,
],
"uncapped_payment_eth": [0, -10 * ONE_ETH],
"capped_payment": [-1000000000000000, -1000000000000000],
Expand Down Expand Up @@ -56,14 +57,14 @@ def test_order_rewards_transformation(self):
"block_deadline": 789,
"block_number": 123,
"data": {
"capped_payment": "-1000000000000000",
"execution_cost": "9999000000000000000000",
"fee": "1000000000000000",
"capped_payment": -1000000000000000,
"execution_cost": 9999000000000000000000,
"fee": 1000000000000000,
"participating_solvers": ["0x51", "0x52", "0x53"],
"reference_score": "1000000000000000000",
"surplus": "2000000000000000000",
"uncapped_payment_eth": "0",
"winning_score": "123456000000000000000000",
"reference_score": 1000000000000000000,
"surplus": 2000000000000000000,
"uncapped_payment_eth": 0,
"winning_score": 123456000000000000000000,
},
"solver": "0x51",
"tx_hash": "0x71",
Expand All @@ -72,9 +73,9 @@ def test_order_rewards_transformation(self):
"block_deadline": 1011,
"block_number": None,
"data": {
"capped_payment": "-1000000000000000",
"execution_cost": "1",
"fee": "0",
"capped_payment": -1000000000000000,
"execution_cost": 1,
"fee": max_uint,
"participating_solvers": [
"0x51",
"0x52",
Expand All @@ -83,10 +84,10 @@ def test_order_rewards_transformation(self):
"0x55",
"0x56",
],
"reference_score": "2000000000000000000",
"surplus": "3000000000000000000",
"uncapped_payment_eth": "-10000000000000000000",
"winning_score": "6789000000000000000000",
"reference_score": 2000000000000000000,
"surplus": 3000000000000000000,
"uncapped_payment_eth": -10000000000000000000,
"winning_score": 6789000000000000000000,
},
"solver": "0x52",
"tx_hash": None,
Expand Down

0 comments on commit 4aac035

Please sign in to comment.