From 737bdabb0e69dd6f89284a9e7e681c27f72d7f19 Mon Sep 17 00:00:00 2001 From: Simon Evans Date: Wed, 13 Dec 2023 22:30:39 +0000 Subject: [PATCH] [PLA-1506] Validate beam code exists. (#60) --- src/GraphQL/Queries/GetPendingClaimsQuery.php | 2 +- tests/Feature/GraphQL/Queries/GetPendingClaimsTest.php | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/GraphQL/Queries/GetPendingClaimsQuery.php b/src/GraphQL/Queries/GetPendingClaimsQuery.php index f8fe6e3..8519722 100644 --- a/src/GraphQL/Queries/GetPendingClaimsQuery.php +++ b/src/GraphQL/Queries/GetPendingClaimsQuery.php @@ -73,7 +73,7 @@ public function resolve( protected function rules(array $args = []): array { return [ - 'code' => ['filled', 'max:1024'], + 'code' => ['filled', 'max:1024', 'exists:beams,code,deleted_at,NULL'], 'account' => ['filled', new ValidSubstrateAccount()], ]; } diff --git a/tests/Feature/GraphQL/Queries/GetPendingClaimsTest.php b/tests/Feature/GraphQL/Queries/GetPendingClaimsTest.php index 036d82e..d06877b 100644 --- a/tests/Feature/GraphQL/Queries/GetPendingClaimsTest.php +++ b/tests/Feature/GraphQL/Queries/GetPendingClaimsTest.php @@ -70,7 +70,16 @@ public function test_will_fail_with_invalid_parameters(): void 'account' => fake()->text(), ], true); $this->assertArraySubset([ + 'code' => ['The selected code is invalid.'], 'account' => ['The account is not a valid substrate account.'], ], $response['error']); + + $response = $this->graphql($this->method, [ + 'code' => fake()->realTextBetween(1025, 1032), + 'account' => $this->claims->first()->wallet_public_key, + ], true); + $this->assertArraySubset([ + 'code' => ['The code field must not be greater than 1024 characters.'], + ], $response['error']); } }