Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CU-86dt1fxtx-1 - Implement Contextual Messages on WcSdk on both sides #116

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/wallet-connect-sdk-core",
"comment": "Implemented a Contextual Messages on WcSdk",
"type": "patch"
}
],
"packageName": "@cityofzion/wallet-connect-sdk-core"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/wallet-connect-sdk-react",
"comment": "Implemented a Contextual Messages on WcSdk",
"type": "patch"
}
],
"packageName": "@cityofzion/wallet-connect-sdk-react"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/wallet-connect-sdk-svelte",
"comment": "Implemented a Contextual Messages on WcSdk",
"type": "patch"
}
],
"packageName": "@cityofzion/wallet-connect-sdk-svelte"
}
4 changes: 2 additions & 2 deletions e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"prepare": "npm install serve -g && pnpm exec playwright install",
"report:clean": "rm -rf playwright-report test-results tests-results",
"report:open": "npx pnpm playwright show-report",
"test": "playwright test --headed",
"test:headless": "playwright test"
"test": "playwright test --headed --trace on",
"test:headless": "playwright test --trace on"
},
"devDependencies": {
"@playwright/test": "^1.38.1",
Expand Down
2 changes: 1 addition & 1 deletion e2e/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { JSON_REPORT_PATH, TESTS_DIR } from './src/constants/PathsDefinitions'
import { MAX_RETRIES, RUN_CONCURRENTLY_COMMAND } from './src/constants/DevConstants'

const config: PlaywrightTestConfig = {
fullyParallel: true,
fullyParallel: false,
testMatch: '**/*.spec.ts',
webServer: {
command: RUN_CONCURRENTLY_COMMAND,
Expand Down
1 change: 1 addition & 0 deletions e2e/src/constants/GenericData.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export const ACCOUNT_PASSWORD: string = "Password: Not '12345' - because we're not living in 1995!"
export const DAPP_METHOD_CONTEXT_MESSAGE: string = "Accept this and your balance goes 'to the moon'!"
6 changes: 5 additions & 1 deletion e2e/src/pageCommonSteps/WalletReactSteps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ export async function connectDappToReactWallet(walletPage: ExampleProject, dappU
await walletPage.page.getByTestId('connect-dapp__dapp-uri-input').fill(dappUri.trim()) // Fill in the dapp URI
await walletPage.awaitAndClickTestId('proposal-card__approve') // Click the approve button
}
export async function acceptPendingRequestToReactWallet(walletPage: ExampleProject) {
export async function acceptPendingRequestToReactWallet(
walletPage: ExampleProject,
actionBeforeAcceptMethod?: (walletPage: ExampleProject) => Promise<void> | void,
) {
let retries = 0
let requests = []
do {
Expand All @@ -24,5 +27,6 @@ export async function acceptPendingRequestToReactWallet(walletPage: ExampleProje
} while (retries < MAX_RETRIES && requests.length == 0)
if (requests.length === 0) throw Error('No pending requests are found')
await walletPage.awaitAndClickTestId('default-card__pending-request')
if (actionBeforeAcceptMethod) await actionBeforeAcceptMethod(walletPage)
await walletPage.awaitAndClickTestId('request-card__approve')
}
19 changes: 18 additions & 1 deletion e2e/tests/DappMethods.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { expect, test } from '@playwright/test'
import { DAPP_REACT, WALLET_REACT } from '../src/constants/ProjectsDefinitions'
import { connectReactDappToNewReactAccount } from '../src/helpers/CommonStepsHelper'
import { getAnyFromInnerHTML } from '../src/helpers/CleanerHelper'
import { getAnyFromInnerHTML, getCleanInnerHTML } from '../src/helpers/CleanerHelper'
import { acceptPendingRequestToReactWallet } from '../src/pageCommonSteps/WalletReactSteps'
import { DAPP_METHOD_CONTEXT_MESSAGE } from '../src/constants/GenericData'

test('Create a new account and connect with a dapp (React)', async ({ context }) => {
// Define the dapp and wallet pages
Expand Down Expand Up @@ -152,3 +153,19 @@ test('Test Wipe Methods on dapp (React)', async ({ context }) => {
const pendingRequests = await walletPage.page.getByTestId('default-card__pending-request').all()
expect(pendingRequests.length).toBe(0) // Verify if has no pending Requests
})

test('Test send a contextual with a Verify Success on dapp (React)', async ({ context }) => {
// Define the dapp and wallet pages
const dappPage = DAPP_REACT
const walletPage = WALLET_REACT
await connectReactDappToNewReactAccount(context, dappPage, walletPage)
await dappPage.awaitAndClickTestId('hello-world__verify-with-context')
await acceptPendingRequestToReactWallet(walletPage, async (walletPageBeforeAcceptMethod) => {
const contextMessage = await walletPageBeforeAcceptMethod.awaitAndGetTestId('request-card__contextual-message')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure that the test ID request-card__contextual-message is consistently used across all relevant test files to avoid potential discrepancies in element targeting.

expect(contextMessage).toBeDefined()
expect(await getCleanInnerHTML(contextMessage)).toBe(DAPP_METHOD_CONTEXT_MESSAGE)
})
const response = await getAnyFromInnerHTML(await dappPage.awaitAndGetTestId('hello-world__method-response'))
expect(response).toBeDefined() // Verify if the response had a return
expect(response as boolean).toBeTruthy() // Verify if the response returned true
})
19 changes: 19 additions & 0 deletions examples/wc-dapp-react/src/components/HelloWorld.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,22 @@ function HelloWorld() {
}
}

const verifySuccessWithContext = async () => {
try {
const resp = await wcSdk.withContext("Accept this and your balance goes 'to the moon'!").verifyMessage({
publicKey: '031757edb62014dea820a0b33a156f6a59fc12bd966202f0e49357c81f26f5de34',
data: 'aeb234ed1639e9fcc95a102633b1c70ca9f9b97e9592cc74bfc40cbc7fefdb19ae8c6b49ebd410dbcbeec6b5906e503d528e34cd5098cc7929dbcbbaf23c5d77',
salt: '052a55a8d56b73b342a8e41da3050b09',
messageHex:
'010001f0a0303532613535613864353662373362333432613865343164613330353062303965794a68624763694f694a49557a49314e694973496e523563434936496b705856434a392e65794a6c654841694f6a45324e444d304e7a63324e6a4d73496d6c68644349364d5459304d7a4d354d5449324d33302e7253315f73735230364c426778744831504862774c306d7a6557563950686d5448477a324849524f4a4f340000',
})
console.log(resp)
setResponse(JSON.stringify(resp, null, 2))
} catch (e) {
onError(e)
}
}

const onError = (error: any) => {
Toastify({
text: error.message,
Expand Down Expand Up @@ -528,6 +544,9 @@ function HelloWorld() {
<button data-testid="hello-world__sign-transaction" onClick={signTransaction}>
Sign Transaction
</button>
<button data-testid="hello-world__verify-with-context" onClick={verifySuccessWithContext}>
Verify Success With Context
</button>
<button data-testid="hello-world__wipe-methods" onClick={wipeMethods}>
Wipe Methods
</button>
Expand Down
8 changes: 8 additions & 0 deletions examples/wc-wallet-react/src/components/RequestCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export default function RequestCard(
props.closeRequest()
}

const contextualMessage = String(request.params.contextualMessage).trim()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure that request.params.contextualMessage exists before converting it to a string and trimming it. This could potentially throw an error if contextualMessage is undefined or not present in request.params.


const items = Array.isArray(request.params)
? request.params
: request.params.invocations
Expand Down Expand Up @@ -59,6 +61,12 @@ export default function RequestCard(
Neo3
</Text>
</Flex>
<Text fontSize="0.875rem" color="#888888" fontWeight="bold" mt="0.875rem">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure that the color #888888 is consistent with the theme or color scheme of the application. If there is a theme file or constants for colors, consider using that instead of hardcoding the color value.

Method Contextual Message
</Text>
<Text fontSize="0.875rem" mt="0.5rem" data-testid="request-card__contextual-message">
{contextualMessage}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The data-testid attribute value request-card__contextual_message should follow a consistent naming convention. Verify that it aligns with other data-testid values throughout the project for consistency.

</Text>
<Text fontSize="0.875rem" color="#888888" fontWeight="bold" mt="0.875rem">
Method
</Text>
Expand Down
2 changes: 1 addition & 1 deletion examples/wc-wallet-react/src/constants/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const DEFAULT_APP_METADATA = {

export const DEFAULT_CHAIN: Chain = 'testnet'
export const DEFAULT_NETWORKS: Record<Chain, { url: string | null; name: string }> = {
testnet: { url: 'https://testnet1.neo.coz.io:443', name: 'Testnet' },
testnet: { url: 'https://testnet2.neo.coz.io:443', name: 'Testnet' },
mainnet: { url: 'http://seed1.neo.org:10332', name: 'Mainnet' },
private: { url: null, name: 'Private Network' },
}
Expand Down
Loading
Loading