fuels-ts icon indicating copy to clipboard operation
fuels-ts copied to clipboard

Add `TestCoin` helper class

Open Dhaiwat10 opened this issue 1 year ago • 5 comments

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 avatar Dec 04 '24 13:12 Dhaiwat10

May I try to solve this Issue?

crStiv avatar Dec 05 '24 15:12 crStiv

Hey @crStiv 👋🏼

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

petertonysmith94 avatar Dec 05 '24 15:12 petertonysmith94

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: 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<Coin> = {}, count: number): Coin[] { return Array.from({ length: count }, () => TestCoin.create(params)); } }

crStiv avatar Dec 08 '24 10:12 crStiv

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

crStiv avatar Dec 08 '24 10:12 crStiv

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

Dhaiwat10 avatar Dec 09 '24 08:12 Dhaiwat10