-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor acceptance tests structure (#211)
* refactor: overall refactor of acceptance structure Signed-off-by: Ivo Yankov <ivo@devlabs.bg> * fix: correctly load env for integration tests Signed-off-by: Ivo Yankov <ivo@devlabs.bg> * chore: test refactoring Signed-off-by: Daniel Ivanov <daniel.k.ivanov95@gmail.com> * chore: test refactoring Signed-off-by: Daniel Ivanov <daniel.k.ivanov95@gmail.com> * chore: enable part of the acceptance tests Signed-off-by: Daniel Ivanov <daniel.k.ivanov95@gmail.com> * chore: remove invalid child logger Signed-off-by: Daniel Ivanov <daniel.k.ivanov95@gmail.com> * chore: test-cicd Signed-off-by: Daniel Ivanov <daniel.k.ivanov95@gmail.com> * feat: partially enable acceptance tests Signed-off-by: Daniel Ivanov <daniel.k.ivanov95@gmail.com> * feat: fix more tests Signed-off-by: Daniel Ivanov <daniel.k.ivanov95@gmail.com> * chore: remove unused methods Signed-off-by: Daniel Ivanov <daniel.k.ivanov95@gmail.com> * chore: enable more tests Signed-off-by: Daniel Ivanov <daniel.k.ivanov95@gmail.com> * chore: enable more tests Signed-off-by: Daniel Ivanov <daniel.k.ivanov95@gmail.com> * feat: fix all tests Signed-off-by: Daniel Ivanov <daniel.k.ivanov95@gmail.com> * feat: resolve comments Signed-off-by: Daniel Ivanov <daniel.k.ivanov95@gmail.com> * feat: resolve last comment Signed-off-by: Daniel Ivanov <daniel.k.ivanov95@gmail.com> Co-authored-by: Daniel Ivanov <daniel.k.ivanov95@gmail.com>
- Loading branch information
1 parent
94328ad
commit 75625e1
Showing
12 changed files
with
1,091 additions
and
1,004 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/*- | ||
* | ||
* Hedera JSON RPC Relay | ||
* | ||
* Copyright (C) 2022 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
import Axios, { AxiosInstance } from 'axios'; | ||
import axiosRetry from 'axios-retry'; | ||
import { Logger } from 'pino'; | ||
|
||
export default class MirrorClient { | ||
|
||
private readonly logger: Logger; | ||
private readonly client: AxiosInstance; | ||
|
||
constructor(mirrorNodeUrl: string, logger: Logger) { | ||
this.logger = logger; | ||
|
||
const mirrorNodeClient = Axios.create({ | ||
baseURL: `${mirrorNodeUrl}/api/v1`, | ||
responseType: 'json' as const, | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
method: 'GET', | ||
timeout: 5 * 1000 | ||
}); | ||
|
||
// allow retries given mirror node waits for consensus, record stream serialization, export and import before parsing and exposing | ||
axiosRetry(mirrorNodeClient, { | ||
retries: 5, | ||
retryDelay: (retryCount) => { | ||
this.logger.info(`Retry delay ${retryCount * 1000} s`); | ||
return retryCount * 1000; | ||
}, | ||
retryCondition: (error) => { | ||
this.logger.error(error, `Request failed`); | ||
|
||
// if retry condition is not specified, by default idempotent requests are retried | ||
return error?.response?.status === 400 || error?.response?.status === 404; | ||
} | ||
}); | ||
|
||
this.client = mirrorNodeClient; | ||
} | ||
|
||
async get(path: string) { | ||
this.logger.debug(`[GET] MirrorNode ${path} endpoint`); | ||
return (await this.client.get(path)).data; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/*- | ||
* | ||
* Hedera JSON RPC Relay | ||
* | ||
* Copyright (C) 2022 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
import { ethers, providers } from 'ethers'; | ||
import { Logger } from 'pino'; | ||
import Assertions from '../helpers/assertions'; | ||
|
||
export default class RelayClient { | ||
|
||
private readonly provider: providers.JsonRpcProvider; | ||
private readonly logger: Logger; | ||
|
||
constructor(relayUrl: string, logger: Logger) { | ||
this.logger = logger; | ||
this.provider = new ethers.providers.JsonRpcProvider(relayUrl); | ||
} | ||
|
||
/** | ||
* Calls the specified methodName with the provided params | ||
* @param methodName | ||
* @param params | ||
*/ | ||
async call(methodName: string, params: any[]) { | ||
const result = await this.provider.send(methodName, params); | ||
this.logger.trace(`[POST] to relay '${methodName}' with params [${params}] returned ${JSON.stringify(result)}`); | ||
return result; | ||
}; | ||
|
||
/** | ||
* Calls the specified methodName with the provided params and asserts that it fails | ||
* @param methodName | ||
* @param params | ||
*/ | ||
async callFailing(methodName: string, params: any[]) { | ||
try { | ||
const res = await this.call(methodName, params); | ||
this.logger.trace(`[POST] to relay '${methodName}' with params [${params}] returned ${JSON.stringify(res)}`); | ||
Assertions.expectedError(); | ||
} catch (err) { | ||
Assertions.unknownResponse(err); | ||
} | ||
} | ||
|
||
/** | ||
* Calls the specified methodName and asserts that it is not supported | ||
* @param methodName | ||
* @param params | ||
*/ | ||
async callUnsupported(methodName: string, params: any[]) { | ||
try { | ||
const res = await this.call(methodName, params); | ||
this.logger.trace(`[POST] to relay '${methodName}' with params [${params}] returned ${JSON.stringify(res)}`); | ||
Assertions.expectedError(); | ||
} catch (err) { | ||
Assertions.unsupportedResponse(err); | ||
return err; | ||
} | ||
}; | ||
|
||
/** | ||
* Gets the account balance by executing `eth_getBalance` | ||
* @param address | ||
* @param block | ||
*/ | ||
async getBalance(address, block = 'latest') { | ||
this.logger.debug(`[POST] to relay eth_getBalance for address ${address}]`); | ||
return this.provider.getBalance(address, block); | ||
}; | ||
|
||
/** | ||
* @param evmAddress | ||
* | ||
* Returns: The nonce of the account with the provided `evmAddress` | ||
*/ | ||
async getAccountNonce(evmAddress): Promise<number> { | ||
this.logger.debug(`[POST] to relay for eth_getTransactionCount for address ${evmAddress}`); | ||
const nonce = await this.provider.send('eth_getTransactionCount', [evmAddress, 'latest']); | ||
return Number(nonce); | ||
}; | ||
|
||
/** | ||
* This invokes the relay logic from eth.ts/sendRawTransaction. | ||
* | ||
* Returns: Transaction hash | ||
* @param signedTx | ||
*/ | ||
async sendRawTransaction(signedTx): Promise<string> { | ||
this.logger.debug(`[POST] to relay for eth_sendRawTransaction`); | ||
return this.provider.send('eth_sendRawTransaction', [signedTx]); | ||
}; | ||
|
||
} |
Oops, something went wrong.