Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upd: web3-eth package #57

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions internal/coder/abi_coder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import AbiCoder from "web3-eth-abi";
import {
decodeParameter,
decodeParameters,
decodeLog,
encodeParameters
} from "web3-eth-abi";

/**
* web3 helper class to access any web3 js related functionalities, use this to define any web3 helper functions
Expand All @@ -11,7 +16,7 @@ export class ABICoder {
* @returns {any} - Can return arrays, numbers, objects, etc. depends on the RLP type
*/
public static decodeParameter(type: any, hex: string): any {
return (AbiCoder as any).decodeParameter(type, hex);
return decodeParameter(type, hex);
}

/**
Expand All @@ -21,7 +26,7 @@ export class ABICoder {
* @returns {any} - Can return an object of arrays, numbers, objects, etc. depends on the RLP type
*/
public static decodeParameters(types: any[], hex: string): { [key: string]: any } {
return (AbiCoder as any).decodeParameters(types, hex);
return decodeParameters(types, hex);
}

/**
Expand All @@ -31,7 +36,7 @@ export class ABICoder {
* @returns {any} - return hex string
*/
public static encodeParameters(types: any[], values: string[]): string {
return (AbiCoder as any).encodeParameters(types, values);
return encodeParameters(types, values);
}

/**
Expand All @@ -44,7 +49,7 @@ export class ABICoder {
* @returns
*/
public static decodeLog(inputs: any[], hex: string, topics: string[]): { [key: string]: string } {
return (AbiCoder as any).decodeLog(inputs, hex, topics);
return decodeLog(inputs, hex, topics) as unknown as { [key: string]: string };
}

/**
Expand All @@ -56,6 +61,6 @@ export class ABICoder {
* @returns {{ [key: string]: any }}
*/
public static decodeMethod(types: any[], data: string): { [key: string]: any } {
return ABICoder.decodeParameters(types, "0x" + data.slice(10));
return decodeParameters(types, "0x" + data.slice(10));
}
}
139 changes: 129 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@maticnetwork/chain-indexer-framework",
"version": "1.3.14",
"version": "1.3.15-beta.0",
"description": "blockchain data indexer",
"type": "module",
"exports": {
Expand Down Expand Up @@ -55,7 +55,7 @@
"web3-core-helpers": "^1.8.2",
"web3-core-subscriptions": "^1.7.5",
"web3-eth": "^1.8.0",
"web3-eth-abi": "^1.8.0",
"web3-eth-abi": "^4.2.3",
"web3-eth-contract": "^1.8.1",
"web3-utils": "^1.8.2",
"winston": "^3.8.2",
Expand Down
22 changes: 11 additions & 11 deletions tests/coder/abi_coder.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { ABICoder } from "../../dist/internal/coder/abi_coder";
import AbiCoder from "web3-eth-abi";
import {
decodeParameter,
decodeParameters,
decodeLog,
encodeParameters
} from "web3-eth-abi";

jest.mock("web3-eth-abi");

describe("abi_coder", () => {
let abiCoderObject: jest.MockedObject<typeof AbiCoder>

beforeEach(() => {
abiCoderObject = AbiCoder as jest.MockedObject<typeof AbiCoder>;
});

describe("ABICoder", () => {
test("decodeParameter", () => {
//@ts-ignore
abiCoderObject.decodeParameter.mockReturnValueOnce("mocked_result")
decodeParameter.mockReturnValueOnce("mocked_result")
expect(
ABICoder.decodeParameter(
"mocked_type",
Expand All @@ -24,7 +24,7 @@ describe("abi_coder", () => {

test("decodeParameters", () => {
//@ts-ignore
abiCoderObject.decodeParameters.mockReturnValueOnce(["mocked_result"])
decodeParameters.mockReturnValueOnce(["mocked_result"])
expect(
ABICoder.decodeParameters(
["mocked_type"],
Expand All @@ -35,7 +35,7 @@ describe("abi_coder", () => {

test("encodeParameters", () => {
//@ts-ignore
abiCoderObject.encodeParameters.mockReturnValueOnce("mocked_result")
encodeParameters.mockReturnValueOnce("mocked_result")
expect(
ABICoder.encodeParameters(
["mocked_type"],
Expand All @@ -46,7 +46,7 @@ describe("abi_coder", () => {

test("decodeLog", () => {
//@ts-ignore
abiCoderObject.decodeLog.mockReturnValueOnce(["mocked_result"])
decodeLog.mockReturnValueOnce(["mocked_result"])
expect(
ABICoder.decodeLog(
["mocked_input"],
Expand All @@ -58,7 +58,7 @@ describe("abi_coder", () => {

test("decodeMethod", () => {
//@ts-ignore
abiCoderObject.decodeParameters.mockReturnValueOnce(["mocked_result"])
decodeParameters.mockReturnValueOnce(["mocked_result"])
expect(
ABICoder.decodeMethod(
['bytes'],
Expand Down
Loading