Skip to content

Commit

Permalink
Don't allow creating developer app with user wallet as address [C-4041 (
Browse files Browse the repository at this point in the history
#8165)

Co-authored-by: Nikki Kang <[email protected]>
  • Loading branch information
nicoback2 and nicoback authored Apr 19, 2024
1 parent 0777866 commit 40379a6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ def get_events_side_effect(_, tx_receipt: TxReceipt):
"users": [
{"user_id": user_id, "wallet": f"user{user_id}wallet"}
for user_id in range(1, 6)
],
# Private key: fcacb6c31a5b6bfd506a277ea34efcc44465476457385220fc252d7e58d6f2e7
]
+ [{"user_id": 99, "wallet": "0xE2975eF7594353238Cc68ECCf5d444c47BC17058"}],
"developer_apps": [
{
"user_id": 5,
Expand Down Expand Up @@ -376,6 +378,21 @@ def get_events_side_effect(_, tx_receipt: TxReceipt):
)
},
],
"CreateAppInvalidTx12": [
{
# Address is a user's wallet
"args": AttributeDict(
{
"_entityId": 0,
"_entityType": EntityType.DEVELOPER_APP,
"_userId": 2,
"_action": Action.CREATE,
"_metadata": '{"app_signature": {"signature": "20e5b1d95cc5d942571a097b5d7cb30cfcf355bbb5a51df498914dc42f4472d53c0d5ee9d2d89a00b56d19c912fade6760daa7f4c62437c5251776bd34cc4f3c1c", "message": "Creating Audius developer app at 1686252026"}, "name": "My app name"}',
"_signer": "user2wallet",
}
)
},
],
}

entity_manager_txs = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ def validate_developer_app_tx(params: ManageEntityParameters, metadata):
f"Programming error while indexing {params.action} Developer App Transaction, user wallet missing"
)
validate_signer(params)
# TODO (C-4041) - Make sure address is not already a user
if params.action == Action.DELETE:
if not address:
raise IndexingValidationError(
Expand Down Expand Up @@ -173,6 +172,10 @@ def validate_developer_app_tx(params: ManageEntityParameters, metadata):
raise IndexingValidationError(
f"Invalid Create Developer App Transaction, address {address} already exists"
)
if address in params.existing_records["UserWallet"]:
raise IndexingValidationError(
"Invalid Create Developer App Transaction, address cannot be a user's wallet"
)
if metadata["is_personal_access"] != None and not isinstance(
metadata["is_personal_access"], bool
):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,11 +520,16 @@ def collect_entities_to_fetch(update_task, entity_manager_txs):
entities_to_fetch[EntityType.DEVELOPER_APP].add(raw_address.lower())
else:
try:
address_from_signature = get_address_from_signature(
json_metadata.get("app_signature", {})
)
entities_to_fetch[EntityType.DEVELOPER_APP].add(
get_address_from_signature(
json_metadata.get("app_signature", {})
)
address_from_signature
)
if action == Action.CREATE:
entities_to_fetch[EntityType.USER_WALLET].add(
address_from_signature
)
except:
logger.error(
"tasks | entity_manager.py | Missing address or valid app signature in metadata required for add developer app tx"
Expand Down

0 comments on commit 40379a6

Please sign in to comment.