Skip to content

Commit d61a89b

Browse files
Update logic to point acceptance tests to remote relay (#224)
* Update logic to point acceptance tests to remote relay Update acceptance tests logic to point to remote instances - Add `E2E_RELAY_HOST` config - Update tests to use a smaller balance for new accounts - Update balance test expected value - Update README with instructions Signed-off-by: Nana-EC <[email protected]> Signed-off-by: Daniel Ivanov <[email protected]> Co-authored-by: Daniel Ivanov <[email protected]>
1 parent 75625e1 commit d61a89b

File tree

5 files changed

+25
-17
lines changed

5 files changed

+25
-17
lines changed

.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ OPERATOR_KEY_MAIN=
44
OPERATOR_ID_ETH_SENDRAWTRANSACTION=
55
OPERATOR_KEY_ETH_SENDRAWTRANSACTION=
66
CHAIN_ID=
7-
MIRROR_NODE_URL=
7+
MIRROR_NODE_URL=
8+
E2E_RELAY_HOST=

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,11 @@ CHAIN_ID=0x12a
6565
MIRROR_NODE_URL=http://127.0.0.1:5551
6666
LOCAL_NODE=true
6767
SERVER_PORT=7546
68+
E2E_RELAY_HOST=http://127.0.0.1:7546
6869
```
6970

71+
> **_NOTE:_** Acceptance tests can be pointed at a remote location. In this case be sure to appropriately update these values to point away from your local host and to valid deployed services.
72+
7073
#### Run
7174

7275
Tests may be run using the following command

packages/server/tests/acceptance/rpc.spec.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ const NETWORK = process.env.HEDERA_NETWORK || '';
6767
const OPERATOR_KEY = process.env.OPERATOR_KEY_MAIN || '';
6868
const OPERATOR_ID = process.env.OPERATOR_ID_MAIN || '';
6969
const MIRROR_NODE_URL = process.env.MIRROR_NODE_URL || '';
70-
const RELAY_URL = 'http://localhost:7546';
70+
const LOCAL_RELAY_URL = 'http://localhost:7546';
71+
const RELAY_URL = process.env.E2E_RELAY_HOST || LOCAL_RELAY_URL;
7172
const ONE_TINYBAR = ethers.utils.parseUnits('1', 10);
7273
const NON_EXISTING_ADDRESS = '0x5555555555555555555555555555555555555555';
7374

@@ -87,9 +88,9 @@ describe('RPC Server Acceptance Tests', function() {
8788
runLocalHederaNetwork();
8889
}
8990

90-
// start relay
91-
logger.info(`Start relay on port ${process.env.SERVER_PORT}`);
92-
relayServer = app.listen({ port: process.env.SERVER_PORT });
91+
if (RELAY_URL === LOCAL_RELAY_URL) {
92+
runLocalRelay();
93+
}
9394

9495
accounts[0] = await servicesNode.createAliasAccount();
9596
accounts[1] = await servicesNode.createAliasAccount();
@@ -316,7 +317,7 @@ describe('RPC Server Acceptance Tests', function() {
316317
});
317318

318319
it('should execute "eth_getTransactionCount" for account with non-zero nonce', async function() {
319-
const account = await servicesNode.createAliasAccount();
320+
const account = await servicesNode.createAliasAccount(10);
320321
// Wait for account creation to propagate
321322
await mirrorNode.get(`/accounts/${account.accountId}`);
322323
const transaction = {
@@ -348,16 +349,16 @@ describe('RPC Server Acceptance Tests', function() {
348349
expect(res).to.be.equal('0xa7a3582000');
349350
});
350351

351-
it('should execute "eth_getBalance" for newly created account with 1000 HBAR', async function() {
352-
const account = await servicesNode.createAliasAccount(1000);
352+
it('should execute "eth_getBalance" for newly created account with 100 HBAR', async function() {
353+
const account = await servicesNode.createAliasAccount(100);
353354
// Wait for account creation to propagate
354355
await mirrorNode.get(`/accounts/${account.accountId}`);
355356

356357
const res = await relay.call('eth_getBalance', [account.address, 'latest']);
357358
const balance = await servicesNode.executeQuery(new AccountBalanceQuery()
358359
.setAccountId(account.accountId));
359360
const balanceInWeiBars = BigNumber.from(balance.hbars.toTinybars().toString()).mul(10 ** 10);
360-
expect(res).to.eq(ethers.utils.hexlify(balanceInWeiBars));
361+
expect(res).to.eq(ethers.utils.hexValue(balanceInWeiBars));
361362
});
362363

363364
it('should execute "eth_getBalance" for non-existing address', async function() {
@@ -501,4 +502,11 @@ describe('RPC Server Acceptance Tests', function() {
501502
shell.exec('npx hedera-local restart');
502503
logger.trace('Hedera Hashgraph local node env started');
503504
}
504-
});
505+
506+
function runLocalRelay() {
507+
// start relay
508+
logger.info(`Start relay on port ${process.env.SERVER_PORT}`);
509+
relayServer = app.listen({ port: process.env.SERVER_PORT });
510+
}
511+
512+
});

packages/server/tests/helpers/assertions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
*/
2020
import { expect } from 'chai';
21-
import { Utils } from './utils';
21+
import { ethers } from 'ethers';
2222

2323
export default class Assertions {
2424

@@ -40,13 +40,13 @@ export default class Assertions {
4040

4141
public static block(relayResponse, mirrorNodeResponse) {
4242
expect(relayResponse.hash).to.be.equal(mirrorNodeResponse.hash.slice(0, 66));
43-
expect(relayResponse.number).to.be.equal(Utils.numberTo0x(mirrorNodeResponse.number));
43+
expect(relayResponse.number).to.be.equal(ethers.utils.hexValue(mirrorNodeResponse.number));
4444
// expect(relayResponse.transactions.length).to.equal(mirrorNodeResponse.count); // FIXME this assertion fails
4545
}
4646

4747
public static transaction(relayResponse, mirrorNodeResponse) {
4848
expect(relayResponse.blockHash).to.eq(mirrorNodeResponse.block_hash.slice(0, 66));
49-
expect(relayResponse.blockNumber).to.eq(Utils.numberTo0x(mirrorNodeResponse.block_number));
49+
expect(relayResponse.blockNumber).to.eq(ethers.utils.hexValue(mirrorNodeResponse.block_number));
5050
// expect(relayResponse.chainId).to.eq(mirrorNodeResponse.chain_id); // FIXME must not be null!
5151
expect(relayResponse.from).to.eq(mirrorNodeResponse.from);
5252
expect(relayResponse.gas).to.eq(mirrorNodeResponse.gas_used);

packages/server/tests/helpers/utils.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ export class Utils {
2727
return parseInt(num).toString(16);
2828
};
2929

30-
static numberTo0x = (input: number): string => {
31-
return `0x${Utils.toHex(input)}`;
32-
};
33-
3430
static idToEvmAddress = (id): string => {
3531
Assertions.assertId(id);
3632
const [shard, realm, num] = id.split('.');

0 commit comments

Comments
 (0)