{"version":3,"file":"account.mjs","sources":["../../src/testing/account.ts"],"sourcesContent":["import algosdk, { Address } from 'algosdk'\nimport { AlgorandClient, Config } from '../'\nimport { TransactionSignerAccount } from '../types/account'\nimport { GetTestAccountParams } from '../types/testing'\nimport Account = algosdk.Account\nimport Algodv2 = algosdk.Algodv2\nimport Kmd = algosdk.Kmd\n\n/**\n * @deprecated Use `getTestAccount(params, algorandClient)` instead. The `algorandClient` object can be created using `AlgorandClient.fromClients({ algod, kmd })`.\n *\n * Creates an ephemeral Algorand account for the purposes of testing.\n * Returns a newly created random test account that is funded from the dispenser\n * DO NOT USE THIS TO CREATE A MAINNET ACCOUNT!\n * Note: By default this will log the mnemonic of the account.\n * @param params The config for the test account to generate\n * @param algod An algod client\n * @param kmd A KMD client, if not specified then a default KMD client will be loaded from environment variables and if not found fallback to the default LocalNet KMD client\n * @returns The account, with private key loaded\n */\nexport async function getTestAccount(\n  params: GetTestAccountParams,\n  algod: Algodv2,\n  kmd?: Kmd,\n): Promise<Address & Account & TransactionSignerAccount>\n/**\n * Creates an ephemeral Algorand account for the purposes of testing.\n * Returns a newly created random test account that is funded from the dispenser\n * DO NOT USE THIS TO CREATE A MAINNET ACCOUNT!\n * Note: By default this will log the mnemonic of the account.\n * @param params The config for the test account to generate\n * @param algorand An AlgorandClient client\n * @returns The account, with private key loaded\n */\nexport async function getTestAccount(\n  params: GetTestAccountParams,\n  algorand: AlgorandClient,\n): Promise<Address & Account & TransactionSignerAccount>\nexport async function getTestAccount(\n  { suppressLog, initialFunds, accountGetter }: GetTestAccountParams,\n  algodOrAlgorandClient: Algodv2 | AlgorandClient,\n  kmd?: Kmd,\n): Promise<Address & Account & TransactionSignerAccount> {\n  const algorand =\n    algodOrAlgorandClient instanceof AlgorandClient\n      ? algodOrAlgorandClient\n      : AlgorandClient.fromClients({\n          algod: algodOrAlgorandClient,\n          kmd,\n        })\n\n  const account = accountGetter ? await accountGetter(algorand) : algosdk.generateAccount()\n\n  Config.getLogger(suppressLog).info(\n    `New test account created with address '${account.addr}' and mnemonic '${algosdk.secretKeyToMnemonic(account.sk)}'.`,\n  )\n\n  const dispenser = await algorand.account.dispenserFromEnvironment()\n\n  await algorand.send.payment({\n    sender: dispenser,\n    receiver: account.addr,\n    amount: initialFunds,\n    note: 'Funding test account',\n    suppressLog,\n  })\n\n  const accountInfo = await algorand.account.getInformation(account.addr)\n\n  Config.getLogger(suppressLog).info('Test account funded; account balance: %d µALGO', accountInfo.balance.microAlgo)\n\n  algorand.setSignerFromAccount(account)\n\n  // eslint-disable-next-line @typescript-eslint/no-explicit-any\n  const address = Address.fromString(account.addr.toString()) as any\n  address.addr = account.addr\n  address.sk = account.sk\n  address.signer = algorand.account.getSigner(address)\n\n  return address\n}\n"],"names":[],"mappings":";;;;AAsCO,eAAe,cAAc,CAClC,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAwB,EAClE,qBAA+C,EAC/C,GAAS,EAAA;AAET,IAAA,MAAM,QAAQ,GACZ,qBAAqB,YAAY;AAC/B,UAAE;AACF,UAAE,cAAc,CAAC,WAAW,CAAC;AACzB,YAAA,KAAK,EAAE,qBAAqB;YAC5B,GAAG;AACJ,SAAA,CAAC;AAER,IAAA,MAAM,OAAO,GAAG,aAAa,GAAG,MAAM,aAAa,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,eAAe,EAAE;IAEzF,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,IAAI,CAChC,CAAA,uCAAA,EAA0C,OAAO,CAAC,IAAI,CAAmB,gBAAA,EAAA,OAAO,CAAC,mBAAmB,CAAC,OAAO,CAAC,EAAE,CAAC,CAAI,EAAA,CAAA,CACrH;IAED,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,wBAAwB,EAAE;AAEnE,IAAA,MAAM,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC;AAC1B,QAAA,MAAM,EAAE,SAAS;QACjB,QAAQ,EAAE,OAAO,CAAC,IAAI;AACtB,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