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-2034] Support version 2 changes #106

Merged
merged 10 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [8.2]
php: [8.3]

name: PHP ${{ matrix.php }}

Expand Down Expand Up @@ -66,7 +66,7 @@ jobs:

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

- name: Execute tests
run: |
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/security_checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: Dependencies Security Checker
on:
pull_request:
paths-ignore:
- '**.md'
- "**.md"
push:
paths-ignore:
- '**.md'
- "**.md"

jobs:
security-checker:
Expand All @@ -22,15 +22,15 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
php-version: 8.3
tools: composer:v2
coverage: none

- name: Checkout sensiolabs security-checker code
uses: actions/checkout@v4
with:
repository: 'sensiolabs/security-checker'
path: 'security-checker'
repository: "sensiolabs/security-checker"
path: "security-checker"

- name: Install dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}
],
"require": {
"php": "^8.2|^8.3",
"php": "^8.3",
"ext-bcmath": "*",
"ext-json": "*",
"ext-openssl": "*",
Expand Down
9 changes: 6 additions & 3 deletions src/Commands/BatchProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ protected function processBatch(BeamType $type): int

$params[$collectionId]['beamId'] = $claim->beam_id;

if (BeamType::TRANSFER_TOKEN == $type) {
if ($type == BeamType::TRANSFER_TOKEN) {
$params[$collectionId]['recipients'][] = [
'accountId' => $claim->wallet_public_key,
'params' => $this->substrate->getTransferParams([
Expand Down Expand Up @@ -186,13 +186,16 @@ protected function processBatch(BeamType $type): int
'initialSupply' => $this->tokenCreatedCache[$key] ? null : $claim->quantity,
'amount' => $this->tokenCreatedCache[$key] ? $claim->quantity : null,
'cap' => [
'type' => $claim->quantity == 1 || $claim->collection?->force_single_mint ? TokenMintCapType::SINGLE_MINT->name : TokenMintCapType::INFINITE->name,
'type' => $claim->quantity == 1 || $claim->collection?->force_collapsing_supply ? TokenMintCapType::COLLAPSING_SUPPLY->name : null,
'amount' => null,
],
'listingForbidden' => false,
'behaviour' => null,
'unitPrice' => config('enjin-platform-beam.unit_price'),
'attributes' => $claim->attributes ?: [],
'accountDepositCount' => 0,
'infusion' => 0,
'anyoneCanInfuse' => false,
]),
];

Expand All @@ -214,7 +217,7 @@ protected function processBatch(BeamType $type): int
continueOnFailure: true
));
} else {
$encodedData = $this->serialize->encode(isRunningLatest() ? $method . 'V1010' : $method, [
$encodedData = $this->serialize->encode($method, [
'collectionId' => $param['collectionId'],
'recipients' => $param['recipients'],
]);
Expand Down
4 changes: 2 additions & 2 deletions src/Rules/TokensDoNotExistInBeam.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ public static function prepareStatement(?Model $beam, ?string $collectionId = nu
(tokens.is_currency is false OR tokens.is_currency is NULL)
AND (
collections.max_token_supply = '1'
OR (collections.force_single_mint is true AND tokens.supply = '1')
OR (collections.force_collapsing_supply is true AND tokens.supply = '1')
OR (tokens.cap='" . TokenMintCapType::SUPPLY->name . "' AND tokens.cap_supply = '1')
OR (tokens.cap='" . TokenMintCapType::SINGLE_MINT->name . "' AND tokens.supply = '1')
OR (tokens.cap='" . TokenMintCapType::COLLAPSING_SUPPLY->name . "' AND tokens.cap_supply = '1')
)
")->when($beam, fn ($query) => $query->where('beam_claims.beam_id', $beam->id));
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/GraphQL/Mutations/UpdateBeamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ public function test_it_will_fail_existing_tokens(): void
'collection_id' => $this->collection->id,
'token_chain_id' => (string) fake()->unique()->numberBetween(2000),
'supply' => (string) $supply = 1,
'cap' => TokenMintCapType::SINGLE_MINT->name,
'cap_supply' => null,
'cap' => TokenMintCapType::COLLAPSING_SUPPLY->name,
'cap_supply' => 1,
'is_frozen' => false,
'unit_price' => (string) $unitPrice = fake()->numberBetween(1 / $supply * 10 ** 17),
'mint_deposit' => (string) ($unitPrice * $supply),
Expand Down
5 changes: 2 additions & 3 deletions tests/Feature/Traits/CreateCollectionData.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Enjin\Platform\Beam\Tests\Feature\Traits;

use Enjin\Platform\Enums\Substrate\TokenMintCapType;
use Enjin\Platform\Models\Collection;
use Enjin\Platform\Models\Token;
use Enjin\Platform\Models\TokenAccount;
Expand Down Expand Up @@ -48,7 +47,7 @@ public function prepareCollectionData(?string $publicKey = null): void
'owner_wallet_id' => $this->wallet->id,
'max_token_count' => fake()->numberBetween(1),
'max_token_supply' => (string) fake()->numberBetween(1),
'force_single_mint' => fake()->boolean(),
'force_collapsing_supply' => fake()->boolean(),
'is_frozen' => false,
'token_count' => '0',
'attribute_count' => '0',
Expand All @@ -60,7 +59,7 @@ public function prepareCollectionData(?string $publicKey = null): void
'collection_id' => $this->collection->id,
'token_chain_id' => (string) fake()->unique()->numberBetween(2000),
'supply' => (string) $supply = fake()->numberBetween(1),
'cap' => TokenMintCapType::INFINITE->name,
'cap' => null,
'cap_supply' => null,
'is_frozen' => false,
'unit_price' => (string) $unitPrice = fake()->numberBetween(1 / $supply * 10 ** 17),
Expand Down
24 changes: 14 additions & 10 deletions tests/Unit/EventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,30 @@ public function test_it_can_listens_to_events(): void
Event::fake();

$collectionCreated = CollectionDestroyedPolkadart::fromChain($this->mockPolkadartEvent('MultiTokens', 'CollectionDestroyed', [
'collection_id' => $this->collection->id,
'caller' => 'd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d',
'T::CollectionId' => $this->collection->collection_chain_id,
'T::AccountId' => 'd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d',
]));

event($event = new CollectionDestroyed($collectionCreated));
Event::assertListening(CollectionDestroyed::class, ExpireBeam::class);
resolve(ExpireBeam::class)->handle($event);

$collectionFrozen = CollectionFrozenPolkadart::fromChain($this->mockPolkadartEvent('MultiTokens', 'Frozen', [
'collection_id' => $this->collection->collection_chain_id,
'freeze_type' => 'Collection',
'FreezeOf<T>' => [
'collection_id' => $this->collection->collection_chain_id,
'freeze_type' => ['Collection' => []],
],
]));

event($event = new CollectionFrozen($collectionFrozen));
Event::assertListening(CollectionFrozen::class, PauseBeam::class);
resolve(PauseBeam::class)->handle($event);

$collectionThawed = CollectionThawedPolkadart::fromChain($this->mockPolkadartEvent('MultiTokens', 'Thawed', [
'collection_id' => $this->collection->collection_chain_id,
'freeze_type' => 'Collection',
'FreezeOf<T>' => [
'collection_id' => $this->collection->collection_chain_id,
'freeze_type' => ['Collection' => []],
],
]));

event($event = new CollectionThawed($collectionThawed));
Expand All @@ -82,15 +86,15 @@ public function test_it_can_listens_to_events(): void
resolve(UpdateClaimStatus::class)->handle($event);

$tokenDestroyed = TokenDestroyedPolkadart::fromChain($this->mockPolkadartEvent('MultiTokens', 'TokenDestroyed', [
'collection_id' => $this->collection->collection_chain_id,
'token_id' => $this->token->token_chain_id,
'caller' => $this->wallet->public_key,
'T::CollectionId' => $this->collection->collection_chain_id,
'T::TokenId' => $this->token->token_chain_id,
'T::AccountId' => $this->wallet->public_key,
]));

event($event = new TokenDestroyed($tokenDestroyed));
$this->collection->update([
'max_token_supply' => 100,
'force_single_mint' => false,
'force_collapsing_supply' => false,
]);
BeamClaim::where('beam_id', $this->beam->id)->first()->update([
'collection_id' => $this->collection->id,
Expand Down
Loading