Skip to content

Commit

Permalink
Merge pull request #1126 from trilitech/fix-network-migration-in-addr…
Browse files Browse the repository at this point in the history
…ess-book

Fix fetching networks on contacts migration
  • Loading branch information
asiia-trilitech authored Apr 16, 2024
2 parents 794f68e + f058324 commit c6e0ff4
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/utils/multisig/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ describe("multisig fetch", () => {
in: ["pkh1,pkh2,pkh3"],
},
select: { fields: ["address"] },
limit: 3,
},
{ baseUrl: network.tzktApiUrl }
);
Expand Down
1 change: 1 addition & 0 deletions src/utils/multisig/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const getExistingContracts = (pkhs: RawPkh[], network: Network): Promise<
{
address: { in: [pkhs.join(",")] },
select: { fields: ["address"] },
limit: Math.min(10000, pkhs.length),
},
{
baseUrl: network.tzktApiUrl,
Expand Down
16 changes: 16 additions & 0 deletions src/utils/multisig/helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ describe("multisig helpers", () => {
in: ["pkh1,pkh2,pkh3"],
},
select: { fields: ["address"] },
limit: 3,
},
{ baseUrl: MAINNET.tzktApiUrl }
);
Expand All @@ -127,6 +128,7 @@ describe("multisig helpers", () => {
in: ["pkh1,pkh2,pkh3"],
},
select: { fields: ["address"] },
limit: 3,
},
{ baseUrl: GHOSTNET.tzktApiUrl }
);
Expand All @@ -151,5 +153,19 @@ describe("multisig helpers", () => {
])
);
});

it("returns empty map for empty contracts list", async () => {
mockedContractsGet.mockImplementation((...args) => {
if (args[1].baseUrl === MAINNET.tzktApiUrl) {
return Promise.resolve(["pkh1", "pkh3", "pkh4"] as any);
} else {
return Promise.resolve(["pkh2", "pkh5"] as any);
}
});

const result = await getNetworksForContracts([MAINNET, GHOSTNET], []);

expect(result).toEqual(new Map());
});
});
});
5 changes: 4 additions & 1 deletion src/utils/multisig/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export const getNetworksForContracts = async (
): Promise<Map<RawPkh, string>> => {
const result = new Map<RawPkh, string>();

if (contractPkhs.length === 0) {
return result;
}

const accountsWithNetwork = await Promise.all(
availableNetworks.map(async network =>
(await getExistingContracts(contractPkhs, network)).map(contractPkh => [
Expand All @@ -58,7 +62,6 @@ export const getNetworksForContracts = async (
)
);
accountsWithNetwork.flat().forEach(([pkh, network]) => result.set(pkh, network));

return result;
};

Expand Down
1 change: 1 addition & 0 deletions src/utils/redux/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,5 @@ export const accountsMigrations = {
});
}),
5: identity,
6: identity,
} as any;

1 comment on commit c6e0ff4

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report

St.
Category Percentage Covered / Total
🟢 Statements 86.64% 3146/3631
🟡 Branches 79.32% 1089/1373
🟢 Functions 85.37% 992/1162
🟢 Lines 86.39% 2977/3446

Test suite run success

1376 tests passing in 172 suites.

Report generated by 🧪jest coverage report action from c6e0ff4

Please sign in to comment.