import { buildTransaction, buildFreezeBalanceTransaction, buildUnfreezeBalanceTransaction, getHolaParameters, extractSignature, verifyAddress, getHolaParameters_Link, buildWithdrawBalanceTransaction, buildVoteWitnessTransaction, buildWithdrawExpiredUnfreezeTransaction, buildTRC10Transaction, buildTRC20Transaction } from "."; import { hexToBytes } from "./TransactionHelper"; import * as mocha from 'mocha'; import * as chai from 'chai'; import { ResourceType } from "./types"; const expect = chai.expect; describe('hw_trx address verification tests', () => { it('Should verify trx address' , () => { expect(verifyAddress("TV7Pts9PaedUKFKEkGs7PJJn5LToSpzRHZ")) .to.equal(true); }); it('Should verify trx address' , () => { expect(verifyAddress("TV7Pts9PaedUKFKEkGs7PJJn5LToSpzRHZ")) .to.equal(true); }); it('Should fail verify trx address' , () => { expect(verifyAddress("TV7Pts9PaedUKFKEkGs7PJJnSLToSpzRHZ")) .to.equal(false); }); }); describe('hw_trx transaction building tests', () => { it('Should build unsigned Tron transaction correctly' , () => { expect(buildTransaction({from: "TV7Pts9PaedUKFKEkGs7PJJn5LToSpzRHZ", to: "TG6vpPN87HYVd9GSQiGtd27Ah9xAYFw6z9", amount: "0.1", fees: "0.1", timestamp: 1622445973395, block: {ref_block_hash: "0000000000ea8727d50d54d96109b181ea5a758934c73826f7666ad783cabe83", ref_block_height: 15370023, ref_block_timestamp:1622445903000 }}).toString('hex')) .to.equal("0a0287272208d50d54d96109b1814098f69a8c9c2f5a67080112630a2d747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e5472616e73666572436f6e747261637412320a1541d1f6cf8f75444b86325a17429d747806b4a0a11f1215414346929a36348d216bcabe2bb8a627366a556c8118a08d067093bfc38a9c2f"); }); const signature = hexToBytes("1CF08881A5CD0381FF47F7ADC5EF609A3188A704C0E1687C4FAAD1B43D5AA57A1AE51DDD01972542E07526D46DAED92EE097335303FEA79EB64B833B831F585200"); it('Should build signed Tron transaction correctly' , () => { expect(buildTransaction({from: "TV7Pts9PaedUKFKEkGs7PJJn5LToSpzRHZ", to: "TG6vpPN87HYVd9GSQiGtd27Ah9xAYFw6z9", amount: "0.1", fees: "0.1", timestamp: 1622445973395, block: {ref_block_hash: "0000000000ea8727d50d54d96109b181ea5a758934c73826f7666ad783cabe83", ref_block_height: 15370023, ref_block_timestamp:1622445903000 }, signature: signature}).toString('hex')) .to.equal("0a85010a0287272208d50d54d96109b1814098f69a8c9c2f5a67080112630a2d747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e5472616e73666572436f6e747261637412320a1541d1f6cf8f75444b86325a17429d747806b4a0a11f1215414346929a36348d216bcabe2bb8a627366a556c8118a08d067093bfc38a9c2f12411cf08881a5cd0381ff47f7adc5ef609a3188a704c0e1687c4faad1b43d5aa57a1ae51ddd01972542e07526d46daed92ee097335303fea79eb64b833b831f585200"); }); }); describe('hw_trx TRC10 transaction building tests', () => { it('Should build unsigned TRC10 Tron transaction correctly' , () => { expect(buildTRC10Transaction({from: "TWRt4RDCfB8nnWAPwmsVi5XyXW84zm25vx", to: "TCvDg5vXUGoJDFSChbnGfCVAaA6WNjapbb", amount: "580", fees: "0.1", timestamp: 1653160990762, assetDecimals: 0, assetName: "1001156", block: {ref_block_hash: "0000000000ea8727d50d54d96109b181ea5a758934c73826f7666ad783cabe83", ref_block_height: 15370023, ref_block_timestamp:1622445903000 }}).toString('hex')) .to.equal("0a0287272208d50d54d96109b1814098f69a8c9c2f5a74080212700a32747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e5472616e736665724173736574436f6e7472616374123a0a0731303031313536121541e06def414a55ea6cac09ea092b6aa35fe1191c891a15412057b0ef65df72fffb21e4db2c5063021a4ac39120c40470aab0cbc08e30"); }); const signature = hexToBytes("1CF08881A5CD0381FF47F7ADC5EF609A3188A704C0E1687C4FAAD1B43D5AA57A1AE51DDD01972542E07526D46DAED92EE097335303FEA79EB64B833B831F585200"); it('Should build signed TRC10 Tron transaction correctly' , () => { expect(buildTRC10Transaction({from: "TWRt4RDCfB8nnWAPwmsVi5XyXW84zm25vx", to: "TCvDg5vXUGoJDFSChbnGfCVAaA6WNjapbb", amount: "580", fees: "0.1", timestamp: 1653160990762, assetDecimals: 0, assetName: "1001156", block: {ref_block_hash: "0000000000ea8727d50d54d96109b181ea5a758934c73826f7666ad783cabe83", ref_block_height: 15370023, ref_block_timestamp:1622445903000 }, signature: signature}).toString('hex')) .to.equal("0a92010a0287272208d50d54d96109b1814098f69a8c9c2f5a74080212700a32747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e5472616e736665724173736574436f6e7472616374123a0a0731303031313536121541e06def414a55ea6cac09ea092b6aa35fe1191c891a15412057b0ef65df72fffb21e4db2c5063021a4ac39120c40470aab0cbc08e3012411cf08881a5cd0381ff47f7adc5ef609a3188a704c0e1687c4faad1b43d5aa57a1ae51ddd01972542e07526d46daed92ee097335303fea79eb64b833b831f585200"); }); }); describe('hw_trx TRC20 transaction building tests', () => { it('Should build unsigned TRC20 Tron transaction correctly' , () => { expect(buildTRC20Transaction({from: "TC8sAwQKLfNnEPPZQEHqqYR4zKZbC1GpSH", to: "TPjZUaK8E8aUH9y4dVpKZ5ndi7CP7RWo3e", amount: "200", fee_limit: 90, timestamp: 1686825058903, assetDecimals: 6, contractAddress: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t", block: {ref_block_hash: "0000000000ea8727d50d54d96109b181ea5a758934c73826f7666ad783cabe83", ref_block_height: 15370023, ref_block_timestamp:1622445903000 }}).toString('hex')) .to.equal("0a0287272208d50d54d96109b1814098f69a8c9c2f5aae01081f12a9010a31747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e54726967676572536d617274436f6e747261637412740a154117c3dbb44ab8e84c82f239c9014f68776bf72448121541a614f803b6fd780986a42c78ec9c7f77e6ded13c2244a9059cbb00000000000000000000000096fd07583e07f124cc048ab5fd88011993011315000000000000000000000000000000000000000000000000000000000bebc20070d784eff48b3190018095f52a"); }); const signature = hexToBytes("1CF08881A5CD0381FF47F7ADC5EF609A3188A704C0E1687C4FAAD1B43D5AA57A1AE51DDD01972542E07526D46DAED92EE097335303FEA79EB64B833B831F585200"); it('Should build signed TRC20 Tron transaction correctly' , () => { expect(buildTRC20Transaction({from: "TC8sAwQKLfNnEPPZQEHqqYR4zKZbC1GpSH", to: "TPjZUaK8E8aUH9y4dVpKZ5ndi7CP7RWo3e", amount: "200", fee_limit: 90, timestamp: 1686825058903, assetDecimals: 6, contractAddress: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t", block: {ref_block_hash: "0000000000ea8727d50d54d96109b181ea5a758934c73826f7666ad783cabe83", ref_block_height: 15370023, ref_block_timestamp:1622445903000 }, signature: signature}).toString('hex')) .to.equal("0ad3010a0287272208d50d54d96109b1814098f69a8c9c2f5aae01081f12a9010a31747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e54726967676572536d617274436f6e747261637412740a154117c3dbb44ab8e84c82f239c9014f68776bf72448121541a614f803b6fd780986a42c78ec9c7f77e6ded13c2244a9059cbb00000000000000000000000096fd07583e07f124cc048ab5fd88011993011315000000000000000000000000000000000000000000000000000000000bebc20070d784eff48b3190018095f52a12411cf08881a5cd0381ff47f7adc5ef609a3188a704c0e1687c4faad1b43d5aa57a1ae51ddd01972542e07526d46daed92ee097335303fea79eb64b833b831f585200"); }); }); describe('hw_trx freeze transaction (Energy) building tests', () => { it('Should build unsigned Tron freeze transaction (Energy) correctly' , () => { expect(buildFreezeBalanceTransaction({from: "TV7Pts9PaedUKFKEkGs7PJJn5LToSpzRHZ", amount: "70", fees: "0.1", timestamp: 1622445973395, block: {ref_block_hash: "0000000000ea8727d50d54d96109b181ea5a758934c73826f7666ad783cabe83", ref_block_height: 15370023, ref_block_timestamp:1622445903000 }, resourceType: ResourceType.Energy}).toString('hex')) .to.equal("0a0287272208d50d54d96109b1814098f69a8c9c2f5a5a083612560a34747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e467265657a6542616c616e63655632436f6e7472616374121e0a1541d1f6cf8f75444b86325a17429d747806b4a0a11f1080bbb02118017093bfc38a9c2f"); }); const signature = hexToBytes("1CF08881A5CD0381FF47F7ADC5EF609A3188A704C0E1687C4FAAD1B43D5AA57A1AE51DDD01972542E07526D46DAED92EE097335303FEA79EB64B833B831F585200"); it('Should build signed Tron freeze transaction (Energy) correctly' , () => { expect(buildFreezeBalanceTransaction({from: "TV7Pts9PaedUKFKEkGs7PJJn5LToSpzRHZ", amount: "70", fees: "0.1", timestamp: 1622445973395, block: {ref_block_hash: "0000000000ea8727d50d54d96109b181ea5a758934c73826f7666ad783cabe83", ref_block_height: 15370023, ref_block_timestamp:1622445903000 }, signature: signature, resourceType: ResourceType.Energy}).toString('hex')) .to.equal("0a780a0287272208d50d54d96109b1814098f69a8c9c2f5a5a083612560a34747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e467265657a6542616c616e63655632436f6e7472616374121e0a1541d1f6cf8f75444b86325a17429d747806b4a0a11f1080bbb02118017093bfc38a9c2f12411cf08881a5cd0381ff47f7adc5ef609a3188a704c0e1687c4faad1b43d5aa57a1ae51ddd01972542e07526d46daed92ee097335303fea79eb64b833b831f585200"); }); }); describe('hw_trx freeze transaction (Bandwidth) building tests', () => { it('Should build unsigned Tron freeze transaction (Bandwidth) correctly' , () => { expect(buildFreezeBalanceTransaction({from: "TV7Pts9PaedUKFKEkGs7PJJn5LToSpzRHZ", amount: "70", fees: "0.1", timestamp: 1622445973395, block: {ref_block_hash: "0000000000ea8727d50d54d96109b181ea5a758934c73826f7666ad783cabe83", ref_block_height: 15370023, ref_block_timestamp:1622445903000 }, resourceType: ResourceType.Bandwidth}).toString('hex')) .to.equal("0a0287272208d50d54d96109b1814098f69a8c9c2f5a58083612540a34747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e467265657a6542616c616e63655632436f6e7472616374121c0a1541d1f6cf8f75444b86325a17429d747806b4a0a11f1080bbb0217093bfc38a9c2f"); }); const signature = hexToBytes("1CF08881A5CD0381FF47F7ADC5EF609A3188A704C0E1687C4FAAD1B43D5AA57A1AE51DDD01972542E07526D46DAED92EE097335303FEA79EB64B833B831F585200"); it('Should build signed Tron freeze transaction (Bandwidth) correctly' , () => { expect(buildFreezeBalanceTransaction({from: "TV7Pts9PaedUKFKEkGs7PJJn5LToSpzRHZ", amount: "70", fees: "0.1", timestamp: 1622445973395, block: {ref_block_hash: "0000000000ea8727d50d54d96109b181ea5a758934c73826f7666ad783cabe83", ref_block_height: 15370023, ref_block_timestamp:1622445903000 }, signature: signature, resourceType: ResourceType.Bandwidth}).toString('hex')) .to.equal("0a760a0287272208d50d54d96109b1814098f69a8c9c2f5a58083612540a34747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e467265657a6542616c616e63655632436f6e7472616374121c0a1541d1f6cf8f75444b86325a17429d747806b4a0a11f1080bbb0217093bfc38a9c2f12411cf08881a5cd0381ff47f7adc5ef609a3188a704c0e1687c4faad1b43d5aa57a1ae51ddd01972542e07526d46daed92ee097335303fea79eb64b833b831f585200"); }); }); describe('hw_trx unfreeze transaction (Energy) building tests', () => { it('Should build unsigned Tron unfreeze transaction (Energy) correctly' , () => { expect(buildUnfreezeBalanceTransaction({from: "TV7Pts9PaedUKFKEkGs7PJJn5LToSpzRHZ", amount: "2", fees: "0.1", timestamp: 1622445973395, block: {ref_block_hash: "0000000000ea8727d50d54d96109b181ea5a758934c73826f7666ad783cabe83", ref_block_height: 15370023, ref_block_timestamp:1622445903000 }, resourceType: ResourceType.Energy}).toString('hex')) .to.equal("0a0287272208d50d54d96109b1814098f69a8c9c2f5a5b083712570a36747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e556e667265657a6542616c616e63655632436f6e7472616374121d0a1541d1f6cf8f75444b86325a17429d747806b4a0a11f1080897a18017093bfc38a9c2f"); }); const signature = hexToBytes("1CF08881A5CD0381FF47F7ADC5EF609A3188A704C0E1687C4FAAD1B43D5AA57A1AE51DDD01972542E07526D46DAED92EE097335303FEA79EB64B833B831F585200"); it('Should build signed Tron unfreeze transaction (Energy) correctly' , () => { expect(buildUnfreezeBalanceTransaction({from: "TV7Pts9PaedUKFKEkGs7PJJn5LToSpzRHZ", amount: "5", fees: "0.1", timestamp: 1622445973395, block: {ref_block_hash: "0000000000ea8727d50d54d96109b181ea5a758934c73826f7666ad783cabe83", ref_block_height: 15370023, ref_block_timestamp:1622445903000 }, signature: signature, resourceType: ResourceType.Energy}).toString('hex')) .to.equal("0a7a0a0287272208d50d54d96109b1814098f69a8c9c2f5a5c083712580a36747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e556e667265657a6542616c616e63655632436f6e7472616374121e0a1541d1f6cf8f75444b86325a17429d747806b4a0a11f10c096b10218017093bfc38a9c2f12411cf08881a5cd0381ff47f7adc5ef609a3188a704c0e1687c4faad1b43d5aa57a1ae51ddd01972542e07526d46daed92ee097335303fea79eb64b833b831f585200"); }); }); describe('hw_trx unfreeze transaction (Bandwidth) building tests', () => { it('Should build unsigned Tron unfreeze transaction (Bandwidth) correctly' , () => { expect(buildUnfreezeBalanceTransaction({from: "TV7Pts9PaedUKFKEkGs7PJJn5LToSpzRHZ", amount: "5", fees: "0.1", timestamp: 1622445973395, block: {ref_block_hash: "0000000000ea8727d50d54d96109b181ea5a758934c73826f7666ad783cabe83", ref_block_height: 15370023, ref_block_timestamp:1622445903000 }, resourceType: ResourceType.Bandwidth}).toString('hex')) .to.equal("0a0287272208d50d54d96109b1814098f69a8c9c2f5a5a083712560a36747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e556e667265657a6542616c616e63655632436f6e7472616374121c0a1541d1f6cf8f75444b86325a17429d747806b4a0a11f10c096b1027093bfc38a9c2f"); }); const signature = hexToBytes("1CF08881A5CD0381FF47F7ADC5EF609A3188A704C0E1687C4FAAD1B43D5AA57A1AE51DDD01972542E07526D46DAED92EE097335303FEA79EB64B833B831F585200"); it('Should build signed Tron unfreeze transaction (Bandwidth) correctly' , () => { expect(buildUnfreezeBalanceTransaction({from: "TV7Pts9PaedUKFKEkGs7PJJn5LToSpzRHZ", amount: "5", fees: "0.1", timestamp: 1622445973395, block: {ref_block_hash: "0000000000ea8727d50d54d96109b181ea5a758934c73826f7666ad783cabe83", ref_block_height: 15370023, ref_block_timestamp:1622445903000 }, signature: signature, resourceType: ResourceType.Bandwidth}).toString('hex')) .to.equal("0a780a0287272208d50d54d96109b1814098f69a8c9c2f5a5a083712560a36747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e556e667265657a6542616c616e63655632436f6e7472616374121c0a1541d1f6cf8f75444b86325a17429d747806b4a0a11f10c096b1027093bfc38a9c2f12411cf08881a5cd0381ff47f7adc5ef609a3188a704c0e1687c4faad1b43d5aa57a1ae51ddd01972542e07526d46daed92ee097335303fea79eb64b833b831f585200"); }); }); describe('hw_trx withdraw transaction building tests', () => { it('Should build unsigned Tron withdraw transaction correctly' , () => { expect(buildWithdrawBalanceTransaction({from: "TV7Pts9PaedUKFKEkGs7PJJn5LToSpzRHZ", fees: "0.1", timestamp: 1622445973395, block: {ref_block_hash: "0000000000ea8727d50d54d96109b181ea5a758934c73826f7666ad783cabe83", ref_block_height: 15370023, ref_block_timestamp:1622445903000 }}).toString('hex')) .to.equal("0a0287272208d50d54d96109b1814098f69a8c9c2f5a53080d124f0a34747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e576974686472617742616c616e6365436f6e747261637412170a1541d1f6cf8f75444b86325a17429d747806b4a0a11f7093bfc38a9c2f"); }); const signature = hexToBytes("1CF08881A5CD0381FF47F7ADC5EF609A3188A704C0E1687C4FAAD1B43D5AA57A1AE51DDD01972542E07526D46DAED92EE097335303FEA79EB64B833B831F585200"); it('Should build signed Tron withdraw transaction correctly' , () => { expect(buildWithdrawBalanceTransaction({from: "TV7Pts9PaedUKFKEkGs7PJJn5LToSpzRHZ", fees: "0.1", timestamp: 1622445973395, block: {ref_block_hash: "0000000000ea8727d50d54d96109b181ea5a758934c73826f7666ad783cabe83", ref_block_height: 15370023, ref_block_timestamp:1622445903000 }, signature: signature}).toString('hex')) .to.equal("0a710a0287272208d50d54d96109b1814098f69a8c9c2f5a53080d124f0a34747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e576974686472617742616c616e6365436f6e747261637412170a1541d1f6cf8f75444b86325a17429d747806b4a0a11f7093bfc38a9c2f12411cf08881a5cd0381ff47f7adc5ef609a3188a704c0e1687c4faad1b43d5aa57a1ae51ddd01972542e07526d46daed92ee097335303fea79eb64b833b831f585200"); }); }); describe('hw_trx withdraw expired unfreeze transaction building tests', () => { it('Should build unsigned Tron withdraw expired unfreeze transaction correctly' , () => { expect(buildWithdrawExpiredUnfreezeTransaction({from: "TV7Pts9PaedUKFKEkGs7PJJn5LToSpzRHZ", fees: "0.1", timestamp: 1622445973395, block: {ref_block_hash: "0000000000ea8727d50d54d96109b181ea5a758934c73826f7666ad783cabe83", ref_block_height: 15370023, ref_block_timestamp:1622445903000 }}).toString('hex')) .to.equal("0a0287272208d50d54d96109b1814098f69a8c9c2f5a5a083812560a3b747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e5769746864726177457870697265556e667265657a65436f6e747261637412170a1541d1f6cf8f75444b86325a17429d747806b4a0a11f7093bfc38a9c2f"); }); const signature = hexToBytes("1CF08881A5CD0381FF47F7ADC5EF609A3188A704C0E1687C4FAAD1B43D5AA57A1AE51DDD01972542E07526D46DAED92EE097335303FEA79EB64B833B831F585200"); it('Should build signed Tron withdraw expired unfreeze transaction correctly' , () => { expect(buildWithdrawExpiredUnfreezeTransaction({from: "TV7Pts9PaedUKFKEkGs7PJJn5LToSpzRHZ", fees: "0.1", timestamp: 1622445973395, block: {ref_block_hash: "0000000000ea8727d50d54d96109b181ea5a758934c73826f7666ad783cabe83", ref_block_height: 15370023, ref_block_timestamp:1622445903000 }, signature: signature}).toString('hex')) .to.equal("0a780a0287272208d50d54d96109b1814098f69a8c9c2f5a5a083812560a3b747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e5769746864726177457870697265556e667265657a65436f6e747261637412170a1541d1f6cf8f75444b86325a17429d747806b4a0a11f7093bfc38a9c2f12411cf08881a5cd0381ff47f7adc5ef609a3188a704c0e1687c4faad1b43d5aa57a1ae51ddd01972542e07526d46daed92ee097335303fea79eb64b833b831f585200"); }); }); describe('hw_trx vote transaction building tests', () => { it('Should build unsigned Tron vote transaction correctly' , () => { expect(buildVoteWitnessTransaction({from: "TV7Pts9PaedUKFKEkGs7PJJn5LToSpzRHZ", fees: "0.1", timestamp: 1622445973395, block: {ref_block_hash: "0000000000ea8727d50d54d96109b181ea5a758934c73826f7666ad783cabe83", ref_block_height: 15370023, ref_block_timestamp:1622445903000 }, votes: [{vote_address: "TJBtdYunmQkeK5KninwgcjuK1RPDhyUWBZ", vote_number: 1000}, {vote_address: "TJBtdYunmQkeK5KninwgcjuK1RPDhyUWBZ", vote_number: 1000}]}).toString('hex')) .to.equal("0a0287272208d50d54d96109b1814098f69a8c9c2f5a880108041283010a30747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e566f74655769746e657373436f6e7472616374124f0a1541d1f6cf8f75444b86325a17429d747806b4a0a11f121a0a15415a27141dbd202aa1344c042b51ae541262eebfb710e807121a0a15415a27141dbd202aa1344c042b51ae541262eebfb710e8077093bfc38a9c2f"); }); const signature = hexToBytes("1CF08881A5CD0381FF47F7ADC5EF609A3188A704C0E1687C4FAAD1B43D5AA57A1AE51DDD01972542E07526D46DAED92EE097335303FEA79EB64B833B831F585200"); it('Should build signed Tron vote transaction correctly' , () => { expect(buildVoteWitnessTransaction({from: "TV7Pts9PaedUKFKEkGs7PJJn5LToSpzRHZ", fees: "0.1", timestamp: 1622445973395, block: {ref_block_hash: "0000000000ea8727d50d54d96109b181ea5a758934c73826f7666ad783cabe83", ref_block_height: 15370023, ref_block_timestamp:1622445903000 }, votes: [{vote_address: "TJBtdYunmQkeK5KninwgcjuK1RPDhyUWBZ", vote_number: 1000}, {vote_address: "TJBtdYunmQkeK5KninwgcjuK1RPDhyUWBZ", vote_number: 1000}] , signature: signature}).toString('hex')) .to.equal("0aa7010a0287272208d50d54d96109b1814098f69a8c9c2f5a880108041283010a30747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e566f74655769746e657373436f6e7472616374124f0a1541d1f6cf8f75444b86325a17429d747806b4a0a11f121a0a15415a27141dbd202aa1344c042b51ae541262eebfb710e807121a0a15415a27141dbd202aa1344c042b51ae541262eebfb710e8077093bfc38a9c2f12411cf08881a5cd0381ff47f7adc5ef609a3188a704c0e1687c4faad1b43d5aa57a1ae51ddd01972542e07526d46daed92ee097335303fea79eb64b833b831f585200"); }); }); describe('hw_trx HOLa parameters generation tests', () => { it('Should generate HOLa parameters correctly' , () => { let parameters = getHolaParameters({from: "TV7Pts9PaedUKFKEkGs7PJJn5LToSpzRHZ", to: "TG6vpPN87HYVd9GSQiGtd27Ah9xAYFw6z9", amount: "0.1", fees: "0.1", timestamp: 1622445973395, block: {ref_block_hash: "0000000000ea8727d50d54d96109b181ea5a758934c73826f7666ad783cabe83", ref_block_height: 15370023, ref_block_timestamp:1622445903000 }}); let correctBlkData = ["0a0287272208d50d54d96109b1814098f69a8c9c2f5a67080112630a2d747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e5472616e73666572436f6e74726163741232","0a1541d1f6cf8f75444b86325a17429d747806b4a0a11f1215414346929a36348d216bcabe2bb8a627366a556c8118a08d06","7093bfc38a9c2f", "00000000000186a0"]; let blkCont = 0; for(let blk of parameters.blk){ expect(blk.toString('hex')).to.equal(correctBlkData[blkCont]); blkCont++; } }); }); describe('hw_trx HOLa parameters generation tests (LINK)', () => { it('Should generate HOLa parameters correctly (LINK)' , () => { let parameters = getHolaParameters_Link({from: "TV7Pts9PaedUKFKEkGs7PJJn5LToSpzRHZ", to: "TG6vpPN87HYVd9GSQiGtd27Ah9xAYFw6z9", amount: "0.1", fees: "0.1", timestamp: 1622445973395, block: {ref_block_hash: "0000000000ea8727d50d54d96109b181ea5a758934c73826f7666ad783cabe83", ref_block_height: 15370023, ref_block_timestamp:1622445903000 }}); let correctBlkData = ["92a404c20378baf14f5293a464c0ec8aa3da8d5121bf783acdea5faa59559380"]; let blkCont = 0; for(let blk of parameters.blk){ expect(blk.toString('hex')).to.equal(correctBlkData[blkCont]); blkCont++; } }); }); describe('hw_trx big transaction building tests', () => { it('Should build unsigned Tron transaction with big amount correctly' , () => { expect(buildTransaction({from: "TV7Pts9PaedUKFKEkGs7PJJn5LToSpzRHZ", to: "TG6vpPN87HYVd9GSQiGtd27Ah9xAYFw6z9", amount: "100850743812", fees: "0.1", timestamp: 1622445973395, block: {ref_block_hash: "0000000000ea8727d50d54d96109b181ea5a758934c73826f7666ad783cabe83", ref_block_height: 15370023, ref_block_timestamp:1622445903000 }}).toString('hex')) .to.equal("0a0287272208d50d54d96109b1814098f69a8c9c2f5a6d080112690a2d747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e5472616e73666572436f6e747261637412380a1541d1f6cf8f75444b86325a17429d747806b4a0a11f1215414346929a36348d216bcabe2bb8a627366a556c81188092fec1f9e692b3017093bfc38a9c2f"); }); const signature = hexToBytes("1CF08881A5CD0381FF47F7ADC5EF609A3188A704C0E1687C4FAAD1B43D5AA57A1AE51DDD01972542E07526D46DAED92EE097335303FEA79EB64B833B831F585200"); it('Should build signed Tron transaction with big amount correctly' , () => { expect(buildTransaction({from: "TV7Pts9PaedUKFKEkGs7PJJn5LToSpzRHZ", to: "TG6vpPN87HYVd9GSQiGtd27Ah9xAYFw6z9", amount: "100850743812", fees: "0.1", timestamp: 1622445973395, block: {ref_block_hash: "0000000000ea8727d50d54d96109b181ea5a758934c73826f7666ad783cabe83", ref_block_height: 15370023, ref_block_timestamp:1622445903000 }, signature: signature}).toString('hex')) .to.equal("0a8b010a0287272208d50d54d96109b1814098f69a8c9c2f5a6d080112690a2d747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e5472616e73666572436f6e747261637412380a1541d1f6cf8f75444b86325a17429d747806b4a0a11f1215414346929a36348d216bcabe2bb8a627366a556c81188092fec1f9e692b3017093bfc38a9c2f12411cf08881a5cd0381ff47f7adc5ef609a3188a704c0e1687c4faad1b43d5aa57a1ae51ddd01972542e07526d46daed92ee097335303fea79eb64b833b831f585200"); }); }); describe('hw_trx small transaction building tests', () => { it('Should build unsigned Tron transaction with small amount correctly' , () => { expect(buildTransaction({from: "TV7Pts9PaedUKFKEkGs7PJJn5LToSpzRHZ", to: "TG6vpPN87HYVd9GSQiGtd27Ah9xAYFw6z9", amount: "0.000001", fees: "0.1", timestamp: 1622445973395, block: {ref_block_hash: "0000000000ea8727d50d54d96109b181ea5a758934c73826f7666ad783cabe83", ref_block_height: 15370023, ref_block_timestamp:1622445903000 }}).toString('hex')) .to.equal("0a0287272208d50d54d96109b1814098f69a8c9c2f5a65080112610a2d747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e5472616e73666572436f6e747261637412300a1541d1f6cf8f75444b86325a17429d747806b4a0a11f1215414346929a36348d216bcabe2bb8a627366a556c8118017093bfc38a9c2f"); }); const signature = hexToBytes("1CF08881A5CD0381FF47F7ADC5EF609A3188A704C0E1687C4FAAD1B43D5AA57A1AE51DDD01972542E07526D46DAED92EE097335303FEA79EB64B833B831F585200"); it('Should build signed Tron transaction with small amount correctly' , () => { expect(buildTransaction({from: "TV7Pts9PaedUKFKEkGs7PJJn5LToSpzRHZ", to: "TG6vpPN87HYVd9GSQiGtd27Ah9xAYFw6z9", amount: "0.000001", fees: "0.1", timestamp: 1622445973395, block: {ref_block_hash: "0000000000ea8727d50d54d96109b181ea5a758934c73826f7666ad783cabe83", ref_block_height: 15370023, ref_block_timestamp:1622445903000 }, signature: signature}).toString('hex')) .to.equal("0a83010a0287272208d50d54d96109b1814098f69a8c9c2f5a65080112610a2d747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e5472616e73666572436f6e747261637412300a1541d1f6cf8f75444b86325a17429d747806b4a0a11f1215414346929a36348d216bcabe2bb8a627366a556c8118017093bfc38a9c2f12411cf08881a5cd0381ff47f7adc5ef609a3188a704c0e1687c4faad1b43d5aa57a1ae51ddd01972542e07526d46daed92ee097335303fea79eb64b833b831f585200"); }); }); describe('hw_trx signature extraction tests', () => { it('Should extract recID and build formated signature from a DER encoded signature' , () => { let sig = hexToBytes("3045022100abeab3edcada7707d7c1072d7d818b032d24aa70ff5207e8fd52ca0ef8150e420220344237cbc59205eb173cf2d7c496d597bd34beee016afc44620ab802191fddc5"); let message = hexToBytes("0a0287272208d50d54d96109b1814098f69a8c9c2f5a67080112630a2d747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e5472616e73666572436f6e747261637412320a15412057b0ef65df72fffb21e4db2c5063021a4ac3911215414346929a36348d216bcabe2bb8a627366a556c8118a0c21e7093bfc38a9c2f") expect(extractSignature({signature: sig, transaction: message, address: "TCvDg5vXUGoJDFSChbnGfCVAaA6WNjapbb"}).toString('hex')) .to.equal("abeab3edcada7707d7c1072d7d818b032d24aa70ff5207e8fd52ca0ef8150e42344237cbc59205eb173cf2d7c496d597bd34beee016afc44620ab802191fddc501"); }); });