import { buildTransaction, getPayload, getHolaParameters, verifyAddress} from "."; import { hexToBytes } from "./TransactionHelper"; import * as mocha from 'mocha'; import * as chai from 'chai'; import { Network } from "./types"; const expect = chai.expect; describe('hw_dot address verification tests', () => { it('Should verify dot address' , () => { expect(verifyAddress("1469eAwvWhqkVmnXdVDbmzZ8rEkTdMExXfUNkbi6MXWwKuM6")) .to.equal(true); }); it('Should verify dot address' , () => { expect(verifyAddress("5D5NGqtcGt5rM8pgC4YarFfWUDMMHE2ifRVQTG2HdM5WbB3z")) .to.equal(true); }); it('Should fail verify dot address' , () => { expect(verifyAddress("5D5NGqtcGt5rM8pgC4YArFfWUDMMHE2ifRVQTG2HdM5WbB3z")) .to.equal(false); }); }); describe('hw_dot transaction building tests', () => { it('Should build unsigned DOT transaction correctly' , () => { expect(buildTransaction({from: "5DABfyrZYXfKiZr2U8hhfCb2Weq4EWScZ9jPupXxsibP8pcT", to: "5GTnjZBoHBp1KU5S534DDrPGgaXpiiWHpbVwgeqFTeuqz5wX", amount:"150", nonce: "3", fee: "0.015534", tip:"0", net: Network.Testnet}).toString('hex')) .to.equal("41010400306a18b8a2e8146169ea0d803f821e335b81a9a041d80295ecb788ccdabd4dd900000c00040000c28bff2cbe3bea5459b1301b91f0de47d5f4838e60fb540fc3d6e39f3d0d29120b0060b7986c88"); }); const signature = hexToBytes("f59d71094572d22aa31b282ba12723e7740ea42a13d26e6bf1d6bbf468c6784b1bf0405780b309a8d42edb13621970d74afbc0975c4b7bbcee5350f53a65e601"); it('Should build signed DOT transaction correctly' , () => { expect(buildTransaction({from: "5DABfyrZYXfKiZr2U8hhfCb2Weq4EWScZ9jPupXxsibP8pcT", to: "5GTnjZBoHBp1KU5S534DDrPGgaXpiiWHpbVwgeqFTeuqz5wX", amount:"150", nonce: "3", fee: "0.015534", tip:"0", net: Network.Testnet, signature: signature}).toString('hex')) .to.equal("41028400306a18b8a2e8146169ea0d803f821e335b81a9a041d80295ecb788ccdabd4dd900f59d71094572d22aa31b282ba12723e7740ea42a13d26e6bf1d6bbf468c6784b1bf0405780b309a8d42edb13621970d74afbc0975c4b7bbcee5350f53a65e601000c00040000c28bff2cbe3bea5459b1301b91f0de47d5f4838e60fb540fc3d6e39f3d0d29120b0060b7986c88"); }); }); describe('hw_dot payload building tests', () => { it('Should build unsigned DOT payload correctly' , () => { expect(getPayload({from: "5DABfyrZYXfKiZr2U8hhfCb2Weq4EWScZ9jPupXxsibP8pcT", to: "5GTnjZBoHBp1KU5S534DDrPGgaXpiiWHpbVwgeqFTeuqz5wX", amount:"150", nonce: "3", fee: "0.015534", tip:"0", net: Network.Testnet}).toString('hex')) .to.equal("040000c28bff2cbe3bea5459b1301b91f0de47d5f4838e60fb540fc3d6e39f3d0d29120b0060b7986c88000c00a223000007000000e143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423ee143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e"); }); }); describe('hw_dot HOLa parameters generation tests', () => { it('Should generate HOLa parameters correctly' , () => { let parameters = getHolaParameters({from: "5DABfyrZYXfKiZr2U8hhfCb2Weq4EWScZ9jPupXxsibP8pcT", to: "5GTnjZBoHBp1KU5S534DDrPGgaXpiiWHpbVwgeqFTeuqz5wX", amount:"150", nonce: "3", fee: "0.015534", tip:"0", net: Network.Testnet}); let correctBlkData = ["040000c28bff2cbe3bea5459b1301b91f0de47d5f4838e60fb540fc3d6e39f3d0d29120b0060b7986c88000c00a223000007000000e143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423ee143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e","039de60780"]; let blkCont = 0; for(let blk of parameters.blk){ expect(blk.toString('hex')).to.equal(correctBlkData[blkCont]); blkCont++; } let correctU32Data = [1,6]; let u32cont = 0 for(let u32 of parameters.u32){ expect(u32).to.equal(correctU32Data[u32cont]); u32cont++; } }); }); describe('hw_dot big transaction building tests', () => { it('Should build unsigned DOT transaction with big amount correctly' , () => { expect(buildTransaction({from: "5DABfyrZYXfKiZr2U8hhfCb2Weq4EWScZ9jPupXxsibP8pcT", to: "5GTnjZBoHBp1KU5S534DDrPGgaXpiiWHpbVwgeqFTeuqz5wX", amount:"1101428557", nonce: "3", fee: "0.015534", tip:"0", net: Network.Testnet}).toString('hex')) .to.equal("4d010400306a18b8a2e8146169ea0d803f821e335b81a9a041d80295ecb788ccdabd4dd900000c00040000c28bff2cbe3bea5459b1301b91f0de47d5f4838e60fb540fc3d6e39f3d0d29121700d01510f94c64b53b"); }); const signature = hexToBytes("f59d71094572d22aa31b282ba12723e7740ea42a13d26e6bf1d6bbf468c6784b1bf0405780b309a8d42edb13621970d74afbc0975c4b7bbcee5350f53a65e601"); it('Should build signed DOT transaction with big amount correctly' , () => { expect(buildTransaction({from: "5DABfyrZYXfKiZr2U8hhfCb2Weq4EWScZ9jPupXxsibP8pcT", to: "5GTnjZBoHBp1KU5S534DDrPGgaXpiiWHpbVwgeqFTeuqz5wX", amount:"1101428557", nonce: "3", fee: "0.015534", tip:"0", net: Network.Testnet, signature: signature}).toString('hex')) .to.equal("4d028400306a18b8a2e8146169ea0d803f821e335b81a9a041d80295ecb788ccdabd4dd900f59d71094572d22aa31b282ba12723e7740ea42a13d26e6bf1d6bbf468c6784b1bf0405780b309a8d42edb13621970d74afbc0975c4b7bbcee5350f53a65e601000c00040000c28bff2cbe3bea5459b1301b91f0de47d5f4838e60fb540fc3d6e39f3d0d29121700d01510f94c64b53b"); }); }); describe('hw_dot small transaction building tests', () => { it('Should build unsigned DOT transaction with small amount correctly' , () => { expect(buildTransaction({from: "5DABfyrZYXfKiZr2U8hhfCb2Weq4EWScZ9jPupXxsibP8pcT", to: "5GTnjZBoHBp1KU5S534DDrPGgaXpiiWHpbVwgeqFTeuqz5wX", amount:"0.000000000001", nonce: "3", fee: "0.015534", tip:"0", net: Network.Testnet}).toString('hex')) .to.equal("29010400306a18b8a2e8146169ea0d803f821e335b81a9a041d80295ecb788ccdabd4dd900000c00040000c28bff2cbe3bea5459b1301b91f0de47d5f4838e60fb540fc3d6e39f3d0d291204"); }); const signature = hexToBytes("f59d71094572d22aa31b282ba12723e7740ea42a13d26e6bf1d6bbf468c6784b1bf0405780b309a8d42edb13621970d74afbc0975c4b7bbcee5350f53a65e601"); it('Should build signed DOT transaction with small amount correctly' , () => { expect(buildTransaction({from: "5DABfyrZYXfKiZr2U8hhfCb2Weq4EWScZ9jPupXxsibP8pcT", to: "5GTnjZBoHBp1KU5S534DDrPGgaXpiiWHpbVwgeqFTeuqz5wX", amount:"0.000000000001", nonce: "3", fee: "0.015534", tip:"0", net: Network.Testnet, signature: signature}).toString('hex')) .to.equal("29028400306a18b8a2e8146169ea0d803f821e335b81a9a041d80295ecb788ccdabd4dd900f59d71094572d22aa31b282ba12723e7740ea42a13d26e6bf1d6bbf468c6784b1bf0405780b309a8d42edb13621970d74afbc0975c4b7bbcee5350f53a65e601000c00040000c28bff2cbe3bea5459b1301b91f0de47d5f4838e60fb540fc3d6e39f3d0d291204"); }); });