rocketh 0.11.21 → 0.11.22-testing.1
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/CHANGELOG.md +12 -0
- package/dist/environment/index.d.ts +0 -3
- package/dist/environment/index.d.ts.map +1 -1
- package/dist/environment/index.js +14 -15
- package/dist/environment/index.js.map +1 -1
- package/dist/environment/types.d.ts +2 -0
- package/dist/environment/types.d.ts.map +1 -1
- package/dist/executor/index.d.ts +31 -3
- package/dist/executor/index.d.ts.map +1 -1
- package/dist/executor/index.js +46 -7
- package/dist/executor/index.js.map +1 -1
- package/dist/executor/setup.test.d.ts +13 -0
- package/dist/executor/setup.test.d.ts.map +1 -0
- package/dist/executor/setup.test.js +106 -0
- package/dist/executor/setup.test.js.map +1 -0
- package/dist/executor/types.d.ts +20 -0
- package/dist/executor/types.d.ts.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/types.d.ts +2 -0
- package/dist/internal/types.d.ts.map +1 -1
- package/dist/utils/curry.d.ts +35 -0
- package/dist/utils/curry.d.ts.map +1 -0
- package/dist/utils/curry.js +30 -0
- package/dist/utils/curry.js.map +1 -0
- package/dist/utils/curry.test.d.ts +16 -0
- package/dist/utils/curry.test.d.ts.map +1 -0
- package/dist/utils/curry.test.js +33 -0
- package/dist/utils/curry.test.js.map +1 -0
- package/package.json +1 -1
- package/src/environment/index.ts +16 -18
- package/src/environment/types.ts +2 -0
- package/src/executor/index.ts +64 -18
- package/src/executor/setup.test.ts +133 -0
- package/src/executor/types.ts +45 -0
- package/src/index.ts +0 -1
- package/src/internal/types.ts +3 -0
- package/src/utils/curry.test.ts +42 -0
- package/src/utils/curry.ts +60 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type {Environment} from '../environment/types.js';
|
|
2
|
+
import {withEnvironment} from './curry.js';
|
|
3
|
+
|
|
4
|
+
// Mock environment for testing
|
|
5
|
+
const mockEnv = {} as Environment;
|
|
6
|
+
|
|
7
|
+
// Example functions that take environment as first parameter
|
|
8
|
+
const exampleFunctions = {
|
|
9
|
+
deploy: (env: Environment, contractName: string, args: any[]): Promise<void> => {
|
|
10
|
+
return Promise.resolve();
|
|
11
|
+
},
|
|
12
|
+
|
|
13
|
+
verify: (env: Environment, address: string): Promise<boolean> => {
|
|
14
|
+
return Promise.resolve(true);
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
getBalance: (env: Environment, address: string): Promise<bigint> => {
|
|
18
|
+
return Promise.resolve(BigInt(0));
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
syncFunction: (env: Environment, value: number): number => {
|
|
22
|
+
return value * 2;
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// Test the currying function
|
|
27
|
+
const curriedFunctions = withEnvironment(mockEnv, exampleFunctions);
|
|
28
|
+
|
|
29
|
+
// Type tests - these should compile without errors
|
|
30
|
+
async function testTypes() {
|
|
31
|
+
// These calls should work without passing env
|
|
32
|
+
await curriedFunctions.deploy('MyContract', []);
|
|
33
|
+
const isVerified = await curriedFunctions.verify('0x123...');
|
|
34
|
+
const balance = await curriedFunctions.getBalance('0x456...');
|
|
35
|
+
const doubled = curriedFunctions.syncFunction(42);
|
|
36
|
+
|
|
37
|
+
console.log('Type tests passed!');
|
|
38
|
+
console.log({isVerified, balance, doubled});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Export for potential use in actual tests
|
|
42
|
+
export {testTypes, curriedFunctions, exampleFunctions};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Environment,
|
|
3
|
+
UnknownDeployments,
|
|
4
|
+
UnresolvedNetworkSpecificData,
|
|
5
|
+
UnresolvedUnknownNamedAccounts,
|
|
6
|
+
} from '../environment/types.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Utility type to remove the first parameter from a function type
|
|
10
|
+
*/
|
|
11
|
+
type RemoveFirstParameter<T> = T extends (first: any, ...rest: infer R) => infer Return
|
|
12
|
+
? (...args: R) => Return
|
|
13
|
+
: never;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Utility type to transform an object of functions by removing their first parameter
|
|
17
|
+
*/
|
|
18
|
+
type CurriedFunctions<T> = {
|
|
19
|
+
[K in keyof T]: RemoveFirstParameter<T[K]>;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Creates a curried version of functions that automatically inject an environment as the first parameter.
|
|
24
|
+
*
|
|
25
|
+
* @param env - The environment object to inject as the first parameter
|
|
26
|
+
* @param functions - An object containing functions that expect the environment as their first parameter
|
|
27
|
+
* @returns An object with the same function names, but with the environment parameter removed
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const functions = {
|
|
32
|
+
* deploy: (env: Environment, contractName: string, args: any[]) => Promise<void>,
|
|
33
|
+
* verify: (env: Environment, address: string) => Promise<boolean>
|
|
34
|
+
* };
|
|
35
|
+
*
|
|
36
|
+
* const curriedFunctions = withEnvironment(env, functions);
|
|
37
|
+
*
|
|
38
|
+
* // Now you can call without passing env:
|
|
39
|
+
* await curriedFunctions.deploy('MyContract', []);
|
|
40
|
+
* await curriedFunctions.verify('0x123...');
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export function withEnvironment<
|
|
44
|
+
NamedAccounts extends UnresolvedUnknownNamedAccounts = UnresolvedUnknownNamedAccounts,
|
|
45
|
+
Data extends UnresolvedNetworkSpecificData = UnresolvedNetworkSpecificData,
|
|
46
|
+
Deployments extends UnknownDeployments = UnknownDeployments,
|
|
47
|
+
T extends Record<string, (env: Environment<NamedAccounts, Data, Deployments>, ...args: any[]) => any> = Record<
|
|
48
|
+
string,
|
|
49
|
+
(env: Environment<NamedAccounts, Data, Deployments>, ...args: any[]) => any
|
|
50
|
+
>
|
|
51
|
+
>(env: Environment<NamedAccounts, Data, Deployments>, functions: T): CurriedFunctions<T> {
|
|
52
|
+
const result = {} as CurriedFunctions<T>;
|
|
53
|
+
|
|
54
|
+
for (const [key, func] of Object.entries(functions)) {
|
|
55
|
+
// Create a new function that automatically passes the environment as the first argument
|
|
56
|
+
(result as any)[key] = (...args: any[]) => func(env, ...args);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return result;
|
|
60
|
+
}
|