Skip to content

Commit

Permalink
fix: tiny fix
Browse files Browse the repository at this point in the history
  • Loading branch information
BarryTong65 committed Sep 9, 2024
1 parent ba338af commit a3651cb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
18 changes: 9 additions & 9 deletions tests/paymaster.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {describe, expect, test} from '@jest/globals'
import {
paymasterProvider,
paymasterClient,
wallet,
tokenAbi,
transformIsSponsorableResponse,
Expand All @@ -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')
})
})
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -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)
Expand Down
26 changes: 13 additions & 13 deletions tests/sponsor.spec.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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],
Expand All @@ -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],
Expand All @@ -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],
Expand All @@ -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],
Expand All @@ -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,
Expand All @@ -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],
Expand All @@ -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,
Expand All @@ -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,
})
Expand All @@ -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,
Expand All @@ -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)
Expand All @@ -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)
})
Expand All @@ -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],
Expand Down
4 changes: 2 additions & 2 deletions tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a3651cb

Please sign in to comment.