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

Add two more validators, providing four nodes in a devnet. #383

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ jobs:
password: ${{ secrets.DOCKER_HUB_CI_TOKEN }}
- name: Add TSS server host mappings
run: |
echo "127.0.0.1 alice-tss-server bob-tss-server" | sudo tee -a /etc/hosts
echo "127.0.0.1 alice-tss-server bob-tss-server dave-tss-server eve-tss-server" | sudo tee -a /etc/hosts
- name: Test
run: yarn run test
4 changes: 3 additions & 1 deletion dev/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ For the tests to run you **must** edit your `/etc/hosts` file, adding:
```
127.0.0.1 alice-tss-server
127.0.0.1 bob-tss-server
127.0.0.1 dave-tss-server
127.0.0.1 eve-tss-server
```

### Gotcha 1 - dirty docker
Expand All @@ -19,7 +21,7 @@ that program is already deployed boo").
Have a look what's running:

```bash
docker ps
docker container list
```

You can close them down like this:
Expand Down
153 changes: 153 additions & 0 deletions dev/docker-scripts/four-nodes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# Docker Compose file for making an Entropy blockchain network.
# Currently, it's intended for LOCAL DEVNET FUNCTIONALITY ONLY.
# Things will get better and more generic, but for the moment
# this iteration is for simplifying the dogfooding and testing
# workflows our engineers use, and trying to cut down on some
# of the more complicated test code that spins up this kind of
# environment for their tests. Eventually, we will converge on
# a more canonical set of environments and configuration files.
---
name: entropy-devnet-local-four-nodes-4-nodes

services:
alice-tss-server:
# This pulls from Docker Hub, so you can replace the image tag name
# (the string after the `:` in the `image` key) with whatever tag
# name you'd like to use. Each Docker image is built from a specific
# commit in the `entropy-core` repository. Refer to the wiki page at
# https://github.com/entropyxyz/meta/wiki/Git#conventions for details
# about how Git tags, branches, and commits refer to image tags here.
image: entropyxyz/entropy-tss:${ENTROPY_CORE_VERSION:-latest}
ports:
- "127.0.0.1:3001:3001/tcp"
command:
- "--alice"
- "--threshold-url"
- "0.0.0.0:3001"
- "--chain-endpoint"
- "ws://alice-chain-node:9944"
- '--no-sync'

alice-chain-node:
image: entropyxyz/entropy:${ENTROPY_CORE_VERSION:-latest}
ports:
- "127.0.0.1:9944:9944/tcp"
volumes:
- ${PWD}/dev:/srv/entropy/dev
command:
- "--chain"
- "devnet-local-four-nodes"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all these need to change to devnet-local

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- "--alice"
- "--base-path"
- ".entropy/alice"
- "--rpc-port"
- "9944"
- "--rpc-cors"
- "all"
- "--unsafe-rpc-external" # Intentional, for TSS's access.
- "--node-key=0000000000000000000000000000000000000000000000000000000000000001"
- "--tss-server-endpoint"
- "http://alice-tss-server:3001"

bob-tss-server:
image: entropyxyz/entropy-tss:${ENTROPY_CORE_VERSION:-latest}
ports:
- "127.0.0.1:3002:3002/tcp"
command:
- "--bob"
- "--threshold-url"
- "0.0.0.0:3002"
- "--chain-endpoint"
- "ws://bob-chain-node:9944"
- '--no-sync'

# "Bob's chain node."
bob-chain-node:
image: entropyxyz/entropy:${ENTROPY_CORE_VERSION:-latest}
ports:
- "127.0.0.1:9945:9944/tcp"
volumes:
- ${PWD}/dev:/srv/entropy/dev
command:
- "--chain"
- "devnet-local-four-nodes"
- "--bob"
- "--base-path"
- ".entropy/bob"
- "--rpc-port"
- "9944"
- "--rpc-cors"
- "all"
- "--unsafe-rpc-external" # Intentional, for TSS's access.
- "--bootnodes"
- "/dns4/alice-chain-node/tcp/30333/p2p/12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp"
- "--tss-server-endpoint"
- "http://bob-tss-server:3002"

dave-tss-server:
image: entropyxyz/entropy-tss:${ENTROPY_CORE_VERSION:-latest}
ports:
- "127.0.0.1:3003:3003/tcp"
command:
- "--dave"
- "--threshold-url"
- "0.0.0.0:3003"
- "--chain-endpoint"
- "ws://dave-chain-node:9944"
- '--no-sync'

