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-2010] v2.0.0 API Updates #100

Closed
wants to merge 4 commits into from
Closed
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
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"scripts": {
"build-sr25519": "cd vendor/gmajor/sr25519-bindings/go && go build -buildmode=c-shared -o sr25519.so . && mv sr25519.so ../src/Crypto/sr25519.so",
"analyse": "vendor/bin/phpstan analyse",
"cache-clear": "@php ./vendor/bin/testbench cache:clear",
"fix": "vendor/bin/pint",
"test": "vendor/bin/phpunit",
"test-coverage": "vendor/bin/phpunit --coverage-html ../../temp/coverage",
Expand Down
7 changes: 5 additions & 2 deletions src/Commands/BatchProcess.php
Original file line number Diff line number Diff line change
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,
'amount' => null,
'type' => $claim->quantity == 1 || $claim->collection?->force_collapsing_supply ? TokenMintCapType::COLLAPSING_SUPPLY->name : null,
'amount' => $claim->collection?->force_collapsing_supply ? 1 : null,
],
'listingForbidden' => false,
'behaviour' => null,
'unitPrice' => config('enjin-platform-beam.unit_price'),
'attributes' => $claim->attributes ?: [],
'accountDepositCount' => 0,
'infusion' => 0,
'anyoneCanInfuse' => false,
]),
];

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.supply = '1')
)
")->when($beam, fn ($query) => $query->where('beam_claims.beam_id', $beam->id));
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/GraphQL/Mutations/UpdateBeamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ 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' => TokenMintCapType::COLLAPSING_SUPPLY->name,
'cap_supply' => null,
'is_frozen' => false,
'unit_price' => (string) $unitPrice = fake()->numberBetween(1 / $supply * 10 ** 17),
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
26 changes: 14 additions & 12 deletions tests/Unit/EventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,29 @@ 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',
$collectionId = $this->collection->collection_chain_id;

$collectionDestroyed = CollectionDestroyedPolkadart::fromChain($this->mockPolkadartEvent('MultiTokens', 'CollectionDestroyed', [
'T::CollectionId' => $collectionId,
'T::AccountId' => 'd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d',
]));

event($event = new CollectionDestroyed($collectionCreated));
event($event = new CollectionDestroyed($collectionDestroyed));
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' => $collectionId,
'FreezeOf<T>.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' => $collectionId,
'FreezeOf<T>.freeze_type' => 'Collection',
]));

event($event = new CollectionThawed($collectionThawed));
Expand All @@ -82,15 +84,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' => $collectionId,
'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