import * as mocha from 'mocha'; import * as chai from 'chai'; import { Network, OutputType } from "./types"; import { buildTransaction, extractSignature, getHolaParameters, getHolaParameters_Link, verifyAddress} from '.'; const expect = chai.expect; describe('hw_fil address verification tests', () => { it('Should verify Filecoin address correctly' , () => { expect(verifyAddress("f01132085")) .to.equal(true); }); it('Should verify Filecoin address correctly' , () => { expect(verifyAddress("t1m2brvreeysex2eypx3q5ygcz2vptkxdz2t3chba")) .to.equal(true); }); it('Should fail verify Filecoin address correctly' , () => { expect(verifyAddress("t1m2brvreeysex2eypx3qSygcz2vptkxdz2t3chba")) .to.equal(false); }); }); describe('hw_fil transaction building tests', () => { it('Should build unsigned Filecoin transaction correctly' , () => { expect(buildTransaction({From: "t1m2brvreeysex2eypx3q5ygcz2vptkxdz2t3chba", To: "t1rjrugxuhlike4jxrylumg7axk34pef6ii43drtq", Nonce: "0", Value: "1", GasFeeCap: "288", GasLimit: 491868, GasPremium: "0"}).toString('hex')) .to.equal("8a0055018a63435e875a144e26f1c2e8c37c1756f8f217c8550166831ac484c4897d130fbee1dc1859d55f355c790049000de0b6b3a76400001a0007815c43000120400040"); }); let transaction = { from: 't1m2brvreeysex2eypx3q5ygcz2vptkxdz2t3chba', to: 't1rjrugxuhlike4jxrylumg7axk34pef6ii43drtq', amount: '1', gasLimit: 491868, gasFeeCap: '288', gasPremium: '0', nonce: '0', signature: 'dcQ3u3LRytMdlWe3HWfFUzyEMcJdwVzw9d3rTw7zwkFglSPbzuwdIrr1D0ZhqMngtyzkez/uYXKyEiCcmuQdJQE=' } let builtTransaction = buildTransaction({From: "t1m2brvreeysex2eypx3q5ygcz2vptkxdz2t3chba", To: "t1rjrugxuhlike4jxrylumg7axk34pef6ii43drtq", Nonce: "0", Value: "1", GasFeeCap: "288", GasLimit: 491868, GasPremium: "0", Signature: "dcQ3u3LRytMdlWe3HWfFUzyEMcJdwVzw9d3rTw7zwkFglSPbzuwdIrr1D0ZhqMngtyzkez/uYXKyEiCcmuQdJQE=", outputType: OutputType.JSON}); it('Should build signed Filecoin transaction correctly' , () => { for(let i in transaction){ expect(transaction[i]) .to.equal(builtTransaction[i]); } }); }); describe('hw_fil signature extraction tests', () => { it('Should extract Filecoin transaction signature correctly' , () => { let tx = Buffer.from("8a0055018a63435e875a144e26f1c2e8c37c1756f8f217c8550166831ac484c4897d130fbee1dc1859d55f355c790049000de0b6b3a76400001a0007815c43000120400040", "hex"); let sig = Buffer.from("3045022100cd59a41f6236cae94f247959e487e2d7a39d393d4c9e554aa8587a3bf139f58b02206d08539a55fc669afa5666016a8b021d968c0efbf7824f25cb7896fbbcb69d82", "hex"); let signature = extractSignature({transaction: tx, signature: sig, address: "t1m2brvreeysex2eypx3q5ygcz2vptkxdz2t3chba", net: Network.Testnet}) expect(signature.toString("base64")).to.equal("zVmkH2I2yulPJHlZ5Ifi16OdOT1MnlVKqFh6O/E59YttCFOaVfxmmvpWZgFqiwIdlowO+/eCTyXLeJb7vLadggE="); }); }); describe('hw_fil HOLa parameters generation tests', () => { it('Should generate Filecoin HOLa parameters correctly' , () => { let parameters = getHolaParameters({From: "t1m2brvreeysex2eypx3q5ygcz2vptkxdz2t3chba", To: "t1rjrugxuhlike4jxrylumg7axk34pef6ii43drtq", Nonce: "0", Value: "1", GasFeeCap: "288", GasLimit: 491868, GasPremium: "0"}); let correctBlkData = ["8a0055018a63435e875a144e26f1c2e8c37c1756f8f217c8550166831ac484c4897d130fbee1dc1859d55f355c790049000de0b6b3a76400001a0007815c43000120400040"]; let blkCont = 0; for(let blk of parameters.blk){ expect(blk.toString('hex')).to.equal(correctBlkData[blkCont]); blkCont++; } let correctU32Data = [1,9]; let u32cont = 0 for(let u32 of parameters.u32){ expect(u32).to.equal(correctU32Data[u32cont]); u32cont++; } }); }); describe('hw_fil HOLa parameters generation tests (LINK)', () => { it('Should generate Filecoin HOLa parameters correctly' , () => { let parameters = getHolaParameters_Link({From: "t1m2brvreeysex2eypx3q5ygcz2vptkxdz2t3chba", To: "t1rjrugxuhlike4jxrylumg7axk34pef6ii43drtq", Nonce: "0", Value: "1", GasFeeCap: "288", GasLimit: 491868, GasPremium: "0"}); let correctBlkData = ["f3e3c971b4b9e05067e7d42e01e05fbdff942facfe4f7657fb26ee69f5b82717"]; let blkCont = 0; for(let blk of parameters.blk){ expect(blk.toString('hex')).to.equal(correctBlkData[blkCont]); blkCont++; } }); });