Skip to content

Commit 4970ac4

Browse files
authored
Merge pull request #844 from LIT-Protocol/feature/node-4612-add-ledger-deposit-for-e2e-tests
Feature/node 4612 add ledger deposit for e2e tests
2 parents 51f2cb1 + cac2eef commit 4970ac4

File tree

10 files changed

+230
-2951
lines changed

10 files changed

+230
-2951
lines changed

apps/lit-auth-service/bun.lock

Lines changed: 0 additions & 1406 deletions
This file was deleted.

apps/lit-login-service/bun.lock

Lines changed: 0 additions & 1397 deletions
This file was deleted.

bun.lock

Lines changed: 170 additions & 120 deletions
Large diffs are not rendered by default.

e2e/src/helper/tests/encrypt-decrypt-flow.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,9 @@ export const createEncryptDecryptFlowTest = (
99
const { createAccBuilder } = await import(
1010
'@lit-protocol/access-control-conditions'
1111
);
12-
const { generatePrivateKey, privateKeyToAccount } = await import(
13-
'viem/accounts'
14-
);
1512

1613
const authContext = getAuthContext();
1714

18-
// Create a test account for Bob (recipient)
19-
const bobAccount = privateKeyToAccount(generatePrivateKey());
20-
2115
// Determine which address to use for Alice based on auth context type
2216
let aliceAddress: string;
2317
if (authContext === ctx.aliceEoaAuthContext) {
@@ -29,7 +23,7 @@ export const createEncryptDecryptFlowTest = (
2923
// Set up access control conditions requiring Bob's wallet ownership
3024
const builder = createAccBuilder();
3125
const accs = builder
32-
.requireWalletOwnership(bobAccount.address)
26+
.requireWalletOwnership(ctx.bobViemAccount.address)
3327
.on('ethereum')
3428
.build();
3529

@@ -50,7 +44,7 @@ export const createEncryptDecryptFlowTest = (
5044
const jsonData = {
5145
message: 'Test JSON data',
5246
sender: aliceAddress,
53-
recipient: bobAccount.address,
47+
recipient: ctx.bobViemAccount.address,
5448
timestamp: Date.now(),
5549
};
5650

@@ -105,7 +99,7 @@ export const createEncryptDecryptFlowTest = (
10599
// Create Bob's auth context for decryption
106100
const bobAuthContext = await ctx.authManager.createEoaAuthContext({
107101
config: {
108-
account: bobAccount,
102+
account: ctx.bobViemAccount,
109103
},
110104
authConfig: {
111105
domain: 'localhost',

e2e/src/init.ts

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type LogLevel = z.infer<typeof LogLevelSchema>;
2525
// Configurations
2626
const LIVE_NETWORK_FUNDING_AMOUNT = '0.01';
2727
const LOCAL_NETWORK_FUNDING_AMOUNT = '1';
28+
const LIVE_NETWORK_LEDGER_DEPOSIT_AMOUNT = '2';
2829

2930
export const init = async (
3031
network?: SupportedNetwork,
@@ -41,6 +42,7 @@ export const init = async (
4142
bobViemAccountPkp: any;
4243
aliceEoaAuthContext: any;
4344
alicePkpAuthContext: any;
45+
masterDepositForUser: (userAddress: string) => Promise<void>;
4446
// alicePkpViemAccountPermissionsManager: any,
4547
}> => {
4648
/**
@@ -132,6 +134,18 @@ export const init = async (
132134
*/
133135
const litClient = await createLitClient({ network: _networkModule });
134136

137+
/**
138+
* ====================================
139+
* (Master) Initialise Payment Manager
140+
* ====================================
141+
*/
142+
const masterPaymentManager = await litClient.getPaymentManager({
143+
account: masterAccount,
144+
});
145+
146+
const masterPaymentBalance = await masterPaymentManager.getBalance({ userAddress: masterAccount.address })
147+
console.log('✅ Master Payment Balance:', masterPaymentBalance);
148+
135149
/**
136150
* ====================================
137151
* Initialise the AuthManager
@@ -211,16 +225,39 @@ export const init = async (
211225
litClient: litClient,
212226
});
213227

214-
// const alicePkpViemAccount = await litClient.getPkpViemAccount({
215-
// pkpPublicKey: aliceViemAccountPkp.publicKey,
216-
// authContext: alicePkpAuthContext,
217-
// chainConfig: _networkModule.getChainConfig(),
218-
// });
228+
const alicePkpViemAccount = await litClient.getPkpViemAccount({
229+
pkpPublicKey: aliceViemAccountPkp.publicKey,
230+
authContext: alicePkpAuthContext,
231+
chainConfig: _networkModule.getChainConfig(),
232+
});
219233

220-
// await fundAccount(alicePkpViemAccount, localMasterAccount, _networkModule, {
221-
// ifLessThan: LOCAL_NETWORK_FUNDING_AMOUNT,
222-
// thenFundWith: LOCAL_NETWORK_FUNDING_AMOUNT,
223-
// });
234+
await fundAccount(alicePkpViemAccount, masterAccount, _networkModule, {
235+
ifLessThan: LOCAL_NETWORK_FUNDING_AMOUNT,
236+
thenFundWith: LOCAL_NETWORK_FUNDING_AMOUNT,
237+
});
238+
239+
/**
240+
* ====================================
241+
* Depositing to Lit Ledger for differen
242+
* ====================================
243+
*/
244+
245+
async function masterDepositForUser(userAddress: string) {
246+
await masterPaymentManager.depositForUser({ userAddress: userAddress, amountInEth: LIVE_NETWORK_LEDGER_DEPOSIT_AMOUNT });
247+
console.log(`✅ New ${userAddress} Ledger Balance:`, await masterPaymentManager.getBalance({ userAddress: userAddress }));
248+
}
249+
250+
// Deposit to the Alice EOA Ledger
251+
await masterDepositForUser(aliceViemAccount.address);
252+
253+
// Deposit to the PKP Ledger
254+
await masterDepositForUser(alicePkpViemAccount.address);
255+
256+
// Deposit to the Bob EOA Ledger
257+
await masterDepositForUser(bobViemAccount.address);
258+
259+
// Deposit to the Bob PKP Ledger
260+
await masterDepositForUser(bobViemAccountPkp.ethAddress);
224261

225262
// const alicePkpViemAccountPermissionsManager = await litClient.getPKPPermissionsManager({
226263
// pkpIdentifier: {
@@ -247,6 +284,7 @@ export const init = async (
247284
bobViemAccountPkp,
248285
aliceEoaAuthContext,
249286
alicePkpAuthContext,
287+
masterDepositForUser
250288
// alicePkpViemAccountPermissionsManager
251289
};
252290
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"private": true,
3535
"dependencies": {
3636
"@dotenvx/dotenvx": "^1.6.4",
37-
"@lit-protocol/contracts": "^0.2.3",
37+
"@lit-protocol/contracts": "^0.4.0",
3838
"@lit-protocol/nacl": "7.1.1",
3939
"@lit-protocol/uint8arrays": "7.1.1",
4040
"@metamask/eth-sig-util": "5.0.2",

packages/auth-services/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"@elysiajs/cors": "^1.2.0",
2121
"@elysiajs/static": "^1.3.0",
2222
"@elysiajs/swagger": "^1.2.0",
23-
"@lit-protocol/contracts": "^0.2.3",
23+
"@lit-protocol/contracts": "^0.4.0",
2424
"@simplewebauthn/server": "6.2.1",
2525
"@simplewebauthn/typescript-types": "^8.3.4",
2626
"@t3-oss/env-core": "^0.12.0",

packages/networks/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"directory": "../../dist/packages/networks"
1919
},
2020
"dependencies": {
21-
"@lit-protocol/contracts": "^0.2.3",
21+
"@lit-protocol/contracts": "^0.4.0",
2222
"@lit-protocol/nacl": "7.1.1",
2323
"@noble/curves": "^1.8.1",
2424
"@wagmi/core": "^2.17.1",

packages/networks/src/networks/vNaga/LitChainClient/apis/highLevelApis/PKPPermissionsManager/handlers/removePermittedAuthMethodByIdentifier.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ export async function removePermittedAuthMethodByIdentifier(
4343
networkCtx
4444
);
4545

46-
console.log('❌ AUTH METHOD TYPE:', authMethodType);
47-
console.log('❌ AUTH METHOD ID:', authMethodId);
48-
console.log('❌ PKP TOKEN ID:', pkpTokenId);
46+
// console.log('❌ AUTH METHOD TYPE:', authMethodType);
47+
// console.log('❌ AUTH METHOD ID:', authMethodId);
48+
// console.log('❌ PKP TOKEN ID:', pkpTokenId);
4949

5050
return removePermittedAuthMethod(
5151
{

packages/networks/src/networks/vNaga/LitChainClient/apis/highLevelApis/PKPPermissionsManager/handlers/removePermittedAuthMethodScopeByIdentifier.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ export async function removePermittedAuthMethodScopeByIdentifier(
4444
networkCtx
4545
);
4646

47-
console.log('🔥 AUTH METHOD TYPE:', authMethodType);
48-
console.log('🔥 AUTH METHOD ID:', authMethodId);
49-
console.log('🔥 SCOPE ID:', scopeId);
50-
console.log('🔥 PKP TOKEN ID:', pkpTokenId);
47+
// console.log('🔥 AUTH METHOD TYPE:', authMethodType);
48+
// console.log('🔥 AUTH METHOD ID:', authMethodId);
49+
// console.log('🔥 SCOPE ID:', scopeId);
50+
// console.log('🔥 PKP TOKEN ID:', pkpTokenId);
5151

5252
return removePermittedAuthMethodScope(
5353
{

0 commit comments

Comments
 (0)