Skip to content

Commit

Permalink
Refactor markup
Browse files Browse the repository at this point in the history
  • Loading branch information
benmalcom committed Jun 6, 2024
1 parent 17b2400 commit 4ec827b
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion packages/near-fast-auth-signer-e2e-tests/test-app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
});
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -140,7 +138,6 @@ export default function SignMultiChain(props: SignMultiChainProps) {
type="text"
id="amount"
name="amount"
defaultValue={0.02}
style={{ marginLeft: '3px' }}
/>
</label>
Expand All @@ -156,7 +153,6 @@ export default function SignMultiChain(props: SignMultiChainProps) {
type="text"
id="address"
name="address"
defaultValue={0.02}
style={{ marginLeft: '3px' }}
/>
</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> };

await expect(getFastAuthIframe(page).getByText('You are not authenticated or there has been an indexer failure')).not.toBeVisible();
Expand All @@ -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' } });
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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]) => {
Expand All @@ -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'),
Expand Down Expand Up @@ -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();
});

Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand Down
31 changes: 15 additions & 16 deletions packages/near-fast-auth-signer-e2e-tests/utils/multiChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Record<string, string | number | bigint>> => {
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<string, string | number | bigint> = {
const payload: Record<string, string | number | bigint> = {
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);
Expand Down

0 comments on commit 4ec827b

Please sign in to comment.