Skip to content

Commit 50b9857

Browse files
committed
feat: abstract pino sdk logger singleton in previous logger package
1 parent a36466b commit 50b9857

File tree

38 files changed

+407
-430
lines changed

38 files changed

+407
-430
lines changed

local-tests/setup/tinny-environment.ts

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { LitContracts } from '@lit-protocol/contracts-sdk';
22
import { LitNodeClient } from '@lit-protocol/lit-node-client';
3+
import { getChildLogger } from '@lit-protocol/logger';
34
import {
45
AuthSig,
56
LitContractContext,
@@ -8,7 +9,6 @@ import {
89
import { ProcessEnvs, TinnyEnvConfig } from './tinny-config';
910
import { TinnyPerson } from './tinny-person';
1011

11-
import { createSiweMessage, generateAuthSig } from '@lit-protocol/auth-helpers';
1212
import {
1313
CENTRALISATION_BY_NETWORK,
1414
LIT_NETWORK,
@@ -20,7 +20,9 @@ import { ethers, Signer } from 'ethers';
2020
import { ShivaClient, TestnetClient } from './shiva-client';
2121
import { toErrorWithMessage } from './tinny-utils';
2222

23-
console.log('checking env', process.env['DEBUG']);
23+
const logger = getChildLogger({ module: 'tinny-environment' });
24+
25+
logger.info({ msg: 'checking env', env: process.env['DEBUG'] });
2426

2527
const DEFAULT_ANVIL_PRIVATE_KEYS = [
2628
'0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d',
@@ -49,7 +51,7 @@ export class TinnyEnvironment {
4951
DEBUG: process.env['DEBUG'] === 'true',
5052
REQUEST_PER_KILOSECOND:
5153
parseInt(process.env['REQUEST_PER_KILOSECOND']) ||
52-
(process.env['NETWORK'] as LIT_NETWORK_VALUES) === 'datil-dev'
54+
(process.env['NETWORK'] as LIT_NETWORK_VALUES) === LIT_NETWORK.NagaDev
5355
? 1
5456
: 200,
5557
LIT_RPC_URL: process.env['LIT_RPC_URL'],
@@ -147,10 +149,10 @@ export class TinnyEnvironment {
147149
);
148150
}
149151

150-
console.log(
151-
'[𐬺🧪 Tinny Environment𐬺] Done configuring environment current config: ',
152-
this.processEnvs
153-
);
152+
logger.info({
153+
msg: '[𐬺🧪 Tinny Environment𐬺] Done configuring environment current config: ',
154+
processEnvs: this.processEnvs,
155+
});
154156
}
155157

156158
world: Map<string, TinnyPerson> = new Map();
@@ -183,11 +185,12 @@ export class TinnyEnvironment {
183185
if (index !== -1) {
184186
// If an available key is found
185187
this.processEnvs.KEY_IN_USE[index] = true; // Mark the key as in use
186-
// console.log('[𐬺🧪 Tinny Environment𐬺] 🔑 Selected key at index', index); // Log a message indicating that we have selected a key
188+
// logger.info({ msg: '[𐬺🧪 Tinny Environment𐬺] 🔑 Selected key at index', index }); // Log a message indicating that we have selected a key
187189

188190
return { privateKey: this.processEnvs.PRIVATE_KEYS[index], index }; // Return the key and its index
189191
} else {
190-
console.log('[𐬺🧪 Tinny Environment𐬺] No available keys. Waiting...', {
192+
logger.info({
193+
msg: '[𐬺🧪 Tinny Environment𐬺] No available keys. Waiting...',
191194
keysInUse: this.processEnvs.KEY_IN_USE,
192195
}); // Log a message indicating that we are waiting
193196
// Wait for the specified interval before checking again
@@ -205,9 +208,9 @@ export class TinnyEnvironment {
205208
releasePrivateKeyFromUser(user: TinnyPerson) {
206209
const index = this.processEnvs.PRIVATE_KEYS.indexOf(user.privateKey);
207210
this.processEnvs.KEY_IN_USE[index] = false;
208-
// console.log(
209-
// `[𐬺🧪 Tinny Environment𐬺] 🪽 Released key at index ${index}. Thank you for your service!`
210-
// );
211+
// logger.info({
212+
// msg: `[𐬺🧪 Tinny Environment𐬺] 🪽 Released key at index ${index}. Thank you for your service!`
213+
// });
211214
}
212215

213216
/**
@@ -216,9 +219,9 @@ export class TinnyEnvironment {
216219
*/
217220
releasePrivateKey(index: number) {
218221
this.processEnvs.KEY_IN_USE[index] = false;
219-
// console.log(
220-
// `[𐬺🧪 Tinny Environment𐬺] 🪽 Released key at index ${index}. Thank you for your service!`
221-
// );
222+
// logger.info({
223+
// msg: `[𐬺🧪 Tinny Environment𐬺] 🪽 Released key at index ${index}. Thank you for your service!`
224+
// });
222225
}
223226

224227
/**
@@ -234,9 +237,9 @@ export class TinnyEnvironment {
234237
*/
235238

236239
async setupLitNodeClient() {
237-
console.log('[𐬺🧪 Tinny Environment𐬺] Setting up LitNodeClient');
240+
logger.info({ msg: '[𐬺🧪 Tinny Environment𐬺] Setting up LitNodeClient' });
238241

239-
console.log('this.network:', this.network);
242+
logger.info({ msg: 'network', network: this.network });
240243
const centralisation = CENTRALISATION_BY_NETWORK[this.network];
241244

242245
if (this.network === LIT_NETWORK.Custom || centralisation === 'unknown') {
@@ -324,7 +327,7 @@ export class TinnyEnvironment {
324327
* @throws Error if the name is not provided.
325328
*/
326329
async createNewPerson(name: string) {
327-
console.log('[𐬺🧪 Tinny Environment𐬺] Creating new person:', name);
330+
logger.info({ msg: '[𐬺🧪 Tinny Environment𐬺] Creating new person', name });
328331
if (!name) {
329332
throw new Error('Name is required');
330333
}
@@ -373,17 +376,17 @@ export class TinnyEnvironment {
373376
async init() {
374377
try {
375378
if (this.processEnvs.NO_SETUP) {
376-
console.log('[𐬺🧪 Tinny Environment𐬺] Skipping setup');
379+
logger.info({ msg: '[𐬺🧪 Tinny Environment𐬺] Skipping setup' });
377380
return;
378381
}
379382
if (this.network === LIT_NETWORK.Custom && this.processEnvs.USE_SHIVA) {
380383
this.testnet = await this._shivaClient.startTestnetManager();
381384
// wait for the testnet to be active before we start the tests.
382385
let state = await this.testnet.pollTestnetForActive();
383386
if (state === `UNKNOWN`) {
384-
console.log(
385-
'Testnet state found to be Unknown meaning there was an error with testnet creation. shutting down'
386-
);
387+
logger.info({
388+
msg: 'Testnet state found to be Unknown meaning there was an error with testnet creation. shutting down',
389+
});
387390
throw new Error(`Error while creating testnet, aborting test run`);
388391
}
389392

@@ -398,10 +401,10 @@ export class TinnyEnvironment {
398401
await this.setupSuperCapacityDelegationAuthSig();
399402
} catch (e) {
400403
const err = toErrorWithMessage(e);
401-
console.log(
402-
`[𐬺🧪 Tinny Environment𐬺] Failed to init() tinny ${err.message}`
403-
);
404-
console.log(err.stack);
404+
logger.error({
405+
msg: `[𐬺🧪 Tinny Environment𐬺] Failed to init() tinny ${err.message}`,
406+
stack: err.stack,
407+
});
405408
process.exit(1);
406409
}
407410
}
@@ -417,7 +420,7 @@ export class TinnyEnvironment {
417420
) {
418421
await this.testnet.stopTestnet();
419422
} else {
420-
console.log('skipping testnet shutdown.');
423+
logger.info('skipping testnet shutdown.');
421424
}
422425
}
423426
//============= END SHIVA ENDPOINTS =============
@@ -498,9 +501,9 @@ export class TinnyEnvironment {
498501

499502
// get wallet balance
500503
const balance = await wallet.getBalance();
501-
console.log('this.rpc:', rpc);
502-
console.log('this.wallet.address', wallet.address);
503-
console.log('Balance:', balance.toString());
504+
logger.info({ msg: 'this.rpc:', rpc });
505+
logger.info({ msg: 'this.wallet.address', address: wallet.address });
506+
logger.info({ msg: 'Balance:', balance: balance.toString() });
504507

505508
const transferTx = await wallet.sendTransaction({
506509
to: capacityCreditWallet.address,
@@ -520,7 +523,7 @@ export class TinnyEnvironment {
520523
}
521524

522525
if (!this.contractsClient) {
523-
console.log('❗️Contracts client not initialized');
526+
logger.info('❗️Contracts client not initialized');
524527
process.exit();
525528
}
526529

@@ -537,7 +540,7 @@ export class TinnyEnvironment {
537540
};
538541

539542
async mintSuperCapacityDelegationAuthSig(wallet: Signer) {
540-
console.log(
543+
logger.info(
541544
'[𐬺🧪 Tinny Environment𐬺] Mint a Capacity Credits NFT and get a capacity delegation authSig with it'
542545
);
543546

@@ -552,9 +555,9 @@ export class TinnyEnvironment {
552555
).capacityDelegationAuthSig;
553556
} catch (e: any) {
554557
if (e.message.includes(`Can't allocate capacity beyond the global max`)) {
555-
console.log('❗️Skipping capacity delegation auth sig setup.', e);
558+
logger.info('❗️Skipping capacity delegation auth sig setup.', e);
556559
} else {
557-
console.log(
560+
logger.info(
558561
'❗️Error while setting up capacity delegation auth sig',
559562
e
560563
);

0 commit comments

Comments
 (0)