@ledgerhq/context-module 1.12.0 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/package.json +1 -1
- package/lib/cjs/src/ContextModuleBuilder.js +1 -1
- package/lib/cjs/src/ContextModuleBuilder.js.map +3 -3
- package/lib/cjs/src/ContextModuleBuilder.test.js +1 -1
- package/lib/cjs/src/ContextModuleBuilder.test.js.map +3 -3
- package/lib/cjs/src/DefaultContextModule.test.js +1 -1
- package/lib/cjs/src/DefaultContextModule.test.js.map +3 -3
- package/lib/cjs/src/calldata/domain/CalldataContextLoader.js +1 -1
- package/lib/cjs/src/calldata/domain/CalldataContextLoader.js.map +3 -3
- package/lib/cjs/src/calldata/domain/CalldataContextLoader.test.js +1 -1
- package/lib/cjs/src/calldata/domain/CalldataContextLoader.test.js.map +3 -3
- package/lib/cjs/src/config/model/ContextModuleBuildArgs.js.map +1 -1
- package/lib/cjs/src/config/model/ContextModuleConfig.js +1 -1
- package/lib/cjs/src/config/model/ContextModuleConfig.js.map +1 -1
- package/lib/cjs/src/di.js +1 -1
- package/lib/cjs/src/di.js.map +2 -2
- package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.js +1 -1
- package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.js.map +3 -3
- package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js +1 -1
- package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js.map +3 -3
- package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.js +1 -1
- package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.js.map +3 -3
- package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.test.js +1 -1
- package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.test.js.map +3 -3
- package/lib/cjs/src/nft/domain/NftContextLoader.js +1 -1
- package/lib/cjs/src/nft/domain/NftContextLoader.js.map +3 -3
- package/lib/cjs/src/nft/domain/NftContextLoader.test.js +1 -1
- package/lib/cjs/src/nft/domain/NftContextLoader.test.js.map +3 -3
- package/lib/cjs/src/solana/domain/DefaultSolanaContextLoader.js.map +1 -1
- package/lib/cjs/src/solana/domain/DefaultSolanaContextLoader.test.js +1 -1
- package/lib/cjs/src/solana/domain/DefaultSolanaContextLoader.test.js.map +3 -3
- package/lib/cjs/src/solanaLifi/domain/SolanaLifiContextLoader.test.js +1 -1
- package/lib/cjs/src/solanaLifi/domain/SolanaLifiContextLoader.test.js.map +3 -3
- package/lib/cjs/src/solanaToken/domain/SolanaTokenContextLoader.test.js +1 -1
- package/lib/cjs/src/solanaToken/domain/SolanaTokenContextLoader.test.js.map +3 -3
- package/lib/cjs/src/token/domain/TokenContextLoader.js +1 -1
- package/lib/cjs/src/token/domain/TokenContextLoader.js.map +3 -3
- package/lib/cjs/src/token/domain/TokenContextLoader.test.js +1 -1
- package/lib/cjs/src/token/domain/TokenContextLoader.test.js.map +3 -3
- package/lib/cjs/src/transaction-check/domain/TransactionCheckContextLoader.js +1 -1
- package/lib/cjs/src/transaction-check/domain/TransactionCheckContextLoader.js.map +3 -3
- package/lib/cjs/src/transaction-check/domain/TransactionCheckContextLoader.test.js +1 -1
- package/lib/cjs/src/transaction-check/domain/TransactionCheckContextLoader.test.js.map +3 -3
- package/lib/cjs/src/transaction-check/domain/TypedDataCheckContextLoader.js +1 -1
- package/lib/cjs/src/transaction-check/domain/TypedDataCheckContextLoader.js.map +3 -3
- package/lib/cjs/src/transaction-check/domain/TypedDataCheckContextLoader.test.js +1 -1
- package/lib/cjs/src/transaction-check/domain/TypedDataCheckContextLoader.test.js.map +3 -3
- package/lib/cjs/src/trusted-name/di/trustedNameModuleFactory.js +1 -1
- package/lib/cjs/src/trusted-name/di/trustedNameModuleFactory.js.map +3 -3
- package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.js +1 -1
- package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.js.map +3 -3
- package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.test.js +1 -1
- package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.test.js.map +3 -3
- package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.js +1 -1
- package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.js.map +3 -3
- package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.test.js +1 -1
- package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.test.js.map +3 -3
- package/lib/cjs/src/uniswap/domain/UniswapContextLoader.js +1 -1
- package/lib/cjs/src/uniswap/domain/UniswapContextLoader.js.map +3 -3
- package/lib/cjs/src/uniswap/domain/UniswapContextLoader.test.js +1 -1
- package/lib/cjs/src/uniswap/domain/UniswapContextLoader.test.js.map +3 -3
- package/lib/esm/package.json +1 -1
- package/lib/esm/src/ContextModuleBuilder.js +1 -1
- package/lib/esm/src/ContextModuleBuilder.js.map +3 -3
- package/lib/esm/src/ContextModuleBuilder.test.js +1 -1
- package/lib/esm/src/ContextModuleBuilder.test.js.map +3 -3
- package/lib/esm/src/DefaultContextModule.test.js +1 -1
- package/lib/esm/src/DefaultContextModule.test.js.map +3 -3
- package/lib/esm/src/calldata/domain/CalldataContextLoader.js +1 -1
- package/lib/esm/src/calldata/domain/CalldataContextLoader.js.map +3 -3
- package/lib/esm/src/calldata/domain/CalldataContextLoader.test.js +1 -1
- package/lib/esm/src/calldata/domain/CalldataContextLoader.test.js.map +3 -3
- package/lib/esm/src/di.js +1 -1
- package/lib/esm/src/di.js.map +2 -2
- package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.js +1 -1
- package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.js.map +3 -3
- package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js +1 -1
- package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js.map +3 -3
- package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.js +1 -1
- package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.js.map +3 -3
- package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.test.js +1 -1
- package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.test.js.map +3 -3
- package/lib/esm/src/nft/domain/NftContextLoader.js +1 -1
- package/lib/esm/src/nft/domain/NftContextLoader.js.map +3 -3
- package/lib/esm/src/nft/domain/NftContextLoader.test.js +1 -1
- package/lib/esm/src/nft/domain/NftContextLoader.test.js.map +3 -3
- package/lib/esm/src/solana/domain/DefaultSolanaContextLoader.js.map +1 -1
- package/lib/esm/src/solana/domain/DefaultSolanaContextLoader.test.js +1 -1
- package/lib/esm/src/solana/domain/DefaultSolanaContextLoader.test.js.map +3 -3
- package/lib/esm/src/solanaLifi/domain/SolanaLifiContextLoader.test.js +1 -1
- package/lib/esm/src/solanaLifi/domain/SolanaLifiContextLoader.test.js.map +3 -3
- package/lib/esm/src/solanaToken/domain/SolanaTokenContextLoader.test.js +1 -1
- package/lib/esm/src/solanaToken/domain/SolanaTokenContextLoader.test.js.map +3 -3
- package/lib/esm/src/token/domain/TokenContextLoader.js +1 -1
- package/lib/esm/src/token/domain/TokenContextLoader.js.map +3 -3
- package/lib/esm/src/token/domain/TokenContextLoader.test.js +1 -1
- package/lib/esm/src/token/domain/TokenContextLoader.test.js.map +3 -3
- package/lib/esm/src/transaction-check/domain/TransactionCheckContextLoader.js +1 -1
- package/lib/esm/src/transaction-check/domain/TransactionCheckContextLoader.js.map +3 -3
- package/lib/esm/src/transaction-check/domain/TransactionCheckContextLoader.test.js +1 -1
- package/lib/esm/src/transaction-check/domain/TransactionCheckContextLoader.test.js.map +3 -3
- package/lib/esm/src/transaction-check/domain/TypedDataCheckContextLoader.js +1 -1
- package/lib/esm/src/transaction-check/domain/TypedDataCheckContextLoader.js.map +3 -3
- package/lib/esm/src/transaction-check/domain/TypedDataCheckContextLoader.test.js +1 -1
- package/lib/esm/src/transaction-check/domain/TypedDataCheckContextLoader.test.js.map +3 -3
- package/lib/esm/src/trusted-name/di/trustedNameModuleFactory.js +1 -1
- package/lib/esm/src/trusted-name/di/trustedNameModuleFactory.js.map +3 -3
- package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.js +1 -1
- package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.js.map +3 -3
- package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.test.js +1 -1
- package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.test.js.map +3 -3
- package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.js +1 -1
- package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.js.map +3 -3
- package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.test.js +1 -1
- package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.test.js.map +3 -3
- package/lib/esm/src/uniswap/domain/UniswapContextLoader.js +1 -1
- package/lib/esm/src/uniswap/domain/UniswapContextLoader.js.map +3 -3
- package/lib/esm/src/uniswap/domain/UniswapContextLoader.test.js +1 -1
- package/lib/esm/src/uniswap/domain/UniswapContextLoader.test.js.map +3 -3
- package/lib/types/src/ContextModuleBuilder.d.ts +10 -3
- package/lib/types/src/ContextModuleBuilder.d.ts.map +1 -1
- package/lib/types/src/calldata/domain/CalldataContextLoader.d.ts +3 -2
- package/lib/types/src/calldata/domain/CalldataContextLoader.d.ts.map +1 -1
- package/lib/types/src/config/model/ContextModuleBuildArgs.d.ts +1 -1
- package/lib/types/src/config/model/ContextModuleBuildArgs.d.ts.map +1 -1
- package/lib/types/src/config/model/ContextModuleConfig.d.ts +2 -0
- package/lib/types/src/config/model/ContextModuleConfig.d.ts.map +1 -1
- package/lib/types/src/di.d.ts.map +1 -1
- package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.d.ts +3 -2
- package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.d.ts.map +1 -1
- package/lib/types/src/external-plugin/domain/ExternalPluginContextLoader.d.ts +3 -2
- package/lib/types/src/external-plugin/domain/ExternalPluginContextLoader.d.ts.map +1 -1
- package/lib/types/src/nft/domain/NftContextLoader.d.ts +3 -2
- package/lib/types/src/nft/domain/NftContextLoader.d.ts.map +1 -1
- package/lib/types/src/token/domain/TokenContextLoader.d.ts +3 -2
- package/lib/types/src/token/domain/TokenContextLoader.d.ts.map +1 -1
- package/lib/types/src/transaction-check/domain/TransactionCheckContextLoader.d.ts +3 -2
- package/lib/types/src/transaction-check/domain/TransactionCheckContextLoader.d.ts.map +1 -1
- package/lib/types/src/transaction-check/domain/TypedDataCheckContextLoader.d.ts +3 -2
- package/lib/types/src/transaction-check/domain/TypedDataCheckContextLoader.d.ts.map +1 -1
- package/lib/types/src/trusted-name/di/trustedNameModuleFactory.d.ts +2 -1
- package/lib/types/src/trusted-name/di/trustedNameModuleFactory.d.ts.map +1 -1
- package/lib/types/src/trusted-name/domain/TrustedNameContextLoader.d.ts +3 -2
- package/lib/types/src/trusted-name/domain/TrustedNameContextLoader.d.ts.map +1 -1
- package/lib/types/src/typed-data/domain/DefaultTypedDataContextLoader.d.ts +3 -1
- package/lib/types/src/typed-data/domain/DefaultTypedDataContextLoader.d.ts.map +1 -1
- package/lib/types/src/uniswap/domain/UniswapContextLoader.d.ts +3 -2
- package/lib/types/src/uniswap/domain/UniswapContextLoader.d.ts.map +1 -1
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/lib/cjs/src/shared/utils/NullLoggerPublisherService.js +0 -2
- package/lib/cjs/src/shared/utils/NullLoggerPublisherService.js.map +0 -7
- package/lib/cjs/src/shared/utils/NullLoggerPublisherService.test.js +0 -2
- package/lib/cjs/src/shared/utils/NullLoggerPublisherService.test.js.map +0 -7
- package/lib/esm/src/shared/utils/NullLoggerPublisherService.js +0 -2
- package/lib/esm/src/shared/utils/NullLoggerPublisherService.js.map +0 -7
- package/lib/esm/src/shared/utils/NullLoggerPublisherService.test.js +0 -2
- package/lib/esm/src/shared/utils/NullLoggerPublisherService.test.js.map +0 -7
- package/lib/types/src/shared/utils/NullLoggerPublisherService.d.ts +0 -3
- package/lib/types/src/shared/utils/NullLoggerPublisherService.d.ts.map +0 -1
- package/lib/types/src/shared/utils/NullLoggerPublisherService.test.d.ts +0 -2
- package/lib/types/src/shared/utils/NullLoggerPublisherService.test.d.ts.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/uniswap/domain/UniswapContextLoader.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { Interface, type TransactionDescription } from \"ethers\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport { type HttpTokenDataSource } from \"@/token/data/HttpTokenDataSource\";\nimport {\n UNISWAP_EXECUTE_SELECTOR,\n UniswapSupportedCommand,\n} from \"@/uniswap/constants/uniswap\";\nimport { type CommandDecoderDataSource } from \"@/uniswap/data/CommandDecoderDataSource\";\nimport { DefaultCommandDecoderDataSource } from \"@/uniswap/data/DefaultCommandDecoderDataSource\";\nimport { EthersAbiDecoderDataSource } from \"@/uniswap/data/EthersAbiDecoderDataSource\";\n\nimport {\n type UniswapContextInput,\n UniswapContextLoader,\n} from \"./UniswapContextLoader\";\n\ndescribe(\"UniswapContextLoader\", () => {\n const commandDecoderMock: CommandDecoderDataSource = {\n decode: vi.fn(),\n };\n const tokenDataSourceMock = {\n getTokenInfosPayload: vi.fn(),\n };\n let loader: UniswapContextLoader;\n\n describe(\"canHandle function\", () => {\n beforeEach(() => {\n loader = new UniswapContextLoader(\n new DefaultCommandDecoderDataSource(new EthersAbiDecoderDataSource()),\n tokenDataSourceMock as unknown as HttpTokenDataSource,\n );\n });\n\n const validInput: UniswapContextInput = {\n data: \"0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000067a4855b\",\n selector: UNISWAP_EXECUTE_SELECTOR,\n chainId: 1,\n };\n\n it(\"should return true for valid input\", () => {\n expect(loader.canHandle(validInput, [ClearSignContextType.TOKEN])).toBe(\n true,\n );\n });\n\n it(\"should return false for invalid expected type\", () => {\n expect(loader.canHandle(validInput, [ClearSignContextType.NFT])).toBe(\n false,\n );\n expect(\n loader.canHandle(validInput, [ClearSignContextType.EXTERNAL_PLUGIN]),\n ).toBe(false);\n });\n\n it.each([\n [null, \"null input\"],\n [undefined, \"undefined input\"],\n [{}, \"empty object\"],\n [\"string\", \"string input\"],\n [123, \"number input\"],\n [{ ...validInput, data: undefined }, \"missing data\"],\n [{ ...validInput, selector: undefined }, \"missing selector\"],\n [{ ...validInput, chainId: undefined }, \"missing chainId\"],\n [{ ...validInput, data: \"invalid-hex\" }, \"invalid data hex\"],\n [{ ...validInput, data: \"0x\" }, \"empty data hex\"],\n [{ ...validInput, selector: \"invalid-hex\" }, \"invalid selector hex\"],\n [{ ...validInput, selector: \"0x\" }, \"empty selector hex\"],\n [{ ...validInput, selector: \"not-hex-at-all\" }, \"non-hex selector\"],\n [{ ...validInput, selector: 0x00000000 }, \"different selector\"],\n [{ ...validInput, chainId: \"1\" }, \"string chainId\"],\n [{ ...validInput, chainId: null }, \"null chainId\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(loader.canHandle(input, [ClearSignContextType.TOKEN])).toBe(false);\n });\n });\n\n describe(\"load\", () => {\n describe(\"with tokenDataSourceMock\", () => {\n beforeEach(() => {\n vi.spyOn(\n tokenDataSourceMock,\n \"getTokenInfosPayload\",\n ).mockImplementation(({ address }) =>\n Promise.resolve(Right(`payload-${address}`)),\n );\n loader = new UniswapContextLoader(\n new DefaultCommandDecoderDataSource(new EthersAbiDecoderDataSource()),\n tokenDataSourceMock as unknown as HttpTokenDataSource,\n );\n });\n\n it(\"should return an empty array if the selector is not UNISWAP_EXECUTE_SELECTOR\", async () => {\n // GIVEN\n const input: UniswapContextInput = {\n selector: \"0x00000000\" as const,\n data: \"0x00000000\" as const,\n chainId: 1,\n };\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return the decoded contexts\", async () => {\n // GIVEN\n // https://etherscan.io/getRawTx?tx=0xc9821c32c1782d9ab6baf6f9ca4b2565bce11aaf5146a2d303215bda026f5e48\n const input: UniswapContextInput = {\n chainId: 1,\n data: \"0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000067a4855b000000000000000000000000000000000000000000000000000000000000000300060c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000a18f07d736b90be5500000000000000000000000000000000000000000000000000000000b0b8122abd8412900000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002bb9f599ce614feb2e1bbe58f180f370d05b39344e002710c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000017cc6042605381c158d2adab487434bde79aa61c000000000000000000000000000000000000000000000000000000000000005b000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000b0b8122abd84129c001a053efc49d03b694742500f49aa09df2360bd7e297fa730c745e0d4320b42fc33fa01ca1c85a46c561f624830fffbae2441ba0f2d54eb5b0f17e0e3561d10db0b7ee\",\n selector: UNISWAP_EXECUTE_SELECTOR,\n };\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: \"token\",\n payload: \"payload-0xb9f599ce614feb2e1bbe58f180f370d05b39344e\",\n }, // ERC20\n {\n type: \"token\",\n payload: \"payload-0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2\",\n }, // WETH\n ]);\n });\n\n it(\"should return the decoded contexts with a permit\", async () => {\n // GIVEN\n // https://etherscan.io/getRawTx?tx=0xc4df7ccc0527541d0e80856a8f38deedc48c84825e9355469ba02d873502ce2f\n // PERMIT2_PERMIT, V3_SWAP_EXACT_OUT, UNWRAP_ETH\n const input = {\n chainId: 1,\n data: \"0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000669b9ec100000000000000000000000000000000000000000000000000000000000000030a010c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000016000000000000000000000000055747be9f9f5beb232ad59fe7af013b81d95fd5e000000000000000000000000ffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000066c32b0d0000000000000000000000000000000000000000000000000000000000000008000000000000000000000000ef1c6e67703c7bd7107eed8303fbe6ec2554bf6b00000000000000000000000000000000000000000000000000000000669b9ec100000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000410d756f55acf289e9754faf91bba0a704b5c7c0aa4b1dfd551115ccbe4c7f290234e1a14265e1da0bc872a23627d997fe37a689c290d519f7b8c9bdde1b79108e1b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000030ba49cbff5a00000000000000000000000000000000000000000000000089677c957272141800000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002bc02aaa39b223fe8d0a0e5c4f27ead9083c756cc200271055747be9f9f5beb232ad59fe7af013b81d95fd5e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000030ba49cbff5a000c001a0e406d9c91c8b46d959fcd31a28518a77bb248ebb316c5fab7b98335cce922f2aa0462cb970c32a8dbfe71c57b888c43b9ed04fce41d169dbfcc745445587adb771\",\n selector: UNISWAP_EXECUTE_SELECTOR,\n } as UniswapContextInput;\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: \"token\",\n payload: \"payload-0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2\",\n }, // WETH\n {\n type: \"token\",\n payload: \"payload-0x55747be9f9f5beb232ad59fe7af013b81d95fd5e\",\n }, // ERC20\n ]);\n });\n\n it(\"should return an empty array if the transaction is not supported\", async () => {\n // GIVEN\n const input = {} as UniswapContextInput;\n vi.spyOn(commandDecoderMock, \"decode\").mockReturnValue([]);\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if a command is not supported\", async () => {\n // GIVEN\n // https://etherscan.io/getRawTx?tx=0xa628c8b3da2ad984aed0354d8ca4b4c3c42941491dc4e0d6a5f423fd65e6c90a\n // The command 0x05 (TRANSFER) is not supported\n const input: UniswapContextInput = {\n chainId: 1,\n data: \"0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000067a4bef600000000000000000000000000000000000000000000000000000000000000050b0105040c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000032000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000078e6708e70aed0f000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000059a16770000000000000000000000000000000000000000000000000078e6708e70aed0f00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002ba0b86991c6218b36c1d19d4a2e9eb0ce3606eb480001f4c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000027213e28d7fda5c57fe9e5dd923818dbccf71c4700000000000000000000000000000000000000000000000000000000003938700000000000000000000000000000000000000000000000000000000000000060000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000006f939b43d65be049b7533907db08e80ba6969f450000000000000000000000000000000000000000000000000000000059682f0000000000000000000000000000000000000000000000000000000000000000400000000000000000000000006f939b43d65be049b7533907db08e80ba6969f4500000000000000000000000000000000000000000000000000000000000000000cc080a07c86dd5813ec1f3725c402f8bea6105546d1093c59676023b971f1d83f61bd4ea02a353bf3028cabcbe68c5dc8906752bafe55afc86b6344edb3ffd8a3650332e8\",\n selector: UNISWAP_EXECUTE_SELECTOR,\n };\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([]);\n });\n });\n\n describe(\"with mocked ethers parseTransaction\", () => {\n beforeEach(() => {\n vi.resetAllMocks();\n loader = new UniswapContextLoader(\n commandDecoderMock,\n tokenDataSourceMock as unknown as HttpTokenDataSource,\n );\n });\n\n it(\"should return an array with contexts if 2 chain swaps are supported\", async () => {\n // GIVEN\n const input = {\n data: UNISWAP_EXECUTE_SELECTOR,\n chainId: 0x42,\n selector: UNISWAP_EXECUTE_SELECTOR,\n } as UniswapContextInput;\n const commands = `0x0809`; // V2_SWAP_EXACT_IN, V2_SWAP_EXACT_OUT\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [commands, [\"0x0001\", \"0x0002\"]],\n } as TransactionDescription);\n vi.spyOn(commandDecoderMock, \"decode\")\n .mockReturnValueOnce([\"0x01\", \"0x04\", \"0x02\"])\n .mockReturnValueOnce([\"0x02\", \"0x03\"]);\n\n vi.spyOn(\n tokenDataSourceMock,\n \"getTokenInfosPayload\",\n ).mockImplementation(({ address }) =>\n Promise.resolve(Right(`payload-${address}`)),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 1,\n UniswapSupportedCommand.V2_SWAP_EXACT_IN,\n \"0x0001\",\n 0x42,\n );\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 2,\n UniswapSupportedCommand.V2_SWAP_EXACT_OUT,\n \"0x0002\",\n 0x42,\n );\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(1, { address: \"0x01\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(2, { address: \"0x04\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(3, { address: \"0x02\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(4, { address: \"0x03\", chainId: 0x42 });\n expect(result).toEqual([\n {\n type: \"token\",\n payload: \"payload-0x01\",\n },\n {\n type: \"token\",\n payload: \"payload-0x04\",\n },\n {\n type: \"token\",\n payload: \"payload-0x02\",\n },\n {\n type: \"token\",\n payload: \"payload-0x03\",\n },\n ]);\n });\n\n it(\"should return an array with contexts if 1 chain swap with a non swap command\", async () => {\n // GIVEN\n const input = {\n data: UNISWAP_EXECUTE_SELECTOR,\n chainId: 0x42,\n selector: UNISWAP_EXECUTE_SELECTOR,\n } as UniswapContextInput;\n const commands = `0x0b0004`; // WRAP_ETH, V3_SWAP_EXACT_IN, SWEEP\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [commands, [\"0x0001\", \"0x0002\", \"0x0003\"]],\n } as TransactionDescription);\n vi.spyOn(commandDecoderMock, \"decode\")\n .mockReturnValueOnce([\"0x01\"])\n .mockReturnValueOnce([\"0x02\", \"0x03\"])\n .mockReturnValueOnce([\"0x04\"]);\n vi.spyOn(\n tokenDataSourceMock,\n \"getTokenInfosPayload\",\n ).mockImplementation(({ address }) =>\n Promise.resolve(Right(`payload-${address}`)),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 1,\n UniswapSupportedCommand.WRAP_ETH,\n \"0x0001\",\n 0x42,\n );\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(1, { address: \"0x01\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(2, { address: \"0x02\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(3, { address: \"0x03\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(4, { address: \"0x04\", chainId: 0x42 });\n expect(result).toEqual([\n {\n type: \"token\",\n payload: \"payload-0x01\",\n },\n {\n type: \"token\",\n payload: \"payload-0x02\",\n },\n {\n type: \"token\",\n payload: \"payload-0x03\",\n },\n {\n type: \"token\",\n payload: \"payload-0x04\",\n },\n ]);\n });\n\n it(\"should return an array with contexts if one token is not found\", async () => {\n // GIVEN\n const input = {\n data: UNISWAP_EXECUTE_SELECTOR,\n chainId: 0x42,\n selector: UNISWAP_EXECUTE_SELECTOR,\n } as UniswapContextInput;\n const commands = `0x0809`; // V2_SWAP_EXACT_IN, V2_SWAP_EXACT_OUT\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [commands, [\"0x0001\", \"0x0002\"]],\n } as TransactionDescription);\n vi.spyOn(commandDecoderMock, \"decode\")\n .mockReturnValueOnce([\"0x01\", \"0x02\"])\n .mockReturnValueOnce([\"0x02\", \"0x03\"]);\n vi.spyOn(tokenDataSourceMock, \"getTokenInfosPayload\")\n .mockResolvedValueOnce(Left(\"error\"))\n .mockImplementation(({ address }) =>\n Promise.resolve(Right(`payload-${address}`)),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 1,\n UniswapSupportedCommand.V2_SWAP_EXACT_IN,\n \"0x0001\",\n 0x42,\n );\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 2,\n UniswapSupportedCommand.V2_SWAP_EXACT_OUT,\n \"0x0002\",\n 0x42,\n );\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(1, { address: \"0x01\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(2, { address: \"0x02\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(3, { address: \"0x03\", chainId: 0x42 });\n expect(result).toEqual([\n {\n type: \"error\",\n error: \"error\",\n },\n {\n type: \"token\",\n payload: \"payload-0x02\",\n },\n {\n type: \"token\",\n payload: \"payload-0x03\",\n },\n ]);\n });\n\n it(\"should return an empty array if the if 2 chain swaps are not supported\", async () => {\n // GIVEN\n const input = {\n data: UNISWAP_EXECUTE_SELECTOR,\n chainId: 0x42,\n selector: UNISWAP_EXECUTE_SELECTOR,\n } as UniswapContextInput;\n const commands = `0x0809`; // V2_SWAP_EXACT_IN, V2_SWAP_EXACT_OUT\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [commands, [\"0x0001\", \"0x0002\"]],\n } as TransactionDescription);\n vi.spyOn(commandDecoderMock, \"decode\").mockReturnValueOnce([\n \"0x01\",\n \"0x02\",\n ]);\n vi.spyOn(commandDecoderMock, \"decode\").mockReturnValueOnce([\n \"0x03\", // should be 0x02\n \"0x04\",\n ]);\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 1,\n UniswapSupportedCommand.V2_SWAP_EXACT_IN,\n \"0x0001\",\n 0x42,\n );\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 2,\n UniswapSupportedCommand.V2_SWAP_EXACT_OUT,\n \"0x0002\",\n 0x42,\n );\n expect(tokenDataSourceMock.getTokenInfosPayload).not.toHaveBeenCalled();\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if no command are returned from parseTransaction\", async () => {\n // GIVEN\n const input: UniswapContextInput = {\n data: UNISWAP_EXECUTE_SELECTOR,\n selector: UNISWAP_EXECUTE_SELECTOR,\n chainId: 1,\n };\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [\"\"],\n } as TransactionDescription);\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(commandDecoderMock.decode).not.toHaveBeenCalled();\n expect(tokenDataSourceMock.getTokenInfosPayload).not.toHaveBeenCalled();\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if no inputs are returned from parseTransaction\", async () => {\n // GIVEN\n const input: UniswapContextInput = {\n data: UNISWAP_EXECUTE_SELECTOR,\n selector: UNISWAP_EXECUTE_SELECTOR,\n chainId: 1,\n };\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [\"0x08\", []],\n } as TransactionDescription);\n vi.spyOn(commandDecoderMock, \"decode\").mockReturnValue([]);\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(tokenDataSourceMock.getTokenInfosPayload).not.toHaveBeenCalled();\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if parseTransaction throws an error\", async () => {\n // GIVEN\n const input: UniswapContextInput = {\n data: UNISWAP_EXECUTE_SELECTOR,\n selector: UNISWAP_EXECUTE_SELECTOR,\n chainId: 1,\n };\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockImplementation(\n () => {\n throw new Error();\n },\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(commandDecoderMock.decode).not.toHaveBeenCalled();\n expect(tokenDataSourceMock.getTokenInfosPayload).not.toHaveBeenCalled();\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if the swap is with multiple pool versions\", async () => {\n // GIVEN\n const input: UniswapContextInput = {\n data: UNISWAP_EXECUTE_SELECTOR,\n chainId: 0x42,\n selector: UNISWAP_EXECUTE_SELECTOR,\n };\n const commands = `0x080900`; // V2_SWAP_EXACT_IN, V2_SWAP_EXACT_OUT, V3_SWAP_EXACT_IN\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [commands, [\"0x00\", \"0x01\", \"0x02\"]],\n } as TransactionDescription);\n vi.spyOn(commandDecoderMock, \"decode\").mockReturnValue([\n \"0x01\",\n \"0x02\",\n ]);\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 1,\n UniswapSupportedCommand.V2_SWAP_EXACT_IN,\n \"0x00\",\n 0x42,\n );\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 2,\n UniswapSupportedCommand.V2_SWAP_EXACT_OUT,\n \"0x01\",\n 0x42,\n );\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 3,\n UniswapSupportedCommand.V3_SWAP_EXACT_IN,\n \"0x02\",\n 0x42,\n );\n expect(tokenDataSourceMock.getTokenInfosPayload).not.toHaveBeenCalled();\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if the selector is not supported\", async () => {\n // GIVEN\n const input = {\n data: \"0x00000000\",\n chainId: 0x42,\n selector: UNISWAP_EXECUTE_SELECTOR,\n } as UniswapContextInput;\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(commandDecoderMock.decode).not.toHaveBeenCalled();\n expect(tokenDataSourceMock.getTokenInfosPayload).not.toHaveBeenCalled();\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if the length of the commands and inputs are different\", async () => {\n // GIVEN\n const input = {\n data: UNISWAP_EXECUTE_SELECTOR,\n chainId: 0x42,\n selector: UNISWAP_EXECUTE_SELECTOR,\n } as UniswapContextInput;\n const commands = `0x0809`; // V2_SWAP_EXACT_IN, V2_SWAP_EXACT_OUT\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [commands, [\"0x0001\"]],\n } as TransactionDescription);\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(commandDecoderMock.decode).not.toHaveBeenCalled();\n expect(tokenDataSourceMock.getTokenInfosPayload).not.toHaveBeenCalled();\n expect(result).toEqual([]);\n });\n });\n });\n});\n"],
|
|
5
|
-
"mappings": "aAAA,IAAAA,EAAuD,kBACvDC,EAA4B,qBAE5BC,EAAqC,2CAErCC,EAGO,uCAEPC,EAAgD,0DAChDC,EAA2C,qDAE3CC,EAGO,kCAEP,SAAS,uBAAwB,IAAM,CACrC,MAAMC,EAA+C,CACnD,OAAQ,GAAG,GAAG,CAChB,EACMC,EAAsB,CAC1B,qBAAsB,GAAG,GAAG,CAC9B,EACA,IAAIC,EAEJ,SAAS,qBAAsB,IAAM,CACnC,WAAW,IAAM,CACfA,EAAS,IAAI,uBACX,IAAI,kCAAgC,IAAI,4BAA4B,EACpED,CACF,CACF,CAAC,EAED,
|
|
6
|
-
"names": ["import_ethers", "import_purify_ts", "import_ClearSignContext", "import_uniswap", "import_DefaultCommandDecoderDataSource", "import_EthersAbiDecoderDataSource", "import_UniswapContextLoader", "commandDecoderMock", "tokenDataSourceMock", "loader", "validInput", "input", "_description", "address", "result"]
|
|
4
|
+
"sourcesContent": ["import { Interface, type TransactionDescription } from \"ethers\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport { type HttpTokenDataSource } from \"@/token/data/HttpTokenDataSource\";\nimport {\n UNISWAP_EXECUTE_SELECTOR,\n UniswapSupportedCommand,\n} from \"@/uniswap/constants/uniswap\";\nimport { type CommandDecoderDataSource } from \"@/uniswap/data/CommandDecoderDataSource\";\nimport { DefaultCommandDecoderDataSource } from \"@/uniswap/data/DefaultCommandDecoderDataSource\";\nimport { EthersAbiDecoderDataSource } from \"@/uniswap/data/EthersAbiDecoderDataSource\";\n\nimport {\n type UniswapContextInput,\n UniswapContextLoader,\n} from \"./UniswapContextLoader\";\n\nconst mockLoggerFactory = () => ({\n debug: vi.fn(),\n info: vi.fn(),\n warn: vi.fn(),\n error: vi.fn(),\n subscribers: [],\n});\n\ndescribe(\"UniswapContextLoader\", () => {\n const commandDecoderMock: CommandDecoderDataSource = {\n decode: vi.fn(),\n };\n const tokenDataSourceMock = {\n getTokenInfosPayload: vi.fn(),\n };\n let loader: UniswapContextLoader;\n\n describe(\"canHandle function\", () => {\n beforeEach(() => {\n loader = new UniswapContextLoader(\n new DefaultCommandDecoderDataSource(new EthersAbiDecoderDataSource()),\n tokenDataSourceMock as unknown as HttpTokenDataSource,\n mockLoggerFactory,\n );\n });\n\n const validInput: UniswapContextInput = {\n data: \"0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000067a4855b\",\n selector: UNISWAP_EXECUTE_SELECTOR,\n chainId: 1,\n };\n\n it(\"should return true for valid input\", () => {\n expect(loader.canHandle(validInput, [ClearSignContextType.TOKEN])).toBe(\n true,\n );\n });\n\n it(\"should return false for invalid expected type\", () => {\n expect(loader.canHandle(validInput, [ClearSignContextType.NFT])).toBe(\n false,\n );\n expect(\n loader.canHandle(validInput, [ClearSignContextType.EXTERNAL_PLUGIN]),\n ).toBe(false);\n });\n\n it.each([\n [null, \"null input\"],\n [undefined, \"undefined input\"],\n [{}, \"empty object\"],\n [\"string\", \"string input\"],\n [123, \"number input\"],\n [{ ...validInput, data: undefined }, \"missing data\"],\n [{ ...validInput, selector: undefined }, \"missing selector\"],\n [{ ...validInput, chainId: undefined }, \"missing chainId\"],\n [{ ...validInput, data: \"invalid-hex\" }, \"invalid data hex\"],\n [{ ...validInput, data: \"0x\" }, \"empty data hex\"],\n [{ ...validInput, selector: \"invalid-hex\" }, \"invalid selector hex\"],\n [{ ...validInput, selector: \"0x\" }, \"empty selector hex\"],\n [{ ...validInput, selector: \"not-hex-at-all\" }, \"non-hex selector\"],\n [{ ...validInput, selector: 0x00000000 }, \"different selector\"],\n [{ ...validInput, chainId: \"1\" }, \"string chainId\"],\n [{ ...validInput, chainId: null }, \"null chainId\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(loader.canHandle(input, [ClearSignContextType.TOKEN])).toBe(false);\n });\n });\n\n describe(\"load\", () => {\n describe(\"with tokenDataSourceMock\", () => {\n beforeEach(() => {\n vi.spyOn(\n tokenDataSourceMock,\n \"getTokenInfosPayload\",\n ).mockImplementation(({ address }) =>\n Promise.resolve(Right(`payload-${address}`)),\n );\n loader = new UniswapContextLoader(\n new DefaultCommandDecoderDataSource(new EthersAbiDecoderDataSource()),\n tokenDataSourceMock as unknown as HttpTokenDataSource,\n mockLoggerFactory,\n );\n });\n\n it(\"should return an empty array if the selector is not UNISWAP_EXECUTE_SELECTOR\", async () => {\n // GIVEN\n const input: UniswapContextInput = {\n selector: \"0x00000000\" as const,\n data: \"0x00000000\" as const,\n chainId: 1,\n };\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return the decoded contexts\", async () => {\n // GIVEN\n // https://etherscan.io/getRawTx?tx=0xc9821c32c1782d9ab6baf6f9ca4b2565bce11aaf5146a2d303215bda026f5e48\n const input: UniswapContextInput = {\n chainId: 1,\n data: \"0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000067a4855b000000000000000000000000000000000000000000000000000000000000000300060c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000a18f07d736b90be5500000000000000000000000000000000000000000000000000000000b0b8122abd8412900000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002bb9f599ce614feb2e1bbe58f180f370d05b39344e002710c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000017cc6042605381c158d2adab487434bde79aa61c000000000000000000000000000000000000000000000000000000000000005b000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000b0b8122abd84129c001a053efc49d03b694742500f49aa09df2360bd7e297fa730c745e0d4320b42fc33fa01ca1c85a46c561f624830fffbae2441ba0f2d54eb5b0f17e0e3561d10db0b7ee\",\n selector: UNISWAP_EXECUTE_SELECTOR,\n };\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: \"token\",\n payload: \"payload-0xb9f599ce614feb2e1bbe58f180f370d05b39344e\",\n }, // ERC20\n {\n type: \"token\",\n payload: \"payload-0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2\",\n }, // WETH\n ]);\n });\n\n it(\"should return the decoded contexts with a permit\", async () => {\n // GIVEN\n // https://etherscan.io/getRawTx?tx=0xc4df7ccc0527541d0e80856a8f38deedc48c84825e9355469ba02d873502ce2f\n // PERMIT2_PERMIT, V3_SWAP_EXACT_OUT, UNWRAP_ETH\n const input = {\n chainId: 1,\n data: \"0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000669b9ec100000000000000000000000000000000000000000000000000000000000000030a010c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000016000000000000000000000000055747be9f9f5beb232ad59fe7af013b81d95fd5e000000000000000000000000ffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000066c32b0d0000000000000000000000000000000000000000000000000000000000000008000000000000000000000000ef1c6e67703c7bd7107eed8303fbe6ec2554bf6b00000000000000000000000000000000000000000000000000000000669b9ec100000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000410d756f55acf289e9754faf91bba0a704b5c7c0aa4b1dfd551115ccbe4c7f290234e1a14265e1da0bc872a23627d997fe37a689c290d519f7b8c9bdde1b79108e1b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000030ba49cbff5a00000000000000000000000000000000000000000000000089677c957272141800000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002bc02aaa39b223fe8d0a0e5c4f27ead9083c756cc200271055747be9f9f5beb232ad59fe7af013b81d95fd5e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000030ba49cbff5a000c001a0e406d9c91c8b46d959fcd31a28518a77bb248ebb316c5fab7b98335cce922f2aa0462cb970c32a8dbfe71c57b888c43b9ed04fce41d169dbfcc745445587adb771\",\n selector: UNISWAP_EXECUTE_SELECTOR,\n } as UniswapContextInput;\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: \"token\",\n payload: \"payload-0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2\",\n }, // WETH\n {\n type: \"token\",\n payload: \"payload-0x55747be9f9f5beb232ad59fe7af013b81d95fd5e\",\n }, // ERC20\n ]);\n });\n\n it(\"should return an empty array if the transaction is not supported\", async () => {\n // GIVEN\n const input = {} as UniswapContextInput;\n vi.spyOn(commandDecoderMock, \"decode\").mockReturnValue([]);\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if a command is not supported\", async () => {\n // GIVEN\n // https://etherscan.io/getRawTx?tx=0xa628c8b3da2ad984aed0354d8ca4b4c3c42941491dc4e0d6a5f423fd65e6c90a\n // The command 0x05 (TRANSFER) is not supported\n const input: UniswapContextInput = {\n chainId: 1,\n data: \"0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000067a4bef600000000000000000000000000000000000000000000000000000000000000050b0105040c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000032000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000078e6708e70aed0f000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000059a16770000000000000000000000000000000000000000000000000078e6708e70aed0f00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002ba0b86991c6218b36c1d19d4a2e9eb0ce3606eb480001f4c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000027213e28d7fda5c57fe9e5dd923818dbccf71c4700000000000000000000000000000000000000000000000000000000003938700000000000000000000000000000000000000000000000000000000000000060000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000006f939b43d65be049b7533907db08e80ba6969f450000000000000000000000000000000000000000000000000000000059682f0000000000000000000000000000000000000000000000000000000000000000400000000000000000000000006f939b43d65be049b7533907db08e80ba6969f4500000000000000000000000000000000000000000000000000000000000000000cc080a07c86dd5813ec1f3725c402f8bea6105546d1093c59676023b971f1d83f61bd4ea02a353bf3028cabcbe68c5dc8906752bafe55afc86b6344edb3ffd8a3650332e8\",\n selector: UNISWAP_EXECUTE_SELECTOR,\n };\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([]);\n });\n });\n\n describe(\"with mocked ethers parseTransaction\", () => {\n beforeEach(() => {\n vi.resetAllMocks();\n loader = new UniswapContextLoader(\n commandDecoderMock,\n tokenDataSourceMock as unknown as HttpTokenDataSource,\n mockLoggerFactory,\n );\n });\n\n it(\"should return an array with contexts if 2 chain swaps are supported\", async () => {\n // GIVEN\n const input = {\n data: UNISWAP_EXECUTE_SELECTOR,\n chainId: 0x42,\n selector: UNISWAP_EXECUTE_SELECTOR,\n } as UniswapContextInput;\n const commands = `0x0809`; // V2_SWAP_EXACT_IN, V2_SWAP_EXACT_OUT\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [commands, [\"0x0001\", \"0x0002\"]],\n } as TransactionDescription);\n vi.spyOn(commandDecoderMock, \"decode\")\n .mockReturnValueOnce([\"0x01\", \"0x04\", \"0x02\"])\n .mockReturnValueOnce([\"0x02\", \"0x03\"]);\n\n vi.spyOn(\n tokenDataSourceMock,\n \"getTokenInfosPayload\",\n ).mockImplementation(({ address }) =>\n Promise.resolve(Right(`payload-${address}`)),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 1,\n UniswapSupportedCommand.V2_SWAP_EXACT_IN,\n \"0x0001\",\n 0x42,\n );\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 2,\n UniswapSupportedCommand.V2_SWAP_EXACT_OUT,\n \"0x0002\",\n 0x42,\n );\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(1, { address: \"0x01\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(2, { address: \"0x04\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(3, { address: \"0x02\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(4, { address: \"0x03\", chainId: 0x42 });\n expect(result).toEqual([\n {\n type: \"token\",\n payload: \"payload-0x01\",\n },\n {\n type: \"token\",\n payload: \"payload-0x04\",\n },\n {\n type: \"token\",\n payload: \"payload-0x02\",\n },\n {\n type: \"token\",\n payload: \"payload-0x03\",\n },\n ]);\n });\n\n it(\"should return an array with contexts if 1 chain swap with a non swap command\", async () => {\n // GIVEN\n const input = {\n data: UNISWAP_EXECUTE_SELECTOR,\n chainId: 0x42,\n selector: UNISWAP_EXECUTE_SELECTOR,\n } as UniswapContextInput;\n const commands = `0x0b0004`; // WRAP_ETH, V3_SWAP_EXACT_IN, SWEEP\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [commands, [\"0x0001\", \"0x0002\", \"0x0003\"]],\n } as TransactionDescription);\n vi.spyOn(commandDecoderMock, \"decode\")\n .mockReturnValueOnce([\"0x01\"])\n .mockReturnValueOnce([\"0x02\", \"0x03\"])\n .mockReturnValueOnce([\"0x04\"]);\n vi.spyOn(\n tokenDataSourceMock,\n \"getTokenInfosPayload\",\n ).mockImplementation(({ address }) =>\n Promise.resolve(Right(`payload-${address}`)),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 1,\n UniswapSupportedCommand.WRAP_ETH,\n \"0x0001\",\n 0x42,\n );\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(1, { address: \"0x01\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(2, { address: \"0x02\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(3, { address: \"0x03\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(4, { address: \"0x04\", chainId: 0x42 });\n expect(result).toEqual([\n {\n type: \"token\",\n payload: \"payload-0x01\",\n },\n {\n type: \"token\",\n payload: \"payload-0x02\",\n },\n {\n type: \"token\",\n payload: \"payload-0x03\",\n },\n {\n type: \"token\",\n payload: \"payload-0x04\",\n },\n ]);\n });\n\n it(\"should return an array with contexts if one token is not found\", async () => {\n // GIVEN\n const input = {\n data: UNISWAP_EXECUTE_SELECTOR,\n chainId: 0x42,\n selector: UNISWAP_EXECUTE_SELECTOR,\n } as UniswapContextInput;\n const commands = `0x0809`; // V2_SWAP_EXACT_IN, V2_SWAP_EXACT_OUT\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [commands, [\"0x0001\", \"0x0002\"]],\n } as TransactionDescription);\n vi.spyOn(commandDecoderMock, \"decode\")\n .mockReturnValueOnce([\"0x01\", \"0x02\"])\n .mockReturnValueOnce([\"0x02\", \"0x03\"]);\n vi.spyOn(tokenDataSourceMock, \"getTokenInfosPayload\")\n .mockResolvedValueOnce(Left(\"error\"))\n .mockImplementation(({ address }) =>\n Promise.resolve(Right(`payload-${address}`)),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 1,\n UniswapSupportedCommand.V2_SWAP_EXACT_IN,\n \"0x0001\",\n 0x42,\n );\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 2,\n UniswapSupportedCommand.V2_SWAP_EXACT_OUT,\n \"0x0002\",\n 0x42,\n );\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(1, { address: \"0x01\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(2, { address: \"0x02\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(3, { address: \"0x03\", chainId: 0x42 });\n expect(result).toEqual([\n {\n type: \"error\",\n error: \"error\",\n },\n {\n type: \"token\",\n payload: \"payload-0x02\",\n },\n {\n type: \"token\",\n payload: \"payload-0x03\",\n },\n ]);\n });\n\n it(\"should return an empty array if the if 2 chain swaps are not supported\", async () => {\n // GIVEN\n const input = {\n data: UNISWAP_EXECUTE_SELECTOR,\n chainId: 0x42,\n selector: UNISWAP_EXECUTE_SELECTOR,\n } as UniswapContextInput;\n const commands = `0x0809`; // V2_SWAP_EXACT_IN, V2_SWAP_EXACT_OUT\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [commands, [\"0x0001\", \"0x0002\"]],\n } as TransactionDescription);\n vi.spyOn(commandDecoderMock, \"decode\").mockReturnValueOnce([\n \"0x01\",\n \"0x02\",\n ]);\n vi.spyOn(commandDecoderMock, \"decode\").mockReturnValueOnce([\n \"0x03\", // should be 0x02\n \"0x04\",\n ]);\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 1,\n UniswapSupportedCommand.V2_SWAP_EXACT_IN,\n \"0x0001\",\n 0x42,\n );\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 2,\n UniswapSupportedCommand.V2_SWAP_EXACT_OUT,\n \"0x0002\",\n 0x42,\n );\n expect(tokenDataSourceMock.getTokenInfosPayload).not.toHaveBeenCalled();\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if no command are returned from parseTransaction\", async () => {\n // GIVEN\n const input: UniswapContextInput = {\n data: UNISWAP_EXECUTE_SELECTOR,\n selector: UNISWAP_EXECUTE_SELECTOR,\n chainId: 1,\n };\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [\"\"],\n } as TransactionDescription);\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(commandDecoderMock.decode).not.toHaveBeenCalled();\n expect(tokenDataSourceMock.getTokenInfosPayload).not.toHaveBeenCalled();\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if no inputs are returned from parseTransaction\", async () => {\n // GIVEN\n const input: UniswapContextInput = {\n data: UNISWAP_EXECUTE_SELECTOR,\n selector: UNISWAP_EXECUTE_SELECTOR,\n chainId: 1,\n };\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [\"0x08\", []],\n } as TransactionDescription);\n vi.spyOn(commandDecoderMock, \"decode\").mockReturnValue([]);\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(tokenDataSourceMock.getTokenInfosPayload).not.toHaveBeenCalled();\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if parseTransaction throws an error\", async () => {\n // GIVEN\n const input: UniswapContextInput = {\n data: UNISWAP_EXECUTE_SELECTOR,\n selector: UNISWAP_EXECUTE_SELECTOR,\n chainId: 1,\n };\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockImplementation(\n () => {\n throw new Error();\n },\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(commandDecoderMock.decode).not.toHaveBeenCalled();\n expect(tokenDataSourceMock.getTokenInfosPayload).not.toHaveBeenCalled();\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if the swap is with multiple pool versions\", async () => {\n // GIVEN\n const input: UniswapContextInput = {\n data: UNISWAP_EXECUTE_SELECTOR,\n chainId: 0x42,\n selector: UNISWAP_EXECUTE_SELECTOR,\n };\n const commands = `0x080900`; // V2_SWAP_EXACT_IN, V2_SWAP_EXACT_OUT, V3_SWAP_EXACT_IN\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [commands, [\"0x00\", \"0x01\", \"0x02\"]],\n } as TransactionDescription);\n vi.spyOn(commandDecoderMock, \"decode\").mockReturnValue([\n \"0x01\",\n \"0x02\",\n ]);\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 1,\n UniswapSupportedCommand.V2_SWAP_EXACT_IN,\n \"0x00\",\n 0x42,\n );\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 2,\n UniswapSupportedCommand.V2_SWAP_EXACT_OUT,\n \"0x01\",\n 0x42,\n );\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 3,\n UniswapSupportedCommand.V3_SWAP_EXACT_IN,\n \"0x02\",\n 0x42,\n );\n expect(tokenDataSourceMock.getTokenInfosPayload).not.toHaveBeenCalled();\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if the selector is not supported\", async () => {\n // GIVEN\n const input = {\n data: \"0x00000000\",\n chainId: 0x42,\n selector: UNISWAP_EXECUTE_SELECTOR,\n } as UniswapContextInput;\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(commandDecoderMock.decode).not.toHaveBeenCalled();\n expect(tokenDataSourceMock.getTokenInfosPayload).not.toHaveBeenCalled();\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if the length of the commands and inputs are different\", async () => {\n // GIVEN\n const input = {\n data: UNISWAP_EXECUTE_SELECTOR,\n chainId: 0x42,\n selector: UNISWAP_EXECUTE_SELECTOR,\n } as UniswapContextInput;\n const commands = `0x0809`; // V2_SWAP_EXACT_IN, V2_SWAP_EXACT_OUT\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [commands, [\"0x0001\"]],\n } as TransactionDescription);\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(commandDecoderMock.decode).not.toHaveBeenCalled();\n expect(tokenDataSourceMock.getTokenInfosPayload).not.toHaveBeenCalled();\n expect(result).toEqual([]);\n });\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "aAAA,IAA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
"names": ["import_ethers", "import_purify_ts", "import_ClearSignContext", "import_uniswap", "import_DefaultCommandDecoderDataSource", "import_EthersAbiDecoderDataSource", "import_UniswapContextLoader", "mockLoggerFactory", "commandDecoderMock", "tokenDataSourceMock", "loader", "validInput", "input", "_description", "address", "result"]
|
|
7
7
|
}
|
package/lib/esm/package.json
CHANGED
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"watch:builds": "pnpm ldmk-tool watch --entryPoints index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
|
|
59
59
|
"watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\""
|
|
60
60
|
},
|
|
61
|
-
"version": "1.
|
|
61
|
+
"version": "1.13.0"
|
|
62
62
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{DefaultContextModule as o}from"./DefaultContextModule";const r="https://crypto-assets-service.api.ledger.com/v1",a="https://web3checks-backend.api.ledger.com/v3",i="https://nft.api.live.ledger.com";class d{config;originToken;constructor({originToken:e,loggerFactory:t}){this.originToken=e,this.config={cal:{url:r,mode:"prod",branch:"main"},web3checks:{url:a},metadataServiceDomain:{url:i},defaultLoaders:!0,customLoaders:[],defaultFieldLoaders:!0,customFieldLoaders:[],customTypedDataLoader:void 0,customSolanaLoader:void 0,loggerFactory:t}}removeDefaultLoaders(){return this.config.defaultLoaders=!1,this}addLoader(e){return this.config.customLoaders.push(e),this}addTypedDataLoader(e){return this.config.customTypedDataLoader=e,this}addSolanaLoader(e){return this.config.customSolanaLoader=e,this}setCalConfig(e){return this.config.cal=e,this}setMetadataServiceConfig(e){return this.config.metadataServiceDomain=e,this}setWeb3ChecksConfig(e){return this.config.web3checks=e,this}setDatasourceConfig(e){return this.config.datasource=e,this}setTrustedNameDataSource(e){return this.config.customTrustedNameDataSource=e,this}setLoggerFactory(e){return this.config.loggerFactory=e,this}build(){const e={...this.config,originToken:this.originToken};return new o(e)}}export{d as ContextModuleBuilder};
|
|
2
2
|
//# sourceMappingURL=ContextModuleBuilder.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/ContextModuleBuilder.ts"],
|
|
4
|
-
"sourcesContent": ["import { type LoggerPublisherService } from \"@ledgerhq/device-management-kit\";\n\nimport { type ContextModuleConstructorArgs } from \"./config/model/ContextModuleBuildArgs\";\nimport {\n type ContextModuleCalConfig,\n type ContextModuleConfig,\n type ContextModuleDatasourceConfig,\n type ContextModuleMetadataServiceConfig,\n type ContextModuleWeb3ChecksConfig,\n} from \"./config/model/ContextModuleConfig\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport {
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["
|
|
4
|
+
"sourcesContent": ["import { type LoggerPublisherService } from \"@ledgerhq/device-management-kit\";\n\nimport { type ContextModuleConstructorArgs } from \"./config/model/ContextModuleBuildArgs\";\nimport {\n type ContextModuleCalConfig,\n type ContextModuleConfig,\n type ContextModuleDatasourceConfig,\n type ContextModuleMetadataServiceConfig,\n type ContextModuleWeb3ChecksConfig,\n} from \"./config/model/ContextModuleConfig\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport { type SolanaContextLoader } from \"./solana/domain/SolanaContextLoader\";\nimport { type TrustedNameDataSource } from \"./trusted-name/data/TrustedNameDataSource\";\nimport { type TypedDataContextLoader } from \"./typed-data/domain/TypedDataContextLoader\";\nimport { type ContextModule } from \"./ContextModule\";\nimport { DefaultContextModule } from \"./DefaultContextModule\";\n\nconst DEFAULT_CAL_URL = \"https://crypto-assets-service.api.ledger.com/v1\";\nconst DEFAULT_WEB3_CHECKS_URL = \"https://web3checks-backend.api.ledger.com/v3\";\nconst DEFAULT_METADATA_SERVICE_DOMAIN = \"https://nft.api.live.ledger.com\";\n\nexport class ContextModuleBuilder {\n private config: ContextModuleConfig;\n private originToken?: string;\n\n constructor({ originToken, loggerFactory }: ContextModuleConstructorArgs) {\n this.originToken = originToken;\n\n this.config = {\n cal: {\n url: DEFAULT_CAL_URL,\n mode: \"prod\",\n branch: \"main\",\n },\n web3checks: {\n url: DEFAULT_WEB3_CHECKS_URL,\n },\n metadataServiceDomain: {\n url: DEFAULT_METADATA_SERVICE_DOMAIN,\n },\n defaultLoaders: true,\n customLoaders: [],\n defaultFieldLoaders: true,\n customFieldLoaders: [],\n customTypedDataLoader: undefined,\n customSolanaLoader: undefined,\n loggerFactory,\n };\n }\n\n /**\n * Remove default loaders from the list of loaders\n *\n * @returns this\n */\n removeDefaultLoaders() {\n this.config.defaultLoaders = false;\n return this;\n }\n\n /**\n * Add a custom loader to the list of loaders\n *\n * @param loader loader to add to the list of loaders\n * @returns this\n */\n addLoader(loader: ContextLoader) {\n this.config.customLoaders.push(loader);\n return this;\n }\n\n /**\n * Replace the default loader for typed data clear signing contexts\n *\n * @param loader loader to use for typed data clear signing contexts\n * @returns this\n */\n addTypedDataLoader(loader: TypedDataContextLoader) {\n this.config.customTypedDataLoader = loader;\n return this;\n }\n\n /**\n * Replace the default loader for Solana context\n *\n * @param loader loader to use for Solana context\n * @returns this\n */\n addSolanaLoader(loader: SolanaContextLoader) {\n this.config.customSolanaLoader = loader;\n return this;\n }\n\n /**\n * Add a custom CAL configuration\n *\n * @param calConfig\n * @returns this\n */\n setCalConfig(calConfig: ContextModuleCalConfig) {\n this.config.cal = calConfig;\n return this;\n }\n\n /**\n * Add a custom metadata service configuration\n *\n * @param metadataServiceConfig\n * @returns this\n */\n setMetadataServiceConfig(\n metadataServiceConfig: ContextModuleMetadataServiceConfig,\n ) {\n this.config.metadataServiceDomain = metadataServiceConfig;\n return this;\n }\n\n /**\n * Add a custom web3 checks configuration\n *\n * @param web3ChecksConfig\n * @returns this\n */\n setWeb3ChecksConfig(web3ChecksConfig: ContextModuleWeb3ChecksConfig) {\n this.config.web3checks = web3ChecksConfig;\n return this;\n }\n\n /**\n * Add datasource configuration\n *\n * @param datasourceConfig\n * @returns this\n */\n setDatasourceConfig(datasourceConfig: ContextModuleDatasourceConfig) {\n this.config.datasource = datasourceConfig;\n return this;\n }\n\n /**\n * Set a custom trusted name data source\n *\n * @param dataSource data source to use for trusted name resolution\n * @returns this\n */\n setTrustedNameDataSource(dataSource: TrustedNameDataSource) {\n this.config.customTrustedNameDataSource = dataSource;\n return this;\n }\n\n /**\n * Set a custom logger factory\n *\n * @param loggerFactory\n * @returns this\n */\n setLoggerFactory(loggerFactory: (tag: string) => LoggerPublisherService) {\n this.config.loggerFactory = loggerFactory;\n return this;\n }\n\n /**\n * Build the context module\n *\n * @returns the context module\n */\n build(): ContextModule {\n const config = { ...this.config, originToken: this.originToken };\n return new DefaultContextModule(config);\n }\n}\n"],
|
|
5
|
+
"mappings": "AAeA,OAAS,wBAAAA,MAA4B,yBAErC,MAAMC,EAAkB,kDAClBC,EAA0B,+CAC1BC,EAAkC,kCAEjC,MAAMC,CAAqB,CACxB,OACA,YAER,YAAY,CAAE,YAAAC,EAAa,cAAAC,CAAc,EAAiC,CACxE,KAAK,YAAcD,EAEnB,KAAK,OAAS,CACZ,IAAK,CACH,IAAKJ,EACL,KAAM,OACN,OAAQ,MACV,EACA,WAAY,CACV,IAAKC,CACP,EACA,sBAAuB,CACrB,IAAKC,CACP,EACA,eAAgB,GAChB,cAAe,CAAC,EAChB,oBAAqB,GACrB,mBAAoB,CAAC,EACrB,sBAAuB,OACvB,mBAAoB,OACpB,cAAAG,CACF,CACF,CAOA,sBAAuB,CACrB,YAAK,OAAO,eAAiB,GACtB,IACT,CAQA,UAAUC,EAAuB,CAC/B,YAAK,OAAO,cAAc,KAAKA,CAAM,EAC9B,IACT,CAQA,mBAAmBA,EAAgC,CACjD,YAAK,OAAO,sBAAwBA,EAC7B,IACT,CAQA,gBAAgBA,EAA6B,CAC3C,YAAK,OAAO,mBAAqBA,EAC1B,IACT,CAQA,aAAaC,EAAmC,CAC9C,YAAK,OAAO,IAAMA,EACX,IACT,CAQA,yBACEC,EACA,CACA,YAAK,OAAO,sBAAwBA,EAC7B,IACT,CAQA,oBAAoBC,EAAiD,CACnE,YAAK,OAAO,WAAaA,EAClB,IACT,CAQA,oBAAoBC,EAAiD,CACnE,YAAK,OAAO,WAAaA,EAClB,IACT,CAQA,yBAAyBC,EAAmC,CAC1D,YAAK,OAAO,4BAA8BA,EACnC,IACT,CAQA,iBAAiBN,EAAwD,CACvE,YAAK,OAAO,cAAgBA,EACrB,IACT,CAOA,OAAuB,CACrB,MAAMO,EAAS,CAAE,GAAG,KAAK,OAAQ,YAAa,KAAK,WAAY,EAC/D,OAAO,IAAIb,EAAqBa,CAAM,CACxC,CACF",
|
|
6
|
+
"names": ["DefaultContextModule", "DEFAULT_CAL_URL", "DEFAULT_WEB3_CHECKS_URL", "DEFAULT_METADATA_SERVICE_DOMAIN", "ContextModuleBuilder", "originToken", "loggerFactory", "loader", "calConfig", "metadataServiceConfig", "web3ChecksConfig", "datasourceConfig", "dataSource", "config"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{configTypes as
|
|
1
|
+
import{configTypes as r}from"./config/di/configTypes";import{HttpTrustedNameDataSource as g}from"./trusted-name/data/HttpTrustedNameDataSource";import{trustedNameTypes as l}from"./trusted-name/di/trustedNameTypes";import{ContextModuleBuilder as a}from"./ContextModuleBuilder";import{DefaultContextModule as s}from"./DefaultContextModule";describe("ContextModuleBuilder",()=>{const u={url:"https://cal/v1",mode:"prod",branch:"main"},i={url:"https://web3checks/v1"},c={originToken:"test",loggerFactory:()=>({debug:vi.fn(),info:vi.fn(),warn:vi.fn(),error:vi.fn(),subscribers:[]})};beforeEach(()=>{vi.resetAllMocks()}),it("should return a default context module",()=>{const e=new a(c).build();expect(e).toBeInstanceOf(s)}),it("should return a custom context module",()=>{const o=new a(c),e={load:vi.fn(),canHandle:vi.fn()},t=o.removeDefaultLoaders().addLoader(e).build();expect(t).toBeInstanceOf(s)}),it("should return a custom context module with a custom typed data loader",()=>{const o=new a(c),e={load:vi.fn()},t=o.removeDefaultLoaders().addTypedDataLoader(e).build();expect(t).toBeInstanceOf(s),expect(t._typedDataLoader).toBe(e)}),it("should return a custom context module with a custom config",()=>{const e=new a(c).setCalConfig(u).setWeb3ChecksConfig(i).build(),t=e._container.get(r.Config);expect(e).toBeInstanceOf(s),expect(t.cal).toEqual(u),expect(t.web3checks).toEqual(i)}),it("should not throw an error if origin token is provided",()=>{const o=new a(c);expect(()=>o.build()).not.toThrow()}),describe("setMetadataServiceConfig",()=>{it("should set the metadata service configuration",()=>{const o=new a(c),e={url:"https://custom-metadata-service.com/v3"},t=o.setMetadataServiceConfig(e).build(),n=t._container.get(r.Config);expect(t).toBeInstanceOf(s),expect(n.metadataServiceDomain).toEqual(e)}),it("should override the default metadata service configuration",()=>{const o=new a(c),e={url:"https://override-metadata-service.com/v1"},n=o.setMetadataServiceConfig(e).build()._container.get(r.Config);expect(n.metadataServiceDomain.url).toBe(e.url),expect(n.metadataServiceDomain.url).not.toBe("https://nft.api.live.ledger.com/v2")})}),describe("setCalConfig",()=>{it("should set the CAL configuration",()=>{const o=new a(c),e={url:"https://custom-cal-service.com/v2",mode:"test",branch:"next"},t=o.setCalConfig(e).build(),n=t._container.get(r.Config);expect(t).toBeInstanceOf(s),expect(n.cal).toEqual(e)}),it("should override the default CAL configuration",()=>{const o=new a(c),e={url:"https://override-cal-service.com/v1",mode:"prod",branch:"demo"},n=o.setCalConfig(e).build()._container.get(r.Config);expect(n.cal.url).toBe(e.url),expect(n.cal.mode).toBe(e.mode),expect(n.cal.branch).toBe(e.branch),expect(n.cal.url).not.toBe("https://crypto-assets-service.api.ledger.com/v1")})}),describe("setWeb3ChecksConfig",()=>{it("should set the web3 checks configuration",()=>{const o=new a(c),e={url:"https://custom-web3checks-service.com/v4"},t=o.setWeb3ChecksConfig(e).build(),n=t._container.get(r.Config);expect(t).toBeInstanceOf(s),expect(n.web3checks).toEqual(e)}),it("should override the default web3 checks configuration",()=>{const o=new a(c),e={url:"https://override-web3checks-service.com/v2"},n=o.setWeb3ChecksConfig(e).build()._container.get(r.Config);expect(n.web3checks.url).toBe(e.url),expect(n.web3checks.url).not.toBe("https://web3checks-backend.api.ledger.com/v3")})}),describe("setDatasourceConfig",()=>{it("should set the datasource configuration with safe proxy",()=>{const o=new a(c),e={proxy:"safe"},t=o.setDatasourceConfig(e).build(),n=t._container.get(r.Config);expect(t).toBeInstanceOf(s),expect(n.datasource).toEqual(e),expect(n.datasource?.proxy).toBe("safe")}),it("should set the datasource configuration with default proxy",()=>{const o=new a(c),e={proxy:"default"},t=o.setDatasourceConfig(e).build(),n=t._container.get(r.Config);expect(t).toBeInstanceOf(s),expect(n.datasource).toEqual(e),expect(n.datasource?.proxy).toBe("default")}),it("should override the default datasource configuration",()=>{const o=new a(c),e={proxy:"safe"},n=o.setDatasourceConfig(e).build()._container.get(r.Config);expect(n.datasource?.proxy).toBe("safe"),expect(n.datasource).not.toBeUndefined()}),it("should set an empty datasource configuration",()=>{const o=new a(c),e={},t=o.setDatasourceConfig(e).build(),n=t._container.get(r.Config);expect(t).toBeInstanceOf(s),expect(n.datasource).toEqual(e),expect(n.datasource?.proxy).toBeUndefined()})}),describe("loggerFactory",()=>{it("should set the loggerFactory when provided in the constructor",()=>{const o=vi.fn(),t=new a({...c,loggerFactory:o}).build(),n=t._container.get(r.Config);expect(t).toBeInstanceOf(s),expect(n.loggerFactory).toBe(o)}),it("should set the loggerFactory via setLoggerFactory",()=>{const o=vi.fn(),t=new a(c).setLoggerFactory(o).build(),n=t._container.get(r.Config);expect(t).toBeInstanceOf(s),expect(n.loggerFactory).toBe(o)}),it("should override constructor loggerFactory with setLoggerFactory",()=>{const o=vi.fn(),e=vi.fn(),d=new a({...c,loggerFactory:o}).setLoggerFactory(e).build()._container.get(r.Config);expect(d.loggerFactory).toBe(e),expect(d.loggerFactory).not.toBe(o)})}),describe("setTrustedNameDataSource",()=>{it("should set a custom trusted name data source",()=>{const o=new a(c),e={getDomainNamePayload:vi.fn(),getTrustedNamePayload:vi.fn()},t=o.setTrustedNameDataSource(e).build(),n=t._container.get(r.Config);expect(t).toBeInstanceOf(s),expect(n.customTrustedNameDataSource).toBe(e)}),it("should inject the custom data source into the container",()=>{const o=new a(c),e={getDomainNamePayload:vi.fn(),getTrustedNamePayload:vi.fn()},n=o.setTrustedNameDataSource(e).build()._container.get(l.TrustedNameDataSource);expect(n).toBe(e)}),it("should use HttpTrustedNameDataSource when no custom data source is set",()=>{const e=new a(c).build(),t=e._container.get(l.TrustedNameDataSource);expect(e).toBeInstanceOf(s),expect(t).toBeInstanceOf(g)})})});
|
|
2
2
|
//# sourceMappingURL=ContextModuleBuilder.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/ContextModuleBuilder.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { type LoggerPublisherService } from \"@ledgerhq/device-management-kit\";\nimport { type Container } from \"inversify\";\n\nimport { configTypes } from \"./config/di/configTypes\";\nimport { type ContextModuleConstructorArgs } from \"./config/model/ContextModuleBuildArgs\";\nimport {\n type ContextModuleCalConfig,\n type ContextModuleConfig,\n type ContextModuleDatasourceConfig,\n type ContextModuleMetadataServiceConfig,\n} from \"./config/model/ContextModuleConfig\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport { ContextModuleBuilder } from \"./ContextModuleBuilder\";\nimport { DefaultContextModule } from \"./DefaultContextModule\";\n\ndescribe(\"ContextModuleBuilder\", () => {\n const defaultCalConfig: ContextModuleCalConfig = {\n url: \"https://cal/v1\",\n mode: \"prod\",\n branch: \"main\",\n };\n const defaultWeb3ChecksConfig = {\n url: \"https://web3checks/v1\",\n };\n const defaultBuilderArgs: ContextModuleConstructorArgs = {\n originToken: \"test\",\n };\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n it(\"should return a default context module\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n\n const res = contextModuleBuilder.build();\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n });\n\n it(\"should return a custom context module\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customLoader: ContextLoader = {\n load: vi.fn(),\n canHandle: vi.fn() as unknown as ContextLoader[\"canHandle\"],\n };\n\n const res = contextModuleBuilder\n .removeDefaultLoaders()\n .addLoader(customLoader)\n .build();\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n });\n\n it(\"should return a custom context module with a custom typed data loader\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customLoader = { load: vi.fn() };\n\n const res = contextModuleBuilder\n .removeDefaultLoaders()\n .addTypedDataLoader(customLoader)\n .build();\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n // @ts-expect-error _typedDataLoader is private\n expect(res[\"_typedDataLoader\"]).toBe(customLoader);\n });\n\n it(\"should return a custom context module with a custom config\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n\n const res = contextModuleBuilder\n .setCalConfig(defaultCalConfig)\n .setWeb3ChecksConfig(defaultWeb3ChecksConfig)\n .build();\n // @ts-expect-error _container is private\n const config = (res[\"_container\"] as Container).get<ContextModuleConfig>(\n configTypes.Config,\n );\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.cal).toEqual(defaultCalConfig);\n expect(config.web3checks).toEqual(defaultWeb3ChecksConfig);\n });\n\n it(\"should not throw an error if origin token is provided\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n\n expect(() => contextModuleBuilder.build()).not.toThrow();\n });\n\n describe(\"setMetadataServiceConfig\", () => {\n it(\"should set the metadata service configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customMetadataConfig: ContextModuleMetadataServiceConfig = {\n url: \"https://custom-metadata-service.com/v3\",\n };\n\n const res = contextModuleBuilder\n .setMetadataServiceConfig(customMetadataConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.metadataServiceDomain).toEqual(customMetadataConfig);\n });\n\n it(\"should override the default metadata service configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customMetadataConfig: ContextModuleMetadataServiceConfig = {\n url: \"https://override-metadata-service.com/v1\",\n };\n\n const res = contextModuleBuilder\n .setMetadataServiceConfig(customMetadataConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(config.metadataServiceDomain.url).toBe(customMetadataConfig.url);\n expect(config.metadataServiceDomain.url).not.toBe(\n \"https://nft.api.live.ledger.com/v2\",\n );\n });\n });\n\n describe(\"setCalConfig\", () => {\n it(\"should set the CAL configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customCalConfig: ContextModuleCalConfig = {\n url: \"https://custom-cal-service.com/v2\",\n mode: \"test\",\n branch: \"next\",\n };\n\n const res = contextModuleBuilder.setCalConfig(customCalConfig).build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.cal).toEqual(customCalConfig);\n });\n\n it(\"should override the default CAL configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customCalConfig: ContextModuleCalConfig = {\n url: \"https://override-cal-service.com/v1\",\n mode: \"prod\",\n branch: \"demo\",\n };\n\n const res = contextModuleBuilder.setCalConfig(customCalConfig).build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(config.cal.url).toBe(customCalConfig.url);\n expect(config.cal.mode).toBe(customCalConfig.mode);\n expect(config.cal.branch).toBe(customCalConfig.branch);\n expect(config.cal.url).not.toBe(\n \"https://crypto-assets-service.api.ledger.com/v1\",\n );\n });\n });\n\n describe(\"setWeb3ChecksConfig\", () => {\n it(\"should set the web3 checks configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customWeb3ChecksConfig = {\n url: \"https://custom-web3checks-service.com/v4\",\n };\n\n const res = contextModuleBuilder\n .setWeb3ChecksConfig(customWeb3ChecksConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.web3checks).toEqual(customWeb3ChecksConfig);\n });\n\n it(\"should override the default web3 checks configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customWeb3ChecksConfig = {\n url: \"https://override-web3checks-service.com/v2\",\n };\n\n const res = contextModuleBuilder\n .setWeb3ChecksConfig(customWeb3ChecksConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(config.web3checks.url).toBe(customWeb3ChecksConfig.url);\n expect(config.web3checks.url).not.toBe(\n \"https://web3checks-backend.api.ledger.com/v3\",\n );\n });\n });\n\n describe(\"setDatasourceConfig\", () => {\n it(\"should set the datasource configuration with safe proxy\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customDatasourceConfig: ContextModuleDatasourceConfig = {\n proxy: \"safe\",\n };\n\n const res = contextModuleBuilder\n .setDatasourceConfig(customDatasourceConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.datasource).toEqual(customDatasourceConfig);\n expect(config.datasource?.proxy).toBe(\"safe\");\n });\n\n it(\"should set the datasource configuration with default proxy\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customDatasourceConfig: ContextModuleDatasourceConfig = {\n proxy: \"default\",\n };\n\n const res = contextModuleBuilder\n .setDatasourceConfig(customDatasourceConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.datasource).toEqual(customDatasourceConfig);\n expect(config.datasource?.proxy).toBe(\"default\");\n });\n\n it(\"should override the default datasource configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customDatasourceConfig: ContextModuleDatasourceConfig = {\n proxy: \"safe\",\n };\n\n const res = contextModuleBuilder\n .setDatasourceConfig(customDatasourceConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(config.datasource?.proxy).toBe(\"safe\");\n expect(config.datasource).not.toBeUndefined();\n });\n\n it(\"should set an empty datasource configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customDatasourceConfig: ContextModuleDatasourceConfig = {};\n\n const res = contextModuleBuilder\n .setDatasourceConfig(customDatasourceConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.datasource).toEqual(customDatasourceConfig);\n expect(config.datasource?.proxy).toBeUndefined();\n });\n });\n\n describe(\"loggerFactory\", () => {\n it(\"should set the loggerFactory when provided in the constructor\", () => {\n const loggerFactory: (tag: string) => LoggerPublisherService = vi.fn();\n\n const contextModuleBuilder = new ContextModuleBuilder({\n ...defaultBuilderArgs,\n loggerFactory,\n });\n\n const res = contextModuleBuilder.build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.loggerFactory).toBe(loggerFactory);\n });\n\n it(\"should set the loggerFactory via setLoggerFactory\", () => {\n const loggerFactory: (tag: string) => LoggerPublisherService = vi.fn();\n\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n\n const res = contextModuleBuilder.setLoggerFactory(loggerFactory).build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.loggerFactory).toBe(loggerFactory);\n });\n\n it(\"should override constructor loggerFactory with setLoggerFactory\", () => {\n const constructorLoggerFactory: (tag: string) => LoggerPublisherService =\n vi.fn();\n const overrideLoggerFactory: (tag: string) => LoggerPublisherService =\n vi.fn();\n\n const contextModuleBuilder = new ContextModuleBuilder({\n ...defaultBuilderArgs,\n loggerFactory: constructorLoggerFactory,\n });\n\n const res = contextModuleBuilder\n .setLoggerFactory(overrideLoggerFactory)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(config.loggerFactory).toBe(overrideLoggerFactory);\n expect(config.loggerFactory).not.toBe(constructorLoggerFactory);\n });\n });\n});\n"],
|
|
5
|
-
"mappings": "AAGA,OAAS,eAAAA,MAAmB,0BAS5B,OAAS,wBAAAC,MAA4B,yBACrC,OAAS,wBAAAC,MAA4B,yBAErC,SAAS,uBAAwB,IAAM,CACrC,MAAMC,EAA2C,CAC/C,IAAK,iBACL,KAAM,OACN,OAAQ,MACV,EACMC,EAA0B,CAC9B,IAAK,uBACP,
|
|
6
|
-
"names": ["configTypes", "ContextModuleBuilder", "DefaultContextModule", "defaultCalConfig", "defaultWeb3ChecksConfig", "defaultBuilderArgs", "res", "contextModuleBuilder", "customLoader", "config", "customMetadataConfig", "customCalConfig", "customWeb3ChecksConfig", "customDatasourceConfig", "loggerFactory", "constructorLoggerFactory", "overrideLoggerFactory"]
|
|
4
|
+
"sourcesContent": ["import { type LoggerPublisherService } from \"@ledgerhq/device-management-kit\";\nimport { type Container } from \"inversify\";\n\nimport { configTypes } from \"./config/di/configTypes\";\nimport { type ContextModuleConstructorArgs } from \"./config/model/ContextModuleBuildArgs\";\nimport {\n type ContextModuleCalConfig,\n type ContextModuleConfig,\n type ContextModuleDatasourceConfig,\n type ContextModuleMetadataServiceConfig,\n} from \"./config/model/ContextModuleConfig\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport { HttpTrustedNameDataSource } from \"./trusted-name/data/HttpTrustedNameDataSource\";\nimport { type TrustedNameDataSource } from \"./trusted-name/data/TrustedNameDataSource\";\nimport { trustedNameTypes } from \"./trusted-name/di/trustedNameTypes\";\nimport { ContextModuleBuilder } from \"./ContextModuleBuilder\";\nimport { DefaultContextModule } from \"./DefaultContextModule\";\n\ndescribe(\"ContextModuleBuilder\", () => {\n const defaultCalConfig: ContextModuleCalConfig = {\n url: \"https://cal/v1\",\n mode: \"prod\",\n branch: \"main\",\n };\n const defaultWeb3ChecksConfig = {\n url: \"https://web3checks/v1\",\n };\n const mockLoggerFactory = () => ({\n debug: vi.fn(),\n info: vi.fn(),\n warn: vi.fn(),\n error: vi.fn(),\n subscribers: [],\n });\n\n const defaultBuilderArgs: ContextModuleConstructorArgs = {\n originToken: \"test\",\n loggerFactory: mockLoggerFactory,\n };\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n it(\"should return a default context module\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n\n const res = contextModuleBuilder.build();\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n });\n\n it(\"should return a custom context module\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customLoader: ContextLoader = {\n load: vi.fn(),\n canHandle: vi.fn() as unknown as ContextLoader[\"canHandle\"],\n };\n\n const res = contextModuleBuilder\n .removeDefaultLoaders()\n .addLoader(customLoader)\n .build();\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n });\n\n it(\"should return a custom context module with a custom typed data loader\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customLoader = { load: vi.fn() };\n\n const res = contextModuleBuilder\n .removeDefaultLoaders()\n .addTypedDataLoader(customLoader)\n .build();\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n // @ts-expect-error _typedDataLoader is private\n expect(res[\"_typedDataLoader\"]).toBe(customLoader);\n });\n\n it(\"should return a custom context module with a custom config\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n\n const res = contextModuleBuilder\n .setCalConfig(defaultCalConfig)\n .setWeb3ChecksConfig(defaultWeb3ChecksConfig)\n .build();\n // @ts-expect-error _container is private\n const config = (res[\"_container\"] as Container).get<ContextModuleConfig>(\n configTypes.Config,\n );\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.cal).toEqual(defaultCalConfig);\n expect(config.web3checks).toEqual(defaultWeb3ChecksConfig);\n });\n\n it(\"should not throw an error if origin token is provided\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n\n expect(() => contextModuleBuilder.build()).not.toThrow();\n });\n\n describe(\"setMetadataServiceConfig\", () => {\n it(\"should set the metadata service configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customMetadataConfig: ContextModuleMetadataServiceConfig = {\n url: \"https://custom-metadata-service.com/v3\",\n };\n\n const res = contextModuleBuilder\n .setMetadataServiceConfig(customMetadataConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.metadataServiceDomain).toEqual(customMetadataConfig);\n });\n\n it(\"should override the default metadata service configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customMetadataConfig: ContextModuleMetadataServiceConfig = {\n url: \"https://override-metadata-service.com/v1\",\n };\n\n const res = contextModuleBuilder\n .setMetadataServiceConfig(customMetadataConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(config.metadataServiceDomain.url).toBe(customMetadataConfig.url);\n expect(config.metadataServiceDomain.url).not.toBe(\n \"https://nft.api.live.ledger.com/v2\",\n );\n });\n });\n\n describe(\"setCalConfig\", () => {\n it(\"should set the CAL configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customCalConfig: ContextModuleCalConfig = {\n url: \"https://custom-cal-service.com/v2\",\n mode: \"test\",\n branch: \"next\",\n };\n\n const res = contextModuleBuilder.setCalConfig(customCalConfig).build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.cal).toEqual(customCalConfig);\n });\n\n it(\"should override the default CAL configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customCalConfig: ContextModuleCalConfig = {\n url: \"https://override-cal-service.com/v1\",\n mode: \"prod\",\n branch: \"demo\",\n };\n\n const res = contextModuleBuilder.setCalConfig(customCalConfig).build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(config.cal.url).toBe(customCalConfig.url);\n expect(config.cal.mode).toBe(customCalConfig.mode);\n expect(config.cal.branch).toBe(customCalConfig.branch);\n expect(config.cal.url).not.toBe(\n \"https://crypto-assets-service.api.ledger.com/v1\",\n );\n });\n });\n\n describe(\"setWeb3ChecksConfig\", () => {\n it(\"should set the web3 checks configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customWeb3ChecksConfig = {\n url: \"https://custom-web3checks-service.com/v4\",\n };\n\n const res = contextModuleBuilder\n .setWeb3ChecksConfig(customWeb3ChecksConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.web3checks).toEqual(customWeb3ChecksConfig);\n });\n\n it(\"should override the default web3 checks configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customWeb3ChecksConfig = {\n url: \"https://override-web3checks-service.com/v2\",\n };\n\n const res = contextModuleBuilder\n .setWeb3ChecksConfig(customWeb3ChecksConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(config.web3checks.url).toBe(customWeb3ChecksConfig.url);\n expect(config.web3checks.url).not.toBe(\n \"https://web3checks-backend.api.ledger.com/v3\",\n );\n });\n });\n\n describe(\"setDatasourceConfig\", () => {\n it(\"should set the datasource configuration with safe proxy\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customDatasourceConfig: ContextModuleDatasourceConfig = {\n proxy: \"safe\",\n };\n\n const res = contextModuleBuilder\n .setDatasourceConfig(customDatasourceConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.datasource).toEqual(customDatasourceConfig);\n expect(config.datasource?.proxy).toBe(\"safe\");\n });\n\n it(\"should set the datasource configuration with default proxy\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customDatasourceConfig: ContextModuleDatasourceConfig = {\n proxy: \"default\",\n };\n\n const res = contextModuleBuilder\n .setDatasourceConfig(customDatasourceConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.datasource).toEqual(customDatasourceConfig);\n expect(config.datasource?.proxy).toBe(\"default\");\n });\n\n it(\"should override the default datasource configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customDatasourceConfig: ContextModuleDatasourceConfig = {\n proxy: \"safe\",\n };\n\n const res = contextModuleBuilder\n .setDatasourceConfig(customDatasourceConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(config.datasource?.proxy).toBe(\"safe\");\n expect(config.datasource).not.toBeUndefined();\n });\n\n it(\"should set an empty datasource configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customDatasourceConfig: ContextModuleDatasourceConfig = {};\n\n const res = contextModuleBuilder\n .setDatasourceConfig(customDatasourceConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.datasource).toEqual(customDatasourceConfig);\n expect(config.datasource?.proxy).toBeUndefined();\n });\n });\n\n describe(\"loggerFactory\", () => {\n it(\"should set the loggerFactory when provided in the constructor\", () => {\n const loggerFactory: (tag: string) => LoggerPublisherService = vi.fn();\n\n const contextModuleBuilder = new ContextModuleBuilder({\n ...defaultBuilderArgs,\n loggerFactory,\n });\n\n const res = contextModuleBuilder.build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.loggerFactory).toBe(loggerFactory);\n });\n\n it(\"should set the loggerFactory via setLoggerFactory\", () => {\n const loggerFactory: (tag: string) => LoggerPublisherService = vi.fn();\n\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n\n const res = contextModuleBuilder.setLoggerFactory(loggerFactory).build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.loggerFactory).toBe(loggerFactory);\n });\n\n it(\"should override constructor loggerFactory with setLoggerFactory\", () => {\n const constructorLoggerFactory: (tag: string) => LoggerPublisherService =\n vi.fn();\n const overrideLoggerFactory: (tag: string) => LoggerPublisherService =\n vi.fn();\n\n const contextModuleBuilder = new ContextModuleBuilder({\n ...defaultBuilderArgs,\n loggerFactory: constructorLoggerFactory,\n });\n\n const res = contextModuleBuilder\n .setLoggerFactory(overrideLoggerFactory)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(config.loggerFactory).toBe(overrideLoggerFactory);\n expect(config.loggerFactory).not.toBe(constructorLoggerFactory);\n });\n });\n\n describe(\"setTrustedNameDataSource\", () => {\n it(\"should set a custom trusted name data source\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customDataSource: TrustedNameDataSource = {\n getDomainNamePayload: vi.fn(),\n getTrustedNamePayload: vi.fn(),\n };\n\n const res = contextModuleBuilder\n .setTrustedNameDataSource(customDataSource)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.customTrustedNameDataSource).toBe(customDataSource);\n });\n\n it(\"should inject the custom data source into the container\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customDataSource: TrustedNameDataSource = {\n getDomainNamePayload: vi.fn(),\n getTrustedNamePayload: vi.fn(),\n };\n\n const res = contextModuleBuilder\n .setTrustedNameDataSource(customDataSource)\n .build();\n const injectedDataSource = (res as DefaultContextModule)[\n \"_container\"\n ].get<TrustedNameDataSource>(trustedNameTypes.TrustedNameDataSource);\n\n expect(injectedDataSource).toBe(customDataSource);\n });\n\n it(\"should use HttpTrustedNameDataSource when no custom data source is set\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n\n const res = contextModuleBuilder.build();\n const injectedDataSource = (res as DefaultContextModule)[\n \"_container\"\n ].get<TrustedNameDataSource>(trustedNameTypes.TrustedNameDataSource);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(injectedDataSource).toBeInstanceOf(HttpTrustedNameDataSource);\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "AAGA,OAAS,eAAAA,MAAmB,0BAS5B,OAAS,6BAAAC,MAAiC,gDAE1C,OAAS,oBAAAC,MAA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AAY,MAAM,EAE7C,OAAOQ,CAAG,EAAE,eAAeJ,CAAoB,EAC/C,OAAOO,EAAO,2BAA2B,EAAE,KAAKQ,CAAgB,CAClE,CAAC,EAED,GAAG,0DAA2D,IAAM,CAClE,MAAMV,EAAuB,IAAIN,EAAqBI,CAAkB,EAClEY,EAA0C,CAC9C,qBAAsB,GAAG,GAAG,EAC5B,sBAAuB,GAAG,GAAG,CAC/B,EAKMC,EAHMX,EACT,yBAAyBU,CAAgB,EACzC,MAAM,EAEP,WACA,IAA2BjB,EAAiB,qBAAqB,EAEnE,OAAOkB,CAAkB,EAAE,KAAKD,CAAgB,CAClD,CAAC,EAED,GAAG,yEAA0E,IAAM,CAGjF,MAAMX,EAFuB,IAAIL,EAAqBI,CAAkB,EAEvC,MAAM,EACjCa,EAAsBZ,EAC1B,WACA,IAA2BN,EAAiB,qBAAqB,EAEnE,OAAOM,CAAG,EAAE,eAAeJ,CAAoB,EAC/C,OAAOgB,CAAkB,EAAE,eAAenB,CAAyB,CACrE,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["configTypes", "HttpTrustedNameDataSource", "trustedNameTypes", "ContextModuleBuilder", "DefaultContextModule", "defaultCalConfig", "defaultWeb3ChecksConfig", "defaultBuilderArgs", "res", "contextModuleBuilder", "customLoader", "config", "customMetadataConfig", "customCalConfig", "customWeb3ChecksConfig", "customDatasourceConfig", "loggerFactory", "constructorLoggerFactory", "overrideLoggerFactory", "customDataSource", "injectedDataSource"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{ClearSignContextType as o}from"./shared/model/ClearSignContext";import{
|
|
1
|
+
import{ClearSignContextType as o}from"./shared/model/ClearSignContext";import{DefaultContextModule as d}from"./DefaultContextModule";const x=()=>({debug:vi.fn(),info:vi.fn(),warn:vi.fn(),error:vi.fn(),subscribers:[]}),u=i=>({load:vi.fn(),canHandle:vi.fn().mockReturnValue(i)}),r=()=>({canHandle:vi.fn(),loadField:vi.fn()});describe("DefaultContextModule",()=>{const i={load:vi.fn()},l={customLoaders:[],defaultLoaders:!1,defaultFieldLoaders:!1,customFieldLoaders:[],customTypedDataLoader:i,cal:{url:"https://cal/v1",mode:"prod",branch:"main"},web3checks:{url:"https://web3checks/v3"},metadataServiceDomain:{url:"https://metadata.com"},originToken:"originToken",loggerFactory:x};beforeEach(()=>{vi.restoreAllMocks()}),it("should initialize the context module with all the default loaders",async()=>{const t=await new d(l).getContexts({});expect(t).toEqual([])}),it("should return an empty array when no loaders",async()=>{const t=await new d(l).getContexts({});expect(t).toEqual([])}),it("should call all fetch method from metadata fetcher",async()=>{const e=u(!0);await new d({...l,customLoaders:[e,e]}).getContexts({}),expect(e.canHandle).toHaveBeenCalledTimes(2),expect(e.load).toHaveBeenCalledTimes(2)}),it("should return an array of context response",async()=>{const e=u(!0),t=[[{type:"provideERC20Info",payload:"payload1"}],[{type:"provideERC20Info",payload:"payload2"},{type:"plugin",payload:"payload3"}]];vi.spyOn(e,"load").mockResolvedValueOnce(t[0]).mockResolvedValueOnce(t[1]);const a=await new d({...l,customLoaders:[e,e]}).getContexts({});expect(e.canHandle).toHaveBeenCalledTimes(2),expect(e.load).toHaveBeenCalledTimes(2),expect(a).toEqual(t.flat())}),it("should only call loaders that can handle the input",async()=>{const e=u(!0),t=u(!0);vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(t,"canHandle").mockReturnValue(!1),vi.spyOn(e,"load").mockResolvedValue([{type:o.TOKEN,payload:"payload1"}]),vi.spyOn(t,"load").mockResolvedValue([{type:o.NFT,payload:"payload2"}]);const n=new d({...l,customLoaders:[e,t]}),a={to:"0x123",selector:"0xabc"},s=await n.getContexts(a);expect(e.canHandle).toHaveBeenCalledWith(a,Object.values(o)),expect(t.canHandle).toHaveBeenCalledWith(a,Object.values(o)),expect(e.load).toHaveBeenCalledWith(a),expect(t.load).not.toHaveBeenCalled(),expect(s).toEqual([{type:"token",payload:"payload1"}])}),it("should use expected types if provided",async()=>{const e=u(!0);vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(e,"load").mockResolvedValue([{type:o.TOKEN,payload:"payload1"}]);const t=new d({...l,customLoaders:[e]}),n={to:"0x123",selector:"0xabc"};await t.getContexts(n,[o.TOKEN]),expect(e.canHandle).toHaveBeenCalledWith(n,[o.TOKEN])}),it("should call the typed data loader",async()=>{await new d({...l,customTypedDataLoader:i}).getTypedDataFilters({}),expect(i.load).toHaveBeenCalledTimes(1)}),describe("getFieldContext",()=>{it("should return error when no loader can handle the field",async()=>{const e=r();vi.spyOn(e,"canHandle").mockReturnValue(!1);const t=new d({...l,customFieldLoaders:[e]}),n={type:"unknown"},a=await t.getFieldContext(n,o.TOKEN);expect(e.canHandle).toHaveBeenCalledWith(n,o.TOKEN),expect(e.loadField).not.toHaveBeenCalled(),expect(a).toEqual({type:o.ERROR,error:new Error(`Loader not found for field: ${n} and expected type: ${o.TOKEN}`)})}),it("should return context when a loader can handle the field",async()=>{const e=r(),t={type:o.TOKEN,payload:"test-payload"};vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(e,"loadField").mockResolvedValue(t);const n=new d({...l,customFieldLoaders:[e]}),a={type:"token",address:"0x123"},s=await n.getFieldContext(a,o.TOKEN);expect(e.canHandle).toHaveBeenCalledWith(a,o.TOKEN),expect(e.loadField).toHaveBeenCalledWith(a),expect(s).toEqual(t)}),it("should return first context when multiple loaders can handle the field",async()=>{const e=r(),t=r(),n={type:o.TOKEN,payload:"first-payload"},a={type:o.NFT,payload:"second-payload"};vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(t,"canHandle").mockReturnValue(!0),vi.spyOn(e,"loadField").mockResolvedValue(n),vi.spyOn(t,"loadField").mockResolvedValue(a);const s=new d({...l,customFieldLoaders:[e,t]}),c={type:"multi",address:"0x123"},p=await s.getFieldContext(c,o.TOKEN);expect(e.canHandle).toHaveBeenCalledWith(c,o.TOKEN),expect(t.canHandle).toHaveBeenCalledWith(c,o.TOKEN),expect(e.loadField).toHaveBeenCalledWith(c),expect(t.loadField).not.toHaveBeenCalled(),expect(p).toEqual(n)}),it("should return second context when first context is an error",async()=>{const e=r(),t=r(),n={type:o.ERROR,error:new Error("first-error")},a={type:o.TOKEN,payload:"second-payload"};vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(t,"canHandle").mockReturnValue(!0),vi.spyOn(e,"loadField").mockResolvedValue(n),vi.spyOn(t,"loadField").mockResolvedValue(a);const s=new d({...l,customFieldLoaders:[e,t]}),c={type:"error",address:"0x123"},p=await s.getFieldContext(c,o.TOKEN);expect(e.canHandle).toHaveBeenCalledWith(c,o.TOKEN),expect(t.canHandle).toHaveBeenCalledWith(c,o.TOKEN),expect(e.loadField).toHaveBeenCalledWith(c),expect(t.loadField).toHaveBeenCalledWith(c),expect(p).toEqual(a)}),it("should handle loader rejection gracefully",async()=>{const e=r(),t=new Error("Load field failed");vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(e,"loadField").mockRejectedValue(t);const n=new d({...l,customFieldLoaders:[e]}),a={type:"error",address:"0x123"};await expect(n.getFieldContext(a,o.TOKEN)).rejects.toThrow("Load field failed"),expect(e.canHandle).toHaveBeenCalledWith(a,o.TOKEN),expect(e.loadField).toHaveBeenCalledWith(a)})})});
|
|
2
2
|
//# sourceMappingURL=DefaultContextModule.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/DefaultContextModule.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { type ContextModuleConfig } from \"./config/model/ContextModuleConfig\";\nimport { type ContextFieldLoader } from \"./shared/domain/ContextFieldLoader\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport {\n type ClearSignContext,\n ClearSignContextType,\n} from \"./shared/model/ClearSignContext\";\nimport { type TypedDataContext } from \"./shared/model/TypedDataContext\";\nimport { NullLoggerPublisherService } from \"./shared/utils/NullLoggerPublisherService\";\nimport type { TypedDataContextLoader } from \"./typed-data/domain/TypedDataContextLoader\";\nimport { DefaultContextModule } from \"./DefaultContextModule\";\n\nconst contextLoaderStubBuilder = (canHandle: boolean): ContextLoader => {\n return {\n load: vi.fn(),\n canHandle: vi\n .fn()\n .mockReturnValue(canHandle) as unknown as ContextLoader[\"canHandle\"],\n };\n};\n\nconst fieldLoaderStubBuilder = (): ContextFieldLoader => {\n return {\n canHandle: vi.fn() as unknown as ContextFieldLoader[\"canHandle\"],\n loadField: vi.fn(),\n };\n};\n\ndescribe(\"DefaultContextModule\", () => {\n const typedDataLoader: TypedDataContextLoader = { load: vi.fn() };\n const defaultContextModuleConfig: ContextModuleConfig = {\n customLoaders: [],\n defaultLoaders: false,\n defaultFieldLoaders: false,\n customFieldLoaders: [],\n customTypedDataLoader: typedDataLoader,\n cal: {\n url: \"https://cal/v1\",\n mode: \"prod\",\n branch: \"main\",\n },\n web3checks: {\n url: \"https://web3checks/v3\",\n },\n metadataServiceDomain: {\n url: \"https://metadata.com\",\n },\n originToken: \"originToken\",\n loggerFactory: NullLoggerPublisherService,\n };\n\n beforeEach(() => {\n vi.restoreAllMocks();\n });\n\n it(\"should initialize the context module with all the default loaders\", async () => {\n const contextModule = new DefaultContextModule(defaultContextModuleConfig);\n\n const res = await contextModule.getContexts({});\n\n expect(res).toEqual([]);\n });\n\n it(\"should return an empty array when no loaders\", async () => {\n const contextModule = new DefaultContextModule(defaultContextModuleConfig);\n\n const res = await contextModule.getContexts({});\n\n expect(res).toEqual([]);\n });\n\n it(\"should call all fetch method from metadata fetcher\", async () => {\n const loader = contextLoaderStubBuilder(true);\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader, loader],\n });\n\n await contextModule.getContexts({});\n\n expect(loader.canHandle).toHaveBeenCalledTimes(2);\n expect(loader.load).toHaveBeenCalledTimes(2);\n });\n\n it(\"should return an array of context response\", async () => {\n const loader = contextLoaderStubBuilder(true);\n const responses = [\n [{ type: \"provideERC20Info\", payload: \"payload1\" }],\n [\n { type: \"provideERC20Info\", payload: \"payload2\" },\n { type: \"plugin\", payload: \"payload3\" },\n ],\n ] as ClearSignContext[][];\n vi.spyOn(loader, \"load\")\n .mockResolvedValueOnce(responses[0]!)\n .mockResolvedValueOnce(responses[1]!);\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader, loader],\n });\n\n const res = await contextModule.getContexts({});\n\n expect(loader.canHandle).toHaveBeenCalledTimes(2);\n expect(loader.load).toHaveBeenCalledTimes(2);\n expect(res).toEqual(responses.flat());\n });\n\n it(\"should only call loaders that can handle the input\", async () => {\n const loader1 = contextLoaderStubBuilder(true);\n const loader2 = contextLoaderStubBuilder(true);\n\n vi.spyOn(loader1, \"canHandle\").mockReturnValue(true);\n vi.spyOn(loader2, \"canHandle\").mockReturnValue(false);\n vi.spyOn(loader1, \"load\").mockResolvedValue([\n { type: ClearSignContextType.TOKEN, payload: \"payload1\" },\n ]);\n vi.spyOn(loader2, \"load\").mockResolvedValue([\n { type: ClearSignContextType.NFT, payload: \"payload2\" },\n ]);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader1, loader2],\n });\n\n const testInput = { to: \"0x123\", selector: \"0xabc\" };\n const res = await contextModule.getContexts(testInput);\n\n expect(loader1.canHandle).toHaveBeenCalledWith(\n testInput,\n Object.values(ClearSignContextType),\n );\n expect(loader2.canHandle).toHaveBeenCalledWith(\n testInput,\n Object.values(ClearSignContextType),\n );\n expect(loader1.load).toHaveBeenCalledWith(testInput);\n expect(loader2.load).not.toHaveBeenCalled(); // Should not be called since canHandle returned false\n expect(res).toEqual([{ type: \"token\", payload: \"payload1\" }]);\n });\n\n it(\"should use expected types if provided\", async () => {\n const loader = contextLoaderStubBuilder(true);\n\n vi.spyOn(loader, \"canHandle\").mockReturnValue(true);\n\n vi.spyOn(loader, \"load\").mockResolvedValue([\n { type: ClearSignContextType.TOKEN, payload: \"payload1\" },\n ]);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader],\n });\n\n const testInput = { to: \"0x123\", selector: \"0xabc\" };\n await contextModule.getContexts(testInput, [ClearSignContextType.TOKEN]);\n\n expect(loader.canHandle).toHaveBeenCalledWith(testInput, [\n ClearSignContextType.TOKEN,\n ]);\n });\n\n it(\"should call the typed data loader\", async () => {\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customTypedDataLoader: typedDataLoader,\n });\n\n await contextModule.getTypedDataFilters({} as TypedDataContext);\n\n expect(typedDataLoader.load).toHaveBeenCalledTimes(1);\n });\n\n describe(\"getFieldContext\", () => {\n it(\"should return error when no loader can handle the field\", async () => {\n // GIVEN\n const fieldLoader = fieldLoaderStubBuilder();\n vi.spyOn(fieldLoader, \"canHandle\").mockReturnValue(false);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader],\n });\n\n const testField = { type: \"unknown\" };\n\n // WHEN\n const result = await contextModule.getFieldContext(\n testField,\n ClearSignContextType.TOKEN,\n );\n\n // THEN\n expect(fieldLoader.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader.loadField).not.toHaveBeenCalled();\n expect(result).toEqual({\n type: ClearSignContextType.ERROR,\n error: new Error(\n `Loader not found for field: ${testField} and expected type: ${ClearSignContextType.TOKEN}`,\n ),\n });\n });\n\n it(\"should return context when a loader can handle the field\", async () => {\n // GIVEN\n const fieldLoader = fieldLoaderStubBuilder();\n const mockContext: ClearSignContext = {\n type: ClearSignContextType.TOKEN,\n payload: \"test-payload\",\n };\n\n vi.spyOn(fieldLoader, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader, \"loadField\").mockResolvedValue(mockContext);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader],\n });\n\n const testField = { type: \"token\", address: \"0x123\" };\n\n // WHEN\n const result = await contextModule.getFieldContext(\n testField,\n ClearSignContextType.TOKEN,\n );\n\n // THEN\n expect(fieldLoader.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader.loadField).toHaveBeenCalledWith(testField);\n expect(result).toEqual(mockContext);\n });\n\n it(\"should return first context when multiple loaders can handle the field\", async () => {\n // GIVEN\n const fieldLoader1 = fieldLoaderStubBuilder();\n const fieldLoader2 = fieldLoaderStubBuilder();\n\n const mockContext1: ClearSignContext = {\n type: ClearSignContextType.TOKEN,\n payload: \"first-payload\",\n };\n const mockContext2: ClearSignContext = {\n type: ClearSignContextType.NFT,\n payload: \"second-payload\",\n };\n\n vi.spyOn(fieldLoader1, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader2, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader1, \"loadField\").mockResolvedValue(mockContext1);\n vi.spyOn(fieldLoader2, \"loadField\").mockResolvedValue(mockContext2);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader1, fieldLoader2],\n });\n\n const testField = { type: \"multi\", address: \"0x123\" };\n\n // WHEN\n const result = await contextModule.getFieldContext(\n testField,\n ClearSignContextType.TOKEN,\n );\n\n // THEN\n expect(fieldLoader1.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader2.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader1.loadField).toHaveBeenCalledWith(testField);\n expect(fieldLoader2.loadField).not.toHaveBeenCalled();\n expect(result).toEqual(mockContext1); // Should return first context\n });\n\n it(\"should return second context when first context is an error\", async () => {\n // GIVEN\n const fieldLoader1 = fieldLoaderStubBuilder();\n const fieldLoader2 = fieldLoaderStubBuilder();\n const mockContext1: ClearSignContext = {\n type: ClearSignContextType.ERROR,\n error: new Error(\"first-error\"),\n };\n const mockContext2: ClearSignContext = {\n type: ClearSignContextType.TOKEN,\n payload: \"second-payload\",\n };\n vi.spyOn(fieldLoader1, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader2, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader1, \"loadField\").mockResolvedValue(mockContext1);\n vi.spyOn(fieldLoader2, \"loadField\").mockResolvedValue(mockContext2);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader1, fieldLoader2],\n });\n\n const testField = { type: \"error\", address: \"0x123\" };\n\n // WHEN\n const result = await contextModule.getFieldContext(\n testField,\n ClearSignContextType.TOKEN,\n );\n\n // THEN\n expect(fieldLoader1.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader2.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader1.loadField).toHaveBeenCalledWith(testField);\n expect(fieldLoader2.loadField).toHaveBeenCalledWith(testField);\n expect(result).toEqual(mockContext2);\n });\n\n it(\"should handle loader rejection gracefully\", async () => {\n // GIVEN\n const fieldLoader = fieldLoaderStubBuilder();\n const loadError = new Error(\"Load field failed\");\n\n vi.spyOn(fieldLoader, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader, \"loadField\").mockRejectedValue(loadError);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader],\n });\n\n const testField = { type: \"error\", address: \"0x123\" };\n\n // WHEN & THEN\n await expect(\n contextModule.getFieldContext(testField, ClearSignContextType.TOKEN),\n ).rejects.toThrow(\"Load field failed\");\n\n expect(fieldLoader.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader.loadField).toHaveBeenCalledWith(testField);\n });\n });\n});\n"],
|
|
5
|
-
"mappings": "AAGA,OAEE,wBAAAA,MACK,
|
|
6
|
-
"names": ["ClearSignContextType", "
|
|
4
|
+
"sourcesContent": ["import { type ContextModuleConfig } from \"./config/model/ContextModuleConfig\";\nimport { type ContextFieldLoader } from \"./shared/domain/ContextFieldLoader\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport {\n type ClearSignContext,\n ClearSignContextType,\n} from \"./shared/model/ClearSignContext\";\nimport { type TypedDataContext } from \"./shared/model/TypedDataContext\";\nimport type { TypedDataContextLoader } from \"./typed-data/domain/TypedDataContextLoader\";\nimport { DefaultContextModule } from \"./DefaultContextModule\";\n\nconst mockLoggerFactory = () => ({\n debug: vi.fn(),\n info: vi.fn(),\n warn: vi.fn(),\n error: vi.fn(),\n subscribers: [],\n});\n\nconst contextLoaderStubBuilder = (canHandle: boolean): ContextLoader => {\n return {\n load: vi.fn(),\n canHandle: vi\n .fn()\n .mockReturnValue(canHandle) as unknown as ContextLoader[\"canHandle\"],\n };\n};\n\nconst fieldLoaderStubBuilder = (): ContextFieldLoader => {\n return {\n canHandle: vi.fn() as unknown as ContextFieldLoader[\"canHandle\"],\n loadField: vi.fn(),\n };\n};\n\ndescribe(\"DefaultContextModule\", () => {\n const typedDataLoader: TypedDataContextLoader = { load: vi.fn() };\n const defaultContextModuleConfig: ContextModuleConfig = {\n customLoaders: [],\n defaultLoaders: false,\n defaultFieldLoaders: false,\n customFieldLoaders: [],\n customTypedDataLoader: typedDataLoader,\n cal: {\n url: \"https://cal/v1\",\n mode: \"prod\",\n branch: \"main\",\n },\n web3checks: {\n url: \"https://web3checks/v3\",\n },\n metadataServiceDomain: {\n url: \"https://metadata.com\",\n },\n originToken: \"originToken\",\n loggerFactory: mockLoggerFactory,\n };\n\n beforeEach(() => {\n vi.restoreAllMocks();\n });\n\n it(\"should initialize the context module with all the default loaders\", async () => {\n const contextModule = new DefaultContextModule(defaultContextModuleConfig);\n\n const res = await contextModule.getContexts({});\n\n expect(res).toEqual([]);\n });\n\n it(\"should return an empty array when no loaders\", async () => {\n const contextModule = new DefaultContextModule(defaultContextModuleConfig);\n\n const res = await contextModule.getContexts({});\n\n expect(res).toEqual([]);\n });\n\n it(\"should call all fetch method from metadata fetcher\", async () => {\n const loader = contextLoaderStubBuilder(true);\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader, loader],\n });\n\n await contextModule.getContexts({});\n\n expect(loader.canHandle).toHaveBeenCalledTimes(2);\n expect(loader.load).toHaveBeenCalledTimes(2);\n });\n\n it(\"should return an array of context response\", async () => {\n const loader = contextLoaderStubBuilder(true);\n const responses = [\n [{ type: \"provideERC20Info\", payload: \"payload1\" }],\n [\n { type: \"provideERC20Info\", payload: \"payload2\" },\n { type: \"plugin\", payload: \"payload3\" },\n ],\n ] as ClearSignContext[][];\n vi.spyOn(loader, \"load\")\n .mockResolvedValueOnce(responses[0]!)\n .mockResolvedValueOnce(responses[1]!);\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader, loader],\n });\n\n const res = await contextModule.getContexts({});\n\n expect(loader.canHandle).toHaveBeenCalledTimes(2);\n expect(loader.load).toHaveBeenCalledTimes(2);\n expect(res).toEqual(responses.flat());\n });\n\n it(\"should only call loaders that can handle the input\", async () => {\n const loader1 = contextLoaderStubBuilder(true);\n const loader2 = contextLoaderStubBuilder(true);\n\n vi.spyOn(loader1, \"canHandle\").mockReturnValue(true);\n vi.spyOn(loader2, \"canHandle\").mockReturnValue(false);\n vi.spyOn(loader1, \"load\").mockResolvedValue([\n { type: ClearSignContextType.TOKEN, payload: \"payload1\" },\n ]);\n vi.spyOn(loader2, \"load\").mockResolvedValue([\n { type: ClearSignContextType.NFT, payload: \"payload2\" },\n ]);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader1, loader2],\n });\n\n const testInput = { to: \"0x123\", selector: \"0xabc\" };\n const res = await contextModule.getContexts(testInput);\n\n expect(loader1.canHandle).toHaveBeenCalledWith(\n testInput,\n Object.values(ClearSignContextType),\n );\n expect(loader2.canHandle).toHaveBeenCalledWith(\n testInput,\n Object.values(ClearSignContextType),\n );\n expect(loader1.load).toHaveBeenCalledWith(testInput);\n expect(loader2.load).not.toHaveBeenCalled(); // Should not be called since canHandle returned false\n expect(res).toEqual([{ type: \"token\", payload: \"payload1\" }]);\n });\n\n it(\"should use expected types if provided\", async () => {\n const loader = contextLoaderStubBuilder(true);\n\n vi.spyOn(loader, \"canHandle\").mockReturnValue(true);\n\n vi.spyOn(loader, \"load\").mockResolvedValue([\n { type: ClearSignContextType.TOKEN, payload: \"payload1\" },\n ]);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader],\n });\n\n const testInput = { to: \"0x123\", selector: \"0xabc\" };\n await contextModule.getContexts(testInput, [ClearSignContextType.TOKEN]);\n\n expect(loader.canHandle).toHaveBeenCalledWith(testInput, [\n ClearSignContextType.TOKEN,\n ]);\n });\n\n it(\"should call the typed data loader\", async () => {\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customTypedDataLoader: typedDataLoader,\n });\n\n await contextModule.getTypedDataFilters({} as TypedDataContext);\n\n expect(typedDataLoader.load).toHaveBeenCalledTimes(1);\n });\n\n describe(\"getFieldContext\", () => {\n it(\"should return error when no loader can handle the field\", async () => {\n // GIVEN\n const fieldLoader = fieldLoaderStubBuilder();\n vi.spyOn(fieldLoader, \"canHandle\").mockReturnValue(false);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader],\n });\n\n const testField = { type: \"unknown\" };\n\n // WHEN\n const result = await contextModule.getFieldContext(\n testField,\n ClearSignContextType.TOKEN,\n );\n\n // THEN\n expect(fieldLoader.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader.loadField).not.toHaveBeenCalled();\n expect(result).toEqual({\n type: ClearSignContextType.ERROR,\n error: new Error(\n `Loader not found for field: ${testField} and expected type: ${ClearSignContextType.TOKEN}`,\n ),\n });\n });\n\n it(\"should return context when a loader can handle the field\", async () => {\n // GIVEN\n const fieldLoader = fieldLoaderStubBuilder();\n const mockContext: ClearSignContext = {\n type: ClearSignContextType.TOKEN,\n payload: \"test-payload\",\n };\n\n vi.spyOn(fieldLoader, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader, \"loadField\").mockResolvedValue(mockContext);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader],\n });\n\n const testField = { type: \"token\", address: \"0x123\" };\n\n // WHEN\n const result = await contextModule.getFieldContext(\n testField,\n ClearSignContextType.TOKEN,\n );\n\n // THEN\n expect(fieldLoader.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader.loadField).toHaveBeenCalledWith(testField);\n expect(result).toEqual(mockContext);\n });\n\n it(\"should return first context when multiple loaders can handle the field\", async () => {\n // GIVEN\n const fieldLoader1 = fieldLoaderStubBuilder();\n const fieldLoader2 = fieldLoaderStubBuilder();\n\n const mockContext1: ClearSignContext = {\n type: ClearSignContextType.TOKEN,\n payload: \"first-payload\",\n };\n const mockContext2: ClearSignContext = {\n type: ClearSignContextType.NFT,\n payload: \"second-payload\",\n };\n\n vi.spyOn(fieldLoader1, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader2, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader1, \"loadField\").mockResolvedValue(mockContext1);\n vi.spyOn(fieldLoader2, \"loadField\").mockResolvedValue(mockContext2);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader1, fieldLoader2],\n });\n\n const testField = { type: \"multi\", address: \"0x123\" };\n\n // WHEN\n const result = await contextModule.getFieldContext(\n testField,\n ClearSignContextType.TOKEN,\n );\n\n // THEN\n expect(fieldLoader1.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader2.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader1.loadField).toHaveBeenCalledWith(testField);\n expect(fieldLoader2.loadField).not.toHaveBeenCalled();\n expect(result).toEqual(mockContext1); // Should return first context\n });\n\n it(\"should return second context when first context is an error\", async () => {\n // GIVEN\n const fieldLoader1 = fieldLoaderStubBuilder();\n const fieldLoader2 = fieldLoaderStubBuilder();\n const mockContext1: ClearSignContext = {\n type: ClearSignContextType.ERROR,\n error: new Error(\"first-error\"),\n };\n const mockContext2: ClearSignContext = {\n type: ClearSignContextType.TOKEN,\n payload: \"second-payload\",\n };\n vi.spyOn(fieldLoader1, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader2, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader1, \"loadField\").mockResolvedValue(mockContext1);\n vi.spyOn(fieldLoader2, \"loadField\").mockResolvedValue(mockContext2);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader1, fieldLoader2],\n });\n\n const testField = { type: \"error\", address: \"0x123\" };\n\n // WHEN\n const result = await contextModule.getFieldContext(\n testField,\n ClearSignContextType.TOKEN,\n );\n\n // THEN\n expect(fieldLoader1.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader2.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader1.loadField).toHaveBeenCalledWith(testField);\n expect(fieldLoader2.loadField).toHaveBeenCalledWith(testField);\n expect(result).toEqual(mockContext2);\n });\n\n it(\"should handle loader rejection gracefully\", async () => {\n // GIVEN\n const fieldLoader = fieldLoaderStubBuilder();\n const loadError = new Error(\"Load field failed\");\n\n vi.spyOn(fieldLoader, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader, \"loadField\").mockRejectedValue(loadError);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader],\n });\n\n const testField = { type: \"error\", address: \"0x123\" };\n\n // WHEN & THEN\n await expect(\n contextModule.getFieldContext(testField, ClearSignContextType.TOKEN),\n ).rejects.toThrow(\"Load field failed\");\n\n expect(fieldLoader.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader.loadField).toHaveBeenCalledWith(testField);\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "AAGA,OAEE,wBAAAA,MACK,kCAGP,OAAS,wBAAAC,MAA4B,yBAErC,MAAMC,EAAoB,KAAO,CAC/B,MAAO,GAAG,GAAG,EACb,KAAM,GAAG,GAAG,EACZ,KAAM,GAAG,GAAG,EACZ,MAAO,GAAG,GAAG,EACb,YAAa,CAAC,CAChB,GAEMC,EAA4BC,IACzB,CACL,KAAM,GAAG,GAAG,EACZ,UAAW,GACR,GAAG,EACH,gBAAgBA,CAAS,CAC9B,GAGIC,EAAyB,KACtB,CACL,UAAW,GAAG,GAAG,EACjB,UAAW,GAAG,GAAG,CACnB,GAGF,SAAS,uBAAwB,IAAM,CACrC,MAAMC,EAA0C,CAAE,KAAM,GAAG,GAAG,CAAE,EAC1DC,EAAkD,CACtD,cAAe,CAAC,EAChB,eAAgB,GAChB,oBAAqB,GACrB,mBAAoB,CAAC,EACrB,sBAAuBD,EACvB,IAAK,CACH,IAAK,iBACL,KAAM,OACN,OAAQ,MACV,EACA,WAAY,CACV,IAAK,uBACP,EACA,sBAAuB,CACrB,IAAK,sBACP,EACA,YAAa,cACb,cAAeJ,CACjB,EAEA,WAAW,IAAM,CACf,GAAG,gBAAgB,CACrB,CAAC,EAED,GAAG,oEAAqE,SAAY,CAGlF,MAAMM,EAAM,MAFU,IAAIP,EAAqBM,CAA0B,EAEzC,YAAY,CAAC,CAAC,EAE9C,OAAOC,CAAG,EAAE,QAAQ,CAAC,CAAC,CACxB,CAAC,EAED,GAAG,+CAAgD,SAAY,CAG7D,MAAMA,EAAM,MAFU,IAAIP,EAAqBM,CAA0B,EAEzC,YAAY,CAAC,CAAC,EAE9C,OAAOC,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C7C,GAAGM,EACH,mBAAoB,CAACY,EAAcC,CAAY,CACjD,CAAC,EAEKJ,EAAY,CAAE,KAAM,QAAS,QAAS,OAAQ,EAG9CC,EAAS,MAAMJ,EAAc,gBACjCG,EACAhB,EAAqB,KACvB,EAGA,OAAOmB,EAAa,SAAS,EAAE,qBAC7BH,EACAhB,EAAqB,KACvB,EACA,OAAOoB,EAAa,SAAS,EAAE,qBAC7BJ,EACAhB,EAAqB,KACvB,EACA,OAAOmB,EAAa,SAAS,EAAE,qBAAqBH,CAAS,EAC7D,OAAOI,EAAa,SAAS,EAAE,qBAAqBJ,CAAS,EAC7D,OAAOC,CAAM,EAAE,QAAQK,CAAY,CACrC,CAAC,EAED,GAAG,4CAA6C,SAAY,CAE1D,MAAMP,EAAcV,EAAuB,EACrCkB,EAAY,IAAI,MAAM,mBAAmB,EAE/C,GAAG,MAAMR,EAAa,WAAW,EAAE,gBAAgB,EAAI,EACvD,GAAG,MAAMA,EAAa,WAAW,EAAE,kBAAkBQ,CAAS,EAE9D,MAAMV,EAAgB,IAAIZ,EAAqB,CAC7C,GAAGM,EACH,mBAAoB,CAACQ,CAAW,CAClC,CAAC,EAEKC,EAAY,CAAE,KAAM,QAAS,QAAS,OAAQ,EAGpD,MAAM,OACJH,EAAc,gBAAgBG,EAAWhB,EAAqB,KAAK,CACrE,EAAE,QAAQ,QAAQ,mBAAmB,EAErC,OAAOe,EAAY,SAAS,EAAE,qBAC5BC,EACAhB,EAAqB,KACvB,EACA,OAAOe,EAAY,SAAS,EAAE,qBAAqBC,CAAS,CAC9D,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["ClearSignContextType", "DefaultContextModule", "mockLoggerFactory", "contextLoaderStubBuilder", "canHandle", "fieldLoaderStubBuilder", "typedDataLoader", "defaultContextModuleConfig", "res", "loader", "responses", "loader1", "loader2", "contextModule", "testInput", "fieldLoader", "testField", "result", "mockContext", "fieldLoader1", "fieldLoader2", "mockContext1", "mockContext2", "loadError"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var D=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var S=(d,e,t,a)=>{for(var r=a>1?void 0:a?I(e,t):e,o=d.length-1,s;o>=0;o--)(s=d[o])&&(r=(a?s(e,t,r):s(r))||r);return a&&r&&D(e,t,r),r},p=(d,e)=>(t,a)=>e(t,a,d);import{DeviceModelId as h,isHexaString as g}from"@ledgerhq/device-management-kit";import{inject as x,injectable as P}from"inversify";import{MaybeAsync as u}from"purify-ts";import{calldataTypes as m}from"../../calldata/di/calldataTypes";import{configTypes as v}from"../../config/di/configTypes";import{proxyTypes as M}from"../../proxy/di/proxyTypes";import{ClearSignContextType as i}from"../../shared/model/ClearSignContext";const b=[i.TRANSACTION_INFO,i.TRANSACTION_FIELD_DESCRIPTION,i.PROXY_INFO,i.ENUM];let C=class{constructor(e,t,a,r){this.dappDataSource=e;this.tokenDataSource=t;this.proxyDataSource=a;this.logger=r("CalldataContextLoader")}logger;canHandle(e,t){return typeof e=="object"&&e!==null&&"to"in e&&"data"in e&&"selector"in e&&"chainId"in e&&"deviceModelId"in e&&e.deviceModelId!==void 0&&e.deviceModelId!==h.NANO_S&&typeof e.chainId=="number"&&g(e.to)&&e.to!=="0x"&&g(e.data)&&g(e.selector)&&e.selector!=="0x"&&b.every(a=>t.includes(a))}async load(e){const{to:t,data:a,selector:r,chainId:o,deviceModelId:s}=e,n={address:t,chainId:o,selector:r,deviceModelId:s,data:a},c=(await this._getContexts(n,this.dappDataSource).alt(this._getContexts(n,this.tokenDataSource)).alt(this._getContextsWithProxy(n,this.dappDataSource)).run()).caseOf({Just:y=>y,Nothing:()=>[{type:i.ERROR,error:new Error("[ContextModule] CalldataContextLoader: No calldata contexts found")}]});return this.logger.debug("load result",{data:{result:c}}),c}_getContexts({address:e,chainId:t,selector:a,deviceModelId:r},o){return u(async({liftMaybe:s})=>{const n=await o.getCalldataDescriptors({deviceModelId:r,address:e,chainId:t,selector:a});return s(n.toMaybe().filter(l=>l.length>0))})}_getContextsWithProxy({address:e,chainId:t,selector:a,deviceModelId:r,data:o},s){return u(async({liftMaybe:l})=>{const c=await this.proxyDataSource.getProxyImplementationAddress({calldata:o,proxyAddress:e,chainId:t,challenge:""});return l(c.toMaybe())}).map(({implementationAddress:l})=>{const c={address:l,chainId:t,selector:a,deviceModelId:r,data:o};return this._getContexts(c,s).map(y=>[{type:i.PROXY_INFO,payload:"0x"},...y])}).join()}};C=S([P(),p(0,x(m.DappCalldataDescriptorDataSource)),p(1,x(m.TokenCalldataDescriptorDataSource)),p(2,x(M.ProxyDataSource)),p(3,x(v.ContextModuleLoggerFactory))],C);export{C as CalldataContextLoader};
|
|
2
2
|
//# sourceMappingURL=CalldataContextLoader.js.map
|