Skip to content

Commit

Permalink
Merge pull request #579 from BoostryJP/fix/#578
Browse files Browse the repository at this point in the history
Fix upper limit check when uploading external data (v23.12)
  • Loading branch information
YoshihitoAso authored Dec 22, 2023
2 parents 0ee168d + 3ab3df5 commit b157831
Show file tree
Hide file tree
Showing 4 changed files with 211 additions and 85 deletions.
5 changes: 3 additions & 2 deletions app/model/schema/ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
SPDX-License-Identifier: Apache-2.0
"""
import sys
from datetime import datetime
from typing import List, Optional

Expand Down Expand Up @@ -67,8 +68,8 @@ class CreateUpdateLedgerDetailsDataRequest(BaseModel):
name: Optional[str] = Field(None, max_length=200)
address: Optional[str] = Field(None, max_length=200)
amount: Optional[int] = Field(None, ge=0, le=1_000_000_000_000)
price: Optional[int] = Field(None, ge=0, le=5_000_000_000)
balance: Optional[int] = Field(None, ge=0, le=1_000_000_000_000 * 5_000_000_000)
price: Optional[int] = Field(None, ge=0, le=1_000_000_000_000)
balance: Optional[int] = Field(None, ge=0, le=sys.maxsize)
acquisition_date: Optional[str] = Field(
None, min_length=10, max_length=10, description="YYYY/MM/DD"
)
Expand Down
1 change: 0 additions & 1 deletion cmd/explorer/src/connector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from typing import Any

from aiohttp import ClientSession

from cache import AsyncTTL

path = os.path.join(os.path.dirname(__file__), "../../../../")
Expand Down
138 changes: 97 additions & 41 deletions tests/test_app_routers_ledger_{token_address}_details_data_POST.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
SPDX-License-Identifier: Apache-2.0
"""
import sys

from sqlalchemy import select

from app.model.db import LedgerDetailsData, Token, TokenType, TokenVersion
Expand Down Expand Up @@ -99,6 +101,61 @@ def test_normal_1(self, client, db):
assert _details_data.balance == 200
assert _details_data.acquisition_date == "2020/01/02"

# <Normal_2>
# Max value
def test_normal_2(self, client, db):
user = config_eth_account("user1")
issuer_address = user["address"]
token_address = "0xABCdeF1234567890abcdEf123456789000000000"

# prepare data
_token = Token()
_token.type = TokenType.IBET_STRAIGHT_BOND.value
_token.tx_hash = ""
_token.issuer_address = issuer_address
_token.token_address = token_address
_token.abi = {}
_token.version = TokenVersion.V_23_12
db.add(_token)

# request target API
req_param = [
{
"name": "name_test_1",
"address": "address_test_1",
"amount": 1_000_000_000_000,
"price": 1_000_000_000_000,
"balance": sys.maxsize,
"acquisition_date": "2020/01/01",
},
]
resp = client.post(
self.base_url.format(token_address=token_address),
json=req_param,
headers={
"issuer-address": issuer_address,
},
)

# assertion
assert resp.status_code == 200
assert resp.json()["data_id"] is not None

_details_data_list = db.scalars(
select(LedgerDetailsData).order_by(LedgerDetailsData.id)
).all()
assert len(_details_data_list) == 1

_details_data = _details_data_list[0]
assert _details_data.id == 1
assert _details_data.data_id == resp.json()["data_id"]
assert _details_data.name == "name_test_1"
assert _details_data.address == "address_test_1"
assert _details_data.amount == 1_000_000_000_000
assert _details_data.price == 1_000_000_000_000
assert _details_data.balance == sys.maxsize
assert _details_data.acquisition_date == "2020/01/01"

