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

[NayNay] Transfer updates + unit testing #140

Merged
merged 9 commits into from
Jul 3, 2024
Prev Previous commit
Next Next commit
updated based on PR suggestions
rh0delta committed Jul 2, 2024

Verified

This commit was signed with the committer’s verified signature. The key has expired.
marekmosna Marek Mosna
commit 2499a56b6ba0436c72c5ecb42a1b7c431a74b3cf
15 changes: 3 additions & 12 deletions src/common/initializeEntropy.ts
Original file line number Diff line number Diff line change
@@ -17,18 +17,9 @@ const keyrings = {
default: undefined // this is the "selected account" keyring
}

export function getKeyring (address?: string, seed?: string) {
export function getKeyring (address?: string) {

if (!address && !seed && keyrings.default) return keyrings.default
if (!address && seed && keyrings.default && Object.keys(keyrings).length > 1) {
const [keyring] = Object.keys(keyrings)
.filter(kr => {

return keyrings[kr]?.admin?.seed === seed
})

return keyring
}
if (!address && keyrings.default) return keyrings.default
if (address && keyrings[address]) return keyrings[address]
// explicitly return undefined so there is no confusion around what is selected
return undefined
@@ -75,7 +66,7 @@ export const initializeEntropy = async ({ keyMaterial, password, endpoint, confi
}

let selectedAccount
const storedKeyring = getKeyring(accountData?.admin?.address, accountData.seed)
const storedKeyring = getKeyring(accountData.admin.address)

if(!storedKeyring) {
const keyring = new Keyring({ ...accountData, debug: true })
6 changes: 4 additions & 2 deletions src/flows/entropyTransfer/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// @ts-ignore
import { Pair } from '@entropyxyz/sdk/keys'
export interface TransferOptions {
Copy link
Contributor

Choose a reason for hiding this comment

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

😍

from?: any
from: Pair
to: string
amount: number | string | bigint
amount: bigint
}
8 changes: 6 additions & 2 deletions tests/testing-utils/setup-test.ts
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@ import { Test } from 'tape'
import { Entropy, wasmGlobalsReady } from '@entropyxyz/sdk'
// @ts-ignore
import { spinNetworkUp, spinNetworkDown, } from "@entropyxyz/sdk/testing"
// @ts-ignore
import Keyring from '@entropyxyz/sdk/keys'
Comment on lines 3 to +6
Copy link
Contributor

Choose a reason for hiding this comment

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

is their an an issue for this on sdk? this dosent look good. why?


import { initializeEntropy } from '../../src/common/initializeEntropy'
import * as config from '../../src/config'
@@ -38,9 +40,11 @@ export async function setupTest (t: Test, opts?: SetupTestOpts): Promise<{ entro

// TODO: remove this after new SDK is published
await sleep(process.env.GITHUB_WORKSPACE ? 30_000 : 5_000)

// To follow the same way we initiate entropy within the cli we must go through the same process of creating an initial keyring
// as done in src/flows/manage-accounts/new-key.ts
const keyring = new Keyring({ seed, debug: true })
const entropy = await initializeEntropy({
keyMaterial: { seed, debug: true },
keyMaterial: keyring.getAccount(),
endpoint: 'ws://127.0.0.1:9944',
configPath
})
12 changes: 8 additions & 4 deletions tests/transfer.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import test from 'tape'
import Entropy, { wasmGlobalsReady } from '@entropyxyz/sdk'
import { wasmGlobalsReady } from '@entropyxyz/sdk'
// WIP: I'm seeing problems importing this?
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it resolved in the SDK that is un-published yet I wonder

import Keyring from '@entropyxyz/sdk/dist/keys/index'
// @ts-ignore
import Keyring from '@entropyxyz/sdk/keys'
import {
makeSeed,
promiseRunner,
@@ -33,8 +34,11 @@ test('Transfer', async (t) => {
await sleep(process.env.GITHUB_WORKSPACE ? 30_000 : 5_000)

const naynaySeed = makeSeed()
const entropy = await initializeEntropy({ keyMaterial: { seed: naynaySeed, debug: true }, endpoint: 'ws://127.0.0.1:9944', })
const charlieEntropy = await initializeEntropy({ keyMaterial: { seed: charlieStashSeed, debug: true }, endpoint: 'ws://127.0.0.1:9944', })
const naynayKeyring = new Keyring({ seed: naynaySeed, debug: true })
const charlieKeyring = new Keyring({ seed: charlieStashSeed, debug: true })

const entropy = await initializeEntropy({ keyMaterial: naynayKeyring.getAccount(), endpoint: 'ws://127.0.0.1:9944', })
const charlieEntropy = await initializeEntropy({ keyMaterial: charlieKeyring.getAccount(), endpoint: 'ws://127.0.0.1:9944', })
await run('entropy ready', entropy.ready)
await run('charlie ready', charlieEntropy.ready)