testFixtures.ts
1 import { Listing, Order } from "@massmarket/schema"; 2 import { extractEntriesFromHAMT, fetchAndDecode } from "@massmarket/utils"; 3 import type { CodecValue } from "@massmarket/utils/codec"; 4 5 type TestVector = Map< 6 string, 7 Array<Map<string, Map<string, Map<string, Map<string, CodecValue>>>>> 8 >; 9 10 const manifestVector = await fetchAndDecode("ManifestOkay") as TestVector; 11 export const allManifests = manifestVector.get("Snapshots")?.map((snapshot) => { 12 return snapshot!.get("After")!.get("Value")!.get("Manifest"); 13 }) || []; 14 15 const listingVector = await fetchAndDecode("ShopOkay") as TestVector; 16 const listingsMap = new Map<number, Listing>(); 17 listingVector.get("Snapshots")?.forEach((snapshot) => { 18 const listingsHamt = extractEntriesFromHAMT( 19 snapshot!.get("After")!.get("Value")!.get("Listings"), 20 ); 21 if (!listingsHamt) throw new Error("No listings found"); 22 if (!(listingsHamt instanceof Map)) { 23 throw new Error("Listings HAMT is not a Map"); 24 } 25 for (const [_key, listingMap] of listingsHamt.entries()) { 26 if (Number(_key) > 2 ** 32) { // TODO: fix ID type number | bigint 27 continue; 28 } 29 listingsMap.set(Number(_key), Listing.fromCBOR(listingMap)); 30 } 31 }); 32 const ordersVector = await fetchAndDecode("OrderOkay") as TestVector; 33 const ordersMap = new Map<number, Order>(); 34 const orderListingsMap = new Map<number, Listing>(); 35 ordersVector.get("Snapshots")?.forEach((snapshot) => { 36 const ordersHamt = extractEntriesFromHAMT( 37 snapshot!.get("After")!.get("Value")!.get("Orders"), 38 ); 39 if (!ordersHamt) throw new Error("No orders found"); 40 if (!(ordersHamt instanceof Map)) throw new Error("Orders HAMT is not a Map"); 41 const listingsHamt = extractEntriesFromHAMT( 42 snapshot!.get("After")!.get("Value")!.get("Listings"), 43 ); 44 45 for (const [_key, orderMap] of ordersHamt.entries()) { 46 ordersMap.set(Number(_key), Order.fromCBOR(orderMap)); 47 } 48 if (!listingsHamt) throw new Error("No listings found"); 49 if (!(listingsHamt instanceof Map)) { 50 throw new Error("Listings HAMT is not a Map"); 51 } 52 for (const [_key, listingMap] of listingsHamt.entries()) { 53 if (Number(_key) > 2 ** 32) { // TODO: fix ID type number | bigint 54 continue; 55 } 56 orderListingsMap.set(Number(_key), Listing.fromCBOR(listingMap)); 57 } 58 }); 59 export const allOrders = ordersMap; 60 export const allOrderListings = orderListingsMap; 61 export const allListings = listingsMap;