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

Create TestCoin feat: add TestCoin helper class (#3445) #3460

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions TestCoin.ts
Copy link
Contributor

Choose a reason for hiding this comment

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

  • This is at the root of the project. Move to a more appropriate location like packages/account/src/test-utils.
  • Add tests so we can validate the functionality.
  • The Coin should reference the following Coin type.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Coin } from '../types';
import { randomBytes } from 'crypto';

export class TestCoin {
/**
* Creates a single test coin with given parameters
*/
static create(params: Partial<Coin> = {}): Coin {
return {
id: params.id || `0x${randomBytes(32).toString('hex')}`,
owner: params.owner || `0x${randomBytes(32).toString('hex')}`,
Comment on lines +10 to +11
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
id: params.id || `0x${randomBytes(32).toString('hex')}`,
owner: params.owner || `0x${randomBytes(32).toString('hex')}`,
id: params.id || getRandomB256(),
owner: params.owner || getRandomB256(),

Favour helper functions

amount: params.amount || BigInt(1000000),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
amount: params.amount || BigInt(1000000),
amount: params.amount || bn(1000000),

Amount is a BN

type: params.type || 0,
...params
};
}

/**
* Generates an array of test coins with the same base parameters
*/
static many(params: Partial<Coin> = {}, count: number = 1): Coin[] {
return Array.from({ length: count }, () => TestCoin.create(params));
}
}