Skip to content

Commit

Permalink
Switch to @wharfkit and update ethereumjs deps
Browse files Browse the repository at this point in the history
  • Loading branch information
guilledk committed Jun 5, 2024
1 parent f121f5c commit 475b184
Show file tree
Hide file tree
Showing 23 changed files with 570 additions and 586 deletions.
17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "leap-mock",
"repository": "git+https://github.com/guilledk/leap-mock.git",
"version": "0.1.7",
"version": "0.1.9-rc1",
"description": "AntelopeIO/leap mocker for advanced indexer testing",
"main": "./build/index.js",
"type": "module",
Expand All @@ -11,29 +11,29 @@
},
"scripts": {
"bootstrap": "yarn",
"build": "npm run bootstrap && tsc && node scripts/create-dist-packages.mjs",
"build": "yarn bootstrap && tsc && node scripts/create-dist-packages.mjs",
"start": "node build/main.js",
"test": "mocha build/tests/**/*.spec.js --timeout 120000",
"docker-build": "npm run build && node scripts/docker-build.mjs",
"docker-build": "yarn build && node scripts/docker-build.mjs",
"docker-start": "node scripts/docker-run.mjs",
"docker-stop": "node scripts/docker-stop.mjs",
"docker-push": "node scripts/docker-push.mjs"
},
"author": "",
"license": "ISC",
"dependencies": {
"@telosnetwork/hyperion-sequential-reader": "1.2.6",
"@ethereumjs/tx": "^5.1.0",
"@ethereumjs/util": "^9.0.1",
"@greymass/eosio": "0.7.0",
"@ethereumjs/tx": "5.3.0",
"@ethereumjs/util": "9.0.3",
"@telosnetwork/hyperion-sequential-reader": "1.2.7-rc10",
"@types/express": "^4.17.20",
"@types/ws": "^8.5.8",
"@wharfkit/antelope": "^1.0.7",
"async": "^3.2.4",
"axios": "^1.6.2",
"commander": "^11.1.0",
"express": "^4.18.2",
"lodash.clonedeep": "^4.5.0",
"telos-evm-custom-ds": "1.0.0-rc4",
"telos-evm-custom-ds": "1.1.1-rc1",
"winston": "^3.11.0",
"ws": "^8.14.2"
},
Expand All @@ -44,7 +44,6 @@
"@types/mocha": "^10.0.6",
"@types/node": "^20.10.4",
"chai": "^4.3.10",
"eosjs": "^22.1.0",
"fs-extra": "^11.2.0",
"mocha": "^10.2.0",
"nodemon": "^2.0.22",
Expand Down
2 changes: 1 addition & 1 deletion src/abis/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ABI} from "@greymass/eosio";
import {ABI} from "@wharfkit/antelope";
import fs from 'fs';
import path from "path";
import {fileURLToPath} from "node:url";
Expand Down
2 changes: 1 addition & 1 deletion src/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
randomInt,
sleep,
} from "./utils.js";
import {ABI, Name, NameType, Serializer} from "@greymass/eosio";
import {ABI, Name, NameType, Serializer} from "@wharfkit/antelope";
import {logger} from "./logging.js";
import {ActionDescriptor, ActionTrace, TransactionTraceOptions} from "./types.js";

Expand Down
2 changes: 1 addition & 1 deletion src/chainbase.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ABI, Checksum256, Int64, Name, NameType, UInt64} from "@greymass/eosio";
import {ABI, Checksum256, Int64, Name, NameType, UInt64} from "@wharfkit/antelope";
import {nameToBigInt, uint8ArrayToBigInt} from "./utils.js";
import {eosVMCheck} from "./mock/abstract.js";
import {BufferedMap, MapLevel} from "./bufferedMap.js";
Expand Down
10 changes: 5 additions & 5 deletions src/controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {MockChain} from "./chain.js";
import {ABI} from "@greymass/eosio";
import {ABI, APIClient, FetchProvider} from "@wharfkit/antelope";
import {
DEFAULT_ABI,
generateInOrderBlockHashes,
Expand All @@ -14,13 +14,13 @@ import fs from "fs";
import {logger} from "./logging.js";
import {ActionDescriptor} from "./types.js";

import { JsonRpc } from 'eosjs';
import fetch from 'node-fetch'

// @ts-ignore
const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));

export function getRPCClient(endpoint: string) {
return new JsonRpc(endpoint, { fetch });
return new APIClient({
provider: new FetchProvider(endpoint, {fetch})
});
}

