From 82738e7245fc9e5fe70e546ee73a616d1f1511b9 Mon Sep 17 00:00:00 2001 From: Mykola Date: Sat, 10 Mar 2018 19:38:16 -0800 Subject: [PATCH] Add test for extractTransactionData() --- test/TransactionParser.test.ts | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 test/TransactionParser.test.ts diff --git a/test/TransactionParser.test.ts b/test/TransactionParser.test.ts new file mode 100644 index 00000000..333eb587 --- /dev/null +++ b/test/TransactionParser.test.ts @@ -0,0 +1,35 @@ + +import { TransactionParser } from "../src/common/TransactionParser"; +import * as mocha from "mocha"; +import { block, contractCreateTrx, ethTransferTrx } from "./SeedData"; +import { should, expect } from "chai" + + +describe("Test TransactionParser", () => { + describe("Test extractTransactionData()", () => { + const extractTransactionData = new TransactionParser().extractTransactionData; + it("Should extract transaction data", () => { + const transaction = extractTransactionData(block, ethTransferTrx); + + transaction.should.to.have.property("_id").to.be.a("string"); + transaction.should.to.have.property("blockNumber").to.be.a("number"); + transaction.should.to.have.property("timeStamp").to.be.a("string"); + transaction.should.to.have.property("nonce").to.be.a("number"); + transaction.should.to.have.property("from").to.be.a("string"); + transaction.should.to.have.property("to").to.be.a("string"); + transaction.should.to.have.property("value").to.be.a("string"); + transaction.should.to.have.property("gas").to.be.a("string"); + transaction.should.to.have.property("gasPrice").to.be.a("string"); + transaction.should.to.have.property("gasUsed").to.be.a("string"); + transaction.should.to.have.property("input").to.be.a("string"); + transaction.should.to.have.property("addresses").to.be.a("array"); + }) + + it("Should extract contract creation transaction correctly", () => { + const transaction = extractTransactionData(block, contractCreateTrx); + + expect(transaction.to).to.equal(""); + expect(transaction.addresses).to.have.lengthOf(1); + }) + }) +}) \ No newline at end of file