Skip to content

Commit

Permalink
feat: added option to run Golang JSON RPC methods against local node …
Browse files Browse the repository at this point in the history
…& added Golang JSON RPC workflow

Signed-off-by: Marcin Piela (ArianeLabs) <marcin.piela@arianelabs.com>
  • Loading branch information
marcin-piela-ariane committed Jul 5, 2024
1 parent 892d69e commit 0749691
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 6 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/dev-tool-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,10 @@ jobs:
with:
command: cd ./tools/web3js-example/ && npm run test
directory: ./tools/web3js-example

golang:
name: Golang
uses: ./.github/workflows/dev-tool-workflow.yml
with:
command: cd ./tools/golang-json-rpc-tests/ && go run . && go run . --wss
directory: ./tools/golang-json-rpc-tests
5 changes: 5 additions & 0 deletions .github/workflows/dev-tool-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ jobs:
- name: Checkout repo
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6

- name: Install go
uses: actions/setup-go@v5
with:
go-version: '1.22.3'

- name: Install packages
run: npm ci

Expand Down
4 changes: 4 additions & 0 deletions tools/golang-json-rpc-tests/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# The operator private keys start with "0x" and are in hexadecimal format
# Your account alias ECDSA hex-encoded private key (Ex: 0xb46751179bc8aa9e129d34463e46cd...)
OPERATOR_PRIVATE_KEY=0x105d050185ccb907fba04dd92d8de9e32c18305e097ab41dadda21489a211524
RELAY_ENDPOINT='http://localhost:7546'
3 changes: 0 additions & 3 deletions tools/golang-json-rpc-tests/.env.sample

This file was deleted.

6 changes: 4 additions & 2 deletions tools/golang-json-rpc-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ go get github.com/ethereum/go-ethereum/ethclient \

5. Copy `.env.example` to `.env`

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

```shell
go run .
Expand All @@ -46,12 +46,14 @@ go get github.com/ethereum/go-ethereum/ethclient \
go run . --wss
```

To run tests on mainnet or previewnet run one of the following commands:
To run tests on mainnet, previewnet or testnet run one of the following commands:
```shell
go run . --mainnet
go run . --previewnet
go run . --testnet
go run . --mainnet --wss
go run . --previewnet --wss
go run . --testnet --wss
```

# Deployment of SampleContract During Tests
Expand Down
7 changes: 6 additions & 1 deletion tools/golang-json-rpc-tests/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func main() {
}
mainnet := flag.Bool("mainnet", false, "Use mainnet network")
previewnet := flag.Bool("previewnet", false, "Use previewnet network")
testnet := flag.Bool("testnet", false, "Use testnet network")
wss := flag.Bool("wss", false, "Enable WebSocket Secure protocol")
privateKeyHex := os.Getenv("OPERATOR_PRIVATE_KEY")

Expand All @@ -63,12 +64,16 @@ func main() {
endpointUrl = mainnetEndpoint
case *previewnet:
endpointUrl = previewnetEndpoint
default:
case *testnet:
endpointUrl = testnetEndpoint
default:
endpointUrl = os.Getenv("RELAY_ENDPOINT")
}
if *wss {
endpointUrl = strings.Replace(endpointUrl, "http://", "ws://", 1)
endpointUrl = strings.Replace(endpointUrl, "https://", "wss://", 1)
endpointUrl = strings.Replace(endpointUrl, "/api", "/ws", 1)
endpointUrl = strings.Replace(endpointUrl, ":7546", ":8546", 1)
}
client, err := ethclient.Dial(endpointUrl)
if err != nil {
Expand Down

0 comments on commit 0749691

Please sign in to comment.