diff --git a/src/Enums/DispatchCall.php b/src/Enums/DispatchCall.php index ad18566..d7dc9cf 100644 --- a/src/Enums/DispatchCall.php +++ b/src/Enums/DispatchCall.php @@ -8,7 +8,7 @@ enum DispatchCall: string { use EnumExtensions; - case MULTI_TOKENS = ''; + case MULTI_TOKENS = 'primary'; case FUEL_TANKS = 'fuel-tanks'; case MARKETPLACE = 'marketplace'; } diff --git a/src/Rules/ValidMutation.php b/src/Rules/ValidMutation.php index e75ae8d..473ca98 100644 --- a/src/Rules/ValidMutation.php +++ b/src/Rules/ValidMutation.php @@ -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), }; } diff --git a/src/Services/Processor/Substrate/Codec/Codec.php b/src/Services/Processor/Substrate/Codec/Codec.php index df2dafc..0c89af2 100644 --- a/src/Services/Processor/Substrate/Codec/Codec.php +++ b/src/Services/Processor/Substrate/Codec/Codec.php @@ -22,7 +22,7 @@ public function __construct() /** * Get the encoder. */ - public function encoder(): Encoder + public function encoder(): FuelTankEncoder { return $this->encoder; } @@ -30,7 +30,7 @@ public function encoder(): Encoder /** * Get the decoder. */ - public function decoder(): Decoder + public function decoder(): FuelTankDecoder { return $this->decoder; } diff --git a/testbench.yaml b/testbench.yaml index ac253df..e366c88 100644 --- a/testbench.yaml +++ b/testbench.yaml @@ -14,4 +14,5 @@ env: - DAEMON_ACCOUNT="0x68b427dda4f3894613e113b570d5878f3eee981196133e308c0a82584cf2e160" providers: + - Enjin\Platform\FuelTanks\FuelTanksServiceProvider - Enjin\Platform\CoreServiceProvider diff --git a/tests/Feature/GraphQL/Mutations/DispatchTest.php b/tests/Feature/GraphQL/Mutations/DispatchTest.php index 8224e53..745ba3d 100644 --- a/tests/Feature/GraphQL/Mutations/DispatchTest.php +++ b/tests/Feature/GraphQL/Mutations/DispatchTest.php @@ -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; @@ -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(); @@ -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, ]; } } diff --git a/tests/Feature/GraphQL/Resources/SetCollectionAttribute.graphql b/tests/Feature/GraphQL/Resources/SetCollectionAttribute.graphql new file mode 100644 index 0000000..8f79014 --- /dev/null +++ b/tests/Feature/GraphQL/Resources/SetCollectionAttribute.graphql @@ -0,0 +1,14 @@ +mutation SetCollectionAttribute( + $collectionId: BigInt! + $key: String! + $value: String! +) { + SetCollectionAttribute( + collectionId: $collectionId + key: $key + value: $value + ) { + id + encodedData + } +} diff --git a/tests/Unit/EncodingTest.php b/tests/Unit/EncodingTest.php index 4e411dc..41bb9bb 100644 --- a/tests/Unit/EncodingTest.php +++ b/tests/Unit/EncodingTest.php @@ -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, @@ -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, @@ -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' ));