UNPKG

@metamask/snaps-simulation

Version:

A simulation framework for MetaMask Snaps, enabling headless testing of Snaps in a controlled environment

1 lines 6.53 kB
{"version":3,"file":"options.cjs","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":";;;AACA,uDAU+B;AAC/B,2CAIyB;AAEzB,+CAMqB;AAErB,MAAM,uBAAuB,GAAG,IAAA,oBAAM,EAAC;IACrC,OAAO,EAAE,IAAA,oBAAM,GAAE;IACjB,EAAE,EAAE,IAAA,oBAAM,GAAE;IACZ,MAAM,EAAE,IAAA,mBAAK,EAAC,yBAAiB,CAAC;IAChC,QAAQ,EAAE,IAAA,uBAAS,EAAC,IAAA,sBAAQ,EAAC,IAAA,qBAAO,GAAE,CAAC,EAAE,KAAK,CAAC;IAC/C,KAAK,EAAE,IAAA,uBAAS,EAAC,IAAA,sBAAQ,EAAC,IAAA,qBAAO,GAAE,CAAC,EAAE,KAAK,CAAC;IAC5C,MAAM,EAAE,IAAA,uBAAS,EAAC,IAAA,sBAAQ,EAAC,IAAA,mBAAK,EAAC,2BAAmB,CAAC,CAAC,EAAE,EAAE,CAAC;CAC5D,CAAC,CAAC;AAIH,MAAM,qBAAqB,GAAG,IAAA,oBAAM,EAAC;IACnC,IAAI,EAAE,IAAA,oBAAM,GAAE;IACd,MAAM,EAAE,IAAA,oBAAM,GAAE;CACjB,CAAC,CAAC;AAIH,MAAM,uBAAuB,GAAG,IAAA,oBAAM,EAAC;IACrC,QAAQ,EAAE,IAAA,uBAAS,EAAC,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC,EAAE,4BAAgB,CAAC;IACzD,oBAAoB,EAAE,IAAA,uBAAS,EAAC,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC,EAAE,uBAAW,CAAC;IAChE,MAAM,EAAE,IAAA,uBAAS,EAAC,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC,EAAE,0BAAc,CAAC;IACrD,KAAK,EAAE,IAAA,uBAAS,E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O,GAAE,CAAC,EAAE,IAAI,CAAC;IACrD,sBAAsB,EAAE,IAAA,uBAAS,EAAC,IAAA,sBAAQ,EAAC,IAAA,qBAAO,GAAE,CAAC,EAAE,IAAI,CAAC;IAC5D,YAAY,EAAE,IAAA,uBAAS,EAAC,IAAA,sBAAQ,EAAC,IAAA,qBAAO,GAAE,CAAC,EAAE,IAAI,CAAC;CACnD,CAAC,CAAC;AAmCH;;;;;;GAMG;AACH,SAAgB,UAAU,CAAC,OAA8B;IACvD,OAAO,IAAA,oBAAM,EACX,OAAO,EACP,uBAAuB,CACW,CAAC;AACvC,CAAC;AALD,gCAKC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport {\n array,\n boolean,\n create,\n defaulted,\n nullable,\n object,\n optional,\n record,\n string,\n} from '@metamask/superstruct';\nimport {\n CaipAssetTypeStruct,\n CaipChainIdStruct,\n JsonStruct,\n} from '@metamask/utils';\n\nimport {\n DEFAULT_ACCOUNTS,\n DEFAULT_ASSETS,\n DEFAULT_CURRENCY,\n DEFAULT_LOCALE,\n DEFAULT_SRP,\n} from './constants';\n\nconst SimulationAccountStruct = object({\n address: string(),\n id: string(),\n scopes: array(CaipChainIdStruct),\n selected: defaulted(optional(boolean()), false),\n owned: defaulted(optional(boolean()), false),\n assets: defaulted(optional(array(CaipAssetTypeStruct)), []),\n});\n\nexport type SimulationAccount = Infer<typeof SimulationAccountStruct>;\n\nconst SimulationAssetStruct = object({\n name: string(),\n symbol: string(),\n});\n\nexport type SimulationAsset = Infer<typeof SimulationAssetStruct>;\n\nconst SimulationOptionsStruct = object({\n currency: defaulted(optional(string()), DEFAULT_CURRENCY),\n secretRecoveryPhrase: defaulted(optional(string()), DEFAULT_SRP),\n locale: defaulted(optional(string()), DEFAULT_LOCALE),\n state: defaulted(optional(nullable(record(string(), JsonStruct))), null),\n unencryptedState: defaulted(\n optional(nullable(record(string(), JsonStruct))),\n null,\n ),\n accounts: defaulted(\n optional(array(SimulationAccountStruct)),\n DEFAULT_ACCOUNTS,\n ),\n assets: defaulted(\n optional(record(CaipAssetTypeStruct, SimulationAssetStruct)),\n DEFAULT_ASSETS,\n ),\n hideBalances: defaulted(optional(boolean()), false),\n useSecurityAlerts: defaulted(optional(boolean()), true),\n simulateOnChainActions: defaulted(optional(boolean()), true),\n useTokenDetection: defaulted(optional(boolean()), true),\n batchCheckBalances: defaulted(optional(boolean()), true),\n displayNftMedia: defaulted(optional(boolean()), true),\n useNftDetection: defaulted(optional(boolean()), true),\n useExternalPricingData: defaulted(optional(boolean()), true),\n showTestnets: defaulted(optional(boolean()), true),\n});\n\n/**\n * Options for the simulation.\n *\n * @property currency - The currency to use. Defaults to `usd`.\n * @property secretRecoveryPhrase - The secret recovery phrase to use. This is\n * used to derive addresses and private keys. Defaults to a test recovery\n * phrase.\n * @property locale - The locale to use. Defaults to `en`.\n * @property state - The initial state of the Snap, if any. Defaults to `null`.\n * @property unencryptedState - The initial unencrypted state of the Snap, if\n * any. Defaults to `null`.\n * @property accounts - The accounts to use in the simulation, if any. Defaults\n * to an empty array.\n * @property assets - The assets to use in the simulation, if any. Defaults to\n * an empty object.\n * @property useSecurityAlerts - Whether to run transactions and signatures through security providers.\n * @property simulateOnChainActions - Whether to simulate transactions and signatures.\n * @property useTokenDetection - Whether to auto-detect tokens.\n * @property batchCheckBalances - Whether to fetch balances in an aggregated manner.\n * @property displayNftMedia - Whether to display NFT media.\n * @property useNftDetection - Whether to auto-detect NFTs.\n * @property useExternalPricingData - Whether to get token price data from an external source.\n * @property showTestnets - Whether to show testnets.\n */\nexport type SimulationUserOptions = Infer<typeof SimulationOptionsStruct>;\n\n/**\n * Options for the simulation, with defaults filled in.\n *\n * See {@link SimulationUserOptions} for documentation.\n */\nexport type SimulationOptions = Required<SimulationUserOptions>;\n\n/**\n * Get the options for the simulation.\n *\n * @param options - The user options. Any options not specified will be filled\n * in with default values.\n * @returns The simulation options.\n */\nexport function getOptions(options: SimulationUserOptions): SimulationOptions {\n return create(\n options,\n SimulationOptionsStruct,\n ) as Required<SimulationUserOptions>;\n}\n"]}