@aastar/core 0.16.7
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/LICENSE +21 -0
- package/dist/abis/BLSAggregator.json +686 -0
- package/dist/abis/BLSValidator.json +42 -0
- package/dist/abis/DVTValidator.json +368 -0
- package/dist/abis/Eip7702Support.json +24 -0
- package/dist/abis/EntryPoint.json +1382 -0
- package/dist/abis/GToken.json +513 -0
- package/dist/abis/GTokenStaking.json +949 -0
- package/dist/abis/LegacyAccount.json +625 -0
- package/dist/abis/MySBT.json +1518 -0
- package/dist/abis/Paymaster.json +1143 -0
- package/dist/abis/PaymasterFactory.json +640 -0
- package/dist/abis/Registry.json +1942 -0
- package/dist/abis/ReputationSystem.json +699 -0
- package/dist/abis/SenderCreator.json +99 -0
- package/dist/abis/Simple7702Account.json +395 -0
- package/dist/abis/SimpleAccount.json +560 -0
- package/dist/abis/SimpleAccountFactory.json +111 -0
- package/dist/abis/SimpleAccountFactoryV08.json +87 -0
- package/dist/abis/SimpleAccountV08.json +557 -0
- package/dist/abis/SuperPaymaster.json +1781 -0
- package/dist/abis/UserOperationLib.json +57 -0
- package/dist/abis/abi.config.json +24 -0
- package/dist/abis/index.d.ts +1126 -0
- package/dist/abis/index.js +91 -0
- package/dist/abis/xPNTsFactory.json +718 -0
- package/dist/abis/xPNTsToken.json +1280 -0
- package/dist/actions/StateValidator.d.ts +68 -0
- package/dist/actions/StateValidator.js +187 -0
- package/dist/actions/StateValidator.test.d.ts +1 -0
- package/dist/actions/StateValidator.test.js +144 -0
- package/dist/actions/account.d.ts +55 -0
- package/dist/actions/account.js +133 -0
- package/dist/actions/account.test.d.ts +1 -0
- package/dist/actions/account.test.js +118 -0
- package/dist/actions/aggregator.d.ts +17 -0
- package/dist/actions/aggregator.js +31 -0
- package/dist/actions/aggregator.test.d.ts +1 -0
- package/dist/actions/aggregator.test.js +67 -0
- package/dist/actions/dvt.d.ts +30 -0
- package/dist/actions/dvt.js +41 -0
- package/dist/actions/dvt.test.d.ts +1 -0
- package/dist/actions/dvt.test.js +98 -0
- package/dist/actions/entryPoint.d.ts +90 -0
- package/dist/actions/entryPoint.js +211 -0
- package/dist/actions/entryPoint.test.d.ts +1 -0
- package/dist/actions/entryPoint.test.js +139 -0
- package/dist/actions/factory.d.ts +215 -0
- package/dist/actions/factory.js +442 -0
- package/dist/actions/factory.test.d.ts +1 -0
- package/dist/actions/factory.test.js +197 -0
- package/dist/actions/faucet.d.ts +48 -0
- package/dist/actions/faucet.js +337 -0
- package/dist/actions/faucet.test.d.ts +1 -0
- package/dist/actions/faucet.test.js +120 -0
- package/dist/actions/gtokenExtended.d.ts +39 -0
- package/dist/actions/gtokenExtended.js +115 -0
- package/dist/actions/gtokenExtended.test.d.ts +1 -0
- package/dist/actions/gtokenExtended.test.js +118 -0
- package/dist/actions/index.d.ts +15 -0
- package/dist/actions/index.js +17 -0
- package/dist/actions/paymasterV4.d.ts +170 -0
- package/dist/actions/paymasterV4.js +334 -0
- package/dist/actions/paymasterV4.test.d.ts +1 -0
- package/dist/actions/paymasterV4.test.js +159 -0
- package/dist/actions/registry.d.ts +246 -0
- package/dist/actions/registry.js +667 -0
- package/dist/actions/registry.test.d.ts +1 -0
- package/dist/actions/registry.test.js +360 -0
- package/dist/actions/reputation.d.ts +129 -0
- package/dist/actions/reputation.js +281 -0
- package/dist/actions/reputation.test.d.ts +1 -0
- package/dist/actions/reputation.test.js +169 -0
- package/dist/actions/sbt.d.ts +191 -0
- package/dist/actions/sbt.js +533 -0
- package/dist/actions/sbt.test.d.ts +1 -0
- package/dist/actions/sbt.test.js +256 -0
- package/dist/actions/staking.d.ts +132 -0
- package/dist/actions/staking.js +330 -0
- package/dist/actions/staking.test.d.ts +1 -0
- package/dist/actions/staking.test.js +223 -0
- package/dist/actions/superPaymaster.d.ts +237 -0
- package/dist/actions/superPaymaster.js +644 -0
- package/dist/actions/superPaymaster.test.d.ts +1 -0
- package/dist/actions/superPaymaster.test.js +287 -0
- package/dist/actions/tokens.d.ts +229 -0
- package/dist/actions/tokens.js +415 -0
- package/dist/actions/tokens.test.d.ts +1 -0
- package/dist/actions/tokens.test.js +53 -0
- package/dist/actions/validators.d.ts +194 -0
- package/dist/actions/validators.js +433 -0
- package/dist/actions/validators.test.d.ts +1 -0
- package/dist/actions/validators.test.js +215 -0
- package/dist/branding.d.ts +30 -0
- package/dist/branding.js +30 -0
- package/dist/clients/BaseClient.d.ts +25 -0
- package/dist/clients/BaseClient.js +66 -0
- package/dist/clients/types.d.ts +60 -0
- package/dist/clients/types.js +1 -0
- package/dist/clients.d.ts +5 -0
- package/dist/clients.js +11 -0
- package/dist/communities.d.ts +52 -0
- package/dist/communities.js +73 -0
- package/dist/config/ContractConfigManager.d.ts +20 -0
- package/dist/config/ContractConfigManager.js +48 -0
- package/dist/constants.d.ts +88 -0
- package/dist/constants.js +125 -0
- package/dist/contract-addresses.d.ts +110 -0
- package/dist/contract-addresses.js +99 -0
- package/dist/contracts.d.ts +424 -0
- package/dist/contracts.js +343 -0
- package/dist/contracts.test.d.ts +1 -0
- package/dist/contracts.test.js +40 -0
- package/dist/crypto/blsSigner.d.ts +64 -0
- package/dist/crypto/blsSigner.js +98 -0
- package/dist/crypto/index.d.ts +1 -0
- package/dist/crypto/index.js +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +21 -0
- package/dist/networks.d.ts +127 -0
- package/dist/networks.js +118 -0
- package/dist/requirementChecker.d.ts +38 -0
- package/dist/requirementChecker.js +139 -0
- package/dist/requirementChecker.test.d.ts +1 -0
- package/dist/requirementChecker.test.js +60 -0
- package/dist/roles.d.ts +204 -0
- package/dist/roles.js +211 -0
- package/dist/roles.test.d.ts +1 -0
- package/dist/roles.test.js +23 -0
- package/dist/utils/validation.d.ts +24 -0
- package/dist/utils/validation.js +56 -0
- package/dist/utils/validation.test.d.ts +1 -0
- package/dist/utils/validation.test.js +40 -0
- package/dist/utils.d.ts +12 -0
- package/dist/utils.js +14 -0
- package/package.json +33 -0
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { parseEther } from 'viem';
|
|
3
|
+
import { registryActions } from './registry.js';
|
|
4
|
+
describe('Registry Actions', () => {
|
|
5
|
+
const mockRegistryAddress = '0x1234567890123456789012345678901234567890';
|
|
6
|
+
let mockPublicClient;
|
|
7
|
+
let mockWalletClient;
|
|
8
|
+
let mockAccount;
|
|
9
|
+
const MOCK_ROLE_ID = '0xabcd1234567890123456789012345678901234567890abcd1234567890123456';
|
|
10
|
+
const MOCK_USER = '0x2222222222222222222222222222222222222222';
|
|
11
|
+
const MOCK_COMMUNITY = '0x3333333333333333333333333333333333333333';
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
mockAccount = {
|
|
14
|
+
address: MOCK_USER,
|
|
15
|
+
type: 'json-rpc'
|
|
16
|
+
};
|
|
17
|
+
mockPublicClient = {
|
|
18
|
+
readContract: vi.fn(),
|
|
19
|
+
};
|
|
20
|
+
mockWalletClient = {
|
|
21
|
+
writeContract: vi.fn(),
|
|
22
|
+
readContract: vi.fn(),
|
|
23
|
+
account: mockAccount,
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
describe('Role queries', () => {
|
|
27
|
+
it('should check if user has role', async () => {
|
|
28
|
+
mockPublicClient.readContract.mockResolvedValue(true);
|
|
29
|
+
const actions = registryActions(mockRegistryAddress)(mockPublicClient);
|
|
30
|
+
const hasRole = await actions.registryHasRole({ user: MOCK_USER, roleId: MOCK_ROLE_ID });
|
|
31
|
+
expect(hasRole).toBe(true);
|
|
32
|
+
expect(mockPublicClient.readContract).toHaveBeenCalledWith(expect.objectContaining({
|
|
33
|
+
functionName: 'hasRole',
|
|
34
|
+
args: [MOCK_ROLE_ID, MOCK_USER],
|
|
35
|
+
}));
|
|
36
|
+
});
|
|
37
|
+
it('should return false for user without role', async () => {
|
|
38
|
+
mockPublicClient.readContract.mockResolvedValue(false);
|
|
39
|
+
const actions = registryActions(mockRegistryAddress)(mockPublicClient);
|
|
40
|
+
const hasRole = await actions.registryHasRole({ user: MOCK_USER, roleId: MOCK_ROLE_ID });
|
|
41
|
+
expect(hasRole).toBe(false);
|
|
42
|
+
});
|
|
43
|
+
it('should get role config', async () => {
|
|
44
|
+
const mockConfig = { owner: MOCK_USER, fee: 100n };
|
|
45
|
+
mockPublicClient.readContract.mockResolvedValue(mockConfig);
|
|
46
|
+
const actions = registryActions(mockRegistryAddress)(mockPublicClient);
|
|
47
|
+
const config = await actions.registryGetRoleConfig({ roleId: MOCK_ROLE_ID });
|
|
48
|
+
expect(config).toEqual(mockConfig);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
describe('Role management', () => {
|
|
52
|
+
it('should register role', async () => {
|
|
53
|
+
const txHash = '0xabc...';
|
|
54
|
+
mockWalletClient.writeContract.mockResolvedValue(txHash);
|
|
55
|
+
const actions = registryActions(mockRegistryAddress)(mockWalletClient);
|
|
56
|
+
const result = await actions.registryRegisterRole({
|
|
57
|
+
roleId: MOCK_ROLE_ID,
|
|
58
|
+
user: MOCK_USER,
|
|
59
|
+
data: '0x',
|
|
60
|
+
account: mockAccount
|
|
61
|
+
});
|
|
62
|
+
expect(result).toBe(txHash);
|
|
63
|
+
expect(mockWalletClient.writeContract).toHaveBeenCalledWith(expect.objectContaining({
|
|
64
|
+
functionName: 'registerRole',
|
|
65
|
+
}));
|
|
66
|
+
});
|
|
67
|
+
it('should unregister role', async () => {
|
|
68
|
+
const txHash = '0xdef...';
|
|
69
|
+
mockWalletClient.writeContract.mockResolvedValue(txHash);
|
|
70
|
+
const actions = registryActions(mockRegistryAddress)(mockWalletClient);
|
|
71
|
+
const result = await actions.registryUnRegisterRole({
|
|
72
|
+
user: MOCK_USER,
|
|
73
|
+
roleId: MOCK_ROLE_ID,
|
|
74
|
+
account: mockAccount
|
|
75
|
+
});
|
|
76
|
+
expect(result).toBe(txHash);
|
|
77
|
+
});
|
|
78
|
+
it('should register role self', async () => {
|
|
79
|
+
const txHash = '0xghi...';
|
|
80
|
+
mockWalletClient.writeContract.mockResolvedValue(txHash);
|
|
81
|
+
const actions = registryActions(mockRegistryAddress)(mockWalletClient);
|
|
82
|
+
const result = await actions.registryRegisterRoleSelf({
|
|
83
|
+
roleId: MOCK_ROLE_ID,
|
|
84
|
+
data: '0x',
|
|
85
|
+
account: mockAccount
|
|
86
|
+
});
|
|
87
|
+
expect(result).toBe(txHash);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
describe('Community queries', () => {
|
|
91
|
+
it('should check community membership', async () => {
|
|
92
|
+
mockPublicClient.readContract.mockResolvedValue(true);
|
|
93
|
+
const actions = registryActions(mockRegistryAddress)(mockPublicClient);
|
|
94
|
+
const isMember = await actions.registryIsCommunityMember({
|
|
95
|
+
community: MOCK_COMMUNITY,
|
|
96
|
+
user: MOCK_USER
|
|
97
|
+
});
|
|
98
|
+
expect(isMember).toBe(true);
|
|
99
|
+
});
|
|
100
|
+
it('should lookup community by name', async () => {
|
|
101
|
+
mockPublicClient.readContract.mockResolvedValue(MOCK_COMMUNITY);
|
|
102
|
+
const actions = registryActions(mockRegistryAddress)(mockPublicClient);
|
|
103
|
+
const addr = await actions.registryCommunityByName({ name: 'test' });
|
|
104
|
+
expect(addr).toBe(MOCK_COMMUNITY);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
describe('Reputation', () => {
|
|
108
|
+
it('should get global reputation', async () => {
|
|
109
|
+
mockPublicClient.readContract.mockResolvedValue(500n);
|
|
110
|
+
const actions = registryActions(mockRegistryAddress)(mockPublicClient);
|
|
111
|
+
const rep = await actions.registryGlobalReputation({ user: MOCK_USER });
|
|
112
|
+
expect(rep).toBe(500n);
|
|
113
|
+
});
|
|
114
|
+
it('should batch update global reputation', async () => {
|
|
115
|
+
const txHash = '0xhash';
|
|
116
|
+
mockWalletClient.writeContract.mockResolvedValue(txHash);
|
|
117
|
+
const actions = registryActions(mockRegistryAddress)(mockWalletClient);
|
|
118
|
+
const result = await actions.registryBatchUpdateGlobalReputation({
|
|
119
|
+
users: [MOCK_USER],
|
|
120
|
+
scores: [1000n],
|
|
121
|
+
epoch: 1n,
|
|
122
|
+
proof: '0x',
|
|
123
|
+
account: mockAccount
|
|
124
|
+
});
|
|
125
|
+
expect(result).toBe(txHash);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
describe('Blacklist Management', () => {
|
|
129
|
+
it('should update and check operator blacklist', async () => {
|
|
130
|
+
const txHash = '0xhash';
|
|
131
|
+
mockWalletClient.writeContract.mockResolvedValue(txHash);
|
|
132
|
+
mockWalletClient.readContract.mockResolvedValue(true);
|
|
133
|
+
const actions = registryActions(mockRegistryAddress)(mockWalletClient);
|
|
134
|
+
const tx = await actions.registryUpdateOperatorBlacklist({
|
|
135
|
+
operator: MOCK_USER,
|
|
136
|
+
users: [MOCK_USER],
|
|
137
|
+
statuses: [true],
|
|
138
|
+
proof: '0x',
|
|
139
|
+
account: mockAccount
|
|
140
|
+
});
|
|
141
|
+
const isBlacklisted = await actions.registryIsOperatorBlacklisted({ operator: MOCK_USER });
|
|
142
|
+
expect(tx).toBe(txHash);
|
|
143
|
+
expect(isBlacklisted).toBe(true);
|
|
144
|
+
expect(mockWalletClient.writeContract).toHaveBeenCalledWith(expect.objectContaining({
|
|
145
|
+
functionName: 'updateOperatorBlacklist',
|
|
146
|
+
args: [MOCK_USER, [MOCK_USER], [true], '0x'],
|
|
147
|
+
}));
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
describe('Contract References', () => {
|
|
151
|
+
it('should query all contract references', async () => {
|
|
152
|
+
mockPublicClient.readContract.mockResolvedValue(MOCK_USER);
|
|
153
|
+
const actions = registryActions(mockRegistryAddress)(mockPublicClient);
|
|
154
|
+
const results = await Promise.all([
|
|
155
|
+
actions.registryBlsValidator(),
|
|
156
|
+
actions.registryBlsAggregator(),
|
|
157
|
+
actions.registryMySBT(),
|
|
158
|
+
actions.registrySuperPaymaster(),
|
|
159
|
+
actions.registryStaking(),
|
|
160
|
+
actions.registryReputationSource(),
|
|
161
|
+
actions.registryLevelThresholds({ level: 0n }),
|
|
162
|
+
actions.registryIsReputationSource({ source: MOCK_USER }),
|
|
163
|
+
actions.registryCreditTierConfig({ level: 1n }),
|
|
164
|
+
actions.registryRoleConfigs({ roleId: MOCK_ROLE_ID }),
|
|
165
|
+
actions.registryRoleLockDurations({ roleId: MOCK_ROLE_ID }),
|
|
166
|
+
actions.registryRoleOwners({ roleId: MOCK_ROLE_ID }),
|
|
167
|
+
actions.registryRoleSBTTokenIds({ roleId: MOCK_ROLE_ID, user: MOCK_USER }),
|
|
168
|
+
actions.registryRoleStakes({ roleId: MOCK_ROLE_ID, user: MOCK_USER }),
|
|
169
|
+
actions.registryUserRoles({ user: MOCK_USER, index: 0n }),
|
|
170
|
+
actions.registryUserRoleCount({ user: MOCK_USER }),
|
|
171
|
+
actions.registryRoleMetadata({ roleId: MOCK_ROLE_ID }),
|
|
172
|
+
actions.registryRoleMemberIndex({ roleId: MOCK_ROLE_ID, user: MOCK_USER }),
|
|
173
|
+
actions.registryRoleMembers({ roleId: MOCK_ROLE_ID, index: 0n }),
|
|
174
|
+
actions.registryRoleCounts({ roleId: MOCK_ROLE_ID })
|
|
175
|
+
]);
|
|
176
|
+
results.forEach(res => expect(res).toBeDefined());
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
describe('Role Operations', () => {
|
|
180
|
+
it('should exit role and calculate fee', async () => {
|
|
181
|
+
const txHash = '0xhash';
|
|
182
|
+
mockWalletClient.writeContract.mockResolvedValue(txHash);
|
|
183
|
+
mockPublicClient.readContract.mockResolvedValue(parseEther('1'));
|
|
184
|
+
const actions = registryActions(mockRegistryAddress)(mockWalletClient);
|
|
185
|
+
const actionsRead = registryActions(mockRegistryAddress)(mockPublicClient);
|
|
186
|
+
const fee = await actionsRead.registryCalculateExitFee({ roleId: MOCK_ROLE_ID, amount: 1000n });
|
|
187
|
+
const tx = await actions.registryExitRole({ roleId: MOCK_ROLE_ID, account: mockAccount });
|
|
188
|
+
expect(fee).toBe(parseEther('1'));
|
|
189
|
+
expect(tx).toBe(txHash);
|
|
190
|
+
expect(mockPublicClient.readContract).toHaveBeenCalledWith(expect.objectContaining({
|
|
191
|
+
functionName: 'calculateExitFee',
|
|
192
|
+
args: [MOCK_ROLE_ID, 1000n],
|
|
193
|
+
}));
|
|
194
|
+
});
|
|
195
|
+
it('should check if user is community member', async () => {
|
|
196
|
+
// isCommunityMember uses ROLE_ENDUSER check internally
|
|
197
|
+
mockPublicClient.readContract.mockResolvedValue('0xROLE'); // ROLE_ENDUSER
|
|
198
|
+
mockPublicClient.readContract.mockResolvedValueOnce('0xROLE').mockResolvedValueOnce(true);
|
|
199
|
+
const actions = registryActions(mockRegistryAddress)(mockPublicClient);
|
|
200
|
+
const isMember = await actions.registryIsCommunityMember({ community: MOCK_COMMUNITY, user: MOCK_USER });
|
|
201
|
+
expect(isMember).toBe(true);
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
describe('Constants (Role IDs)', () => {
|
|
205
|
+
it('should return all role ID constants', async () => {
|
|
206
|
+
mockPublicClient.readContract.mockResolvedValue('0xROLE');
|
|
207
|
+
const actions = registryActions(mockRegistryAddress)(mockPublicClient);
|
|
208
|
+
expect(await actions.registryROLE_COMMUNITY()).toBe('0xROLE');
|
|
209
|
+
expect(await actions.registryROLE_ENDUSER()).toBe('0xROLE');
|
|
210
|
+
expect(await actions.registryROLE_PAYMASTER_AOA()).toBe('0xROLE');
|
|
211
|
+
expect(await actions.registryROLE_PAYMASTER_SUPER()).toBe('0xROLE');
|
|
212
|
+
expect(await actions.registryROLE_DVT()).toBe('0xROLE');
|
|
213
|
+
expect(await actions.registryROLE_ANODE()).toBe('0xROLE');
|
|
214
|
+
expect(await actions.registryROLE_KMS()).toBe('0xROLE');
|
|
215
|
+
expect(await actions.registryGTOKEN_STAKING()).toBe('0xROLE');
|
|
216
|
+
expect(await actions.registryMYSBT()).toBe('0xROLE');
|
|
217
|
+
expect(await actions.registrySUPER_PAYMASTER()).toBe('0xROLE');
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
describe('View & Metadata Functions', () => {
|
|
221
|
+
it('should query role metadata and count', async () => {
|
|
222
|
+
mockPublicClient.readContract
|
|
223
|
+
.mockResolvedValueOnce(10n) // count
|
|
224
|
+
.mockResolvedValueOnce({ meta: 'data' }) // metadata
|
|
225
|
+
.mockResolvedValueOnce(3600n); // lock duration
|
|
226
|
+
const actions = registryActions(mockRegistryAddress)(mockPublicClient);
|
|
227
|
+
const count = await actions.registryGetRoleUserCount({ roleId: MOCK_ROLE_ID });
|
|
228
|
+
const meta = await actions.registryRoleMetadata({ roleId: MOCK_ROLE_ID });
|
|
229
|
+
const lock = await actions.registryRoleLockDurations({ roleId: MOCK_ROLE_ID });
|
|
230
|
+
expect(count).toBe(10n);
|
|
231
|
+
expect(meta).toEqual({ meta: 'data' });
|
|
232
|
+
expect(lock).toBe(3600n);
|
|
233
|
+
});
|
|
234
|
+
it('should query user-specific role data', async () => {
|
|
235
|
+
mockPublicClient.readContract
|
|
236
|
+
.mockResolvedValueOnce(100n) // stake
|
|
237
|
+
.mockResolvedValueOnce(1n); // sbt id
|
|
238
|
+
const actions = registryActions(mockRegistryAddress)(mockPublicClient);
|
|
239
|
+
const stake = await actions.registryRoleStakes({ roleId: MOCK_ROLE_ID, user: MOCK_USER });
|
|
240
|
+
const sbtId = await actions.registryRoleSBTTokenIds({ roleId: MOCK_ROLE_ID, user: MOCK_USER });
|
|
241
|
+
expect(stake).toBe(100n);
|
|
242
|
+
expect(sbtId).toBe(1n);
|
|
243
|
+
});
|
|
244
|
+
it('should query list functions', async () => {
|
|
245
|
+
mockPublicClient.readContract
|
|
246
|
+
.mockResolvedValueOnce([MOCK_USER]) // members
|
|
247
|
+
.mockResolvedValueOnce(['0xROLE']); // user roles
|
|
248
|
+
const actions = registryActions(mockRegistryAddress)(mockPublicClient);
|
|
249
|
+
const members = await actions.registryGetRoleMembers({ roleId: MOCK_ROLE_ID });
|
|
250
|
+
const roles = await actions.registryGetUserRoles({ user: MOCK_USER });
|
|
251
|
+
expect(members).toEqual([MOCK_USER]);
|
|
252
|
+
expect(roles).toEqual(['0xROLE']);
|
|
253
|
+
});
|
|
254
|
+
it('should get version', async () => {
|
|
255
|
+
mockPublicClient.readContract.mockResolvedValue('1.0.0');
|
|
256
|
+
const actions = registryActions(mockRegistryAddress)(mockPublicClient);
|
|
257
|
+
expect(await actions.registryVersion()).toBe('1.0.0');
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
describe('Advanced View & Utility Functions', () => {
|
|
261
|
+
it('should query role metadata specifics', async () => {
|
|
262
|
+
mockPublicClient.readContract
|
|
263
|
+
.mockResolvedValueOnce(MOCK_USER) // roleOwners
|
|
264
|
+
.mockResolvedValueOnce(0n) // roleMemberIndex
|
|
265
|
+
.mockResolvedValueOnce('ProposedName'); // proposedRoleNames
|
|
266
|
+
const actions = registryActions(mockRegistryAddress)(mockPublicClient);
|
|
267
|
+
const owner = await actions.registryRoleOwners({ roleId: MOCK_ROLE_ID });
|
|
268
|
+
const index = await actions.registryRoleMemberIndex({ roleId: MOCK_ROLE_ID, user: MOCK_USER });
|
|
269
|
+
const name = await actions.registryProposedRoleNames({ roleId: MOCK_ROLE_ID });
|
|
270
|
+
expect(owner).toBe(MOCK_USER);
|
|
271
|
+
expect(index).toBe(0n);
|
|
272
|
+
expect(name).toBe('ProposedName');
|
|
273
|
+
});
|
|
274
|
+
it('should query reputation source and epoch', async () => {
|
|
275
|
+
mockPublicClient.readContract
|
|
276
|
+
.mockResolvedValueOnce(true) // isReputationSource
|
|
277
|
+
.mockResolvedValueOnce(10n); // lastReputationEpoch
|
|
278
|
+
const actions = registryActions(mockRegistryAddress)(mockPublicClient);
|
|
279
|
+
expect(await actions.registryIsReputationSource({ source: MOCK_USER })).toBe(true);
|
|
280
|
+
expect(await actions.registryLastReputationEpoch()).toBe(10n);
|
|
281
|
+
});
|
|
282
|
+
it('should lookup accounts and executed proposals', async () => {
|
|
283
|
+
mockPublicClient.readContract
|
|
284
|
+
.mockResolvedValueOnce(MOCK_USER) // accountToUser
|
|
285
|
+
.mockResolvedValueOnce(true); // executedProposals
|
|
286
|
+
const actions = registryActions(mockRegistryAddress)(mockPublicClient);
|
|
287
|
+
const user = await actions.registryAccountToUser({ account: MOCK_USER });
|
|
288
|
+
const executed = await actions.registryExecutedProposals({ proposalId: 1n });
|
|
289
|
+
expect(user).toBe(MOCK_USER);
|
|
290
|
+
expect(executed).toBe(true);
|
|
291
|
+
});
|
|
292
|
+
it('should lookup communities', async () => {
|
|
293
|
+
mockPublicClient.readContract.mockResolvedValue(MOCK_COMMUNITY);
|
|
294
|
+
const actions = registryActions(mockRegistryAddress)(mockPublicClient);
|
|
295
|
+
expect(await actions.registryCommunityByName({ name: 'test' })).toBe(MOCK_COMMUNITY);
|
|
296
|
+
expect(await actions.registryCommunityByENS({ ensName: 'test.eth' })).toBe(MOCK_COMMUNITY);
|
|
297
|
+
expect(await actions.registryCommunityByNameV3({ name: 'test' })).toBe(MOCK_COMMUNITY);
|
|
298
|
+
expect(await actions.registryCommunityByENSV3({ ensName: 'test.eth' })).toBe(MOCK_COMMUNITY);
|
|
299
|
+
});
|
|
300
|
+
it('should manage role settings (admin)', async () => {
|
|
301
|
+
const txHash = '0xhash';
|
|
302
|
+
mockWalletClient.writeContract.mockResolvedValue(txHash);
|
|
303
|
+
const actions = registryActions(mockRegistryAddress)(mockWalletClient);
|
|
304
|
+
expect(await actions.registrySetRoleLockDuration({ roleId: MOCK_ROLE_ID, duration: 86400n, account: mockAccount })).toBe(txHash);
|
|
305
|
+
expect(await actions.registrySetRoleOwner({ roleId: MOCK_ROLE_ID, newOwner: MOCK_USER, account: mockAccount })).toBe(txHash);
|
|
306
|
+
expect(await actions.registryAddLevelThreshold({ threshold: 100n, account: mockAccount })).toBe(txHash);
|
|
307
|
+
expect(await actions.registrySetLevelThreshold({ index: 0n, threshold: 50n, account: mockAccount })).toBe(txHash);
|
|
308
|
+
expect(await actions.registrySetCreditTier({ level: 1n, limit: 1000n, account: mockAccount })).toBe(txHash);
|
|
309
|
+
});
|
|
310
|
+
it('should perform advanced admin operations', async () => {
|
|
311
|
+
const txHash = '0xhash';
|
|
312
|
+
mockWalletClient.writeContract.mockResolvedValue(txHash);
|
|
313
|
+
const actions = registryActions(mockRegistryAddress)(mockWalletClient);
|
|
314
|
+
expect(await actions.registryAdminConfigureRole({
|
|
315
|
+
roleId: MOCK_ROLE_ID,
|
|
316
|
+
minStake: 1n,
|
|
317
|
+
entryBurn: 1n,
|
|
318
|
+
exitFeePercent: 100,
|
|
319
|
+
minExitFee: 1n,
|
|
320
|
+
account: mockAccount
|
|
321
|
+
})).toBe(txHash);
|
|
322
|
+
expect(await actions.registryCreateNewRole({
|
|
323
|
+
roleId: MOCK_ROLE_ID,
|
|
324
|
+
config: { minStake: 1n },
|
|
325
|
+
roleOwner: MOCK_USER,
|
|
326
|
+
account: mockAccount
|
|
327
|
+
})).toBe(txHash);
|
|
328
|
+
expect(await actions.registrySafeMintForRole({
|
|
329
|
+
roleId: MOCK_ROLE_ID,
|
|
330
|
+
user: MOCK_USER,
|
|
331
|
+
data: '0x',
|
|
332
|
+
account: mockAccount
|
|
333
|
+
})).toBe(txHash);
|
|
334
|
+
});
|
|
335
|
+
it('should query credit and tiers', async () => {
|
|
336
|
+
mockPublicClient.readContract.mockResolvedValue(1000n);
|
|
337
|
+
const actions = registryActions(mockRegistryAddress)(mockPublicClient);
|
|
338
|
+
expect(await actions.registryGetCreditLimit({ user: MOCK_USER })).toBe(1000n);
|
|
339
|
+
expect(await actions.registryCreditTierConfig({ level: 1n })).toBe(1000n);
|
|
340
|
+
});
|
|
341
|
+
it('should manage administrative setters', async () => {
|
|
342
|
+
const txHash = '0xhash';
|
|
343
|
+
mockWalletClient.writeContract.mockResolvedValue(txHash);
|
|
344
|
+
const actions = registryActions(mockRegistryAddress)(mockWalletClient);
|
|
345
|
+
expect(await actions.registrySetBLSValidator({ validator: MOCK_USER, account: mockAccount })).toBe(txHash);
|
|
346
|
+
expect(await actions.registrySetBLSAggregator({ aggregator: MOCK_USER, account: mockAccount })).toBe(txHash);
|
|
347
|
+
expect(await actions.registrySetMySBT({ sbt: MOCK_USER, account: mockAccount })).toBe(txHash);
|
|
348
|
+
expect(await actions.registrySetSuperPaymaster({ paymaster: MOCK_USER, account: mockAccount })).toBe(txHash);
|
|
349
|
+
expect(await actions.registrySetStaking({ staking: MOCK_USER, account: mockAccount })).toBe(txHash);
|
|
350
|
+
expect(await actions.registrySetReputationSource({ source: MOCK_USER, account: mockAccount })).toBe(txHash);
|
|
351
|
+
expect(await actions.registryTransferOwnership({ newOwner: MOCK_USER, account: mockAccount })).toBe(txHash);
|
|
352
|
+
expect(await actions.registryRenounceOwnership({ account: mockAccount })).toBe(txHash);
|
|
353
|
+
});
|
|
354
|
+
it('should query simple properties', async () => {
|
|
355
|
+
mockPublicClient.readContract.mockResolvedValue(MOCK_USER);
|
|
356
|
+
const actions = registryActions(mockRegistryAddress)(mockPublicClient);
|
|
357
|
+
expect(await actions.registryOwner()).toBe(MOCK_USER);
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
});
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { type Address, type PublicClient, type WalletClient, type Hex, type Hash, type Account } from 'viem';
|
|
2
|
+
export type ReputationActions = {
|
|
3
|
+
setReputationRule: (args: {
|
|
4
|
+
ruleId: Hex;
|
|
5
|
+
rule: any;
|
|
6
|
+
account?: Account | Address;
|
|
7
|
+
}) => Promise<Hash>;
|
|
8
|
+
getReputationRule: (args: {
|
|
9
|
+
ruleId: Hex;
|
|
10
|
+
}) => Promise<any>;
|
|
11
|
+
enableRule: (args: {
|
|
12
|
+
ruleId: Hex;
|
|
13
|
+
account?: Account | Address;
|
|
14
|
+
}) => Promise<Hash>;
|
|
15
|
+
disableRule: (args: {
|
|
16
|
+
ruleId: Hex;
|
|
17
|
+
account?: Account | Address;
|
|
18
|
+
}) => Promise<Hash>;
|
|
19
|
+
isRuleActive: (args: {
|
|
20
|
+
ruleId: Hex;
|
|
21
|
+
}) => Promise<boolean>;
|
|
22
|
+
getActiveRules: (args: {
|
|
23
|
+
community: Address;
|
|
24
|
+
}) => Promise<Hex[]>;
|
|
25
|
+
getRuleCount: () => Promise<bigint>;
|
|
26
|
+
computeScore: (args: {
|
|
27
|
+
user: Address;
|
|
28
|
+
community: Address;
|
|
29
|
+
}) => Promise<bigint>;
|
|
30
|
+
getUserScore: (args: {
|
|
31
|
+
user: Address;
|
|
32
|
+
}) => Promise<bigint>;
|
|
33
|
+
getCommunityScore: (args: {
|
|
34
|
+
community: Address;
|
|
35
|
+
}) => Promise<bigint>;
|
|
36
|
+
communityReputations: (args: {
|
|
37
|
+
community: Address;
|
|
38
|
+
user: Address;
|
|
39
|
+
}) => Promise<bigint>;
|
|
40
|
+
setRule: (args: {
|
|
41
|
+
ruleId: Hex;
|
|
42
|
+
rule: any;
|
|
43
|
+
account?: Account | Address;
|
|
44
|
+
}) => Promise<Hash>;
|
|
45
|
+
calculateReputation: (args: {
|
|
46
|
+
user: Address;
|
|
47
|
+
community: Address;
|
|
48
|
+
}) => Promise<bigint>;
|
|
49
|
+
nftCollectionBoost: (args: {
|
|
50
|
+
collection: Address;
|
|
51
|
+
}) => Promise<bigint>;
|
|
52
|
+
batchUpdateScores: (args: {
|
|
53
|
+
users: Address[];
|
|
54
|
+
scores: bigint[];
|
|
55
|
+
account?: Account | Address;
|
|
56
|
+
}) => Promise<Hash>;
|
|
57
|
+
batchSyncToRegistry: (args: {
|
|
58
|
+
users: Address[];
|
|
59
|
+
account?: Account | Address;
|
|
60
|
+
}) => Promise<Hash>;
|
|
61
|
+
syncToRegistry: (args: {
|
|
62
|
+
user: Address;
|
|
63
|
+
communities: Address[];
|
|
64
|
+
ruleIds: Hex[][];
|
|
65
|
+
activities: bigint[][];
|
|
66
|
+
epoch: bigint;
|
|
67
|
+
proof: Hex;
|
|
68
|
+
account?: Account | Address;
|
|
69
|
+
}) => Promise<Hash>;
|
|
70
|
+
setRegistry: (args: {
|
|
71
|
+
registry: Address;
|
|
72
|
+
account?: Account | Address;
|
|
73
|
+
}) => Promise<Hash>;
|
|
74
|
+
setEntropyFactor: (args: {
|
|
75
|
+
factor: bigint;
|
|
76
|
+
account?: Account | Address;
|
|
77
|
+
}) => Promise<Hash>;
|
|
78
|
+
getEntropyFactor: () => Promise<bigint>;
|
|
79
|
+
REGISTRY: () => Promise<Address>;
|
|
80
|
+
reputationOwner: () => Promise<Address>;
|
|
81
|
+
transferReputationOwnership: (args: {
|
|
82
|
+
newOwner: Address;
|
|
83
|
+
account?: Account | Address;
|
|
84
|
+
}) => Promise<Hash>;
|
|
85
|
+
renounceReputationOwnership: (args: {
|
|
86
|
+
account?: Account | Address;
|
|
87
|
+
}) => Promise<Hash>;
|
|
88
|
+
setCommunityReputation: (args: {
|
|
89
|
+
community: Address;
|
|
90
|
+
reputation: bigint;
|
|
91
|
+
account?: Account | Address;
|
|
92
|
+
}) => Promise<Hash>;
|
|
93
|
+
updateNFTHoldStart: (args: {
|
|
94
|
+
user: Address;
|
|
95
|
+
collection: Address;
|
|
96
|
+
start: bigint;
|
|
97
|
+
account?: Account | Address;
|
|
98
|
+
}) => Promise<Hash>;
|
|
99
|
+
communityRules: (args: {
|
|
100
|
+
community: Address;
|
|
101
|
+
ruleId: Hex;
|
|
102
|
+
}) => Promise<boolean>;
|
|
103
|
+
defaultRule: () => Promise<Hex>;
|
|
104
|
+
entropyFactors: (args: {
|
|
105
|
+
factorId: bigint;
|
|
106
|
+
}) => Promise<bigint>;
|
|
107
|
+
nftHoldStart: (args: {
|
|
108
|
+
user: Address;
|
|
109
|
+
collection: Address;
|
|
110
|
+
}) => Promise<bigint>;
|
|
111
|
+
boostedCollections: (args: {
|
|
112
|
+
collection: Address;
|
|
113
|
+
}) => Promise<bigint>;
|
|
114
|
+
communityActiveRules: (args: {
|
|
115
|
+
community: Address;
|
|
116
|
+
ruleId: Hex;
|
|
117
|
+
}) => Promise<boolean>;
|
|
118
|
+
getReputationBreakdown: (args: {
|
|
119
|
+
user: Address;
|
|
120
|
+
community: Address;
|
|
121
|
+
}) => Promise<any>;
|
|
122
|
+
setNFTBoost: (args: {
|
|
123
|
+
collection: Address;
|
|
124
|
+
boost: bigint;
|
|
125
|
+
account?: Account | Address;
|
|
126
|
+
}) => Promise<Hash>;
|
|
127
|
+
reputationVersion: () => Promise<string>;
|
|
128
|
+
};
|
|
129
|
+
export declare const reputationActions: (address: Address) => (client: PublicClient | WalletClient) => ReputationActions;
|