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

Ensure acceptance tests run on previewnet/testnet #351

Merged
merged 7 commits into from
Jul 20, 2022
Merged
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ E2E_RELAY_HOST=http://127.0.0.1:7546

The following table highlights some initial configuration values to consider

| Config | Default | Description |
| ------------|-------|-----------------------|
| `CHAIN_ID` | `0x12a` | The netowrk chain id. Local and previewnet envs should use `0x12a`. Mainnet and Testnet should use `0x127` and `0x128` respectively |
| Config | Default | Description |
| ------------|-------|---------------------------------------------------------------------------------------------------------------------------------------------------|
| `CHAIN_ID` | `0x12a` | The netowrk chain id. Local and previewnet envs should use `0x12a`. Mainnet, Testnet and Previewnet should use `0x127`, `0x128` and `0x129` respectively |

> **_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.

Expand Down
4 changes: 2 additions & 2 deletions packages/relay/tests/lib/mirrorNodeClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import pino from 'pino';
const logger = pino();

describe('MirrorNodeClient', async function () {
this.timeout(10000);
this.timeout(20000);

// mock axios
const instance = axios.create({
Expand All @@ -40,7 +40,7 @@ describe('MirrorNodeClient', async function () {
headers: {
'Content-Type': 'application/json'
},
timeout: 10 * 1000
timeout: 20 * 1000
});
const mock = new MockAdapter(instance);
const mirrorNodeInstance = new MirrorNodeClient(process.env.MIRROR_NODE_URL, logger.child({ name: `mirror-node` }), instance);
Expand Down
4 changes: 2 additions & 2 deletions packages/server/tests/acceptance/erc20.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ describe('ERC20 Acceptance Tests', async function () {

before(async () => {
accounts[0] = await servicesNode.createAliasAccount(30, relay.provider);
accounts[1] = await servicesNode.createAliasAccount(10, relay.provider);
accounts[2] = await servicesNode.createAliasAccount(10, relay.provider);
accounts[1] = await servicesNode.createAliasAccount(15, relay.provider);
accounts[2] = await servicesNode.createAliasAccount(15, relay.provider);

initialHolder = accounts[0].address;
recipient = accounts[1].address;
Expand Down
172 changes: 110 additions & 62 deletions packages/server/tests/acceptance/rpc.spec.ts

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions packages/server/tests/clients/relayClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,10 @@ export default class RelayClient {
return this.provider.send('eth_sendRawTransaction', [signedTx]);
};

/**
* Returns the result of eth_gasPrice as a Number.
*/
async gasPrice(): Promise<number> {
return Number(await this.call('eth_gasPrice', []));
}
}
10 changes: 9 additions & 1 deletion packages/server/tests/clients/servicesClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,15 @@ export default class ServicesClient {
const expiration = new Date();
expiration.setDate(expiration.getDate() + 30);

const htsClient = Client.forNetwork(JSON.parse(this.network));
let network = this.network;
try {
network = JSON.parse(this.network);
}
catch(e) {
// network config is a string and not a valid JSON
}

const htsClient = Client.forNetwork(network);
htsClient.setOperator(AccountId.fromString(args.treasuryAccountId), args.adminPrivateKey);

const tokenCreate = await (await new TokenCreateTransaction()
Expand Down
18 changes: 14 additions & 4 deletions packages/server/tests/helpers/assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
*/
import { expect } from 'chai';
import { ethers } from 'ethers';
import { ethers, BigNumber } from 'ethers';
import { JsonRpcError, predefined } from '../../../relay/src/lib/errors';
import { Utils } from './utils';

Expand Down Expand Up @@ -59,7 +59,15 @@ export default class Assertions {
*/
public static block(relayResponse, mirrorNodeResponse, mirrorTransactions, hydratedTransactions = false) {
// Assert static values
expect(relayResponse.baseFeePerGas).to.be.equal(ethers.utils.hexValue(this.defaultGasPrice));
expect(relayResponse.baseFeePerGas).to.exist;

if (process.env.LOCAL_NODE && process.env.LOCAL_NODE !== 'false') {
expect(relayResponse.baseFeePerGas).to.be.equal(ethers.utils.hexValue(this.defaultGasPrice));
}
else {
expect(Number(relayResponse.baseFeePerGas)).to.be.gt(0);
}

expect(relayResponse.difficulty).to.be.equal(ethers.utils.hexValue(0));
expect(relayResponse.extraData).to.be.equal(Assertions.emptyHex);
expect(relayResponse.miner).to.be.equal(ethers.constants.AddressZero);
Expand Down Expand Up @@ -125,7 +133,9 @@ export default class Assertions {
// expect(relayResponse.gasPrice).to.eq(mirrorNodeResponse.gas_price); // FIXME must not be null!
expect(relayResponse.hash).to.eq(mirrorNodeResponse.hash.slice(0, 66));
expect(relayResponse.input).to.eq(mirrorNodeResponse.function_parameters);
expect(relayResponse.to).to.eq(mirrorNodeResponse.to);
if (relayResponse.to || mirrorNodeResponse.to) {
expect(relayResponse.to).to.eq(mirrorNodeResponse.to);
}
expect(relayResponse.transactionIndex).to.eq(ethers.utils.hexValue(mirrorNodeResponse.transaction_index));
expect(relayResponse.value).to.eq(ethers.utils.hexValue(mirrorNodeResponse.amount));
}
Expand Down Expand Up @@ -164,7 +174,7 @@ export default class Assertions {
? mirrorResult.gas_price
: mirrorResult.max_fee_per_gas;
const mirrorEffectiveGasPrice = Utils.tinyBarsToWeibars(effectiveGas);
expect(transactionReceipt.effectiveGasPrice).to.eq(mirrorEffectiveGasPrice);
expect(BigNumber.from(transactionReceipt.effectiveGasPrice).toString()).to.eq(mirrorEffectiveGasPrice.toString());

expect(transactionReceipt.status).to.exist;
expect(transactionReceipt.status).to.eq(mirrorResult.status);
Expand Down