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

QA file-restructure #247

Open
wants to merge 5 commits into
base: naynay/file-restructure
Choose a base branch
from

Conversation

mixmix
Copy link
Contributor

@mixmix mixmix commented Oct 1, 2024

  • a script for testing CLI
  • some gotchas!
  • WIP bugs!

@mixmix mixmix marked this pull request as draft October 1, 2024 04:05
@@ -0,0 +1,53 @@
#! /usr/bin/bash
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here's a script I've been using to QA the CLI

It's breaking down at Transfer 😠

Comment on lines 18 to 23
const entropy = await loadEntropy(opts.account, opts.endpoint)
.catch(err => {
// WIP here. SOMETHING is wrecking the config upstream
console.error("loadEntropy failed", err)
throw err
})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

something 🔥

import { EntropyTransfer } from "./main"

export function entropyTransferCommand () {
const transferCommand = new Command('tranfer')
const transferCommand = new Command('transfer')
Copy link
Contributor Author

@mixmix mixmix Oct 1, 2024

Choose a reason for hiding this comment

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

🔥 spelling!

# entropy balance faucet
entropy balance 5CqJyjALDFz4sKjQgK8NXBQGHCWAiV63xXn2Dye393Y6Vghz


Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe we should log the config through-out this script to see where it done breaks

@mixmix mixmix requested a review from frankiebee October 2, 2024 03:16
@mixmix mixmix marked this pull request as ready for review October 2, 2024 03:16
Comment on lines +81 to +88
const accounts = await config.get()
.then(storedConfig => EntropyAccount.list(storedConfig))
.catch((err) => {
if (err.message.includes('currently no accounts')) return []

throw err
})

Copy link
Contributor Author

Choose a reason for hiding this comment

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

entropy account ls
If I don't have any accounts yet I don't expect an error, I expect []

@@ -35,7 +38,8 @@ function entropyAccountCreate () {

cliWrite({
name: newAccount.name,
address: newAccount.address
address: newAccount.address,
verifyingKeys: []
Copy link
Contributor Author

Choose a reason for hiding this comment

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

entropy account create
entropy account create

Have them output the same format as entropy account ls
✔️ consistency
✔️ set up expectations that there is something interesting/ important meant to go in here

const fullAccount = keyring.getAccount()
// TODO: sdk should create account on constructor
const { admin } = keyring.getAccount()
const data = fixData(fullAccount)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a bug in the SDK where you are "cloning" with `JSON.parse(JSON.stringify(obj)) and it fucks up the Uint8Array, which then fucks up config, logging etc.

This is a quick hack

@@ -49,7 +49,7 @@ export class EntropyAccount extends EntropyBase {
return accounts.map((account: EntropyAccountConfig) => ({
name: account.name,
address: account.address,
verifyingKeys: account?.data?.admin?.verifyingKeys
verifyingKeys: account?.data?.registration?.verifyingKeys || []
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🔥 CHECK?
I assume verifyingKeys were meant to go under registration and not admin right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AH tests say no. I don't know what the difference is between `admin + registration.
I changed where vks are being pushed into elsewhere in code too

'seed',
'secretKey',
'addressRaw',
];
]);

export function maskPayload (payload: any): any {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ended up in here cos of the masking of the badly handled UInt8Arrays... and reading it I saw there was not test and it was pretty confusing, so I wrote tests and wrote a simpler function with less dependencies.

I think it's an improvement ... I mean it needed to check the DEFAULT_MASKED_FIELDS earlier cos the test for "is this a Uint8Array or a munted Uint8Array (object like { "0": 34, "1": 23, ... }) ... yeah that broke when I fixed the bad keys coming from SDK...

There's a chance I introduced more edge cases...but look at the tests I guess!

@@ -20,7 +20,7 @@ function getConfigOrNull () {

export function endpointOption () {
return new Option(
'-e, --endpoint <endpoint>',
'-e, --endpoint <url>',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

reading the docs the pattern is -shortcode --longcode <input-type>

selectedAccount: account
})
}
.argParser(addressOrName => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🔥 🔥 NASTY bug

this thing don't handle async!

See comments below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I caught this cos I tried to register naynay in my QA and it was registering faucet!

src/config/encoding.ts Outdated Show resolved Hide resolved
Comment on lines +76 to +89
export async function setSelectedAccount (account: EntropyAccountConfig, configPath = CONFIG_PATH) {
const storedConfig = await get(configPath)

if (storedConfig.selectedAccount === account.name) return storedConfig
// no need for update

const newConfig = {
...storedConfig,
selectedAccount: account.name
}
await set(newConfig, configPath)
return newConfig
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🔥 one bug I saw was inconsistency around what config.selectedAccount was (an address? a name?).

I decided to fix it to be name because then in the --help you will see the default by name not some crazy address

I then changed

  • accountOption to deal with name
  • added a special method setSelectedAccount to handle the persistence of the right thing

Things I'm not happy about:

  • we are now doing a LOT of get/set/get/set of the same config in a few places
  • some places we need to persist the whole config (e.g. new verifyingKeys... and so the knowledge of what the selecttedAccount is is leaking out into the code)
  • does this suggest there should be a getSelectedAccount ?? where do the helper methods stop!

Comment on lines +3 to +10
# WARNING - this script nukes your config!
#
# Dependencies
# - internet connection
# - jq - see https://jqlang.github.io/jq
#
# Run
# $ yarn build && ./tests/qa.sh
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm pretty stoked with this. This script allowed me to hammer the CLI repeatedly till I got all the weird lil bugs out.

I imagine this could be the basis for a CLI integration test that uses frankie's new CLI runner in the future so we can check the outputs are good

tests/qa.sh Outdated Show resolved Hide resolved
@mixmix mixmix changed the title WIP: QA file-restructure QA file-restructure Oct 2, 2024
@mixmix
Copy link
Contributor Author

mixmix commented Oct 2, 2024

Checklist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant