@openzeppelin/ui-builder-adapter-evm 1.2.0 → 1.4.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/README.md +33 -18
- package/dist/index.cjs +4651 -4448
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -226
- package/dist/index.d.ts +12 -226
- package/dist/index.js +4737 -4535
- package/dist/index.js.map +1 -1
- package/package.json +7 -6
- package/src/__tests__/adapter-parsing.test.ts +4 -3
- package/src/__tests__/getDefaultServiceConfig.test.ts +185 -0
- package/src/__tests__/mocks/mock-network-configs.ts +1 -1
- package/src/__tests__/provenanceLinks.test.ts +6 -4
- package/src/__tests__/providerSelection.test.ts +5 -4
- package/src/__tests__/timeouts.test.ts +5 -3
- package/src/__tests__/wallet-connect.test.ts +2 -2
- package/src/adapter.ts +61 -107
- package/src/configuration/execution.ts +1 -52
- package/src/configuration/index.ts +2 -3
- package/src/configuration/network-services.ts +47 -60
- package/src/index.ts +22 -13
- package/src/networks/index.ts +2 -1
- package/src/networks/mainnet.ts +1 -1
- package/src/networks/testnet.ts +1 -1
- package/src/query/adapter-query.ts +72 -0
- package/src/query/index.ts +2 -2
- package/src/transaction/components/useEvmRelayerOptions.ts +5 -3
- package/src/transaction/index.ts +1 -5
- package/src/types/artifacts.ts +5 -30
- package/src/types/providers.ts +7 -18
- package/src/wallet/components/EvmWalletUiRoot.tsx +1 -1
- package/src/wallet/evmUiKitManager.ts +26 -129
- package/src/wallet/hooks/index.ts +0 -1
- package/src/wallet/implementation/wagmi-implementation.ts +45 -577
- package/src/wallet/index.ts +2 -3
- package/src/wallet/rainbowkit/__tests__/export-service.test.ts +1 -2
- package/src/wallet/rainbowkit/componentFactory.ts +10 -8
- package/src/wallet/rainbowkit/components.tsx +16 -133
- package/src/wallet/rainbowkit/index.ts +27 -5
- package/src/wallet/utils/__tests__/uiKitService.test.ts +5 -1
- package/src/wallet/utils/connection.ts +8 -52
- package/src/wallet/utils/index.ts +0 -2
- package/src/wallet/utils/uiKitService.ts +7 -3
- package/src/wallet/utils/walletImplementationManager.ts +5 -4
- package/src/wallet/utils.ts +1 -65
- package/src/abi/__tests__/etherscan-v2.test.ts +0 -117
- package/src/abi/__tests__/transformer.test.ts +0 -342
- package/src/abi/comparison.ts +0 -389
- package/src/abi/etherscan-v2.ts +0 -243
- package/src/abi/etherscan.ts +0 -158
- package/src/abi/index.ts +0 -7
- package/src/abi/loader.ts +0 -415
- package/src/abi/sourcify.ts +0 -75
- package/src/abi/transformer.ts +0 -163
- package/src/abi/types.ts +0 -101
- package/src/configuration/__tests__/explorer.test.ts +0 -174
- package/src/configuration/__tests__/rpc.test.ts +0 -176
- package/src/configuration/explorer.ts +0 -243
- package/src/configuration/rpc.ts +0 -257
- package/src/mapping/__tests__/field-generator.test.ts +0 -137
- package/src/mapping/__tests__/type-mapper.test.ts +0 -139
- package/src/mapping/constants.ts +0 -57
- package/src/mapping/field-generator.ts +0 -115
- package/src/mapping/index.ts +0 -4
- package/src/mapping/type-mapper.ts +0 -80
- package/src/proxy/detection.ts +0 -465
- package/src/query/handler.ts +0 -227
- package/src/query/view-checker.ts +0 -10
- package/src/transaction/eoa.ts +0 -98
- package/src/transaction/execution-strategy.ts +0 -33
- package/src/transaction/formatter.ts +0 -101
- package/src/transaction/relayer.ts +0 -380
- package/src/transaction/sender.ts +0 -185
- package/src/transform/index.ts +0 -3
- package/src/transform/input-parser.ts +0 -177
- package/src/transform/output-formatter.ts +0 -64
- package/src/types/__tests__/artifacts.test.ts +0 -105
- package/src/types.ts +0 -92
- package/src/utils/__tests__/artifacts.test.ts +0 -81
- package/src/utils/artifacts.ts +0 -30
- package/src/utils/formatting.ts +0 -25
- package/src/utils/gas.ts +0 -17
- package/src/utils/index.ts +0 -6
- package/src/utils/json.ts +0 -19
- package/src/utils/validation.ts +0 -10
- package/src/validation/eoa.ts +0 -33
- package/src/validation/index.ts +0 -2
- package/src/validation/relayer.ts +0 -13
- package/src/wallet/__tests__/utils.test.ts +0 -149
- package/src/wallet/components/account/AccountDisplay.tsx +0 -52
- package/src/wallet/components/connect/ConnectButton.tsx +0 -125
- package/src/wallet/components/connect/ConnectorDialog.tsx +0 -140
- package/src/wallet/components/index.ts +0 -4
- package/src/wallet/components/network/NetworkSwitcher.tsx +0 -90
- package/src/wallet/context/index.ts +0 -1
- package/src/wallet/context/wagmi-context.tsx +0 -7
- package/src/wallet/hooks/useIsWagmiProviderInitialized.ts +0 -11
- package/src/wallet/rainbowkit/config-generator.ts +0 -56
- package/src/wallet/rainbowkit/config-service.ts +0 -169
- package/src/wallet/rainbowkit/export-service.ts +0 -18
- package/src/wallet/rainbowkit/rainbowkitAssetManager.ts +0 -74
- package/src/wallet/rainbowkit/types.ts +0 -74
- package/src/wallet/rainbowkit/utils.ts +0 -96
- package/src/wallet/services/configResolutionService.ts +0 -65
- package/src/wallet/utils/SafeWagmiComponent.tsx +0 -72
- package/src/wallet/utils/filterWalletComponents.ts +0 -89
|
@@ -1,342 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unit tests for ABI transformation logic.
|
|
3
|
-
*/
|
|
4
|
-
import type { AbiFunction } from 'viem';
|
|
5
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
6
|
-
|
|
7
|
-
import type { ContractFunction, ContractSchema } from '@openzeppelin/ui-types';
|
|
8
|
-
|
|
9
|
-
import type { AbiItem } from '../../types';
|
|
10
|
-
// Adjust path as necessary
|
|
11
|
-
import { createAbiFunctionItem, transformAbiToSchema } from '../transformer';
|
|
12
|
-
|
|
13
|
-
// Mock utility functions as their specific formatting is not under test here
|
|
14
|
-
vi.mock('../../utils', () => ({
|
|
15
|
-
formatMethodName: vi.fn((name: string) => `formatted_${name}`),
|
|
16
|
-
formatInputName: vi.fn(
|
|
17
|
-
(name: string | undefined, type: string) => `${name ? `formatted_${name}` : `param_${type}`}`
|
|
18
|
-
),
|
|
19
|
-
}));
|
|
20
|
-
|
|
21
|
-
describe('ABI Transformer', () => {
|
|
22
|
-
describe('transformAbiToSchema', () => {
|
|
23
|
-
const mockContractName = 'TestContract';
|
|
24
|
-
const mockContractAddress = '0x1234567890123456789012345678901234567890';
|
|
25
|
-
|
|
26
|
-
it('should transform an empty ABI to an empty functions array', () => {
|
|
27
|
-
const abi: readonly AbiItem[] = [];
|
|
28
|
-
const expectedSchema: ContractSchema = {
|
|
29
|
-
ecosystem: 'evm',
|
|
30
|
-
name: mockContractName,
|
|
31
|
-
address: undefined,
|
|
32
|
-
functions: [],
|
|
33
|
-
};
|
|
34
|
-
expect(transformAbiToSchema(abi, mockContractName)).toEqual(expectedSchema);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('should transform a simple function correctly', () => {
|
|
38
|
-
const abi: readonly AbiItem[] = [
|
|
39
|
-
{
|
|
40
|
-
type: 'function',
|
|
41
|
-
name: 'myFunction',
|
|
42
|
-
inputs: [],
|
|
43
|
-
outputs: [],
|
|
44
|
-
stateMutability: 'nonpayable',
|
|
45
|
-
},
|
|
46
|
-
];
|
|
47
|
-
const result = transformAbiToSchema(abi, mockContractName, mockContractAddress);
|
|
48
|
-
expect(result.functions).toHaveLength(1);
|
|
49
|
-
expect(result.functions[0]).toEqual(
|
|
50
|
-
expect.objectContaining({
|
|
51
|
-
name: 'myFunction',
|
|
52
|
-
displayName: 'formatted_myFunction',
|
|
53
|
-
inputs: [],
|
|
54
|
-
outputs: [],
|
|
55
|
-
stateMutability: 'nonpayable',
|
|
56
|
-
modifiesState: true,
|
|
57
|
-
type: 'function',
|
|
58
|
-
})
|
|
59
|
-
);
|
|
60
|
-
expect(result.ecosystem).toBe('evm');
|
|
61
|
-
expect(result.name).toBe(mockContractName);
|
|
62
|
-
expect(result.address).toBe(mockContractAddress);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('should handle different stateMutability values', () => {
|
|
66
|
-
const abi: readonly AbiItem[] = [
|
|
67
|
-
{ type: 'function', name: 'viewFunc', inputs: [], outputs: [], stateMutability: 'view' },
|
|
68
|
-
{ type: 'function', name: 'pureFunc', inputs: [], outputs: [], stateMutability: 'pure' },
|
|
69
|
-
{
|
|
70
|
-
type: 'function',
|
|
71
|
-
name: 'payableFunc',
|
|
72
|
-
inputs: [],
|
|
73
|
-
outputs: [],
|
|
74
|
-
stateMutability: 'payable',
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
type: 'function',
|
|
78
|
-
name: 'nonPayableFunc',
|
|
79
|
-
inputs: [],
|
|
80
|
-
outputs: [],
|
|
81
|
-
stateMutability: 'nonpayable',
|
|
82
|
-
},
|
|
83
|
-
];
|
|
84
|
-
const result = transformAbiToSchema(abi, mockContractName);
|
|
85
|
-
expect(result.functions[0]).toHaveProperty('modifiesState', false);
|
|
86
|
-
expect(result.functions[1]).toHaveProperty('modifiesState', false);
|
|
87
|
-
expect(result.functions[2]).toHaveProperty('modifiesState', true);
|
|
88
|
-
expect(result.functions[3]).toHaveProperty('modifiesState', true);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('should correctly map input and output parameters', () => {
|
|
92
|
-
const abi: readonly AbiItem[] = [
|
|
93
|
-
{
|
|
94
|
-
type: 'function',
|
|
95
|
-
name: 'transfer',
|
|
96
|
-
inputs: [
|
|
97
|
-
{ name: 'to', type: 'address' },
|
|
98
|
-
{ name: 'amount', type: 'uint256' },
|
|
99
|
-
],
|
|
100
|
-
outputs: [{ name: 'success', type: 'bool' }],
|
|
101
|
-
stateMutability: 'nonpayable',
|
|
102
|
-
},
|
|
103
|
-
];
|
|
104
|
-
const result = transformAbiToSchema(abi, mockContractName);
|
|
105
|
-
const func = result.functions[0];
|
|
106
|
-
expect(func.inputs).toHaveLength(2);
|
|
107
|
-
expect(func.inputs[0]).toEqual({ name: 'to', type: 'address', displayName: 'formatted_to' });
|
|
108
|
-
expect(func.inputs[1]).toEqual({
|
|
109
|
-
name: 'amount',
|
|
110
|
-
type: 'uint256',
|
|
111
|
-
displayName: 'formatted_amount',
|
|
112
|
-
});
|
|
113
|
-
expect(func.outputs).toBeDefined();
|
|
114
|
-
expect(func.outputs).toHaveLength(1);
|
|
115
|
-
if (func.outputs) {
|
|
116
|
-
expect(func.outputs[0]).toEqual({
|
|
117
|
-
name: 'success',
|
|
118
|
-
type: 'bool',
|
|
119
|
-
displayName: 'formatted_success',
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it('should strip internalType and other non-standard properties from parameters', () => {
|
|
125
|
-
const abi: readonly AbiItem[] = [
|
|
126
|
-
{
|
|
127
|
-
type: 'function',
|
|
128
|
-
name: 'complexCall',
|
|
129
|
-
inputs: [
|
|
130
|
-
{
|
|
131
|
-
name: 'param1',
|
|
132
|
-
type: 'address',
|
|
133
|
-
internalType: 'contract IERC20', // This should be stripped
|
|
134
|
-
extraProperty: 'shouldBeGone', // This should be stripped
|
|
135
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
136
|
-
} as any, // Cast the input object to allow extra property for the test
|
|
137
|
-
],
|
|
138
|
-
outputs: [],
|
|
139
|
-
stateMutability: 'view',
|
|
140
|
-
},
|
|
141
|
-
];
|
|
142
|
-
const result = transformAbiToSchema(abi, mockContractName);
|
|
143
|
-
const funcInput = result.functions[0].inputs[0];
|
|
144
|
-
expect(funcInput).toEqual({
|
|
145
|
-
name: 'param1',
|
|
146
|
-
type: 'address',
|
|
147
|
-
displayName: 'formatted_param1',
|
|
148
|
-
});
|
|
149
|
-
expect(funcInput).not.toHaveProperty('internalType');
|
|
150
|
-
expect(funcInput).not.toHaveProperty('extraProperty');
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it('should handle tuple inputs and strip internalType from components', () => {
|
|
154
|
-
const abi: readonly AbiItem[] = [
|
|
155
|
-
{
|
|
156
|
-
type: 'function',
|
|
157
|
-
name: 'processStruct',
|
|
158
|
-
inputs: [
|
|
159
|
-
{
|
|
160
|
-
name: 'myStruct',
|
|
161
|
-
type: 'tuple',
|
|
162
|
-
components: [
|
|
163
|
-
{ name: 'field1', type: 'uint256', internalType: 'uint256_internal' },
|
|
164
|
-
{ name: 'field2', type: 'address', internalType: 'address_internal' },
|
|
165
|
-
],
|
|
166
|
-
},
|
|
167
|
-
],
|
|
168
|
-
outputs: [],
|
|
169
|
-
stateMutability: 'nonpayable',
|
|
170
|
-
},
|
|
171
|
-
];
|
|
172
|
-
const result = transformAbiToSchema(abi, mockContractName);
|
|
173
|
-
const structInput = result.functions[0].inputs[0];
|
|
174
|
-
expect(structInput.type).toBe('tuple');
|
|
175
|
-
expect(structInput.components).toBeDefined();
|
|
176
|
-
expect(structInput.components).toHaveLength(2);
|
|
177
|
-
if (structInput.components) {
|
|
178
|
-
expect(structInput.components[0]).toEqual({
|
|
179
|
-
name: 'field1',
|
|
180
|
-
type: 'uint256',
|
|
181
|
-
displayName: 'formatted_field1',
|
|
182
|
-
});
|
|
183
|
-
expect(structInput.components[0]).not.toHaveProperty('internalType');
|
|
184
|
-
expect(structInput.components[1]).toEqual({
|
|
185
|
-
name: 'field2',
|
|
186
|
-
type: 'address',
|
|
187
|
-
displayName: 'formatted_field2',
|
|
188
|
-
});
|
|
189
|
-
expect(structInput.components[1]).not.toHaveProperty('internalType');
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
it('should generate a unique ID for functions, considering overloads', () => {
|
|
194
|
-
const abi: readonly AbiItem[] = [
|
|
195
|
-
{
|
|
196
|
-
type: 'function',
|
|
197
|
-
name: 'overloadedFunc',
|
|
198
|
-
inputs: [{ name: 'a', type: 'uint256' }],
|
|
199
|
-
outputs: [],
|
|
200
|
-
stateMutability: 'view',
|
|
201
|
-
},
|
|
202
|
-
{
|
|
203
|
-
type: 'function',
|
|
204
|
-
name: 'overloadedFunc',
|
|
205
|
-
inputs: [{ name: 'a', type: 'string' }],
|
|
206
|
-
outputs: [],
|
|
207
|
-
stateMutability: 'view',
|
|
208
|
-
},
|
|
209
|
-
];
|
|
210
|
-
const result = transformAbiToSchema(abi, mockContractName);
|
|
211
|
-
expect(result.functions[0].id).toBe('overloadedFunc_uint256');
|
|
212
|
-
expect(result.functions[1].id).toBe('overloadedFunc_string');
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
it('should handle missing names for functions and parameters gracefully', () => {
|
|
216
|
-
// Define the parameter with undefined name separately to test handling
|
|
217
|
-
const paramWithoutName = { name: undefined, type: 'bool' };
|
|
218
|
-
const abi: readonly AbiItem[] = [
|
|
219
|
-
{
|
|
220
|
-
type: 'function',
|
|
221
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
222
|
-
name: undefined as any, // Simulate missing function name - intentional 'any' for test
|
|
223
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
224
|
-
// @ts-ignore - Deliberately passing possibly invalid input type for robustness test
|
|
225
|
-
inputs: [paramWithoutName], // Use the defined object, ignoring TS error for test
|
|
226
|
-
outputs: [],
|
|
227
|
-
stateMutability: 'view',
|
|
228
|
-
},
|
|
229
|
-
];
|
|
230
|
-
const result = transformAbiToSchema(abi, mockContractName);
|
|
231
|
-
expect(result.functions[0].name).toBe('');
|
|
232
|
-
expect(result.functions[0].displayName).toBe('formatted_');
|
|
233
|
-
expect(result.functions[0].inputs[0].name).toBe('');
|
|
234
|
-
expect(result.functions[0].inputs[0].displayName).toBe('param_bool');
|
|
235
|
-
});
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
describe('createAbiFunctionItem', () => {
|
|
239
|
-
it('should convert a simple ContractFunction to AbiFunction', () => {
|
|
240
|
-
const contractFunc: ContractFunction = {
|
|
241
|
-
id: 'test_func_',
|
|
242
|
-
name: 'testFunc',
|
|
243
|
-
displayName: 'Test Func',
|
|
244
|
-
inputs: [],
|
|
245
|
-
outputs: [],
|
|
246
|
-
type: 'function',
|
|
247
|
-
stateMutability: 'view',
|
|
248
|
-
modifiesState: false,
|
|
249
|
-
};
|
|
250
|
-
const expectedAbiFunc: AbiFunction = {
|
|
251
|
-
name: 'testFunc',
|
|
252
|
-
type: 'function',
|
|
253
|
-
inputs: [],
|
|
254
|
-
outputs: [],
|
|
255
|
-
stateMutability: 'view',
|
|
256
|
-
};
|
|
257
|
-
expect(createAbiFunctionItem(contractFunc)).toEqual(expectedAbiFunc);
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
it('should convert ContractFunction with inputs and outputs', () => {
|
|
261
|
-
const contractFunc: ContractFunction = {
|
|
262
|
-
id: 'transfer_address_uint256',
|
|
263
|
-
name: 'transfer',
|
|
264
|
-
displayName: 'Transfer',
|
|
265
|
-
inputs: [
|
|
266
|
-
{ name: 'to', type: 'address', displayName: 'To' },
|
|
267
|
-
{ name: 'amount', type: 'uint256', displayName: 'Amount' },
|
|
268
|
-
],
|
|
269
|
-
outputs: [{ name: 'success', type: 'bool', displayName: 'Success' }],
|
|
270
|
-
type: 'function',
|
|
271
|
-
stateMutability: 'nonpayable',
|
|
272
|
-
modifiesState: true,
|
|
273
|
-
};
|
|
274
|
-
const expectedAbiFunc: AbiFunction = {
|
|
275
|
-
name: 'transfer',
|
|
276
|
-
type: 'function',
|
|
277
|
-
inputs: [
|
|
278
|
-
{ name: 'to', type: 'address' },
|
|
279
|
-
{ name: 'amount', type: 'uint256' },
|
|
280
|
-
],
|
|
281
|
-
outputs: [{ name: 'success', type: 'bool' }],
|
|
282
|
-
stateMutability: 'nonpayable',
|
|
283
|
-
};
|
|
284
|
-
expect(createAbiFunctionItem(contractFunc)).toEqual(expectedAbiFunc);
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
it('should convert ContractFunction with tuple components', () => {
|
|
288
|
-
const contractFunc: ContractFunction = {
|
|
289
|
-
id: 'structFunc_tuple',
|
|
290
|
-
name: 'structFunc',
|
|
291
|
-
displayName: 'Struct Func',
|
|
292
|
-
inputs: [
|
|
293
|
-
{
|
|
294
|
-
name: 'myStruct',
|
|
295
|
-
type: 'tuple',
|
|
296
|
-
displayName: 'My Struct',
|
|
297
|
-
components: [
|
|
298
|
-
{ name: 'field1', type: 'uint256', displayName: 'Field 1' },
|
|
299
|
-
{ name: 'field2', type: 'address', displayName: 'Field 2' },
|
|
300
|
-
],
|
|
301
|
-
},
|
|
302
|
-
],
|
|
303
|
-
outputs: [],
|
|
304
|
-
type: 'function',
|
|
305
|
-
stateMutability: 'pure',
|
|
306
|
-
modifiesState: false,
|
|
307
|
-
};
|
|
308
|
-
const expectedAbiFunc: AbiFunction = {
|
|
309
|
-
name: 'structFunc',
|
|
310
|
-
type: 'function',
|
|
311
|
-
inputs: [
|
|
312
|
-
{
|
|
313
|
-
name: 'myStruct',
|
|
314
|
-
type: 'tuple',
|
|
315
|
-
components: [
|
|
316
|
-
{ name: 'field1', type: 'uint256' },
|
|
317
|
-
{ name: 'field2', type: 'address' },
|
|
318
|
-
],
|
|
319
|
-
},
|
|
320
|
-
],
|
|
321
|
-
outputs: [],
|
|
322
|
-
stateMutability: 'pure',
|
|
323
|
-
};
|
|
324
|
-
expect(createAbiFunctionItem(contractFunc)).toEqual(expectedAbiFunc);
|
|
325
|
-
});
|
|
326
|
-
|
|
327
|
-
it('should default stateMutability to view if undefined in ContractFunction', () => {
|
|
328
|
-
const contractFunc: ContractFunction = {
|
|
329
|
-
id: 'anotherFunc_',
|
|
330
|
-
name: 'anotherFunc',
|
|
331
|
-
displayName: 'Another Func',
|
|
332
|
-
inputs: [],
|
|
333
|
-
outputs: [],
|
|
334
|
-
type: 'function',
|
|
335
|
-
// stateMutability is undefined
|
|
336
|
-
modifiesState: false,
|
|
337
|
-
};
|
|
338
|
-
const result = createAbiFunctionItem(contractFunc);
|
|
339
|
-
expect(result.stateMutability).toBe('view');
|
|
340
|
-
});
|
|
341
|
-
});
|
|
342
|
-
});
|