Skip to content

Commit

Permalink
Don't throw if creation transaction doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
iamacook committed Jan 6, 2025
1 parent ca56887 commit dba536c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 6 deletions.
41 changes: 41 additions & 0 deletions src/routes/transactions/transactions-history.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,47 @@ describe('Transactions History Controller (Unit)', () => {
});
});

it('Should not throw if creation transaction does not exist', async () => {
const chainResponse = chainBuilder().build();
const chainId = chainResponse.chainId;
const safe = safeBuilder().build();
const transactionHistoryBuilder = {
count: 0,
next: null,
previous: null,
results: [],
};
networkService.get.mockImplementation(({ url }) => {
const getChainUrl = `${safeConfigUrl}/api/v1/chains/${chainId}`;
const getAllTransactions = `${chainResponse.transactionService}/api/v1/safes/${safe.address}/all-transactions/`;
const getSafeUrl = `${chainResponse.transactionService}/api/v1/safes/${safe.address}`;
const getSafeCreationUrl = `${chainResponse.transactionService}/api/v1/safes/${safe.address}/creation/`;
if (url === getChainUrl) {
return Promise.resolve({ data: rawify(chainResponse), status: 200 });
}
if (url === getAllTransactions) {
return Promise.resolve({
data: rawify(transactionHistoryBuilder),
status: 200,
});
}
if (url === getSafeUrl) {
return Promise.resolve({ data: rawify(safe), status: 200 });
}
if (url === getSafeCreationUrl) {
return Promise.reject(new Error('Not found'));
}
return Promise.reject(new Error(`Could not match ${url}`));
});

await request(app.getHttpServer())
.get(`/v1/chains/${chainId}/safes/${safe.address}/transactions/history/`)
.expect(200)
.then(({ body }) => {
expect(body.results).toHaveLength(0);
});
});

it('Should return correctly each date label', async () => {
const safe = safeBuilder().build();
const chain = chainBuilder().build();
Expand Down
19 changes: 13 additions & 6 deletions src/routes/transactions/transactions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { TransactionsHistoryMapper } from '@/routes/transactions/mappers/transac
import { TransferDetailsMapper } from '@/routes/transactions/mappers/transfers/transfer-details.mapper';
import { TransferMapper } from '@/routes/transactions/mappers/transfers/transfer.mapper';
import { getAddress, isAddress } from 'viem';
import { LoggingService, ILoggingService } from '@/logging/logging.interface';

@Injectable()
export class TransactionsService {
Expand All @@ -51,6 +52,7 @@ export class TransactionsService {
private readonly moduleTransactionDetailsMapper: ModuleTransactionDetailsMapper,
private readonly multisigTransactionDetailsMapper: MultisigTransactionDetailsMapper,
private readonly transferDetailsMapper: TransferDetailsMapper,
@Inject(LoggingService) private readonly loggingService: ILoggingService,
) {}

async getById(args: {
Expand Down Expand Up @@ -392,12 +394,17 @@ export class TransactionsService {
const nextURL = buildNextPageURL(args.routeUrl, domainTransactions.count);
const previousURL = buildPreviousPageURL(args.routeUrl);
if (nextURL == null) {
const creationTransaction =
await this.safeRepository.getCreationTransaction({
chainId: args.chainId,
safeAddress: args.safeAddress,
});
domainTransactions.results.push(creationTransaction);
// If creation is not indexed, we shouldn't block the entire history
try {
const creationTransaction =
await this.safeRepository.getCreationTransaction({
chainId: args.chainId,
safeAddress: args.safeAddress,
});
domainTransactions.results.push(creationTransaction);
} catch (error) {
this.loggingService.warn(error);
}
}
const safeInfo = await this.safeRepository.getSafe({
chainId: args.chainId,
Expand Down

0 comments on commit dba536c

Please sign in to comment.