• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hicommonwealth / commonwealth / 16647103923

31 Jul 2025 10:57AM UTC coverage: 38.735% (-0.4%) from 39.148%
16647103923

push

github

web-flow
Skip the Token Allocation Lifecycle tests for now (#12705)

1861 of 5176 branches covered (35.95%)

Branch coverage included in aggregate %.

3290 of 8122 relevant lines covered (40.51%)

35.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/libs/model/src/aggregates/token-allocation/UpdateClaimAddress.command.ts
1
import { type Command, InvalidActor, InvalidState } from '@hicommonwealth/core';
2
import * as schemas from '@hicommonwealth/schemas';
3
import { QueryTypes } from 'sequelize';
4
import { models } from '../../database';
5

6
export function UpdateClaimAddress(): Command<
7
  typeof schemas.UpdateClaimAddress
8
> {
9
  return {
×
10
    ...schemas.UpdateClaimAddress,
11
    auth: [],
12
    secure: true,
13
    body: async ({ payload, actor }) => {
14
      const { address_id } = payload;
×
15

16
      const [address] = await models.sequelize.query<{
×
17
        user_id: number;
18
        address: `0x${string}`;
19
        community_id: number;
20
      }>(
21
        `
22
          SELECT A.user_id, A.address, C.id as community_id
23
          FROM "Addresses" A
24
                 LEFT JOIN "Communities" C ON C.id = A.community_id
25
          WHERE A.id = :address_id
26
            AND C.network = 'ethereum'
27
            AND C.base = 'ethereum'
28
            AND A.address LIKE '0x%'
29
            AND LENGTH(A.address) = 42;
30
        `,
31
        {
32
          type: QueryTypes.SELECT,
33
          replacements: {
34
            address_id,
35
          },
36
        },
37
      );
38

39
      if (address.user_id !== actor.user.id) {
×
40
        throw new InvalidActor(actor, 'Cannot update claim address');
×
41
      }
42

43
      if (!address) {
×
44
        throw new InvalidState('Address not found!');
×
45
      } else if (!address.community_id) {
×
46
        throw new InvalidState('Invalid EVM address!');
×
47
      }
48

49
      const result = await models.sequelize.query<{ address: string }>(
×
50
        `
51
          WITH magna_check AS (
52
            SELECT EXISTS (
53
              SELECT 1 FROM "HistoricalAllocations"
54
              WHERE user_id = :user_id 
55
              AND magna_synced_at IS NOT NULL
56
              FOR UPDATE
57
            ) as is_synced
58
          )
59
          INSERT INTO "ClaimAddresses" (user_id, address, created_at, updated_at)
60
          SELECT :user_id, :address, NOW(), NOW()
61
          WHERE NOT (SELECT is_synced FROM magna_check)
62
          ON CONFLICT (user_id) DO UPDATE SET address = EXCLUDED.address, updated_at = NOW()
63
          RETURNING address;
64
        `,
65
        {
66
          type: QueryTypes.SELECT,
67
          replacements: {
68
            user_id: address.user_id,
69
            address: address.address,
70
          },
71
        },
72
      );
73

74
      if (result.length === 0) {
×
75
        throw new InvalidState(
×
76
          'Cannot update claim address after user has been synchronized with magna',
77
        );
78
      }
79

80
      return {
×
81
        claim_address: address.address,
82
      };
83
    },
84
  };
85
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc