Skip to content

Commit

Permalink
finished sign tx flow and added an xdr with 3 operations
Browse files Browse the repository at this point in the history
  • Loading branch information
jeesunikim committed Nov 22, 2024
1 parent d1b1519 commit 5b21830
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 17 deletions.
12 changes: 9 additions & 3 deletions src/app/(sidebar)/transaction/sign/components/Overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,11 @@ export const Overview = () => {
/>
</Box>

<Box gap="md" addlClassName="PageBody__content">
<Box
gap="md"
addlClassName="PageBody__content"
data-testid="sign-tx-signature"
>
<LabelHeading size="md">Add a signature</LabelHeading>

<>
Expand Down Expand Up @@ -870,15 +874,17 @@ export const Overview = () => {
</PageCard>

{sign.signedTx ? (
<div ref={successResponseEl}>
<div ref={successResponseEl} data-testid="sign-tx-validation-card">
<ValidationResponseCard
variant="success"
title="Transaction signed!"
subtitle={getAllSigsMessage()}
response={
<Box gap="xs">
<div>
<div>{sign.signedTx}</div>
<div data-testid="validation-card-response">
{sign.signedTx}
</div>
</div>
</Box>
}
Expand Down
161 changes: 147 additions & 14 deletions tests/signTransactionPage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ test.describe("Sign Transaction Page", () => {
const secretKeysView = page.getByTestId("sign-tx-secretkeys");
const hardwareView = page.getByTestId("sign-tx-hardware");
const walletExtView = page.getByTestId("sign-tx-wallet-ext");
const sigExtView = page.getByTestId("sign-tx-signature");
const validationView = page.getByTestId("sign-tx-validation-card");
const signedXdr = page.getByTestId("validation-card-response");

// Import Screen
const importBtn = page.getByText("Import transaction");
Expand Down Expand Up @@ -79,21 +82,19 @@ test.describe("Sign Transaction Page", () => {
);
const addAddlSecretBtn = multiPickerContainer.getByText("Add additional");
const secretKeysSignBtn = secretKeysView.getByText("Sign transaction");

await expect(multiPickerInput).toHaveCount(1);
await addAddlSecretBtn.click();
await expect(multiPickerInput).toHaveCount(2);

// Type in a string in an invalid secret key format
await multiPickerInput.nth(0).fill("lkjlsdkjflksdjf");

const invalidSecretKeyErrorMsg = page.getByText(
"Invalid secret key. Please check your secret key and try again.",
);
const successSecretKeyMsg = secretKeysView.getByText(
"Successfully added 1 signature",
);

await expect(multiPickerInput).toHaveCount(1);
await addAddlSecretBtn.click();
await expect(multiPickerInput).toHaveCount(2);

// Type in a string in an invalid secret key format
await multiPickerInput.nth(0).fill("lkjlsdkjflksdjf");
await expect(invalidSecretKeyErrorMsg).toBeVisible();

// Type in a string in an valid secret key format
Expand All @@ -107,6 +108,12 @@ test.describe("Sign Transaction Page", () => {

await expect(successSecretKeyMsg).toBeVisible();

const firstSignedResponse = await signedXdr.getByText(
"AAAAAgAAAADJrq4b4AopDZibkeBWpDxuWKUcY4FUUNQdIEF3Nm9dkQAAAGQAAAIiAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAACXlGN76T6NQcaUJxbEkH3mi1HHWsHnLqMDdlLl9NlJgQAAAAAAAAAABfXhAAAAAAAAAAABjc9OtQAAAEBrpI8Q90yqEqjcLSubVj5nqtyt53bpVzi8Bzikps4xuom0xHQgrM6MsQS503ortwLcYOw0gyLPyst7J88ZDoQJ",
);

await expect(firstSignedResponse).toBeVisible();

/*** Signatures: Hardware Wallet ***/
const bipPathInput = await hardwareView.getByPlaceholder(
"BIP path in format: 44'/148'/0'",
Expand All @@ -126,26 +133,91 @@ test.describe("Sign Transaction Page", () => {
"Trezor",
]);

const hardwareSignBtn = hardwareView.getByText("Sign transaction");

await hardwareSignBtn.isDisabled();

await hardwareSelect.selectOption("Trezor");

await expect(hardwareSelect).toHaveValue("trezor");

const hardwareSignBtn = hardwareView.getByText("Sign transaction");
await hardwareSignBtn.isEnabled();

await hardwareSelect.selectOption("Ledger");

// Start waiting for popup before clicking. Note no await.
const pagePromise = page.context().waitForEvent("page");
await hardwareSignBtn.click();
await pagePromise;
await expect(hardwareSelect).toHaveValue("ledger");

// @TODO mock the hardware API
await hardwareSelect.selectOption("Hash with Ledger");

await expect(hardwareSelect).toHaveValue("ledger_hash");

/*** Signatures: Wallet Extension ***/
const walletExtSignBtn = walletExtView.getByRole("button", {
name: "Sign with wallet",
});
await walletExtSignBtn.click();

await expect(
page.getByRole("heading", { name: "Connect a Wallet" }),
).toBeVisible();

// Wallet Extension to display 6 wallets
await expect(page.getByRole("listitem")).toHaveCount(6);

// Exit out of the wallet extension modal
await page.click("body", { position: { x: 10, y: 10 } });

/*** Signatures: Add a signature ***/
const addSigBtn = sigExtView.getByText("Add signature to transaction");
await addSigBtn.isDisabled();

const pubKeyInput = sigExtView.getByPlaceholder("Public key");
const sigInput = sigExtView.getByPlaceholder(
"Hex encoded 64-byte ed25519 signature",
);
const pubKeyErrorMsg = sigExtView.getByText("Public key is invalid.");
const addSigErrorMsg = sigExtView.getByText(
"Error: invalid encoded string",
);
const addSigSuccessMsg = sigExtView.getByText(
"Successfully added 1 signature",
);

await expect(pubKeyInput).toBeVisible();
await expect(sigInput).toBeVisible();

pubKeyInput.fill("sdfsdf");

await expect(pubKeyErrorMsg).toBeVisible();

sigInput.fill(
"ef6db30947dafea9f87f821751812dc15180f084c70dfab6e359bc92fa892f10aa0eb403c37ccc77c67cb0fabc77eba6e151485a72c5e549c58a2f57f0c26101",
);

await addSigBtn.isEnabled();
await addSigBtn.click();

await expect(addSigErrorMsg).toBeVisible();

pubKeyInput.fill(
"GDBE5AQAPXR6DYK7WPTWY25KM4TN552VZ3543DZUGUND7KI2TB2SIAJX",
);

await expect(addSigErrorMsg).toBeHidden();

await addSigBtn.click();

await expect(addSigSuccessMsg).toBeVisible();

await expect(signedXdr).toContainText(
"AAAAAgAAAADJrq4b4AopDZibkeBWpDxuWKUcY4FUUNQdIEF3Nm9dkQAAAGQAAAIiAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAACXlGN76T6NQcaUJxbEkH3mi1HHWsHnLqMDdlLl9NlJgQAAAAAAAAAABfXhAAAAAAAAAAACjc9OtQAAAEBrpI8Q90yqEqjcLSubVj5nqtyt53bpVzi8Bzikps4xuom0xHQgrM6MsQS503ortwLcYOw0gyLPyst7J88ZDoQJGph1JAAAAEDvbbMJR9r+qfh/ghdRgS3BUYDwhMcN+rbjWbyS+okvEKoOtAPDfMx3xnyw+rx366bhUUhacsXlScWKL1fwwmEB",
);

const submitBtn = validationView.getByText(
"Submit in Transaction Submitter",
);
await expect(submitBtn).toBeEnabled();
await submitBtn.click();
});

test("Use an ScVal Type XDR that is not Transaction Envelope XDR", async ({
Expand All @@ -165,6 +237,64 @@ test.describe("Sign Transaction Page", () => {
await expect(decodeErrorMsg).toBeVisible();
});

test("Use an XDR that includes 3 operations", async ({ page }) => {
// sections
const overview = page.getByTestId("sign-tx-overview");
const signaturesView = page.getByTestId("sign-tx-sigs");

// Import Screen
const importBtn = page.getByText("Import transaction");
const validMsg = page.getByText("Valid Transaction Envelope XDR");

const xdrInput = page.getByLabel(
"Import a transaction envelope in XDR format",
);
await xdrInput.fill(MOCK_TX_XDR_3_OPERATIONS);

await expect(validMsg).toBeVisible();

await importBtn.click();

// Overview and Signatures Screen
await expect(overview).toBeVisible();
await expect(signaturesView).toBeVisible();

/*** TX Overview Details ***/
// Network passphrase
const overviewSigning = page.getByLabel("Signing for");
await expect(overviewSigning).toHaveValue(
"Test SDF Network ; September 2015",
);

// TX XDR
const overviewTxXDR = page.getByLabel("Transaction Envelope XDR");
await expect(overviewTxXDR).toHaveValue(MOCK_TX_XDR_3_OPERATIONS);

// TX HASH
const overviewTxHash = page.getByLabel("Transaction Hash");
await expect(overviewTxHash).toHaveValue(
"892110aecc9f30662d5ececcf2a1f2fdd03fc42f3b3ca55c475a05d421838e60",
);

// Source Account
const overviewSource = page.getByLabel("Source account");
await expect(overviewSource).toHaveValue(
"GBTQEP2NS6WSRRXYXZ4JJLLLO4OWH5LWHZFEGL5PMOQQDELD4MY5YUWJ",
);

// Sequence number
const overviewSeq = page.getByLabel("Sequence number");
await expect(overviewSeq).toHaveValue("4552819952582657");

// Transaction Fee (stroops)
const overviewTxFee = page.getByLabel("Transaction Fee (stroops)");
await expect(overviewTxFee).toHaveValue("300");

// Number of operations
const overviewOpsNum = page.getByLabel("Number of operations");
await expect(overviewOpsNum).toHaveValue("3");
});

test("Invalid XDR", async ({ page }) => {
const decodeErrorMsg = page.getByText(
"Unable to parse input XDR into Transaction Envelope",
Expand All @@ -190,3 +320,6 @@ const MOCK_SC_VAL_XDR =

const MOCK_TX_XDR =
"AAAAAgAAAADJrq4b4AopDZibkeBWpDxuWKUcY4FUUNQdIEF3Nm9dkQAAAGQAAAIiAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAACXlGN76T6NQcaUJxbEkH3mi1HHWsHnLqMDdlLl9NlJgQAAAAAAAAAABfXhAAAAAAAAAAAA";

const MOCK_TX_XDR_3_OPERATIONS =
"AAAAAgAAAABnAj9Nl60oxvi+eJSta3cdY/V2PkpDL69joQGRY+Mx3AAAASwAECzEAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAEAAAAABHLXc6lPRFz7BJua75KzEQi1Iw3Hj6bUXLrNdMRPZmYwAAAAAAAAAAAAAAAEctdzqU9EXPsEm5rvkrMRCLUjDcePptRcus10xE9mZjAAAAAAExLQAAAAAAAAAAEQAAAAAAAAAA";

0 comments on commit 5b21830

Please sign in to comment.