-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2bab9f9
commit 58fa700
Showing
32 changed files
with
3,596 additions
and
1,266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,90 @@ | ||
import { expect, test } from "@playwright/test"; | ||
import { expect, Page, test } from "@playwright/test"; | ||
|
||
import { satoshiToBtc } from "@/utils/btcConversions"; | ||
import { maxDecimals } from "@/utils/maxDecimals"; | ||
import { trim } from "@/utils/trim"; | ||
|
||
import { | ||
NATIVE_SEGWIT_MAINNET_ADDRESS, | ||
NATIVE_SEGWIT_SIGNET_ADDRESS, | ||
TAPROOT_MAINNET_ADDRESS, | ||
TAPROOT_SIGNET_ADDRESS, | ||
} from "./constants/wallet"; | ||
import { setupWalletConnection } from "./helper/connect"; | ||
import { extractNumericBalance } from "./helper/utils"; | ||
import { nativeSegwitMainnetBalance } from "./mock/mainnet/nativeSegwit/utxos"; | ||
import { taprootMainnetBalance } from "./mock/mainnet/taproot/utxos"; | ||
import { nativeSegwitSignetBalance } from "./mock/signet/nativeSegwit/utxos"; | ||
import { taprootSignetBalance } from "./mock/signet/taproot/utxos"; | ||
|
||
type Network = "mainnet" | "signet"; | ||
type AddressType = "taproot" | "nativeSegwit"; | ||
|
||
// Determine the network from environment variable or default to 'mainnet' | ||
const network: Network = | ||
(process.env.NEXT_PUBLIC_NETWORK as Network) || "mainnet"; | ||
|
||
// Define the address types to test | ||
const addressTypes: AddressType[] = ["taproot", "nativeSegwit"]; | ||
|
||
// Mappings for expected addresses based on network and address type | ||
const expectedAddresses: Record<AddressType, Record<Network, string>> = { | ||
taproot: { | ||
mainnet: TAPROOT_MAINNET_ADDRESS, | ||
signet: TAPROOT_SIGNET_ADDRESS, | ||
}, | ||
nativeSegwit: { | ||
mainnet: NATIVE_SEGWIT_MAINNET_ADDRESS, | ||
signet: NATIVE_SEGWIT_SIGNET_ADDRESS, | ||
}, | ||
}; | ||
|
||
// Mappings for expected balances based on network and address type | ||
const expectedBalances: Record<AddressType, Record<Network, number>> = { | ||
taproot: { | ||
mainnet: taprootMainnetBalance, | ||
signet: taprootSignetBalance, | ||
}, | ||
nativeSegwit: { | ||
mainnet: nativeSegwitMainnetBalance, | ||
signet: nativeSegwitSignetBalance, | ||
}, | ||
}; | ||
|
||
// Reusable function for checking address | ||
async function checkAddress(page: Page, expectedAddress: string) { | ||
const address = await page.getByTestId("address").textContent(); | ||
expect(address).toBe(trim(expectedAddress)); | ||
} | ||
|
||
// Reusable function for checking balance | ||
async function checkBalance(page: Page, expectedBalance: number) { | ||
const balanceText = await page.getByTestId("balance").textContent(); | ||
const balance = maxDecimals(extractNumericBalance(balanceText), 8); | ||
expect(balance).toBe(satoshiToBtc(expectedBalance)); | ||
} | ||
|
||
test.describe("Balance and address checks after connection", () => { | ||
test.beforeEach(async ({ page }) => { | ||
await page.goto("/"); | ||
await setupWalletConnection(page); | ||
}); | ||
|
||
test("balance is correct", async ({ page }) => { | ||
const balance = await page.getByTestId("balance").textContent(); | ||
expect(balance).toBe("0.12345678 BTC"); | ||
}); | ||
|
||
test("address is correct", async ({ page }) => { | ||
const address = await page.getByTestId("address").textContent(); | ||
expect(address).toBe("bc1p...97sd"); | ||
}); | ||
// Iterate over each address type | ||
for (const type of addressTypes) { | ||
test.describe(`${type} address on ${network}`, () => { | ||
// Setup wallet connection before each test | ||
test.beforeEach(async ({ page }) => { | ||
await setupWalletConnection(page, network, type); | ||
}); | ||
|
||
test(`should verify the ${type} address and balance on ${network}`, async ({ | ||
page, | ||
}) => { | ||
const expectedAddress = expectedAddresses[type][network]; | ||
const expectedBalance = expectedBalances[type][network]; | ||
|
||
// Perform address check | ||
await checkAddress(page, expectedAddress); | ||
|
||
// Perform balance check | ||
await checkBalance(page, expectedBalance); | ||
}); | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Constants for selectors and texts | ||
|
||
export const BUTTON_TEXT_CONNECT_TO_BTC = "Connect to BTC"; | ||
export const LABEL_TEXT_ACCEPT_TERMS = "I certify that I have read"; | ||
export const LABEL_TEXT_NO_INSCRIPTIONS = "I certify that there are no"; | ||
export const LABEL_TEXT_HW_WALLET = "I acknowledge that Keystone via QR code"; | ||
export const BUTTON_TEXT_BROWSER = "Browser"; | ||
export const INPUT_DURATION_BLOCKS = "Blocks"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Don't use real funds with these addresses | ||
export const MNEMONIC = | ||
"baby baby baby baby baby baby baby rocket rocket rocket rocket science"; | ||
|
||
// The following addresses are derived from the above mnemonic | ||
export const TAPROOT_MAINNET_ADDRESS = | ||
"bc1p620x2d0wvycj0y7jmc0lxytk0m64swcx2lp430grtn0klqwugpcsgwalan"; | ||
// 038f561718d7f3ead37bd57e7b68360325db2263acfbbc8cb6b129e768d27aa46d | ||
export const NATIVE_SEGWIT_MAINNET_ADDRESS = | ||
"bc1q7w09t8gl84c7ksus5nt3r2eg0qexk987hk9n23"; | ||
// 02ed32cf86745ea2c7a13f72b3194a576c249736e0b773e1a9f837767d60a3adcf | ||
export const TAPROOT_SIGNET_ADDRESS = | ||
"tb1pc29r075qcgypvxzaq34680sk3epwv3xrqu4fnkskrqesd65d9yjqun5x5j"; | ||
// 025bf662d62fdfaa781c6ecb6b533d50f5a8a1b6892e9fe5609ccccd07e041b20a | ||
export const NATIVE_SEGWIT_SIGNET_ADDRESS = | ||
"tb1qrspcmpwh4k05xlflx7fqz5dmgpt06fydfmyzyr"; | ||
// 026b4ebd2b5ec63b8e9260c540921e46e75bbdcc42cf14bc3c0274e8d6a544bda1 |
Oops, something went wrong.