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

[PLA-2157] Fixes transfer validation rules #322

Merged
merged 19 commits into from
Jan 30, 2025
Merged
61 changes: 61 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Automatic Linter
on:
push:
paths-ignore:
- '**.md'

jobs:
lint:
runs-on: ubuntu-latest
permissions:
contents: write
services:
redis:
image: redis:7
ports:
- 6379:6379
options: --entrypoint redis-server
strategy:
fail-fast: true
matrix:
php: [8.3]

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
tools: composer:v2
coverage: none

- name: Install dependencies
run: |
composer install

- name: Run Rector
run: |
./vendor/bin/rector --dry-run

- name: Run Laravel Pint
run: |
./vendor/bin/pint --test

# - name: "Import GPG key"
# id: import-gpg
# uses: crazy-max/ghaction-import-gpg@v6
# with:
# gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
# passphrase: ${{ secrets.GPG_PASSPHRASE }}
# git_user_signingkey: true
# git_commit_gpgsign: true
#
# - name: Commit linted files
# uses: stefanzweifel/git-auto-commit-action@v5
# with:
# commit_message: "Automatic linter"
# commit_author: "${{ steps.import-gpg.outputs.name }} <${{ steps.import-gpg.outputs.email }}>"
# commit_user_name: ${{ steps.import-gpg.outputs.name }}
# commit_user_email: ${{ steps.import-gpg.outputs.email }}
2 changes: 1 addition & 1 deletion .github/workflows/pr_agent.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: PR Agent

on:
pull_request:
push:
issue_comment:

jobs:
Expand Down
10 changes: 4 additions & 6 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
name: Unit & Functional Tests

on:
pull_request:
paths-ignore:
- "**.md"
push:
paths-ignore:
- '**.md'
workflow_run:
workflows: [Automatic Linter]
types:
- completed

jobs:
test:
Expand Down
65 changes: 0 additions & 65 deletions .github/workflows/sast.yml

This file was deleted.

10 changes: 4 additions & 6 deletions .github/workflows/security_checker.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
name: Security Checker

on:
pull_request:
paths-ignore:
- '**.md'
push:
paths-ignore:
- '**.md'
workflow_run:
workflows: [Automatic Linter]
types:
- completed

jobs:
security-checker:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Enjin\Platform\Interfaces\PlatformBlockchainTransaction;
use Enjin\Platform\Interfaces\PlatformGraphQlMutation;
use Enjin\Platform\Models\Transaction;
use Enjin\Platform\Rules\IsCollectionOwner;
use Enjin\Platform\Rules\MaxBigInt;
use Enjin\Platform\Rules\MaxTokenBalance;
use Enjin\Platform\Rules\MinBigInt;
Expand Down Expand Up @@ -191,7 +190,7 @@ protected function rulesCommon(array $args): array
protected function rulesWithValidation(array $args): array
{
return [
'collectionId' => [new IsCollectionOwner()],
'collectionId' => ['exists:collections,collection_chain_id'],
...$this->getTokenFieldRulesExist('recipients.*.simpleParams', $args),
...$this->getTokenFieldRulesExist('recipients.*.operatorParams', $args),
'recipients.*.simpleParams.amount' => [new MinBigInt(1), new MaxBigInt(Hex::MAX_UINT128), new MaxTokenBalance()],
Expand All @@ -205,6 +204,7 @@ protected function rulesWithValidation(array $args): array
protected function rulesWithoutValidation(array $args): array
{
return [
'collectionId' => [new MinBigInt(2000), new MaxBigInt(Hex::MAX_UINT128)],
...$this->getTokenFieldRules('recipients.*.simpleParams', $args),
...$this->getTokenFieldRules('recipients.*.operatorParams', $args),
'recipients.*.simpleParams.amount' => [new MinBigInt(1), new MaxBigInt(Hex::MAX_UINT128)],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,10 @@ public static function getEncodableParams(...$params): array
*/
protected function rulesWithValidation(array $args): array
{
$removeTokenStorage = Arr::get($args, 'params.removeTokenStorage', false);
$min = $removeTokenStorage ? 0 : 1;
$min = Arr::get($args, 'params.removeTokenStorage', false) ? 0 : 1;

return [
'collectionId' => ['bail', $removeTokenStorage ? new IsCollectionOwner() : 'exists:collections,collection_chain_id'],
'collectionId' => [$removeTokenStorage ? new IsCollectionOwner() : 'exists:collections,collection_chain_id'],
'params.amount' => [new MinBigInt($min), new MaxTokenBalance()],
...$this->getTokenFieldRulesExist('params'),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Enjin\Platform\Interfaces\PlatformGraphQlMutation;
use Enjin\Platform\Models\Substrate\OperatorTransferParams;
use Enjin\Platform\Models\Transaction;
use Enjin\Platform\Rules\IsCollectionOwner;
use Enjin\Platform\Rules\MaxBigInt;
use Enjin\Platform\Rules\MaxTokenBalance;
use Enjin\Platform\Rules\MinBigInt;
Expand Down Expand Up @@ -154,8 +153,9 @@ protected function rulesCommon(array $args): array
*/
protected function rulesWithValidation(array $args): array
{
// TODO: We need to have a rule that checks if the signed has approval on the source collection / token and if enough approval balance
return [
'collectionId' => [new IsCollectionOwner()],
'collectionId' => ['exists:collections,collection_chain_id'],
'params.amount' => [new MinBigInt(0), new MaxBigInt(Hex::MAX_UINT128), new MaxTokenBalance()],
...$this->getTokenFieldRulesExist('params'),
];
Expand All @@ -167,6 +167,7 @@ protected function rulesWithValidation(array $args): array
protected function rulesWithoutValidation(array $args): array
{
return [
'collectionId' => [new MinBigInt(2000), new MaxBigInt(Hex::MAX_UINT128)],
'params.amount' => [new MinBigInt(0), new MaxBigInt(Hex::MAX_UINT128)],
...$this->getTokenFieldRules('params')];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Enjin\Platform\Interfaces\PlatformGraphQlMutation;
use Enjin\Platform\Models\Substrate\SimpleTransferParams;
use Enjin\Platform\Models\Transaction;
use Enjin\Platform\Rules\IsCollectionOwner;
use Enjin\Platform\Rules\MaxBigInt;
use Enjin\Platform\Rules\MaxTokenBalance;
use Enjin\Platform\Rules\MinBigInt;
Expand Down Expand Up @@ -153,7 +152,7 @@ protected function rulesCommon(array $args): array
protected function rulesWithValidation(array $args): array
{
return [
'collectionId' => [new IsCollectionOwner()],
'collectionId' => ['exists:collections,collection_chain_id'],
'params.amount' => [new MinBigInt(1), new MaxBigInt(Hex::MAX_UINT128), new MaxTokenBalance()],
...$this->getTokenFieldRulesExist('params'),
];
Expand All @@ -165,6 +164,7 @@ protected function rulesWithValidation(array $args): array
protected function rulesWithoutValidation(array $args): array
{
return [
'collectionId' => [new MinBigInt(2000), new MaxBigInt(Hex::MAX_UINT128)],
'params.amount' => [new MinBigInt(1), new MaxBigInt(Hex::MAX_UINT128)],
...$this->getTokenFieldRules('params'),
];
Expand Down