Skip to content

Commit

Permalink
feat(compose_txn): allow Base64 input for note, lease, and metadata h…
Browse files Browse the repository at this point in the history
…ash fields
  • Loading branch information
No-Cash-7970 committed Dec 29, 2023
1 parent 7d0788f commit 4d8b3ad
Show file tree
Hide file tree
Showing 19 changed files with 1,439 additions and 160 deletions.
9 changes: 8 additions & 1 deletion src/app/[lang]/txn/compose/components/ComposeForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ describe('Compose Form Component', () => {

it('has base transaction fields (using suggested parameters)', async () => {
render(<ComposeForm />);

expect(await screen.findByText('fields.type.label')).toBeInTheDocument();
expect(screen.getByText('fields.snd.label')).toBeInTheDocument();
expect(screen.getByText('fields.use_sug_fee.label')).toBeInTheDocument();
Expand All @@ -59,10 +60,12 @@ describe('Compose Form Component', () => {
expect(screen.queryByText('fields.lv.label')).not.toBeInTheDocument();
expect(screen.getByText('fields.lx.label')).toBeInTheDocument();
expect(screen.getByText('fields.rekey.label')).toBeInTheDocument();
expect(screen.getAllByText('fields.base64.label')).toHaveLength(2);
});

it('has base transaction fields (not using suggested parameters)', async () => {
render(<ComposeForm />);

expect(await screen.findByText('fields.type.label')).toBeInTheDocument();
expect(screen.getByText('fields.snd.label')).toBeInTheDocument();

Expand All @@ -78,10 +81,10 @@ describe('Compose Form Component', () => {
expect(useSugRoundsToggle).not.toBeChecked();
expect(screen.getByText('fields.fv.label')).toBeInTheDocument();
expect(screen.getByText('fields.lv.label')).toBeInTheDocument();

expect(screen.getByText('fields.note.label')).toBeInTheDocument();
expect(screen.getByText('fields.lx.label')).toBeInTheDocument();
expect(screen.getByText('fields.rekey.label')).toBeInTheDocument();
expect(screen.getAllByText('fields.base64.label')).toHaveLength(2);
});

it('has fields for payment transaction type if "Payment" transaction type is selected',
Expand Down Expand Up @@ -177,6 +180,7 @@ describe('Compose Form Component', () => {
expect(screen.queryByText('fields.apar_r_use_snd.label')).not.toBeInTheDocument();
expect(screen.queryByText('fields.apar_r.label')).not.toBeInTheDocument();
expect(screen.queryByText('fields.apar_am.label')).not.toBeInTheDocument();
expect(screen.getAllByText('fields.base64.label')).toHaveLength(2);

await userEvent.selectOptions(screen.getByLabelText(/fields.type.label/), 'acfg');

Expand All @@ -196,6 +200,7 @@ describe('Compose Form Component', () => {
expect(screen.getByText('fields.apar_r_use_snd.label')).toBeInTheDocument();
expect(screen.queryByText('fields.apar_r.label')).not.toBeInTheDocument();
expect(screen.getByText('fields.apar_am.label')).toBeInTheDocument();
expect(screen.getAllByText('fields.base64.label')).toHaveLength(3);
});

// eslint-disable-next-line max-len
Expand All @@ -219,6 +224,7 @@ describe('Compose Form Component', () => {
expect(screen.queryByText('fields.apar_r_use_snd.label')).not.toBeInTheDocument();
expect(screen.queryByText('fields.apar_r.label')).not.toBeInTheDocument();
expect(screen.queryByText('fields.apar_am.label')).not.toBeInTheDocument();
expect(screen.getAllByText('fields.base64.label')).toHaveLength(2);

await userEvent.selectOptions(screen.getByLabelText(/fields.type.label/), 'acfg');

Expand All @@ -230,6 +236,7 @@ describe('Compose Form Component', () => {
expect(screen.getByText('fields.apar_df.label')).toBeInTheDocument();
expect(screen.getByText('fields.apar_au.label')).toBeInTheDocument();
expect(screen.getByText('fields.apar_am.label')).toBeInTheDocument();
expect(screen.getAllByText('fields.base64.label')).toHaveLength(3);

// Turn off using sender for manager address
const aparMSndToggle = screen.getByLabelText('fields.apar_m_use_snd.label');
Expand Down
170 changes: 169 additions & 1 deletion src/app/[lang]/txn/compose/components/ComposeSubmitButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,51 @@ describe('Compose Form Component', () => {
expect(routerPushMock).toHaveBeenCalled();
});

it('can store submitted transaction data with Base64 note and lease', async () => {
render(
// Wrap component in new Jotai provider to reset data stored in Jotai atoms
<JotaiProvider><ComposeForm /></JotaiProvider>
);

// Enter data
await userEvent.selectOptions(screen.getByLabelText(/fields.type.label/), 'pay');
await userEvent.click(screen.getByLabelText(/fields.snd.label/));
await userEvent.paste('EW64GC6F24M7NDSC5R3ES4YUVE3ZXXNMARJHDCCCLIHZU6TBEOC7XRSBG4');
await userEvent.click(screen.getByLabelText(/fields.rcv.label/));
await userEvent.paste('GD64YIY3TWGDMCNPP553DZPPR6LDUSFQOIJVFDPPXWEG3FVOJCCDBBHU5A');
await userEvent.click(screen.getByLabelText(/fields.amt.label/));
await userEvent.paste('5');

const b64Checkboxes = screen.getAllByLabelText('fields.base64.label');
// Enter note as Base64
await userEvent.click(b64Checkboxes[0]); // Enable base64 for note
await userEvent.click(screen.getByLabelText(/fields.note.label/));
await userEvent.paste('SGVsbG8gd29ybGQh');
// Enter lease as Base64
await userEvent.click(b64Checkboxes[1]); // Enable base64 for note
await userEvent.click(screen.getByLabelText(/fields.lx.label/));
await userEvent.paste('SSB0aGluaywgdGhlcmVmb3JlIEkgYW0uIEZvb2Jhcg==');

// Submit data
await userEvent.click(screen.getByText('sign_txn_btn'));

// Check session storage
expect(JSON.parse(sessionStorage.getItem('txnData') || '{}')).toStrictEqual({
txn: {
type: 'pay',
snd: 'EW64GC6F24M7NDSC5R3ES4YUVE3ZXXNMARJHDCCCLIHZU6TBEOC7XRSBG4',
rcv: 'GD64YIY3TWGDMCNPP553DZPPR6LDUSFQOIJVFDPPXWEG3FVOJCCDBBHU5A',
amt: 5,
note: 'SGVsbG8gd29ybGQh',
lx: 'SSB0aGluaywgdGhlcmVmb3JlIEkgYW0uIEZvb2Jhcg==',
},
useSugFee: true,
useSugRounds: true,
b64Note: true,
b64Lx: true,
});
});

it('can store submitted *payment* transaction data', async () => {
render(
// Wrap component in new Jotai provider to reset data stored in Jotai atoms
Expand Down Expand Up @@ -81,6 +126,8 @@ describe('Compose Form Component', () => {
},
useSugFee: true,
useSugRounds: true,
b64Note: false,
b64Lx: false,
});
});

Expand Down Expand Up @@ -115,10 +162,74 @@ describe('Compose Form Component', () => {
},
useSugFee: true,
useSugRounds: true,
b64Note: false,
b64Lx: false,
retrievedAssetInfo: { name: 'Foo Token', unitName: 'FOO', total: 1000, decimals: 2 },
});
});

it('can store submitted *asset configuration* transaction data with Base64 metadata hash',
async () => {
render(
// Wrap component in new Jotai provider to reset data stored in Jotai atoms
<JotaiProvider><ComposeForm /></JotaiProvider>
);

// Enter data
await userEvent.selectOptions(screen.getByLabelText(/fields.type.label/), 'acfg');

await userEvent.click(screen.getByLabelText(/fields.snd.label/));
await userEvent.paste('EW64GC6F24M7NDSC5R3ES4YUVE3ZXXNMARJHDCCCLIHZU6TBEOC7XRSBG4');
await userEvent.click(screen.getByLabelText(/fields.apar_un.label/));
await userEvent.paste('FAKE');
await userEvent.click(screen.getByLabelText(/fields.apar_an.label/));
await userEvent.paste('Fake Token');
await userEvent.click(screen.getByLabelText(/fields.apar_t.label/));
await userEvent.paste('10000000');
await userEvent.click(screen.getByLabelText(/fields.apar_dc.label/));
await userEvent.paste('3');
await userEvent.click(screen.getByLabelText(/fields.apar_df.label/));
await userEvent.click(screen.getByLabelText(/fields.apar_au.label/));
await userEvent.paste('https://fake.token');

const b64Checkboxes = screen.getAllByLabelText('fields.base64.label');
// Enter metadata hash as Base64
await userEvent.click(b64Checkboxes[1]); // Enable base64 for metadata hash
await userEvent.click(screen.getByLabelText(/fields.apar_am.label/));
await userEvent.paste('VGhpcyBpcyBhIHZhbGlkIGhhc2ghISEhISEhISEhISE=');

// Submit data
await userEvent.click(screen.getByText('sign_txn_btn'));

// Check session storage
expect(JSON.parse(sessionStorage.getItem('txnData') || '{}')).toStrictEqual({
txn: {
type: 'acfg',
snd: 'EW64GC6F24M7NDSC5R3ES4YUVE3ZXXNMARJHDCCCLIHZU6TBEOC7XRSBG4',
apar_un: 'FAKE',
apar_an: 'Fake Token',
apar_t: '10000000',
apar_dc: 3,
apar_df: true,
apar_au: 'https://fake.token',
apar_m: 'EW64GC6F24M7NDSC5R3ES4YUVE3ZXXNMARJHDCCCLIHZU6TBEOC7XRSBG4',
apar_f: 'EW64GC6F24M7NDSC5R3ES4YUVE3ZXXNMARJHDCCCLIHZU6TBEOC7XRSBG4',
apar_c: 'EW64GC6F24M7NDSC5R3ES4YUVE3ZXXNMARJHDCCCLIHZU6TBEOC7XRSBG4',
apar_r: 'EW64GC6F24M7NDSC5R3ES4YUVE3ZXXNMARJHDCCCLIHZU6TBEOC7XRSBG4',
apar_am: 'VGhpcyBpcyBhIHZhbGlkIGhhc2ghISEhISEhISEhISE=',
},
useSugFee: true,
useSugRounds: true,
b64Note: false,
b64Lx: false,
b64Apar_am: true,
apar_mUseSnd: true,
apar_fUseSnd: true,
apar_cUseSnd: true,
apar_rUseSnd: true,
});
}, 10000);

// eslint-disable-next-line max-len
it('can store submitted *asset configuration* transaction data (with asset addresses set to sender)',
async () => {
Expand Down Expand Up @@ -168,10 +279,13 @@ describe('Compose Form Component', () => {
},
useSugFee: true,
useSugRounds: true,
b64Note: false,
b64Lx: false,
apar_mUseSnd: true,
apar_fUseSnd: true,
apar_cUseSnd: true,
apar_rUseSnd: true,
b64Apar_am: false,
});
}, 10000);

Expand Down Expand Up @@ -235,10 +349,13 @@ describe('Compose Form Component', () => {
},
useSugFee: true,
useSugRounds: true,
b64Note: false,
b64Lx: false,
apar_mUseSnd: false,
apar_fUseSnd: false,
apar_cUseSnd: false,
apar_rUseSnd: false,
b64Apar_am: false,
});
}, 10000);

Expand Down Expand Up @@ -286,6 +403,8 @@ describe('Compose Form Component', () => {
},
useSugFee: true,
useSugRounds: true,
b64Note: false,
b64Lx: false,
retrievedAssetInfo: {name: 'Foo Token', unitName: 'FOO', total: 1000, decimals: 2 },
});
}, 10000);
Expand Down Expand Up @@ -320,6 +439,8 @@ describe('Compose Form Component', () => {
},
useSugFee: true,
useSugRounds: true,
b64Note: false,
b64Lx: false,
retrievedAssetInfo: { name: 'Foo Token', unitName: 'FOO', total: 1000, decimals: 2 },
});
});
Expand Down Expand Up @@ -368,6 +489,8 @@ describe('Compose Form Component', () => {
},
useSugFee: true,
useSugRounds: true,
b64Note: false,
b64Lx: false,
});
});

