diff --git a/src/Abi.php b/src/Abi.php index 2a0ca89..e0a5387 100644 --- a/src/Abi.php +++ b/src/Abi.php @@ -19,18 +19,8 @@ /** * Provides message encoding and decoding according to the ABI specification */ -class Abi +class Abi extends AbstractModule { - private TonClient $tonClient; - - /** - * @param TonClient $tonClient - */ - public function __construct(TonClient $tonClient) - { - $this->tonClient = $tonClient; - } - /** * Encodes message body according to ABI function call * @@ -63,28 +53,22 @@ public function encodeMessageBody( } /** - * Attach signature to message body + * Decodes message body using provided body BOC and ABI * - * @param AbiParams $abi Contract ABI - * @param string $publicKey Public key. Must be encoded with hex - * @param string $message Unsigned message BOC. Must be encoded with base64 - * @param string $signature Signature. Must be encoded with hex - * @return ResultOfAttachSignatureToMessageBody + * @param AbiParams $abi Contract ABI used to decode + * @param string $body Message body BOC encoded in base64 + * @param bool $isInternal True if the body belongs to the internal message + * @return DecodedMessageBody */ - public function attachSignatureToMessageBody( - AbiParams $abi, - string $publicKey, - string $message, - string $signature - ): ResultOfAttachSignatureToMessageBody { - return new ResultOfAttachSignatureToMessageBody( + public function decodeMessageBody(AbiParams $abi, string $body, bool $isInternal = false): DecodedMessageBody + { + return new DecodedMessageBody( $this->tonClient->request( - 'abi.attach_signature_to_message_body', + 'abi.decode_message_body', [ - 'abi' => $abi, - 'public_key' => $publicKey, - 'message' => $message, - 'signature' => $signature, + 'abi' => $abi, + 'body' => $body, + 'is_internal' => $isInternal, ] )->wait() ); @@ -124,6 +108,26 @@ public function encodeMessage( ); } + /** + * Decodes message body using provided message BOC and ABI + * + * @param AbiParams $abi Contract ABI used to decode + * @param string $message Boc message + * @return DecodedMessageBody + */ + public function decodeMessage(AbiParams $abi, string $message): DecodedMessageBody + { + return new DecodedMessageBody( + $this->tonClient->request( + 'abi.decode_message', + [ + 'abi' => $abi, + 'message' => $message, + ] + )->wait() + ); + } + /** * Combines hex-encoded signature with base64-encoded unsigned_message. Returns signed message encoded in base64 * @@ -153,42 +157,28 @@ public function attachSignature( } /** - * Decodes message body using provided message BOC and ABI - * - * @param AbiParams $abi Contract ABI used to decode - * @param string $message Boc message - * @return DecodedMessageBody - */ - public function decodeMessage(AbiParams $abi, string $message): DecodedMessageBody - { - return new DecodedMessageBody( - $this->tonClient->request( - 'abi.decode_message', - [ - 'abi' => $abi, - 'message' => $message, - ] - )->wait() - ); - } - - /** - * Decodes message body using provided body BOC and ABI + * Attach signature to message body * - * @param AbiParams $abi Contract ABI used to decode - * @param string $body Message body BOC encoded in base64 - * @param bool $isInternal True if the body belongs to the internal message - * @return DecodedMessageBody + * @param AbiParams $abi Contract ABI + * @param string $publicKey Public key. Must be encoded with hex + * @param string $message Unsigned message BOC. Must be encoded with base64 + * @param string $signature Signature. Must be encoded with hex + * @return ResultOfAttachSignatureToMessageBody */ - public function decodeMessageBody(AbiParams $abi, string $body, bool $isInternal = false): DecodedMessageBody - { - return new DecodedMessageBody( + public function attachSignatureToMessageBody( + AbiParams $abi, + string $publicKey, + string $message, + string $signature + ): ResultOfAttachSignatureToMessageBody { + return new ResultOfAttachSignatureToMessageBody( $this->tonClient->request( - 'abi.decode_message_body', + 'abi.attach_signature_to_message_body', [ - 'abi' => $abi, - 'body' => $body, - 'is_internal' => $isInternal, + 'abi' => $abi, + 'public_key' => $publicKey, + 'message' => $message, + 'signature' => $signature, ] )->wait() ); diff --git a/src/AbstractModule.php b/src/AbstractModule.php new file mode 100644 index 0000000..7748e0e --- /dev/null +++ b/src/AbstractModule.php @@ -0,0 +1,26 @@ +tonClient = $tonClient; + } + + /** + * @return TonClient + */ + public function getTonClient(): TonClient + { + return $this->tonClient; + } +} diff --git a/src/Boc.php b/src/Boc.php index 37fe65f..ead50fc 100644 --- a/src/Boc.php +++ b/src/Boc.php @@ -10,18 +10,8 @@ /** * Boc module */ -class Boc +class Boc extends AbstractModule { - private TonClient $tonClient; - - /** - * @param TonClient $tonClient - */ - public function __construct(TonClient $tonClient) - { - $this->tonClient = $tonClient; - } - /** * Parses message boc * diff --git a/src/Crypto.php b/src/Crypto.php index e39d99f..1b90a25 100644 --- a/src/Crypto.php +++ b/src/Crypto.php @@ -30,18 +30,8 @@ /** * Crypto module */ -class Crypto +class Crypto extends AbstractModule { - private TonClient $tonClient; - - /** - * @param TonClient $tonClient - */ - public function __construct(TonClient $tonClient) - { - $this->tonClient = $tonClient; - } - /** * Performs prime factorization * @@ -80,9 +70,9 @@ public function modularPower(string $base, string $exponent, string $modulus): R $this->tonClient->request( 'crypto.modular_power', [ - 'base' => $base, + 'base' => $base, 'exponent' => $exponent, - 'modulus' => $modulus, + 'modulus' => $modulus, ] )->wait() ); @@ -168,7 +158,7 @@ public function sign(string $unsigned, KeyPair $keyPair): ResultOfSign 'crypto.sign', [ 'unsigned' => $unsigned, - 'keys' => $keyPair, + 'keys' => $keyPair, ] )->wait() ); @@ -253,11 +243,11 @@ public function scrypt(string $password, string $salt, int $logN, int $r, int $p 'crypto.scrypt', [ 'password' => $password, - 'salt' => $salt, - 'log_n' => $logN, - 'r' => $r, - 'p' => $p, - 'dk_len' => $dkLen, + 'salt' => $salt, + 'log_n' => $logN, + 'r' => $r, + 'p' => $p, + 'dk_len' => $dkLen, ] )->wait() ); @@ -295,7 +285,7 @@ public function naclSign(string $unsigned, string $secret): ResultOfNaclSign 'crypto.nacl_sign', [ 'unsigned' => $unsigned, - 'secret' => $secret, + 'secret' => $secret, ] )->wait() ); @@ -335,7 +325,7 @@ public function naclSignDetached(string $unsigned, string $secret): ResultOfNacl 'crypto.nacl_sign_detached', [ 'unsigned' => $unsigned, - 'secret' => $secret, + 'secret' => $secret, ] )->wait() ); @@ -388,10 +378,10 @@ public function naclBox(string $decrypted, string $nonce, string $theirPublic, s $this->tonClient->request( 'crypto.nacl_box', [ - 'decrypted' => $decrypted, - 'nonce' => $nonce, + 'decrypted' => $decrypted, + 'nonce' => $nonce, 'their_public' => $theirPublic, - 'secret' => $secret, + 'secret' => $secret, ], )->wait() ); @@ -406,16 +396,20 @@ public function naclBox(string $decrypted, string $nonce, string $theirPublic, s * @param string $secret Sender's private key - unprefixed 0-padded to 64 symbols hex string * @return ResultOfNaclBoxOpen */ - public function naclBoxOpen(string $encrypted, string $nonce, string $theirPublic, string $secret): ResultOfNaclBoxOpen - { + public function naclBoxOpen( + string $encrypted, + string $nonce, + string $theirPublic, + string $secret + ): ResultOfNaclBoxOpen { return new ResultOfNaclBoxOpen( $this->tonClient->request( 'crypto.nacl_box_open', [ - 'encrypted' => $encrypted, - 'nonce' => $nonce, + 'encrypted' => $encrypted, + 'nonce' => $nonce, 'their_public' => $theirPublic, - 'secret' => $secret, + 'secret' => $secret, ], )->wait() ); @@ -436,8 +430,8 @@ public function naclSecretBox(string $decrypted, string $nonce, string $key): Re 'crypto.nacl_secret_box', [ 'decrypted' => $decrypted, - 'nonce' => $nonce, - 'key' => $key, + 'nonce' => $nonce, + 'key' => $key, ], )->wait() ); @@ -458,8 +452,8 @@ public function naclSecretBoxOpen(string $encrypted, string $nonce, string $key) 'crypto.nacl_secret_box_open', [ 'encrypted' => $encrypted, - 'nonce' => $nonce, - 'key' => $key, + 'nonce' => $nonce, + 'key' => $key, ], )->wait() ); @@ -515,13 +509,12 @@ public function mnemonicFromEntropy( string $entropy, int $dictionary = null, int $wordCount = null - ): ResultOfGenerateMnemonic - { + ): ResultOfGenerateMnemonic { return new ResultOfGenerateMnemonic( $this->tonClient->request( 'crypto.mnemonic_from_entropy', [ - 'entropy' => $entropy, + 'entropy' => $entropy, 'dictionary' => $dictionary, 'word_count' => $wordCount, ], @@ -541,13 +534,12 @@ public function mnemonicVerify( string $phrase, int $dictionary = null, int $wordCount = null - ): ResultOfMnemonicVerify - { + ): ResultOfMnemonicVerify { return new ResultOfMnemonicVerify( $this->tonClient->request( 'crypto.mnemonic_verify', [ - 'phrase' => $phrase, + 'phrase' => $phrase, 'dictionary' => $dictionary, 'word_count' => $wordCount, ], @@ -569,14 +561,13 @@ public function mnemonicDeriveSignKeys( string $path = null, int $dictionary = null, int $wordCount = null - ): ResultOfGenerateSignKeys - { + ): ResultOfGenerateSignKeys { return new ResultOfGenerateSignKeys( $this->tonClient->request( 'crypto.mnemonic_derive_sign_keys', [ - 'phrase' => $phrase, - 'path' => $path, + 'phrase' => $phrase, + 'path' => $path, 'dictionary' => $dictionary, 'word_count' => $wordCount, ], @@ -596,13 +587,12 @@ public function hdkeyXprvFromMnemonic( string $phrase, int $dictionary = null, int $wordCount = null - ): ResultOfHDKeyXPrv - { + ): ResultOfHDKeyXPrv { return new ResultOfHDKeyXPrv( $this->tonClient->request( 'crypto.hdkey_xprv_from_mnemonic', [ - 'phrase' => $phrase, + 'phrase' => $phrase, 'dictionary' => $dictionary, 'word_count' => $wordCount, ], @@ -624,9 +614,9 @@ public function hdkeyDeriveFromXprv(string $xprv, int $childIndex, bool $hardene $this->tonClient->request( 'crypto.hdkey_derive_from_xprv', [ - 'xprv' => $xprv, + 'xprv' => $xprv, 'child_index' => $childIndex, - 'hardened' => $hardened, + 'hardened' => $hardened, ], )->wait() ); diff --git a/src/Entity/Abi/AbiParams.php b/src/Entity/Abi/AbiParams.php index 36efb01..6da87ab 100644 --- a/src/Entity/Abi/AbiParams.php +++ b/src/Entity/Abi/AbiParams.php @@ -4,14 +4,14 @@ namespace Extraton\TonClient\Entity\Abi; -use Extraton\TonClient\Entity\ParamsInterface; +use Extraton\TonClient\Entity\Params; use JsonException; use function json_decode; use const JSON_THROW_ON_ERROR; -class AbiParams implements ParamsInterface +class AbiParams implements Params { public const TYPE_SERIALIZED = 'Serialized'; diff --git a/src/Entity/Abi/CallSetParams.php b/src/Entity/Abi/CallSetParams.php index 5b080e2..6e8a1b7 100644 --- a/src/Entity/Abi/CallSetParams.php +++ b/src/Entity/Abi/CallSetParams.php @@ -4,9 +4,9 @@ namespace Extraton\TonClient\Entity\Abi; -use Extraton\TonClient\Entity\ParamsInterface; +use Extraton\TonClient\Entity\Params; -class CallSetParams implements ParamsInterface +class CallSetParams implements Params { private string $functionName; diff --git a/src/Entity/Abi/DeploySetParams.php b/src/Entity/Abi/DeploySetParams.php index 3cc8b81..e31b6b2 100644 --- a/src/Entity/Abi/DeploySetParams.php +++ b/src/Entity/Abi/DeploySetParams.php @@ -4,9 +4,9 @@ namespace Extraton\TonClient\Entity\Abi; -use Extraton\TonClient\Entity\ParamsInterface; +use Extraton\TonClient\Entity\Params; -class DeploySetParams implements ParamsInterface +class DeploySetParams implements Params { private string $tvc; diff --git a/src/Entity/Abi/FunctionHeaderParams.php b/src/Entity/Abi/FunctionHeaderParams.php index b0829dd..594765e 100644 --- a/src/Entity/Abi/FunctionHeaderParams.php +++ b/src/Entity/Abi/FunctionHeaderParams.php @@ -4,9 +4,9 @@ namespace Extraton\TonClient\Entity\Abi; -use Extraton\TonClient\Entity\ParamsInterface; +use Extraton\TonClient\Entity\Params; -class FunctionHeaderParams implements ParamsInterface +class FunctionHeaderParams implements Params { private ?int $expire; diff --git a/src/Entity/Abi/MessageSource.php b/src/Entity/Abi/MessageSource.php index a6ca09d..8000a57 100644 --- a/src/Entity/Abi/MessageSource.php +++ b/src/Entity/Abi/MessageSource.php @@ -4,10 +4,10 @@ namespace Extraton\TonClient\Entity\Abi; -use Extraton\TonClient\Entity\ParamsInterface; +use Extraton\TonClient\Entity\Params; use RuntimeException; -class MessageSource implements ParamsInterface +class MessageSource implements Params { public const TYPE_ENCODED = 'Encoded'; diff --git a/src/Entity/Abi/SignerParams.php b/src/Entity/Abi/SignerParams.php index 66dcea3..8cbb0c3 100644 --- a/src/Entity/Abi/SignerParams.php +++ b/src/Entity/Abi/SignerParams.php @@ -5,10 +5,10 @@ namespace Extraton\TonClient\Entity\Abi; use Extraton\TonClient\Entity\Crypto\KeyPair; -use Extraton\TonClient\Entity\ParamsInterface; +use Extraton\TonClient\Entity\Params; use LogicException; -class SignerParams implements ParamsInterface +class SignerParams implements Params { public const TYPE_NONE = 'None'; diff --git a/src/Entity/Abi/StateInitSource.php b/src/Entity/Abi/StateInitSource.php index dff16a5..52ddda1 100644 --- a/src/Entity/Abi/StateInitSource.php +++ b/src/Entity/Abi/StateInitSource.php @@ -4,10 +4,10 @@ namespace Extraton\TonClient\Entity\Abi; -use Extraton\TonClient\Entity\ParamsInterface; +use Extraton\TonClient\Entity\Params; use RuntimeException; -class StateInitSource implements ParamsInterface +class StateInitSource implements Params { public const TYPE_MESSAGE = 'Message'; diff --git a/src/Entity/AbstractResult.php b/src/Entity/AbstractResult.php index 7fc4350..0e98165 100644 --- a/src/Entity/AbstractResult.php +++ b/src/Entity/AbstractResult.php @@ -14,6 +14,9 @@ use function is_int; use function is_string; +/** + * Abstract result + */ abstract class AbstractResult implements IteratorAggregate { private Response $response; @@ -156,7 +159,7 @@ protected function requireInt(string ...$keys): int /** * @param string ...$keys - * @return int + * @return bool */ protected function requireBool(string ...$keys): bool { diff --git a/src/Entity/Crypto/KeyPair.php b/src/Entity/Crypto/KeyPair.php index 38543d5..872469e 100644 --- a/src/Entity/Crypto/KeyPair.php +++ b/src/Entity/Crypto/KeyPair.php @@ -4,12 +4,12 @@ namespace Extraton\TonClient\Entity\Crypto; -use Extraton\TonClient\Entity\ParamsInterface; +use Extraton\TonClient\Entity\Params; /** * Key pair */ -class KeyPair implements ParamsInterface +class KeyPair implements Params { private string $public; diff --git a/src/Entity/Net/AbstractQuery.php b/src/Entity/Net/AbstractQuery.php index 3b2c048..7cf81f5 100644 --- a/src/Entity/Net/AbstractQuery.php +++ b/src/Entity/Net/AbstractQuery.php @@ -4,7 +4,7 @@ namespace Extraton\TonClient\Entity\Net; -use Extraton\TonClient\Entity\ParamsInterface; +use Extraton\TonClient\Entity\Params; use RuntimeException; use function array_filter; @@ -96,7 +96,7 @@ public function getResult(): string return implode(' ', $fields); } - public function getFilters(): ?ParamsInterface + public function getFilters(): ?Params { return $this->filters; } @@ -108,7 +108,7 @@ public function setFilters(?Filters $filters): self return $this; } - public function getOrderBy(): ?ParamsInterface + public function getOrderBy(): ?Params { return $this->orderBy; } diff --git a/src/Entity/Net/Filters.php b/src/Entity/Net/Filters.php index 5e0bbeb..6919820 100644 --- a/src/Entity/Net/Filters.php +++ b/src/Entity/Net/Filters.php @@ -4,7 +4,7 @@ namespace Extraton\TonClient\Entity\Net; -use Extraton\TonClient\Entity\ParamsInterface; +use Extraton\TonClient\Entity\Params; use LogicException; use RuntimeException; @@ -13,7 +13,7 @@ /** * Filter collection */ -class Filters implements ParamsInterface +class Filters implements Params { public const EQ = 'eq'; diff --git a/src/Entity/Net/OrderBy.php b/src/Entity/Net/OrderBy.php index 4868113..42b2af0 100644 --- a/src/Entity/Net/OrderBy.php +++ b/src/Entity/Net/OrderBy.php @@ -4,12 +4,12 @@ namespace Extraton\TonClient\Entity\Net; -use Extraton\TonClient\Entity\ParamsInterface; +use Extraton\TonClient\Entity\Params; use LogicException; use function in_array; -class OrderBy implements ParamsInterface +class OrderBy implements Params { public const ASC = 'ASC'; diff --git a/src/Entity/Net/ParamsOfSubscribeCollection.php b/src/Entity/Net/ParamsOfSubscribeCollection.php index 00c0d5c..a7a8a93 100644 --- a/src/Entity/Net/ParamsOfSubscribeCollection.php +++ b/src/Entity/Net/ParamsOfSubscribeCollection.php @@ -4,7 +4,7 @@ namespace Extraton\TonClient\Entity\Net; -use Extraton\TonClient\Entity\ParamsInterface; +use Extraton\TonClient\Entity\Params; use RuntimeException; class ParamsOfSubscribeCollection extends AbstractQuery @@ -18,7 +18,7 @@ public function __construct( $this->setFilters($filters); } - public function getOrderBy(): ?ParamsInterface + public function getOrderBy(): ?Params { throw new RuntimeException('Method ParamsOfSubscribeCollection::getOrderBy is not implemented.'); } diff --git a/src/Entity/Net/ParamsOfWaitForCollection.php b/src/Entity/Net/ParamsOfWaitForCollection.php index 759e1b0..124bdac 100644 --- a/src/Entity/Net/ParamsOfWaitForCollection.php +++ b/src/Entity/Net/ParamsOfWaitForCollection.php @@ -4,7 +4,7 @@ namespace Extraton\TonClient\Entity\Net; -use Extraton\TonClient\Entity\ParamsInterface; +use Extraton\TonClient\Entity\Params; use RuntimeException; class ParamsOfWaitForCollection extends AbstractQuery @@ -20,7 +20,7 @@ public function __construct( $this->setTimeout($timeout); } - public function getOrderBy(): ?ParamsInterface + public function getOrderBy(): ?Params { throw new RuntimeException('Method ParamsOfWaitForCollection::getOrderBy is not implemented.'); } diff --git a/src/Entity/Net/QueryInterface.php b/src/Entity/Net/QueryInterface.php index d5c1418..01e29ba 100644 --- a/src/Entity/Net/QueryInterface.php +++ b/src/Entity/Net/QueryInterface.php @@ -4,7 +4,7 @@ namespace Extraton\TonClient\Entity\Net; -use Extraton\TonClient\Entity\ParamsInterface; +use Extraton\TonClient\Entity\Params; interface QueryInterface { @@ -12,9 +12,9 @@ public function getCollection(): string; public function getResult(): string; - public function getFilters(): ?ParamsInterface; + public function getFilters(): ?Params; - public function getOrderBy(): ?ParamsInterface; + public function getOrderBy(): ?Params; public function getLimit(): ?int; diff --git a/src/Entity/ParamsInterface.php b/src/Entity/Params.php similarity index 54% rename from src/Entity/ParamsInterface.php rename to src/Entity/Params.php index 4cbfa9e..0858364 100644 --- a/src/Entity/ParamsInterface.php +++ b/src/Entity/Params.php @@ -6,7 +6,13 @@ use JsonSerializable; -interface ParamsInterface extends JsonSerializable +/** + * Parameters interface + */ +interface Params extends JsonSerializable { + /** + * @return array + */ public function jsonSerialize(): array; } diff --git a/src/Entity/Tvm/AccountForExecutor.php b/src/Entity/Tvm/AccountForExecutor.php index 5ea7939..b14ca08 100644 --- a/src/Entity/Tvm/AccountForExecutor.php +++ b/src/Entity/Tvm/AccountForExecutor.php @@ -4,12 +4,12 @@ namespace Extraton\TonClient\Entity\Tvm; -use Extraton\TonClient\Entity\ParamsInterface; +use Extraton\TonClient\Entity\Params; use RuntimeException; use function in_array; -class AccountForExecutor implements ParamsInterface +class AccountForExecutor implements Params { public const TYPE_NONE = 'None'; diff --git a/src/Entity/Tvm/ExecutionOptions.php b/src/Entity/Tvm/ExecutionOptions.php index 987ba42..766babf 100644 --- a/src/Entity/Tvm/ExecutionOptions.php +++ b/src/Entity/Tvm/ExecutionOptions.php @@ -4,12 +4,12 @@ namespace Extraton\TonClient\Entity\Tvm; -use Extraton\TonClient\Entity\ParamsInterface; +use Extraton\TonClient\Entity\Params; /** * Execution options */ -class ExecutionOptions implements ParamsInterface +class ExecutionOptions implements Params { private ?string $blockchainConfig; diff --git a/src/Entity/Utils/AddressStringFormat.php b/src/Entity/Utils/AddressStringFormat.php index e5cc058..3c92381 100644 --- a/src/Entity/Utils/AddressStringFormat.php +++ b/src/Entity/Utils/AddressStringFormat.php @@ -4,12 +4,12 @@ namespace Extraton\TonClient\Entity\Utils; -use Extraton\TonClient\Entity\ParamsInterface; +use Extraton\TonClient\Entity\Params; use RuntimeException; use function in_array; -class AddressStringFormat implements ParamsInterface +class AddressStringFormat implements Params { public const TYPE_ACCOUNT_ID = 'AccountId'; diff --git a/src/Module.php b/src/Module.php new file mode 100644 index 0000000..9e34a54 --- /dev/null +++ b/src/Module.php @@ -0,0 +1,13 @@ +tonClient = $tonClient; - } - /** * Queries collection data * diff --git a/src/Processing.php b/src/Processing.php index fd49428..58588aa 100644 --- a/src/Processing.php +++ b/src/Processing.php @@ -15,18 +15,8 @@ /** * Message processing module */ -class Processing +class Processing extends AbstractModule { - private TonClient $tonClient; - - /** - * @param TonClient $tonClient - */ - public function __construct(TonClient $tonClient) - { - $this->tonClient = $tonClient; - } - /** * Sends message to the network * diff --git a/src/Tvm.php b/src/Tvm.php index 318fb91..f50ffb2 100644 --- a/src/Tvm.php +++ b/src/Tvm.php @@ -15,18 +15,8 @@ /** * Tvm module */ -class Tvm +class Tvm extends AbstractModule { - private TonClient $tonClient; - - /** - * @param TonClient $tonClient - */ - public function __construct(TonClient $tonClient) - { - $this->tonClient = $tonClient; - } - /** * Run executor * diff --git a/src/Utils.php b/src/Utils.php index 6dde340..82ab1d0 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -10,18 +10,8 @@ /** * Utils module */ -class Utils +class Utils extends AbstractModule { - private TonClient $tonClient; - - /** - * @param TonClient $tonClient - */ - public function __construct(TonClient $tonClient) - { - $this->tonClient = $tonClient; - } - /** * Convert Ton address * diff --git a/tests/Integration/AbiTest.php b/tests/Integration/AbiTest.php index ddc0f9f..bdb5ee1 100644 --- a/tests/Integration/AbiTest.php +++ b/tests/Integration/AbiTest.php @@ -10,19 +10,18 @@ use Extraton\TonClient\Entity\Abi\DecodedMessageBody; use Extraton\TonClient\Entity\Abi\DeploySetParams; use Extraton\TonClient\Entity\Abi\FunctionHeaderParams; +use Extraton\TonClient\Entity\Abi\MessageSource; use Extraton\TonClient\Entity\Abi\ResultOfAttachSignature; +use Extraton\TonClient\Entity\Abi\ResultOfEncodeAccount; use Extraton\TonClient\Entity\Abi\ResultOfEncodeMessage; use Extraton\TonClient\Entity\Abi\SignerParams; +use Extraton\TonClient\Entity\Abi\StateInitSource; use Extraton\TonClient\Entity\Crypto\KeyPair; use Extraton\TonClient\Entity\Crypto\ResultOfSign; +use Extraton\TonClient\Exception\RequestException; use Extraton\TonClient\Handler\Response; use JsonException; -use function file_get_contents; -use function json_decode; - -use const JSON_THROW_ON_ERROR; - /** * Integration tests for Abi module * @@ -31,17 +30,39 @@ class AbiTest extends AbstractModuleTest { /** - * @covers ::decodeMessage + * @covers ::encodeMessageBody + * @covers ::decodeMessageBody */ - public function testDecodeMessageWithSuccessResult(): void + public function testEncodeMessageBody(): void { - $abiJson = file_get_contents(__DIR__ . '/Data/Events.abi.json'); - $abiArray = json_decode($abiJson, true, 32, JSON_THROW_ON_ERROR); + $abi = AbiParams::fromArray($this->dataProvider->getEventsAbiArray()); - $abiFromJson = AbiParams::fromJson($abiJson); - $abiFromArray = AbiParams::fromArray($abiArray); + $keyPair = new KeyPair( + $this->dataProvider->getPublicKey(), + $this->dataProvider->getPrivateKey() + ); + $signer = SignerParams::fromKeys($keyPair); - $message = 'te6ccgEBAwEAvAABRYgAC31qq9KF9Oifst6LU9U6FQSQQRlCSEMo+A3LN5MvphIMAQHhrd/b+MJ5Za+AygBc5qS/dVIPnqxCsM9PvqfVxutK+lnQEKzQoRTLYO6+jfM8TF4841bdNjLQwIDWL4UVFdxIhdMfECP8d3ruNZAXul5xxahT91swIEkEHph08JVlwmUmQAAAXRnJcuDX1XMZBW+LBKACAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=='; + $functionHeaderParams = new FunctionHeaderParams( + $this->dataProvider->getPublicKey(), + $this->dataProvider->getEventsTime(), + $this->dataProvider->getEventsExpire() + ); + + $callSet = new CallSetParams( + 'returnValue', + $functionHeaderParams, + [ + 'id' => $id = '0x1', + ] + ); + + $resultOfEncodeMessageBody = $this->abi->encodeMessageBody( + $abi, + $signer, + $callSet, + false + ); $expected = new DecodedMessageBody( new Response( @@ -50,36 +71,39 @@ public function testDecodeMessageWithSuccessResult(): void 'name' => 'returnValue', 'value' => [ - 'id' => '0x0', + 'id' => $id, ], 'header' => [ - 'expire' => 1599458404, - 'time' => 1599458364291, + 'expire' => $this->dataProvider->getEventsExpire(), + 'time' => $this->dataProvider->getEventsTime(), 'pubkey' => '4c7c408ff1ddebb8d6405ee979c716a14fdd6cc08124107a61d3c25597099499', ], ] ) ); - self::assertEquals($expected, $this->abi->decodeMessage($abiFromJson, $message)); - self::assertEquals($expected, $this->abi->decodeMessage($abiFromArray, $message)); + self::assertEquals( + $expected, + $this->abi->decodeMessageBody( + $abi, + $resultOfEncodeMessageBody->getBody(), + false + ) + ); } /** * @covers ::decodeMessageBody + * @covers \Extraton\TonClient\Boc::parseMessage */ - public function testDecodeMessageBodyWithSuccessResult(): void + public function testDecodeMessageBody(): void { - $abiJson = file_get_contents(__DIR__ . '/Data/Events.abi.json'); - $abiArray = json_decode($abiJson, true, 32, JSON_THROW_ON_ERROR); - - $abiFromJson = AbiParams::fromJson($abiJson); - $abiFromArray = AbiParams::fromArray($abiArray); + $abi = AbiParams::fromArray($this->dataProvider->getEventsAbiArray()); $message = 'te6ccgEBAwEAvAABRYgAC31qq9KF9Oifst6LU9U6FQSQQRlCSEMo+A3LN5MvphIMAQHhrd/b+MJ5Za+AygBc5qS/dVIPnqxCsM9PvqfVxutK+lnQEKzQoRTLYO6+jfM8TF4841bdNjLQwIDWL4UVFdxIhdMfECP8d3ruNZAXul5xxahT91swIEkEHph08JVlwmUmQAAAXRnJcuDX1XMZBW+LBKACAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=='; - $parsed = $this->boc->parseMessage($message)->getParsed(); - $body = $parsed['body'] ?? ''; + $resultOfParse = $this->boc->parseMessage($message); + $body = $resultOfParse->getParsed()['body'] ?? ''; $expected = new DecodedMessageBody( new Response( @@ -100,13 +124,14 @@ public function testDecodeMessageBodyWithSuccessResult(): void ) ); - self::assertEquals($expected, $this->abi->decodeMessageBody($abiFromJson, $body)); - self::assertEquals($expected, $this->abi->decodeMessageBody($abiFromArray, $body)); + self::assertEquals($expected, $this->abi->decodeMessageBody($abi, $body)); } /** * @covers ::encodeMessage * @covers \Extraton\TonClient\Crypto::sign + * @covers \Extraton\TonClient\Abi::attachSignature + * @covers * * @throws JsonException */ @@ -217,14 +242,79 @@ public function testEncodeMessage(): void $signer = SignerParams::fromExternal($this->dataProvider->getPublicKey()); - $expectedResult = [ - 'message' => 'te6ccgEBAgEAeAABpYgAC31qq9KF9Oifst6LU9U6FQSQQRlCSEMo+A3LN5MvphIFMfECP8d3ruNZAXul5xxahT91swIEkEHph08JVlwmUmQAAAXRnJcuDX1XMZBW+LBKAQBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=', - 'data_to_sign' => 'i4Hs3PB12QA9UBFbOIpkG3JerHHqjm4LgvF4MA7TDsY=', - 'address' => '0:05beb555e942fa744fd96f45a9ea9d0a8248208ca12421947c06e59bc997d309', - 'message_id' => '0bf67f00d10145b2809663c599203fe2dc2cf75caf089afbaf33e51156230062', - ]; + $expected = new ResultOfEncodeMessage( + new Response( + [ + 'message' => 'te6ccgEBAgEAeAABpYgAC31qq9KF9Oifst6LU9U6FQSQQRlCSEMo+A3LN5MvphIFMfECP8d3ruNZAXul5xxahT91swIEkEHph08JVlwmUmQAAAXRnJcuDX1XMZBW+LBKAQBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=', + 'data_to_sign' => 'i4Hs3PB12QA9UBFbOIpkG3JerHHqjm4LgvF4MA7TDsY=', + 'address' => '0:05beb555e942fa744fd96f45a9ea9d0a8248208ca12421947c06e59bc997d309', + 'message_id' => '0bf67f00d10145b2809663c599203fe2dc2cf75caf089afbaf33e51156230062', + ] + ) + ); - $expected = new ResultOfEncodeMessage(new Response($expectedResult)); + self::assertEquals( + $expected, + $resultOfEncodeMessage = $this->abi->encodeMessage( + $abi, + $signer, + null, + $callSet, + $address + ) + ); + + // Create detached signature + $expected = new ResultOfSign( + new Response( + [ + 'signed' => 'W7+38YTyy18BlAC5zUl+6qQfPViFYZ6ffU+rjdaV9LOgIVmhQimWwd19G+Z4mLx5xq26bGWhgQGsXwoqK7iRC4uB7NzwddkAPVARWziKZBtyXqxx6o5uC4LxeDAO0w7G', + 'signature' => '5bbfb7f184f2cb5f019400b9cd497eeaa41f3d5885619e9f7d4fab8dd695f4b3a02159a1422996c1dd7d1be67898bc79c6adba6c65a18101ac5f0a2a2bb8910b', + ] + ) + ); + + self::assertEquals( + $expected, + $resultOfSign = $this->crypto->sign( + $resultOfEncodeMessage->getDataToSign(), + $keyPair + ) + ); + + // Attach signature + $expected = new ResultOfAttachSignature( + new Response( + [ + 'message' => 'te6ccgEBAwEAvAABRYgAC31qq9KF9Oifst6LU9U6FQSQQRlCSEMo+A3LN5MvphIMAQHhrd/b+MJ5Za+AygBc5qS/dVIPnqxCsM9PvqfVxutK+lnQEKzQoRTLYO6+jfM8TF4841bdNjLQwIDWL4UVFdxIhdMfECP8d3ruNZAXul5xxahT91swIEkEHph08JVlwmUmQAAAXRnJcuDX1XMZBW+LBKACAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==', + 'message_id' => '4ce690920fa498d6e52051e952093438b9e37fa6d803caa5a724090be2cf78c7', + ] + ) + ); + + self::assertEquals( + $expected, + $this->abi->attachSignature( + $abi, + $this->dataProvider->getPublicKey(), + $resultOfEncodeMessage->getMessage(), + $resultOfSign->getSignature() + ) + ); + + // Create initially signed message + $signer = SignerParams::fromKeys($keyPair); + + $expected = new ResultOfEncodeMessage( + new Response( + [ + 'message' => 'te6ccgEBAwEAvAABRYgAC31qq9KF9Oifst6LU9U6FQSQQRlCSEMo+A3LN5MvphIMAQHhrd/b+MJ5Za+AygBc5qS/dVIPnqxCsM9PvqfVxutK+lnQEKzQoRTLYO6+jfM8TF4841bdNjLQwIDWL4UVFdxIhdMfECP8d3ruNZAXul5xxahT91swIEkEHph08JVlwmUmQAAAXRnJcuDX1XMZBW+LBKACAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==', + 'data_to_sign' => null, + 'address' => '0:05beb555e942fa744fd96f45a9ea9d0a8248208ca12421947c06e59bc997d309', + 'message_id' => '4ce690920fa498d6e52051e952093438b9e37fa6d803caa5a724090be2cf78c7', + ] + ) + ); self::assertEquals( $expected, @@ -233,8 +323,232 @@ public function testEncodeMessage(): void $signer, null, $callSet, - $address + $address, + ) + ); + } + + /** + * @covers ::decodeMessage + */ + public function testDecodeMessage(): void + { + $abi = AbiParams::fromArray($this->dataProvider->getEventsAbiArray()); + $message = 'te6ccgEBAwEAvAABRYgAC31qq9KF9Oifst6LU9U6FQSQQRlCSEMo+A3LN5MvphIMAQHhrd/b+MJ5Za+AygBc5qS/dVIPnqxCsM9PvqfVxutK+lnQEKzQoRTLYO6+jfM8TF4841bdNjLQwIDWL4UVFdxIhdMfECP8d3ruNZAXul5xxahT91swIEkEHph08JVlwmUmQAAAXRnJcuDX1XMZBW+LBKACAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=='; + + $expected = new DecodedMessageBody( + new Response( + [ + 'body_type' => 'Input', + 'name' => 'returnValue', + 'value' => + [ + 'id' => '0x0', + ], + 'header' => + [ + 'expire' => 1599458404, + 'time' => 1599458364291, + 'pubkey' => '4c7c408ff1ddebb8d6405ee979c716a14fdd6cc08124107a61d3c25597099499', + ], + ] ) ); + + self::assertEquals( + $expected, + $this->abi->decodeMessage( + $abi, + $message + ) + ); + + $message = 'te6ccgEBAQEAVQAApeACvg5/pmQpY4m61HmJ0ne+zjHJu3MNG8rJxUDLbHKBu/AAAAAAAAAMJL6z6ro48sYvAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABA'; + + $expected = new DecodedMessageBody( + new Response( + [ + 'body_type' => 'Event', + 'name' => 'EventThrown', + 'value' => + [ + 'id' => '0x0', + ], + 'header' => null, + ] + ) + ); + + self::assertEquals( + $expected, + $this->abi->decodeMessage( + $abi, + $message + ) + ); + + $message = 'te6ccgEBAQEAVQAApeACvg5/pmQpY4m61HmJ0ne+zjHJu3MNG8rJxUDLbHKBu/AAAAAAAAAMKr6z6rxK3xYJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABA'; + + $expected = new DecodedMessageBody( + new Response( + [ + 'body_type' => 'Output', + 'name' => 'returnValue', + 'value' => [ + 'value0' => '0x0', + ], + 'header' => null, + ] + ) + ); + + self::assertEquals( + $expected, + $this->abi->decodeMessage( + $abi, + $message + ) + ); + + // Test exception + $this->expectExceptionObject( + RequestException::create( + [ + 'message' => 'Message can\'t be decoded: failed to fill whole buffer', + 'code' => 304, + ] + ) + ); + + $this->abi->decodeMessage( + $abi, + '0x0' + ); + } + + /** + * @covers ::encodeAccount + */ + public function testEncodeAccount(): void + { + $abi = AbiParams::fromArray($this->dataProvider->getEventsAbiArray()); + + // Encode account from encoded deploy message + $encodedDeployMessage = 'te6ccgECFwEAA2gAAqeIAAt9aqvShfTon7Lei1PVOhUEkEEZQkhDKPgNyzeTL6YSEZTHxAj/Hd67jWQF7peccWoU/dbMCBJBB6YdPCVZcJlJkAAAF0ZyXLg19VzGRotV8/gGAQEBwAICA88gBQMBAd4EAAPQIABB2mPiBH+O713GsgL3S844tQp+62YECSCD0w6eEqy4TKTMAib/APSkICLAAZL0oOGK7VNYMPShCQcBCvSkIPShCAAAAgEgDAoByP9/Ie1E0CDXScIBjhDT/9M/0wDRf/hh+Gb4Y/hijhj0BXABgED0DvK91wv/+GJw+GNw+GZ/+GHi0wABjh2BAgDXGCD5AQHTAAGU0/8DAZMC+ELiIPhl+RDyqJXTAAHyeuLTPwELAGqOHvhDIbkgnzAg+COBA+iogggbd0Cgud6S+GPggDTyNNjTHwH4I7zyudMfAfAB+EdukvI83gIBIBINAgEgDw4AvbqLVfP/hBbo417UTQINdJwgGOENP/0z/TANF/+GH4Zvhj+GKOGPQFcAGAQPQO8r3XC//4YnD4Y3D4Zn/4YeLe+Ebyc3H4ZtH4APhCyMv/+EPPCz/4Rs8LAMntVH/4Z4AgEgERAA5biABrW/CC3Rwn2omhp/+mf6YBov/ww/DN8Mfwxb30gyupo6H0gb+j8IpA3SRg4b3whXXlwMnwAZGT9ghBkZ8KEZ0aCBAfQAAAAAAAAAAAAAAAAACBni2TAgEB9gBh8IWRl//wh54Wf/CNnhYBk9qo//DPAAxbmTwqLfCC3Rwn2omhp/+mf6YBov/ww/DN8Mfwxb2uG/8rqaOhp/+/o/ABkRe4AAAAAAAAAAAAAAAAIZ4tnwOfI48sYvRDnhf/kuP2AGHwhZGX//CHnhZ/8I2eFgGT2qj/8M8AIBSBYTAQm4t8WCUBQB/PhBbo4T7UTQ0//TP9MA0X/4Yfhm+GP4Yt7XDf+V1NHQ0//f0fgAyIvcAAAAAAAAAAAAAAAAEM8Wz4HPkceWMXohzwv/yXH7AMiL3AAAAAAAAAAAAAAAABDPFs+Bz5JW+LBKIc8L/8lx+wAw+ELIy//4Q88LP/hGzwsAye1UfxUABPhnAHLccCLQ1gIx0gAw3CHHAJLyO+Ah1w0fkvI84VMRkvI74cEEIoIQ/////byxkvI84AHwAfhHbpLyPN4='; + $messageSource = MessageSource::fromEncoded($encodedDeployMessage, $abi); + $stateInitSource = StateInitSource::fromMessage($messageSource); + + $expected = new ResultOfEncodeAccount( + new Response( + [ + 'account' => 'te6ccgECFwEAA00AAnHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACLoWrAAAAAAAAAAAAAAAAAUXSHboAE0AGAQEBwAICA88gBQMBAd4EAAPQIABB2mPiBH+O713GsgL3S844tQp+62YECSCD0w6eEqy4TKTMAib/APSkICLAAZL0oOGK7VNYMPShCQcBCvSkIPShCAAAAgEgDAoByP9/Ie1E0CDXScIBjhDT/9M/0wDRf/hh+Gb4Y/hijhj0BXABgED0DvK91wv/+GJw+GNw+GZ/+GHi0wABjh2BAgDXGCD5AQHTAAGU0/8DAZMC+ELiIPhl+RDyqJXTAAHyeuLTPwELAGqOHvhDIbkgnzAg+COBA+iogggbd0Cgud6S+GPggDTyNNjTHwH4I7zyudMfAfAB+EdukvI83gIBIBINAgEgDw4AvbqLVfP/hBbo417UTQINdJwgGOENP/0z/TANF/+GH4Zvhj+GKOGPQFcAGAQPQO8r3XC//4YnD4Y3D4Zn/4YeLe+Ebyc3H4ZtH4APhCyMv/+EPPCz/4Rs8LAMntVH/4Z4AgEgERAA5biABrW/CC3Rwn2omhp/+mf6YBov/ww/DN8Mfwxb30gyupo6H0gb+j8IpA3SRg4b3whXXlwMnwAZGT9ghBkZ8KEZ0aCBAfQAAAAAAAAAAAAAAAAACBni2TAgEB9gBh8IWRl//wh54Wf/CNnhYBk9qo//DPAAxbmTwqLfCC3Rwn2omhp/+mf6YBov/ww/DN8Mfwxb2uG/8rqaOhp/+/o/ABkRe4AAAAAAAAAAAAAAAAIZ4tnwOfI48sYvRDnhf/kuP2AGHwhZGX//CHnhZ/8I2eFgGT2qj/8M8AIBSBYTAQm4t8WCUBQB/PhBbo4T7UTQ0//TP9MA0X/4Yfhm+GP4Yt7XDf+V1NHQ0//f0fgAyIvcAAAAAAAAAAAAAAAAEM8Wz4HPkceWMXohzwv/yXH7AMiL3AAAAAAAAAAAAAAAABDPFs+Bz5JW+LBKIc8L/8lx+wAw+ELIy//4Q88LP/hGzwsAye1UfxUABPhnAHLccCLQ1gIx0gAw3CHHAJLyO+Ah1w0fkvI84VMRkvI74cEEIoIQ/////byxkvI84AHwAfhHbpLyPN4=', + 'id' => '05beb555e942fa744fd96f45a9ea9d0a8248208ca12421947c06e59bc997d309', + ] + ) + ); + + self::assertEquals( + $expected, + $this->abi->encodeAccount($stateInitSource) + ); + + // Encode account from encoding params + $deploySet = new DeploySetParams($this->dataProvider->getEventsTvc()); + + $keyPair = new KeyPair( + $this->dataProvider->getPublicKey(), + $this->dataProvider->getPrivateKey(), + ); + + $functionHeaderParams = new FunctionHeaderParams( + $this->dataProvider->getPublicKey(), + $this->dataProvider->getEventsTime(), + $this->dataProvider->getEventsExpire(), + ); + $callSet = new CallSetParams('constructor', $functionHeaderParams); + + $signer = SignerParams::fromKeys($keyPair); + + $messageSource = MessageSource::fromEncodingParams( + $abi, + $signer, + $deploySet, + $callSet + ); + + $stateInitSource = StateInitSource::fromMessage($messageSource); + + $expected = new ResultOfEncodeAccount( + new Response( + [ + 'account' => 'te6ccgECFwEAA00AAnHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACLoWrAAAAAAAAAAAAAAAAAUXSHboAE0AGAQEBwAICA88gBQMBAd4EAAPQIABB2mPiBH+O713GsgL3S844tQp+62YECSCD0w6eEqy4TKTMAib/APSkICLAAZL0oOGK7VNYMPShCQcBCvSkIPShCAAAAgEgDAoByP9/Ie1E0CDXScIBjhDT/9M/0wDRf/hh+Gb4Y/hijhj0BXABgED0DvK91wv/+GJw+GNw+GZ/+GHi0wABjh2BAgDXGCD5AQHTAAGU0/8DAZMC+ELiIPhl+RDyqJXTAAHyeuLTPwELAGqOHvhDIbkgnzAg+COBA+iogggbd0Cgud6S+GPggDTyNNjTHwH4I7zyudMfAfAB+EdukvI83gIBIBINAgEgDw4AvbqLVfP/hBbo417UTQINdJwgGOENP/0z/TANF/+GH4Zvhj+GKOGPQFcAGAQPQO8r3XC//4YnD4Y3D4Zn/4YeLe+Ebyc3H4ZtH4APhCyMv/+EPPCz/4Rs8LAMntVH/4Z4AgEgERAA5biABrW/CC3Rwn2omhp/+mf6YBov/ww/DN8Mfwxb30gyupo6H0gb+j8IpA3SRg4b3whXXlwMnwAZGT9ghBkZ8KEZ0aCBAfQAAAAAAAAAAAAAAAAACBni2TAgEB9gBh8IWRl//wh54Wf/CNnhYBk9qo//DPAAxbmTwqLfCC3Rwn2omhp/+mf6YBov/ww/DN8Mfwxb2uG/8rqaOhp/+/o/ABkRe4AAAAAAAAAAAAAAAAIZ4tnwOfI48sYvRDnhf/kuP2AGHwhZGX//CHnhZ/8I2eFgGT2qj/8M8AIBSBYTAQm4t8WCUBQB/PhBbo4T7UTQ0//TP9MA0X/4Yfhm+GP4Yt7XDf+V1NHQ0//f0fgAyIvcAAAAAAAAAAAAAAAAEM8Wz4HPkceWMXohzwv/yXH7AMiL3AAAAAAAAAAAAAAAABDPFs+Bz5JW+LBKIc8L/8lx+wAw+ELIy//4Q88LP/hGzwsAye1UfxUABPhnAHLccCLQ1gIx0gAw3CHHAJLyO+Ah1w0fkvI84VMRkvI74cEEIoIQ/////byxkvI84AHwAfhHbpLyPN4=', + 'id' => '05beb555e942fa744fd96f45a9ea9d0a8248208ca12421947c06e59bc997d309', + ] + ) + ); + + self::assertEquals( + $expected, + $this->abi->encodeAccount($stateInitSource) + ); + + // Encode account from TVC + $stateInitSource = StateInitSource::fromTvc($this->dataProvider->getEventsTvc()); + + $expected = new ResultOfEncodeAccount( + new Response( + [ + 'account' => 'te6ccgECFwEAA00AAnHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACLoWrAAAAAAAAAAAAAAAAAUXSHboAE0AGAQEBwAICA88gBQMBAd4EAAPQIABB2AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAib/APSkICLAAZL0oOGK7VNYMPShCQcBCvSkIPShCAAAAgEgDAoByP9/Ie1E0CDXScIBjhDT/9M/0wDRf/hh+Gb4Y/hijhj0BXABgED0DvK91wv/+GJw+GNw+GZ/+GHi0wABjh2BAgDXGCD5AQHTAAGU0/8DAZMC+ELiIPhl+RDyqJXTAAHyeuLTPwELAGqOHvhDIbkgnzAg+COBA+iogggbd0Cgud6S+GPggDTyNNjTHwH4I7zyudMfAfAB+EdukvI83gIBIBINAgEgDw4AvbqLVfP/hBbo417UTQINdJwgGOENP/0z/TANF/+GH4Zvhj+GKOGPQFcAGAQPQO8r3XC//4YnD4Y3D4Zn/4YeLe+Ebyc3H4ZtH4APhCyMv/+EPPCz/4Rs8LAMntVH/4Z4AgEgERAA5biABrW/CC3Rwn2omhp/+mf6YBov/ww/DN8Mfwxb30gyupo6H0gb+j8IpA3SRg4b3whXXlwMnwAZGT9ghBkZ8KEZ0aCBAfQAAAAAAAAAAAAAAAAACBni2TAgEB9gBh8IWRl//wh54Wf/CNnhYBk9qo//DPAAxbmTwqLfCC3Rwn2omhp/+mf6YBov/ww/DN8Mfwxb2uG/8rqaOhp/+/o/ABkRe4AAAAAAAAAAAAAAAAIZ4tnwOfI48sYvRDnhf/kuP2AGHwhZGX//CHnhZ/8I2eFgGT2qj/8M8AIBSBYTAQm4t8WCUBQB/PhBbo4T7UTQ0//TP9MA0X/4Yfhm+GP4Yt7XDf+V1NHQ0//f0fgAyIvcAAAAAAAAAAAAAAAAEM8Wz4HPkceWMXohzwv/yXH7AMiL3AAAAAAAAAAAAAAAABDPFs+Bz5JW+LBKIc8L/8lx+wAw+ELIy//4Q88LP/hGzwsAye1UfxUABPhnAHLccCLQ1gIx0gAw3CHHAJLyO+Ah1w0fkvI84VMRkvI74cEEIoIQ/////byxkvI84AHwAfhHbpLyPN4=', + 'id' => '84a9510b0278047154b1b84b6dd445c1349d8d42d75a2eece07b72ad6e4ea136', + ] + ) + ); + + self::assertEquals( + $expected, + $this->abi->encodeAccount($stateInitSource) + ); + + $stateInitSource = StateInitSource::fromTvc( + $this->dataProvider->getEventsTvc(), + $this->dataProvider->getPublicKey() + ); + + $expected = new ResultOfEncodeAccount( + new Response( + [ + 'account' => 'te6ccgECFwEAA00AAnHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACLoWrAAAAAAAAAAAAAAAAAUXSHboAE0AGAQEBwAICA88gBQMBAd4EAAPQIABB2mPiBH+O713GsgL3S844tQp+62YECSCD0w6eEqy4TKTMAib/APSkICLAAZL0oOGK7VNYMPShCQcBCvSkIPShCAAAAgEgDAoByP9/Ie1E0CDXScIBjhDT/9M/0wDRf/hh+Gb4Y/hijhj0BXABgED0DvK91wv/+GJw+GNw+GZ/+GHi0wABjh2BAgDXGCD5AQHTAAGU0/8DAZMC+ELiIPhl+RDyqJXTAAHyeuLTPwELAGqOHvhDIbkgnzAg+COBA+iogggbd0Cgud6S+GPggDTyNNjTHwH4I7zyudMfAfAB+EdukvI83gIBIBINAgEgDw4AvbqLVfP/hBbo417UTQINdJwgGOENP/0z/TANF/+GH4Zvhj+GKOGPQFcAGAQPQO8r3XC//4YnD4Y3D4Zn/4YeLe+Ebyc3H4ZtH4APhCyMv/+EPPCz/4Rs8LAMntVH/4Z4AgEgERAA5biABrW/CC3Rwn2omhp/+mf6YBov/ww/DN8Mfwxb30gyupo6H0gb+j8IpA3SRg4b3whXXlwMnwAZGT9ghBkZ8KEZ0aCBAfQAAAAAAAAAAAAAAAAACBni2TAgEB9gBh8IWRl//wh54Wf/CNnhYBk9qo//DPAAxbmTwqLfCC3Rwn2omhp/+mf6YBov/ww/DN8Mfwxb2uG/8rqaOhp/+/o/ABkRe4AAAAAAAAAAAAAAAAIZ4tnwOfI48sYvRDnhf/kuP2AGHwhZGX//CHnhZ/8I2eFgGT2qj/8M8AIBSBYTAQm4t8WCUBQB/PhBbo4T7UTQ0//TP9MA0X/4Yfhm+GP4Yt7XDf+V1NHQ0//f0fgAyIvcAAAAAAAAAAAAAAAAEM8Wz4HPkceWMXohzwv/yXH7AMiL3AAAAAAAAAAAAAAAABDPFs+Bz5JW+LBKIc8L/8lx+wAw+ELIy//4Q88LP/hGzwsAye1UfxUABPhnAHLccCLQ1gIx0gAw3CHHAJLyO+Ah1w0fkvI84VMRkvI74cEEIoIQ/////byxkvI84AHwAfhHbpLyPN4=', + 'id' => '05beb555e942fa744fd96f45a9ea9d0a8248208ca12421947c06e59bc997d309', + ] + ) + ); + + self::assertEquals( + $expected, + $this->abi->encodeAccount($stateInitSource) + ); + + // Test exception with external signer + $signer = SignerParams::fromExternal($this->dataProvider->getPublicKey()); + + $messageSource = MessageSource::fromEncodingParams( + $abi, + $signer, + $deploySet, + $callSet + ); + + $stateInitSource = StateInitSource::fromMessage($messageSource); + + $this->expectExceptionObject( + RequestException::create( + [ + 'message' => 'Function `process_message` must not be used with external message signing.', + 'code' => 513, + ] + ) + ); + + $this->abi->encodeAccount($stateInitSource); } }