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

feat: add Golang tests to workflow #2679

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
14 changes: 14 additions & 0 deletions .github/workflows/dev-tool-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,17 @@ jobs:
with:
command: cd ./tools/web3js-example/ && npm run test
directory: ./tools/web3js-example

golang-http:
name: Golang HTTP
uses: ./.github/workflows/dev-tool-workflow.yml
with:
command: cd ./tools/golang-json-rpc-tests/ && go run .
directory: ./tools/golang-json-rpc-tests

golang-wss:
name: Golang WSS
uses: ./.github/workflows/dev-tool-workflow.yml
with:
command: cd ./tools/golang-json-rpc-tests/ && 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'

acuarica marked this conversation as resolved.
Show resolved Hide resolved
- 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
quiet-node marked this conversation as resolved.
Show resolved Hide resolved
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
Loading