Skip to content

Commit

Permalink
test: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
petarTxFusion committed Jan 27, 2025
1 parent d6ee584 commit 0bda7fd
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 13 deletions.
17 changes: 14 additions & 3 deletions packages/worker/src/token/token.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe("TokenService", () => {
let addressRepositoryMock: AddressRepository;
let startGetTokenInfoDurationMetricMock: jest.Mock;
let stopGetTokenInfoDurationMetricMock: jest.Mock;

let configServiceMock: ConfigService;
beforeEach(async () => {
blockchainServiceMock = mock<BlockchainService>({
bridgeAddresses: {
Expand All @@ -30,6 +30,16 @@ describe("TokenService", () => {
stopGetTokenInfoDurationMetricMock = jest.fn();
startGetTokenInfoDurationMetricMock = jest.fn().mockReturnValue(stopGetTokenInfoDurationMetricMock);

configServiceMock = mock<ConfigService>({
get: jest
.fn()
.mockReturnValueOnce("0x0000000000000000000000000000000000000000")
.mockReturnValueOnce("ETH")
.mockReturnValueOnce("Ether")
.mockReturnValueOnce(18)
.mockReturnValueOnce("https://assets.coingecko.com/coins/images/279/large/ethereum.png?1696501427"),
});

const app: TestingModule = await Test.createTestingModule({
providers: [
TokenService,
Expand All @@ -47,7 +57,7 @@ describe("TokenService", () => {
},
{
provide: ConfigService,
useValue: mock<ConfigService>(),
useValue: configServiceMock,
},
{
provide: "PROM_METRIC_GET_TOKEN_INFO_DURATION_SECONDS",
Expand Down Expand Up @@ -128,6 +138,7 @@ describe("TokenService", () => {
symbol: "ETH",
decimals: 18,
name: "Ether",
iconURL: "https://assets.coingecko.com/coins/images/279/large/ethereum.png?1696501427",
};
const deployedETHContractAddress = mock<ContractAddress>({
address: utils.L2_BASE_TOKEN_ADDRESS,
Expand All @@ -146,7 +157,7 @@ describe("TokenService", () => {
l2Address: deployedETHContractAddress.address,
l1Address: utils.ETH_ADDRESS,
logIndex: deployedETHContractAddress.logIndex,
iconURL: undefined,
iconURL: "https://assets.coingecko.com/coins/images/279/large/ethereum.png?1696501427",
});
});
});
Expand Down
6 changes: 3 additions & 3 deletions packages/worker/src/token/token.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ export class TokenService {
logIndex: contractAddress.logIndex,
l2Address: utils.L2_BASE_TOKEN_ADDRESS,
l1Address: this.configService.get<string>("tokens.baseToken.l1Address"),
symbol: this.configService.get<string>("tokens.baseToken.symbol") ?? "ETH",
name: this.configService.get<string>("tokens.baseToken.name") ?? "Ether",
decimals: this.configService.get<number>("tokens.baseToken.decimals") ?? 18,
symbol: this.configService.get<string>("tokens.baseToken.symbol"),
name: this.configService.get<string>("tokens.baseToken.name"),
decimals: this.configService.get<number>("tokens.baseToken.decimals"),
iconURL: this.configService.get<string>("tokens.baseToken.iconUrl"),
});
} else {
Expand Down
31 changes: 24 additions & 7 deletions packages/worker/src/transaction/transaction.processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ import { utils } from "zksync-ethers";
@Injectable()
export class TransactionProcessor {
private readonly logger: Logger;
private readonly baseTokenConfig: {
l1Address: string;
symbol: string;
name: string;
decimals: number;
iconUrl: string;
};

public constructor(
private readonly transactionRepository: TransactionRepository,
Expand All @@ -25,11 +32,20 @@ export class TransactionProcessor {
private readonly transferRepository: TransferRepository,
private readonly addressRepository: AddressRepository,
private readonly tokenRepository: TokenRepository,
private readonly configService: ConfigService,
@InjectMetric(TRANSACTION_PROCESSING_DURATION_METRIC_NAME)
private readonly transactionProcessingDurationMetric: Histogram
private readonly transactionProcessingDurationMetric: Histogram,
configService: ConfigService
) {
this.logger = new Logger(TransactionProcessor.name);
console.log("Batch processing polling interval", configService);

this.baseTokenConfig = {
l1Address: configService.get<string>("tokens.baseToken.l1Address"),
symbol: configService.get<string>("tokens.baseToken.symbol"),
name: configService.get<string>("tokens.baseToken.name"),
decimals: configService.get<number>("tokens.baseToken.decimals"),
iconUrl: configService.get<string>("tokens.baseToken.iconUrl"),
};
}

public async add(blockNumber: number, transactionData: TransactionData): Promise<void> {
Expand Down Expand Up @@ -104,6 +120,7 @@ export class TransactionProcessor {
blockNumber: blockNumber,
transactionHash: transactionData.transaction.hash,
});
console.log("Config l1 transaction processor", this.baseTokenConfig.l1Address);
await Promise.all(
transactionData.tokens.map((token) => {
if (token.l2Address.toLowerCase() === utils.L2_BASE_TOKEN_ADDRESS.toLowerCase()) {
Expand All @@ -112,11 +129,11 @@ export class TransactionProcessor {
transactionHash: token.transactionHash,
logIndex: token.logIndex,
l2Address: utils.L2_BASE_TOKEN_ADDRESS,
l1Address: this.configService.get<string>("tokens.baseToken.l1Address"),
symbol: this.configService.get<string>("tokens.baseToken.symbol"),
name: this.configService.get<string>("tokens.baseToken.name"),
decimals: this.configService.get<number>("tokens.baseToken.decimals"),
iconURL: this.configService.get<string>("tokens.baseToken.iconUrl"),
l1Address: this.baseTokenConfig.l1Address,
symbol: this.baseTokenConfig.symbol,
name: this.baseTokenConfig.name,
decimals: this.baseTokenConfig.decimals,
iconURL: this.baseTokenConfig.iconUrl,
});
} else {
this.tokenRepository.upsert(token);
Expand Down

0 comments on commit 0bda7fd

Please sign in to comment.