Skip to content

Commit

Permalink
fix tests and ignore failed transfers if already executed;
Browse files Browse the repository at this point in the history
Signed-off-by: tcar <[email protected]>
  • Loading branch information
tcar121293 committed Dec 19, 2024
1 parent 93637b7 commit 5971038
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 229 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ services:
restart: always
environment:
DATABASE_URL: mongodb://mongo1:30001/sygmaprotocol-explorer-indexer?replicaSet=my-replica-set&authSource=admin&retryWrites=true&w=majority
SHARED_CONFIG_URL: https://ipfs.io/ipfs/QmW9RhxFFotHtvsU2PMVYU2NNZigeCpbg1ywDCZ3vX675b
SHARED_CONFIG_URL: https://ipfs.io/ipfs/bafkreiasnla2ya55of6nwm3swjstip4q2ixfa3t6tvixyibclfovxnerte
RPC_URL_CONFIG: '[{"id": 1, "endpoint": "http://evm1:8545"}, {"id": 2, "endpoint": "http://evm2:8545"}, {"id": 3, "endpoint": "ws://substrate-pallet:9944"}]'
RETRY_COUNT: '1'
BACKOFF: '100'
Expand Down
3 changes: 3 additions & 0 deletions src/indexer/utils/evm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,9 @@ export async function saveFailedHandlerExecutionLogs(
executionRepository: ExecutionRepository,
): Promise<void> {
let transfer = await transferRepository.findTransfer(error.depositNonce, Number(error.domainId), toDomainId)
if (transfer?.status == TransferStatus.executed) {
return
}
if (!transfer) {
transfer = await transferRepository.insertFailedTransfer(error, toDomainId)
} else {
Expand Down
3 changes: 3 additions & 0 deletions src/indexer/utils/substrate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ export async function saveFailedHandlerExecution(
const numDepositNonce = Number(depositNonce.replace(/,/g, ""))

let transfer = await transferRepository.findTransfer(numDepositNonce, Number(originDomainId), toDomainId)
if (transfer?.status == TransferStatus.executed) {
return
}
// there is no transfer yet, but a proposal execution exists
if (!transfer) {
transfer = await transferRepository.insertFailedTransfer(
Expand Down
42 changes: 21 additions & 21 deletions tests/e2e/domainAndResourceRoute.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe("Get all transfers for a specific resource between source and destinati
before(async () => {
let transfers = 0
let isProcessing = false
while (transfers !== 35 || isProcessing) {
while (transfers !== 31 || isProcessing) {
const res: { data: Array<TransferResponse> } = await axios.get("http://localhost:8000/api/transfers?page=1&limit=100")

transfers = res.data.length
Expand Down Expand Up @@ -75,7 +75,7 @@ describe("Get all transfers for a specific resource between source and destinati
fromDomainId: 1,
toDomainId: 2,
destination: "0x8e0a907331554af72563bd8d43051c2e64be5d35",
amount: "2296080355773541392",
amount: "2935717020161974584",
status: "executed",
accountId: "0x5C1F5961696BaD2e73f73417f07EF55C62a2dC5b",
message: "",
Expand All @@ -90,22 +90,22 @@ describe("Get all transfers for a specific resource between source and destinati
id: transfers[0].fee.id,
transferId: transfers[0].id,
decimals: 18,
amount: "1000000000000000",
amount: "100000000000000",
tokenAddress: "0x0000000000000000000000000000000000000000",
tokenSymbol: "eth",
},
deposit: {
txHash: "0x7b7c2be6b60c25a1be9f506fdd75e1aab76d3016f0bc708715405f2e6718c6df",
blockNumber: "591",
txHash: "0x12327002087fe09d30a4bd45e97e55549d92dbf05d254788591dc2b6bca4ef0f",
blockNumber: "130",
depositData:
"0x0000000000000000000000000000000000000000000000001fdd50eb1da26c1000000000000000000000000000000000000000000000000000000000000000148e0a907331554af72563bd8d43051c2e64be5d35000000000000000000000000000000000000000000000000000000000000000c6d657461646174612e75726c",
"0x00000000000000000000000000000000000000000000000028bdc31363d2a13800000000000000000000000000000000000000000000000000000000000000148e0a907331554af72563bd8d43051c2e64be5d35000000000000000000000000000000000000000000000000000000000000000c6d657461646174612e75726c",
handlerResponse: "0x6d657461646174612e746573746d657461646174612e75726c",
timestamp: "2023-07-17T08:31:22.000Z",
timestamp: "2024-11-14T08:17:11.000Z",
},
execution: {
txHash: "0x3de2201e548a8332aaa50147a2fb02e2b6669184f042b4dbcf23b4f5d40edcfb",
blockNumber: "598",
timestamp: "2023-07-17T08:31:35.000Z",
txHash: "0x43c02a7cee493621c550e059489db14500b5a388185d61deeb7d9a7f52959e8d",
blockNumber: "138",
timestamp: "2024-11-14T08:17:31.000Z",
},
account: { addressStatus: "" },
},
Expand All @@ -124,11 +124,11 @@ describe("Get all transfers for a specific resource between source and destinati
expect(transfers).to.be.deep.equal([
{
id: transfers[0].id,
depositNonce: 29,
depositNonce: 28,
resourceID: "0x0000000000000000000000000000000000000000000000000000000000000500",
fromDomainId: 1,
toDomainId: 2,
destination: "0xb1387b365ae7294ea13bad9db83436e671dd16ba",
destination: "0xa2451c8553371e754f5e93a440adcca1c0dcf395",
amount: "",
status: "executed",
accountId: "0x5C1F5961696BaD2e73f73417f07EF55C62a2dC5b",
Expand All @@ -141,25 +141,25 @@ describe("Get all transfers for a specific resource between source and destinati
toDomain: { name: "evm2", lastIndexedBlock: transfers[0].toDomain.lastIndexedBlock, id: 2 },
fromDomain: { name: "Ethereum 1", lastIndexedBlock: transfers[0].fromDomain.lastIndexedBlock, id: 1 },
fee: {
amount: "1000000000000000",
amount: "100000000000000",
id: transfers[0].fee.id,
decimals: 18,
tokenAddress: "0x0000000000000000000000000000000000000000",
tokenSymbol: "eth",
transferId: transfers[0].id,
},
deposit: {
txHash: "0x18fa527a4773789a5ba487dae5bc3d00cc04dc50509b6f67e438efdb60e75c67",
blockNumber: "623",
txHash: "0x2b355542a454d8faedccc75c8741ef0d2f531ea4cd8ed53544734ff681377699",
blockNumber: "155",
depositData:
"0x0000000000000000000000000000000000000000000000000000000000030d400004ea287d1514b1387b365ae7294ea13bad9db83436e671dd16ba145c1f5961696bad2e73f73417f07ef55c62a2dc5b47ed248f568cc8f9fe4371a1d1fab88a62af595f8efb9aeff6f0e043b7ea33b10000000000000000000000005c1f5961696bad2e73f73417f07ef55c62a2dc5b",
"0x00000000000000000000000000000000000000000000000000000000000927c00004ea287d1514a2451c8553371e754f5e93a440adcca1c0dcf395145c1f5961696bad2e73f73417f07ef55c62a2dc5b35353436383833363939383137363233353732000000000000000000000000000000000000000000000000005c1f5961696bad2e73f73417f07ef55c62a2dc5b",
handlerResponse: "0x",
timestamp: "2023-07-17T08:32:27.000Z",
timestamp: "2024-11-14T08:18:03.000Z",
},
execution: {
txHash: "0xcc7c318cfd71745c27111772f21dec553f53277c9dc218fe07b54f897560c0cb",
blockNumber: "631",
timestamp: "2023-07-17T08:32:42.000Z",
txHash: "0x508195d23128b60c20a577eca7ace567e6ec68f636bad42ddb554b7d96644dd3",
blockNumber: "162",
timestamp: "2024-11-14T08:18:20.000Z",
},
account: { addressStatus: "" },
},
Expand All @@ -173,7 +173,7 @@ describe("Get all transfers for a specific resource between source and destinati
const transfers = res.data as Array<TransferResponse>

expect(res.status).to.be.deep.equal(200)
expect(transfers.length).to.be.deep.equal(3)
expect(transfers.length).to.be.deep.equal(1)

for (const transfer of transfers) {
expect(transfer.resourceID).to.be.deep.equal(ERC20LRTEST_RESOURCE_ID)
Expand Down
12 changes: 6 additions & 6 deletions tests/e2e/domainRoute.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe("Get all transfers with a specific domain as source or destination", fu
before(async () => {
let transfers = 0
let isProcessing = false
while (transfers !== 35 || isProcessing) {
while (transfers !== 31 || isProcessing) {
const res: { data: Array<TransferResponse> } = await axios.get("http://localhost:8000/api/transfers?page=1&limit=100")

transfers = res.data.length
Expand All @@ -42,7 +42,7 @@ describe("Get all transfers with a specific domain as source or destination", fu
const transfers = res.data as Array<TransferResponse>

expect(res.status).to.be.deep.equal(200)
expect(transfers.length).to.be.deep.equal(32)
expect(transfers.length).to.be.deep.equal(30)

for (const transfer of transfers) {
expect(transfer.fromDomainId).to.be.deep.equal(parseInt(DOMAIN_1))
Expand All @@ -54,7 +54,7 @@ describe("Get all transfers with a specific domain as source or destination", fu
const transfers = res.data as Array<TransferResponse>

expect(res.status).to.be.deep.equal(200)
expect(transfers.length).to.be.deep.equal(32)
expect(transfers.length).to.be.deep.equal(30)

for (const transfer of transfers) {
expect(transfer.fromDomainId).to.be.deep.equal(parseInt(DOMAIN_1))
Expand All @@ -76,7 +76,7 @@ describe("Get all transfers with a specific domain as source or destination", fu
const transfers = res.data as Array<TransferResponse>

expect(res.status).to.be.deep.equal(200)
expect(transfers.length).to.be.deep.equal(3)
expect(transfers.length).to.be.deep.equal(1)

for (const transfer of transfers) {
expect(transfer.toDomainId).to.be.deep.equal(parseInt(DOMAIN_1))
Expand All @@ -88,7 +88,7 @@ describe("Get all transfers with a specific domain as source or destination", fu
const transfers = res.data as Array<TransferResponse>

expect(res.status).to.be.deep.equal(200)
expect(transfers.length).to.be.deep.equal(30)
expect(transfers.length).to.be.deep.equal(29)

for (const transfer of transfers) {
expect(transfer.toDomainId).to.be.deep.equal(parseInt(DOMAIN_2))
Expand All @@ -100,7 +100,7 @@ describe("Get all transfers with a specific domain as source or destination", fu
const transfers = res.data as Array<TransferResponse>

expect(res.status).to.be.deep.equal(200)
expect(transfers.length).to.be.deep.equal(3)
expect(transfers.length).to.be.deep.equal(1)

for (const transfer of transfers) {
expect(transfer.fromDomainId).to.be.deep.equal(parseInt(DOMAIN_3))
Expand Down
Loading

0 comments on commit 5971038

Please sign in to comment.