Skip to content

Commit 85d3200

Browse files
committed
feat: test/api features
Includes test cases and example implementations for all new features.
1 parent f2d2ffc commit 85d3200

File tree

247 files changed

+8383
-650
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

247 files changed

+8383
-650
lines changed

.github/workflows/build-example-web.yml

Lines changed: 12 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ name: Build and Deploy Examples
33
on: workflow_dispatch
44

55
env:
6-
COMMIT_FULL_SHA: ${{ github.sha }}
6+
COMMIT_SHORT_SHA: ${{ github.sha }}
77

8-
jobs:
9-
deploy_preview:
8+
build_expo:
109
runs-on: ubuntu-latest
1110
steps:
1211
- uses: actions/checkout@v4
@@ -19,133 +18,35 @@ jobs:
1918
with:
2019
node-version: '22'
2120
registry-url: 'https://registry.npmjs.org'
22-
2321
- name: Install Dependencies
2422
run: |
2523
yarn
2624
yarn bootstrap
27-
2825
- name: Build All Packages
2926
run: yarn build
30-
3127
- name: Build Expo Example
3228
run: EXPO_PUBLIC_COMMIT_SHA=${{ env.COMMIT_SHORT_SHA }} yarn expo export:web
3329
working-directory: packages/connect-examples/expo-example
3430

