import { buildTransaction, generateAddress, getaccountId, getCurrentTimestamp, getHolaParameters, verifyAddress } from "."; import * as mocha from 'mocha'; import * as chai from 'chai'; import { Network } from "./types"; const expect = chai.expect; describe('hw_ardr accountId generation tests', () => { it('Should generate ARDOR accountId correctly' , () => { expect(getaccountId(Buffer.from("feb823bac150e799fbfc124564d4c1a72b920ec26ce11a07e3efda51ca9a425f", "hex"))) .to.equal("11551286933940986965"); }); it('Should generate ARDOR accountId correctly' , () => { expect(getaccountId(Buffer.from("2456c3f852b6116c7af0fa75292c721898fd914d2206e0906b2d7f58a4b02576", "hex"))) .to.equal("6615231097176472778"); }); }); describe('hw_ardr address encoding tests', () => { it('Should encode ARDOR address correctly' , () => { expect(generateAddress(Buffer.from("feb823bac150e799fbfc124564d4c1a72b920ec26ce11a07e3efda51ca9a425f", "hex"))) .to.equal("ARDOR-MT4P-AHG4-A4NA-CCMM2"); }); it('Should encode ARDOR address correctly' , () => { expect(generateAddress(Buffer.from("1fa6178a907846f6b3b4af988869d65549747fa27b1ce057b08676ddee72b94e", "hex"))) .to.equal("ARDOR-ACAV-H58U-CM3J-2LFJ2"); }); }); describe('hw_ardr address verification tests', () => { it('Should verify ARDOR address correctly' , () => { expect(verifyAddress("ARDOR-TVHV-39MC-35NK-B2JE3")) .to.equal(true); }); it('Should fail verify ARDOR address correctly' , () => { expect(verifyAddress("ARDOR-TVHV-39MI-35NK-B2JE3")) .to.equal(false); }); it('Should fail verify ARDOR address correctly' , () => { expect(verifyAddress("ARDOR-TVHV-39MC-35NK-B2JE37")) .to.equal(false); }); it('Should fail verify ARDOR address correctly' , () => { expect(verifyAddress("ARDOR-TVHV-39MC-35NK-")) .to.equal(false); }); }); describe('hw_ardr transaction building tests', () => { it('Should build unsigned ARDOR transaction correctly' , () => { expect(buildTransaction({recipientID: "14323656705617210936", amount: "10", fees: "2", blockData: {blockheight: "7568700", ecBlockID: "13955905241799441184"}, timestamp: 113317081, isIgnisTx:false}).toString('hex')) .to.equal("01000000fe0001d914c1060f00000000000000000000000000000000000000000000000000000000000000000038aef43ee2d9c7c600ca9a3b0000000000c2eb0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003c7d730020bb7738e055adc100000000"); }); let publicKey = hexToBytes("013f303df80c7776316047db9f8d8b8bb772c0bef271012ebc2d037ab4dab20e"); let sign = hexToBytes("f39c2d6238102756798adda06a95e7b331fd6e479240771478d63e37e85eda00f421f60907be00e27ce1e10af2e3625ab78cf8181d013e2f39b22919abd19977"); it('Should build signed ARDOR transaction correctly' , () => { expect(buildTransaction({recipientID: "14323656705617210936", amount: "10", fees: "2", blockData: {blockheight: '7568700', ecBlockID: "13955905241799441184"}, senderPublicKey: publicKey, signature: sign, timestamp: 113321241, isIgnisTx:false}).toString('hex')) .to.equal("01000000fe00011925c1060f00013f303df80c7776316047db9f8d8b8bb772c0bef271012ebc2d037ab4dab20e38aef43ee2d9c7c600ca9a3b0000000000c2eb0b00000000f39c2d6238102756798adda06a95e7b331fd6e479240771478d63e37e85eda00f421f60907be00e27ce1e10af2e3625ab78cf8181d013e2f39b22919abd199773c7d730020bb7738e055adc100000000"); }); }); describe('hw_ardr transaction building tests (IGNIS)', () => { it('Should build unsigned ARDOR transaction correctly' , () => { expect(buildTransaction({recipientID: "14323656705617210936", amount: "10", fees: "2", blockData: {blockheight: "7568700", ecBlockID: "13955905241799441184"}, timestamp: 113317081, isIgnisTx:true}).toString('hex')) .to.equal("02000000000001d914c1060f00000000000000000000000000000000000000000000000000000000000000000038aef43ee2d9c7c600ca9a3b0000000000c2eb0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003c7d730020bb7738e055adc100000000000000000000000000000000000000000000000000000000000000000000000000000000"); }); let publicKey = hexToBytes("013f303df80c7776316047db9f8d8b8bb772c0bef271012ebc2d037ab4dab20e"); let sign = hexToBytes("f39c2d6238102756798adda06a95e7b331fd6e479240771478d63e37e85eda00f421f60907be00e27ce1e10af2e3625ab78cf8181d013e2f39b22919abd19977"); it('Should build signed ARDOR transaction correctly' , () => { expect(buildTransaction({recipientID: "14323656705617210936", amount: "10", fees: "2", blockData: {blockheight: '7568700', ecBlockID: "13955905241799441184"}, senderPublicKey: publicKey, signature: sign, timestamp: 113321241, isIgnisTx:true}).toString('hex')) .to.equal("020000000000011925c1060f00013f303df80c7776316047db9f8d8b8bb772c0bef271012ebc2d037ab4dab20e38aef43ee2d9c7c600ca9a3b0000000000c2eb0b00000000f39c2d6238102756798adda06a95e7b331fd6e479240771478d63e37e85eda00f421f60907be00e27ce1e10af2e3625ab78cf8181d013e2f39b22919abd199773c7d730020bb7738e055adc100000000000000000000000000000000000000000000000000000000000000000000000000000000"); }); }); describe('hw_ardr HOLa parameters generation tests', () => { it('Should generate HOLa parameters correctly' , () => { let parameters = getHolaParameters({recipientID: "14323656705617210936", amount: "10", fees: "2", blockData: {blockheight: '7568700', ecBlockID: "13955905241799441184"}, timestamp: 113383560, isIgnisTx:false}); let correctBlkData = ["01000000fe00018818c2060f00","38aef43ee2d9c7c600ca9a3b0000000000c2eb0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003c7d730020bb7738e055adc100000000"]; let blkCont = 0; for(let blk of parameters.blk){ expect(blk.toString('hex')).to.equal(correctBlkData[blkCont]); blkCont++; } }); }); describe('hw_ardr big transaction building tests', () => { it('Should build unsigned ARDOR transaction with big amount correctly' , () => { expect(buildTransaction({recipientID: "14323656705617210936", amount: "998999495", fees: "2", blockData: {blockheight: '7568700', ecBlockID: "13955905241799441184"}, timestamp: 113997222, isIgnisTx:false}).toString('hex')) .to.equal("01000000fe0001a675cb060f00000000000000000000000000000000000000000000000000000000000000000038aef43ee2d9c7c600e7068b79ea620100c2eb0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003c7d730020bb7738e055adc100000000"); }); let publicKey = hexToBytes("013f303df80c7776316047db9f8d8b8bb772c0bef271012ebc2d037ab4dab20e"); let sign = hexToBytes("f39c2d6238102756798adda06a95e7b331fd6e479240771478d63e37e85eda00f421f60907be00e27ce1e10af2e3625ab78cf8181d013e2f39b22919abd19977"); it('Should build signed ARDOR transaction with big amount correctly' , () => { expect(buildTransaction({recipientID: "14323656705617210936", amount: "998999495", fees: "2", blockData: {blockheight: '7568700', ecBlockID: "13955905241799441184"}, senderPublicKey: publicKey, signature: sign, timestamp: 113997222, isIgnisTx:false}).toString('hex')) .to.equal("01000000fe0001a675cb060f00013f303df80c7776316047db9f8d8b8bb772c0bef271012ebc2d037ab4dab20e38aef43ee2d9c7c600e7068b79ea620100c2eb0b00000000f39c2d6238102756798adda06a95e7b331fd6e479240771478d63e37e85eda00f421f60907be00e27ce1e10af2e3625ab78cf8181d013e2f39b22919abd199773c7d730020bb7738e055adc100000000"); }); }); describe('hw_ardr small transaction building tests', () => { it('Should build unsigned ARDOR transaction with small amount correctly' , () => { expect(buildTransaction({recipientID: "14323656705617210936", amount: "0.00000001", fees: "2", blockData: {blockheight: '7568700', ecBlockID: "13955905241799441184"}, timestamp: 114079410, isIgnisTx:false}).toString('hex')) .to.equal("01000000fe0001b2b6cc060f00000000000000000000000000000000000000000000000000000000000000000038aef43ee2d9c7c6010000000000000000c2eb0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003c7d730020bb7738e055adc100000000"); }); let publicKey = hexToBytes("013f303df80c7776316047db9f8d8b8bb772c0bef271012ebc2d037ab4dab20e"); let sign = hexToBytes("f39c2d6238102756798adda06a95e7b331fd6e479240771478d63e37e85eda00f421f60907be00e27ce1e10af2e3625ab78cf8181d013e2f39b22919abd19977"); it('Should build signed ARDOR transaction with small amount correctly' , () => { expect(buildTransaction({recipientID: "14323656705617210936", amount: "0.00000001", fees: "2", blockData: {blockheight: '7568700', ecBlockID: "13955905241799441184"}, senderPublicKey: publicKey, signature: sign, timestamp: 114079410, isIgnisTx:false}).toString('hex')) .to.equal("01000000fe0001b2b6cc060f00013f303df80c7776316047db9f8d8b8bb772c0bef271012ebc2d037ab4dab20e38aef43ee2d9c7c6010000000000000000c2eb0b00000000f39c2d6238102756798adda06a95e7b331fd6e479240771478d63e37e85eda00f421f60907be00e27ce1e10af2e3625ab78cf8181d013e2f39b22919abd199773c7d730020bb7738e055adc100000000"); }); }); 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"); }