###########################################################################
# Error Case
###########################################################################
Expand Down Expand Up @@ -193,19 +250,19 @@ def test_error_3(self, client, db):
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"1",
"address": "address_test_1",
"amount": 1_000_000_000_001,
"amount": -1,
"price": -1,
"balance": 1_000_000_000_001 * 5_000_000_001,
"balance": -1,
"acquisition_date": "2020/01/01a",
},
{
"name": "name_test_2",
"address": "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"1",
"amount": -1,
"price": 5_000_000_001,
"balance": -1,
"amount": 1_000_000_000_001,
"price": 1_000_000_000_001,
"balance": sys.maxsize + 1,
"acquisition_date": "2020/02/31",
},
]
Expand All @@ -223,75 +280,74 @@ def test_error_3(self, client, db):
"meta": {"code": 1, "title": "RequestValidationError"},
"detail": [
{
"ctx": {"max_length": 200},
"input": "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901",
"type": "string_too_long",
"loc": ["body", 0, "name"],
"msg": "String should have at most 200 characters",
"type": "string_too_long",
"input": "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901",
"ctx": {"max_length": 200},
},
{
"ctx": {"le": 1000000000000},
"input": 1000000000001,
"type": "greater_than_equal",
"loc": ["body", 0, "amount"],
"msg": "Input should be less than or equal to 1000000000000",
"type": "less_than_equal",
"msg": "Input should be greater than or equal to 0",
"input": -1,
"ctx": {"ge": 0},
},
{
"ctx": {"ge": 0},
"input": -1,
"type": "greater_than_equal",
"loc": ["body", 0, "price"],
"msg": "Input should be greater than or equal to 0",
"type": "greater_than_equal",
"input": -1,
"ctx": {"ge": 0},
},
{
"ctx": {"le": 5000000000000000000000},
"input": 5000000001005000000001,
"type": "greater_than_equal",
"loc": ["body", 0, "balance"],
"msg": "Input should be less than or equal to "
"5000000000000000000000",
"type": "less_than_equal",
"msg": "Input should be greater than or equal to 0",
"input": -1,
"ctx": {"ge": 0},
},
{
"ctx": {"max_length": 10},
"input": "2020/01/01a",
"type": "string_too_long",
"loc": ["body", 0, "acquisition_date"],
"msg": "String should have at most 10 characters",
"type": "string_too_long",
"input": "2020/01/01a",
"ctx": {"max_length": 10},
},
{
"ctx": {"max_length": 200},
"input": "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901",
"type": "string_too_long",
"loc": ["body", 1, "address"],
"msg": "String should have at most 200 characters",
"type": "string_too_long",
"input": "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901",
"ctx": {"max_length": 200},
},
{
"ctx": {"ge": 0},
"input": -1,
"type": "less_than_equal",
"loc": ["body", 1, "amount"],
"msg": "Input should be greater than or equal to 0",
"type": "greater_than_equal",
"msg": "Input should be less than or equal to 1000000000000",
"input": 1000000000001,
"ctx": {"le": 1000000000000},
},
{
"ctx": {"le": 5000000000},
"input": 5000000001,
"loc": ["body", 1, "price"],
"msg": "Input should be less than or equal to 5000000000",
"type": "less_than_equal",
"loc": ["body", 1, "price"],
"msg": "Input should be less than or equal to 1000000000000",
"input": 1000000000001,
"ctx": {"le": 1000000000000},
},
{
"ctx": {"ge": 0},
"input": -1,
"type": "less_than_equal",
"loc": ["body", 1, "balance"],
"msg": "Input should be greater than or equal to 0",
"type": "greater_than_equal",
"msg": "Input should be less than or equal to 9223372036854775807",
"input": 9223372036854775808,
"ctx": {"le": 9223372036854775807},
},
{
"ctx": {"error": {}},
"input": "2020/02/31",
"type": "value_error",
"loc": ["body", 1, "acquisition_date"],
"msg": "Value error, The date format must be YYYY/MM/DD",
"type": "value_error",
"input": "2020/02/31",
"ctx": {"error": {}},
},
],
}
Expand Down
Loading

0 comments on commit b157831

Please sign in to comment.