diff --git a/tests/paymaster.spec.ts b/tests/paymaster.spec.ts index e972178..d1eed25 100644 --- a/tests/paymaster.spec.ts +++ b/tests/paymaster.spec.ts @@ -1,6 +1,6 @@ import {describe, expect, test} from '@jest/globals' import { - paymasterProvider, + paymasterClient, wallet, tokenAbi, transformIsSponsorableResponse, @@ -22,7 +22,7 @@ describe('paymasterQuery', () => { */ describe('chainID', () => { test('chainID should return the expected value', async () => { - const res = await paymasterProvider.chainID() + const res = await paymasterClient.chainID() expect(res).toEqual('0x61') }) }) @@ -34,7 +34,7 @@ describe('paymasterQuery', () => { test('should successfully determine if transaction is sponsorable', async () => { const tokenContract = new ethers.Contract(TOKEN_CONTRACT_ADDRESS, tokenAbi, wallet) const tokenAmount = ethers.parseUnits('0', 18) - const nonce = await paymasterProvider.getTransactionCount(wallet.address, 'pending') + const nonce = await paymasterClient.getTransactionCount(wallet.address, 'pending') const transaction = await tokenContract.transfer.populateTransaction(RECIPIENT_ADDRESS.toLowerCase(), tokenAmount) transaction.from = wallet.address @@ -51,13 +51,13 @@ describe('paymasterQuery', () => { } console.log('Prepared transaction:', safeTransaction) - const resRaw = await paymasterProvider.isSponsorable(safeTransaction) + const resRaw = await paymasterClient.isSponsorable(safeTransaction) const res = transformIsSponsorableResponse(resRaw) expect(res.Sponsorable).toEqual(true) const signedTx = await wallet.signTransaction(safeTransaction) try { - const tx = await paymasterProvider.sendRawTransaction(signedTx) + const tx = await paymasterClient.sendRawTransaction(signedTx) TX_HASH = tx console.log('Transaction hash received:', TX_HASH) } catch (error) { @@ -74,23 +74,23 @@ describe('paymasterQuery', () => { console.log('Waiting for transaction confirmation...') await delay(8000) console.log('Querying gasless transaction by hash:', TX_HASH) - const resRaw = await paymasterProvider.getGaslessTransactionByHash(TX_HASH) + const resRaw = await paymasterClient.getGaslessTransactionByHash(TX_HASH) const res = transformToGaslessTransaction(resRaw) expect(res.ToAddress).toEqual(TOKEN_CONTRACT_ADDRESS.toLowerCase()) console.log('Querying gasless transaction', res) console.log('Retrieving sponsor transaction by bundle UUID:', res.BundleUUID) - const txRaw = await paymasterProvider.getSponsorTxByBundleUuid(res.BundleUUID) + const txRaw = await paymasterClient.getSponsorTxByBundleUuid(res.BundleUUID) const tx = transformSponsorTxResponse(txRaw) expect(txRaw).not.toBeNull() console.log('Sponsor transaction details:', tx) - const bundleRaw = await paymasterProvider.getBundleByUuid(res.BundleUUID) + const bundleRaw = await paymasterClient.getBundleByUuid(res.BundleUUID) const bundle = transformBundleResponse(bundleRaw) expect(bundle.BundleUUID).toEqual(res.BundleUUID) console.log('Bundle details:', bundle) - const sponsorTxRaw = await paymasterProvider.getSponsorTxByTxHash(tx.TxHash) + const sponsorTxRaw = await paymasterClient.getSponsorTxByTxHash(tx.TxHash) const sponsorTx = transformSponsorTxResponse(sponsorTxRaw) console.log('Sponsor transaction:', sponsorTx) expect(sponsorTx.TxHash).toEqual(tx.TxHash) diff --git a/tests/sponsor.spec.ts b/tests/sponsor.spec.ts index d55f042..33dfcba 100644 --- a/tests/sponsor.spec.ts +++ b/tests/sponsor.spec.ts @@ -1,5 +1,5 @@ import {describe, expect, test} from '@jest/globals' -import {client} from './utils' +import {sponsorClient} from './utils' import {WhitelistType} from '../src' import {POLICY_UUID, ACCOUNT_ADDRESS, CONTRACT_METHOD} from './env' @@ -12,7 +12,7 @@ describe('sponsorQuery', () => { */ describe('addToWhitelist FromAccountWhitelist', () => { test('should add an account address to FromAccountWhitelist successfully', async () => { - const res = await client.addToWhitelist({ + const res = await sponsorClient.addToWhitelist({ PolicyUUID: POLICY_UUID, WhitelistType: WhitelistType.FromAccountWhitelist, Values: [ACCOUNT_ADDRESS], @@ -28,7 +28,7 @@ describe('sponsorQuery', () => { */ describe('addToWhitelist ToAccountWhitelist', () => { test('should add an account address to ToAccountWhitelist successfully', async () => { - const res = await client.addToWhitelist({ + const res = await sponsorClient.addToWhitelist({ PolicyUUID: POLICY_UUID, WhitelistType: WhitelistType.ToAccountWhitelist, Values: [ACCOUNT_ADDRESS], @@ -44,7 +44,7 @@ describe('sponsorQuery', () => { */ describe('addToWhitelist BEP20ReceiverWhiteList', () => { test('should add an account address to BEP20ReceiverWhiteList successfully', async () => { - const res = await client.addToWhitelist({ + const res = await sponsorClient.addToWhitelist({ PolicyUUID: POLICY_UUID, WhitelistType: WhitelistType.BEP20ReceiverWhiteList, Values: [ACCOUNT_ADDRESS], @@ -60,7 +60,7 @@ describe('sponsorQuery', () => { */ describe('addToWhitelist ContractMethodSigWhitelist', () => { test('should add a contract method signature to ContractMethodSigWhitelist successfully', async () => { - const res = await client.addToWhitelist({ + const res = await sponsorClient.addToWhitelist({ PolicyUUID: POLICY_UUID, WhitelistType: WhitelistType.ContractMethodSigWhitelist, Values: [CONTRACT_METHOD], @@ -76,7 +76,7 @@ describe('sponsorQuery', () => { */ describe('getWhitelist', () => { test('should retrieve contract method signatures successfully', async () => { - const res = await client.getWhitelist({ + const res = await sponsorClient.getWhitelist({ PolicyUUID: POLICY_UUID, WhitelistType: WhitelistType.ContractMethodSigWhitelist, Offset: 0, @@ -93,7 +93,7 @@ describe('sponsorQuery', () => { */ describe('removeFromWhitelist', () => { test('should remove an account address from FromAccountWhitelist successfully', async () => { - const res = await client.removeFromWhitelist({ + const res = await sponsorClient.removeFromWhitelist({ PolicyUUID: POLICY_UUID, WhitelistType: WhitelistType.FromAccountWhitelist, Values: [ACCOUNT_ADDRESS], @@ -109,7 +109,7 @@ describe('sponsorQuery', () => { */ describe('getWhitelist', () => { test('should not contain account address post-removal', async () => { - const res = await client.getWhitelist({ + const res = await sponsorClient.getWhitelist({ PolicyUUID: POLICY_UUID, WhitelistType: WhitelistType.FromAccountWhitelist, Offset: 0, @@ -127,7 +127,7 @@ describe('sponsorQuery', () => { */ describe('emptyWhitelist', () => { test('should clear all entries from BEP20ReceiverWhiteList successfully', async () => { - const res = await client.emptyWhitelist({ + const res = await sponsorClient.emptyWhitelist({ PolicyUUID: POLICY_UUID, WhitelistType: WhitelistType.BEP20ReceiverWhiteList, }) @@ -142,7 +142,7 @@ describe('sponsorQuery', () => { */ describe('getWhitelist', () => { test('should confirm the whitelist is empty', async () => { - const res = await client.getWhitelist({ + const res = await sponsorClient.getWhitelist({ PolicyUUID: POLICY_UUID, WhitelistType: WhitelistType.BEP20ReceiverWhiteList, Offset: 0, @@ -159,7 +159,7 @@ describe('sponsorQuery', () => { */ describe('getUserSpendData', () => { test('should return null for spend data when user has none', async () => { - const res = await client.getUserSpendData(ACCOUNT_ADDRESS, POLICY_UUID) + const res = await sponsorClient.getUserSpendData(ACCOUNT_ADDRESS, POLICY_UUID) expect(res).toBeNull() console.log('User spend data:', res) @@ -171,7 +171,7 @@ describe('sponsorQuery', () => { */ describe('getPolicySpendData', () => { test('should retrieve policy spend data successfully', async () => { - const res = await client.getPolicySpendData(POLICY_UUID) + const res = await sponsorClient.getPolicySpendData(POLICY_UUID) expect(res.ChainID).not.toBeNull() console.log('Policy spend data:', res) }) @@ -182,7 +182,7 @@ describe('sponsorQuery', () => { */ describe('addToWhitelist FromAccountWhitelist', () => { test('should re-add an account address to FromAccountWhitelist successfully after removal', async () => { - const res = await client.addToWhitelist({ + const res = await sponsorClient.addToWhitelist({ PolicyUUID: POLICY_UUID, WhitelistType: WhitelistType.FromAccountWhitelist, Values: [ACCOUNT_ADDRESS], diff --git a/tests/utils.ts b/tests/utils.ts index ea883d0..b18e51b 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -10,13 +10,13 @@ import { import {CHAIN_ID, SPONSOR_URL, CHAIN_URL, PAYMASTER_URL, PRIVATE_KEY, TOKEN_CONTRACT_ADDRESS} from './env' import {ethers} from 'ethers' -export const client = new SponsorClient(SPONSOR_URL, undefined, {staticNetwork: ethers.Network.from(Number(CHAIN_ID))}) +export const sponsorClient = new SponsorClient(SPONSOR_URL, undefined, {staticNetwork: ethers.Network.from(Number(CHAIN_ID))}) // Provider for assembling the transaction (e.g., testnet) export const assemblyProvider = new ethers.JsonRpcProvider(CHAIN_URL) // Provider for sending the transaction (e.g., could be a different network or provider) -export const paymasterProvider = new PaymasterClient(PAYMASTER_URL) +export const paymasterClient = new PaymasterClient(PAYMASTER_URL) export const wallet = new ethers.Wallet(PRIVATE_KEY, assemblyProvider) // ERC20 token ABI (only including the transfer function)