From f4ba2a693d4fc89c6aa19d887f06cc2e8cf70e66 Mon Sep 17 00:00:00 2001 From: OjusWiZard Date: Thu, 15 Feb 2024 15:56:10 +0530 Subject: [PATCH] Chore (CI): Test CSVs header and addresses Signed-off-by: OjusWiZard --- README.md | 2 ++ airdrops/1inch.csv | 2 +- airdrops/diva.csv | 2 +- airdrops/ens.csv | 2 +- airdrops/furucombo_airdrop.csv | 2 +- airdrops/psp.csv | 2 +- airdrops/saddle_finance.csv | 2 +- airdrops/shapeshift.csv | 2 +- airdrops/shutter.csv | 2 +- airdrops/uniswap.csv | 2 +- scripts/checksum_addresses.py | 22 ++++++++++++++++++++++ tests/test_airdrops.py | 17 ++++++++++++++++- 12 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 scripts/checksum_addresses.py diff --git a/README.md b/README.md index c3435cc..bd3832c 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ Repo containing various data that can be pulled by the app - It's entry should be added in the `airdrops/index_v1.json` under the `airdrops` field. - If the token is new and is not expected to exist in the userDB and globalDB then `new_asset_data` should be added in the index. - It's CSV should be added in `airdrops/` directory, with its path provided in its index entry. + - The CSV's header should have first column as `address` and second column as `amount`. + - The amounts should be normalised according to their decimals. - If the asset's icon is not present in `rotki` repo, it should be added in `airdrops/icons` directory, with its path provided in its airdrop's index entry. - CSV should have one line header. First column should be `address`, and second column should be the `amount` in the decimal normalised form. ### POAP Airdrops diff --git a/airdrops/1inch.csv b/airdrops/1inch.csv index 72ff0f2..562dec9 100644 --- a/airdrops/1inch.csv +++ b/airdrops/1inch.csv @@ -1,4 +1,4 @@ -address,tokens +address,amount 0xa0f75491720835b36edC92D06DDc468D201e9b73,9749686.003287061223247467 0x28d804Bf2212E220BC2B7B6252993Db8286dF07f,1344238.68647478240512482 0x2C18c9B00b4B3F5240c72513eDB778d6f7e2E65a,1334108.849354363658021531 diff --git a/airdrops/diva.csv b/airdrops/diva.csv index d4bf5b3..038f850 100644 --- a/airdrops/diva.csv +++ b/airdrops/diva.csv @@ -1,4 +1,4 @@ -address,earnings +address,amount 0x00173C4cB23E6d876fcb036bA954A2F9cfCafA19,12000 0x001d7cCf4bd1f7997BBFC8Db07b00Ec154f3fb20,12000 0x005C17dd5BEAad3cb9226bB50a02f066eB125E0B,12000 diff --git a/airdrops/ens.csv b/airdrops/ens.csv index 9523bde..81700af 100644 --- a/airdrops/ens.csv +++ b/airdrops/ens.csv @@ -1,4 +1,4 @@ -owner,amount +address,amount 0xc58a205a6eA0bC349Ac0F55A0dbf7Ca4596D013C,1143.54420443468825396849 0x671294753e6627a7E6c4ca4d41578aC4D43dbaeF,1143.54420443468825396849 0x324D9c68CDfFF092dF515075989a2a1A06417Ba3,1143.54420443468825396849 diff --git a/airdrops/furucombo_airdrop.csv b/airdrops/furucombo_airdrop.csv index 0c7440c..66822ff 100644 --- a/airdrops/furucombo_airdrop.csv +++ b/airdrops/furucombo_airdrop.csv @@ -1,4 +1,4 @@ -address,total,week_0,week_1,week_2,week_3,week_4,week_5,week_6,week_7,week_8 +address,amount,week_0,week_1,week_2,week_3,week_4,week_5,week_6,week_7,week_8 0xfa396090B4dfD2bd86bbf6de63635d6E390b5dE1,350,87.5,32.8125,32.8125,32.8125,32.8125,32.8125,32.8125,32.8125,32.8125 0xe2689e394faE140069486becf07508a4b8AE2a32,350,87.5,32.8125,32.8125,32.8125,32.8125,32.8125,32.8125,32.8125,32.8125 0xe64b1A000b931080A73546d4ED5d742495Ce2a92,350,87.5,32.8125,32.8125,32.8125,32.8125,32.8125,32.8125,32.8125,32.8125 diff --git a/airdrops/psp.csv b/airdrops/psp.csv index a58a50d..0728fb7 100644 --- a/airdrops/psp.csv +++ b/airdrops/psp.csv @@ -1,4 +1,4 @@ -user,amount +address,amount 0x00000000005eF87F8cA7014309eCe7260BbcDAEB,10400 0x00000000034b55ebd82cde9b38a85aB0978B7a47,7800 0x00000000b9d747EF42D224e572a5B7e6488929c8,7800 diff --git a/airdrops/saddle_finance.csv b/airdrops/saddle_finance.csv index f247b3e..197d833 100644 --- a/airdrops/saddle_finance.csv +++ b/airdrops/saddle_finance.csv @@ -1,4 +1,4 @@ -owner,amount +address,amount 0x0000000000002D534FF79e9C69e7Fcc742f0BE83,1674480910917615539182 0x000000000000aBE945C436595Ce765A8A261317b,1674480910917615539182 0x0000000000e189dD664b9aB08a33C4839953852c,5052206130010104000000 diff --git a/airdrops/shapeshift.csv b/airdrops/shapeshift.csv index a6d4490..9c54687 100644 --- a/airdrops/shapeshift.csv +++ b/airdrops/shapeshift.csv @@ -1,4 +1,4 @@ -user,amount +address,amount 0x00E05C577e2D0f5ed2EAC3b1FB9e4ed7ce5971F6,150 0x0194D670D1B978E9F94EFDD04301179277f82D57,150 0x019557b83D09AB03Cff1709061e378e2d7fd19ca,150 diff --git a/airdrops/shutter.csv b/airdrops/shutter.csv index 40b215c..77a0857 100644 --- a/airdrops/shutter.csv +++ b/airdrops/shutter.csv @@ -1,4 +1,4 @@ -owner,amount +address,amount 0x8eEF779818Afa953b0652e45438423ebE089F55A,1086.956521739130000000 0x2Ea5E9E452F85f55Be47504153f25740A5f3D78A,1086.956521739130000000 0xD03Ad690ed8065EDfdC1E08197a3ebC71535A7ff,1086.956521739130000000 diff --git a/airdrops/uniswap.csv b/airdrops/uniswap.csv index 09fd7d1..1e2a884 100644 --- a/airdrops/uniswap.csv +++ b/airdrops/uniswap.csv @@ -1,4 +1,4 @@ -address,uni,is_lp,is_user,is_socks +address,amount,is_lp,is_user,is_socks 0x0000000000000000000000000000000000000000,400,True,True,False 0x0000000000000000000000000000000000000001,5988.626491,True,True,False 0x0000000000000000000000000000000000001337,400.010855,True,True,False diff --git a/scripts/checksum_addresses.py b/scripts/checksum_addresses.py new file mode 100644 index 0000000..a6ddeeb --- /dev/null +++ b/scripts/checksum_addresses.py @@ -0,0 +1,22 @@ +import csv +import sys +from eth_utils import to_checksum_address + + +if __name__ == '__main__': + data = [] + + try: + csv_path = sys.argv[1] + except IndexError as e: + raise ValueError('Please provide a csv file path') from e + + with open(csv_path) as f: + reader = csv.DictReader(f) # read rows into a dictionary format + for row in reader: + data.append((to_checksum_address(row['address']), row['amount'])) + + with open(csv_path, 'w') as f: + writer = csv.writer(f, delimiter=',') + writer.writerow(['address', 'amount']) + writer.writerows(data) diff --git a/tests/test_airdrops.py b/tests/test_airdrops.py index 406a657..868553f 100644 --- a/tests/test_airdrops.py +++ b/tests/test_airdrops.py @@ -1,8 +1,10 @@ +import csv import json import os -from jsonschema import validate import pytest import requests +from eth_utils import is_checksum_address +from jsonschema import validate ROTKI_REPO_BASE = 'https://raw.githubusercontent.com/rotki/rotki/develop' @@ -24,6 +26,19 @@ def test_airdrops_metadata(): assert os.path.exists(airdrop['icon_path']) +def test_csvs(): + with open('airdrops/index_v1.json', 'r') as f: + airdrop_index = json.load(f) + + for airdrop in airdrop_index['airdrops'].values(): + with open(airdrop['csv_path']) as f: + reader = csv.DictReader(f) # read rows into a dictionary format + assert 'address' in reader.fieldnames, f'{airdrop["csv_path"]} airdrop missing `address` header' + assert 'amount' in reader.fieldnames, f'{airdrop["csv_path"]} airdrop missing `amount` header' + for row in reader: # test that all addresses are checksummed + assert is_checksum_address(row['address']), f'{airdrop["name"]} airdrop address {row["address"]} is not checksummed' + + @pytest.mark.skip('It makes too many requests') def test_data_migration(): old_airdrop_urls = {