Skip to content

Commit 0485787

Browse files
feat: add Golang tests to workflow (#2679)
* feat: added option to run Golang JSON RPC methods against local node & added Golang JSON RPC workflow (#2681) Signed-off-by: Marcin Piela (ArianeLabs) <[email protected]> * feat: separated HTTP & WSS tests for Golang JSON RPC workflow (#2681) Signed-off-by: Marcin Piela (ArianeLabs) <[email protected]> * feat: changed comment in .env.example (#2681) Signed-off-by: Marcin Piela (ArianeLabs) <[email protected]> --------- Signed-off-by: Marcin Piela (ArianeLabs) <[email protected]>
1 parent 8b42df2 commit 0485787

File tree

6 files changed

+32
-6
lines changed

6 files changed

+32
-6
lines changed

.github/workflows/dev-tool-test.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,17 @@ jobs:
3434
with:
3535
command: cd ./tools/web3js-example/ && npm run test
3636
directory: ./tools/web3js-example
37+
38+
golang-http:
39+
name: Golang HTTP
40+
uses: ./.github/workflows/dev-tool-workflow.yml
41+
with:
42+
command: cd ./tools/golang-json-rpc-tests/ && go run .
43+
directory: ./tools/golang-json-rpc-tests
44+
45+
golang-wss:
46+
name: Golang WSS
47+
uses: ./.github/workflows/dev-tool-workflow.yml
48+
with:
49+
command: cd ./tools/golang-json-rpc-tests/ && go run . --wss
50+
directory: ./tools/golang-json-rpc-tests

.github/workflows/dev-tool-workflow.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ jobs:
3232
- name: Checkout repo
3333
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
3434

35+
- name: Install go
36+
uses: actions/setup-go@v5
37+
with:
38+
go-version: '1.22.3'
39+
3540
- name: Install packages
3641
run: npm ci
3742

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# all available private keys can be found here https://github.com/hashgraph/hedera-local-node#commands
2+
OPERATOR_PRIVATE_KEY=0x105d050185ccb907fba04dd92d8de9e32c18305e097ab41dadda21489a211524
3+
RELAY_ENDPOINT='http://localhost:7546'

tools/golang-json-rpc-tests/.env.sample

Lines changed: 0 additions & 3 deletions
This file was deleted.

tools/golang-json-rpc-tests/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ go get github.com/ethereum/go-ethereum/ethclient \
3434

3535
5. Copy `.env.example` to `.env`
3636

37-
6. Run the test script from the root directory of the project. The default network is set to "testnet".
37+
6. Run the test script from the root directory of the project. The default network is set through the `RELAY_ENDPOINT` environment variable.
3838

3939
```shell
4040
go run .
@@ -46,12 +46,14 @@ go get github.com/ethereum/go-ethereum/ethclient \
4646
go run . --wss
4747
```
4848

49-
To run tests on mainnet or previewnet run one of the following commands:
49+
To run tests on mainnet, previewnet or testnet run one of the following commands:
5050
```shell
5151
go run . --mainnet
5252
go run . --previewnet
53+
go run . --testnet
5354
go run . --mainnet --wss
5455
go run . --previewnet --wss
56+
go run . --testnet --wss
5557
```
5658

5759
# Deployment of SampleContract During Tests

tools/golang-json-rpc-tests/main.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func main() {
5353
}
5454
mainnet := flag.Bool("mainnet", false, "Use mainnet network")
5555
previewnet := flag.Bool("previewnet", false, "Use previewnet network")
56+
testnet := flag.Bool("testnet", false, "Use testnet network")
5657
wss := flag.Bool("wss", false, "Enable WebSocket Secure protocol")
5758
privateKeyHex := os.Getenv("OPERATOR_PRIVATE_KEY")
5859

@@ -63,12 +64,16 @@ func main() {
6364
endpointUrl = mainnetEndpoint
6465
case *previewnet:
6566
endpointUrl = previewnetEndpoint
66-
default:
67+
case *testnet:
6768
endpointUrl = testnetEndpoint
69+
default:
70+
endpointUrl = os.Getenv("RELAY_ENDPOINT")
6871
}
6972
if *wss {
73+
endpointUrl = strings.Replace(endpointUrl, "http://", "ws://", 1)
7074
endpointUrl = strings.Replace(endpointUrl, "https://", "wss://", 1)
7175
endpointUrl = strings.Replace(endpointUrl, "/api", "/ws", 1)
76+
endpointUrl = strings.Replace(endpointUrl, ":7546", ":8546", 1)
7277
}
7378
client, err := ethclient.Dial(endpointUrl)
7479
if err != nil {

0 commit comments

Comments
 (0)