Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update primary key definitions #758

Merged
merged 5 commits into from
Feb 13, 2025
Merged

Update primary key definitions #758

merged 5 commits into from
Feb 13, 2025

Conversation

purplesmoke05
Copy link
Member

@purplesmoke05 purplesmoke05 marked this pull request as draft February 12, 2025 12:40
@purplesmoke05 purplesmoke05 force-pushed the feature/#757 branch 2 times, most recently from 0832965 to df29f52 Compare February 12, 2025 14:16
Copy link

github-actions bot commented Feb 12, 2025

Coverage

Coverage Report •
FileStmtsMissCoverMissing
app/model/db
   idx_personal_info.py56394%80, 98, 150
   idx_position.py29196%91
app/model/schema
   personal_info.py710100% 
app/routers/issuer
   bond.py117989624%228–229, 234–235, 238, 241, 246–248, 261–262, 265–266, 269, 285–291, 293, 295–302, 304, 307–308, 314–315, 318–325, 328–335, 338, 340, 343–351, 354–361, 365, 409–410, 412, 415–416, 419–422, 424, 452–455, 458–463, 465, 511–512, 531–534, 537–538, 544, 548–550, 554–556, 561–562, 569–570, 573–580, 583, 607–608, 612–613, 618–619, 622, 626–627, 630, 638–640, 642–643, 645, 648–651, 655, 703–706, 709, 716, 719–721, 723–724, 726, 729–732, 736–739, 750, 805–806, 825–828, 831–832, 837–838, 840, 871–872, 877–878, 880, 883–886, 890–893, 904, 913, 970–973, 976, 979–986, 988–994, 998, 1036–1037, 1059, 1070, 1115–1118, 1121, 1128, 1131–1133, 1135–1136, 1138, 1141–1144, 1148–1151, 1162, 1217–1218, 1237–1240, 1243–1244, 1249–1250, 1252, 1284–1285, 1290–1291, 1293, 1296–1299, 1303–1306, 1317, 1326, 1383–1386, 1389, 1392–1399, 1401–1407, 1411, 1449–1450, 1472, 1483, 1542–1544, 1547–1548, 1562, 1620–1623, 1626–1627, 1633, 1637–1639, 1643–1644, 1648, 1653–1658, 1661–1664, 1667, 1725–1728, 1730–1731, 1733–1734, 1740, 1744–1746, 1750–1751, 1755, 1760–1765, 1768–1771, 1773, 1777, 1824–1825, 1827, 1830–1831, 1895–1896, 1898, 1901–1902, 1913, 1916, 1942–1943, 1960–1963, 1966–1967, 2011–2012, 2022–2029, 2031, 2035–2037, 2040–2041, 2044–2045, 2049–2056, 2058, 2062–2064, 2068–2069, 2073–2074, 2079–2080, 2084–2085, 2091–2092, 2101–2108, 2110, 2112–2113, 2115–2116, 2118, 2121–2124, 2136, 2147–2148, 2155, 2160–2163, 2165, 2171, 2187, 2223–2224, 2241–2244, 2247, 2277, 2304–2305, 2322–2325, 2363–2369, 2371–2375, 2377–2380, 2382, 2389, 2411–2412, 2414, 2429–2430, 2432, 2434, 2446, 2501–2504, 2508–2516, 2520, 2580–2583, 2586, 2598–2603, 2608, 2612, 2614–2616, 2621, 2626–2627, 2629, 2661–2664, 2667, 2673–2674, 2679–2680, 2682, 2685–2688, 2694–2697, 2705, 2773–2778, 2780–2786, 2788–2789, 2791–2797, 2800, 2805, 2812–2813, 2815–2816, 2820, 2824, 2867–2868, 2882, 2982–2988, 2991, 2993–2996, 2999–3000, 3003–3004, 3011–3013, 3015, 3017, 3019, 3024–3027, 3029, 3046–3051, 3069, 3078, 3121–3122, 3141–3144, 3146–3147, 3152–3153, 3155, 3185–3188, 3191–3193, 3215–3216, 3222–3223, 3229–3234, 3239–3240, 3245–3258, 3262–3268, 3270–3271, 3273–3274, 3276, 3279–3282, 3288–3291, 3314, 3425–3428, 3432–3433, 3442, 3454, 3494–3497, 3500, 3553–3555, 3596–3601, 3606–3607, 3609–3611, 3613–3614, 3616, 3619–3622, 3635–3636, 3644–3649, 3651–3652, 3654–3657, 3659–3660, 3662, 3664, 3667, 3669, 3672, 3676–3677, 3680, 3682, 3684–3685, 3688, 3692, 3694–3695, 3698, 3702, 3704, 3713, 3722, 3746, 3802–3803, 3821–3824, 3839–3840, 3842–3846, 3850–3851, 3856, 3875–3876, 3891–3892, 3908–3909, 3918–3922, 3926–3927, 3932, 3936–3937, 3942–3945, 3947, 3949–3952, 3957, 3959–3961, 3963–3965, 3970, 3972–3976, 3979–3984, 3987, 3990, 4025–4028, 4043–4044, 4063–4064, 4069–4070, 4076–4079, 4085–4087, 4089–4094, 4096–4097, 4099–4102, 4104–4105, 4107, 4109, 4112, 4114, 4117, 4121–4122, 4125, 4127, 4129–4130, 4133, 4137, 4139–4140, 4143, 4147, 4153, 4158–4159, 4174, 4191, 4195, 4216, 4262–4264, 4266–4267, 4270, 4287–4290, 4295, 4298–4304, 4307–4317, 4321, 4368, 4371–4374, 4378–4381, 4392, 4484, 4487–4490, 4496–4497, 4502, 4527–4528, 4530
   position.py17811237%143–144, 149–152, 158–159, 161–165, 167, 187, 197, 238–239, 244–247, 253–254, 256–263, 274, 283, 362–368, 371, 373, 375–376, 379–384, 387–388, 395–397, 399, 401, 403, 408–411, 413, 430–439, 441–442, 460, 469, 511–512, 515–516, 534–537, 540, 547–548, 553–556, 558, 607–610, 639–641, 643–644, 646, 648, 653–657, 659, 672
   share.py116587724%229–230, 235–237, 240, 243, 246, 257–258, 261–262, 265, 277–283, 285, 287–294, 296, 299–300, 306–307, 310–317, 320–327, 330, 332, 335–343, 346–353, 357, 395–396, 398–400, 403–406, 408, 436–439, 442–447, 449, 495–496, 515–518, 521–523, 528–529, 536–537, 540–547, 550, 574–575, 579–580, 585–586, 589, 593–594, 597, 605–607, 609–610, 612, 615–618, 622, 670–673, 676, 683, 686–688, 690–691, 693, 696–699, 703–706, 717, 772–773, 792–795, 798–799, 804–805, 807, 838–839, 844–845, 847, 850–853, 857–860, 871, 880, 937–940, 943, 946–953, 955–961, 965, 1003–1004, 1026, 1037, 1082–1085, 1088, 1095, 1098–1100, 1102–1103, 1105, 1108–1111, 1115–1118, 1129, 1184–1185, 1204–1207, 1210–1211, 1216–1217, 1219, 1251–1252, 1257–1258, 1260, 1263–1266, 1270–1273, 1284, 1293, 1350–1353, 1356, 1359–1366, 1368–1374, 1378, 1416–1417, 1439, 1450, 1509–1511, 1514–1515, 1529, 1587–1590, 1593–1595, 1600–1605, 1608–1611, 1615, 1673–1676, 1678–1679, 1681–1683, 1688–1693, 1696–1699, 1701, 1705, 1752–1753, 1755, 1758–1759, 1823–1824, 1826, 1829–1830, 1841, 1844, 1870–1871, 1888–1891, 1894–1895, 1939–1940, 1950–1957, 1959, 1963–1965, 1968–1969, 1972–1973, 1977–1984, 1986, 1990–1992, 1996–1997, 2001–2002, 2007–2008, 2012–2013, 2019–2020, 2029–2036, 2038, 2040–2041, 2043–2044, 2046, 2049–2052, 2064, 2075–2076, 2083, 2088–2091, 2093, 2099, 2115, 2151–2152, 2169–2172, 2175, 2205, 2232–2233, 2250–2253, 2291–2297, 2299–2303, 2305–2308, 2310, 2317, 2339–2340, 2342, 2357–2358, 2360, 2362, 2374, 2429–2432, 2436–2444, 2448, 2508–2511, 2514, 2526–2531, 2536, 2540, 2542–2544, 2549, 2554–2555, 2557, 2589–2592, 2595, 2601–2602, 2607–2608, 2610, 2613–2616, 2622–2625, 2633, 2701–2706, 2708–2714, 2716–2717, 2719–2725, 2728, 2732, 2739–2740, 2742–2743, 2747, 2751, 2796–2797, 2811, 2917–2919, 2921–2924, 2927, 2929–2932, 2935–2936, 2939–2940, 2947–2949, 2951, 2953, 2955, 2960–2963, 2965, 2982–2987, 3005, 3014, 3058–3059, 3078–3081, 3083–3084, 3089–3090, 3092, 3122–3125, 3128–3130, 3152–3153, 3159–3160, 3166–3171, 3176–3177, 3182–3195, 3199–3205, 3207–3208, 3210–3211, 3213, 3216–3219, 3225–3228, 3251, 3362–3365, 3369–3370, 3379, 3391, 3431–3434, 3437, 3490–3492, 3533–3538, 3543–3544, 3546–3548, 3550–3551, 3553, 3556–3559, 3572–3573, 3581–3586, 3588–3589, 3591–3594, 3596–3597, 3599, 3601, 3604, 3606, 3609, 3613–3614, 3617, 3619, 3621–3622, 3625, 3629, 3631–3632, 3635, 3639, 3641, 3650, 3659, 3683, 3739–3740, 3758–3761, 3776–3777, 3779–3783, 3787–3788, 3793, 3812–3813, 3828–3829, 3845–3846, 3855–3859, 3863–3864, 3869, 3873–3874, 3879–3882, 3884, 3886–3889, 3894, 3896–3898, 3900–3902, 3907, 3909–3913, 3916–3921, 3924, 3927, 3958–3961, 3976–3977, 3996–3997, 4002–4003, 4009–4012, 4018–4020, 4022–4027, 4029–4030, 4032–4035, 4037–4038, 4040, 4042, 4045, 4047, 4050, 4054–4055, 4058, 4060, 4062–4063, 4066, 4070, 4072–4073, 4076, 4080, 4086, 4091–4092, 4107, 4124, 4128, 4150, 4196–4198, 4200–4201, 4204, 4221–4224, 4229, 4232–4238, 4241–4251, 4255, 4302, 4305–4308, 4312–4315, 4326, 4418, 4421–4424, 4430–4431, 4436, 4461–4462, 4464
