Skip to content

Commit

Permalink
Merge pull request #14 from gnosischain/fix/db
Browse files Browse the repository at this point in the history
DB: fix issues with /info enpoint and missing DB data.
  • Loading branch information
giacomognosis authored Mar 7, 2024
2 parents 34d10ae + 5d47000 commit b10f11c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
12 changes: 9 additions & 3 deletions api/api/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,17 @@ def create_enabled_token_cmd(name, chain_id, address, max_amount_day, type):
current_app.config['FAUCET_PRIVATE_KEY']
)

# check if Token already exists
check_token = Token.get_by_address(w3.to_checksum_address(address))

if check_token:
raise Exception('Token %s already exists' % address)

# Checks
if type.lower() != 'native' or type.lower() != 'erc20':
raise Exception('Type must be any of (erc20, native)')
if type.lower() not in ('native', 'erc20'):
raise Exception('Type must be any of (erc20, native) got %s' % type)
if float(max_amount_day) <= 0:
raise Exception('Max amount per day must be greater than 0')
raise Exception('Max amount per day must be greater than 0, got %d' % float(max_amount_day))

token = Token()
token.name = name
Expand Down
3 changes: 2 additions & 1 deletion api/api/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def info():
{
'address': t.address,
'name': t.name,
'maximumAmount': t.max_amount_day
'maximumAmount': t.max_amount_day,
'type': t.type
} for t in enabled_tokens
]
return jsonify(
Expand Down
8 changes: 5 additions & 3 deletions api/api/services/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,11 @@ class Token(BaseModel):

@classmethod
def enabled_tokens(cls):
return cls.query.with_entities(cls.name,
cls.address,
cls.chain_id).filter_by(enabled=True).all()
return cls.query.filter_by(enabled=True).all()

@classmethod
def get_by_address(cls, address):
return cls.query.filter_by(address=address).first()


class AccessKey(BaseModel):
Expand Down
4 changes: 4 additions & 0 deletions api/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def test_status_route(self, client):
assert response.status_code == 200
assert response.get_json().get('status') == 'ok'

def test_info_route(self, client):
response = client.get(api_prefix + '/info')
assert response.status_code == 200

def test_ask_route_parameters(self, client):
response = client.post(api_prefix + '/ask', json={})
assert response.status_code == 400
Expand Down

0 comments on commit b10f11c

Please sign in to comment.