Skip to content

Commit 91a175d

Browse files
committed
chore(sdk): added test output scripts to compare implementations across different languages.
1 parent cbe396e commit 91a175d

4 files changed

Lines changed: 399 additions & 3 deletions

File tree

sdk/js/test-outputs.js

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
#!/usr/bin/env node
2+
3+
const { DstackClient, TappdClient, getComposeHash, verifyEnvEncryptPublicKey } = require('./dist/node/index.js');
4+
const { toViemAccount, toViemAccountSecure } = require('./dist/node/viem.js');
5+
const { toKeypair, toKeypairSecure } = require('./dist/node/solana.js');
6+
7+
async function main() {
8+
console.log("=== JS SDK Output Test ===");
9+
10+
try {
11+
// Test client get_key
12+
const client = new DstackClient();
13+
console.log("\n1. Testing DstackClient.getKey()");
14+
15+
const testPaths = [
16+
{ path: "test/wallet", purpose: "ethereum" },
17+
{ path: "test/signing", purpose: "solana" },
18+
{ path: "user/alice", purpose: "mainnet" }
19+
];
20+
21+
for (const { path, purpose } of testPaths) {
22+
const keyResult = await client.getKey(path, purpose);
23+
console.log(`getKey('${path}', '${purpose}'):`);
24+
console.log(` key: ${Buffer.from(keyResult.key).toString('hex')}`);
25+
console.log(` signature_chain length: ${keyResult.signature_chain.length}`);
26+
console.log(` signature_chain[0]: ${Buffer.from(keyResult.signature_chain[0]).toString('hex')}`);
27+
}
28+
29+
// Test viem integration
30+
console.log("\n2. Testing Viem Integration");
31+
const ethKey = await client.getKey("eth/test", "wallet");
32+
33+
console.log("\n2.1 toViemAccount (legacy):");
34+
try {
35+
const account = toViemAccount(ethKey);
36+
console.log(` address: ${account.address}`);
37+
console.log(` type: ${account.type}`);
38+
} catch (error) {
39+
console.log(` error: ${error.message}`);
40+
}
41+
42+
console.log("\n2.2 toViemAccountSecure:");
43+
try {
44+
const accountSecure = toViemAccountSecure(ethKey);
45+
console.log(` address: ${accountSecure.address}`);
46+
console.log(` type: ${accountSecure.type}`);
47+
} catch (error) {
48+
console.log(` error: ${error.message}`);
49+
}
50+
51+
// Test solana integration
52+
console.log("\n3. Testing Solana Integration");
53+
const solKey = await client.getKey("sol/test", "wallet");
54+
55+
console.log("\n3.1 toKeypair (legacy):");
56+
try {
57+
const keypair = toKeypair(solKey);
58+
console.log(` publicKey: ${keypair.publicKey.toString()}`);
59+
console.log(` secretKey length: ${keypair.secretKey.length}`);
60+
console.log(` secretKey (first 32 bytes): ${Buffer.from(keypair.secretKey.slice(0, 32)).toString('hex')}`);
61+
} catch (error) {
62+
console.log(` error: ${error.message}`);
63+
}
64+
65+
console.log("\n3.2 toKeypairSecure:");
66+
try {
67+
const keypairSecure = toKeypairSecure(solKey);
68+
console.log(` publicKey: ${keypairSecure.publicKey.toString()}`);
69+
console.log(` secretKey length: ${keypairSecure.secretKey.length}`);
70+
console.log(` secretKey (first 32 bytes): ${Buffer.from(keypairSecure.secretKey.slice(0, 32)).toString('hex')}`);
71+
} catch (error) {
72+
console.log(` error: ${error.message}`);
73+
}
74+
75+
// Test TappdClient (deprecated)
76+
console.log("\n4. Testing TappdClient (deprecated)");
77+
try {
78+
const tappdClient = new TappdClient();
79+
console.log("\n4.1 TappdClient.getKey():");
80+
const tappdKey = await tappdClient.getKey("test/wallet", "ethereum");
81+
console.log(` key: ${Buffer.from(tappdKey.key).toString('hex')}`);
82+
console.log(` signature_chain length: ${tappdKey.signature_chain.length}`);
83+
84+
console.log("\n4.2 TappdClient.tdxQuote():");
85+
const tappdQuote = await tappdClient.tdxQuote("test-data", "raw");
86+
console.log(` quote length: ${tappdQuote.quote.length}`);
87+
console.log(` event_log length: ${tappdQuote.event_log.length}`);
88+
console.log(` rtmrs count: ${tappdQuote.replayRtmrs().length}`);
89+
} catch (error) {
90+
console.log(` error: ${error.message}`);
91+
}
92+
93+
// Test quotes
94+
console.log("\n5. Testing Quote Methods");
95+
console.log("\n5.1 DstackClient.getQuote():");
96+
const dstackQuote = await client.getQuote("test-data-for-quote");
97+
console.log(` quote length: ${dstackQuote.quote.length}`);
98+
console.log(` event_log length: ${dstackQuote.event_log.length}`);
99+
console.log(` rtmrs count: ${dstackQuote.replayRtmrs().length}`);
100+
101+
// Test getComposeHash
102+
console.log("\n6. Testing getComposeHash");
103+
const testComposes = [
104+
{
105+
manifest_version: 1,
106+
name: "test-app",
107+
runner: "docker-compose",
108+
docker_compose_file: "services:\\n app:\\n image: test\\n ports:\\n - 8080:8080"
109+
},
110+
{
111+
manifest_version: 1,
112+
name: "another-app",
113+
runner: "docker-compose",
114+
docker_compose_file: "services:\\n web:\\n build: .\\n environment:\\n - NODE_ENV=production"
115+
}
116+
];
117+
118+
testComposes.forEach((compose, index) => {
119+
const hash = getComposeHash(compose);
120+
console.log(`compose ${index + 1}: ${hash}`);
121+
console.log(` name: ${compose.name}`);
122+
console.log(` runner: ${compose.runner}`);
123+
});
124+
125+
// Test verifyEnvEncryptPublicKey
126+
console.log("\n7. Testing verifyEnvEncryptPublicKey");
127+
const testCases = [
128+
{
129+
publicKey: Buffer.from('e33a1832c6562067ff8f844a61e51ad051f1180b66ec2551fb0251735f3ee90a', 'hex'),
130+
signature: Buffer.from('8542c49081fbf4e03f62034f13fbf70630bdf256a53032e38465a27c36fd6bed7a5e7111652004aef37f7fd92fbfc1285212c4ae6a6154203a48f5e16cad2cef00', 'hex'),
131+
appId: '0000000000000000000000000000000000000000'
132+
},
133+
{
134+
publicKey: Buffer.from('deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef', 'hex'),
135+
signature: Buffer.from('0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', 'hex'),
136+
appId: 'invalid-app-id'
137+
}
138+
];
139+
140+
testCases.forEach((testCase, index) => {
141+
try {
142+
const result = verifyEnvEncryptPublicKey(testCase.publicKey, testCase.signature, testCase.appId);
143+
console.log(`test case ${index + 1}: ${result ? Buffer.from(result).toString('hex') : 'null'}`);
144+
} catch (error) {
145+
console.log(`test case ${index + 1}: error - ${error.message}`);
146+
}
147+
});
148+
149+
} catch (error) {
150+
console.error("Error:", error.message);
151+
process.exit(1);
152+
}
153+
}
154+
155+
main().catch(console.error);

