Fix tests
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
||||
createStorageAdapter,
|
||||
State,
|
||||
StorageType,
|
||||
UnspentOutputStatus,
|
||||
type UnspentOutputData,
|
||||
} from "@xo-cash/state";
|
||||
import { InMemoryBlockchainProvider } from "@xo-cash/engine";
|
||||
@@ -13,6 +14,8 @@ import { binToHex, sha256 } from "@bitauth/libauth";
|
||||
import { AppService } from "../../../src/services/app";
|
||||
import { InMemoryStorage } from "../../../src/services/storage";
|
||||
import { MockElectrumService } from "./electrum-service";
|
||||
import { MockRatesService } from "./rates-service";
|
||||
import { RatesService } from "../../../src/services/rates";
|
||||
|
||||
export const DEFAULT_SEED =
|
||||
"page pencil stock planet limb cluster assault speak off joke private pioneer";
|
||||
@@ -57,11 +60,11 @@ export const randomTxHash = (): string => {
|
||||
* @returns The created UnspentOutputData object.
|
||||
*/
|
||||
export const addFakeResource = async (
|
||||
engine: Engine,
|
||||
state: State,
|
||||
options: FakeResourceOptions = {},
|
||||
): Promise<UnspentOutputData> => {
|
||||
const resource: UnspentOutputData = {
|
||||
status: "confirmed",
|
||||
status: UnspentOutputStatus.CONFIRMED,
|
||||
selectable: true,
|
||||
privacy: false,
|
||||
templateIdentifier: options.templateIdentifier ?? "test-template",
|
||||
@@ -76,7 +79,7 @@ export const addFakeResource = async (
|
||||
reservedBy: options.reservedBy,
|
||||
};
|
||||
|
||||
await engine.state.storeUnspentOutputData(resource);
|
||||
await state.storeUnspentOutputData(resource);
|
||||
return resource;
|
||||
};
|
||||
|
||||
@@ -88,12 +91,12 @@ export const addFakeResource = async (
|
||||
* @param invitationIdentifier - The invitation identifier to reserve for.
|
||||
*/
|
||||
export const reserveResource = async (
|
||||
engine: Engine,
|
||||
state: State,
|
||||
outpointTransactionHash: string,
|
||||
outpointIndex: number,
|
||||
invitationIdentifier: string,
|
||||
): Promise<void> => {
|
||||
await engine.state.executeBulkUnspentOutputReservation(
|
||||
await state.executeBulkUnspentOutputReservation(
|
||||
[{ outpointTransactionHash, outpointIndex }],
|
||||
true,
|
||||
invitationIdentifier,
|
||||
@@ -108,12 +111,12 @@ export const reserveResource = async (
|
||||
* @param invitationIdentifier - The invitation identifier to unreserve from.
|
||||
*/
|
||||
export const unreserveResource = async (
|
||||
engine: Engine,
|
||||
state: State,
|
||||
outpointTransactionHash: string,
|
||||
outpointIndex: number,
|
||||
invitationIdentifier: string,
|
||||
): Promise<void> => {
|
||||
await engine.state.executeBulkUnspentOutputReservation(
|
||||
await state.executeBulkUnspentOutputReservation(
|
||||
[{ outpointTransactionHash, outpointIndex }],
|
||||
false,
|
||||
invitationIdentifier,
|
||||
@@ -153,13 +156,14 @@ export const createMockEngine = async (seed: string) => {
|
||||
const engine = new Engine(seed, state, blockchainMonitor, blockchainProvider);
|
||||
await engine.initializeStateSync();
|
||||
|
||||
return engine;
|
||||
return { engine, state, blockchainMonitor, blockchainProvider };
|
||||
};
|
||||
|
||||
export const createMockAppService = async (engine: Engine) => {
|
||||
const storage = await InMemoryStorage.create();
|
||||
|
||||
const electrum = new MockElectrumService();
|
||||
const mockRates = new MockRatesService();
|
||||
const rates = new RatesService(mockRates);
|
||||
|
||||
const config = {
|
||||
syncServerUrl: "http://localhost:3000",
|
||||
@@ -170,5 +174,5 @@ export const createMockAppService = async (engine: Engine) => {
|
||||
invitationStoragePath: "test-invitations.db",
|
||||
};
|
||||
|
||||
return new AppService(engine, storage, config, electrum);
|
||||
return new AppService(engine, storage, config, rates);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user