From 4ec827be9bc32ba4553922654ff02c515ae2e63b Mon Sep 17 00:00:00 2001 From: Ikeji Benjamin Date: Thu, 6 Jun 2024 22:55:34 +0100 Subject: [PATCH] Refactor markup --- .../test-app/App.tsx | 2 +- .../test-app/components/SignMultiChain.tsx | 16 ++++------ .../tests/models/SignMultiChain.ts | 8 ++--- .../tests/sign/sign-transaction.spec.ts | 6 ++-- .../signMultiChain/sign-multi-chain.spec.ts | 13 +++++--- .../utils/multiChain.ts | 31 +++++++++---------- 6 files changed, 38 insertions(+), 38 deletions(-) diff --git a/packages/near-fast-auth-signer-e2e-tests/test-app/App.tsx b/packages/near-fast-auth-signer-e2e-tests/test-app/App.tsx index b9132f61..c2e0b3ee 100644 --- a/packages/near-fast-auth-signer-e2e-tests/test-app/App.tsx +++ b/packages/near-fast-auth-signer-e2e-tests/test-app/App.tsx @@ -55,7 +55,7 @@ export default function App() { keyType: string, chainValue: number, amount: number, - chainId: string | bigint + chainId: string address: string }) => { const accountId = JSON.parse(window.localStorage.accountId); diff --git a/packages/near-fast-auth-signer-e2e-tests/test-app/components/SignMultiChain.tsx b/packages/near-fast-auth-signer-e2e-tests/test-app/components/SignMultiChain.tsx index bc9a6955..16f27539 100644 --- a/packages/near-fast-auth-signer-e2e-tests/test-app/components/SignMultiChain.tsx +++ b/packages/near-fast-auth-signer-e2e-tests/test-app/components/SignMultiChain.tsx @@ -6,7 +6,7 @@ type SignMultiChainProps = { keyType: string, chainValue: number, amount: number, - chainId: string | bigint, + chainId: string, address: string}) => void } export default function SignMultiChain(props: SignMultiChainProps) { @@ -27,17 +27,15 @@ export default function SignMultiChain(props: SignMultiChainProps) { const keyType = formData.get('keyType') as string; const chainValue = Number(formData.get('assetType')); + const amount = Number(formData.get('amount')); + const address = formData.get('address') as string; - let chainId: bigint | string = document + const chainId: bigint | string = document .querySelector('input[name="assetType"]:checked') .getAttribute('data-chainid'); - if (Number.isInteger(Number(chainId))) { - chainId = BigInt(chainId); - } - onSubmitForm({ keyType, chainId, chainValue, amount, address }); @@ -101,7 +99,7 @@ export default function SignMultiChain(props: SignMultiChainProps) { type="radio" id="eth" value={60} - data-chainid={BigInt('11155111')} + data-chainid={11155111} name="assetType" /> ETH sepolia @@ -112,7 +110,7 @@ export default function SignMultiChain(props: SignMultiChainProps) { type="radio" id="bnb" value={60} - data-chainid={BigInt('97')} + data-chainid={97} name="assetType" /> BSC testnet @@ -140,7 +138,6 @@ export default function SignMultiChain(props: SignMultiChainProps) { type="text" id="amount" name="amount" - defaultValue={0.02} style={{ marginLeft: '3px' }} /> @@ -156,7 +153,6 @@ export default function SignMultiChain(props: SignMultiChainProps) { type="text" id="address" name="address" - defaultValue={0.02} style={{ marginLeft: '3px' }} /> diff --git a/packages/near-fast-auth-signer-e2e-tests/tests/models/SignMultiChain.ts b/packages/near-fast-auth-signer-e2e-tests/tests/models/SignMultiChain.ts index 612ae876..35d7869c 100644 --- a/packages/near-fast-auth-signer-e2e-tests/tests/models/SignMultiChain.ts +++ b/packages/near-fast-auth-signer-e2e-tests/tests/models/SignMultiChain.ts @@ -43,10 +43,10 @@ class SignMultiChain { async submitTransactionInfo({ keyType, assetType, amount, address }: TransactionDetail) { - await this.page.check(`input[name="keyType"][value="${keyType}"]`); - await this.page.check(`input[name="assetType"][id="${assetType.toLowerCase()}"]`); - await this.page.fill('input[name="amount"]', `${amount}`); - await this.page.fill('input[name="address"]', `${address}`); + await this.page.check(`input#${keyType}`); + await this.page.check(`input#${assetType.toLowerCase()}`); + await this.page.fill('input#amount', `${amount}`); + await this.page.fill('input#address', `${address}`); await this.page.click('button[type="submit"]'); } diff --git a/packages/near-fast-auth-signer-e2e-tests/tests/sign/sign-transaction.spec.ts b/packages/near-fast-auth-signer-e2e-tests/tests/sign/sign-transaction.spec.ts index 4c783c7d..373d03db 100644 --- a/packages/near-fast-auth-signer-e2e-tests/tests/sign/sign-transaction.spec.ts +++ b/packages/near-fast-auth-signer-e2e-tests/tests/sign/sign-transaction.spec.ts @@ -118,8 +118,8 @@ describe('Sign transaction', () => { provider: { type: 'JsonRpcProvider', args: { url: 'https://rpc.testnet.near.org' } }, signer: { type: 'InMemorySigner', keyStore: new InMemoryKeyStore() }, }), 'dontcare'), 'v1.social08.testnet', { - viewMethods: ['get'], - changeMethods: [], + viewMethods: ['get'], + changeMethods: [] }) as Contract & { get: (args) => Promise }; await expect(getFastAuthIframe(page).getByText('You are not authenticated or there has been an indexer failure')).not.toBeVisible(); @@ -128,4 +128,4 @@ describe('Sign transaction', () => { const result = await new Promise((resolve) => { setTimeout(resolve, 5000); }).then(() => socialdbContract.get({ keys: [`${accountId}/**`] })); expect(result).toEqual({ [accountId]: { 'fast-auth-e2e-test': 'true' } }); }); -}); \ No newline at end of file +}); diff --git a/packages/near-fast-auth-signer-e2e-tests/tests/signMultiChain/sign-multi-chain.spec.ts b/packages/near-fast-auth-signer-e2e-tests/tests/signMultiChain/sign-multi-chain.spec.ts index 26bfd1a3..778a975b 100644 --- a/packages/near-fast-auth-signer-e2e-tests/tests/signMultiChain/sign-multi-chain.spec.ts +++ b/packages/near-fast-auth-signer-e2e-tests/tests/signMultiChain/sign-multi-chain.spec.ts @@ -30,13 +30,14 @@ const fakKeyPair = KeyPair.fromString(userFAK); test.describe('Sign MultiChain', () => { // Retry failed tests twice before giving up - test.describe.configure({ retries: 2 }); + // test.describe.configure({ retries: 2 }); test.beforeAll(async ({ browser }) => { const context = await browser.newContext(); page = await context.newPage(); signMultiChain = new SignMultiChain(page); await page.goto('/'); + await page.waitForLoadState('domcontentloaded'); await page.evaluate( // eslint-disable-next-line no-shadow async ([accountId]) => { @@ -47,6 +48,7 @@ test.describe('Sign MultiChain', () => { }); test.afterAll(async () => { + // Check if the derived address are low on funds and request new testnet tokens try { const balances = await Promise.all([ fetchEVMWalletBalance(ETH_PERSONAL_KEY_ADDRESS, 'eth-sepolia'), @@ -93,6 +95,7 @@ test.describe('Sign MultiChain', () => { keyType: 'personalKey', assetType: 'eth', amount: 0.001, address: receivingAddresses.ETH_BNB }); await signMultiChain.waitForMultiChainResponse(page); + await expect(page.locator('#nfw-connect-iframe')).toBeVisible(); await expect(getFastAuthIframe(page).getByText('You are not authenticated or there has been an indexer failure')).toBeVisible(); }); @@ -112,10 +115,11 @@ test.describe('Sign MultiChain', () => { await frame.locator('text=Send 0.001 ETH').waitFor({ state: 'visible' }); await signMultiChain.clickApproveButton(frame); const multiChainResponse = await signMultiChain.waitForMultiChainResponse(page); + expect(multiChainResponse.transactionHash).toBeDefined(); expect(multiChainResponse).toHaveProperty('message'); - expect(multiChainResponse).toHaveProperty('transactionHash'); expect(multiChainResponse.message).toBe('Successfully signed and sent transaction'); await expect(page.locator('#nfw-connect-iframe')).not.toBeVisible(); + await expect(page.locator('#nfw-connect-iframe')).not.toBeVisible(); }); test('Should Pass: Send BNB with domain Key', async () => { @@ -128,12 +132,13 @@ test.describe('Sign MultiChain', () => { retrievalKeypair: fakKeyPair }); await signMultiChain.submitTransactionInfo({ - keyType: 'domainKey', assetType: 'bnb', amount: 0.001, address: receivingAddresses.ETH_BNB + keyType: 'domainKey', assetType: 'bnb', amount: 0.0001, address: receivingAddresses.ETH_BNB }); const multiChainResponse = await signMultiChain.waitForMultiChainResponse(page); + expect(multiChainResponse.transactionHash).toBeDefined(); expect(multiChainResponse).toHaveProperty('message'); - expect(multiChainResponse).toHaveProperty('transactionHash'); expect(multiChainResponse.message).toBe('Successfully signed and sent transaction'); + await expect(page.locator('#nfw-connect-iframe')).not.toBeVisible(); }); test('Should Fail: Insufficient Funds with Unknown Key + BTC', async () => { diff --git a/packages/near-fast-auth-signer-e2e-tests/utils/multiChain.ts b/packages/near-fast-auth-signer-e2e-tests/utils/multiChain.ts index 77e3bb1b..196f4d82 100644 --- a/packages/near-fast-auth-signer-e2e-tests/utils/multiChain.ts +++ b/packages/near-fast-auth-signer-e2e-tests/utils/multiChain.ts @@ -71,38 +71,37 @@ export const fetchDerivedAddress = async ({ accountId, chainValue, keyType }: { } }; -export const getTransactionPayload = async ({ - keyType, - chainId, - chainValue, - amount, - address, - accountId -}: { +export const getTransactionPayload = async (values: { keyType: string, chainValue: number, amount: number, - chainId: string | bigint, + chainId: string, address: string, accountId: string, }): Promise> => { + const { + keyType, + chainId, + chainValue, + amount, + address, + accountId + } = values; try { const derivedAddress = await fetchDerivedAddress({ accountId, chainValue, keyType }); console.log('derivedAddress ', derivedAddress); const domain = getDomain(keyType); - let payload: Record = { + const payload: Record = { chain: chainValue, - ...(domain ? { domain } : {}), to: address, value: BigInt(getValue(chainValue, amount)), from: derivedAddress, }; - if (chainValue !== 0) { - payload = { ...payload, chainId: chainId as bigint }; - } else { - payload = { ...payload, network: 'testnet' }; - } + if (domain) payload.domain = domain; + if (chainValue !== 0) payload.chainId = BigInt(chainId); + else payload.network = 'testnet'; + return payload; } catch (error) { console.log('Error generating transaction payload ', error);