Skip to content

Instantly share code, notes, and snippets.

@tms1337
Created December 1, 2020 04:08
Show Gist options
  • Select an option

  • Save tms1337/a391665661f357aca6a62e9e4d8b0275 to your computer and use it in GitHub Desktop.

Select an option

Save tms1337/a391665661f357aca6a62e9e4d8b0275 to your computer and use it in GitHub Desktop.
// function
import createFilterTransactions from "../functions/filterTransactions";
// fake services
import { createFakeGetAddresses } from "../services/argent/getAddresses";
import { createFakeGetTransactionsForBlock } from "../services/eth/getTransactionsForBlock";
describe("filterTransactions", () => {
it("correctly filters transactions", async (done) => {
const transactions = [
{ txHash: "0x1", from: "0x1234", to: "0x123", value: "0x1" },
{ txHash: "0x2", from: "0x1234", to: "0x123", value: "0x2" },
{ txHash: "0x3", from: "0x1234", to: "0x122", value: "0x3" },
{ txHash: "0x4", from: "0x1234", to: "0x122", value: "0x4" },
];
const getTransactionsForBlock = createFakeGetTransactionsForBlock({
transactions,
});
const argentAddresses = ["0x123"];
const getAddresses = createFakeGetAddresses({
addressess: argentAddresses,
});
const filterTransactions = createFilterTransactions({
getTransactionsForBlock,
getAddresses,
});
const result = await filterTransactions({ blockNumber: 123 });
const expectedOutput = [
{ txHash: "0x1", from: "0x1234", to: "0x123", value: "0x1" },
{ txHash: "0x2", from: "0x1234", to: "0x123", value: "0x2" },
];
expect(expectedOutput).toEqual(result);
done();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment