xek-sdk
Version:
SDK for katana blockchain
54 lines (51 loc) • 3.07 kB
JavaScript
;
const assert = require ('assert');
const sdk = require ('../index');
describe ('SDK test case', () => {
describe ('Test SDK generate address and import address', () => {
it ('generate address', async () => {
const wallet = sdk.Wallet;
const newWallet = await wallet.generateWallet ('longtd', '123456789');
assert.deepEqual (newWallet.walletName, 'longtd', "wallet name must be same with input");
assert.notDeepEqual (newWallet.walletName, null, "wallet name must not be empty");
assert.notDeepEqual (newWallet.publicKey, null, "publicKey must not be empty");
assert.notDeepEqual (newWallet.address, null, "address must not be empty");
assert.notDeepEqual (newWallet.mnemonic, null, "mnemonic must not be empty");
assert.notDeepEqual (newWallet.keyEncrypt, null, "keyEncrypt must not be empty");
});
it ('import wallet', async () => {
const mnemonic = 'claw limb inspire pulse fee test myth source peanut category region parade';
const wallet = sdk.Wallet;
const importWallet = await wallet.restoreWallet (mnemonic, 'longtd', '123456789');
assert.deepEqual (importWallet.walletName, 'longtd', "wallet name must be same with input");
assert.notDeepEqual (importWallet.walletName, null, "wallet name must not be empty");
assert.notDeepEqual (importWallet.publicKey, null, "publicKey must not be empty");
assert.notDeepEqual (importWallet.address, null, "address must not be empty");
assert.notDeepEqual (importWallet.keyEncrypt, null, "keyEncrypt must not be empty");
});
});
describe ('Test SDK send transaction', () => {
it ('send transaction success', async () => {
const privateKey = 'E9D2136DC48A6BAF814E2F5803755FAA5D077DFE17FD53EEAB205AD47E6B165AF20D409A8E197BC5305221BC77E2B529E20956419F8C945066D10127C5EDB05E';
const receive = 'E4E7C88BEB93B6A2C70B1D8DFC9493D9D8A55424';
const sender = '51C5086A4EAB851BB276CB85893AF08F387DD415';
const amount = 100;
const chainId = 'xek-network-25D77A';
const XEKSdk = sdk.XEKSdk;
const SDK = new XEKSdk (chainId);
// let amountBefore = await SDK.webAPI.getBalance(sender);
// amountBefore = new BigNumber(amountBefore);
// let amountBeforeReceiver = await SDK.webAPI.getBalance(receive);
// amountBeforeReceiver = new BigNumber(amountBeforeReceiver);
let tx = await SDK.createSendTx (sender, receive, amount, privateKey);
// let amountAfter = await SDK.webAPI.getBalance(sender);
// amountAfter = new BigNumber(amountAfter);
// let amountAfterReceiver = await SDK.webAPI.getBalance(receive);
// amountAfterReceiver = new BigNumber(amountAfterReceiver);
// console.log(amountBefore.minus(amountAfter).toNumber());
// console.log(amountAfterReceiver.plus(amountBeforeReceiver).toNumber());
assert.notDeepEqual(tx.success, false, 'Transaction success must be true');
assert.notDeepEqual(tx.data, undefined, 'Transaction data must be different undefined');
});
});
});