Skip to content

Commit

Permalink
fixed a false wpositive with register test
Browse files Browse the repository at this point in the history
  • Loading branch information
rh0delta committed Jul 11, 2024
1 parent bce1135 commit 19c84c0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
7 changes: 3 additions & 4 deletions src/flows/register/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// import inquirer from "inquirer"
// @ts-ignore
import { ChildKey } from '@entropyxyz/sdk/keys'
import { getSelectedAccount, print, /*accountChoices*/ } from "../../common/utils"
import { initializeEntropy } from "../../common/initializeEntropy"
import { EntropyLogger } from "src/common/logger";
Expand All @@ -25,8 +23,9 @@ export async function entropyRegister (storedConfig, options, logger: EntropyLog
// // Setting default to default key proxy program
// default: '0x0000000000000000000000000000000000000000000000000000000000000000'
// }])

logger.debug('about to register selectedAccount.address' + selectedAccount.address + 'keyring:' + entropy.keyring.getLazyLoadAccountProxy(ChildKey.registration).pair.address, FLOW_CONTEXT)
// @ts-expect-error: Expecting error here as method expects typeof ChildKey enum from sdk
// export from sdk is not working as intended currently
logger.debug('about to register selectedAccount.address' + selectedAccount.address + 'keyring:' + entropy.keyring.getLazyLoadAccountProxy('registration').pair.address, FLOW_CONTEXT)
print("Attempting to register the address:", selectedAccount.address, )

try {
Expand Down
9 changes: 4 additions & 5 deletions src/flows/register/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { print } from "src/common/utils";
export async function register (entropy: Entropy, params?: RegsiterParams): Promise<string> {
let verifyingKey: string
try {
const registerParams = params.programModAddress && params.programData ? { programDeployer: params.programModAddress, programData: params.programData } : undefined
const registerParams = params?.programModAddress && params?.programData ? { programDeployer: params.programModAddress, programData: params.programData } : undefined

verifyingKey = await entropy.register(registerParams)
return verifyingKey
} catch (error) {
if (!verifyingKey) {
// logger.debug('Pruning Registration', FLOW_CONTEXT)
try {
const tx = await entropy.substrate.tx.registry.pruneRegistration()
const tx = entropy.substrate.tx.registry.pruneRegistration()
await tx.signAndSend(entropy.keyring.accounts.registration.pair, ({ status }) => {
if (status.isFinalized) {
print('Successfully pruned registration');
Expand All @@ -22,8 +22,7 @@ export async function register (entropy: Entropy, params?: RegsiterParams): Prom
console.error('Unable to prune registration due to:', error.message);
throw error
}
} else {
throw error
}
throw error
}
}
3 changes: 2 additions & 1 deletion tests/register.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import test from 'tape'

import { charlieStashSeed, setupTest } from './testing-utils'
import { register } from 'src/flows/register/register'

const networkType = 'two-nodes'

test('Regsiter - Default Program', async (t) => {
const { run, entropy } = await setupTest(t, { networkType, seed: charlieStashSeed })

const verifyingKey = await run('register account', entropy.register())
const verifyingKey = await run('register account', register(entropy))

const fullAccount = entropy.keyring.getAccount()

Expand Down

0 comments on commit 19c84c0

Please sign in to comment.