-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Аdd k6 performance tests for WS server (#2803)
* fix: prep.js is not working with ethers v6 Signed-off-by: Victor Yanev <[email protected]> * test: add k6 performance tests for WS server Signed-off-by: Victor Yanev <[email protected]> * fix: prep.js Signed-off-by: Victor Yanev <[email protected]> * fix: response checks Signed-off-by: Victor Yanev <[email protected]> * Update k6/src/prepare/contracts/Greeter.sol Co-authored-by: Logan Nguyen <[email protected]> Signed-off-by: Eric Badiere <[email protected]> --------- Signed-off-by: Victor Yanev <[email protected]> Signed-off-by: Eric Badiere <[email protected]> Co-authored-by: Eric Badiere <[email protected]> Co-authored-by: Logan Nguyen <[email protected]>
- Loading branch information
1 parent
8245f51
commit fe0c21f
Showing
25 changed files
with
433 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
src/prepare/.smartContractParams.json |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
|
||
contract Greeter { | ||
string private greeting; | ||
|
||
event GreetingSet(string greeting); | ||
|
||
constructor(string memory _greeting) { | ||
greeting = _greeting; | ||
|
||
emit GreetingSet(_greeting); | ||
} | ||
|
||
function greet() public view returns (string memory) { | ||
return greeting; | ||
} | ||
|
||
function setGreeting(string memory _greeting) public { | ||
greeting = _greeting; | ||
|
||
emit GreetingSet(_greeting); | ||
} | ||
} |
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 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,95 @@ | ||
/*- | ||
* | ||
* Hedera JSON RPC Relay | ||
* | ||
* Copyright (C) 2022-2024 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 ws from 'k6/ws'; | ||
import { check } from 'k6'; | ||
|
||
const errorField = 'error'; | ||
const resultField = 'result'; | ||
|
||
const isDebugMode = __ENV['DEBUG_MODE'] === 'true'; | ||
|
||
let requestId = 1; | ||
|
||
function getPayLoad(methodName, paramInput = []) { | ||
return JSON.stringify({ | ||
id: requestId++, | ||
jsonrpc: '2.0', | ||
method: methodName, | ||
params: paramInput, | ||
}); | ||
} | ||
|
||
function connectToWebSocket(url, methodName, params = [], responseChecks = {}) { | ||
return ws.connect(url, {}, (socket) => { | ||
socket.on('open', () => { | ||
const message = getPayLoad(methodName, params); | ||
if (isDebugMode) { | ||
console.log('Connected, sending request: ' + message); | ||
} | ||
socket.send(message); | ||
|
||
socket.on('message', (message) => { | ||
check(message, responseChecks); | ||
socket.close(); | ||
}); | ||
}); | ||
|
||
socket.on('close', function () { | ||
if (isDebugMode) { | ||
console.log('Disconnected'); | ||
} | ||
}); | ||
|
||
socket.on('error', (e) => { | ||
if (isDebugMode) { | ||
console.error('Received WebSocketError:', e); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
function isNonErrorResponse(message) { | ||
try { | ||
const response = JSON.parse(message); | ||
const success = response.hasOwnProperty(resultField) && !response.hasOwnProperty(errorField); | ||
if (isDebugMode) { | ||
console.log(`isNonErrorResponse: message=${message}, result=${success}`); | ||
} | ||
return success; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
|
||
function isErrorResponse(message) { | ||
try { | ||
const response = JSON.parse(message); | ||
const success = response.hasOwnProperty(errorField) && !response.hasOwnProperty(resultField); | ||
if (isDebugMode) { | ||
console.log(`isErrorResponse: message=${message}, result=${success}`); | ||
} | ||
return success; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
|
||
export { connectToWebSocket, isNonErrorResponse, isErrorResponse }; |
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,37 @@ | ||
/*- | ||
* | ||
* Hedera JSON RPC Relay | ||
* | ||
* Copyright (C) 2022-2024 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 { TestScenarioBuilder } from '../../lib/common.js'; | ||
import { connectToWebSocket, isNonErrorResponse } from './common.js'; | ||
|
||
const url = __ENV.WS_RELAY_BASE_URL; | ||
const methodName = 'eth_chainId'; | ||
|
||
const { options, run } = new TestScenarioBuilder() | ||
.name(methodName) // use unique scenario name among all tests | ||
.request(() => connectToWebSocket( | ||
url, | ||
methodName, | ||
[], | ||
{ methodName: (r) => isNonErrorResponse(r) } | ||
)) | ||
.build(); | ||
|
||
export { options, run }; |
Oops, something went wrong.