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

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