35-
- name: Add commit info to Expo Example
31+
- name: Add commit info to build output
3632
run: |
33+
# 先备份原始构建产物到临时目录
3734
mkdir -p temp-build
3835
cp -r web-build/* temp-build/ 2>/dev/null || true
36+
# 创建带有 commit id 的子目录
3937
mkdir -p web-build/commits/${{ env.COMMIT_SHORT_SHA }}
38+
# 复制备份的构建产物到带有 commit id 的目录
4039
cp -r temp-build/* web-build/commits/${{ env.COMMIT_SHORT_SHA }}/
40+
# 创建一个 commit 信息文件
4141
echo '{"commit": "${{ env.COMMIT_SHORT_SHA }}", "fullCommit": "${{ github.sha }}", "timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"}' > web-build/commits/${{ env.COMMIT_SHORT_SHA }}/commit-info.json
42+
# 为 commit 版本也创建 404.html
4243
cp web-build/commits/${{ env.COMMIT_SHORT_SHA }}/index.html web-build/commits/${{ env.COMMIT_SHORT_SHA }}/404.html
44+
# 清理临时目录
4345
rm -rf temp-build
4446
working-directory: packages/connect-examples/expo-example
4547

46-
- name: Build Expo Playground (testing preview)
47-
working-directory: packages/connect-examples/expo-playground
48-
env:
49-
COMMIT_SHA: ${{ env.COMMIT_SHORT_SHA }}
50-
run: yarn build
51-
52-
- name: Add SPA fallback pages
53-
run: |
54-
cp packages/connect-examples/expo-playground/dist/index.html packages/connect-examples/expo-playground/dist/404.html
55-
cp packages/connect-examples/expo-example/web-build/index.html packages/connect-examples/expo-example/web-build/404.html
56-
57-
- name: Prepare root static assets
58-
run: |
59-
rm -rf gh-pages-root
60-
mkdir -p gh-pages-root
61-
cp .github/templates/404.html gh-pages-root/404.html
62-
cp .github/templates/404.html gh-pages-root/index.html
63-
if [ -f "packages/connect-examples/expo-example/web-build/manifest.json" ]; then
64-
cp packages/connect-examples/expo-example/web-build/manifest.json gh-pages-root/manifest.json
65-
echo "✅ Copied manifest.json from expo-example"
66-
else
67-
cp .github/templates/manifest.json gh-pages-root/manifest.json
68-
echo "⚠️ expo-example manifest not found, using template"
69-
fi
70-
find packages/connect-examples/expo-example/web-build -maxdepth 1 -type f -name "favicon*" -exec cp {} gh-pages-root/ \;
71-
72-
- name: Deploy root assets
73-
uses: peaceiris/actions-gh-pages@v4
74-
with:
75-
github_token: ${{ secrets.GITHUB_TOKEN }}
76-
publish_dir: ./gh-pages-root
77-
cname: hardware-example.onekeytest.com
78-
force_orphan: true
79-
80-
- name: Deploy Expo Example (GitHub Pages)
81-
uses: peaceiris/actions-gh-pages@v4
82-
with:
83-
github_token: ${{ secrets.GITHUB_TOKEN }}
84-
publish_dir: packages/connect-examples/expo-example/web-build
85-
destination_dir: expo-example
86-
keep_files: true
87-
88-
- name: Deploy Expo Playground (GitHub Pages)
89-
uses: peaceiris/actions-gh-pages@v4
90-
with:
91-
github_token: ${{ secrets.GITHUB_TOKEN }}
92-
publish_dir: packages/connect-examples/expo-playground/dist
93-
destination_dir: expo-playground
94-
keep_files: true
95-
96-
build_playground_production:
97-
runs-on: ubuntu-latest
98-
needs: deploy_preview
99-
steps:
100-
- uses: actions/checkout@v4
101-
102-
- name: Get short commit SHA
103-
run: echo "COMMIT_SHORT_SHA=${GITHUB_SHA:0:7}" >> $GITHUB_ENV
104-
105-
- name: Setup Node.js
106-
uses: actions/setup-node@v4
107-
with:
108-
node-version: '22'
109-
registry-url: 'https://registry.npmjs.org'
110-
111-
- name: Install Dependencies
112-
run: |
113-
yarn
114-
yarn bootstrap
115-
116-
- name: Build All Packages
117-
run: yarn build
118-
119-
- name: Build Expo Playground (production)
120-
working-directory: packages/connect-examples/expo-playground
121-
env:
122-
COMMIT_SHA: ${{ env.COMMIT_FULL_SHA }}
123-
run: yarn build
124-
125-
- name: Package production bundle with commit id
126-
working-directory: packages/connect-examples/expo-playground
127-
env:
128-
COMMIT_FULL_SHA: ${{ env.COMMIT_FULL_SHA }}
129-
COMMIT_SHORT_SHA: ${{ env.COMMIT_SHORT_SHA }}
130-
run: |
131-
RELEASE_ROOT="release"
132-
rm -rf "${RELEASE_ROOT}"
133-
mkdir -p "${RELEASE_ROOT}"
134-
cp dist/index.html "${RELEASE_ROOT}/index.html"
135-
cp dist/404.html "${RELEASE_ROOT}/404.html"
136-
mkdir -p "${RELEASE_ROOT}/${COMMIT_FULL_SHA}"
137-
cp -R dist/${COMMIT_FULL_SHA}/. "${RELEASE_ROOT}/${COMMIT_FULL_SHA}/"
138-
cat <<EOF > "${RELEASE_ROOT}/${COMMIT_FULL_SHA}/build-info.json"
139-
{
140-
"commit": "${COMMIT_FULL_SHA}",
141-
"shortCommit": "${COMMIT_SHORT_SHA}",
142-
"buildEnv": "production",
143-
"buildTime": "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
144-
}
145-
EOF
146-
147-
- name: Upload Production Artifact
48+
- name: Upload Artifact
14849
uses: actions/upload-artifact@v4
14950
with:
150-
name: ${{ env.COMMIT_FULL_SHA }}
151-
path: packages/connect-examples/expo-playground/release
51+
name: expo-build
52+
path: packages/connect-examples/expo-example/web-build

.husky/pre-commit

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
# Run tests
33
yarn test
44

5-
# Run check versions
6-
yarn check-versions
7-
85
# Run lint:fix
96
yarn lint:staged
107

packages/connect-examples/expo-example/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { TamaguiProvider, PortalProvider, Text, Stack, Card, YStack } from 'tama
55
import { Toast, ToastProvider, ToastViewport, useToastState } from '@tamagui/toast';
66
import * as ExpoLinking from 'expo-linking';
77
import { SafeAreaProvider, useSafeAreaInsets } from 'react-native-safe-area-context';
8-
8+
import Watermark from '@uiw/react-watermark';
99
import { useIntl } from 'react-intl';
1010
import SDKProvider from './src/provider/SDKProvider';
1111

packages/connect-examples/expo-example/locale/en-US.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"action__ok": "OK",
3535

3636
"action__start_test": "Start Test",
37+
"action__start_error_test": "Testing failed cases",
3738
"action__stop_test": "Stop Test",
3839

3940
"tip__update_ready": "There are new versions that can be updated",
@@ -119,7 +120,6 @@
119120

120121
"label__device_bootloader_statue": "Bootloader",
121122
"label__device_firmware_status": "Firmware",
122-
123123
"label__device_se_info": "Device SE Information",
124124
"label__device_info_update_time": "Update Time",
125125
"label__device_info_refresh": "Refreshing Device Information",

packages/connect-examples/expo-example/locale/zh-CN.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"action__ok": "好的",
3535

3636
"action__start_test": "开始测试",
37+
"action__start_error_test": "测试失败用例",
3738
"action__stop_test": "停止测试",
3839

3940
"tip__update_ready": "检测到新的版本可以更新,点击进行安装",
@@ -50,7 +51,7 @@
5051
"tip__no_select_file": "未选择文件",
5152
"tip__update_success": "更新成功",
5253

53-
"title__common_parameters": "常用参数",
54+
"title__common_parameters": "通用参数 (每次请求都会使用)",
5455
"title__hardware_api_test": "硬件 API 测试",
5556
"title__updating": "正在更新",
5657
"title__input_pin": "输入 PIN",
@@ -119,7 +120,6 @@
119120

120121
"label__device_bootloader_statue": "Bootloader 状态",
121122
"label__device_firmware_status": "开机状态",
122-
123123
"label__device_se_info": "设备 SE 信息",
124124
"label__device_info_update_time": "更新时间",
125125
"label__device_info_refresh": "刷新设备信息",
@@ -197,7 +197,6 @@
197197
"message__address_not_match": "地址不匹配",
198198
"message__create": "创建",
199199
"message__generate": "生成",
200-
201200
"message__passphrase_count_test_describe": "开始之后根据提示解锁硬件, 根据硬件提示确认 passphrase, 不用自己输入",
202201
"message__passphrase_count_test_step1": "1. 从零开始创建钱包 passphrase 并记录下来,注意在硬件按确认 passphrase",
203202
"message__passphrase_count_test_step2": "2. 每次创建完一个 passphrase 钱包,都会去检查一遍之前创建过的钱包,是否可以正常获取地址",
@@ -206,7 +205,6 @@
206205
"message__passphrase_special_test_describe": "请输入与当前设备一致的助记词",
207206
"message__test_device_create_wallet_describe": "在硬件上创建钱包,将助记词输入在这里,用来验证硬件的助记词是否正确",
208207
"message__test_blind_signature_security_check_describe": "检查钱包盲签安全性,是否可以使用规定 CoinType 之外的私钥签名",
209-
210208
"message__message_is_empty": "请先输入设备的助记词",
211209

212210
"ignore": "忽略"

packages/connect-examples/expo-example/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"@tamagui/lucide-icons": "1.90.2",
3939
"@tamagui/toast": "1.90.2",
4040
"@ton/core": "^0.57.0",
41+
"@uiw/react-watermark": "^1.0.1",
4142
"asyncstorage-down": "^4.2.0",
4243
"axios": "1.12.2",
4344
"bchaddrjs": "^0.5.2",

packages/connect-examples/expo-example/src/components/Playground.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,46 @@ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
22
import * as Clipboard from 'expo-clipboard';
33
import { Group, H4, Stack, Text } from 'tamagui';
44
import { useIntl } from 'react-intl';
5+
import { IDeviceType } from '@onekeyfe/hd-core';
56
import PlaygroundExecutor, { type MethodPayload } from './PlaygroundExecutor';
67
import { useExpandMode } from '../provider/ExpandModeProvider';
78
import { Button } from './ui/Button';
89
import AutoWrapperTextArea from './ui/AutoWrapperTextArea';
910

11+
export type TestDeviceType = IDeviceType | 'common';
12+
13+
export interface TestExpect {
14+
skip?: boolean;
15+
success?: boolean;
16+
requestPin?: boolean;
17+
requestButton?: boolean;
18+
unknownMessage?: boolean;
19+
error?: boolean | number;
20+
}
21+
22+
export interface TestModalExpect {
23+
normal?: TestExpect;
24+
bootloader?: TestExpect;
25+
}
26+
27+
export type TestDeviceExpect = {
28+
[key in TestDeviceType]?: TestModalExpect;
29+
};
30+
1031
export interface PresupposeProps {
1132
title: string;
1233
value: any; // JSON object
34+
35+
expect?: TestDeviceExpect;
1336
}
1437

1538
export type PlaygroundProps = {
1639
description?: string;
1740
presupposes?: PresupposeProps[];
1841
deprecated?: boolean;
42+
43+
// eslint-disable-next-line react/no-unused-prop-types
44+
expect?: TestDeviceExpect;
1945
} & MethodPayload;
2046

2147
const Playground = ({
Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ScrollView, View } from 'tamagui';
2+
import Watermark from '@uiw/react-watermark';
23
import HeaderView from './Header';
34

45
export interface PageViewProps {
@@ -7,16 +8,18 @@ export interface PageViewProps {
78
}
89

910
const PageView = ({ children, scrollable = true }: PageViewProps) => (
10-
<View flex={1} backgroundColor="bgApp">
11-
<HeaderView />
12-
{scrollable ? (
13-
<ScrollView flex={1} testID="page-view-scrollable" overflow="scroll">
14-
{children}
15-
</ScrollView>
16-
) : (
17-
<View testID="page-view-non-scrollable">{children}</View>
18-
)}
19-
</View>
11+
<Watermark
12+
content="测试使用,需要特殊 Bridge"
13+
fontColor="rgb(255 0 0 / 15%)"
14+
gapX={480}
15+
gapY={480}
16+
fontSize={28}
17+
>
18+
<View flex={1} backgroundColor="bgApp">
19+
<HeaderView />
20+
{scrollable ? <ScrollView flex={1}>{children}</ScrollView> : <View>{children}</View>}
21+
</View>
22+
</Watermark>
2023
);
2124

2225
export default PageView;
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
// eslint-disable-next-line import/no-relative-packages
21

3-
export const CONNECT_SRC = process.env.CONNECT_SRC || `https://jssdk.onekey.so/1.1.17/`;
2+
export const CONNECT_SRC = process.env.CONNECT_SRC || `https://jssdk.onekeytest.com/`;

packages/connect-examples/expo-example/src/data/alephium.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ import { type PlaygroundProps } from '../components/Playground';
33
const api: PlaygroundProps[] = [
44
{
55
method: 'alephiumGetAddress',
6-
6+
description: 'Get address',
77
presupposes: [
88
{
99
title: 'Get address',
1010
value: {
1111
path: "m/44'/1234'/0'/0/0",
12-
includePublicKey: true,
1312
showOnOneKey: false,
1413
group: 0,
1514
},
@@ -20,13 +19,11 @@ const api: PlaygroundProps[] = [
2019
bundle: [
2120
{
2221
path: "m/44'/1234'/0'/0/0",
23-
includePublicKey: true,
2422
showOnOneKey: false,
2523
group: 0,
2624
},
2725
{
2826
path: "m/44'/1234'/0'/0/1",
29-
includePublicKey: true,
3027
showOnOneKey: false,
3128
group: 0,
3229
},
@@ -42,7 +39,7 @@ const api: PlaygroundProps[] = [
4239
},
4340
{
4441
method: 'alephiumSignMessage',
45-
42+
description: 'Sign Message',
4643
presupposes: [
4744
{
4845
title: 'Sign Alephium',
@@ -80,7 +77,7 @@ const api: PlaygroundProps[] = [
8077
},
8178
{
8279
method: 'alephiumSignTransaction',
83-
80+
description: 'Sign Transaction',
8481
presupposes: [
8582
{
8683
title: 'Native Transfer',

0 commit comments

Comments
 (0)