Two users
A complete test file where a maker places an order and a trader fills it, each in their own tab and wallet.
Two users trade with each other: a maker places an order, and a trader fills it. Each has their own tab and Varial (formerly Freighter) wallet, as two people with two browsers would. The routes and labels belong to an example app.
import { test, expect, type User } from 'stardust-stellar/test';
const short = (address: string) =>
`${address.slice(0, 4)}…${address.slice(-4)}`;
test.use({
stardust: {
users: {
maker: {
wallet: 'varial',
connected: true,
accounts: { main: { fund: '1000' } },
},
trader: {
wallet: 'varial',
connected: true,
accounts: { main: { fund: '1000' } },
},
},
},
});
// The orderbook is shared with every test and developer on testnet,
// so each test finds its own maker's order.
const orderOf = (maker: User, viewer: User) =>
viewer.page
.getByRole('row')
.filter({ hasText: short(maker.account.address) });
test('a trader fills a maker order', async ({ users: { maker, trader } }) => {
// The maker places an order.
await maker.page.goto('/orders/new');
await maker.page.getByLabel('Amount (XLM)').fill('500');
await maker.page.getByRole('button', { name: 'Place order' }).click();
const placed = await maker.wallet.nextPrompt('signTransaction');
await expect(placed).toLand();
// The trader fills it.
await trader.page.goto('/orders');
await orderOf(maker, trader).getByRole('button', { name: 'Fill' }).click();
const filled = await trader.wallet.nextPrompt('signTransaction');
await expect(filled).toLand();
// Both see the result.
await expect(trader.page.getByText('Order filled')).toBeVisible();
await expect(maker.page.getByText('Your order was filled')).toBeVisible();
});
test('the order stays open when the trader rejects', async ({
users: { maker, trader },
}) => {
trader.wallet.setPolicy('reject'); // this trader rejects every request
await maker.page.goto('/orders/new');
await maker.page.getByLabel('Amount (XLM)').fill('500');
await maker.page.getByRole('button', { name: 'Place order' }).click();
const placed = await maker.wallet.nextPrompt('signTransaction');
await expect(placed).toLand();
await trader.page.goto('/orders');
await orderOf(maker, trader).getByRole('button', { name: 'Fill' }).click();
await expect(trader.page.getByText('Transaction cancelled')).toBeVisible();
await maker.page.goto('/orders');
await expect(orderOf(maker, maker)).toContainText('Open');
});maker.walletsees only the maker's prompts, andtrader.walletonly the trader's.- The default
'approve'policy signs both transactions, sonextPromptreturns them already approved. setPolicy('reject')changes the trader's policy for the rest of the test. Withconnected: true, only signatures are rejected.- Testnet is shared with everyone, so
orderOffinds the order by the maker's address instead of taking the first row.