@@ -8,25 +8,37 @@ import { LitNodeClientNodeJs } from "@lit-protocol/lit-node-client-nodejs";
88import { LitRelay , EthWalletProvider } from "@lit-protocol/lit-auth-client" ;
99import { LIT_NETWORKS_KEYS } from "@lit-protocol/types" ;
1010
11- describe ( "pkpsign Integration Tests" , ( ) => {
11+ type NetworkType = 'datil-dev' | 'datil-test' | 'datil' ;
12+
13+ const REGISTRY_ADDRESSES = {
14+ 'datil-dev' : '0x2707eabb60D262024F8738455811a338B0ECd3EC' ,
15+ 'datil-test' : '0x525bF2bEb622D7C05E979a8b3fFcDBBEF944450E' ,
16+ 'datil' : '0xBDEd44A02b64416C831A0D82a630488A854ab4b1' ,
17+ } as const ;
18+
19+ // Example ABI for PKP contract interactions
20+ const PKP_PERMISSIONS_ABI = [
21+ 'function addDelegatees(uint256 pkpTokenId, address[] calldata delegatees) external' ,
22+ 'function getDelegatees(uint256 pkpTokenId) external view returns (address[] memory)'
23+ ] ;
24+
25+ const networks : NetworkType [ ] = [ 'datil-dev' , 'datil-test' , 'datil' ] ;
26+
27+ describe . each ( networks ) ( 'pkpsign Integration Tests on %s' , ( network ) => {
1228 let app : express . Application ;
1329 let litNodeClient : LitNodeClientNodeJs ;
1430 let provider : ethers . providers . JsonRpcProvider ;
1531 let pkp : any ;
1632 let authMethod : any ;
1733 let pkpTokenId : ethers . BigNumber ;
1834
19-
20- // Example ABI for PKP contract interactions
21- const PKP_PERMISSIONS_ABI = [
22- 'function addDelegatees(uint256 pkpTokenId, address[] calldata delegatees) external' ,
23- 'function getDelegatees(uint256 pkpTokenId) external view returns (address[] memory)'
24- ] ;
25-
2635 beforeAll ( async ( ) => {
36+ // Set network for this test suite
37+ process . env . NETWORK = network ;
38+
2739 // connect to lit so we can sign messages
2840 litNodeClient = new LitNodeClientNodeJs ( {
29- litNetwork : process . env . NETWORK as LIT_NETWORKS_KEYS ,
41+ litNetwork : network ,
3042 debug : false ,
3143 } ) ;
3244 await litNodeClient . connect ( ) ;
@@ -38,7 +50,7 @@ describe("pkpsign Integration Tests", () => {
3850 const authWallet = getSigner ( ) ;
3951
4052 const litRelay = new LitRelay ( {
41- relayUrl : LitRelay . getRelayUrl ( process . env . NETWORK as LIT_NETWORKS_KEYS ) ,
53+ relayUrl : LitRelay . getRelayUrl ( network ) ,
4254 relayApiKey : "test-api-key" ,
4355 } ) ;
4456
@@ -58,6 +70,7 @@ describe("pkpsign Integration Tests", () => {
5870 pkpPublicKey : pkp . pkpPublicKey ,
5971 pkpEthAddress : pkp . pkpEthAddress ,
6072 tokenId : pkp . tokenId ,
73+ network : network ,
6174 fullResponse : pkp // Log the full response to see what we get
6275 } ) ;
6376
@@ -74,15 +87,9 @@ describe("pkpsign Integration Tests", () => {
7487 console . log ( "Token ID conversion:" , {
7588 original : tokenId ,
7689 hex : tokenIdHex ,
77- decimal : pkpTokenId . toString ( )
90+ decimal : pkpTokenId . toString ( ) ,
91+ network : network
7892 } ) ;
79-
80- // Create contract instance to verify permissions
81- const pkpPermissionsContract = new ethers . Contract (
82- "0x2707eabb60D262024F8738455811a338B0ECd3EC" ,
83- PKP_PERMISSIONS_ABI ,
84- provider
85- ) ;
8693 } , 60000 ) ; // Increase timeout to 60 seconds
8794
8895 beforeEach ( ( ) => {
@@ -96,7 +103,7 @@ describe("pkpsign Integration Tests", () => {
96103 litNodeClient . disconnect ( ) ;
97104 } ) ;
98105
99- it ( " should successfully sign a message using PKP" , async ( ) => {
106+ it ( ` should successfully sign a message using PKP on ${ network } ` , async ( ) => {
100107 const messageToSign = "Hello, World!" ;
101108
102109 const response = await request ( app )
@@ -121,10 +128,12 @@ describe("pkpsign Integration Tests", () => {
121128 expect ( recoveredAddress . toLowerCase ( ) ) . toBe ( pkp . pkpEthAddress ! . toLowerCase ( ) ) ;
122129 } ) ;
123130
124- it ( "should successfully sign a contract interaction using PKP" , async ( ) => {
131+ it ( `should successfully sign a contract interaction using PKP on ${ network } ` , async ( ) => {
132+ // Get the correct contract address for the current network
133+ const contractAddress = REGISTRY_ADDRESSES [ network ] ;
134+
125135 // Create a contract interface for testing
126136 const iface = new ethers . utils . Interface ( PKP_PERMISSIONS_ABI ) ;
127- const contractAddress = "0x2707eabb60D262024F8738455811a338B0ECd3EC" ;
128137
129138 // Generate a random Ethereum address as delegatee
130139 const delegatee = ethers . Wallet . createRandom ( ) . address ;
@@ -143,6 +152,7 @@ describe("pkpsign Integration Tests", () => {
143152 pkpAddress : pkp . pkpEthAddress ,
144153 delegatee,
145154 contractAddress,
155+ network,
146156 encodedData : data ,
147157 } ) ;
148158
@@ -152,7 +162,7 @@ describe("pkpsign Integration Tests", () => {
152162 value : "0x0" ,
153163 gasPrice : await provider . getGasPrice ( ) ,
154164 nonce : await provider . getTransactionCount ( pkp . pkpEthAddress ) ,
155- gasLimit : ethers . BigNumber . from ( 179970 ) , // Updated to match estimated gas
165+ gasLimit : ethers . BigNumber . from ( 179970 ) ,
156166 chainId : ( await provider . getNetwork ( ) ) . chainId ,
157167 } ;
158168
@@ -170,7 +180,8 @@ describe("pkpsign Integration Tests", () => {
170180 data : error . data ,
171181 pkpAddress : pkp . pkpEthAddress ,
172182 tokenId : pkpTokenId . toString ( ) ,
173- delegatee
183+ delegatee,
184+ network
174185 } ) ;
175186 }
176187
@@ -179,7 +190,8 @@ describe("pkpsign Integration Tests", () => {
179190 ...transaction ,
180191 pkpPublicKey : pkp . pkpPublicKey ,
181192 pkpEthAddress : pkp . pkpEthAddress ,
182- tokenId : pkpTokenId . toString ( )
193+ tokenId : pkpTokenId . toString ( ) ,
194+ network
183195 } ) ;
184196
185197 try {
@@ -195,7 +207,8 @@ describe("pkpsign Integration Tests", () => {
195207 console . log ( "Response from pkp-sign:" , {
196208 status : response . status ,
197209 body : response . body ,
198- txHash : response . body . requestId // This is the transaction hash
210+ txHash : response . body . requestId ,
211+ network
199212 } ) ;
200213
201214 // Log transaction hash separately for easy copying
@@ -216,7 +229,8 @@ describe("pkpsign Integration Tests", () => {
216229 const delegatees = await contract . getDelegatees ( pkpTokenId ) ;
217230 console . log ( "Delegatees after transaction:" , {
218231 delegatees : delegatees . map ( ( d : string ) => d . toLowerCase ( ) ) ,
219- expectedDelegatee : delegatee . toLowerCase ( )
232+ expectedDelegatee : delegatee . toLowerCase ( ) ,
233+ network
220234 } ) ;
221235
222236 // Check if our delegatee is in the list
@@ -227,13 +241,14 @@ describe("pkpsign Integration Tests", () => {
227241 console . log ( "Error from pkp-sign request:" , {
228242 error : error . message ,
229243 response : error . response ?. body ,
230- errorDetails : error . response ?. body ?. error
244+ errorDetails : error . response ?. body ?. error ,
245+ network
231246 } ) ;
232247 throw error ;
233248 }
234249 } , 60000 ) ;
235250
236- it ( " should reject direct ETH transfers" , async ( ) => {
251+ it ( ` should reject direct ETH transfers on ${ network } ` , async ( ) => {
237252 // Create a simple ETH transfer transaction
238253 const transaction = {
239254 to : ethers . Wallet . createRandom ( ) . address ,
@@ -259,7 +274,7 @@ describe("pkpsign Integration Tests", () => {
259274 expect ( response . body . error ) . toContain ( "Direct ETH transfers are not allowed" ) ;
260275 } ) ;
261276
262- it ( " should fail with missing parameters" , async ( ) => {
277+ it ( ` should fail with missing parameters on ${ network } ` , async ( ) => {
263278 const response = await request ( app )
264279 . post ( "/pkp-sign" )
265280 . send ( {
0 commit comments