import { readFileSync , writeFileSync } from "fs" ; import { resolve } from "path" ; import { StringHashMap } from "./types" ; const LOCAL_STORAGE_FILE = resolve ( __dirname , "../chrome-profile/greenboard-local-storage.json" ) ; /**
 * This class is used to pick up state from the Metamask extension's
 * Local Storage and transfer it to the next test. Useful for
 * testing Node state for returning users.
 */ export default class StateCollector { /**
     * Contains a key/value map, mimicking LocalStorage's data structure.
     */ private data : StringHashMap = { } ; param key param value public set ( key , value ) { this . data [ key ] = value ; } param key public get ( key ) { return this . data [ key ] ; } param data public write ( data ) { this . data = data ; writeFileSync ( LOCAL_STORAGE_FILE , JSON . stringify ( this . data ) ) ; } public read ( ) { this . data = JSON . parse ( readFileSync ( LOCAL_STORAGE_FILE ) . toString ( ) ) ; return this . data ; } }