Skip to content

Commit

Permalink
Merge branch 'main' into 295-openrpc-integration-test
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Rusev <[email protected]>
  • Loading branch information
ar-conmit committed Jul 26, 2022
2 parents da21db0 + 5fd35e3 commit c4862e7
Show file tree
Hide file tree
Showing 21 changed files with 23,241 additions and 212 deletions.
File renamed without changes.
54 changes: 54 additions & 0 deletions .github/workflows/web3js-compatibility.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Web3js Compatibility

on:
pull_request:
branches: [ main, release/** ]
push:
branches: [ main, release/** ]
tags: [ v* ]

jobs:
setup-local-hedera:
name: Web3js Compatibility
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: 16

- name: Checkout repo
uses: actions/checkout@v2

- name: Install packages
run: npm ci

- name: Create .env file
run: |
cp ./tools/web3js-example/.env.example ./tools/web3js-example/.env
cp ./packages/server/tests/localAcceptance.env .env
- name: Lerna Bootstrap
run: npm run setup

- name: Install pnpm
run: npm install -g pnpm

- name: Build Typescript
run: npx lerna run build

- name: Run RPC Server
run: npm run integration:prerequisite &

- name: Install web3js dependencies
run: cd ./tools/web3js-example/ && npm ci

- name: Run the web3js tests
uses: nick-fields/retry@v2
with:
max_attempts: 10
timeout_minutes: 10
retry_wait_seconds: 45
command: cd ./tools/web3js-example/ && npm run test
6 changes: 5 additions & 1 deletion packages/relay/src/lib/clients/sdkClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export class SDKClient {
.setEthereumData(transactionBuffer), callerName);
}

async submitContractCallQuery(to: string, data: string, gas: number, callerName: string): Promise<ContractFunctionResult> {
async submitContractCallQuery(to: string, data: string, gas: number, from: string, callerName: string): Promise<ContractFunctionResult> {
const contract = SDKClient.prune0x(to);
const contractId = contract.startsWith("00000000000")
? ContractId.fromSolidityAddress(contract)
Expand All @@ -209,6 +209,10 @@ export class SDKClient {
contractCallQuery.setFunctionParameters(Buffer.from(SDKClient.prune0x(data), 'hex'));
}

if (from) {
contractCallQuery.setSenderAccountId(AccountId.fromEvmAddress(0,0, from))
}

if (this.clientMain.operatorAccountId !== null) {
contractCallQuery
.setPaymentTransactionId(TransactionId.generate(this.clientMain.operatorAccountId));
Expand Down
37 changes: 5 additions & 32 deletions packages/relay/src/lib/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import { Eth } from '../index';
import { ContractId, Status, Hbar, EthereumTransaction } from '@hashgraph/sdk';
import { BigNumber } from '@hashgraph/sdk/lib/Transfer';
import { Logger } from 'pino';
import { Block, CachedBlock, Transaction, Log } from './model';
import { MirrorNode } from './mirrorNode';
import { Block, Transaction, Log } from './model';
import { MirrorNodeClient, SDKClient } from './clients';
import { JsonRpcError, predefined } from './errors';
import constants from './constants';
Expand Down Expand Up @@ -76,12 +75,6 @@ export class EthImpl implements Eth {
*/
private readonly sdkClient: SDKClient;

/**
* The mirror node mock
* @private
*/
private readonly mirrorNode: MirrorNode;

/**
* The interface through which we interact with the mirror node
* @private
Expand Down Expand Up @@ -109,20 +102,17 @@ export class EthImpl implements Eth {
/**
* Create a new Eth implementation.
* @param nodeClient
* @param mirrorNode
* @param mirrorNodeClient
* @param logger
* @param chain
*/
constructor(
nodeClient: SDKClient,
mirrorNode: MirrorNode,
mirrorNodeClient: MirrorNodeClient,
logger: Logger,
chain: string
) {
this.sdkClient = nodeClient;
this.mirrorNode = mirrorNode;
this.mirrorNodeClient = mirrorNodeClient;
this.logger = logger;
this.chain = chain;
Expand Down Expand Up @@ -669,24 +659,7 @@ export class EthImpl implements Eth {
if (record.ethereumHash == null) {
throw new Error('The ethereumHash can never be null for an ethereum transaction, and yet it was!!');
}
const txHash = EthImpl.prepend0x(Buffer.from(record.ethereumHash).toString('hex'));

// If the transaction succeeded, create a new block for the transaction.
const mostRecentBlock = await this.mirrorNode.getMostRecentBlock();
this.logger.debug('mostRecentBlock=%o', mostRecentBlock);
let block = mostRecentBlock;
if (record.receipt.status == Status.Success) {
block = new CachedBlock(mostRecentBlock, txHash);
this.mirrorNode.storeBlock(block);
}

// Create a receipt. Register the receipt in the cache and return the tx hash
if (block == null) {
this.logger.error('Failed to get a block for transaction');
return '';
}

return txHash;
return EthImpl.prepend0x(Buffer.from(record.ethereumHash).toString('hex'));
} catch (e) {
this.logger.error(e,
'Failed sendRawTransaction during record retrieval for transaction %s, returning computed hash', transaction);
Expand Down Expand Up @@ -730,10 +703,10 @@ export class EthImpl implements Eth {
gas = call.gas;
}
}

// Execute the call and get the response
this.logger.debug('Making eth_call on contract %o with gas %d and call data "%s"', call.to, gas, call.data);
const contractCallResponse = await this.sdkClient.submitContractCallQuery(call.to, call.data, gas, EthImpl.ethCall);
this.logger.debug('Making eth_call on contract %o with gas %d and call data "%s" from "%s"', call.to, gas, call.data, call.from);
const contractCallResponse = await this.sdkClient.submitContractCallQuery(call.to, call.data, gas, call.from, EthImpl.ethCall);

// FIXME Is this right? Maybe so?
return EthImpl.prepend0x(Buffer.from(contractCallResponse.asBytes()).toString('hex'));
Expand Down
143 changes: 0 additions & 143 deletions packages/relay/src/lib/mirrorNode.ts

This file was deleted.

21 changes: 0 additions & 21 deletions packages/relay/src/lib/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,27 +80,6 @@ export class Block {
}
}

export class CachedBlock extends Block {
public readonly parentBlock:Block|null;
public readonly transactionHashes:string[] = [];

constructor(parentBlock:(null | Block), transactionHash:(string|null), args?:any) {
super(args);
this.parentBlock = parentBlock;

const num = parentBlock == null ? 0 : parentBlock.getNum() + 1;
this.number = '0x' + Number(num).toString(16);
this.parentHash = parentBlock == null ? '0x0' : parentBlock.hash;
if (transactionHash) {
this.transactionHashes.push(transactionHash);
}

const numberAsString = num.toString();
const baseHash = "0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b";
this.hash = baseHash.slice(0, baseHash.length - numberAsString.length) + numberAsString;
}
}

export class Receipt {
public readonly transactionHash:string;
public readonly transactionIndex:string;
Expand Down
4 changes: 0 additions & 4 deletions packages/relay/src/lib/relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import { NetImpl } from './net';
import { EthImpl } from './eth';
import { AccountId, Client, PrivateKey } from '@hashgraph/sdk';
import { Logger } from 'pino';
import { MirrorNode } from './mirrorNode';
import { MirrorNodeClient, SDKClient } from './clients';
import { Registry } from 'prom-client';

Expand Down Expand Up @@ -57,8 +56,6 @@ export class RelayImpl implements Relay {
this.web3Impl = new Web3Impl(this.clientMain);
this.netImpl = new NetImpl(this.clientMain, chainId);

const mirrorNode = new MirrorNode(logger.child({ name: `mirror-node` }));

const mirrorNodeClient = new MirrorNodeClient(
process.env.MIRROR_NODE_URL || '',
logger.child({ name: `mirror-node` }),
Expand All @@ -69,7 +66,6 @@ export class RelayImpl implements Relay {

this.ethImpl = new EthImpl(
sdkClient,
mirrorNode,
mirrorNodeClient,
logger.child({ name: 'relay-eth' }),
chainId);
Expand Down
Loading

0 comments on commit c4862e7

Please sign in to comment.