Skip to content

Commit

Permalink
refactor: update tests ot use new event format
Browse files Browse the repository at this point in the history
  • Loading branch information
aimensahnoun committed Oct 28, 2024
1 parent 57665b0 commit eba8d37
Showing 1 changed file with 23 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
IdentityTypes,
RequestLogicTypes,
} from '@requestnetwork/types';
import { providers, Wallet } from 'ethers';
import { providers, Wallet, utils } from 'ethers';
import {
deploySingleRequestProxy,
payRequestWithSingleRequestProxy,
Expand Down Expand Up @@ -180,16 +180,21 @@ describe('deploySingleRequestProxy', () => {
// Get the latest events
const latestBlock = await provider.getBlockNumber();
const events = await singleRequestProxyFactory.queryFilter(
singleRequestProxyFactory.filters.EthereumSingleRequestProxyCreated(),
{
topics: [utils.id('EthereumSingleRequestProxyCreated(address,address,bytes)')],
},
initialEventCount,
latestBlock,
);

// Check if the event was emitted with the correct parameters
const event = events.find((e) => e.args?.proxyAddress === proxyAddress);
expect(event).toBeDefined();
expect(event?.args?.payee).toBe(paymentAddress);
expect(event?.args?.paymentReference).toBeDefined();
// Check if the event exists
expect(events.length).toBeGreaterThan(0);

// Decode the event data to get the proxy address and payee
const eventData = utils.defaultAbiCoder.decode(['address', 'address'], events[0].data);

expect(eventData[0]).toBe(proxyAddress);
expect(eventData[1]).toBe(wallet.address);
});

it('should deploy ERC20SingleRequestProxy and emit event', async () => {
Expand All @@ -207,16 +212,21 @@ describe('deploySingleRequestProxy', () => {
// Get the latest events
const latestBlock = await provider.getBlockNumber();
const events = await singleRequestProxyFactory.queryFilter(
singleRequestProxyFactory.filters.ERC20SingleRequestProxyCreated(),
{
topics: [utils.id('ERC20SingleRequestProxyCreated(address,address,bytes)')],
},
initialEventCount,
latestBlock,
);

// Check if the event was emitted with the correct parameters
const event = events.find((e) => e.args?.proxyAddress === proxyAddress);
expect(event).toBeDefined();
expect(event?.args?.payee).toBe(paymentAddress);
expect(event?.args?.paymentReference).toBeDefined();
// Check if the event exists
expect(events.length).toBeGreaterThan(0);

// Decode the event data to get the proxy address and payee
const eventData = utils.defaultAbiCoder.decode(['address', 'address'], events[0].data);

expect(eventData[0]).toBe(proxyAddress);
expect(eventData[1]).toBe(wallet.address);
});

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

0 comments on commit eba8d37

Please sign in to comment.