@dolaned/wallet-sdk-ts
Version:
Wallet SDK for the Nexa blockchain
70 lines (56 loc) • 2.4 kB
text/typescript
import {describe, test, expect} from "vitest";
import {Wallet} from "../../../src";
import {rostrumProvider} from "../../../src/network/RostrumProvider";
import WatchOnlyWallet from "../../../src/wallet/WatchOnlyWallet";
/**
* Test suite for the main Wallet class
*
* Tests wallet initialization, account management, and transaction creation
* on the Nexa testnet.
*/
describe('#Wallet', {timeout: 100000}, function() {
/**
* Test wallet initialization and basic transaction creation
*
* This test:
* - Creates a wallet from a seed phrase
* - Initializes it to discover accounts
* - Creates a transaction with OP_RETURN data
* - Tests the full transaction flow
*/
test('Init wallet', async () => {
await rostrumProvider.connect()
const wallet = new Wallet('mask wool cram snap cross wood rebuild among total vicious script diamond', 'testnet')
await wallet.initialize()
const defaultAccount = wallet.accountStore.getAccount('2.0')
expect(defaultAccount).toBeDefined()
if(!defaultAccount){
return;
}
const transactions = await defaultAccount.getTransactions()
expect(transactions).toBeDefined()
const newAddress = defaultAccount.getNewAddress()
expect(newAddress).toBeDefined()
const tx = await wallet.newTransaction(defaultAccount)
.onNetwork('testnet')
.sendTo('nexatest:nqtsq5g5jsdmqqywaqd82lhnnk3a8wqunjz6gtxdtavnnekc', '10000')
.addOpReturn("First wallet SDK transaction, Woo!!")
.populate()
.sign()
.build()
expect(tx).toBeDefined()
const watchOnlyWallet = new WatchOnlyWallet([{
address: 'nexatest:nqtsq5g5dsgh6mwjchqypn8hvdrjue0xpmz293fl7rm926xv',
}], 'testnet')
const tx2 = await watchOnlyWallet.newTransaction()
.sendTo('nexatest:nqtsq5g5jsdmqqywaqd82lhnnk3a8wqunjz6gtxdtavnnekc', '100000')
.addOpReturn("Second wallet SDK transaction, Woo!!")
.populate()
.build()
expect(tx2).toBeDefined()
const parsedTx = await wallet.newTransaction(defaultAccount, tx2).sign().build()
expect(parsedTx).toBeDefined()
const walletData = wallet.export()
expect(walletData).toBeDefined()
});
});