vana-sdk
Version:
A TypeScript library for interacting with Vana Network smart contracts
110 lines • 5.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const viem_1 = require("viem");
const accounts_1 = require("viem/accounts");
const vitest_1 = require("vitest");
const chains_1 = require("../../config/chains");
const provider_1 = require("../provider");
// Test constants
const TEST_PRIVATE_KEY = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80";
const TEST_RPC_URL = process.env.NEXT_PUBLIC_RPC_URL || "https://rpc.moksha.vana.org";
const RICH_ADDRESS = "0x1111000000000000000000000000000000000000";
const TEST_BALANCE = 1000000000000000000n; // 1 ETH
const testAccount = (0, accounts_1.privateKeyToAccount)(TEST_PRIVATE_KEY);
(0, vitest_1.describe)("VanaProvider", () => {
const testClient = (0, viem_1.createTestClient)({
chain: chains_1.mokshaTestnet,
mode: "hardhat",
transport: (0, viem_1.http)(TEST_RPC_URL),
})
.extend(viem_1.publicActions)
.extend(viem_1.walletActions);
let vana;
let signer;
(0, vitest_1.beforeEach)(async () => {
signer = (0, accounts_1.privateKeyToAccount)(TEST_PRIVATE_KEY);
vana = new provider_1.VanaProvider({
chainId: chains_1.mokshaTestnet.id,
rpcUrl: TEST_RPC_URL,
signer,
});
vitest_1.vi.clearAllMocks();
});
(0, vitest_1.describe)("Initialization", () => {
(0, vitest_1.it)("should initialize with correct properties", () => {
(0, vitest_1.expect)(vana.chainId).toBe(chains_1.mokshaTestnet.id);
(0, vitest_1.expect)(vana.client).toBeDefined();
(0, vitest_1.expect)(vana.contracts).toBeDefined();
(0, vitest_1.expect)(vana.contracts.dataRegistry).toBeDefined();
(0, vitest_1.expect)(vana.contracts.teePool).toBeDefined();
(0, vitest_1.expect)(vana.contracts.dataLiquidityPool).toBeDefined();
(0, vitest_1.expect)(vana.contracts.computeEngine).toBeDefined();
});
});
(0, vitest_1.describe)("Signer Operations", () => {
(0, vitest_1.it)("should return correct signer address", async () => {
const address = await vana.signerAddress();
(0, vitest_1.expect)(address.toLowerCase()).toBe(testAccount.address.toLowerCase());
});
(0, vitest_1.it)("should throw error when no signer is configured", async () => {
const vanaWithoutSigner = new provider_1.VanaProvider({
chainId: chains_1.mokshaTestnet.id,
rpcUrl: TEST_RPC_URL,
});
await (0, vitest_1.expect)(vanaWithoutSigner.signerAddress()).rejects.toThrow("No signer configured");
});
});
(0, vitest_1.describe)("Network Operations", () => {
(0, vitest_1.it)("should connect to Moksha testnet and get block data", async () => {
const blockNumber = await testClient.getBlockNumber();
(0, vitest_1.expect)(blockNumber).toBeTypeOf("bigint");
(0, vitest_1.expect)(blockNumber).toBeGreaterThan(0n);
});
vitest_1.it.skip("should handle account impersonation", async () => {
// Skipping as impersonation is not supported on public testnets
await testClient.setBalance({
address: RICH_ADDRESS,
value: TEST_BALANCE,
});
await testClient.impersonateAccount({ address: RICH_ADDRESS });
const balance = await testClient.getBalance({ address: RICH_ADDRESS });
(0, vitest_1.expect)(balance).toBe(TEST_BALANCE);
await testClient.stopImpersonatingAccount({ address: RICH_ADDRESS });
await (0, vitest_1.expect)(testClient.getBalance({ address: RICH_ADDRESS })).resolves.toBeDefined();
});
});
(0, vitest_1.describe)("Contract Interactions", () => {
(0, vitest_1.it)("should handle contract version reading when deployed", async () => {
vitest_1.vi.spyOn(console, "log").mockImplementation(() => { });
try {
const version = await testClient.readContract({
address: vana.contracts.dataRegistry.address,
abi: vana.contracts.dataRegistry.abi,
functionName: "version",
});
(0, vitest_1.expect)(version).toBeDefined();
}
catch (error) {
(0, vitest_1.expect)(console.log).toHaveBeenCalledWith("Contracts not deployed on test network, skipping interaction tests");
}
});
(0, vitest_1.it)("should return valid contract addresses", () => {
(0, vitest_1.expect)(vana.contracts.dataRegistry.address).toMatch(/^0x[a-fA-F0-9]{40}$/);
(0, vitest_1.expect)(vana.contracts.teePool.address).toMatch(/^0x[a-fA-F0-9]{40}$/);
(0, vitest_1.expect)(vana.contracts.dataLiquidityPool.address).toMatch(/^0x[a-fA-F0-9]{40}$/);
(0, vitest_1.expect)(vana.contracts.computeEngine.address).toMatch(/^0x[a-fA-F0-9]{40}$/);
});
});
(0, vitest_1.describe)("Error Handling", () => {
(0, vitest_1.it)("should handle invalid chain ID", () => {
(0, vitest_1.expect)(() => {
new provider_1.VanaProvider({
chainId: 999999,
rpcUrl: TEST_RPC_URL,
signer,
});
}).toThrow("Chain 999999 not found");
});
});
});
//# sourceMappingURL=provider.test.js.map