Skip to content

Commit a08c550

Browse files
committed
refactor: update tests ot use new event format
1 parent 57665b0 commit a08c550

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

packages/payment-processor/test/payment/single-request-proxy.test.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
IdentityTypes,
88
RequestLogicTypes,
99
} from '@requestnetwork/types';
10-
import { providers, Wallet } from 'ethers';
10+
import { providers, Wallet, utils } from 'ethers';
1111
import {
1212
deploySingleRequestProxy,
1313
payRequestWithSingleRequestProxy,
@@ -168,55 +168,56 @@ describe('deploySingleRequestProxy', () => {
168168
it('should deploy EthereumSingleRequestProxy and emit event', async () => {
169169
const singleRequestProxyFactory = singleRequestProxyFactoryArtifact.connect('private', wallet);
170170

171-
// Get the initial event count
172171
const initialEventCount = await provider.getBlockNumber();
173172

173+
const walletAddress = await wallet.getAddress();
174+
174175
const proxyAddress = await deploySingleRequestProxy(ethRequest, wallet);
175176

176177
expect(proxyAddress).toBeDefined();
177178
expect(typeof proxyAddress).toBe('string');
178179
expect(proxyAddress).toMatch(/^0x[a-fA-F0-9]{40}$/);
179180

180-
// Get the latest events
181181
const latestBlock = await provider.getBlockNumber();
182182
const events = await singleRequestProxyFactory.queryFilter(
183183
singleRequestProxyFactory.filters.EthereumSingleRequestProxyCreated(),
184184
initialEventCount,
185185
latestBlock,
186186
);
187187

188-
// Check if the event was emitted with the correct parameters
189-
const event = events.find((e) => e.args?.proxyAddress === proxyAddress);
190-
expect(event).toBeDefined();
191-
expect(event?.args?.payee).toBe(paymentAddress);
192-
expect(event?.args?.paymentReference).toBeDefined();
188+
expect(events.length).toBeGreaterThan(0);
189+
190+
const eventData = utils.defaultAbiCoder.decode(['address', 'address'], events[0].data);
191+
192+
expect(eventData[0]).toBe(proxyAddress);
193+
expect(eventData[1]).toBe(walletAddress);
193194
});
194195

195196
it('should deploy ERC20SingleRequestProxy and emit event', async () => {
196197
const singleRequestProxyFactory = singleRequestProxyFactoryArtifact.connect('private', wallet);
197198

198-
// Get the initial event count
199199
const initialEventCount = await provider.getBlockNumber();
200200

201+
const walletAddress = await wallet.getAddress();
202+
201203
const proxyAddress = await deploySingleRequestProxy(erc20Request, wallet);
202204

203205
expect(proxyAddress).toBeDefined();
204206
expect(typeof proxyAddress).toBe('string');
205207
expect(proxyAddress).toMatch(/^0x[a-fA-F0-9]{40}$/);
206208

207-
// Get the latest events
208209
const latestBlock = await provider.getBlockNumber();
209210
const events = await singleRequestProxyFactory.queryFilter(
210211
singleRequestProxyFactory.filters.ERC20SingleRequestProxyCreated(),
211212
initialEventCount,
212213
latestBlock,
213214
);
214215

215-
// Check if the event was emitted with the correct parameters
216-
const event = events.find((e) => e.args?.proxyAddress === proxyAddress);
217-
expect(event).toBeDefined();
218-
expect(event?.args?.payee).toBe(paymentAddress);
219-
expect(event?.args?.paymentReference).toBeDefined();
216+
expect(events.length).toBeGreaterThan(0);
217+
218+
const eventData = utils.defaultAbiCoder.decode(['address', 'address'], events[0].data);
219+
220+
expect(eventData[0]).toBe(proxyAddress);
220221
});
221222

222223
it('should throw error when trying to pay with invalid single request proxy', async () => {

0 commit comments

Comments
 (0)