import { buildTransaction, getCurrentTimestamp, getHolaParameters, verifyAddress } from "."; import * as mocha from 'mocha'; import * as chai from 'chai'; const expect = chai.expect; describe('hw_ardr address verification tests', () => { it('Should verify NXT address correctly' , () => { expect(verifyAddress("NXT-TVHV-39MC-35NK-B2JE3")) .to.equal(true); }); it('Should fail verify NXT address correctly' , () => { expect(verifyAddress("NXT-TVHV-39MI-35NK-B2JE3")) .to.equal(false); }); it('Should fail verify NXT address correctly' , () => { expect(verifyAddress("NXT-TVHV-39MC-35NK-B2JE37")) .to.equal(false); }); it('Should fail verify NXT address correctly' , () => { expect(verifyAddress("NXT-TVHV-39MC-35NK-")) .to.equal(false); }); }); describe('hw_nxt transaction building tests', () => { it('Should build unsigned NXT transaction correctly' , () => { expect(buildTransaction({recipientID: "2313571441833823888", amount: "2", fees: "1", blockData: {blockheight: '3423084', ecBlockID: "11334766886302577940"}, timestamp: 242857214}).toString('hex')) .to.equal("0010feb4790e0f000000000000000000000000000000000000000000000000000000000000000000904efef0f7741b2000c2eb0b0000000000e1f50500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006c3b340014f5eccd6d2e4d9d"); }); let publicKey = hexToBytes("a719cdf4e91f81662df51b54d04c97bef0ba2a83551c31287a053c5cb4a24447"); let sign = hexToBytes("0baa6d962e30757a1a772d0190d8e2b6c772897e5b02f94f70cdb9138927380e14a0bf9db633f6ce23f27ef60aedf33d828cc15929e10b0d9da56e413c729e2d"); it('Should build signed NXT transaction correctly' , () => { expect(buildTransaction({recipientID: "2313571441833823888", amount: "2", fees: "1", blockData: {blockheight: '3423084', ecBlockID: "11334766886302577940"}, senderPublicKey: publicKey, signature: sign, timestamp: 242857214}).toString('hex')) .to.equal("0010feb4790e0f00a719cdf4e91f81662df51b54d04c97bef0ba2a83551c31287a053c5cb4a24447904efef0f7741b2000c2eb0b0000000000e1f5050000000000000000000000000000000000000000000000000000000000000000000000000baa6d962e30757a1a772d0190d8e2b6c772897e5b02f94f70cdb9138927380e14a0bf9db633f6ce23f27ef60aedf33d828cc15929e10b0d9da56e413c729e2d000000006c3b340014f5eccd6d2e4d9d"); }); }); describe('hw_nxt HOLa parameters generation tests', () => { it('Should generate HOLa parameters correctly' , () => { let parameters = getHolaParameters({recipientID: "2313571441833823888", amount: "2", fees: "1", blockData: {blockheight: '3423084', ecBlockID: "11334766886302577940"}, timestamp: 242858011}); let correctBlkData = ["00101bb8790e0f00","904efef0f7741b2000c2eb0b0000000000e1f50500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006c3b340014f5eccd6d2e4d9d"]; let blkCont = 0; for(let blk of parameters.blk){ expect(blk.toString('hex')).to.equal(correctBlkData[blkCont]); blkCont++; } }); }); describe('hw_nxt big transaction building tests', () => { it('Should build unsigned NXT transaction with big amount correctly' , () => { expect(buildTransaction({recipientID: "2313571441833823888", amount: "998999941.51", fees: "1", blockData: {blockheight: '3423084', ecBlockID: "11334766886302577940"}, timestamp: 243467953}).toString('hex')) .to.equal("0010b106830e0f000000000000000000000000000000000000000000000000000000000000000000904efef0f7741b20c0176ff083ea620100e1f50500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006c3b340014f5eccd6d2e4d9d"); }); let publicKey = hexToBytes("a719cdf4e91f81662df51b54d04c97bef0ba2a83551c31287a053c5cb4a24447"); let sign = hexToBytes("0baa6d962e30757a1a772d0190d8e2b6c772897e5b02f94f70cdb9138927380e14a0bf9db633f6ce23f27ef60aedf33d828cc15929e10b0d9da56e413c729e2d"); it('Should build signed NXT transaction with big amount correctly' , () => { expect(buildTransaction({recipientID: "2313571441833823888", amount: "998999941.51", fees: "1", blockData: {blockheight: '3423084', ecBlockID: "11334766886302577940"}, senderPublicKey: publicKey, signature: sign, timestamp: 243467953}).toString('hex')) .to.equal("0010b106830e0f00a719cdf4e91f81662df51b54d04c97bef0ba2a83551c31287a053c5cb4a24447904efef0f7741b20c0176ff083ea620100e1f5050000000000000000000000000000000000000000000000000000000000000000000000000baa6d962e30757a1a772d0190d8e2b6c772897e5b02f94f70cdb9138927380e14a0bf9db633f6ce23f27ef60aedf33d828cc15929e10b0d9da56e413c729e2d000000006c3b340014f5eccd6d2e4d9d"); }); }); describe('hw_nxt small transaction building tests', () => { it('Should build unsigned NXT transaction with big amount correctly' , () => { expect(buildTransaction({recipientID: "2313571441833823888", amount: "0.00000001", fees: "1", blockData: {blockheight: '3423084', ecBlockID: "11334766886302577940"}, timestamp: 243550338}).toString('hex')) .to.equal("00108248840e0f000000000000000000000000000000000000000000000000000000000000000000904efef0f7741b20010000000000000000e1f50500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006c3b340014f5eccd6d2e4d9d"); }); let publicKey = hexToBytes("a719cdf4e91f81662df51b54d04c97bef0ba2a83551c31287a053c5cb4a24447"); let sign = hexToBytes("0baa6d962e30757a1a772d0190d8e2b6c772897e5b02f94f70cdb9138927380e14a0bf9db633f6ce23f27ef60aedf33d828cc15929e10b0d9da56e413c729e2d"); it('Should build signed NXT transaction with big amount correctly' , () => { expect(buildTransaction({recipientID: "2313571441833823888", amount: "0.00000001", fees: "1", blockData: {blockheight: '3423084', ecBlockID: "11334766886302577940"}, senderPublicKey: publicKey, signature: sign, timestamp: 243550338}).toString('hex')) .to.equal("00108248840e0f00a719cdf4e91f81662df51b54d04c97bef0ba2a83551c31287a053c5cb4a24447904efef0f7741b20010000000000000000e1f5050000000000000000000000000000000000000000000000000000000000000000000000000baa6d962e30757a1a772d0190d8e2b6c772897e5b02f94f70cdb9138927380e14a0bf9db633f6ce23f27ef60aedf33d828cc15929e10b0d9da56e413c729e2d000000006c3b340014f5eccd6d2e4d9d"); }); }); function hexToBytes(hex: string) : Buffer{ // for (var bytes = [], c = 0; c < hex.length; c += 2) // bytes.push(parseInt(hex.substr(c, 2), 16)); // return Buffer.from(bytes); return Buffer.from(hex, "hex"); }