Skip to content

Fix ci tests #215

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

Closed
wants to merge 16 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
16 changes: 13 additions & 3 deletions src/registration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class RegistrationManager extends ExtrinsicBaseClass {
// this is sloppy
// TODO: store multiple signers via address. and respond accordingly
// however it should be handled in extrinsic class and not here

console.log('checking registration')
const isCurrentlyRegistered = await this.checkRegistrationStatus(address)
if (isCurrentlyRegistered) {
throw new Error('already registered')
Expand All @@ -40,16 +40,24 @@ export default class RegistrationManager extends ExtrinsicBaseClass {
// fgilter through events for accountregistartion :P vom
// this.substrate.events.relayer.AccountRegistered
// unsubcribes from blocks once event has been found
console.log('subscribe to new blocks')
const registered: Promise<undefined> = new Promise((resolve, reject) => {
try {
const unsubPromise = this.substrate.rpc.chain.subscribeNewHeads(
async () => {
const registeredCheck = await this.checkRegistrationStatus(
this.signer.wallet.address
)
console.log('subscribe to new blocks: is registered?', registeredCheck)

if (registeredCheck) {
console.log('subscribe to new blocks: finish is registered')

const unsub = await unsubPromise
unsub()
console.log('subscribe to new blocks: awaited unsub')
await unsub()
console.log('subscribe to new blocks: called unsub')

resolve(undefined)
}
}
Expand All @@ -64,11 +72,13 @@ export default class RegistrationManager extends ExtrinsicBaseClass {
keyVisibility,
initialProgram ? initialProgram : null
)
console.log('created register tx about to send')

await this.sendAndWaitFor(registerTx, freeTx, {
section: 'relayer',
name: 'SignalRegister',
})

console.log('sent tx')
return registered
}

Expand Down
53 changes: 36 additions & 17 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
whitelisted_test_tx_req,
non_whitelisted_test_tx_req,
whitelisted_test_constraints,
noBalanceSeed,
} from './testing-utils'
import { ethers } from 'ethers'
import { keccak256 } from 'ethers/lib/utils'
Expand Down Expand Up @@ -41,7 +42,7 @@ describe('Core Tests', () => {
await sleep(3000)
chainProcess2 = await spinChain(chainPath, 'bob', '9945')
await sleep(3000)

console.log('created all chains and threshold servers')
// Handle process errors
const processes = [
serverProcess1,
Expand All @@ -62,14 +63,6 @@ describe('Core Tests', () => {
'ws://127.0.0.1:9945',
'http://localhost:3002/user/new'
)
entropy = new Entropy({
seed: charlieStashSeed,
// devnet endpoint
// endpoint: customEndpoint
})

// Wait for the entropy instance to be ready
await entropy.ready
})
afterEach(async () => {
jest.setTimeout(30000)
Expand All @@ -95,10 +88,37 @@ afterEach(async () => {
}
})

it('should fail registration', async () => {
entropy = new Entropy({
seed: noBalanceSeed,
// devnet endpoint
// endpoint: customEndpoint
})

// Wait for the entropy instance to be ready
await entropy.ready
try {
const preRegistrationStatus = await entropy.isRegistered(noBalanceSeed)
expect(preRegistrationStatus).toBeFalsy()

} catch (e) {
expect(e).toBeTruthy()
}
})

it('should handle registration, program management, and signing', async () => {
jest.setTimeout(60000)

entropy = new Entropy({
seed: charlieStashSeed,
// devnet endpoint
// endpoint: customEndpoint
})

// Wait for the entropy instance to be ready
await entropy.ready

// Pre-registration check

try {
const preRegistrationStatus = await entropy.isRegistered(charlieStashAddress)
expect(preRegistrationStatus).toBeFalsy()
Expand All @@ -108,7 +128,7 @@ it('should handle registration, program management, and signing', async () => {
} catch (e) {
console.error('Error in pre-registration status check:', e.message)
}

try {
await entropy.register({
address: charlieStashAddress,
Expand All @@ -126,26 +146,25 @@ it('should handle registration, program management, and signing', async () => {
charlieStashAddress
)
).toBeTruthy()

// Post-registration check
try {
const postRegistrationStatus = await entropy.isRegistered(charlieStashAddress)
expect(postRegistrationStatus).toBeTruthy()

const postStringifiedResponse = JSON.stringify(postRegistrationStatus)
console.log("is Registered post-registration?", postStringifiedResponse)

if (postStringifiedResponse === 'false') {
console.log("is not registered")
}

expect(postStringifiedResponse).toBe('true')

console.log('post registration')
} catch (e) {
console.error('Error in post-registration status check:', e.message)
}


// Set a program for the user
const dummyProgram: any = readFileSync(
Expand Down
2 changes: 2 additions & 0 deletions tests/testing-utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { BigNumber, ethers } from 'ethers'

export const noBalanceSeed = '0x3ac4129b6c919016a8145eecbf6a2aae39b9963bc814e2b11ba25ad2d5326c27'

export const x25519_public_key_alice =
'0x0ac029f0b853b23bed652d6d0de69b7cc38d94f93732eefc85b5861e90f73a22'

Expand Down
43 changes: 23 additions & 20 deletions tests/testing-utils/spinUp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,20 @@ export const spinChain = async (

const process = spawn(bin, args)
// comment in for chain logging and add verbose to jest
// process.stderr.on('data', async function (chunk) {
// const message = chunk.toString()
// console.log(name, ': ', {message})
// })
process.stderr.on('data', (data) => {
console.log(`STDERR: ${data}`)
})

// process.on('error', (error) => {
// console.error(`chain for ${name} Error in spinChain process: ${error.message}`)
// })
// process.on('exit', (code) => {
// console.log(`spinChain process exited with code: ${code}`)
// })
process.stdout.on('data', (data) => {
console.log(`STDOUT: ${data}`);
});

process.on('error', (error) => {
console.error(`chain for ${name} Error in spinChain process: ${error.message}`)
})
process.on('exit', (code) => {
console.log(`spinChain process exited with code: ${code}`)
})
return process
}

Expand All @@ -80,16 +83,16 @@ export const spinThreshold = async (
const process = spawn(bin, args)
await sleep(1000)
// comment in for threshold logging and add verbose to jest
// process.stdout.on('data', async function (chunk) {
// const message = chunk.toString()
// console.log('Threshold chain data for ', name, ':', message)
// })
// process.on('error', (error) => {
// console.error(`Error in spinThreshold process: ${error.message}`)
// })
// process.on('exit', (code) => {
// console.log(`spinThreshold process exited with code: ${code}`)
// })
process.stdout.on('data', async function (chunk) {
const message = chunk.toString()
console.log('Threshold chain data for ', name, ':', message)
})
process.on('error', (error) => {
console.error(`Error in spinThreshold process: ${error.message}`)
})
process.on('exit', (code) => {
console.log(`spinThreshold process exited with code: ${code}`)
})
return process
}

Expand Down
Binary file removed tests/testing-utils/test-binaries/entropy
Binary file not shown.
Binary file removed tests/testing-utils/test-binaries/server
Binary file not shown.