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-1691] Ensure schema is not empty for multi-tokens when using dispatch. #37

Merged
merged 2 commits into from
Mar 22, 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
2 changes: 1 addition & 1 deletion src/Enums/DispatchCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ enum DispatchCall: string
{
use EnumExtensions;

case MULTI_TOKENS = '';
case MULTI_TOKENS = 'primary';
case FUEL_TANKS = 'fuel-tanks';
case MARKETPLACE = 'marketplace';
}
1 change: 1 addition & 0 deletions src/Rules/ValidMutation.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
{
match (Arr::get($this->data, 'dispatch.call')) {
DispatchCall::FUEL_TANKS->name => $this->validateQuery('fuel-tanks', $value, $fail),
DispatchCall::MARKETPLACE->name => $this->validateQuery('marketplace', $value, $fail),
DispatchCall::MULTI_TOKENS->name => $this->validateQuery('primary', $value, $fail),
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/Services/Processor/Substrate/Codec/Codec.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ public function __construct()
/**
* Get the encoder.
*/
public function encoder(): Encoder
public function encoder(): FuelTankEncoder
{
return $this->encoder;
}

/**
* Get the decoder.
*/
public function decoder(): Decoder
public function decoder(): FuelTankDecoder
{
return $this->decoder;
}
Expand Down
1 change: 1 addition & 0 deletions testbench.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ env:
- DAEMON_ACCOUNT="0x68b427dda4f3894613e113b570d5878f3eee981196133e308c0a82584cf2e160"

providers:
- Enjin\Platform\FuelTanks\FuelTanksServiceProvider
- Enjin\Platform\CoreServiceProvider
44 changes: 38 additions & 6 deletions tests/Feature/GraphQL/Mutations/DispatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Enjin\Platform\FuelTanks\GraphQL\Mutations\DispatchMutation;
use Enjin\Platform\FuelTanks\Models\FuelTank;
use Enjin\Platform\FuelTanks\Tests\Feature\GraphQL\TestCaseGraphQL;
use Enjin\Platform\Models\Collection;
use Enjin\Platform\Models\Wallet;
use Enjin\Platform\Providers\Faker\SubstrateProvider;
use Enjin\Platform\Support\Hex;
Expand Down Expand Up @@ -49,6 +50,21 @@ public function test_it_can_dispatch(): void
);
}

public function test_it_can_dispatch_multi_token(): void
{
$response = $this->graphql(
$this->method,
$params = $this->generateParams(DispatchCall::MULTI_TOKENS)
);

$encodedCall = DispatchMutation::getEncodedCall($params);

$this->assertEquals(
$response['encodedData'],
TransactionSerializer::encode($this->method, DispatchMutation::getEncodableParams(...$params)) . $encodedCall . '00'
);
}

public function test_it_will_fail_with_invalid_parameter_tank_id(): void
{
$pubicKey = resolve(SubstrateProvider::class)->public_key();
Expand Down Expand Up @@ -218,16 +234,32 @@ public function test_it_will_fail_with_invalid_parameter_dispatch(): void
/**
* Generate parameters.
*/
protected function generateParams(): array
protected function generateParams(?DispatchCall $schema = null): array
{
return [
'tankId' => $this->tank->public_key,
'ruleSetId' => $this->tank->dispatchRules->first()->rule_set_id,
'dispatch' => [
$dispatch = match ($schema) {
DispatchCall::MULTI_TOKENS => [
'call' => DispatchCall::MULTI_TOKENS->name,
'query' => static::$queries['SetCollectionAttribute'],
'variables' => [
'collectionId' => Collection::factory()->create(['owner_wallet_id' => $this->wallet])->collection_chain_id,
'key' => 'key',
'value' => 'value',
],
],
default => [
'call' => DispatchCall::FUEL_TANKS->name,
'query' => static::$queries['AddAccount'],
'variables' => ['tankId' => $this->tank->public_key, 'userId' => resolve(SubstrateProvider::class)->public_key()],
'variables' => [
'tankId' => $this->tank->public_key,
'userId' => resolve(SubstrateProvider::class)->public_key(),
],
],
};

return [
'tankId' => $this->tank->public_key,
'ruleSetId' => $this->tank->dispatchRules->first()->rule_set_id,
'dispatch' => $dispatch,
];
}
}
14 changes: 14 additions & 0 deletions tests/Feature/GraphQL/Resources/SetCollectionAttribute.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
mutation SetCollectionAttribute(
$collectionId: BigInt!
$key: String!
$value: String!
) {
SetCollectionAttribute(
collectionId: $collectionId
key: $key
value: $value
) {
id
encodedData
}
}
6 changes: 3 additions & 3 deletions tests/Unit/EncodingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ public function test_it_can_encode_insert_or_update_rule_set()
),
);

$data = TransactionSerializer::encode('InsertRuleSet', InsertRulesetMutation::getEncodableParams(
$data = TransactionSerializer::encode('InsertRuleSet', InsertRuleSetMutation::getEncodableParams(
tankId: '0x18353dcf7a6eb053b6f0c01774d1f8cfe0c15963780f6935c49a9fd4f50b893c',
ruleSetId: '10',
dispatchRules: $dispatchRules,
Expand All @@ -421,7 +421,7 @@ public function test_it_can_encode_insert_or_update_rule_with_permitted_extrinsi
),
);

$data = TransactionSerializer::encode('InsertRuleSet', InsertRulesetMutation::getEncodableParams(
$data = TransactionSerializer::encode('InsertRuleSet', InsertRuleSetMutation::getEncodableParams(
tankId: '0x18353dcf7a6eb053b6f0c01774d1f8cfe0c15963780f6935c49a9fd4f50b893c',
ruleSetId: '10',
dispatchRules: $dispatchRules,
Expand All @@ -439,7 +439,7 @@ public function test_it_can_encode_insert_or_update_rule_with_permitted_extrinsi

public function test_it_can_encode_remove_rule_set()
{
$data = TransactionSerializer::encode('RemoveRuleSet', RemoveRulesetmutation::getEncodableParams(
$data = TransactionSerializer::encode('RemoveRuleSet', RemoveRuleSetMutation::getEncodableParams(
tankId: '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d',
ruleSetId: '10'
));
Expand Down
Loading