From 911ae24a575d21231ffe33ca2cd7717e0c4e129e Mon Sep 17 00:00:00 2001 From: Julian <52217955+julianmerlo95@users.noreply.github.com> Date: Thu, 25 Jul 2024 12:19:30 -0300 Subject: [PATCH] [Blockchain Watcher] (WORMCHAIN) Improve how create the providers (#1561) * Improve how create the providers for wormchain * Remove validation when create a client * Fix rpcs * Remove bsc rpcs * Add default chain * Throw error when we cant map cosmos chain --- blockchain-watcher/config/mainnet.json | 15 +--- blockchain-watcher/src/common/wormchain.ts | 2 +- .../actions/wormchain/GetWormchainLogs.ts | 4 +- .../actions/wormchain/GetWormchainRedeems.ts | 4 +- .../domain/actions/wormchain/PollWormchain.ts | 4 +- blockchain-watcher/src/domain/repositories.ts | 4 +- .../repositories/RepositoriesBuilder.ts | 39 ++++---- ...eLimitedWormchainJsonRPCBlockRepository.ts | 8 +- .../WormchainJsonRPCBlockRepository.ts | 54 +++++------- .../wormchain/GetWormchainLogs.test.ts | 4 +- .../wormchain/GetWormchainRedeems.test.ts | 4 +- .../actions/wormchain/PollWormchain.test.ts | 2 +- .../WormchainJsonRPCBlockRepository.test.ts | 88 ++++++++++++------- 13 files changed, 116 insertions(+), 116 deletions(-) diff --git a/blockchain-watcher/config/mainnet.json b/blockchain-watcher/config/mainnet.json index c348a163..65002fc5 100644 --- a/blockchain-watcher/config/mainnet.json +++ b/blockchain-watcher/config/mainnet.json @@ -12,7 +12,6 @@ "rpcs": [ "https://api.securerpc.com/v1", "https://rpc.mevblocker.io/noreverts", - "https://endpoints.omniatech.io/v1/eth/mainnet/public", "https://ethereum.publicnode.com" ] }, @@ -38,13 +37,7 @@ "polygon": { "network": "mainnet", "chainId": 5, - "rpcs": [ - "https://rpc-mainnet.matic.quiknode.pro", - "https://polygon-rpc.com", - "https://rpc-mainnet.maticvigil.com", - "https://endpoints.omniatech.io/v1/matic/mainnet/public", - "https://polygon-bor.publicnode.com" - ] + "rpcs": ["https://rpc-mainnet.matic.quiknode.pro", "https://polygon-rpc.com"] }, "avalanche": { "network": "mainnet", @@ -137,11 +130,7 @@ "arbitrum": { "network": "mainnet", "chainId": 23, - "rpcs": [ - "https://endpoints.omniatech.io/v1/arbitrum/one/public", - "https://arbitrum.blockpi.network/v1/rpc/public", - "https://arb1.arbitrum.io/rpc" - ] + "rpcs": ["https://arbitrum.blockpi.network/v1/rpc/public", "https://arb1.arbitrum.io/rpc"] }, "optimism": { "network": "mainnet", diff --git a/blockchain-watcher/src/common/wormchain.ts b/blockchain-watcher/src/common/wormchain.ts index 4bd4d58c..8cc0bf08 100644 --- a/blockchain-watcher/src/common/wormchain.ts +++ b/blockchain-watcher/src/common/wormchain.ts @@ -5,6 +5,6 @@ const chains: Map = new Map([ [4002, "kujira"], ]); -export function mapChain(chainId: number) { +export function mapChain(chainId: number): string { return chains.get(chainId) || "wormchain"; } diff --git a/blockchain-watcher/src/domain/actions/wormchain/GetWormchainLogs.ts b/blockchain-watcher/src/domain/actions/wormchain/GetWormchainLogs.ts index 4bb31181..e523899a 100644 --- a/blockchain-watcher/src/domain/actions/wormchain/GetWormchainLogs.ts +++ b/blockchain-watcher/src/domain/actions/wormchain/GetWormchainLogs.ts @@ -15,7 +15,7 @@ export class GetWormchainLogs { async execute( range: Range, - opts: { addresses: string[]; chainId: number } + opts: { addresses: string[]; chain: string } ): Promise { const fromBlock = range.fromBlock; const toBlock = range.toBlock; @@ -34,7 +34,7 @@ export class GetWormchainLogs { for (let blockNumber = fromBlock; blockNumber <= toBlock; blockNumber++) { const wormchainLogs = await this.blockRepo.getBlockLogs( - opts.chainId, + opts.chain, blockNumber, ATTRIBUTES_TYPES ); diff --git a/blockchain-watcher/src/domain/actions/wormchain/GetWormchainRedeems.ts b/blockchain-watcher/src/domain/actions/wormchain/GetWormchainRedeems.ts index 1560345c..78f0a413 100644 --- a/blockchain-watcher/src/domain/actions/wormchain/GetWormchainRedeems.ts +++ b/blockchain-watcher/src/domain/actions/wormchain/GetWormchainRedeems.ts @@ -15,7 +15,7 @@ export class GetWormchainRedeems { async execute( range: Range, - opts: { addresses: string[]; chainId: number } + opts: { addresses: string[]; chain: string } ): Promise { let fromBlock = range.fromBlock; let toBlock = range.toBlock; @@ -35,7 +35,7 @@ export class GetWormchainRedeems { for (let blockNumber = fromBlock; blockNumber <= toBlock; blockNumber++) { const wormchainLogs = await this.blockRepo.getBlockLogs( - opts.chainId, + opts.chain, blockNumber, ATTRIBUTES_TYPES ); diff --git a/blockchain-watcher/src/domain/actions/wormchain/PollWormchain.ts b/blockchain-watcher/src/domain/actions/wormchain/PollWormchain.ts index 16a1d1bb..fb6898c8 100644 --- a/blockchain-watcher/src/domain/actions/wormchain/PollWormchain.ts +++ b/blockchain-watcher/src/domain/actions/wormchain/PollWormchain.ts @@ -56,7 +56,7 @@ export class PollWormchain extends RunPollingJob { } protected async get(): Promise { - this.latestBlockHeight = await this.blockRepo.getBlockHeight(this.cfg.chainId); + this.latestBlockHeight = await this.blockRepo.getBlockHeight(this.cfg.chain); if (!this.latestBlockHeight) { throw new Error(`Could not obtain latest block height: ${this.latestBlockHeight}`); @@ -66,7 +66,7 @@ export class PollWormchain extends RunPollingJob { const records = await this.getWormchain.execute(range, { addresses: this.cfg.addresses, - chainId: this.cfg.chainId, + chain: this.cfg.chain, }); this.lastRange = range; diff --git a/blockchain-watcher/src/domain/repositories.ts b/blockchain-watcher/src/domain/repositories.ts index 5456f2c0..e0d4d6b7 100644 --- a/blockchain-watcher/src/domain/repositories.ts +++ b/blockchain-watcher/src/domain/repositories.ts @@ -85,9 +85,9 @@ export interface AptosRepository { } export interface WormchainRepository { - getBlockHeight(chainId: number): Promise; + getBlockHeight(chain: string): Promise; getBlockLogs( - chainId: number, + chain: string, blockNumber: bigint, attributesTypes: string[] ): Promise; diff --git a/blockchain-watcher/src/infrastructure/repositories/RepositoriesBuilder.ts b/blockchain-watcher/src/infrastructure/repositories/RepositoriesBuilder.ts index 05bd4ae9..dda3d537 100644 --- a/blockchain-watcher/src/infrastructure/repositories/RepositoriesBuilder.ts +++ b/blockchain-watcher/src/infrastructure/repositories/RepositoriesBuilder.ts @@ -92,6 +92,7 @@ export class RepositoriesBuilder { private build(): void { this.snsClient = this.createSnsClient(); this.repositories.set("sns", new SnsEventRepository(this.snsClient, this.cfg.sns)); + this.cfg.influx && this.repositories.set( "infux", @@ -103,18 +104,23 @@ export class RepositoriesBuilder { this.cfg.influx ) ); + this.cfg.metadata?.dir && this.repositories.set("metadata", new FileMetadataRepository(this.cfg.metadata.dir)); this.repositories.set("metrics", new PromStatRepository()); + const pools = this.createAllProvidersPool(); + this.cfg.enabledPlatforms.forEach((chain) => { - this.buildWormchainRepository(chain); + // Set up all providers because we use various chains + this.buildWormchainRepository(chain, pools); + this.buildCosmosRepository(chain, pools); + this.buildEvmRepository(chain, pools); + // Set up the specific providers for the chain this.buildAlgorandRepository(chain); this.buildSolanaRepository(chain); - this.buildCosmosRepository(chain); this.buildAptosRepository(chain); - this.buildEvmRepository(chain); this.buildSuiRepository(chain); }); @@ -226,9 +232,8 @@ export class RepositoriesBuilder { } } - private buildEvmRepository(chain: string): void { + private buildEvmRepository(chain: string, pools: ProviderPoolMap): void { if (chain == EVM_CHAIN) { - const pools = this.createAllProvidersPool(); const repoCfg: JsonRPCBlockRepositoryCfg = { chains: this.cfg.chains, environment: this.cfg.environment, @@ -286,9 +291,8 @@ export class RepositoriesBuilder { } } - private buildCosmosRepository(chain: string): void { + private buildCosmosRepository(chain: string, pools: ProviderPoolMap): void { if (chain == COSMOS_CHAIN) { - const pools = this.createAllProvidersPool(); const repoCfg: JsonRPCBlockRepositoryCfg = { chains: this.cfg.chains, environment: this.cfg.environment, @@ -302,24 +306,15 @@ export class RepositoriesBuilder { } } - private buildWormchainRepository(chain: string): void { + private buildWormchainRepository(chain: string, pools: ProviderPoolMap): void { if (chain == WORMCHAIN_CHAIN) { - const injectivePools = this.createDefaultProviderPools("injective"); - const wormchainPools = this.createDefaultProviderPools("wormchain"); - const osmosisPools = this.createDefaultProviderPools("osmosis"); - const kujiraPools = this.createDefaultProviderPools("kujira"); - const evmosPools = this.createDefaultProviderPools("evmos"); - - const cosmosPools: Map> = new Map([ - [19, injectivePools], - [20, osmosisPools], - [3104, wormchainPools], - [4001, evmosPools], - [4002, kujiraPools], - ]); + const repoCfg: JsonRPCBlockRepositoryCfg = { + chains: this.cfg.chains, + environment: this.cfg.environment, + }; const wormchainRepository = new RateLimitedWormchainJsonRPCBlockRepository( - new WormchainJsonRPCBlockRepository(cosmosPools) + new WormchainJsonRPCBlockRepository(repoCfg, pools) ); this.repositories.set("wormchain-repo", wormchainRepository); diff --git a/blockchain-watcher/src/infrastructure/repositories/wormchain/RateLimitedWormchainJsonRPCBlockRepository.ts b/blockchain-watcher/src/infrastructure/repositories/wormchain/RateLimitedWormchainJsonRPCBlockRepository.ts index ed9fc5d7..2d3dbfe0 100644 --- a/blockchain-watcher/src/infrastructure/repositories/wormchain/RateLimitedWormchainJsonRPCBlockRepository.ts +++ b/blockchain-watcher/src/infrastructure/repositories/wormchain/RateLimitedWormchainJsonRPCBlockRepository.ts @@ -17,17 +17,17 @@ export class RateLimitedWormchainJsonRPCBlockRepository this.logger = winston.child({ module: "RateLimitedWormchainJsonRPCBlockRepository" }); } - getBlockHeight(chainId: number): Promise { - return this.breaker.fn(() => this.delegate.getBlockHeight(chainId)).execute(); + getBlockHeight(chain: string): Promise { + return this.breaker.fn(() => this.delegate.getBlockHeight(chain)).execute(); } getBlockLogs( - chainId: number, + chain: string, blockNumber: bigint, attributesTypes: string[] ): Promise { return this.breaker - .fn(() => this.delegate.getBlockLogs(chainId, blockNumber, attributesTypes)) + .fn(() => this.delegate.getBlockLogs(chain, blockNumber, attributesTypes)) .execute(); } diff --git a/blockchain-watcher/src/infrastructure/repositories/wormchain/WormchainJsonRPCBlockRepository.ts b/blockchain-watcher/src/infrastructure/repositories/wormchain/WormchainJsonRPCBlockRepository.ts index f84b1d9a..5a45e75b 100644 --- a/blockchain-watcher/src/infrastructure/repositories/wormchain/WormchainJsonRPCBlockRepository.ts +++ b/blockchain-watcher/src/infrastructure/repositories/wormchain/WormchainJsonRPCBlockRepository.ts @@ -1,8 +1,8 @@ -import { divideIntoBatches, hexToHash } from "../common/utils"; -import { InstrumentedHttpProvider } from "../../rpc/http/InstrumentedHttpProvider"; +import { divideIntoBatches, getChainProvider, hexToHash } from "../common/utils"; +import { ProviderPoolMap, JsonRPCBlockRepositoryCfg } from "../RepositoriesBuilder"; import { WormchainRepository } from "../../../domain/repositories"; -import { ProviderPool } from "@xlabs/rpc-pool"; import { setTimeout } from "timers/promises"; +import { mapChain } from "../../../common/wormchain"; import winston from "winston"; import { WormchainTransaction, @@ -19,25 +19,21 @@ let BLOCK_ENDPOINT = "/block"; const GROW_SLEEP_TIME = 350; const MAX_ATTEMPTS = 20; -type ProviderPoolMap = ProviderPool; - export class WormchainJsonRPCBlockRepository implements WormchainRepository { private readonly logger: winston.Logger; - protected cosmosPools: Map; + protected pool: ProviderPoolMap; + protected cfg: JsonRPCBlockRepositoryCfg; - constructor(cosmosPools: Map) { + constructor(cfg: JsonRPCBlockRepositoryCfg, pool: ProviderPoolMap) { this.logger = winston.child({ module: "WormchainJsonRPCBlockRepository" }); - this.cosmosPools = cosmosPools; + this.pool = pool; + this.cfg = cfg; } - async getBlockHeight(chainId: number): Promise { + async getBlockHeight(chain: string): Promise { try { let results: ResultBlockHeight; - - results = await this.cosmosPools - .get(chainId)! - .get() - .get(BLOCK_HEIGHT_ENDPOINT); + results = await getChainProvider(chain, this.pool).get(BLOCK_HEIGHT_ENDPOINT); if ( results && @@ -56,7 +52,7 @@ export class WormchainJsonRPCBlockRepository implements WormchainRepository { } async getBlockLogs( - chainId: number, + chain: string, blockNumber: bigint, attributesTypes: string[] ): Promise { @@ -65,10 +61,10 @@ export class WormchainJsonRPCBlockRepository implements WormchainRepository { let resultsBlock: ResultBlock; // Set up cosmos client - const cosmosClient = this.cosmosPools.get(chainId)!; + const cosmosClient = getChainProvider(chain, this.pool); // Get wormchain block data - resultsBlock = await cosmosClient.get().get(blockEndpoint); + resultsBlock = await cosmosClient.get(blockEndpoint); const txs = resultsBlock.result.block.data.txs; if (!txs || txs.length === 0) { @@ -90,9 +86,9 @@ export class WormchainJsonRPCBlockRepository implements WormchainRepository { const txEndpoint = `${TRANSACTION_ENDPOINT}?hash=0x${hash}`; // Get wormchain transactions data - const resultTransaction: ResultTransaction = await cosmosClient - .get() - .get(txEndpoint); + const resultTransaction: ResultTransaction = await cosmosClient.get< + typeof resultTransaction + >(txEndpoint); if ( resultTransaction && @@ -144,14 +140,8 @@ export class WormchainJsonRPCBlockRepository implements WormchainRepository { async getRedeems(ibcTransaction: IbcTransaction): Promise { try { // Set up cosmos client - const cosmosClient = this.cosmosPools.get(ibcTransaction.targetChain); - - if (!cosmosClient) { - this.logger.warn( - `[wormchain] No cosmos client found for chain ${ibcTransaction.targetChain}` - ); - return []; - } + const chain = mapChain(ibcTransaction.targetChain); + const cosmosClient = getChainProvider(chain, this.pool); let resultTransactionSearch: ResultTransactionSearch | undefined; let isIBCTransferFinalized = false; @@ -170,11 +160,9 @@ export class WormchainJsonRPCBlockRepository implements WormchainRepository { await this.sleep(sleepTime); // Get cosmos transactions data - resultTransactionSearch = await cosmosClient - .get() - .get( - `${TRANSACTION_SEARCH_ENDPOINT}?query=${query}&prove=false&page=1&per_page=1` - ); + resultTransactionSearch = await cosmosClient.get( + `${TRANSACTION_SEARCH_ENDPOINT}?query=${query}&prove=false&page=1&per_page=1` + ); if ( resultTransactionSearch && diff --git a/blockchain-watcher/test/domain/actions/wormchain/GetWormchainLogs.test.ts b/blockchain-watcher/test/domain/actions/wormchain/GetWormchainLogs.test.ts index 8a21e775..92e2bc8f 100644 --- a/blockchain-watcher/test/domain/actions/wormchain/GetWormchainLogs.test.ts +++ b/blockchain-watcher/test/domain/actions/wormchain/GetWormchainLogs.test.ts @@ -64,7 +64,7 @@ describe("GetWormchainLogs", () => { // Then await thenWaitForAssertion(() => - expect(getBlockLogsSpy).toBeCalledWith(3104, 7606614n, ["wasm"]) + expect(getBlockLogsSpy).toBeCalledWith("wormchain", 7606614n, ["wasm"]) ); }); @@ -123,7 +123,7 @@ describe("GetWormchainLogs", () => { // Then await thenWaitForAssertion(() => - expect(getBlockLogsSpy).toBeCalledWith(3104, 7606615n, ["wasm"]) + expect(getBlockLogsSpy).toBeCalledWith("wormchain", 7606615n, ["wasm"]) ); }); }); diff --git a/blockchain-watcher/test/domain/actions/wormchain/GetWormchainRedeems.test.ts b/blockchain-watcher/test/domain/actions/wormchain/GetWormchainRedeems.test.ts index 21418d27..aa3fc225 100644 --- a/blockchain-watcher/test/domain/actions/wormchain/GetWormchainRedeems.test.ts +++ b/blockchain-watcher/test/domain/actions/wormchain/GetWormchainRedeems.test.ts @@ -64,7 +64,7 @@ describe("GetWormchainRedeems", () => { // Then await thenWaitForAssertion(() => - expect(getBlockLogsSpy).toBeCalledWith(3104, 8418529n, ["wasm", "send_packet"]) + expect(getBlockLogsSpy).toBeCalledWith("wormchain", 8418529n, ["wasm", "send_packet"]) ); }); @@ -174,7 +174,7 @@ describe("GetWormchainRedeems", () => { // Then await thenWaitForAssertion(() => - expect(getBlockLogsSpy).toBeCalledWith(3104, 7606615n, ["wasm", "send_packet"]) + expect(getBlockLogsSpy).toBeCalledWith("wormchain", 7606615n, ["wasm", "send_packet"]) ); }); }); diff --git a/blockchain-watcher/test/domain/actions/wormchain/PollWormchain.test.ts b/blockchain-watcher/test/domain/actions/wormchain/PollWormchain.test.ts index 93de4ade..170dd8fc 100644 --- a/blockchain-watcher/test/domain/actions/wormchain/PollWormchain.test.ts +++ b/blockchain-watcher/test/domain/actions/wormchain/PollWormchain.test.ts @@ -93,7 +93,7 @@ describe("PollWormchain", () => { await thenWaitForAssertion( () => expect(getBlockHeightSpy).toHaveReturnedTimes(1), - () => expect(getBlockLogsSpy).toHaveBeenCalledWith(3104, currentHeight, ["wasm"]) + () => expect(getBlockLogsSpy).toHaveBeenCalledWith("wormchain", currentHeight, ["wasm"]) ); }); diff --git a/blockchain-watcher/test/infrastructure/repositories/WormchainJsonRPCBlockRepository.test.ts b/blockchain-watcher/test/infrastructure/repositories/WormchainJsonRPCBlockRepository.test.ts index 85217941..e22d5042 100644 --- a/blockchain-watcher/test/infrastructure/repositories/WormchainJsonRPCBlockRepository.test.ts +++ b/blockchain-watcher/test/infrastructure/repositories/WormchainJsonRPCBlockRepository.test.ts @@ -12,22 +12,14 @@ const rpc = "http://localhost"; let repo: WormchainJsonRPCBlockRepository; -// Mock pools -const cosmosPools: Map = new Map([ - [19, () => new InstrumentedHttpProvider({ url: rpc, chain: "injective" })], - [3104, { get: () => new InstrumentedHttpProvider({ url: rpc, chain: "wormchain" }) } as any], - [4001, { get: () => new InstrumentedHttpProvider({ url: rpc, chain: "evmos" }) } as any], - [4002, () => new InstrumentedHttpProvider({ url: rpc, chain: "kujira" })], -]); - describe("WormchainJsonRPCBlockRepository", () => { describe("getBlockHeight", () => { it("should be able to get block height", async () => { const expectedHeight = 9187752n; - givenARepo(cosmosPools); + givenARepo(); givenBlockHeightIs(); - const result = await repo.getBlockHeight(3104); + const result = await repo.getBlockHeight("wormchain"); expect(result).toBe(expectedHeight); }); @@ -35,23 +27,23 @@ describe("WormchainJsonRPCBlockRepository", () => { describe("getBlockLogs", () => { it("should not process the block because does not have transactions", async () => { - givenARepo(cosmosPools); + givenARepo(); givenBlockLogs([]); - const result = await repo.getBlockLogs(3104, 8453618n, ["wasm", "send_packet"]); + const result = await repo.getBlockLogs("wormchain", 8453618n, ["wasm", "send_packet"]); expect(result.transactions).toEqual([]); expect(result.blockHeight).toEqual(8453618n); }); it("should process the block because have one transaction", async () => { - givenARepo(cosmosPools); + givenARepo(); givenBlockLogs([ "CrYICrMICiQvY29zbXdhc20ud2FzbS52MS5Nc2dFeGVjdXRlQ29udHJhY3QSiggKL3dvcm1ob2xlMTV6ZGFhbjhzN2x0MHgyd2p0d2tsdXowMHB0cGx1a3BqcnZuOGtoEkN3b3JtaG9sZTE0aGoydGF2cThmcGVzZHd4eGN1NDRydHkza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iwyOCw1MCwxMDIsMTYsMTcsMTQ2LDIyNSwxNjMsMjAyLDQxLDg3LDI1MCwyMTYsNjgsNTYsMjYsMTYwLDMxLDgwLDgyLDIyMCw3MCw2NCwxNjgsMjU0LDEwMCwzOCw5Nyw1OSwyMzUsMTg0LDEyNiwyMDgsMTYsMjIxLDcyLDEyNSw5Myw5OCwxOTcsMTUyLDE4MSwwXX19fRJaClIKRgofL2Nvc21vcy5jcnlwdG8uc2VjcDI1NmsxLlB1YktleRIjCiECTNU10MWVzKLoEbR3KVeQzNN0RcrBOuz+X/R+8hcjr00SBAoCCAEYhtcEEgQQgIl6GkC6wWnfEe2JArWPIpcypfQ+AhCamp6n+hga87jh07agcAJVuCXS3EgxAc0xdb1y+2TMuapNPwjVDyKctycFVtGn", ]); givenOneTransaction(); - const result = await repo.getBlockLogs(3104, 8453618n, ["wasm", "send_packet"]); + const result = await repo.getBlockLogs("wormchain", 8453618n, ["wasm", "send_packet"]); expect(result).toEqual({ transactions: [ @@ -145,14 +137,14 @@ describe("WormchainJsonRPCBlockRepository", () => { }); it("should process the block because have more than one transaction", async () => { - givenARepo(cosmosPools); + givenARepo(); givenBlockLogs([ "CrYICrMICiQvY29zbXdhc20ud2FzbS52MS5Nc2dFeGVjdXRlQ29udHJhY3QSiggKL3dvcm1ob2xlMXJtZXJteDZ0ZDZwcHI3eDIzeThtYTc1NjRuYXV6d203bnVrOWUwEkN3b3JtaG9sZTE0aGoydGF2cThmcGVzZHd4eGN1NDRydHkzaGg5MHZodWpydmNtc3RsNHpyM3R4bWZ2dzlzcnJnNDY1GpEHeyJzdWJtaXRfb2JzZXJ2YXRpb25zIjp7Im9ic2VydmF0aW9ucyI6Ilczc2lkSGhmYUdGemFDSTZJa1o1WW5wbGRHNTVhVTVRZGpZNVJucEtUR05sTUVoV2JGUlVSV0pTWm5Wa1ZUaDJZVWd6UlRaS04yczlJaXdpZEdsdFpYTjBZVzF3SWpveE56RTFOelV4TlRNMExDSnViMjVqWlNJNk5UW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QnpZVlJLT1ZWWVZtODFha05RU0doNlV5OVRjM0pRVGxNdlFVSTBRVUZCUVVGQlFVRkJRVUZCUVVGQlFVRkJRVUZCUVVGQlFVRkJRVUZCUVVGQlFVRkJRVUZCUVVGQlFUMDlJbjFkIiwiZ3VhcmRpYW5fc2V0X2luZGV4Ijo0LCJzaWduYXR1cmUiOnsiaW5kZXgiOjE2LCJzaWduYXR1cmUiOls1NCw5OCwxOTcsMTQyLDEyMSwxNTQsMTI4LDIsMTQ2LDExLDEzNSwxMDMsMTIxLDk1LDE4NSwxOTUsODcsMjAwLDExNCwyMjEsMjIsNCwyMzIsMTQsNCwyMTQsMTUyLDEyNiwxNjMsMjUyLDEyMCwxNzMsMTExLDI0Nyw5NiwyNyw1MSw1NCwxMyw3MSwyMjYsMTQyLDY5LDExLDc0LDc4LDM5LDIyNywzNyw3MSw1Miw2NiwyMjUsMjA4LDIxMSwxNzEsMjA1LDIyNyw0OSwxNzksMTM3LDE5MywxNjQsMTA4LDFdfX19EloKUgpGCh8vY29zbW9zLmNyeXB0by5zZWNwMjU2azEuUHViS2V5EiMKIQPnPs02nEn7crSxHqFZ7k3b8rPU0hWuOjTvlwrU/UIvwRIECgIIARi77XQSBBCAiXoaQK57xFZmOQFdmdkoHKhlYzyoEfBIaYrzqRUBIliUIRW+Nj9faFWJleYBl4WcLeEj5AB2b7iZZGoD2s7dA10aPlE=", ]); givenTwoTransaction(); - const result = await repo.getBlockLogs(3104, 8453618n, ["wasm", "send_packet"]); + const result = await repo.getBlockLogs("wormchain", 8453618n, ["wasm", "send_packet"]); expect(result).toEqual({ transactions: [ @@ -441,29 +433,65 @@ describe("WormchainJsonRPCBlockRepository", () => { sender: "osmo17zr4md042hn5h84h4ycpk8eq8mwt2rgfp8nug5", }; - it("should not be able to get redeems because do not find the cosmos client", async () => { - givenARepo(cosmosPools); - givenBlockHeightIs(); - - osmosisRedeem.targetChain = 20; - const result = await repo.getRedeems(osmosisRedeem); - - expect(result).toEqual([]); - }); - it("should be able to get the redeems and map the information from cosmos transaction", async () => { - givenARepo(cosmosPools); + givenARepo(); givenOneTransactionByQuery(); const result = await repo.getRedeems(osmosisRedeem); - expect(result).toEqual([]); + expect(result.length).toEqual(1); + expect(result[0].chainId).toEqual(4001); + expect(result[0].hash).toEqual( + "1B099AAD307B55CED63DCE877961BF8AB04B0A2E13FFC7EEF7AAC1293AC069A6" + ); + expect(result[0].height).toEqual(19255525n); + expect(result[0].blockTimestamp).toEqual(1715751595401); + }); + + it("should not be able to get redeems because do not find the cosmos client", async () => { + givenARepo(); + givenBlockHeightIs(); + + try { + osmosisRedeem.targetChain = 20; + await repo.getRedeems(osmosisRedeem); + } catch (e) { + expect(e).toBeInstanceOf(Error); + } }); }); }); -const givenARepo = (cosmosPools: any = undefined) => { - repo = new WormchainJsonRPCBlockRepository(cosmosPools); +const givenARepo = () => { + repo = new WormchainJsonRPCBlockRepository( + { + chains: { + injective: { + rpcs: [rpc], + timeout: 100, + name: "injective", + network: "mainnet", + chainId: 19, + }, + wormchain: { + rpcs: [rpc], + timeout: 100, + name: "wormchain", + network: "mainnet", + chainId: 3104, + }, + evmos: { rpcs: [rpc], timeout: 100, name: "evmos", network: "mainnet", chainId: 4001 }, + kujira: { rpcs: [rpc], timeout: 100, name: "kujira", network: "mainnet", chainId: 4002 }, + }, + environment: "mainnet", + }, + { + injective: { get: () => new InstrumentedHttpProvider({ url: rpc, chain: "injective" }) }, + wormchain: { get: () => new InstrumentedHttpProvider({ url: rpc, chain: "wormchain" }) }, + evmos: { get: () => new InstrumentedHttpProvider({ url: rpc, chain: "evmos" }) }, + kujira: { get: () => new InstrumentedHttpProvider({ url: rpc, chain: "kujira" }) }, + } as any + ); }; const givenBlockHeightIs = () => {