Skip to content

Commit

Permalink
feat: configurable dummy price
Browse files Browse the repository at this point in the history
  • Loading branch information
0xnigir1 committed Aug 29, 2024
1 parent e977641 commit 5834cd0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
5 changes: 4 additions & 1 deletion packages/pricing/src/providers/dummy.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import { IPricingProvider, PriceResponse } from "../internal.js";
* This provider returns a fixed price of 1 for each token address.
*/
export class DummyPricingProvider implements IPricingProvider {
constructor(private readonly dummyPrice: number | undefined = undefined) {}
async getTokenPrices(addresses: Address[]): Promise<PriceResponse> {
return Promise.resolve(Object.fromEntries(addresses.map((address) => [address, 1])));
return Promise.resolve(
Object.fromEntries(addresses.map((address) => [address, this.dummyPrice])),
);
}
}
25 changes: 18 additions & 7 deletions packages/pricing/test/unit/services/dummy.provider.spec.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
import { beforeEach, describe, expect, it } from "vitest";
import { describe, expect, it } from "vitest";

import { Address } from "@zkchainhub/shared";

import { DummyPricingProvider } from "../../../src/providers/dummy.provider.js";

describe("DummyPricingProvider", () => {
let provider: DummyPricingProvider;
it("return undefined for all token prices", async () => {
const provider = new DummyPricingProvider();

beforeEach(() => {
provider = new DummyPricingProvider();
const addresses: Address[] = ["0x123456789", "0xabcdef123"];
const expectedResponse = {
"0x123456789": undefined,
"0xabcdef123": undefined,
};

const response = await provider.getTokenPrices(addresses);

expect(response).toEqual(expectedResponse);
});

it("return 1 for all token prices", async () => {
it("return number for all token prices", async () => {
const price = 1;
const provider = new DummyPricingProvider(price);

const addresses: Address[] = ["0x123456789", "0xabcdef123"];
const expectedResponse = {
"0x123456789": 1,
"0xabcdef123": 1,
"0x123456789": price,
"0xabcdef123": price,
};

const response = await provider.getTokenPrices(addresses);
Expand Down

0 comments on commit 5834cd0

Please sign in to comment.