-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-sdk.ts
More file actions
93 lines (80 loc) · 3.49 KB
/
test-sdk.ts
File metadata and controls
93 lines (80 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**
* Simple test script to verify the Cryptos EVM SDK is working.
* Run with: npx tsx test-sdk.ts
*/
// Import from compiled dist files directly
import { createCryptosClient, cryptosTestnetBeta, assertWallet } from "./packages/evm-client/dist/index.js";
import { ExampleErc20, ADDRESSES } from "./packages/contracts/dist/index.js";
async function main() {
console.log("=== Cryptos EVM SDK Test ===\n");
// 1. Test chain configuration
console.log("1. Chain Configuration:");
console.log(` Name: ${cryptosTestnetBeta.name}`);
console.log(` Chain ID: ${cryptosTestnetBeta.id}`);
console.log(` RPC: ${cryptosTestnetBeta.rpcUrls.default.http[0]}`);
console.log(` Native Currency: ${cryptosTestnetBeta.nativeCurrency.symbol}`);
console.log("");
// 2. Create client
console.log("2. Creating CryptosClient...");
const client = createCryptosClient({
rpcUrl: "https://rpc-testnet-beta-evm.cryptos.com",
});
console.log(" Client created successfully!");
console.log(` Has wallet: ${!!client.wallet}`);
console.log("");
// 3. Test public client - get block number
console.log("3. Testing Public Client (getBlockNumber)...");
try {
const blockNumber = await client.public.getBlockNumber();
console.log(` Current block number: ${blockNumber}`);
} catch (error) {
console.log(` Note: RPC call failed (network may be unavailable)`);
console.log(` Error: ${error instanceof Error ? error.message : error}`);
}
console.log("");
// 4. Test assertWallet (should throw since we didn't configure a wallet)
console.log("4. Testing assertWallet (should throw)...");
try {
assertWallet(client);
console.log(" ERROR: assertWallet should have thrown!");
} catch (error) {
console.log(` Correctly threw: "${error instanceof Error ? error.message : error}"`);
}
console.log("");
// 5. Test ExampleErc20 wrapper
console.log("5. Testing ExampleErc20 contract wrapper...");
// Test that it throws when no address configured
console.log(" 5a. Without address (should throw):");
try {
ExampleErc20(client);
console.log(" ERROR: Should have thrown!");
} catch (error) {
console.log(` Correctly threw: "${error instanceof Error ? error.message : error}"`);
}
// Test with explicit address
console.log(" 5b. With explicit address:");
const testAddress = "0x0000000000000000000000000000000000000001" as const;
const erc20 = ExampleErc20(client, testAddress);
console.log(` Contract address: ${erc20.getAddress()}`);
console.log(" Available read methods: name, symbol, decimals, totalSupply, balanceOf");
console.log(" Available write methods: transfer");
console.log(" Available watch methods: Transfer");
console.log("");
// 6. Test calling a read method (will fail on network but tests the interface)
console.log("6. Testing ERC20 read call (symbol)...");
try {
const symbol = await erc20.read.symbol();
console.log(` Symbol: ${symbol}`);
} catch (error) {
console.log(` Note: Contract call failed (expected - test address has no contract)`);
console.log(` This confirms the SDK is correctly calling the RPC.`);
}
console.log("");
// 7. Test ADDRESSES export
console.log("7. Testing ADDRESSES export:");
console.log(` Networks: ${Object.keys(ADDRESSES).join(", ")}`);
console.log(` ExampleErc20 address: ${ADDRESSES["cryptos-testnet-beta"].ExampleErc20 ?? "not configured"}`);
console.log("");
console.log("=== All SDK Tests Completed ===");
}
main().catch(console.error);