-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NayNay] Entropy Register + Unit Tests
- added new register pure function - imported new types from sdk - added unit test for default register
- Loading branch information
Showing
7 changed files
with
68 additions
and
39 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
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,29 @@ | ||
import Entropy from "@entropyxyz/sdk"; | ||
import { RegsiterParams } from "./types"; | ||
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 | ||
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() | ||
await tx.signAndSend(entropy.keyring.accounts.registration.pair, ({ status }) => { | ||
if (status.isFinalized) { | ||
print('Successfully pruned registration'); | ||
} | ||
}) | ||
} catch (error) { | ||
console.error('Unable to prune registration due to:', error.message); | ||
throw error | ||
} | ||
} else { | ||
throw error | ||
} | ||
} | ||
} |
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,5 @@ | ||
export interface RegsiterParams { | ||
programModAddress?: string | ||
// TODO: Export ProgramInstance type from sdk | ||
programData?: any | ||
} |
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,17 @@ | ||
import test from 'tape' | ||
|
||
import { charlieStashSeed, setupTest } from './testing-utils' | ||
|
||
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 fullAccount = entropy.keyring.getAccount() | ||
|
||
t.equal(verifyingKey, fullAccount.registration.verifyingKeys[0], 'verifying key matches key added to regsitration account') | ||
|
||
t.end() | ||
}) |