Expand All @@ -381,7 +504,6 @@ describe('Compose Form Component', () => {
await userEvent.selectOptions(screen.getByLabelText(/fields.type.label/), 'appl');
await userEvent.click(screen.getByLabelText(/fields.snd.label/));
await userEvent.paste('EW64GC6F24M7NDSC5R3ES4YUVE3ZXXNMARJHDCCCLIHZU6TBEOC7XRSBG4');

await userEvent.click(screen.getByLabelText(/fields.apap.label/));
await userEvent.paste('BYEB');
await userEvent.click(screen.getByLabelText(/fields.apsu.label/));
Expand Down Expand Up @@ -464,6 +586,8 @@ describe('Compose Form Component', () => {
},
useSugFee: true,
useSugRounds: true,
b64Note: false,
b64Lx: false,
});
}, 10000);

Expand All @@ -482,6 +606,8 @@ describe('Compose Form Component', () => {
},
useSugFee: false,
useSugRounds: false,
b64Note: false,
b64Lx: false,
}));
render(
// Wrap component in new Jotai provider to reset data stored in Jotai atoms
Expand All @@ -493,6 +619,8 @@ describe('Compose Form Component', () => {
use_sug_fee: false,
fee: 0.001,
use_sug_rounds: false,
b64_note: false,
b64_lx: false,
fv: 5,
lv: 1005,
rekey: 'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB',
Expand Down Expand Up @@ -529,8 +657,48 @@ describe('Compose Form Component', () => {
rekey: 'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB',
rcv: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
amt: 42,
b64_note: false,
b64_lx: false
});
});

it('can retrieve transaction data from session storage with Base64 note and lease',
async () => {
sessionStorage.setItem('txnData', JSON.stringify({
txn: {
type: 'pay',
snd: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
fee: 0.001, // This should be ignored
fv: 5, // This should be ignored
lv: 1005, // This should be ignored
note: 'SGVsbG8gd29ybGQh',
rekey: 'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB',
rcv: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
amt: 42,
lx: 'VGhpcyBpcyBhIGxlYXNl',
},
useSugFee: true,
useSugRounds: true,
b64Note: true,
b64Lx: true,
}));
render(
// Wrap component in new Jotai provider to reset data stored in Jotai atoms
<JotaiProvider><ComposeForm /></JotaiProvider>
);
expect(await screen.findByRole('form')).toHaveFormValues({
type: 'pay',
snd: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
note: 'SGVsbG8gd29ybGQh',
use_sug_fee: true,
use_sug_rounds: true,
b64_note: true,
rekey: 'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB',
rcv: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
amt: 42,
lx: 'VGhpcyBpcyBhIGxlYXNl',
b64_lx: true
});
});

});
Loading

0 comments on commit 4d8b3ad

Please sign in to comment.