Skip to content

Commit 6013baa

Browse files
PR comments
1 parent ceaa3b3 commit 6013baa

File tree

4 files changed

+38
-22
lines changed

4 files changed

+38
-22
lines changed

daemon/algod/api/server/v2/handlers.go

+6
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,13 @@ func (v2 *Handlers) DeleteParticipationKeyByID(ctx echo.Context, participationID
143143
}
144144

145145
err = v2.Node.RemoveParticipationKey(decodedParticipationID)
146+
146147
if err != nil {
148+
149+
if errors.Is(err, account.ErrParticipationIDNotFound) {
150+
return ctx.JSON(http.StatusOK, generated.ErrorResponse{Message: "participation id not found"})
151+
}
152+
147153
return badRequest(ctx, err, err.Error(), v2.Log)
148154
}
149155

node/node.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ func (node *AlgorandFullNode) RemoveParticipationKey(partKey account.Participati
825825
partRecord := node.accountManager.Registry().Get(partKey)
826826

827827
if partRecord.IsZero() {
828-
return nil
828+
return account.ErrParticipationIDNotFound
829829
}
830830

831831
genID := node.GenesisID()

test/scripts/e2e_subs/rest-participation-key.sh

+25-11
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,39 @@ popd || exit
2323

2424
call_and_verify "Get List of Keys" "/v2/participation" 200 'Address'
2525

26+
# Find out how many keys there are installed so far
27+
NUM_IDS_1=$(echo "$RES" | python3 -c 'import json,sys;o=json.load(sys.stdin);print(len(o))')
28+
2629
call_post_and_verify "Install a basic participation key" "/v2/participation" 200 ${NAME_OF_TEMP_PARTKEY} 'partId'
2730

28-
call_and_verify "Get List of Keys" "/v2/participation" 200 'Address'
31+
# Get the returned participation id from the RESULT (aka $RES) variable
32+
INSTALLED_ID=$(echo "$RES" | python3 -c 'import json,sys;o=json.load(sys.stdin);print(o["partId"])')
33+
34+
# Should contain the installed id
35+
call_and_verify "Get List of Keys" "/v2/participation" 200 'Address' "${INSTALLED_ID}"
2936

30-
# Let's get a key from the previous response manually and request it specifically
31-
SAMPLE_ID=$(curl -q -s -H "Authorization: Bearer $ADMIN_TOKEN" "$NET/v2/participation" | python3 -c 'import json,sys;obj=json.load(sys.stdin);print(obj[0]["ID"])')
32-
NUMBER_OF_IDS=$(curl -q -s -H "Authorization: Bearer $ADMIN_TOKEN" "$NET/v2/participation" | python3 -c 'import json,sys;obj=json.load(sys.stdin);print(len(obj))')
37+
# Get list of keys
38+
NUM_IDS_2=$(echo "$RES" | python3 -c 'import json,sys;o=json.load(sys.stdin);print(len(o))')
39+
40+
if [[ $((NUM_IDS_1 + 1)) -ne $NUM_IDS_2 ]]; then
41+
printf "\n\nFailed test. New number of IDs (%s) is not one more than old ID count(%s)\n\n" "${NUM_IDS_2}" "${NUM_IDS_1}"
42+
exit 1
43+
fi
3344

34-
call_and_verify "Get a specific ID" "/v2/participation/${SAMPLE_ID}" 200 "${SAMPLE_ID}"
45+
call_and_verify "Get a specific ID" "/v2/participation/${INSTALLED_ID}" 200 "${INSTALLED_ID}"
3546

36-
call_delete_and_verify "Delete the specific ID" "/v2/participation/${SAMPLE_ID}" 200
47+
# Should return 200 but not return that error message
48+
call_delete_and_verify "Delete the specific ID" "/v2/participation/${INSTALLED_ID}" 200 false 'participation id not found'
3749

38-
# Verify that it got called previously and will NOT return an error now even though it isn't there
39-
call_delete_and_verify "Delete the specific ID" "/v2/participation/${SAMPLE_ID}" 200
50+
# Verify that it got called previously and will NOT return an error now even though it isn't there.
51+
# But it will contain a message saying that no key was found
52+
call_delete_and_verify "Delete the specific ID" "/v2/participation/${INSTALLED_ID}" 200 true 'participation id not found'
4053

41-
NEW_NUMBER_OF_IDS=$(curl -q -s -H "Authorization: Bearer $ADMIN_TOKEN" "$NET/v2/participation" | python3 -c 'import json,sys;obj=json.load(sys.stdin);print(len(obj))')
54+
# Get list of keys
55+
NUM_IDS_3=$(echo "$RES" | python3 -c 'import json,sys;o=json.load(sys.stdin);print(len(o))')
4256

43-
if [[ "$NEW_NUMBER_OF_IDS" -ge "$NUMBER_OF_IDS" ]]; then
44-
printf "\n\nFailed test. New number of IDs (%s) is greater than or equal to original IDs (%s)\n\n" "${NEW_NUMBER_OF_IDS}" "${NUMBER_OF_IDS}"
57+
if [[ "$NUM_IDS_3" -ne "$NUM_IDS_1" ]]; then
58+
printf "\n\nFailed test. New number of IDs (%s) is not equal to original ID count (%s)\n\n" "${NUM_IDS_3}" "${NUM_IDS_1}"
4559
exit 1
4660
fi
4761

test/scripts/e2e_subs/rest.sh

+6-10
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ function curl_post_test {
129129
# $1 - test description.
130130
# $2 - query
131131
# $3 - expected status code
132+
# $4 - match result
132133
function call_delete_and_verify {
133134
local DESCRIPTION="$1"
134135
shift
@@ -137,6 +138,9 @@ function call_delete_and_verify {
137138
local EXPECTED_CODE="$1"
138139
shift
139140

141+
local MATCH_RESULT="$1"
142+
shift
143+
140144
set +e
141145

142146
local CODE
@@ -146,7 +150,7 @@ function call_delete_and_verify {
146150
CODE=$(call_delete "$QUERY" "${TEMPDIR}/curl_out.txt" )
147151
fi
148152

149-
verify $? "$CODE" "$DESCRIPTION" "$QUERY" "$EXPECTED_CODE" "false"
153+
verify $? "$CODE" "$DESCRIPTION" "$QUERY" "$EXPECTED_CODE" "$MATCH_RESULT" "$@"
150154

151155
}
152156

@@ -265,12 +269,6 @@ function verify {
265269
fail_and_exit "$DESCRIPTION" "$QUERY" "unexpected HTTP status code expected $EXPECTED_CODE (actual $CODE): $RES"
266270
fi
267271

268-
#local ELAPSED=$(($SECONDS - $START))
269-
#if [[ $ELAPSED -gt $MAX_TIME ]]; then
270-
# fail_and_exit "$DESCRIPTION" "$QUERY" "query duration too long, $ELAPSED > $MAX_TIME"
271-
#fi
272-
273-
274272
local SUBSTRING
275273

276274
# Check result substrings
@@ -286,6 +284,4 @@ function verify {
286284
fi
287285
fi
288286
done
289-
290-
291-
}
287+
}

0 commit comments

Comments
 (0)