import * as State from 'tevm/State';
import * as fs from 'fs/promises';
// Load storage from JSON
async function loadStorage(filePath: string): Promise<Map<BrandedStorageKey, bigint>> {
const data = await fs.readFile(filePath, 'utf-8');
const entries = JSON.parse(data);
const storage = new Map<BrandedStorageKey, bigint>();
for (const entry of entries) {
const key = State.StorageKey(entry.key);
const value = BigInt(entry.value);
storage.set(key, value);
}
return storage;
}
// storage.json:
// [
// { "key": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48:0", "value": "1000" },
// { "key": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48:1", "value": "2000" }
// ]
const storage = await loadStorage('./storage.json');
console.log(storage.size); // 2