import { expectTypeOf, test } from 'vp/test' import type * as Hex from '../core/Hex.js' import * as AccountOperation from './AccountOperation.js' import type * as TxEnvelopeTempo from './TxEnvelopeTempo.js' declare const transaction: AccountOperation.TransactionOperation declare const transactionRpc: AccountOperation.TransactionRpc declare const keyAuthorization: AccountOperation.KeyAuthorizationOperation declare const keyAuthorizationRpc: AccountOperation.KeyAuthorizationRpc declare const operation: AccountOperation.Operation declare const operationRpc: AccountOperation.Rpc declare const getHashOptions: AccountOperation.getHash.Options declare const selectApprovalsOptions: AccountOperation.selectApprovals.Options declare const serializedKeyAuthorization: Hex.Hex declare const serializeKeyAuthorizationOptions: AccountOperation.serializeKeyAuthorization.Options declare const serializeTransactionOptions: AccountOperation.serializeTransaction.Options test('preserves operation kinds during validation', () => { expectTypeOf( AccountOperation.from(transaction), ).toEqualTypeOf() expectTypeOf( AccountOperation.from(keyAuthorization), ).toEqualTypeOf() expectTypeOf( AccountOperation.from(operation), ).toEqualTypeOf() }) test('preserves operation kinds during RPC conversion', () => { expectTypeOf( AccountOperation.fromRpc(transactionRpc), ).toEqualTypeOf() expectTypeOf( AccountOperation.fromRpc(keyAuthorizationRpc), ).toEqualTypeOf() expectTypeOf( AccountOperation.toRpc(transaction), ).toEqualTypeOf() expectTypeOf( AccountOperation.toRpc(keyAuthorization), ).toEqualTypeOf() expectTypeOf( AccountOperation.fromRpc(operationRpc), ).toEqualTypeOf() expectTypeOf( AccountOperation.toRpc(operation), ).toEqualTypeOf() }) test('uses JSON-RPC quantities only in RPC operations', () => { expectTypeOf< AccountOperation.Operation['config']['version'] >().toEqualTypeOf() expectTypeOf< AccountOperation.Rpc['config']['version'] >().toEqualTypeOf() }) test('operation helpers return narrow types', async () => { expectTypeOf( AccountOperation.getHash(getHashOptions), ).toEqualTypeOf() expectTypeOf( await AccountOperation.selectApprovals(selectApprovalsOptions), ).toEqualTypeOf() expectTypeOf( AccountOperation.serializeKeyAuthorization( serializedKeyAuthorization, serializeKeyAuthorizationOptions, ), ).toEqualTypeOf() expectTypeOf( AccountOperation.serializeTransaction( transaction, serializeTransactionOptions, ), ).toEqualTypeOf() })