import { buildTransaction, getHolaParameters, extractSignature, verifyAddress, getHolaParameters_LINK } 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_etc address verification tests', () => { it('Should verify Ethereum classic address correctly' , () => { expect(verifyAddress("0x34c3e76432d9842cfe2bb6c882dad2b43505baaa")) .to.equal(true); }); it('Should fail verify Ethereum classic address correctly' , () => { expect(verifyAddress("0x34c3e76432d9842cfe2bb6c882dad2b43505baa")) .to.equal(false); }); it('Should fail verify Ethereum classic address correctly' , () => { expect(verifyAddress("0x34c3e76432d9842cfe2bb6c882dad2b4350ybaaa")) .to.equal(false); }); }); describe('hw_etc transaction building tests', () => { it('Should build unsigned Ethereum transaction correctly' , () => { expect(buildTransaction({nonce: "0", gasPrice: "1", gasLimit: 21000, toAddress: "0x1223de8a29a4820d3fed6a354f8d37c9efd9d943", amount: "0.001", network: Network.Testnet}).toString('hex')) .to.equal("ea80843b9aca00825208941223de8a29a4820d3fed6a354f8d37c9efd9d94387038d7ea4c6800080068080"); }); let rD = hexToBytes("1c340003890afc27e8ef7ccf9ab42e185594b7e09b016d942daace4ab5c3a418"); let sD = hexToBytes("7de42356dea72445e06a3eee37c93a88dc19fd2a5ff5c856a3a7380f6d4a74a1"); it('Should build signed Ethereum transaction correctly' , () => { expect(buildTransaction({nonce : "0", gasPrice: "1", gasLimit: 21000, toAddress: "0x1223de8a29a4820d3fed6a354f8d37c9efd9d943", "amount": "0.001", signature: {v:0x30, r: rD, s: sD}, network: Network.Testnet}).toString('hex')) .to.equal("f86a80843b9aca00825208941223de8a29a4820d3fed6a354f8d37c9efd9d94387038d7ea4c680008030a01c340003890afc27e8ef7ccf9ab42e185594b7e09b016d942daace4ab5c3a418a07de42356dea72445e06a3eee37c93a88dc19fd2a5ff5c856a3a7380f6d4a74a1"); }); }); describe('hw_etc HOLa parameters generation tests', () => { it('Should generate HOLa parameters correctly' , () => { let parameters = getHolaParameters({nonce: "0", gasPrice: "1", gasLimit: 21000, toAddress: "0x1223de8a29a4820d3fed6a354f8d37c9efd9d943", amount: "0.001", network: Network.Testnet}); expect(parameters.blk[0].toString('hex')) .to.equal("ea80843b9aca00825208941223de8a29a4820d3fed6a354f8d37c9efd9d94387038d7ea4c6800080068080"); let correctU32Data = [3,6]; let u32cont = 0 for(let u32 of parameters.u32){ expect(u32).to.equal(correctU32Data[u32cont]); u32cont++; } }); }); describe('hw_etc HOLa parameters generation tests (LINK)', () => { it('Should generate HOLa parameters correctly' , () => { let parameters = getHolaParameters_LINK({nonce: "0", gasPrice: "1", gasLimit: 21000, toAddress: "0x1223de8a29a4820d3fed6a354f8d37c9efd9d943", amount: "0.001", network: Network.Testnet}); expect(parameters.blk[0].toString('hex')) .to.equal("7717fd2a4dbf967fc5aaa4ba9570dd54485cc778b7e48841a409283868dc2877"); }); }); describe('hw_etc big transaction building tests', () => { it('Should build unsigned Ethereum transaction with big amount correctly' , () => { expect(buildTransaction({nonce : "0", gasPrice: "50", gasLimit: 21000, toAddress: "0x34c3e76432d9842cfe2bb6c882dad2b43505baaa", "amount": "117084665.25", network: Network.Testnet}).toString('hex')) .to.equal("ef80850ba43b74008252089434c3e76432d9842cfe2bb6c882dad2b43505baaa8b60d9a46be373e25e1d000080068080"); }); let rD = hexToBytes("BBB2D06AB85B3AB1AF13560E2A18BB0E36DE6465FEE34C96953D28241F5E6724"); let sD = hexToBytes("57FB79AE09A7DA48693F4D8F861CA96CD71BD629DDEA972A181C5F65B5F56AF9"); it('Should build signed Ethereum transaction with big amount correctly' , () => { expect(buildTransaction({nonce : "0", gasPrice: "50", gasLimit: 21000, toAddress: "0x34c3e76432d9842cfe2bb6c882dad2b43505baaa", "amount": "117084665.25", signature: {v:0x1C, r: rD, s: sD}, network: Network.Testnet}).toString('hex')) .to.equal("f86f80850ba43b74008252089434c3e76432d9842cfe2bb6c882dad2b43505baaa8b60d9a46be373e25e1d0000801ca0bbb2d06ab85b3ab1af13560e2a18bb0e36de6465fee34c96953d28241f5e6724a057fb79ae09a7da48693f4d8f861ca96cd71bd629ddea972a181c5f65b5f56af9"); }); }); describe('hw_etc small transaction building tests', () => { it('Should build unsigned Ethereum transaction with small amount correctly' , () => { expect(buildTransaction({nonce : "0", gasPrice: "50", gasLimit: 21000, toAddress: "0x34c3e76432d9842cfe2bb6c882dad2b43505baaa", "amount": "0.000000000000000001", network: Network.Testnet}).toString('hex')) .to.equal("e480850ba43b74008252089434c3e76432d9842cfe2bb6c882dad2b43505baaa0180068080"); }); let rD = hexToBytes("BBB2D06AB85B3AB1AF13560E2A18BB0E36DE6465FEE34C96953D28241F5E6724"); let sD = hexToBytes("57FB79AE09A7DA48693F4D8F861CA96CD71BD629DDEA972A181C5F65B5F56AF9"); it('Should build signed Ethereum transaction with small amount correctly' , () => { expect(buildTransaction({nonce : "0", gasPrice: "50", gasLimit: 21000, toAddress: "0x34c3e76432d9842cfe2bb6c882dad2b43505baaa", "amount": "0.000000000000000001", signature: {v:0x1C, r: rD, s: sD}, network: Network.Testnet}).toString('hex')) .to.equal("f86480850ba43b74008252089434c3e76432d9842cfe2bb6c882dad2b43505baaa01801ca0bbb2d06ab85b3ab1af13560e2a18bb0e36de6465fee34c96953d28241f5e6724a057fb79ae09a7da48693f4d8f861ca96cd71bd629ddea972a181c5f65b5f56af9"); }); }); describe('hw_etc signature extraction tests', () => { it('Should extract v,r,s from a DER encoded signature' , () => { let sig = hexToBytes("304402201c340003890afc27e8ef7ccf9ab42e185594b7e09b016d942daace4ab5c3a41802207de42356dea72445e06a3eee37c93a88dc19fd2a5ff5c856a3a7380f6d4a74a1"); let message = hexToBytes("ea80843b9aca00825208941223de8a29a4820d3fed6a354f8d37c9efd9d94387038d7ea4c6800080068080") let signature = extractSignature({signature: sig, transaction: message, address: "0x73f0619172782b2d9a8d8778215416d9e76aeda5", net: Network.Testnet}) expect(signature.v) .to.equal(48); expect(signature.r.toString('hex')) .to.equal("1c340003890afc27e8ef7ccf9ab42e185594b7e09b016d942daace4ab5c3a418"); expect(signature.s.toString('hex')) .to.equal("7de42356dea72445e06a3eee37c93a88dc19fd2a5ff5c856a3a7380f6d4a74a1"); }); });