emblem-vault-sdk 2.3.6 → 3.0.0-experimental

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.
Files changed (147) hide show
  1. package/.traces/blockchain-provider-abstraction-plan.md +302 -0
  2. package/.traces/notes.md +43 -0
  3. package/.traces/readme-verification-trace.md +988 -0
  4. package/.traces/test-migration-status.md +227 -0
  5. package/.traces/tests-consolidated-trace.md +667 -0
  6. package/dist/abi/abi.json +53 -0
  7. package/dist/bundle.js +21602 -17419
  8. package/dist/clients/emblemVaultSolanaWalletClient.d.ts +74 -0
  9. package/dist/clients/emblemVaultSolanaWalletClient.js +149 -0
  10. package/dist/clients/emblemVaultSolanaWalletClient.js.map +1 -0
  11. package/dist/clients/emblemVaultWalletClient.d.ts +52 -0
  12. package/dist/clients/emblemVaultWalletClient.js +110 -0
  13. package/dist/clients/emblemVaultWalletClient.js.map +1 -0
  14. package/dist/derive.js +7 -0
  15. package/dist/derive.js.map +1 -0
  16. package/dist/index.js +319 -114
  17. package/dist/index.js.map +1 -0
  18. package/dist/providers/ProviderManager.d.ts +57 -0
  19. package/dist/providers/ProviderManager.js +283 -0
  20. package/dist/providers/ProviderManager.js.map +1 -0
  21. package/dist/providers.d.ts +101 -0
  22. package/dist/providers.js +96 -0
  23. package/dist/providers.js.map +1 -0
  24. package/dist/types.js +1 -0
  25. package/dist/types.js.map +1 -0
  26. package/dist/utils.js +61 -58
  27. package/dist/utils.js.map +1 -0
  28. package/docs/bundle.js +21602 -17419
  29. package/docs/index.html +150 -13
  30. package/docs/local.html +385 -0
  31. package/docs/steps.html +420 -53
  32. package/package.json +22 -13
  33. package/readme.md +795 -21
  34. package/src/abi/abi.json +54 -1
  35. package/src/clients/emblemVaultSolanaWalletClient.ts +257 -0
  36. package/src/clients/emblemVaultWalletClient.ts +159 -0
  37. package/src/derive.ts +5 -5
  38. package/src/index.ts +320 -102
  39. package/src/providers/ProviderManager.ts +254 -0
  40. package/src/providers.ts +163 -0
  41. package/src/types.ts +50 -0
  42. package/src/utils.ts +63 -62
  43. package/test/.mocharc.js +8 -0
  44. package/test/README.md +212 -0
  45. package/test/fixtures/ethscriptions/balance-with-native-first.json +24 -0
  46. package/test/fixtures/ethscriptions/balance-with-native.json +23 -0
  47. package/test/fixtures/ethscriptions/balance.json +18 -0
  48. package/test/helpers/sdkLoader.js +88 -0
  49. package/test/helpers/setup.js +55 -0
  50. package/test/integration/ApiOperations.spec.js +102 -0
  51. package/test/integration/VaultAI.spec.js +57 -0
  52. package/test/integration/VaultCreation.spec.js +95 -0
  53. package/test/mocks.js +127 -0
  54. package/test/tsconfig.json +25 -0
  55. package/test/unit/AllowedBells.spec.js +53 -0
  56. package/test/unit/AllowedBitcoinDeGods.spec.js +53 -0
  57. package/test/unit/AllowedBitcoinOrdinals.spec.js +46 -0
  58. package/test/unit/AllowedCounterparty.spec.js +66 -0
  59. package/test/unit/AllowedCursedOrdinals.spec.js +68 -0
  60. package/test/unit/AllowedEmbells.spec.js +11 -0
  61. package/test/unit/AllowedEmbels.spec.js +11 -0
  62. package/test/unit/AllowedEmblemOpen.spec.js +20 -0
  63. package/test/unit/AllowedEthscriptions.spec.js +53 -0
  64. package/test/unit/AllowedHardcodedNfts.spec.js +77 -0
  65. package/test/unit/AllowedNamecoin.spec.js +33 -0
  66. package/test/unit/AllowedOrdi.spec.js +46 -0
  67. package/test/unit/AllowedOxbt.spec.js +46 -0
  68. package/test/unit/AllowedProjectCollection.spec.js +51 -0
  69. package/test/unit/AllowedProtocolCollection.spec.js +44 -0
  70. package/test/unit/AllowedStamps.spec.js +78 -0
  71. package/test/unit/DarkfarmsMetadata.spec.js +10 -0
  72. package/test/unit/EmblemVaultSdk.spec.js +188 -0
  73. package/test/unit/Providers.spec.js +290 -0
  74. package/test/unit/ResourceMonitor.spec.js +111 -0
  75. package/test/unit/SDKMemoryLeaks.spec.js +176 -0
  76. package/test/unit/Signing.spec.js +321 -0
  77. package/test/unit/VaultAI.spec.js +140 -0
  78. package/test/unit/clients/EmblemVaultSolanaWalletClient.spec.js +296 -0
  79. package/test/unit/clients/EmblemVaultWalletClient.spec.js +246 -0
  80. package/test/utils/ResourceMonitor.js +169 -0
  81. package/test/windsurf-rules.md +68 -0
  82. package/tsconfig.json +7 -3
  83. package/types/derive.d.ts +0 -5
  84. package/types/index.d.ts +152 -32
  85. package/types/types.d.ts +43 -0
  86. package/types/utils.d.ts +7 -1
  87. package/dist/abi/quote.js +0 -29
  88. package/dist/abi/quote.json +0 -26
  89. package/jest.config.js +0 -6
  90. package/tests/AllowedBells.test.ts +0 -53
  91. package/tests/AllowedBitcoinDeGods.test.ts +0 -53
  92. package/tests/AllowedBitcoinOrdinals.test.ts +0 -46
  93. package/tests/AllowedCounterparty.test.ts +0 -45
  94. package/tests/AllowedCursedOrdinals.test.ts +0 -68
  95. package/tests/AllowedEmbells.test.ts +0 -12
  96. package/tests/AllowedEmbels.test.ts +0 -16
  97. package/tests/AllowedEmblemOpen.test.ts +0 -20
  98. package/tests/AllowedEthscriptions.test.ts +0 -39
  99. package/tests/AllowedHardcodedNfts.test.ts +0 -78
  100. package/tests/AllowedNamecoin.test.ts +0 -33
  101. package/tests/AllowedOrdi.test.ts +0 -47
  102. package/tests/AllowedOxbt.test.ts +0 -47
  103. package/tests/AllowedProjectlCollection.test.ts +0 -51
  104. package/tests/AllowedProtocolCollection.test.ts +0 -44
  105. package/tests/AllowedStamps.test.ts +0 -73
  106. package/tests/DarkfarmsMetadata.test.ts +0 -10
  107. package/tests/EmblemVaultSdk.test.ts +0 -124
  108. package/tests/fixtures/embels/balance.json +0 -10
  109. package/tests/fixtures/ethscriptions/balance-with-native-first.json +0 -69
  110. package/tests/fixtures/ethscriptions/balance-with-native.json +0 -37
  111. package/tests/fixtures/ethscriptions/balance.json +0 -64
  112. /package/{tests → test}/fixtures/bells/balance-with-non-bell-first.json +0 -0
  113. /package/{tests → test}/fixtures/bells/balance-with-non-bell.json +0 -0
  114. /package/{tests → test}/fixtures/bells/balance.json +0 -0
  115. /package/{tests → test}/fixtures/bitcoin-degods/balance-with-non-degods-first.json +0 -0
  116. /package/{tests → test}/fixtures/bitcoin-degods/balance-with-non-degods.json +0 -0
  117. /package/{tests → test}/fixtures/bitcoin-degods/balance.json +0 -0
  118. /package/{tests → test}/fixtures/bitcoin-ordinals/balance-with-native-first.json +0 -0
  119. /package/{tests → test}/fixtures/bitcoin-ordinals/balance-with-only-native.json +0 -0
  120. /package/{tests → test}/fixtures/bitcoin-ordinals/balance.json +0 -0
  121. /package/{tests → test}/fixtures/counterparty/balance-with-multiple.json +0 -0
  122. /package/{tests → test}/fixtures/counterparty/balance.json +0 -0
  123. /package/{tests → test}/fixtures/cursed-ordinals/balance-with-native-first.json +0 -0
  124. /package/{tests → test}/fixtures/cursed-ordinals/balance-with-native.json +0 -0
  125. /package/{tests → test}/fixtures/cursed-ordinals/balance.json +0 -0
  126. /package/{tests → test}/fixtures/dogeparty/balance-with-non-dogeparty-first.json +0 -0
  127. /package/{tests → test}/fixtures/dogeparty/balance-with-non-dogeparty.json +0 -0
  128. /package/{tests → test}/fixtures/dogeparty/balance.json +0 -0
  129. /package/{tests → test}/fixtures/emblem-open/balance.json +0 -0
  130. /package/{tests → test}/fixtures/hardcoded-nfts/balance-witn-non-hardcoded-first.json +0 -0
  131. /package/{tests → test}/fixtures/hardcoded-nfts/balance-witn-non-hardcoded.json +0 -0
  132. /package/{tests → test}/fixtures/hardcoded-nfts/balance.json +0 -0
  133. /package/{tests → test}/fixtures/megapunks/balance-with-non-megapunk-first.json +0 -0
  134. /package/{tests → test}/fixtures/megapunks/balance-with-non-megapunk.json +0 -0
  135. /package/{tests → test}/fixtures/megapunks/balance.json +0 -0
  136. /package/{tests → test}/fixtures/namecoin/balance-with-native-first.json +0 -0
  137. /package/{tests → test}/fixtures/namecoin/balance-with-native.json +0 -0
  138. /package/{tests → test}/fixtures/namecoin/balance.json +0 -0
  139. /package/{tests → test}/fixtures/ordi/balance-with-native-first.json +0 -0
  140. /package/{tests → test}/fixtures/ordi/balance-with-native.json +0 -0
  141. /package/{tests → test}/fixtures/ordi/balance.json +0 -0
  142. /package/{tests → test}/fixtures/oxbt/balance-with-native-first.json +0 -0
  143. /package/{tests → test}/fixtures/oxbt/balance-with-native.json +0 -0
  144. /package/{tests → test}/fixtures/oxbt/balance.json +0 -0
  145. /package/{tests → test}/fixtures/stamps/balance-with-non-stamps-first.json +0 -0
  146. /package/{tests → test}/fixtures/stamps/balance-with-non-stamps.json +0 -0
  147. /package/{tests → test}/fixtures/stamps/balance.json +0 -0