dave-chain-node:
image: entropyxyz/entropy:${ENTROPY_CORE_VERSION:-latest}
ports:
- "127.0.0.1:9946:9944/tcp"
volumes:
- ${PWD}/dev:/srv/entropy/dev
command:
- "--chain"
- "devnet-local-four-nodes"
- "--dave"
- "--base-path"
- ".entropy/dave"
- "--rpc-port"
- "9944"
- "--rpc-cors"
- "all"
- "--unsafe-rpc-external" # Intentional, for TSS's access.
- "--bootnodes"
- "/dns4/alice-chain-node/tcp/30333/p2p/12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp"
- "--tss-server-endpoint"
- "http://dave-tss-server:3003"

eve-tss-server:
image: entropyxyz/entropy-tss:${ENTROPY_CORE_VERSION:-latest}
ports:
- "127.0.0.1:3004:3004/tcp"
command:
- "--dave"
- "--threshold-url"
- "0.0.0.0:3004"
- "--chain-endpoint"
- "ws://eve-chain-node:9944"
- '--no-sync'

eve-chain-node:
image: entropyxyz/entropy:${ENTROPY_CORE_VERSION:-latest}
ports:
- "127.0.0.1:9947:9944/tcp"
volumes:
- ${PWD}/dev:/srv/entropy/dev
command:
- "--chain"
- "devnet-local-four-nodes"
- "--eve"
- "--base-path"
- ".entropy/eve"
- "--rpc-port"
- "9944"
- "--rpc-cors"
- "all"
- "--unsafe-rpc-external" # Intentional, for TSS's access.
- "--bootnodes"
- "/dns4/alice-chain-node/tcp/30333/p2p/12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp"
- "--tss-server-endpoint"
- "http://eve-tss-server:3004"
64 changes: 64 additions & 0 deletions tests/four-nodes.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import test from 'tape'
import { readFileSync } from 'fs'
import Entropy, { wasmGlobalsReady } from '../src'
import Keyring from '../src/keys'
import * as util from '@polkadot/util'

import {
sleep,
promiseRunner,
spinNetworkUp,
charlieStashSeed,
charlieStashAddress,
spinNetworkDown,
} from './testing-utils'

const networkType = 'four-nodes'


test('test the four-nodes docker script for subgroups', async (t) => {
const run = promiseRunner(t)
// context: all run does is checks that it runs
await run('network up', spinNetworkUp(networkType))

await sleep(process.env.GITHUB_WORKSPACE ? 30_000 * 2 : 5_000 * 2)

// this gets called after all tests are run
t.teardown(async () => {
await entropy.close()
await spinNetworkDown(networkType).catch((error) =>
console.error('Error while spinning network down', error.message)
)
})

await run('wasm', wasmGlobalsReady())

const keyring = new Keyring({ seed: charlieStashSeed, debug: true })
let store = keyring.getAccount()
t.equal(store.admin.address, keyring.accounts.registration.pair.address, 'admin account should have an address and for now it should match registrations address')
keyring.accounts.on('account-update', (fullAccount) => {
store = fullAccount
})


const entropy = new Entropy({
keyring,
endpoint: 'ws://127.0.0.1:9944',
})

await run('entropy ready', entropy.ready)
const entries = await run('signingGroups', entropy.substrate.query.stakingExtension.signingGroups.entries())

const subGroups = entries.map((group) => {
// aka: subGroup
const keyGroup = group[1]
console.log('')
// omg polkadot type gen is a head ache
// @ts-ignore: next line
return keyGroup.unwrap()
})
t.equal(subGroups.length, 2, 'expecting 2 subgroups')
t.equal(subGroups[0].length, 2, 'expecting 2 validators per subgroup')
await entropy.close()
t.end()
})
33 changes: 33 additions & 0 deletions tests/testing-utils/network.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { ApiPromise /* WsProvider */ } from '@polkadot/api'
import { execFileSync } from 'child_process'

export async function spinNetworkUp(networkType = 'two-nodes') {
try {
execFileSync(
'dev/bin/spin-up.sh',
[networkType],
{ shell: true, cwd: process.cwd(), stdio: 'inherit' } // Use shell's search path.
)
} catch (e) {
console.error('Error in spinNetworkUp: ', e.message)
}
}

export async function spinNetworkDown(networkType = 'two-nodes') {
try {
execFileSync('dev/bin/spin-down.sh', [networkType], {
shell: true,
cwd: process.cwd(),
stdio: 'inherit',
})
} catch (e) {
console.error('Error in afterAll: ', e.message)
}
}

// export async function getApi(endpoint = 'ws://127.0.0.1:9944'): Promise<ApiPromise> {
// const wsProvider = new WsProvider(endpoint)
// const api = new ApiPromise({ provider: wsProvider })
// await api.isReady
// return api
// }
Loading