sdk/python/Makefile

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
.PHONY: install lint format type-check test check-all verify
2+
3+
# Install dependencies including linting tools
4+
install:
5+
pdm install -G lint
6+
7+
# Run all formatters (using PDM scripts)
8+
format:
9+
pdm run fmt
10+
11+
# Alias for format
12+
fmt: format
13+
14+
# Run linting tools (using PDM scripts)
15+
lint:
16+
pdm run lint
17+
18+
# Run type checking only
19+
type-check:
20+
pdm run mypy src/
21+
22+
# Run tests
23+
test:
24+
@if [ -z "$$DSTACK_SIMULATOR_ENDPOINT" ]; then \
25+
echo "error: DSTACK_SIMULATOR_ENDPOINT environment variable is not set"; \
26+
exit 1; \
27+
fi
28+
@if [ -z "$$TAPPD_SIMULATOR_ENDPOINT" ]; then \
29+
echo "error: TAPPD_SIMULATOR_ENDPOINT environment variable is not set"; \
30+
exit 1; \
31+
fi
32+
@if [[ "$$DSTACK_SIMULATOR_ENDPOINT" == /* ]] && [ ! -e "$$DSTACK_SIMULATOR_ENDPOINT" ]; then \
33+
echo "error: dstack socket file $$DSTACK_SIMULATOR_ENDPOINT does not exist"; \
34+
exit 1; \
35+
fi
36+
@if [[ "$$TAPPD_SIMULATOR_ENDPOINT" == /* ]] && [ ! -e "$$TAPPD_SIMULATOR_ENDPOINT" ]; then \
37+
echo "error: tappd socket file $$TAPPD_SIMULATOR_ENDPOINT does not exist"; \
38+
exit 1; \
39+
fi
40+
pdm run test
41+
42+
# Run all checks (format, lint, skip test)
43+
check-all:
44+
pdm run fmt
45+
pdm run lint
46+
47+
# Check code without fixing (for CI)
48+
check:
49+
pdm run check
50+
51+
# Run verification without formatting (skip test)
52+
verify:
53+
pdm run check

sdk/python/pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ repository = "pypi"
124124
[tool.pdm.scripts]
125125
# Formatting scripts
126126
fmt = {composite = ["isort src/ tests/", "black src/ tests/"]}
127-
format = {call = "pdm:fmt"}
127+
format = {composite = ["isort src/ tests/", "black src/ tests/"]}
128128

129129
# Linting scripts
130130
lint = {composite = ["flake8 src/ tests/", "mypy src/"]}
@@ -135,8 +135,8 @@ test = "pytest"
135135
test-cov = "pytest --cov=src/"
136136

137137
# Combined scripts
138-
check-all = {composite = ["pdm:fmt", "pdm:lint", "pdm:test"]}
139-
verify = {composite = ["pdm:check", "pdm:test"]}
138+
check-all = {composite = ["fmt", "lint", "test"]}
139+
verify = {composite = ["check", "test"]}
140140

141141
[tool.pdm.dev-dependencies]
142142
solana = [

0 commit comments

Comments
 (0)