@@ -0,0 +1,8 @@
1
+ module.exports = {
2
+ require: 'ts-node/register',
3
+ extension: ['.ts'],
4
+ spec: './test/**/*.spec.ts',
5
+ timeout: 30000, // 30 seconds, matching the Jest timeout
6
+ exit: true,
7
+ recursive: true
8
+ };
package/test/README.md ADDED
@@ -0,0 +1,212 @@
1
+ # Emblem Vault SDK Test Suite
2
+
3
+ This directory contains the tests for the Emblem Vault SDK. We have migrated from Jest to Mocha/Chai while maintaining backward compatibility.
4
+
5
+ ## Directory Structure
6
+
7
+ ```
8
+ /test
9
+ ├── fixtures/ # Test fixtures (JSON, mock data)
10
+ ├── unit/ # Unit tests for individual components
11
+ ├── integration/ # Integration tests that interact with live API
12
+ ├── utils/ # Test utilities including ResourceMonitor
13
+ ├── helpers/ # Test helper functions and utilities
14
+ ├── .mocharc.js # Mocha configuration
15
+ └── windsurf-rules.md # Migration guidelines
16
+ ```
17
+
18
+ ## Test Categories
19
+
20
+ ### Unit Tests
21
+
22
+ Unit tests focus on testing individual components in isolation:
23
+ - Do not make actual API calls
24
+ - Use mock data and override functions
25
+ - Run quickly and reliably
26
+ - Located in `/test/unit/`
27
+
28
+ ### Integration Tests
29
+
30
+ Integration tests interact with the live Emblem Vault API:
31
+ - Make actual API calls to Emblem Vault services
32
+ - Require valid API keys to execute successfully
33
+ - Take longer to run than unit tests
34
+ - May create or modify real resources
35
+ - Located in `/test/integration/`
36
+
37
+ #### Integration Test Categories
38
+
39
+ The integration tests are organized into the following categories:
40
+
41
+ ##### API Operations (`ApiOperations.spec.js`)
42
+
43
+ Tests for read-only API operations:
44
+ - Fetching curated contracts
45
+ - Retrieving vault information
46
+ - Getting asset metadata
47
+
48
+ ##### Vault Creation (`VaultCreation.spec.js`)
49
+
50
+ Tests for operations that create or modify vaults:
51
+ - Creating empty vaults
52
+ - Creating vaults with specific assets
53
+ - Validating vault templates
54
+
55
+ ## Running Tests
56
+
57
+ ### Mocha Tests
58
+
59
+ Run all Mocha tests:
60
+
61
+ ```bash
62
+ npm run test:mocha
63
+ ```
64
+
65
+ Run Mocha tests in watch mode (useful during development):
66
+
67
+ ```bash
68
+ npm run test:mocha:watch
69
+ ```
70
+
71
+ Run Mocha tests with coverage:
72
+
73
+ ```bash
74
+ npm run test:mocha:coverage
75
+ ```
76
+
77
+ ### Integration Tests
78
+
79
+ To run the integration tests, you need a valid API key:
80
+
81
+ ```bash
82
+ # Run with your API key
83
+ API_KEY=your_api_key npx mocha test/integration/**/*.spec.js
84
+
85
+ # Run a specific integration test file
86
+ API_KEY=your_api_key npx mocha test/integration/ApiOperations.spec.js
87
+ ```
88
+
89
+ Without a valid API key, most integration tests will be skipped.
90
+
91
+ ### Legacy Jest Tests
92
+
93
+ The legacy Jest tests are still available and can be run with:
94
+
95
+ ```bash
96
+ npm test # Runs Jest tests after building
97
+ npm run test:node # Runs Jest tests in Node environment
98
+ npm run test:browser # Runs Jest tests in browser environment
99
+ ```
100
+
101
+ ### Running All Tests
102
+
103
+ To run both Jest and Mocha tests:
104
+
105
+ ```bash
106
+ npm run test:all:both
107
+ ```
108
+
109
+ ## ResourceMonitor for Memory Leak Detection
110
+
111
+ The SDK includes a ResourceMonitor utility for detecting memory leaks in tests:
112
+
113
+ ```javascript
114
+ const { ResourceMonitor } = require('../utils/ResourceMonitor');
115
+
116
+ describe('Memory Usage Tests', function() {
117
+ let monitor = new ResourceMonitor();
118
+
119
+ beforeEach(() => {
120
+ monitor.takeSnapshot('test-start');
121
+ });
122
+
123
+ afterEach(() => {
124
+ monitor.takeSnapshot('test-end');
125
+ console.log(monitor.generateReport());
126
+ });
127
+
128
+ it('should not leak memory during operations', async function() {
129
+ // Test code here
130
+
131
+ // Check if memory usage exceeds threshold
132
+ const thresholdCheck = monitor.checkThreshold('test-start');
133
+ expect(thresholdCheck.exceeded).to.be.false;
134
+ });
135
+ });
136
+ ```
137
+
138
+ ### ResourceMonitor Features
139
+
140
+ - **Memory Snapshots**: Track memory usage at different points in test execution
141
+ - **Difference Calculation**: Measure memory changes between operations
142
+ - **Threshold Checking**: Set custom thresholds for acceptable memory growth
143
+ - **Detailed Reports**: Generate comprehensive memory usage reports
144
+ - **GC Support**: Trigger garbage collection when available (run with `--expose-gc`)
145
+
146
+ ## Migration Status
147
+
148
+ We are gradually migrating tests from Jest to Mocha/Chai. The following tests have been migrated:
149
+
150
+ - [x] EmblemVaultSdk - Core SDK functionality
151
+ - [x] AllowedCounterparty - Counterparty collection tests
152
+ - [x] ResourceMonitor - Memory leak detection utility
153
+
154
+ Remaining tests to migrate:
155
+ - [ ] AllowedBells
156
+ - [ ] AllowedBitcoinDeGods
157
+ - [ ] AllowedBitcoinOrdinals
158
+ - [ ] AllowedCursedOrdinals
159
+ - [ ] AllowedEmbells
160
+ - [ ] AllowedEmbels
161
+ - [ ] AllowedEmblemOpen
162
+ - [ ] AllowedEthscriptions
163
+ - [ ] AllowedHardcodedNfts
164
+ - [ ] AllowedNamecoin
165
+ - [ ] AllowedOrdi
166
+ - [ ] AllowedOxbt
167
+ - [ ] AllowedProjectlCollection
168
+ - [ ] AllowedProtocolCollection
169
+ - [ ] AllowedStamps
170
+ - [ ] DarkfarmsMetadata
171
+
172
+ ## Best Practices
173
+
174
+ ### For All Tests
175
+
176
+ 1. **Never commit API keys** to the repository
177
+ 2. Use environment variables for sensitive information
178
+ 3. Use descriptive test names that indicate what's being tested
179
+ 4. Follow the project's coding standards
180
+
181
+ ### For Integration Tests
182
+
183
+ 1. Keep integration tests isolated from each other
184
+ 2. Add proper cleanup after tests that create resources
185
+ 3. Set appropriate timeouts for tests that may take longer to complete
186
+ 4. Skip tests when using demo keys or missing required credentials
187
+
188
+ ## Writing New Tests
189
+
190
+ All new tests should be written using Mocha/Chai and placed in the appropriate directory:
191
+
192
+ - Unit tests go in `/test/unit/` with the naming convention `*.spec.js`
193
+ - Integration tests go in `/test/integration/` with the naming convention `*.spec.js`
194
+ - Fixtures should be placed in `/test/fixtures/` in an appropriate subdirectory
195
+
196
+ Example test structure:
197
+
198
+ ```javascript
199
+ const { expect } = require('chai');
200
+ const { EmblemVaultSDK } = require('../../dist');
201
+
202
+ describe('Feature Name', () => {
203
+ const sdk = new EmblemVaultSDK('DEMO_KEY');
204
+
205
+ it('should do something specific', async () => {
206
+ // Test code here
207
+ expect(result).to.be.true;
208
+ });
209
+ });
210
+ ```
211
+
212
+ For more detailed migration guidelines, see the [windsurf-rules.md](./windsurf-rules.md) file.
@@ -0,0 +1,24 @@
1
+ [
2
+
3
+ {
4
+ "coin": "eth",
5
+ "name": "ETH",
6
+ "balance": 1
7
+ },
8
+ {
9
+ "coin": "ethscription",
10
+ "name": "Ethscription #7104",
11
+ "balance": 1,
12
+ "type": "nft",
13
+ "external_url": "https://ethscriptions.com/0x438397AB9350b1B4527cB8397BDF557e5389a456",
14
+ "image": "https://image-scaler.vercel.app/image2?url=https://eth-script-indexer-eca25c4cf43b.herokuapp.com/api/ethscriptions/7104/data",
15
+ "id": "0xc7282e29440679a1e283d86dee79e9da483c7d6ae55a37ceee19568a0ebacaf7",
16
+ "number": 7104,
17
+ "traits": [
18
+ {
19
+ "trait_type": "Ethscriptions",
20
+ "value": "Sub 10k"
21
+ }
22
+ ]
23
+ }
24
+ ]
@@ -0,0 +1,23 @@
1
+ [
2
+ {
3
+ "coin": "ethscription",
4
+ "name": "Ethscription #7104",
5
+ "balance": 1,
6
+ "type": "nft",
7
+ "external_url": "https://ethscriptions.com/0x438397AB9350b1B4527cB8397BDF557e5389a456",
8
+ "image": "https://image-scaler.vercel.app/image2?url=https://eth-script-indexer-eca25c4cf43b.herokuapp.com/api/ethscriptions/7104/data",
9
+ "id": "0xc7282e29440679a1e283d86dee79e9da483c7d6ae55a37ceee19568a0ebacaf7",
10
+ "number": 7104,
11
+ "traits": [
12
+ {
13
+ "trait_type": "Ethscriptions",
14
+ "value": "Sub 10k"
15
+ }
16
+ ]
17
+ },
18
+ {
19
+ "coin": "eth",
20
+ "name": "ETH",
21
+ "balance": 1
22
+ }
23
+ ]
@@ -0,0 +1,18 @@
1
+ [
2
+ {
3
+ "coin": "ethscription",
4
+ "name": "Ethscription #7104",
5
+ "balance": 1,
6
+ "type": "nft",
7
+ "external_url": "https://ethscriptions.com/0x438397AB9350b1B4527cB8397BDF557e5389a456",
8
+ "image": "https://image-scaler.vercel.app/image2?url=https://eth-script-indexer-eca25c4cf43b.herokuapp.com/api/ethscriptions/7104/data",
9
+ "id": "0xc7282e29440679a1e283d86dee79e9da483c7d6ae55a37ceee19568a0ebacaf7",
10
+ "number": 7104,
11
+ "traits": [
12
+ {
13
+ "trait_type": "Ethscriptions",
14
+ "value": "Sub 10k"
15
+ }
16
+ ]
17
+ }
18
+ ]
@@ -0,0 +1,88 @@
1
+ /**
2
+ * SDK Loader Helper
3
+ * Provides a singleton pattern for SDK initialization across tests
4
+ */
5
+
6
+ const { EmblemVaultSDK } = require('../../dist');
7
+
8
+ // Default values from environment or fallbacks
9
+ const DEFAULT_API_KEY = process.env.API_KEY || 'DEMO_KEY';
10
+ const DEFAULT_BASE_URL = process.env.BASE_URL;
11
+ const DEFAULT_V3_URL = process.env.V3_URL;
12
+ const DEFAULT_SIG_URL = process.env.SIG_URL;
13
+
14
+ // Singleton instance
15
+ let sdkInstance = null;
16
+ let currentConfig = null;
17
+
18
+ /**
19
+ * Get the SDK instance - creates a new instance if one doesn't exist
20
+ * or returns the existing instance
21
+ *
22
+ * @param {Object} options - SDK initialization options
23
+ * @param {string} options.apiKey - API key to use (defaults to env API_KEY or 'DEMO_KEY')
24
+ * @param {string} options.baseUrl - Base URL to use (defaults to env BASE_URL or SDK default)
25
+ * @param {string} options.v3Url - V3 URL to use (defaults to env V3_URL or SDK default)
26
+ * @param {string} options.sigUrl - Signature URL to use (defaults to env SIG_URL or SDK default)
27
+ * @param {boolean} options.forceNew - Force creation of a new instance
28
+ * @returns {EmblemVaultSDK} The SDK instance
29
+ */
30
+ function getSDK(options = {}) {
31
+ const {
32
+ apiKey = DEFAULT_API_KEY,
33
+ baseUrl = DEFAULT_BASE_URL,
34
+ v3Url = DEFAULT_V3_URL,
35
+ sigUrl = DEFAULT_SIG_URL,
36
+ forceNew = false
37
+ } = options;
38
+
39
+ // Create new configuration object for comparison
40
+ const newConfig = { apiKey, baseUrl, v3Url, sigUrl };
41
+
42
+ // Create a new instance if:
43
+ // 1. No instance exists yet
44
+ // 2. forceNew is true
45
+ // 3. Configuration has changed
46
+ const configChanged = currentConfig && (
47
+ currentConfig.apiKey !== newConfig.apiKey ||
48
+ currentConfig.baseUrl !== newConfig.baseUrl ||
49
+ currentConfig.v3Url !== newConfig.v3Url ||
50
+ currentConfig.sigUrl !== newConfig.sigUrl
51
+ );
52
+
53
+ if (!sdkInstance || forceNew || configChanged) {
54
+ // Initialize with all possible parameters
55
+ // Only pass parameters that are defined to avoid overriding SDK defaults
56
+ const initParams = [apiKey];
57
+
58
+ if (baseUrl) initParams.push(baseUrl);
59
+ else if (v3Url || sigUrl) initParams.push(undefined); // Add placeholder if later params exist
60
+
61
+ if (v3Url) initParams.push(v3Url);
62
+ else if (sigUrl) initParams.push(undefined); // Add placeholder if later params exist
63
+
64
+ if (sigUrl) initParams.push(sigUrl);
65
+
66
+ // Create new instance with spread parameters
67
+ sdkInstance = new EmblemVaultSDK(...initParams);
68
+
69
+ // Store current configuration
70
+ currentConfig = { ...newConfig };
71
+ }
72
+
73
+ return sdkInstance;
74
+ }
75
+
76
+ /**
77
+ * Reset the SDK instance
78
+ * Useful for tests that need to start with a fresh instance
79
+ */
80
+ function resetSDK() {
81
+ sdkInstance = null;
82
+ currentConfig = null;
83
+ }
84
+
85
+ module.exports = {
86
+ getSDK,
87
+ resetSDK
88
+ };
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Global Mocha/Chai test setup file
3
+ * Provides common utilities and configurations for tests
4
+ */
5
+
6
+ const { expect } = require('chai');
7
+
8
+ // Export chai expect for use in tests
9
+ module.exports = {
10
+ expect,
11
+
12
+ // Test constants
13
+ TEST_ADDRESS: "0xb0573e14D92755DE30281f7b10d0F3a5DD3e747B",
14
+ API_KEY: 'DEMO_KEY',
15
+
16
+ // Common mocks used across tests
17
+ mocks: {
18
+ emblemopen_create_template: {
19
+ "fromAddress": { "type": "user-provided" },
20
+ "toAddress": { "type": "user-provided" },
21
+ "chainId": { "type": "user-provided" },
22
+ "experimental": true,
23
+ "targetContract": {
24
+ "1": "0x184ddb67E2EF517f6754F055b56905f2A9b29b6A",
25
+ "900": "5rxENZEa3rhDk2hcuG6RNFbCGGQwU9APm4CMmaW4s4xy",
26
+ "name": "EmblemOpen",
27
+ "description": "The vaults within this collection feature deposit addresses spanning two or more blockchains. Vault images, titles, and descriptions are generated by users. Prior to making a purchase, it is advisable to authenticate the legitimacy of the assets within the vault. Supported blockchains encompass, but are not restricted to: Bitcoin, Litecoin, Bitcoin Cash, Ethereum, Dogecoin, Solana, Tezos, Namecoin, and any EVM-compatible protocol.",
28
+ "fusion": false
29
+ },
30
+ "targetAsset": {
31
+ "name": { "type": "user-provided" },
32
+ "image": { "type": "user-provided" },
33
+ "description": { "type": "user-provided" }
34
+ }
35
+ },
36
+ empty_create_template: {
37
+ "fromAddress": { "type": "user-provided" },
38
+ "toAddress": { "type": "user-provided" },
39
+ "chainId": { "type": "user-provided" },
40
+ "experimental": true,
41
+ "targetContract": {
42
+ "1": "0xEAD67175CDb9CBDeA5bDDC36015e52f4A954E3fD",
43
+ "name": "BitcoinOrdinals",
44
+ "description": "Ordinal Theory is a method for assigning unique identifiers to individual satoshis on the Bitcoin blockchain. This is done by assigning each satoshi a unique identifier based on the order in which it was mined. This identifier can be used to track the satoshi's history and ownership, and to transfer it to another party. Ordinal Theory can also be used to inscribe additional data to satoshis, such as a message, image, serial number, audio file, or document.",
45
+ "fusion": false
46
+ },
47
+ "targetAsset": {
48
+ "name": "Loading...",
49
+ "image": "https://emblem.finance/ordinals.png"
50
+ }
51
+ }
52
+ }
53
+ };
54
+
55
+ // Helper functions can be added here
@@ -0,0 +1,102 @@
1
+ const { expect } = require('chai');
2
+ const { getSDK } = require('../helpers/sdkLoader');
3
+ // const dotenv = require('dotenv');
4
+ // const path = require('path');
5
+ const mocks = require('../mocks');
6
+
7
+ // Load environment variables
8
+ // dotenv.config({ path: path.resolve(__dirname, '../../.env') });
9
+
10
+ // Test constants
11
+ const API_KEY = 'DEMO_KEY';
12
+ const TEST_ADDRESS = "0xb0573e14D92755DE30281f7b10d0F3a5DD3e747B";
13
+
14
+ describe('API Operations Integration Tests', function() {
15
+ // Get SDK instance using the loader
16
+ const sdk = getSDK();
17
+
18
+ // Increase timeout for these tests as they make API calls
19
+ this.timeout(15000);
20
+
21
+ describe('Curated Contracts', function() {
22
+ it('should fetch curated contracts from the API', async function() {
23
+ const contracts = await sdk.fetchCuratedContracts();
24
+ expect(contracts).to.be.an('array');
25
+ expect(contracts.length).to.be.greaterThan(0);
26
+
27
+ // Verify contract structure
28
+ const firstContract = contracts[0];
29
+ expect(firstContract).to.have.property('name');
30
+ expect(firstContract).to.have.property('mintable');
31
+ });
32
+
33
+ it('should fetch a specific curated contract by name', async function() {
34
+ // Use override function with mock data when using demo key
35
+ const contractName = 'Ethscription';
36
+ // First get all contracts
37
+ const contracts = await sdk.fetchCuratedContracts();
38
+ // Then find the specific one by name
39
+ const contract = await sdk.fetchCuratedContractByName(
40
+ contractName,
41
+ contracts
42
+ );
43
+
44
+ expect(contract).to.be.an('object');
45
+ expect(contract).to.have.property('name');
46
+ expect(contract.name).to.equal('Ethscription');
47
+ });
48
+ });
49
+
50
+ describe('Vault Operations', function() {
51
+ it('should fetch vaults of a specific type', async function() {
52
+ const vaults = await sdk.fetchVaultsOfType(
53
+ "created",
54
+ TEST_ADDRESS,
55
+ API_KEY === 'DEMO_KEY' ? () => mocks.sample_vaults : null
56
+ );
57
+
58
+ expect(vaults).to.be.an('array');
59
+
60
+ // If vaults exist, check their structure
61
+ if (vaults.length > 0) {
62
+ const firstVault = vaults[0];
63
+ expect(firstVault).to.have.property('tokenId');
64
+ }
65
+ });
66
+
67
+ it('should fetch vaults for an address', async function() {
68
+ // Using fetchVaultsOfType with "all" type to get all vaults for an address
69
+ const vaults = await sdk.fetchVaultsOfType(
70
+ "all",
71
+ TEST_ADDRESS,
72
+ API_KEY === 'DEMO_KEY' ? () => mocks.sample_vaults : null
73
+ );
74
+
75
+ expect(vaults).to.be.an('array');
76
+ });
77
+ });
78
+
79
+ describe('Asset Metadata', function() {
80
+ it('should fetch asset metadata from the API', async function() {
81
+ const metadata = await sdk.getAssetMetadata(
82
+ 'Bitcoin Ordinals',
83
+ API_KEY === 'DEMO_KEY' ? () => mocks.bitcoin_ordinals_metadata : null
84
+ );
85
+
86
+ expect(metadata).to.be.an('array');
87
+
88
+ if (metadata.length > 0) {
89
+ expect(metadata[0]).to.have.property('projectName');
90
+ expect(metadata[0].projectName.toLowerCase()).to.include('bitcoin ordinals');
91
+ }
92
+ });
93
+
94
+ it('should fetch remote asset metadata project list', async function() {
95
+ const projects = await sdk.getRemoteAssetMetadataProjectList(
96
+ API_KEY === 'DEMO_KEY' ? () => mocks.project_list : null
97
+ );
98
+
99
+ expect(projects).to.be.an('array');
100
+ });
101
+ });
102
+ });
@@ -0,0 +1,57 @@
1
+ const { expect } = require('chai');
2
+ const { EmblemVaultSDK } = require('../../dist/index');
3
+
4
+ // API key for testing
5
+ const API_KEY = 'demo';
6
+ const AI_API_KEY = 'demo-ai-key';
7
+
8
+ describe.skip('Vault AI Integration Tests', () => {
9
+ let sdk;
10
+
11
+ before(() => {
12
+ // Create a new SDK instance with the demo AI API key
13
+ sdk = new EmblemVaultSDK(API_KEY, undefined, undefined, undefined, undefined, AI_API_KEY);
14
+ });
15
+
16
+ it('should fetch NOT vault info using the demo AI API key', async function() {
17
+ this.timeout(10000); // Increase timeout for API call
18
+
19
+ // Call the method with the demo AI API key
20
+ const result = await sdk.vaultInfoFromApiKey();
21
+
22
+ // Verify the response structure
23
+ expect(result).to.be.an('object');
24
+ expect(result).to.have.property('data');
25
+
26
+ // Log the response for debugging
27
+ console.log('Vault info response:', JSON.stringify(result, null, 2));
28
+
29
+ // If the API returns an error with the demo key, this test will still pass
30
+ // as long as we get a proper response object
31
+ if (result.success === true) {
32
+ expect(result.data).to.be.an('object');
33
+ // Add more specific assertions based on the expected response structure
34
+ } else {
35
+ console.log('Note: API returned an error, but the test is verifying the call was made correctly');
36
+ }
37
+ });
38
+
39
+ it('should handle API errors gracefully', async function() {
40
+ this.timeout(10000); // Increase timeout for API call
41
+
42
+ // Call the method with an invalid API key
43
+ try {
44
+ const result = await sdk.vaultInfoFromApiKey('invalid-key');
45
+
46
+ // If we get here, the API might return an error object rather than throwing
47
+ expect(result).to.be.an('object');
48
+
49
+ // Log the response for debugging
50
+ console.log('Error response with invalid key:', JSON.stringify(result, null, 2));
51
+ } catch (error) {
52
+ // If the API throws an error, that's also acceptable
53
+ console.log('API threw an error with invalid key (expected):', error.message);
54
+ expect(error).to.exist;
55
+ }
56
+ });
57
+ });
@@ -0,0 +1,95 @@
1
+ const { expect } = require('chai');
2
+ const { getSDK } = require('../helpers/sdkLoader');
3
+
4
+ // Test constants
5
+ const TEST_ADDRESS = "0xb0573e14D92755DE30281f7b10d0F3a5DD3e747B";
6
+ const CONTRACT_NAME = "EmblemOpen";
7
+
8
+ describe.skip('Vault Creation Integration Tests', function() {
9
+ // Get SDK instance using the loader
10
+ const sdk = getSDK();
11
+
12
+ // Increase timeout for these tests as they make API calls
13
+ this.timeout(155000);
14
+
15
+ it('should create vault using contract template', async () => {
16
+ // Get all contracts
17
+ const contracts = await sdk.fetchCuratedContracts();
18
+ expect(contracts).to.be.an('array');
19
+ expect(contracts.length).to.be.greaterThan(0);
20
+
21
+ // Find the Emblem Open contract
22
+ const contract = contracts.find(contract => contract.name === CONTRACT_NAME);
23
+ expect(contract).to.be.an('object');
24
+
25
+ // Generate a template using the contract's generateCreateTemplate function
26
+ const template = contract.generateCreateTemplate(contract);
27
+ expect(template).to.be.an('object');
28
+
29
+ // Populate the template with test data
30
+ template.fromAddress = TEST_ADDRESS
31
+ template.toAddress = TEST_ADDRESS
32
+ template.chainId = "1" // Add Ethereum mainnet chainId
33
+ template.targetAsset.name = "Test Asset"
34
+ template.targetAsset.image = "https://emblem.finance/stamps.png"
35
+ template.targetAsset.description = "Test Asset Description"
36
+ template.targetAsset.ownedImage = "https://emblem.finance/stamps.png" // Add required ownedImage field
37
+
38
+ // Create the vault using the populated template
39
+ const vault = await sdk.createCuratedVault(template);
40
+
41
+ // Verify the created vault
42
+ expect(vault).to.be.an('object');
43
+ expect(vault).to.have.property('tokenId');
44
+ });
45
+
46
+ it('should create vault with asset details', async () => {
47
+ // Get all contracts
48
+ const contracts = await sdk.fetchCuratedContracts();
49
+ expect(contracts).to.be.an('array');
50
+
51
+ // Find the Emblem Open contract
52
+ const contract = contracts.find(contract => contract.name === CONTRACT_NAME);
53
+ expect(contract).to.be.an('object');
54
+
55
+ // Generate a template using the contract's generateCreateTemplate function
56
+ const template = contract.generateCreateTemplate(contract);
57
+ expect(template).to.be.an('object');
58
+
59
+ // Populate the template with test data
60
+ template.name = `Test Vault with Asset ${Date.now()}`;
61
+ template.description = 'Test vault with asset created by integration tests';
62
+ template.fromAddress = TEST_ADDRESS;
63
+ template.toAddress = TEST_ADDRESS;
64
+ template.chainId = "1"; // Ethereum mainnet
65
+
66
+ // Add asset details
67
+ template.targetAsset = {
68
+ name: "Test Asset",
69
+ image: "https://emblem.finance/stamps.png",
70
+ description: "Test Asset Description",
71
+ ownedImage: "https://emblem.finance/stamps.png"
72
+ };
73
+
74
+ // Create the vault using the populated template
75
+ const vault = await sdk.createCuratedVault(template);
76
+
77
+ // Verify the created vault
78
+ expect(vault).to.be.an('object');
79
+ expect(vault).to.have.property('tokenId');
80
+ expect(vault.targetAsset.name).to.equal("Test Asset");
81
+ expect(vault.targetAsset.image).to.equal("https://emblem.finance/stamps.png");
82
+ expect(vault.targetAsset.description).to.equal("Test Asset Description");
83
+ });
84
+
85
+ it('should fetch vault details after creation', async () => {
86
+ // Fetch vaults for the test address
87
+ const vaults = await sdk.fetchVaultsOfType("created", TEST_ADDRESS);
88
+ expect(vaults).to.be.an('array');
89
+
90
+ if (vaults.length > 0) {
91
+ const firstVault = vaults[0];
92
+ expect(firstVault).to.have.property('tokenId');
93
+ }
94
+ });
95
+ });