The tests work
This commit is contained in:
@@ -10,7 +10,7 @@ import {
|
||||
UnspentOutputStatus,
|
||||
type UnspentOutputData,
|
||||
} from "@xo-cash/state";
|
||||
import { InMemoryBlockchainProvider } from "@xo-cash/engine";
|
||||
import { InMemoryBlockchainProvider } from "../../../src/utils/blockchain/in-memory-blockchain-provider.js";
|
||||
import { convertMnemonicToSeedBytes } from "@xo-cash/crypto";
|
||||
|
||||
import { binToHex, sha256 } from "@bitauth/libauth";
|
||||
@@ -20,6 +20,7 @@ import { MockElectrumService } from "./electrum-service";
|
||||
import { MockRatesService } from "./rates-service";
|
||||
import { RatesService } from "../../../src/services/rates";
|
||||
import { SettingsService } from "../../../src/services/settings";
|
||||
import { mkdirSync } from "node:fs";
|
||||
|
||||
export const DEFAULT_SEED =
|
||||
"oven crop same above under tower promote decrease vocal pretty require slow";
|
||||
@@ -68,6 +69,7 @@ export const addFakeResource = async (
|
||||
options: FakeResourceOptions = {},
|
||||
): Promise<UnspentOutputData> => {
|
||||
const resource: UnspentOutputData = {
|
||||
templateIdentifier: options.templateIdentifier ?? "test-template",
|
||||
status: UnspentOutputStatus.CONFIRMED,
|
||||
selectable: true,
|
||||
privacy: false,
|
||||
@@ -131,10 +133,16 @@ export const unreserveResource = async (
|
||||
* @returns A mock engine instance.
|
||||
*/
|
||||
export const createMockEngine = async (seed: string) => {
|
||||
const randomId = Math.random().toString(36).substring(2, 15);
|
||||
const stateDir = `${tmpdir()}/test-data-${randomId}`;
|
||||
mkdirSync(stateDir, { recursive: true });
|
||||
|
||||
// Create the in-memory storage adapter.
|
||||
const storage = await createStorageAdapter({
|
||||
storageType: "inmemory",
|
||||
storageType: StorageType.INDEXEDDB,
|
||||
accountHash: binToHex(sha256.hash(convertMnemonicToSeedBytes(seed))),
|
||||
databasePath: stateDir,
|
||||
databaseFilename: `xo-wallet-${randomId}.db`,
|
||||
});
|
||||
|
||||
// Initialize the storage adapter.
|
||||
@@ -152,13 +160,17 @@ export const createMockEngine = async (seed: string) => {
|
||||
await blockchainMonitor.initializeEventListeners();
|
||||
|
||||
// Create the engine instance.
|
||||
const engine = new Engine(seed, state, blockchainMonitor, blockchainProvider);
|
||||
const engine = new Engine(seed, state, blockchainProvider, blockchainMonitor);
|
||||
await engine.initializeStateSync();
|
||||
|
||||
return { engine, state, blockchainMonitor, blockchainProvider };
|
||||
};
|
||||
|
||||
export const createMockAppService = async (engine: Engine) => {
|
||||
export const createMockAppService = async (engine: Engine, state: State) => {
|
||||
if (!state) {
|
||||
throw new Error("State is required");
|
||||
}
|
||||
|
||||
const settings = new SettingsService(
|
||||
`${tmpdir()}/xo-cli-tests-settings.json`,
|
||||
);
|
||||
@@ -187,6 +199,7 @@ export const createMockAppService = async (engine: Engine) => {
|
||||
mockElectrum,
|
||||
rates,
|
||||
settings,
|
||||
state,
|
||||
new Uint8Array(32).fill(1),
|
||||
);
|
||||
};
|
||||
|
||||
+1395
-1444
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user