/ packages / cli / shopGen.ts
shopGen.ts
 1  import { numberToHex } from "viem";
 2  import { faker } from "@faker-js/faker";
 3  import {
 4    createTestBlockchainClient,
 5    createTestRelayClient,
 6  } from "@massmarket/client/test";
 7  import { MemStore } from "@massmarket/store/mem";
 8  import { Listing, ListingMetadata } from "@massmarket/schema";
 9  import StateManager from "@massmarket/stateManager";
10  
11  const blockchainClient = createTestBlockchainClient();
12  const relayClient = await createTestRelayClient(blockchainClient);
13  
14  console.log("creating shop", numberToHex(relayClient.shopId));
15  
16  const root = new Map(Object.entries({
17    Tags: new Map(),
18    Orders: new Map(),
19    Accounts: new Map(),
20    Inventory: new Map(),
21    Listings: new Map(),
22    Manifest: new Map(),
23    SchemeVersion: 1,
24  }));
25  
26  const store = new MemStore();
27  const sm = new StateManager({
28    store,
29    id: relayClient.shopId,
30    defaultState: root,
31  });
32  
33  await sm.open();
34  
35  sm.addConnection(relayClient);
36  
37  const writes = [];
38  for (let i = 1; i < 100; i++) {
39    writes.push(
40      sm.set(
41        ["Listings", i],
42        new Listing(
43          i,
44          faker.number.bigInt(),
45          new ListingMetadata(
46            faker.commerce.productName(),
47            faker.commerce.productDescription(),
48            [faker.image.urlPicsumPhotos()],
49          ),
50          1,
51        ),
52      ),
53    );
54  }
55  
56  await Promise.all(writes);
57  
58  sm.close();