tests/app
   test_ledger_RetrieveLedgerHistory.py5210100% 
   test_sealed_tx_SealedTxRegisterPersonalInfo.py880100% 
   test_token_holders_ListTokenHoldersPersonalInfo.py3720100% 
tests/batch
   test_indexer_personal_info.py5230100% 
   test_processor_update_token.py5460100% 
TOTAL81090420294% 

Tests Skipped Failures Errors Time
2059 0 💤 0 ❌ 0 🔥 19m 16s ⏱️

@purplesmoke05 purplesmoke05 marked this pull request as ready for review February 12, 2025 23:58
Comment on lines 2041 to +2042
personal_get_info_mock_patch.assert_has_calls(
[call(account_address=account_address_2, default_value=None)]
[call(account_address=account_address_1, default_value=None)]
Copy link
Member

@YoshihitoAso YoshihitoAso Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test case probably wants to test something like this:

    # <Normal_3_5>
    # latest_flg = 1 (Get the latest personal info)
    #   - address_1 has personal info in the DB but the values are null
    #   - address_2 has personal info in the DB
    @pytest.mark.asyncio
    async def test_normal_3_5(self, async_client, async_db):
        user_1 = config_eth_account("user1")
        issuer_address = user_1["address"]
        token_address = "0xABCdeF1234567890abcdEf123456789000000000"
        account_address_1 = "0xABCdeF1234567890abCDeF123456789000000001"
        account_address_2 = "0xaBcdEF1234567890aBCDEF123456789000000002"
        personal_info_contract_address = "0xabcDEF1234567890AbcDEf123456789000000003"

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

        _ledger_1 = Ledger()
        _ledger_1.token_address = token_address
        _ledger_1.token_type = TokenType.IBET_STRAIGHT_BOND
        _ledger_1.ledger = {
            "created": "2022/12/01",
            "token_name": "テスト原簿",
            "currency": "JPY",
            "headers": [
                {
                    "key": "aaa",
                    "value": "aaa",
                },
                {
                    "hoge": "aaaa",
                    "fuga": "bbbb",
                },
            ],
            "details": [
                {
                    "token_detail_type": "権利_test_1",
                    "headers": [
                        {
                            "key": "aaa",
                            "value": "aaa",
                        },
                        {"test1": "a", "test2": "b"},
                    ],
                    "data": [
                        {
                            "account_address": account_address_1,
                            "name": "name_test_1",
                            "address": "address_test_1",
                            "amount": 10,
                            "price": 20,
                            "balance": 30,
                            "acquisition_date": "2022/12/02",
                        },
                        {
                            "account_address": account_address_2,
                            "name": "name_test_2",
                            "address": "address_test_2",
                            "amount": 100,
                            "price": 200,
                            "balance": 300,
                            "acquisition_date": "2022/12/03",
                        },
                    ],
                    "footers": [
                        {
                            "key": "aaa",
                            "value": "aaa",
                        },
                        {"f-test1": "a", "f-test2": "b"},
                    ],
                    "some_personal_info_not_registered": False,
                },
                {
                    "token_detail_type": "権利_test_2",
                    "headers": [
                        {
                            "key": "aaa",
                            "value": "aaa",
                        },
                        {"test1-1": "a", "test2-1": "b"},
                    ],
                    "data": [
                        {
                            "account_address": None,
                            "name": "name_test_1",
                            "address": "address_test_1",
                            "amount": 10,
                            "price": 20,
                            "balance": 200,
                            "acquisition_date": "2020/01/01",
                        },
                        {
                            "account_address": None,
                            "name": "name_test_2",
                            "address": "address_test_2",
                            "amount": 20,
                            "price": 30,
                            "balance": 600,
                            "acquisition_date": "2020/01/02",
                        },
                    ],
                    "footers": [
                        {
                            "key": "aaa",
                            "value": "aaa",
                        },
                        {"f-test1-1": "a", "f-test2-1": "b"},
                    ],
                    "some_personal_info_not_registered": False,
                },
            ],
            "footers": [
                {
                    "key": "aaa",
                    "value": "aaa",
                },
                {
                    "f-hoge": "aaaa",
                    "f-fuga": "bbbb",
                },
            ],
        }
        _ledger_1.ledger_created = datetime.strptime(
            "2022/01/01 15:20:30", "%Y/%m/%d %H:%M:%S"
        )  # JST 2022/01/02
        async_db.add(_ledger_1)

        _idx_personal_info_1 = IDXPersonalInfo()  # Note: account_address_1 has personal information in DB but the values are null
        _idx_personal_info_1.account_address = account_address_1
        _idx_personal_info_1.issuer_address = issuer_address
        _idx_personal_info_1.personal_info = {
            "name": None,
            "address": None,
        }
        _idx_personal_info_1.data_source = PersonalInfoDataSource.ON_CHAIN
        async_db.add(_idx_personal_info_1)

        _idx_personal_info_2 = IDXPersonalInfo()  # Note: account_address_2 has personal information in DB
        _idx_personal_info_2.account_address = account_address_2
        _idx_personal_info_2.issuer_address = issuer_address
        _idx_personal_info_2.personal_info = {
            "name": "name_db_2",
            "address": "address_db_2",
        }
        _idx_personal_info_2.data_source = PersonalInfoDataSource.ON_CHAIN
        async_db.add(_idx_personal_info_2)

        _details_1 = LedgerDetailsTemplate()
        _details_1.token_address = token_address
        _details_1.token_detail_type = "権利_test_1"
        _details_1.headers = [
            {
                "key": "aaa",
                "value": "aaa",
            },
            {"test1": "a", "test2": "b"},
        ]
        _details_1.footers = [
            {
                "key": "aaa",
                "value": "aaa",
            },
            {"f-test1": "a", "f-test2": "b"},
        ]
        _details_1.data_type = LedgerDataType.IBET_FIN
        _details_1.data_source = token_address
        async_db.add(_details_1)

        await async_db.commit()

        # Mock
        token = IbetStraightBondContract()
        token.personal_info_contract_address = personal_info_contract_address
        token.issuer_address = issuer_address
        token.require_personal_info_registered = True
        token_get_mock = mock.patch(
            "app.model.blockchain.IbetStraightBondContract.get", return_value=token
        )
        personal_get_info_mock = mock.patch(
            "app.model.blockchain.PersonalInfoContract.get_info"
        )

        # request target API
        with (
            token_get_mock,
            personal_get_info_mock as personal_get_info_mock_patch,
        ):
            # Note:
            # account_address_1 has no personal information in the DB
            # and gets information from the contract
            personal_get_info_mock_patch.side_effect = [
                {
                    "name": "name_contract_1",
                    "address": "address_contract_1",
                },
                {
                    "name": "name_contract_2",
                    "address": "address_contract_2",
                },
            ]

            resp = await async_client.get(
                self.base_url.format(token_address=token_address, ledger_id=1),
                params={
                    "latest_flg": 1,
                },
                headers={
                    "issuer-address": issuer_address,
                },
            )
            # assertion
            personal_get_info_mock_patch.assert_has_calls(
                [call(account_address=account_address_1, default_value=None)]
            )

        # assertion
        assert resp.status_code == 200
        assert resp.json() == {
            "created": "2022/12/01",
            "token_name": "テスト原簿",
            "currency": "JPY",
            "headers": [
                {
                    "key": "aaa",
                    "value": "aaa",
                },
                {
                    "hoge": "aaaa",
                    "fuga": "bbbb",
                },
            ],
            "details": [
                {
                    "token_detail_type": "権利_test_1",
                    "headers": [
                        {
                            "key": "aaa",
                            "value": "aaa",
                        },
                        {"test1": "a", "test2": "b"},
                    ],
                    "data": [
                        {
                            "account_address": account_address_1,
                            "name": "name_contract_1",
                            "address": "address_contract_1",
                            "amount": 10,
                            "price": 20,
                            "balance": 30,
                            "acquisition_date": "2022/12/02",
                        },
                        {
                            "account_address": account_address_2,
                            "name": "name_db_2",
                            "address": "address_db_2",
                            "amount": 100,
                            "price": 200,
                            "balance": 300,
                            "acquisition_date": "2022/12/03",
                        },
                    ],
                    "footers": [
                        {
                            "key": "aaa",
                            "value": "aaa",
                        },
                        {"f-test1": "a", "f-test2": "b"},
                    ],
                    "some_personal_info_not_registered": False,
                },
                {
                    "token_detail_type": "権利_test_2",
                    "headers": [
                        {
                            "key": "aaa",
                            "value": "aaa",
                        },
                        {"test1-1": "a", "test2-1": "b"},
                    ],
                    "data": [
                        {
                            "account_address": None,
                            "name": "name_test_1",
                            "address": "address_test_1",
                            "amount": 10,
                            "price": 20,
                            "balance": 200,
                            "acquisition_date": "2020/01/01",
                        },
                        {
                            "account_address": None,
                            "name": "name_test_2",
                            "address": "address_test_2",
                            "amount": 20,
                            "price": 30,
                            "balance": 600,
                            "acquisition_date": "2020/01/02",
                        },
                    ],
                    "footers": [
                        {
                            "key": "aaa",
                            "value": "aaa",
                        },
                        {"f-test1-1": "a", "f-test2-1": "b"},
                    ],
                    "some_personal_info_not_registered": False,
                },
            ],
            "footers": [
                {
                    "key": "aaa",
                    "value": "aaa",
                },
                {
                    "f-hoge": "aaaa",
                    "f-fuga": "bbbb",
                },
            ],
        }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I understand properly this test case verifies fetching personal information from chain when reset to null(like account_address_1). Now fixed.

@YoshihitoAso YoshihitoAso merged commit 8fbb9be into dev-25.3 Feb 13, 2025
@YoshihitoAso YoshihitoAso deleted the feature/#757 branch February 13, 2025 03:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Correctly redefine primary keys for some tables
2 participants