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 more docker spin-up time for mix's laptop #440

Closed
wants to merge 4 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
7 changes: 7 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This is a template for using a .env file to configure your test setup
#
# $ cp .env.template .env

ENTROPY_SDK_TESTS_RETRY_COUNT_DEFAULT=20
ENTROPY_SDK_TESTS_RETRY_TIMEOUT_DEFAULT=1000
# ENTROPY_SDK_TESTS_DONT_KILL=true
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
docs
dist
.env

# Created by https://www.toptal.com/developers/gitignore/api/macos,node
# Edit at https://www.toptal.com/developers/gitignore?templates=macos,node
Expand Down Expand Up @@ -193,4 +194,4 @@ prepTests.sh
*.sublime-workspace

# Testing npm package
bootstrap/
bootstrap/
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,24 @@ Version header format: `[version] Name - year-month-day (entropy-core compatibil
### Added
- utility method to return substrate api instance to interact with without needing to instantiate entropy instance (#435)[https://github.com/entropyxyz/sdk/pull/435]
- verifying method for signatures `keccak` and `blake2_256` hashed signatures

### Fixed

### Changed

### Broke
- sign and sign with adapters no longer returns just the signature. It now returns a object `SignatureData` that contains the signature and information pronating to it see the `SignatureData` interface in (./src/signing/index.ts)(./src/signing/index.ts)
- `entropy.sign` and `entropy.signWithAdaptersInOrder` function argument interface key renamed `sigRequestHash` -> `hexMessage`

### Dev

- added `dotenv` for handling ENV in tests. See `.env.template`
- new ENV:
- `ENTROPY_SDK_TESTS_RETRY_COUNT_DEFAULT` - default number of times to run `retryUntil` function
- `ENTROPY_SDK_TESTS_RETRY_TIMEOUT_DEFAULT` - default timeout between runs of `retryUntil` function
- renamed ENV:
- `ENTROPY_DONT_KILL` => `ENTROPY_SDK_TESTS_DONT_KILL`

### Meta

## [0.4.0] Fa - 2024-11-05 (entropy-core compatibility: 0.3.0)
Expand Down
35 changes: 27 additions & 8 deletions dev/testing-utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,27 @@ import { fileURLToPath } from 'url';
import { execFileSync } from 'child_process';
import { WebSocket } from 'ws';
import { promisify } from 'util'
import 'dotenv/config'

const __dirname = dirname(fileURLToPath(import.meta.url));
const moduleRoot = join(__dirname, '..')

const {
GITHUB_WORKSPACE,
ENTROPY_SDK_TESTS_RETRY_COUNT_DEFAULT,
ENTROPY_SDK_TESTS_RETRY_TIMEOUT_DEFAULT
} = process.env

const SECONDS = 1000
const DEFAULT_RETRY_COUNT = (
parseInt(ENTROPY_SDK_TESTS_RETRY_COUNT_DEFAULT) ||
GITHUB_WORKSPACE && 60 ||
20
)
const DEFAULT_RETRY_TIMEOUT = (
parseInt(ENTROPY_SDK_TESTS_RETRY_TIMEOUT_DEFAULT) ||
1 * SECONDS
)

// NOTE: you need to edit your /etc/hosts file to use these. See dev/README.md

Expand All @@ -31,26 +48,28 @@ export async function spinNetworkUp (networkType = 'four-nodes') {

async function retryUntil (fn, isSuccess = Boolean, opts = {}) {
const {
triesRemaining = process.env.GITHUB_WORKSPACE ? 60 : 10,
timeout = 1 * SECONDS
retryCount = DEFAULT_RETRY_COUNT,
retryTimeout = DEFAULT_RETRY_TIMEOUT
} = opts

return fn()
.then(result => {
if (isSuccess(result)) return result
else throw Error('retry failed')
})
.catch(async (err) => {
// out of tries, do not recurse
if (triesRemaining === 1) throw err
await promisify(setTimeout)(timeout)
if (retryCount === 1) throw err
await promisify(setTimeout)(retryTimeout)

return retryUntil(fn, isSuccess, {
triesRemaining: triesRemaining - 1,
timeout
retryCount: retryCount - 1,
retryTimeout
})
})
}


async function isWebSocketReady (endpoint) {
return new Promise((resolve, reject) => {
try {
Expand Down Expand Up @@ -136,8 +155,8 @@ total-block-time: ${headersSenseStart} blocks
}

export async function spinNetworkDown (networkType = 'four-nodes') {
if (process.env.ENTROPY_DONT_KILL) {
console.warn('$ENTROPY_DONT_KILL is set not spinning the network down')
if (process.env.ENTROPY_SDK_TESTS_DONT_KILL) {
console.warn('$ENTROPY_SDK_TESTS_DONT_KILL is set, so not spinning the network down')
return false
}
try {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"@typescript-eslint/eslint-plugin": "^5.43.0",
"@typescript-eslint/parser": "^5.43.0",
"depcheck": "^1.4.7",
"dotenv": "^16.4.7",
"eslint": "^8.57.0",
"husky": "^9.0.11",
"lint-staged": ">=10",
Expand Down
8 changes: 2 additions & 6 deletions tests/four-nodes.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
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,
jumpStartNetwork,
eveSeed,
eveAddress,
// eveAddress,
spinNetworkDown,
} from './testing-utils'

Expand All @@ -21,8 +19,6 @@ test('test the four-nodes docker script', async (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)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is now in spinNetworkUp , I think removing this line is gonna save us 60s in CI 😆


// this gets called after all tests are run
t.teardown(async () => {
await entropy.close()
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1975,6 +1975,11 @@ doctrine@^3.0.0:
dependencies:
esutils "^2.0.2"

dotenv@^16.4.7:
version "16.4.7"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.4.7.tgz#0e20c5b82950140aa99be360a8a5f52335f53c26"
integrity sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==

dotignore@^0.1.2:
version "0.1.2"
resolved "https://registry.npmjs.org/dotignore/-/dotignore-0.1.2.tgz"
Expand Down
Loading