-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from skalenetwork/add-network-browser-tests
Add test pipeline for network-browser module
- Loading branch information
Showing
23 changed files
with
578 additions
and
33 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,28 @@ | ||
name: network-browser test | ||
on: [push, pull_request] | ||
env: | ||
ETH_PRIVATE_KEY: ${{ secrets.ETH_PRIVATE_KEY }} | ||
MANAGER_TAG: "1.9.3-beta.0" | ||
jobs: | ||
test_network_browser: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
submodules: true | ||
- uses: oven-sh/setup-bun@v1 | ||
- name: Launch hardhat node | ||
working-directory: hardhat-node | ||
run: docker-compose up -d | ||
- name: Deploy manager contracts | ||
run: | | ||
bash ./helper-scripts/deploy_test_manager.sh | ||
docker rmi -f skalenetwork/skale-manager:${{ env.MANAGER_TAG }} | ||
- name: Install network-browser dependencies | ||
working-directory: network-browser | ||
run: bun i | ||
|
||
- name: Run network-browser tests | ||
working-directory: network-browser | ||
run: bash run_tests.sh |
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 |
---|---|---|
@@ -1,3 +1,9 @@ | ||
[submodule "IMA"] | ||
path = IMA | ||
url = https://github.com/skalenetwork/IMA.git | ||
[submodule "hardhat-node"] | ||
path = hardhat-node | ||
url = https://github.com/skalenetwork/hardhat-node.git | ||
[submodule "helper-scripts"] | ||
path = helper-scripts | ||
url = https://github.com/skalenetwork/helper-scripts.git |
Submodule hardhat-node
added at
8a4b03
Submodule helper-scripts
added at
34adbe
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
Binary file not shown.
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,16 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | ||
|
||
export IMA_NETWORK_BROWSER_DATA_PATH="$DIR/test_schainsData.json" | ||
export SCHAIN_PROXY_PATH="$DIR/test_ima_schain.json" | ||
export MANAGER_ABI_PATH="$DIR/../helper-scripts/contracts_data/manager.json" | ||
|
||
export MAINNET_RPC_URL="http://127.0.0.1:8545" | ||
export SCHAIN_RPC_URL="http://127.0.0.1:8545" | ||
export SCHAIN_NAME="test" | ||
export CONNECTED_ONLY=false | ||
|
||
bun test |
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
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.
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,98 @@ | ||
import { unlinkSync, existsSync } from 'node:fs' | ||
import { describe, beforeAll, test, expect, beforeEach } from 'bun:test' | ||
import { Contract, Wallet } from 'ethers' | ||
|
||
import { | ||
getMainnetProvider, | ||
nodesContract, | ||
getMainnetManagerAbi, | ||
schainsInternalContract | ||
} from '../src/contracts' | ||
import { browse } from '../src/browser' | ||
import { getSChain } from '../src/schains' | ||
import { readJson } from '../src/tools' | ||
import { NetworkBrowserData } from '../src/interfaces' | ||
import { MAINNET_RPC_URL, IMA_NETWORK_BROWSER_DATA_PATH } from '../src/constants' | ||
|
||
import { | ||
ETH_PRIVATE_KEY, | ||
NODES_IN_SCHAIN, | ||
validatorsContract, | ||
managerContract, | ||
schainsContract, | ||
addAllPermissions, | ||
generateWallets, | ||
initDefaultValidator, | ||
linkNodes, | ||
registerNodes, | ||
addTestSchainTypes, | ||
createSchain, | ||
randomString | ||
} from './testUtils' | ||
|
||
describe('browser module test', () => { | ||
let nodes: Contract | ||
let schainsInternal: Contract | ||
let wallet: Wallet | ||
const chainName = randomString() | ||
|
||
beforeAll(async () => { | ||
console.log('initializing provider and contracts') | ||
const provider = await getMainnetProvider(MAINNET_RPC_URL, false) | ||
wallet = new Wallet(ETH_PRIVATE_KEY, provider) | ||
|
||
const managerAbi = getMainnetManagerAbi() | ||
const validators = validatorsContract(managerAbi, wallet) | ||
schainsInternal = schainsInternalContract(managerAbi, wallet) | ||
const schains = schainsContract(managerAbi, wallet) | ||
const manager = managerContract(managerAbi, wallet) | ||
|
||
nodes = nodesContract(managerAbi, provider) | ||
|
||
await addAllPermissions(validators, schainsInternal, schains, wallet) | ||
await initDefaultValidator(validators) | ||
const wallets = await generateWallets(provider, wallet, NODES_IN_SCHAIN) | ||
await linkNodes(validators, wallet, wallets) | ||
await registerNodes(nodes, wallets) | ||
|
||
await addTestSchainTypes(schainsInternal) | ||
await createSchain(schains, chainName, wallet.address) | ||
}) | ||
|
||
beforeEach(async () => { | ||
if (existsSync(IMA_NETWORK_BROWSER_DATA_PATH)) { | ||
console.log('removing browse results') | ||
unlinkSync(IMA_NETWORK_BROWSER_DATA_PATH) | ||
} | ||
}) | ||
|
||
test('browse', async () => { | ||
const schain = await getSChain(schainsInternal, chainName) | ||
expect(schain.name).toBe(chainName) | ||
expect(schain.mainnetOwner).toBe(wallet.address) | ||
|
||
expect(existsSync(IMA_NETWORK_BROWSER_DATA_PATH)).toBeFalse | ||
await browse(schainsInternal, nodes) | ||
expect(existsSync(IMA_NETWORK_BROWSER_DATA_PATH)).toBeTrue | ||
|
||
const nbData: NetworkBrowserData = readJson(IMA_NETWORK_BROWSER_DATA_PATH) | ||
|
||
expect(nbData.updatedAt).toBeNumber | ||
expect(nbData.schains).toBeArray | ||
expect(nbData.schains[0].name).toBeString | ||
expect(nbData.schains[0].mainnetOwner).toBeString | ||
expect(nbData.schains[0].indexInOwnerList).toBeString | ||
expect(nbData.schains[0].partOfNode).toBeString | ||
expect(nbData.schains[0].lifetime).toBeString | ||
expect(nbData.schains[0].startBlock).toBeString | ||
expect(nbData.schains[0].deposit).toBeString | ||
expect(nbData.schains[0].index).toBeString | ||
expect(nbData.schains[0].generation).toBeString | ||
expect(nbData.schains[0].chainId).toBeNumber | ||
expect(nbData.schains[0].nodes).toBeArrayOfSize(NODES_IN_SCHAIN) | ||
if (nbData.schains[0].nodes) { | ||
expect(nbData.schains[0].nodes[0].endpoints?.domain.https).toBeString | ||
expect(nbData.schains[0].nodes[0].endpoints?.ip.ws).toBeString | ||
} | ||
}) | ||
}) |
Oops, something went wrong.