export interface ChainDescriptor {
Expand Down
1 change: 0 additions & 1 deletion src/controllerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import process from "process";
import ControllerHTTPClient from "./controllerHTTPClient.js";
import {generateTestChainDescriptor} from "./tests/utils.js";
import {logger} from "./logging.js";
import {ABI} from "@greymass/eosio";
import {ActionDescriptor} from "./types";

process.on('unhandledRejection', error => {
Expand Down
2 changes: 1 addition & 1 deletion src/mock/abstract.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {ActionDescriptor, ActionTrace} from "../types.js";
import {generateActionTrace} from "../utils.js";
import {ABI, Name, NameType} from "@greymass/eosio";
import {ABI, Name, NameType} from "@wharfkit/antelope";
import {MockChainbase, TableIndexMapping, TableRow} from "../chainbase.js";


Expand Down
2 changes: 1 addition & 1 deletion src/mock/eosio.token/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Asset, Name} from "@greymass/eosio";
import {Asset, Name} from "@wharfkit/antelope";

export const SELF = Name.from('eosio.token');
export const TOKEN_SYMBOL = Asset.Symbol.fromParts('TLOS', 4);
2 changes: 1 addition & 1 deletion src/mock/eosio.token/descriptors.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {ActionDescriptor} from "../../types";
import {SELF} from "./constants.js";
import {AssetType, NameType} from "@greymass/eosio";
import {AssetType, NameType} from "@wharfkit/antelope";

export class AntelopeTransfer implements ActionDescriptor {
account: NameType = SELF;
Expand Down
2 changes: 1 addition & 1 deletion src/mock/eosio.token/mockers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {ActionMocker, ApplyContext} from "../abstract.js";
import {Asset} from "@greymass/eosio";
import {Asset} from "@wharfkit/antelope";
import {SELF, TOKEN_SYMBOL} from "./constants.js";
import {AccountsRow} from "./tables.js";

Expand Down
2 changes: 1 addition & 1 deletion src/mock/eosio.token/tables.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Asset} from "@greymass/eosio";
import {Asset} from "@wharfkit/antelope";
import {JsonSerializable, TableRow} from "../../chainbase.js";

export interface AccountsRowJSON {
Expand Down
7 changes: 3 additions & 4 deletions src/mock/eosio.token/utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {ChainRuntime} from "../../controller.js";
import {JsonRpc} from "eosjs";
import {NameType} from "@greymass/eosio";
import {AccountsRow} from "./tables.js";
import {JsonSerializable} from "../../chainbase.js";
import {SELF} from "./constants.js";
import {APIClient, NameType} from "@wharfkit/antelope";

export function getBalanceForAccount(runtime: ChainRuntime, account: NameType): AccountsRow | undefined {
const rows = runtime.chain.getDB().getTableRows(
Expand All @@ -15,8 +14,8 @@ export function getBalanceForAccount(runtime: ChainRuntime, account: NameType):
return undefined;
}

export async function getBalanceForAccountHTTP(rpc: JsonRpc, account: NameType): Promise<AccountsRow | undefined> {
const rows = (await rpc.get_table_rows({
export async function getBalanceForAccountHTTP(rpc: APIClient, account: NameType): Promise<AccountsRow | undefined> {
const rows = (await rpc.v1.chain.get_table_rows({
json: true,
code: SELF.toString(), table: 'accounts', scope: account.toString(),
})).rows as JsonSerializable[];
Expand Down
2 changes: 1 addition & 1 deletion src/mock/telos.evm/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Asset, Name} from "@greymass/eosio";
import {Asset, Name} from "@wharfkit/antelope";

export const SELF = Name.from('eosio.evm');
export const TOKEN_CONTRACT = Name.from('eosio.token');
Expand Down
9 changes: 4 additions & 5 deletions src/mock/telos.evm/descriptors.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {SELF, TOKEN_CONTRACT} from "./constants.js";
import {AntelopeTransfer} from "../eosio.token/descriptors.js";
import {AssetType, Checksum160Type, NameType} from "@greymass/eosio";
import {SELF} from "./constants.js";
import {AssetType, Checksum160Type, NameType} from "@wharfkit/antelope";
import {ActionDescriptor} from "../../types.js";
import {TEVMTransaction} from "telos-evm-custom-ds";
import {LegacyTransaction} from "@ethereumjs/tx";
import {TEVMTransaction} from "telos-evm-custom-ds";


export class TelosEVMCreate implements ActionDescriptor {
Expand Down Expand Up @@ -44,7 +43,7 @@ export class TelosEVMRaw implements ActionDescriptor {

constructor(opts: {
ram_payer: NameType,
tx: Uint8Array | string | LegacyTransaction,
tx: Uint8Array | string | LegacyTransaction | TEVMTransaction,
estimate_gas: boolean,
sender?: Checksum160Type
}) {
Expand Down
2 changes: 1 addition & 1 deletion src/mock/telos.evm/mockers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {ApplyContext, eosVMCheck} from "../abstract.js";
import {Checksum160} from "@greymass/eosio";
import {Checksum160} from "@wharfkit/antelope";
import {Address} from "@ethereumjs/util";
import {randomByteArray} from "../../utils.js";
import {TEVMTransaction} from "telos-evm-custom-ds";
Expand Down
2 changes: 1 addition & 1 deletion src/mock/telos.evm/tables.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Asset, Checksum160, Name, NameType, UInt64} from "@greymass/eosio";
import {Asset, Checksum160, Name, NameType, UInt64} from "@wharfkit/antelope";
import {ActionMocker, ApplyContext, eosVMCheck} from "../abstract.js";
import {Address} from "@ethereumjs/util";
import {
Expand Down
23 changes: 11 additions & 12 deletions src/mock/telos.evm/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import {LegacyTxData} from "@ethereumjs/tx";
import {TEVMTransaction} from "telos-evm-custom-ds";
import {addHexPrefix, Address} from "@ethereumjs/util";
import * as evm from "@ethereumjs/common";
import {Name, NameType} from "@greymass/eosio";
import {APIClient, Name, NameType, UInt64} from "@wharfkit/antelope";
import {AccountRow} from "./tables.js";
import {ChainRuntime} from "../../controller.js";
import {JsonRpc} from "eosjs";
import {addressToSHA256} from "../../utils.js";
import {JsonSerializable} from "../../chainbase.js";
import {SELF} from "./constants.js";
Expand Down Expand Up @@ -98,14 +97,14 @@ export function getEVMBalanceForAccount(runtime: ChainRuntime, account: NameType
return undefined;
}

export async function getEVMBalanceForAccountHTTP(rpc: JsonRpc, account: NameType): Promise<AccountRow | undefined> {
const rows = (await rpc.get_table_rows({
export async function getEVMBalanceForAccountHTTP(rpc: APIClient, account: NameType): Promise<AccountRow | undefined> {
const rows = (await rpc.v1.chain.get_table_rows({
json: true,
code: SELF.toString(), table: 'account', scope: SELF.toString(),
key_type: 'i64',
index_position: 3,
lower_bound: Name.from(account).value.toString(),
upper_bound: Name.from(account).value.toString(),
index_position: 'fourth',
lower_bound: UInt64.from(account),
upper_bound: UInt64.from(account),
limit: 1
})).rows as JsonSerializable[];

Expand All @@ -131,14 +130,14 @@ export function getEVMBalanceForAddress(runtime: ChainRuntime, addr: Address): A
return undefined;
}

export async function getEVMBalanceForAddressHTTP(rpc: JsonRpc, addr: Address): Promise<AccountRow | undefined> {
const rows = (await rpc.get_table_rows({
export async function getEVMBalanceForAddressHTTP(rpc: APIClient, addr: Address): Promise<AccountRow | undefined> {
const rows = (await rpc.v1.chain.get_table_rows({
json: true,
code: SELF, table: 'account', scope: SELF,
key_type: 'sha256',
index_position: 2,
lower_bound: addressToSHA256(addr).toString(),
upper_bound: addressToSHA256(addr).toString(),
index_position: 'tertiary',
lower_bound: addressToSHA256(addr),
upper_bound: addressToSHA256(addr),
limit: 1
})).rows as JsonSerializable[];

Expand Down
2 changes: 1 addition & 1 deletion src/shipSocket.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Serializer} from "@greymass/eosio";
import {Serializer} from "@wharfkit/antelope";
import {WebSocket, WebSocketServer} from "ws";
import {MockChain} from "./chain.js";
import {DEFAULT_ABI_STRING} from "./utils.js";
Expand Down
2 changes: 1 addition & 1 deletion src/tests/hyperion-sequence.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import {addressToChecksum160, assetQuantityToEvm, randomByteArray} from "../utils.js";
import {Address} from "@ethereumjs/util";
import {getBalanceForAccount, getBalanceForAccountHTTP} from "../mock/eosio.token/utils.js";
import {Name, Serializer} from "@greymass/eosio";
import {Serializer} from "@wharfkit/antelope";

const quantity = '420.0000 TLOS'

Expand Down
2 changes: 1 addition & 1 deletion src/tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ import {
} from "../utils.js";
import {describe} from "mocha";
import {ActionDescriptor} from "../types";
import {ABI} from "@greymass/eosio";
import {ABI} from "@wharfkit/antelope";

export function describeMockChainTests(
title: string,
Expand Down
3 changes: 1 addition & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {ABI, Name, NameType} from "@greymass/eosio";
import {MockChainbase} from "./chainbase";
import {NameType} from "@wharfkit/antelope";

export interface ActionReceipt {
receiver: NameType;
Expand Down
4 changes: 1 addition & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,10 @@ import {
AssetType,
Checksum160,
Checksum256,
Int64,
Name,
NameType,
Serializer,
UInt64
} from "@greymass/eosio";
} from "@wharfkit/antelope";
import * as crypto from "crypto";
import {Address} from "@ethereumjs/util";
import {AddressType} from "./mock/telos.evm";
Expand Down
Loading

0 comments on commit 475b184

Please sign in to comment.