You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

backendTest.ts 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  1. import { Injector } from "../src/backend/Injector/Injector";
  2. import { FrontworkAdmin } from "../src/backend/Admin/Admin";
  3. import { T1, T2, Tiers } from "../src/backend/Types/Items";
  4. import { RPCSocket } from "rpclibrary";
  5. import { FrontcraftIfc, Auth, User, FrontcraftFeatureIfc, Raid, Character, Rank, Class, Race, SRPriority, Spec, Signup } from "../src/backend/Types/Types";
  6. import { SpecT } from "../src/backend/Types/PlayerSpecs";
  7. type protoAccount<C extends Class = Class> = {
  8. name: string,
  9. pwHash?: string
  10. rank: Rank,
  11. race: Race,
  12. class: C,
  13. spec: SpecT[C]
  14. }
  15. const trialsAndUp = {
  16. ADMIN: true,
  17. Guildmaster: true,
  18. Officer: true,
  19. Classleader: true,
  20. Raider: true,
  21. Trial: true,
  22. Social: false,
  23. Guest: false
  24. }
  25. const adminsOnly = {
  26. ADMIN: true,
  27. Guildmaster: true,
  28. Officer: true,
  29. Classleader: false,
  30. Raider: false,
  31. Trial: false,
  32. Social: false,
  33. Guest: false
  34. }
  35. const defaultPermissions = [
  36. {
  37. rpcname: 'signup', ...trialsAndUp
  38. }, {
  39. rpcname: 'reset', ...adminsOnly
  40. }, {
  41. rpcname: 'modifyPermissions', ...adminsOnly
  42. }, {
  43. rpcname: 'manageGuild', ...adminsOnly
  44. }, {
  45. rpcname: 'managePriorities', ...adminsOnly
  46. }, {
  47. rpcname: 'softreserveCurrency', ...adminsOnly
  48. }, {
  49. rpcname: 'manageRaid', ...adminsOnly
  50. }]
  51. const testAccounts: protoAccount[] = [
  52. {
  53. name: 'Rain',
  54. race: 'Human',
  55. class: 'Warrior',
  56. spec: 'Protection',
  57. rank: 'Guildmaster'
  58. }, {
  59. name: 'Celinda',
  60. class: 'Warrior',
  61. race: 'Night Elf',
  62. spec: 'Protection',
  63. rank: 'Officer'
  64. }, {
  65. name: 'Silver',
  66. class: 'Druid',
  67. race: 'Night Elf',
  68. spec: 'Restoration',
  69. rank: 'Raider'
  70. }, {
  71. name: 'Dagger',
  72. race: 'Dwarf',
  73. class: 'Rogue',
  74. spec: 'Assassination',
  75. rank: 'Classleader'
  76. }, {
  77. name: 'Hope',
  78. class: 'Paladin',
  79. race: 'Human',
  80. spec: 'Holy',
  81. rank: 'Classleader'
  82. }, {
  83. name: 'Shrekd',
  84. class: 'Warrior',
  85. race: 'Dwarf',
  86. spec: 'Fury',
  87. rank: 'Classleader'
  88. }, {
  89. name: 'Teeniweeni',
  90. class: 'Warlock',
  91. race: 'Gnome',
  92. spec: 'Demonology',
  93. rank: 'Classleader'
  94. }, {
  95. name: 'Hagibaba',
  96. class: 'Priest',
  97. race: 'Human',
  98. spec: 'Discipline',
  99. rank: 'Classleader'
  100. }, {
  101. name: 'Muffinbreak',
  102. class: 'Mage',
  103. race: 'Gnome',
  104. spec: 'Arcane',
  105. rank: 'Classleader'
  106. },
  107. ]
  108. describe('Frontcraft', () => {
  109. let auth: Auth,
  110. adminUser: User,
  111. server: FrontworkAdmin,
  112. client: RPCSocket & FrontcraftIfc,
  113. adminClient: RPCSocket & FrontcraftFeatureIfc,
  114. raids: Raid[] = [],
  115. users: { [username in string]: { account: User, character: Character, auth: Auth, signup?: Signup, item?: string } } = {}
  116. const createAccount = (user: User) => {
  117. return client.UserManager.createUser(user)
  118. }
  119. const createAccountAndUser = async (acc: protoAccount) => {
  120. const account = await createAccount({
  121. pwhash: 'ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb', //sha256("a")
  122. rank: acc.rank,
  123. username: acc.name,
  124. })
  125. const auth = await client.UserManager.login(acc.name, 'ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb')
  126. const id = await client.CharacterManager.getSpecId(acc.class, acc.spec)
  127. const char = await client.CharacterManager.createCharacter(auth.token.value, {
  128. charactername: acc.name,
  129. specid: id,
  130. userid: account.id!,
  131. race: acc.race
  132. })
  133. return {
  134. account: account,
  135. character: char,
  136. auth: auth
  137. }
  138. }
  139. before(function (done) {
  140. this.timeout(10000);
  141. server = Injector.resolve<FrontworkAdmin>(FrontworkAdmin)
  142. server.start().then((_server) => {
  143. RPCSocket.makeSocket<FrontcraftIfc>(20000, 'localhost').then(_client => {
  144. client = _client
  145. createAccount({
  146. pwhash: 'ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb', //hash("a")
  147. rank: 'ADMIN',
  148. username: 'a',
  149. MC: 2
  150. }).then(adminUser => {
  151. client.UserManager.login(adminUser.username, 'ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb').then(auth => {
  152. const sock = new RPCSocket(
  153. auth.port,
  154. "localhost"
  155. )
  156. sock.connect<any>(auth.token.value).then(cli => {
  157. adminClient = cli
  158. sock.hook('kick', () => {
  159. console.log("I got kicked");
  160. })
  161. sock.hook('getUserData', () => auth)
  162. sock.hook('navigate', (where: string) => {
  163. console.log("Nagivate client to " + where);
  164. })
  165. sock.on('error', (e) => {
  166. console.log('Socket error', e)
  167. })
  168. done()
  169. })
  170. })
  171. })
  172. })
  173. }).catch(done)
  174. })
  175. after(() => {
  176. client.destroy()
  177. adminClient.destroy()
  178. server.stop()
  179. })
  180. it('create raids', (done) => {
  181. let insertRaid = <Raid>{
  182. description: "Test raid 1",
  183. title: 'BWL :D',
  184. start: Date.now().toString(),
  185. tier: 'BWL'
  186. }
  187. adminClient.manageRaid.createRaid(insertRaid).then(() => {
  188. client.RaidManager.getRaids().then((r) => {
  189. if (r[0].title === insertRaid.title
  190. && r[0].description === insertRaid.description
  191. && r[0].tier === "BWL") {
  192. raids.push(r[0])
  193. done()
  194. }
  195. }).catch(done)
  196. }).catch(done)
  197. })
  198. it('create users', (done) => {
  199. Promise.all(testAccounts.map(acc => createAccountAndUser(acc))).then(accs => {
  200. if (accs.length === testAccounts.length) {
  201. accs.forEach(acc => {
  202. users[acc.account.username] = acc
  203. })
  204. done()
  205. }
  206. }).catch(done)
  207. })
  208. it('should sign up', (done) => {
  209. Promise.all(Object.values(users).map((user) =>
  210. adminClient.signup.sign(user.auth.token.value, user.character, raids[0], false).catch(done)
  211. )).then(x => {
  212. adminClient.signup.getSignups(raids[0]).then(s => {
  213. if (s.length == testAccounts.length) {
  214. s.forEach(sign => {
  215. users[sign.username].signup = sign
  216. })
  217. done()
  218. } else {
  219. done("Unexpected number of signups: " + s.length)
  220. }
  221. })
  222. })
  223. })
  224. it('calculate priorities', (done) => {
  225. const makePrio = async (itemname: string, spec?: Spec, race?: Race, mod: number = 0, description: string = "") => {
  226. let specid
  227. if (spec)
  228. specid = await client.CharacterManager.getSpecId(spec.class, <any>spec.specname)
  229. await adminClient.managePriorities.setPriority(itemname, {
  230. specid: specid,
  231. race: race,
  232. modifier: mod,
  233. description: description
  234. })
  235. }
  236. Promise.all([
  237. makePrio(
  238. 'Bracers of Arcane Accuracy',
  239. { class: 'Warlock', specname: 'Demonology' },
  240. undefined, 2, "hit bias"
  241. ),
  242. makePrio(
  243. 'Bracers of Arcane Accuracy',
  244. { class: 'Warlock', specname: 'Affliction' },
  245. undefined, 2, "hit bias"
  246. ),
  247. makePrio(
  248. 'Bracers of Arcane Accuracy',
  249. { class: 'Warlock', specname: 'Destruction' },
  250. undefined, 2, "hit bias"
  251. ),
  252. makePrio(
  253. 'Bracers of Arcane Accuracy',
  254. { class: 'Mage', specname: 'Arcane' },
  255. undefined, 1, "hit bias"
  256. ),
  257. makePrio(
  258. 'Bracers of Arcane Accuracy',
  259. { class: 'Mage', specname: 'Frost' },
  260. undefined, 1, "hit bias"
  261. ),
  262. makePrio(
  263. 'Bracers of Arcane Accuracy',
  264. { class: 'Mage', specname: 'Fire' },
  265. undefined, 1, "hit bias"
  266. ),
  267. makePrio(
  268. 'Maladath, Runed Blade of the Black Flight',
  269. undefined,
  270. "Human", -2, "[1] Non-Human"
  271. ),
  272. makePrio(
  273. 'Maladath, Runed Blade of the Black Flight',
  274. { class: 'Rogue', specname: 'Combat' },
  275. undefined, 2, "Weapon skill bias"
  276. ),
  277. makePrio(
  278. 'Maladath, Runed Blade of the Black Flight',
  279. { class: 'Warrior', specname: 'Fury' },
  280. 'Human', 4, "+2 Fury Warrior (weapon skill bias), +2 to offset [1]"
  281. ),
  282. makePrio(
  283. 'Maladath, Runed Blade of the Black Flight',
  284. { class: 'Warrior', specname: 'Protection' },
  285. 'Human', 5, "+3 Prot Warrior, +2 to offset [1]"
  286. ),
  287. makePrio(
  288. 'Cloak of Firemaw',
  289. { class: 'Rogue', specname: 'Assassination' },
  290. undefined, 2, "agi-to-ap bias"
  291. ),
  292. makePrio(
  293. 'Cloak of Firemaw',
  294. { class: 'Rogue', specname: 'Combat' },
  295. undefined, 2, "agi-to-ap bias"
  296. ),
  297. makePrio(
  298. 'Cloak of Firemaw',
  299. { class: 'Rogue', specname: 'Subtlety' },
  300. undefined, 2, "agi-to-ap bias"
  301. ),
  302. makePrio(
  303. 'Band of Forced Concentration',
  304. { class: 'Warlock', specname: 'Demonology' },
  305. undefined, 2, "hit bias"
  306. ),
  307. makePrio(
  308. 'Band of Forced Concentration',
  309. { class: 'Warlock', specname: 'Affliction' },
  310. undefined, 2, "hit bias"
  311. ),
  312. makePrio(
  313. 'Band of Forced Concentration',
  314. { class: 'Warlock', specname: 'Destruction' },
  315. undefined, 2, "hit bias"
  316. ),
  317. makePrio(
  318. 'Band of Forced Concentration',
  319. { class: 'Mage', specname: 'Arcane' },
  320. undefined, 1, "hit bias"
  321. ),
  322. makePrio(
  323. 'Band of Forced Concentration',
  324. { class: 'Mage', specname: 'Frost' },
  325. undefined, 1, "hit bias"
  326. ),
  327. makePrio(
  328. 'Band of Forced Concentration',
  329. { class: 'Mage', specname: 'Fire' },
  330. undefined, 1, "hit bias"
  331. ),
  332. makePrio(
  333. 'Chromatic Boots',
  334. { class: 'Warrior', specname: 'Protection' },
  335. undefined, 2, "hit bias"
  336. ),
  337. makePrio(
  338. 'Crul\'shorukh, Edge of Chaos',
  339. undefined,
  340. "Human", -2, "Non-human"
  341. ),
  342. makePrio(
  343. 'Crul\'shorukh, Edge of Chaos',
  344. { class: 'Warrior', specname: 'Protection' },
  345. undefined, 2, "nice dps bias"
  346. ),
  347. makePrio(
  348. 'Crul\'shorukh, Edge of Chaos',
  349. { class: 'Warrior', specname: 'Fury' },
  350. undefined, 2, "nice dps bias"
  351. ),
  352. makePrio(
  353. 'Drake Talon Pauldrons',
  354. { class: 'Warrior', specname:'Protection'},
  355. undefined, 2, 'dodge + stats-to-threat bias'
  356. ),
  357. makePrio(
  358. 'Helm of Endless Rage',
  359. { class: 'Warrior', specname:'Protection'},
  360. undefined, 2, 'stats-to-threat bias'
  361. ),
  362. makePrio(
  363. 'Drake Fang Talisman',
  364. { class: 'Warrior', specname: 'Protection' },
  365. undefined, 5, "hit bias"
  366. ),
  367. makePrio(
  368. 'Drake Fang Talisman',
  369. { class: 'Rogue', specname: 'Assassination' },
  370. undefined, 4, "hit bias"
  371. ),
  372. makePrio(
  373. 'Drake Fang Talisman',
  374. { class: 'Rogue', specname: 'Combat' },
  375. undefined, 4, "hit bias"
  376. ),
  377. makePrio(
  378. 'Drake Fang Talisman',
  379. { class: 'Rogue', specname: 'Subtlety' },
  380. undefined, 4, "hit bias"
  381. ),
  382. makePrio(
  383. 'Drake Fang Talisman',
  384. { class: 'Warrior', specname: 'Fury' },
  385. undefined, 2, "hit bias"
  386. ),
  387. makePrio(
  388. 'Drake Fang Talisman',
  389. { class: 'Druid', specname: 'Feral (DPS)' },
  390. undefined, 2, "hit bias"
  391. ),
  392. makePrio(
  393. 'Circle of Applied Force',
  394. { class: 'Warrior', specname: 'Fury' },
  395. undefined, 2, "str-to-ap bias"
  396. ),
  397. makePrio(
  398. 'Circle of Applied Force',
  399. { class: 'Druid', specname: 'Feral (DPS)' },
  400. undefined, 3, "str-to-ap bias + agi-to-ap bias"
  401. ),
  402. makePrio(
  403. 'Empowered Leggings',
  404. { class: 'Paladin', specname: 'Holy' },
  405. undefined, 2, "crit bias"
  406. ),
  407. makePrio(
  408. 'Empowered Leggings',
  409. { class: 'Druid', specname: 'Restoration' },
  410. undefined, 2, "crit bias"
  411. ),
  412. makePrio(
  413. 'Boots of the Shadow Flame',
  414. { class: 'Rogue', specname: 'Assassination' },
  415. undefined, 2, "hit bias"
  416. ),
  417. makePrio(
  418. 'Boots of the Shadow Flame',
  419. { class: 'Rogue', specname: 'Combat' },
  420. undefined, 2, "hit bias"
  421. ),
  422. makePrio(
  423. 'Boots of the Shadow Flame',
  424. { class: 'Rogue', specname: 'Subtlety' },
  425. undefined, 2, "hit bias"
  426. ),
  427. makePrio(
  428. 'Boots of the Shadow Flame',
  429. { class: 'Druid', specname: 'Feral (DPS)' },
  430. undefined, 2, "hit bias"
  431. ),
  432. makePrio(
  433. 'Neltharion\'s Tear',
  434. { class: 'Warlock', specname: 'Demonology' },
  435. undefined, 4, "hit bias"
  436. ),
  437. makePrio(
  438. 'Neltharion\'s Tear',
  439. { class: 'Warlock', specname: 'Affliction' },
  440. undefined, 4, "hit bias"
  441. ),
  442. makePrio(
  443. 'Neltharion\'s Tear',
  444. { class: 'Warlock', specname: 'Destruction' },
  445. undefined, 4, "hit bias"
  446. ),
  447. makePrio(
  448. 'Neltharion\'s Tear',
  449. { class: 'Mage', specname: 'Arcane' },
  450. undefined, 2, "hit bias"
  451. ),
  452. makePrio(
  453. 'Neltharion\'s Tear',
  454. { class: 'Mage', specname: 'Frost' },
  455. undefined, 2, "hit bias"
  456. ),
  457. makePrio(
  458. 'Neltharion\'s Tear',
  459. { class: 'Mage', specname: 'Fire' },
  460. undefined, 2, "hit bias"
  461. ),
  462. makePrio(
  463. 'Cloak of Draconic Might',
  464. { class: 'Warrior', specname: 'Fury' },
  465. undefined, 2, "str-to-ap bias"
  466. ),
  467. makePrio(
  468. 'Cloak of Draconic Might',
  469. { class: 'Druid', specname: 'Feral (DPS)' },
  470. undefined, 1, "str-to-ap bias"
  471. ),
  472. ]).then(() => {
  473. const user = Object.values(users)[0]
  474. client.ItemManager.calculatePriorities("Maladath, Runed Blade of the Black Flight", user.character).then(sum => {
  475. if (sum === 3)
  476. done()
  477. else
  478. console.log("Expected prio on maladath to be 4, but was:", sum, user.character);
  479. })
  480. })
  481. })
  482. it('buy token', (done) => {
  483. Promise.all(Object.values(users).map(async (user) => {
  484. const itemname = "Maladath, Runed Blade of the Black Flight" //T1[Math.floor(T1.length*Math.random())]
  485. const modifier = await client.ItemManager.calculatePriorities(itemname, user.character)
  486. const token = await client.ItemManager.buyToken(user.auth.token.value, user.character.charactername, itemname, user.signup!)
  487. users[user.account.username].item = itemname
  488. if (!token) return false
  489. return modifier + 1 === token.level
  490. })).then(success => {
  491. if (success.reduce((prev, curr) => prev && curr, true)) done()
  492. })
  493. })
  494. it('not buy token without currency', (done) => {
  495. const user = Object.values(users)[0]
  496. const itemname = "Maladath, Runed Blade of the Black Flight"
  497. client.ItemManager.buyToken(user.auth.token.value, user.character.charactername, itemname, user.signup!).then(token => {
  498. if (!token)
  499. done()
  500. else {
  501. console.log("Unexpected token", token);
  502. }
  503. })
  504. })
  505. it('upgrade token', (done) => {
  506. const user = Object.values(users)[0]
  507. const itemname = "Maladath, Runed Blade of the Black Flight"
  508. client.ItemManager.getItem(itemname).then(async item => {
  509. await adminClient.softreserveCurrency.incrementCurrency(user.account, item.tier, 2)
  510. const before = await client.ItemManager.getToken(user.character, item)
  511. if (!before || before.level !== 4) {
  512. console.log("expected level to be 4", before ? before.level : '?');
  513. return
  514. }
  515. await client.ItemManager.buyToken(user.auth.token.value, user.character.charactername, itemname, user.signup!)
  516. const after = await client.ItemManager.buyToken(user.auth.token.value, user.character.charactername, itemname, user.signup!)
  517. if (!after || after.level !== 6) {
  518. console.log("expected level after to be 6", after ? after.level : '?');
  519. return
  520. }
  521. done()
  522. })
  523. })
  524. it('should buy more tokens', (done) => {
  525. Promise.all(Object.values(users).map(async (user) => {
  526. await adminClient.softreserveCurrency.incrementCurrency(user.account, raids[0].tier, 1)
  527. return await client.ItemManager
  528. .buyToken(
  529. user.auth.token.value,
  530. user.character.charactername,
  531. T2[Math.floor(T2.length * Math.random())],
  532. user.signup!
  533. )
  534. })).then(_ => {
  535. done()
  536. })
  537. })
  538. it('can set permissions', (done) => {
  539. Promise.all(
  540. defaultPermissions.map(perm => adminClient.modifyPermissions.setPermission(perm)),
  541. ).then(_ => {
  542. done()
  543. })
  544. })
  545. it('start raid', (done) => {
  546. client.RaidManager.getRaids().then((r) => {
  547. adminClient.manageRaid.startRaid(raids[0]).then(async data => {
  548. const dbRaids = await client.RaidManager.getRaids()
  549. if (dbRaids.length === 0) {
  550. await client.UserManager.getUser(testAccounts[0].name).then(dbUser => {
  551. if (dbUser && dbUser.BWL === 1) {
  552. adminClient.signup.getSignups(raids[0]).then(signups => {
  553. if (signups.length === 0) {
  554. done()
  555. } else {
  556. console.log(signups);
  557. }
  558. })
  559. }
  560. else {
  561. console.log("Bad user currency", dbUser);
  562. }
  563. })
  564. }
  565. })
  566. })
  567. })
  568. it('reset system', (done) => {
  569. adminClient.reset.wipeCurrencyAndItems().then(() => {
  570. client.UserManager.getUser(testAccounts[0].name).then(user => {
  571. if (user && user.MC === 1) {
  572. client.ItemManager.getTokens(users[testAccounts[0].name.toLowerCase()].character, ['BWL']).then(tokens => {
  573. if (tokens!.length === 0) {
  574. done()
  575. } else {
  576. console.log(tokens);
  577. }
  578. })
  579. } else {
  580. console.log(user)
  581. }
  582. })
  583. })
  584. })
  585. it('implements loot system correctly', (done) => {
  586. const ONE_WEEK = 4800000000
  587. const Raid = (week: number, tier: string) => {
  588. return <Raid>{
  589. description: tier + " Test raid 1",
  590. title: tier,
  591. start: (week * ONE_WEEK + Date.now()).toString(),
  592. tier: tier
  593. }
  594. }
  595. const user = Object.values(users)[0]
  596. const createRaid = adminClient.manageRaid.createRaid
  597. const sign = async (raid: Raid, late = false) => await adminClient.signup.sign(user.auth.token.value, user.character, raid, late)
  598. const buyToken = async (signup: Signup, itemname: string) => await client.ItemManager.buyToken(user.auth.token.value, user.character.charactername, itemname, signup)
  599. const getCurrency = async (tier: Tiers) => {
  600. const dbUser = await client.UserManager.getUser(user.account.username)
  601. return dbUser[tier]
  602. }
  603. createRaid(Raid(0, 'BWL')).then(async (BWL0: Raid) => {
  604. const T2_0 = await client.ItemManager.getItem(T2[0])
  605. //const BWL0 = await createRaid(Raid(0, 'BWL'))
  606. const signupBWL0 = await sign(BWL0)
  607. let BWL = await getCurrency(BWL0.tier)
  608. let token = await buyToken(signupBWL0, T2[0])
  609. const BWLAfter = await getCurrency(BWL0.tier)
  610. if (!token
  611. || BWL - BWLAfter != 1) {
  612. console.log("Bad Token status", BWL0, signupBWL0, BWL, BWLAfter)
  613. done(new Error("Bad Token status 0"))
  614. return
  615. }
  616. let reserves = await client.ItemManager.getTokens(user.character, [BWL0.tier], true)
  617. let streaks = await client.ItemManager.getTokens(user.character, [BWL0.tier], false)
  618. if (reserves!.length != 1
  619. || streaks!.length != 0
  620. || reserves![0].itemname !== T2_0.itemname
  621. || reserves![0].level !== 1) {
  622. console.log("Bad Token status 1", reserves, streaks);
  623. done(new Error("Bad Token status"))
  624. return
  625. }
  626. await adminClient.manageRaid.startRaid(BWL0)
  627. reserves = await client.ItemManager.getTokens(user.character, [BWL0.tier], true)
  628. streaks = await client.ItemManager.getTokens(user.character, [BWL0.tier], false)
  629. if (reserves!.length != 0
  630. || streaks!.length != 1
  631. || streaks![0].itemname !== T2[0]
  632. || streaks![0].level !== 1) {
  633. console.log("Bad Token status", reserves, streaks);
  634. done(new Error("Bad Token status 2"))
  635. return
  636. }
  637. const BWL1 = await createRaid(Raid(1, 'BWL'))
  638. let signupBWL1 = await sign(BWL1)
  639. BWL = await getCurrency(BWL1.tier)
  640. await adminClient.manageRaid.adminUnsign(user.character, BWL1)
  641. let afterUnsign = await getCurrency(BWL1.tier)
  642. if (BWL !== afterUnsign) {
  643. console.log("Expected currency to be equal", BWL, afterUnsign)
  644. done(new Error("Expected currency to be equal"))
  645. return
  646. }
  647. signupBWL1 = await sign(BWL1)
  648. BWL = await getCurrency(BWL1.tier)
  649. await buyToken(signupBWL1, T2[1])
  650. await adminClient.manageRaid.adminUnsign(user.character, BWL1)
  651. afterUnsign = await getCurrency(BWL1.tier)
  652. if (BWL !== afterUnsign) {
  653. console.log("Expected currency to be equal", BWL, afterUnsign)
  654. done(new Error("Expected currency to be equal"))
  655. return
  656. }
  657. signupBWL1 = await sign(BWL1)
  658. await buyToken(signupBWL1, T2[1])
  659. reserves = await client.ItemManager.getTokens(user.character, [BWL1.tier], true)
  660. streaks = await client.ItemManager.getTokens(user.character, [BWL1.tier], false)
  661. if (reserves!.length != 1
  662. || streaks!.length != 0
  663. || reserves![0].itemname !== T2[1]
  664. || reserves![0].level !== 1) {
  665. console.log("Bad Token status", reserves, streaks);
  666. done(new Error("Bad Token status 3"))
  667. return
  668. }
  669. BWL = await getCurrency(BWL1.tier)
  670. const data = await adminClient.manageRaid.startRaid(BWL1)
  671. const afterStart = await getCurrency(BWL1.tier)
  672. if (BWL != 0 || afterStart != 1) {
  673. console.log("Wrong currency values", BWL, afterStart)
  674. done(new Error("Wrong currency values"))
  675. return
  676. }
  677. done()
  678. }).catch(e => {
  679. console.log(e);
  680. done(e)
  681. })
  682. })
  683. })