{"version":3,"file":"account.mjs","names":[],"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"],"mappings":";;;;AAsCA,eAAsB,eACpB,EAAE,aAAa,cAAc,iBAC7B,uBACA,KACuD;CACvD,MAAM,WACJ,iCAAiC,iBAC7B,wBACA,eAAe,YAAY;EACzB,OAAO;EACP;CACF,CAAC;CAEP,MAAM,UAAU,gBAAgB,MAAM,cAAc,QAAQ,IAAI,QAAQ,gBAAgB;CAExF,OAAO,UAAU,WAAW,CAAC,CAAC,KAC5B,0CAA0C,QAAQ,KAAK,kBAAkB,QAAQ,oBAAoB,QAAQ,EAAE,EAAE,GACnH;CAEA,MAAM,YAAY,MAAM,SAAS,QAAQ,yBAAyB;CAElE,MAAM,SAAS,KAAK,QAAQ;EAC1B,QAAQ;EACR,UAAU,QAAQ;EAClB,QAAQ;EACR,MAAM;EACN;CACF,CAAC;CAED,MAAM,cAAc,MAAM,SAAS,QAAQ,eAAe,QAAQ,IAAI;CAEtE,OAAO,UAAU,WAAW,CAAC,CAAC,KAAK,kDAAkD,YAAY,QAAQ,SAAS;CAElH,SAAS,qBAAqB,OAAO;CAGrC,MAAM,UAAU,QAAQ,WAAW,QAAQ,KAAK,SAAS,CAAC;CAC1D,QAAQ,OAAO,QAAQ;CACvB,QAAQ,KAAK,QAAQ;CACrB,QAAQ,SAAS,SAAS,QAAQ,UAAU,OAAO;CAEnD,OAAO;AACT"}