From acf743e53c63930fe096f01ea7a3632bb748c443 Mon Sep 17 00:00:00 2001 From: Fabricius Zatti Date: Sat, 29 Jun 2024 19:31:16 -0300 Subject: [PATCH] chore: remove unused mocks --- .../test/mocks/account-response-mock.ts | 49 ----------- src/stellar-plus/test/mocks/accounts.ts | 27 ------ src/stellar-plus/test/mocks/balances.ts | 28 ------- .../test/mocks/classic-transaction.ts | 84 ------------------- src/stellar-plus/test/mocks/constants.ts | 6 -- 5 files changed, 194 deletions(-) delete mode 100644 src/stellar-plus/test/mocks/account-response-mock.ts delete mode 100644 src/stellar-plus/test/mocks/accounts.ts delete mode 100644 src/stellar-plus/test/mocks/balances.ts delete mode 100644 src/stellar-plus/test/mocks/classic-transaction.ts delete mode 100644 src/stellar-plus/test/mocks/constants.ts diff --git a/src/stellar-plus/test/mocks/account-response-mock.ts b/src/stellar-plus/test/mocks/account-response-mock.ts deleted file mode 100644 index 643c97ee..00000000 --- a/src/stellar-plus/test/mocks/account-response-mock.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { HorizonApi } from '@stellar/stellar-sdk/lib/horizon' - -import { balances } from './balances' - -export class MockAccountResponse { - private readonly _baseAccount - readonly id: string - readonly paging_token: string - readonly account_id: string - sequence: string - readonly sequence_ledger?: number - readonly sequence_time?: string - readonly subentry_count: number - readonly home_domain?: string - readonly inflation_destination?: string - readonly last_modified_ledger!: number - readonly last_modified_time!: string - readonly thresholds!: HorizonApi.AccountThresholds - readonly flags!: HorizonApi.Flags - readonly balances!: HorizonApi.BalanceLine[] - readonly signers!: HorizonApi.AccountSigner[] - readonly data!: (options: { value: string }) => Promise<{ value: string }> - readonly data_attr!: Record - - constructor( - account_id = 'GBDMM7FQBVQPZFQPXVS3ZKK4UMELIWPBLG2BZQSWERD2KZR44WI6PTBQ', - asset_issuer = 'GCL3QOGZXUN4OSP35ZR6MZHIZPFJNSCT2XPX227HFTDF7DE526FBDZV6' - ) { - this.id = 'mock_id' - this.paging_token = 'mock_paging_token' - this.account_id = account_id - this.sequence = '123456' - this.subentry_count = 0 - this._baseAccount = '_baseAccount' - this.balances = balances(asset_issuer) - } - - accountId(): string { - return this.account_id - } - - sequenceNumber(): string { - return this.sequence - } - - incrementSequenceNumber(): void { - return - } -} diff --git a/src/stellar-plus/test/mocks/accounts.ts b/src/stellar-plus/test/mocks/accounts.ts deleted file mode 100644 index d158ccb4..00000000 --- a/src/stellar-plus/test/mocks/accounts.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { Account } from '@stellar/stellar-sdk' - -import { DefaultAccountHandlerClient as DefaultAccountHandler } from 'stellar-plus/account/account-handler/default' -import { ACCOUNT_A_PK, ACCOUNT_A_SK, NETWORK } from 'stellar-plus/test/mocks/constants' - -export type SimpleKeyPairMock = { - publicKey: string - secretKey: string -} - -export const mockedSimpleKeyPair: SimpleKeyPairMock = { - publicKey: ACCOUNT_A_PK, - secretKey: ACCOUNT_A_SK, -} - -export const mockedStellarAccount: Account = { - accountId: () => ACCOUNT_A_PK, - sequenceNumber: () => '12345', - incrementSequenceNumber: () => { - return - }, -} - -export const mockedDefaultAccountHandler = new DefaultAccountHandler({ - networkConfig: NETWORK, - secretKey: ACCOUNT_A_SK, -}) diff --git a/src/stellar-plus/test/mocks/balances.ts b/src/stellar-plus/test/mocks/balances.ts deleted file mode 100644 index ba606be6..00000000 --- a/src/stellar-plus/test/mocks/balances.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { HorizonApi } from '@stellar/stellar-sdk/lib/horizon' - -export const balances = ( - asset_issuer = 'GCL3QOGZXUN4OSP35ZR6MZHIZPFJNSCT2XPX227HFTDF7DE526FBDZV6', - asset_code = 'CAKE' -): HorizonApi.BalanceLine[] => { - return [ - { - balance: '3000000.0000000', - limit: '922337203685.4775807', - asset_type: 'credit_alphanum4', - asset_code: asset_code, - asset_issuer: asset_issuer, - buying_liabilities: '0.0000000', - selling_liabilities: '0.0000000', - last_modified_ledger: 2849609, - is_authorized: true, - is_authorized_to_maintain_liabilities: true, - is_clawback_enabled: false, - }, - { - balance: '10000.0000000', - buying_liabilities: '0.0000000', - selling_liabilities: '0.0000000', - asset_type: 'native', - }, - ] -} diff --git a/src/stellar-plus/test/mocks/classic-transaction.ts b/src/stellar-plus/test/mocks/classic-transaction.ts deleted file mode 100644 index 7619184a..00000000 --- a/src/stellar-plus/test/mocks/classic-transaction.ts +++ /dev/null @@ -1,84 +0,0 @@ -import { Account, Keypair, Operation, Transaction, TransactionBuilder } from '@stellar/stellar-sdk' -import { HorizonApi } from '@stellar/stellar-sdk/lib/horizon' - -import { TransactionInvocation } from 'stellar-plus/core/types' -import { mockedStellarAccount } from 'stellar-plus/test/mocks/accounts' -import { ACCOUNT_A_SK, NETWORK_PASSPHRASE } from 'stellar-plus/test/mocks/constants' - -// ============================== -// simple classic transactions -// ============================== - -const sourceAccount = mockedStellarAccount as Account - -const unsignedClassicTransaction = new TransactionBuilder(sourceAccount, { - fee: '100', - networkPassphrase: NETWORK_PASSPHRASE, -}) - .addOperation( - Operation.setOptions({ - homeDomain: 'cake.com', // Set the home domain to 'cake.com' - }) - ) - .setTimeout(0) - .build() - -const unsignedClassicTransactionXdr = unsignedClassicTransaction.toXDR() - -const signingKeypair = Keypair.fromSecret(ACCOUNT_A_SK) - -const signedClassicTransaction = TransactionBuilder.cloneFrom(unsignedClassicTransaction).build() -signedClassicTransaction.sign(signingKeypair) - -const signedClassicTransactionXdr = signedClassicTransaction.toXDR() - -export { - unsignedClassicTransaction as mockUnsignedClassicTransaction, - unsignedClassicTransactionXdr as mockUnsignedClassicTransactionXdr, - signedClassicTransaction as mockSignedClassicTransaction, - signedClassicTransactionXdr as mockSignedClassicTransactionXdr, -} - -// ============================== - -// ============================== -// Classic Transaction Processor -// ============================== - -export type MockTransactionProcessorType = { - processTransaction: () => Promise - buildCustomTransaction: ( - operations: Operation[], - txInvocation: TransactionInvocation - ) => Promise<{ builtTx: Transaction; updatedTxInvocation: TransactionInvocation }> -} - -export class mockClassicTransactionProcessor implements MockTransactionProcessorType { - public processTransaction = jest.fn().mockImplementation((): Promise => { - return Promise.resolve(mockHorizonApiSubmitTransactionResponse()) - }) - - public buildCustomTransaction = jest - .fn() - .mockImplementation( - ( - operations: Operation[], - txInvocation: TransactionInvocation - ): Promise<{ builtTx: Transaction; updatedTxInvocation: TransactionInvocation }> => { - console.log('mocking buildCustomTransaction') - return Promise.resolve({ builtTx: unsignedClassicTransaction, updatedTxInvocation: txInvocation }) - } - ) -} - -export const mockHorizonApiSubmitTransactionResponse = (): HorizonApi.SubmitTransactionResponse => { - return { - hash: 'mock hash', - ledger: 12345, - successful: true, - envelope_xdr: 'mock envelope xdr', - result_xdr: 'mock result xdr', - result_meta_xdr: 'mock result meta xdr', - paging_token: 'mock paging token', - } -} diff --git a/src/stellar-plus/test/mocks/constants.ts b/src/stellar-plus/test/mocks/constants.ts deleted file mode 100644 index bd1534e2..00000000 --- a/src/stellar-plus/test/mocks/constants.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { TestNet } from 'stellar-plus/network' - -export const ACCOUNT_A_PK = 'GAVVRSYGWDE3N24SJRCMCXOAOXVPM7YPTEUSOVXEN344Q45UZ6DMQSR2' -export const ACCOUNT_A_SK = 'SDZTDX3J7PGZW6PKIPODAFQ7SRBCKTQGSG7YD7QMJQDKOSN6ZZTJOSMT' -export const NETWORK_PASSPHRASE = 'Test SDF Network ; September 2015' -export const NETWORK = TestNet()