aboutsummaryrefslogtreecommitdiffstats
path: root/packages/pipeline/src
diff options
context:
space:
mode:
authorAlex Browne <stephenalexbrowne@gmail.com>2018-09-20 02:56:41 +0800
committerFred Carlsen <fred@sjelfull.no>2018-12-13 01:11:53 +0800
commitc9dc69bed6e57f18b35ecd53dd65b9c5a44d9886 (patch)
tree1fff32aaac6d2cba8468a158d0711f2593b52798 /packages/pipeline/src
parentcd7e41bd5bbf1abae4c855d6a666e6d9f7da2294 (diff)
downloaddexon-0x-contracts-c9dc69bed6e57f18b35ecd53dd65b9c5a44d9886.tar.gz
dexon-0x-contracts-c9dc69bed6e57f18b35ecd53dd65b9c5a44d9886.tar.zst
dexon-0x-contracts-c9dc69bed6e57f18b35ecd53dd65b9c5a44d9886.zip
Add tests for etherscan events
Diffstat (limited to 'packages/pipeline/src')
-rw-r--r--packages/pipeline/src/data-sources/etherscan/events.ts23
-rw-r--r--packages/pipeline/src/index.ts3
2 files changed, 17 insertions, 9 deletions
diff --git a/packages/pipeline/src/data-sources/etherscan/events.ts b/packages/pipeline/src/data-sources/etherscan/events.ts
index 50962a266..3083af267 100644
--- a/packages/pipeline/src/data-sources/etherscan/events.ts
+++ b/packages/pipeline/src/data-sources/etherscan/events.ts
@@ -25,21 +25,30 @@ export interface EventsResponseResult {
transactionIndex: string;
}
-function convertResponseToLogEntry(result: EventsResponseResult): LogEntry {
- const radix = 10;
+const hexRadix = 16;
+
+function hexToInt(hex: string): number {
+ return parseInt(hex.replace('0x', ''), hexRadix);
+}
+
+// Converts a raw event response to a LogEntry
+// tslint:disable-next-line:completed-docs
+export function _convertResponseToLogEntry(result: EventsResponseResult): LogEntry {
return {
- logIndex: parseInt(result.logIndex, radix),
- transactionIndex: parseInt(result.logIndex, radix),
+ logIndex: hexToInt(result.logIndex),
+ transactionIndex: hexToInt(result.transactionIndex),
transactionHash: result.transactionHash,
blockHash: '',
- blockNumber: parseInt(result.blockNumber, radix),
+ blockNumber: hexToInt(result.blockNumber),
address: result.address,
data: result.data,
topics: result.topics,
};
}
-function tryToDecodeLogOrNoop(log: LogEntry): LogWithDecodedArgs<DecodedLogArgs> {
+// Decodes a LogEntry into a LogWithDecodedArgs
+// tslint:disable-next-line:completed-docs
+export function _decodeLogEntry(log: LogEntry): LogWithDecodedArgs<DecodedLogArgs> {
const abiDecoder = new AbiDecoder([artifacts.Exchange.compilerOutput.abi]);
const logWithDecodedArgs = abiDecoder.tryToDecodeLogOrNoop(log);
// tslint:disable-next-line:no-unnecessary-type-assertion
@@ -51,4 +60,4 @@ function tryToDecodeLogOrNoop(log: LogEntry): LogWithDecodedArgs<DecodedLogArgs>
* @param rawEventsResponse The raw events response from etherescan.io.
* @returns Parsed and decoded events.
*/
-export const parseRawEventsResponse = R.pipe(R.map(convertResponseToLogEntry), R.map(tryToDecodeLogOrNoop));
+export const parseRawEventsResponse = R.pipe(R.map(_convertResponseToLogEntry), R.map(_decodeLogEntry));
diff --git a/packages/pipeline/src/index.ts b/packages/pipeline/src/index.ts
index c9254cc2a..baed6933e 100644
--- a/packages/pipeline/src/index.ts
+++ b/packages/pipeline/src/index.ts
@@ -3,6 +3,5 @@ import { Etherscan } from './data-sources/etherscan';
const etherscan = new Etherscan(process.env.ETHERSCAN_API_KEY as string);
(async () => {
- const events = await etherscan.getContractEventsAsync('0x4f833a24e1f95d70f028921e27040ca56e09ab0b');
- console.log(events);
+ await etherscan.getContractEventsAsync('0x4f833a24e1f95d70f028921e27040ca56e09ab0b');
})();