Skip to content

Commit

Permalink
test: add tests for paying with single request proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
aimensahnoun committed Oct 28, 2024
1 parent ff74af2 commit 7a0cebf
Showing 1 changed file with 44 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { providers, Wallet } from 'ethers';
import { singleRequestProxyFactoryArtifact } from '@requestnetwork/smart-contracts';
import { TestERC20__factory } from '@requestnetwork/smart-contracts/types';
import {
ClientTypes,
CurrencyTypes,
ExtensionTypes,
IdentityTypes,
RequestLogicTypes,
CurrencyTypes,
} from '@requestnetwork/types';
import { deploySingleRequestProxy } from '../../src/payment/single-request-proxy';
import { singleRequestProxyFactoryArtifact } from '@requestnetwork/smart-contracts';
import { providers, Wallet } from 'ethers';
import {
deploySingleRequestProxy,
payRequestWithSingleRequestProxy,
} from '../../src/payment/single-request-proxy';

const mnemonic = 'candy maple cake sugar pudding cream honey rich smooth crumble sweet treat';
const paymentAddress = '0x1234567890123456789012345678901234567890';
Expand Down Expand Up @@ -223,4 +227,40 @@ describe('deploySingleRequestProxy', () => {
expect(event?.args?.payee).toBe(paymentAddress);
expect(event?.args?.paymentReference).toBeDefined();
});

it('should throw error when trying to pay with invalid single request proxy', async () => {
const invalidProxy = '0x1234567890123456789012345678901234567890';

await expect(payRequestWithSingleRequestProxy(invalidProxy, wallet, '100')).rejects.toThrow(
'Invalid SingleRequestProxy contract',
);
});

it('should pay with EthereumSingleRequestProxy', async () => {
const proxyAddress = await deploySingleRequestProxy(ethRequest, wallet);

const walletBalanceBefore = await provider.getBalance(wallet.address);

await payRequestWithSingleRequestProxy(proxyAddress, wallet, '1000');

const walletBalanceAfter = await provider.getBalance(wallet.address);

expect(walletBalanceAfter.toBigInt()).toBeLessThan(walletBalanceBefore.toBigInt());
});

it('should pay with ERC20SingleRequestProxy', async () => {
const amount = '1000';

const testERC20 = await new TestERC20__factory(wallet).deploy(1000);

const proxyAddress = await deploySingleRequestProxy(erc20Request, wallet);

const initialProxyBalance = await testERC20.balanceOf(wallet.address);

await payRequestWithSingleRequestProxy(proxyAddress, wallet, amount);

const finalProxyBalance = await testERC20.balanceOf(wallet.address);

expect(finalProxyBalance.toBigInt()).toBeLessThan(initialProxyBalance.toBigInt());
});
});

0 comments on commit 7a0cebf

Please sign in to comment.