Skip to content
Closed
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
32 changes: 32 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Run SDK Tests

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
cache: 'pnpm'

- name: Set up pnpm
uses: pnpm/action-setup@v2
with:
version: 8

- name: Install SDK deps
run: pnpm --filter @mintlayer/sdk install

- name: Run SDK tests
run: pnpm --filter @mintlayer/sdk run test
22 changes: 21 additions & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ <h1 class="text-3xl font-bold text-center text-blue-600 mb-6">Mintlayer Wallet D
<div class="grid grid-cols-2 gap-4">
<button onclick="checkConnection()" class="bg-blue-500 text-white py-2 px-4 rounded-md shadow hover:bg-blue-600 transition">Check Connection</button>
<button onclick="connectWallet()" class="bg-blue-500 text-white py-2 px-4 rounded-md shadow hover:bg-blue-600 transition">Connect Wallet</button>
<button onclick="disconnectWallet()" class="bg-blue-500 text-white py-2 px-4 rounded-md shadow hover:bg-blue-600 transition">Disconnect Wallet</button>
<button onclick="getNewAddress()" class="bg-blue-500 text-white py-2 px-4 rounded-md shadow hover:bg-blue-600 transition">Get New Address</button>
<button onclick="getVersion()" class="bg-blue-500 text-white py-2 px-4 rounded-md shadow hover:bg-blue-600 transition">Get Version</button>
<button onclick="createDelegation()" class="bg-blue-500 text-white py-2 px-4 rounded-md shadow hover:bg-blue-600 transition">Create Delegation</button>
<button onclick="getBalance()" class="bg-blue-500 text-white py-2 px-4 rounded-md shadow hover:bg-blue-600 transition">Get Balance</button>
<button onclick="getBalances()" class="bg-blue-500 text-white py-2 px-4 rounded-md shadow hover:bg-blue-600 transition">Get Balances</button>
<button onclick="getDelegations()" class="bg-blue-500 text-white py-2 px-4 rounded-md shadow hover:bg-blue-600 transition">Get Delegations</button>
<button onclick="getDelegationsTotal()" class="bg-blue-500 text-white py-2 px-4 rounded-md shadow hover:bg-blue-600 transition">Get Delegations Total</button>
<button onclick="getAccountOrders()" class="bg-blue-500 text-white py-2 px-4 rounded-md shadow hover:bg-blue-600 transition">Get Account Orders</button>
Expand Down Expand Up @@ -357,7 +359,7 @@ <h3 class="text-xl font-semibold text-gray-700 mb-4">Output</h3>

async function checkConnection() {
try {
const result = await window.mintlayer.request({ method: 'checkConnection' });
const result = await window.mintlayer.isConnected();
displayOutput(`Connection status: ${JSON.stringify(result, null, 2)}`);
} catch (error) {
displayOutput(`Error: ${error.message}`);
Expand All @@ -373,6 +375,15 @@ <h3 class="text-xl font-semibold text-gray-700 mb-4">Output</h3>
}
}

async function disconnectWallet() {
try {
const result = await window.mintlayer.disconnect();
displayOutput(`Disconnected: ${JSON.stringify(result, null, 2)}`);
} catch (error) {
displayOutput(`Error: ${error.message}`);
}
}

async function getNewAddress() {
try {
const addresses = await window.mintlayer.request({ method: 'getNewAddress' });
Expand Down Expand Up @@ -400,6 +411,15 @@ <h3 class="text-xl font-semibold text-gray-700 mb-4">Output</h3>
}
}

async function getBalances() {
try {
const balance = await window.mintlayer.getBalances();
displayOutput(`Balance: ${JSON.stringify(balance, null, 2)}`);
} catch (error) {
displayOutput(`Error: ${error.message}`);
}
}

async function getDelegations() {
try {
const delegations = await window.mintlayer.getDelegations();
Expand Down
9 changes: 9 additions & 0 deletions packages/sdk/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// jest.config.js
module.exports = {
preset: 'ts-jest',
testEnvironment: 'jsdom',
setupFiles: ['<rootDir>/jest.setup.ts'],
moduleNameMapper: {
'^@mintlayer/wasm-lib$': '<rootDir>/tests/__mocks__/@mintlayer/wasm-lib.ts',
},
};
3 changes: 3 additions & 0 deletions packages/sdk/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import fetchMock from 'jest-fetch-mock';
import 'whatwg-fetch';
fetchMock.enableMocks();
Loading
Loading