Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add TestCoin helper class #3445

Open
Dhaiwat10 opened this issue Dec 4, 2024 · 5 comments
Open

Add TestCoin helper class #3445

Dhaiwat10 opened this issue Dec 4, 2024 · 5 comments
Labels
feat Issue is a feature

Comments

@Dhaiwat10
Copy link
Member

Similar to the TestMessage helper class, it might be worth having one for coins as well.

We could have a static many function which could generate multiple coins.

const coins: Coin[] = TestCoin.many({
  owner: '0x09c0b2d1a486c439a87bcba6b46a7a1a23f3897cc83a94521a96da5c23bc58db'
}, 4);
@Dhaiwat10 Dhaiwat10 added the feat Issue is a feature label Dec 4, 2024
@crStiv
Copy link

crStiv commented Dec 5, 2024

May I try to solve this Issue?

@petertonysmith94
Copy link
Contributor

Hey @crStiv 👋🏼

Go ahead - let us know if you need anything :)

@crStiv
Copy link

crStiv commented Dec 8, 2024

import { Coin } from '../types';
import { randomBytes } from 'crypto';

export class TestCoin {
/**

  • Creates a single test coin with given parameters
    */
    static create(params: Partial = {}): Coin {
    return {
    id: randomBytes(32).toString('hex'),
    owner: randomBytes(32).toString('hex'),
    amount: '1000000000000000000', // 1 ETH by default
    ...params
    };
    }

/**

  • Generates an array of test coins
  • @param params - Parameters for all generated coins
  • @param count - Number of coins to generate
    */
    static many(params: Partial = {}, count: number): Coin[] {
    return Array.from({ length: count }, () => TestCoin.create(params));
    }
    }

@crStiv
Copy link

crStiv commented Dec 8, 2024

does this one helps in any shape or form, or did I go into the wrong direction?

@Dhaiwat10
Copy link
Member Author

@crStiv feel free to open a draft PR with this implementation. It is easier for the team to review and collaborate

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
feat Issue is a feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants