tools/client/test_backyard_bank.mjs (4669B)
1 import assert from 'node:assert/strict'; 2 import {createRequire} from 'node:module'; 3 import {GameTest} from './game_test.mjs'; 4 5 const {chromium} = createRequire(import.meta.url)('playwright'); 6 const [url, output, phase] = process.argv.slice(2); 7 const browser = await chromium.launch({executablePath: '/usr/bin/chromium', 8 args: ['--enable-gpu', '--use-gl=angle', '--use-angle=gl', '--no-sandbox', '--disable-dev-shm-usage', 9 '--disable-background-timer-throttling', '--disable-renderer-backgrounding']}); 10 const failures = []; 11 try { 12 for (const [index, id] of [[0, 3221752760], [1, 3221357727]]) { 13 const context = await browser.newContext({viewport: {width: 1024, height: 768}}); 14 await context.addCookies([{name: 'ao_client', value: 'bank-check-' + index, url}]); 15 const page = await context.newPage(); 16 const game = await GameTest.attach(page); 17 const state = async () => (await (await page.request.get(url + '/test-state')).json())[index + 1]; 18 try { 19 await page.goto(url); 20 await game.ready(); 21 if (phase === 'live' && index === 0) await game.walk(109.204704, 150.720703); 22 if (!game.state.camera.firstPerson) await game.key('F8'); 23 await game.wait('native first-person camera', snapshot => snapshot.camera.firstPerson); 24 await game.save(output + '/' + index + '/approach'); 25 const [px, py] = await game.pick(51005, id); 26 await game.click(px, py, 'right'); 27 await game.wait('bank Use acknowledged', () => game.events.some(event => 28 event.direction === 'framereceived' && event.opcode === '343c287f')); 29 await game.wait('native bank window open', snapshot => snapshot.regions.some(region => 30 region[0] === 0 && region[1] === 0 && region[2] === 178 && region[3] === 128)); 31 assert.equal((await state()).bankOpen, true); 32 await game.key('KeyI'); 33 const expected = {ID: index + 1, Type: 51005, Template: 42640, Quality: 1, Slot: 64, Count: 1, Ammo: 0}; 34 if (phase === 'live') { 35 assert.deepEqual((await state()).inventory.Items, [expected]); 36 await game.click(681, 45); 37 await game.click(30, 45); 38 await game.wait('exact deposit removes the carried row', snapshot => !game.local(snapshot).inventory.some(item => item.id === index + 1)); 39 assert.deepEqual((await state()).inventory.Bank, [{...expected, Slot: 0}]); 40 await game.save(output + '/' + index + '/deposited'); 41 } else { 42 assert.deepEqual((await state()).inventory.Bank, [{...expected, Slot: 0}]); 43 } 44 await game.click(30, 45); 45 await game.wait('exact bank withdrawal returns the row', snapshot => game.local(snapshot).inventory.some(item => item.id === index + 1 && item.slot === 48)); 46 assert.deepEqual((await state()).inventory.Items, [expected]); 47 assert.deepEqual((await state()).inventory.Bank, []); 48 await game.click(170, 8); 49 await game.wait('native bank close', snapshot => !snapshot.regions.some(region => 50 region[0] === 0 && region[1] === 0 && region[2] === 178 && region[3] === 128)); 51 assert.equal((await state()).bankOpen, false); 52 if (phase === 'live') { 53 await page.reload(); 54 await game.ready(); 55 assert(game.local().inventory.some(item => item.id === index + 1 && item.slot === 48)); 56 if (!game.state.camera.firstPerson) await game.hold('F8', 'reconnected first-person camera', 57 snapshot => snapshot.camera.firstPerson); 58 await game.wait('reconnected first-person camera', snapshot => snapshot.camera.firstPerson); 59 const [x, y] = await game.pick(51005, id); 60 await game.click(x, y, 'right'); 61 await game.wait('reconnected native bank open', snapshot => snapshot.regions.some(region => 62 region[0] === 0 && region[1] === 0 && region[2] === 178 && region[3] === 128)); 63 await game.key('KeyI'); 64 await game.click(681, 45); 65 await game.click(30, 45); 66 await game.wait('same item deposited before cold startup', snapshot => !game.local(snapshot).inventory.some(item => item.id === index + 1)); 67 assert.deepEqual((await state()).inventory.Bank, [{...expected, Slot: 0}]); 68 } 69 assert.equal(game.errors.length, 0); 70 console.log('PASS:', phase, 'original bank picking and exact-instance transfers', index, id); 71 } catch (error) { 72 failures.push(error); 73 console.log('FAIL:', index, error.message); 74 } finally { 75 try { await game.save(output + '/' + index + '/final'); } 76 finally { await context.close(); } 77 } 78 } 79 assert.equal(failures.length, 0, failures.map(error => error.message).join('\n')); 80 } finally { 81 await browser.close(); 82 }