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

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Coin } from '../types';
import { randomBytes } from 'crypto';
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
import { randomBytes } from 'crypto';
import { randomBytes } from '@fuel-ts/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')}`,
amount: params.amount || BigInt(1000000),
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));
}
}
Loading