Skip to content

Commit

Permalink
refactor: walletd integrate sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Mar 29, 2024
1 parent e40a150 commit 025ef45
Show file tree
Hide file tree
Showing 41 changed files with 559 additions and 921 deletions.
9 changes: 4 additions & 5 deletions apps/walletd-e2e/src/fixtures/createWallet.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import { expect, Page } from '@playwright/test'
import { mockApiWallet } from '../mocks/mock'
import { mockApiWallet, mockApiWallets } from '@siafoundation/mocks'
import {
Wallet,
WalletAddressesResponse,
WalletBalanceResponse,
WalletFundResponse,
WalletOutputsSiacoinResponse,
} from '@siafoundation/react-walletd'
import { mockApiWallets } from '../mocks/wallets'

export async function createWallet({
page,
seed,
mnemonic,
newWallet,
responses = {},
}: {
page: Page
seed: string
mnemonic: string
newWallet: Wallet
responses?: {
balance?: WalletBalanceResponse
Expand Down Expand Up @@ -45,6 +44,6 @@ export async function createWallet({
await expect(
page.getByText(`Wallet ${newWallet.name.slice(0, 5)}`)
).toBeVisible()
await page.locator('input[name=mnemonic]').fill(seed)
await page.locator('input[name=mnemonic]').fill(mnemonic)
await page.getByRole('button', { name: 'Continue' }).click()
}
2 changes: 1 addition & 1 deletion apps/walletd-e2e/src/specs/login.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, expect } from '@playwright/test'
import { mockApiDefaults } from '../mocks/mock'
import { mockApiDefaults } from '@siafoundation/mocks'
import { login } from '../fixtures/login'

test('login', async ({ page }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
import { test, expect } from '@playwright/test'
import { mockApiDefaults } from '../../mocks/mock'
import { login } from '../../fixtures/login'
import { createWallet } from '../../fixtures/createWallet'
import { navigateToWallet } from '../../fixtures/navigateToWallet'
import { login } from '../fixtures/login'
import { createWallet } from '../fixtures/createWallet'
import { navigateToWallet } from '../fixtures/navigateToWallet'
import {
seed,
newWallet,
mockWalletAddressesResponse,
} from './seedGenerateAddresses.mock'
import { cloneDeep } from '@technically/lodash'
getMockScenarioSeedWallet,
mockApiDefaults,
} from '@siafoundation/mocks'
import { WalletAddressesResponse } from '@siafoundation/react-walletd'

const defaultMockWalletResponses = {
addresses: mockWalletAddressesResponse,
function getMockWalletAddressesResponse(): WalletAddressesResponse {
return []
}

function getDefaultMockWalletResponses() {
return {
addresses: getMockWalletAddressesResponse(),
}
}

test('generate new addresses', async ({ page }) => {
await mockApiDefaults({ page })
await login({ page })

const mockAddressesInvalid = cloneDeep(mockWalletAddressesResponse)
mockAddressesInvalid.forEach((address) => {
address.metadata.publicKey = undefined
})
const mocks = getMockScenarioSeedWallet()
const { newWallet, mnemonic } = mocks
await createWallet({
page,
newWallet,
seed,
responses: defaultMockWalletResponses,
mnemonic,
responses: getDefaultMockWalletResponses(),
})
await navigateToWallet({ page, wallet: newWallet })
await page.getByLabel('view addresses').click()
await page.getByRole('button', { name: 'Add addresses' }).click()
await page.locator('input[name=count]').fill('5')
await page.getByRole('button', { name: 'Continue' }).click()
await expect(
page.getByText('60838523a4bdeeec5b4f70a6678da48a77ad58fe...')
).toBeVisible()
await expect(
page.getByText('65b40f6a720352ad5b9546b9f5077209672914cc...')
).toBeVisible()
Expand All @@ -48,4 +47,7 @@ test('generate new addresses', async ({ page }) => {
await expect(
page.getByText('170173c40ca0f39f9618da30af14c390c7ce7024...')
).toBeVisible()
await expect(
page.getByText('90c6057cdd2463eca61f83796e83152dbba28b6c...')
).toBeVisible()
})

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
import { test, expect } from '@playwright/test'
import { mockApiDefaults } from '../../mocks/mock'
import { login } from '../../fixtures/login'
import { createWallet } from '../../fixtures/createWallet'
import { navigateToWallet } from '../../fixtures/navigateToWallet'
import { login } from '../fixtures/login'
import { createWallet } from '../fixtures/createWallet'
import { navigateToWallet } from '../fixtures/navigateToWallet'
import { fillComposeTransactionSiacoin } from '../fixtures/sendSiacoinDialog'
import {
seed,
newWallet,
receiveAddress,
changeAddress,
mockWalletFundResponse,
mockWalletOutputsSiacoinResponse,
mockWalletAddressesResponse,
} from './seedSendSiacoin.mock'
import { fillComposeTransactionSiacoin } from '../../fixtures/sendSiacoinDialog'
import { cloneDeep } from '@technically/lodash'
getMockScenarioSeedWallet,
mockApiDefaults,
} from '@siafoundation/mocks'

const defaultMockWalletResponses = {
fund: mockWalletFundResponse,
outputsSiacoin: mockWalletOutputsSiacoinResponse,
addresses: mockWalletAddressesResponse,
function getDefaultMockWalletResponses(
mocks: ReturnType<typeof getMockScenarioSeedWallet>
) {
return {
fund: mocks.walletFundResponse,
outputsSiacoin: mocks.walletOutputsSiacoinResponse,
addresses: mocks.walletAddressesResponse,
}
}

test('send siacoin with a seed wallet', async ({ page }) => {
await mockApiDefaults({ page })
await login({ page })
const mocks = getMockScenarioSeedWallet()
const { newWallet, mnemonic, receiveAddress, changeAddress } = mocks
await createWallet({
page,
newWallet,
seed,
responses: defaultMockWalletResponses,
mnemonic,
responses: getDefaultMockWalletResponses(mocks),
})
await navigateToWallet({ page, wallet: newWallet })
await page.getByLabel('send').click()
await fillComposeTransactionSiacoin({
page,
receiveAddress,
changeAddress,
receiveAddress: mocks.receiveAddress,
changeAddress: mocks.changeAddress,
amount: '1',
})
await expect(page.getByText('The wallet is currently unlocked')).toBeVisible()
Expand All @@ -46,7 +45,7 @@ test('send siacoin with a seed wallet', async ({ page }) => {
.getByRole('button', { name: 'Sign and broadcast transaction' })
.click()
await expect(
page.getByText('Transaction successfully broadcasted')
page.getByText('Transaction successfully broadcast')
).toBeVisible()
await expect(page.getByText(receiveAddress.slice(0, 5))).toBeVisible()
await expect(page.getByText(changeAddress.slice(0, 5))).toBeVisible()
Expand All @@ -58,16 +57,18 @@ test('errors if the input to sign is not found on the transaction', async ({
page,
}) => {
await mockApiDefaults({ page })
const mockFundInvalid = cloneDeep(mockWalletFundResponse)
const mocks = getMockScenarioSeedWallet()
const { newWallet, mnemonic, receiveAddress, changeAddress } = mocks
const mockFundInvalid = mocks.walletFundResponse
mockFundInvalid.transaction.siacoinInputs[0].parentID =
'scoid:bb3e781330c9b3991e0141807df1327fadf114ca6c37acb9e58004f942d91dfb'
await login({ page })
await createWallet({
page,
newWallet,
seed,
mnemonic,
responses: {
...defaultMockWalletResponses,
...getDefaultMockWalletResponses(mocks),
fund: mockFundInvalid,
},
})
Expand All @@ -91,17 +92,19 @@ test('errors if the input to sign is not found on the transaction', async ({

test('errors if the inputs matching utxo is not found', async ({ page }) => {
await mockApiDefaults({ page })
const mockOutputsInvalid = cloneDeep(mockWalletOutputsSiacoinResponse)
const mocks = getMockScenarioSeedWallet()
const { newWallet, mnemonic, receiveAddress, changeAddress } = mocks
const mockOutputsInvalid = mocks.walletOutputsSiacoinResponse
mockOutputsInvalid.forEach((output) => {
output.id = 'not the matching id'
})
await login({ page })
await createWallet({
page,
newWallet,
seed,
mnemonic: mnemonic,
responses: {
...defaultMockWalletResponses,
...getDefaultMockWalletResponses(mocks),
outputsSiacoin: mockOutputsInvalid,
},
})
Expand All @@ -127,16 +130,18 @@ test('errors if the address is missing its index', async ({ page }) => {
await mockApiDefaults({ page })
await login({ page })

const mockAddressesInvalid = cloneDeep(mockWalletAddressesResponse)
const mocks = getMockScenarioSeedWallet()
const { newWallet, mnemonic, receiveAddress, changeAddress } = mocks
const mockAddressesInvalid = mocks.walletAddressesResponse
mockAddressesInvalid.forEach((address) => {
address.metadata.index = undefined
})
await createWallet({
page,
newWallet,
seed,
mnemonic: mnemonic,
responses: {
...defaultMockWalletResponses,
...getDefaultMockWalletResponses(mocks),
addresses: mockAddressesInvalid,
},
})
Expand All @@ -162,16 +167,18 @@ test('errors if the address is missing its public key', async ({ page }) => {
await mockApiDefaults({ page })
await login({ page })

const mockAddressesInvalid = cloneDeep(mockWalletAddressesResponse)
const mocks = getMockScenarioSeedWallet()
const { newWallet, mnemonic, receiveAddress, changeAddress } = mocks
const mockAddressesInvalid = mocks.walletAddressesResponse
mockAddressesInvalid.forEach((address) => {
address.metadata.publicKey = undefined
address.metadata.unlockConditions.publicKeys[0] = undefined
})
await createWallet({
page,
newWallet,
seed,
mnemonic: mnemonic,
responses: {
...defaultMockWalletResponses,
...getDefaultMockWalletResponses(mocks),
addresses: mockAddressesInvalid,
},
})
Expand Down
25 changes: 7 additions & 18 deletions apps/walletd-e2e/src/specs/walletCreate.spec.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,17 @@
import { test, expect } from '@playwright/test'
import { mockApiDefaults } from '../mocks/mock'
import { login } from '../fixtures/login'
import { createWallet } from '../fixtures/createWallet'

const seed =
'credit tonight gauge army noodle reopen pepper property try mom taste solid'

const newWallet = {
id: '100',
name: 'new wallet 1',
description: 'wallet description',
dateCreated: new Date().toISOString(),
lastUpdated: new Date().toISOString(),
metadata: {
type: 'seed',
seedHash:
'9fe676742eb80d61fea4476e2d33a088d708a24c2762fa028f9bfbe693612d15b83223f7ba5bc2e0fe2390d243a47a18144f19acd34b105757b1ac7751da821f',
},
}
import {
getMockScenarioSeedWallet,
mockApiDefaults,
} from '@siafoundation/mocks'

test('wallet create', async ({ page }) => {
const mocks = getMockScenarioSeedWallet()
const { newWallet, mnemonic } = mocks
await mockApiDefaults({ page })
await login({ page })
await createWallet({ page, newWallet, seed })
await createWallet({ page, newWallet, mnemonic })
await expect(page.locator(`span:text('${newWallet.name}')`)).toBeVisible()
await page.locator(`span:text('${newWallet.name}')`).click()
await expect(page.getByText('The wallet has no')).toBeVisible()
Expand Down
2 changes: 1 addition & 1 deletion apps/walletd/components/Node/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function Node() {

const transactionCount = txPool.data
? (txPool.data.transactions?.length || 0) +
(txPool.data.v2Transactions?.length || 0)
(txPool.data.v2transactions?.length || 0)
: 0

return (
Expand Down
Loading

0 comments on commit 025ef45

Please sign in to comment.