-
Notifications
You must be signed in to change notification settings - Fork 284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: Cleanup sandbox dependent tests #3861
Changes from 11 commits
b93d531
db662e8
7076ee6
3453dce
a30be6a
28a1ef5
9231590
e370f7b
431f72b
ef4c2ba
d8c2892
3378e09
695bccc
1b0a10b
b71c0e6
88fb559
2774060
4504a69
867350a
362f4d8
b9bbe1f
2d942fb
74a2193
6fb4248
e8c44ab
74149e2
ea1d635
1896b72
796a6bd
940b161
d96bae8
c1c5a81
463c858
a1ac6bc
8c00e6c
74d179a
4c169f3
2f38742
848497c
29a2aa7
9247064
2b01828
53ecc7c
2e7d550
3f68a96
b5334bd
c237ea1
b54ec49
1881d06
0c3355c
0d36628
b011582
224c50b
7003e5a
5a01b07
df057ed
2cde2bd
a3b13f1
9a54b82
bdaae06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { createPXEClient, PXE } from '@aztec/aztec.js'; | ||
|
||
const { PXE_URL = 'http://localhost:8080' } = process.env; | ||
|
||
export const waitForSandbox = async (pxe?: PXE) => { | ||
pxe = pxe ?? createPXEClient(PXE_URL); | ||
while (true) { | ||
try { | ||
await pxe!.getNodeInfo(); | ||
return true; | ||
} catch (error) { | ||
await new Promise(resolve => { | ||
setTimeout(resolve, 1000); | ||
}); | ||
} | ||
} | ||
}; | ||
|
||
// assumes sandbox is running locally, which this script does not trigger | ||
// as well as anvil. anvil can be started with yarn test:integration | ||
export const setupSandbox = async () => { | ||
const pxe = createPXEClient(PXE_URL); | ||
await waitForSandbox(pxe); | ||
return pxe; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { createPXEClient, PXE } from '@aztec/aztec.js'; | ||
|
||
const { PXE_URL = 'http://localhost:8080' } = process.env; | ||
|
||
export const waitForSandbox = async (pxe?: PXE) => { | ||
pxe = pxe ?? createPXEClient(PXE_URL); | ||
while (true) { | ||
try { | ||
await pxe!.getNodeInfo(); | ||
return true; | ||
} catch (error) { | ||
await new Promise(resolve => { | ||
setTimeout(resolve, 1000); | ||
}); | ||
} | ||
} | ||
}; | ||
|
||
// assumes sandbox is running locally, which this script does not trigger | ||
// as well as anvil. anvil can be started with yarn test:integration | ||
export const setupSandbox = async () => { | ||
const pxe = createPXEClient(PXE_URL); | ||
await waitForSandbox(pxe); | ||
return pxe; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { createPXEClient, PXE } from '@aztec/aztec.js'; | ||
|
||
const { PXE_URL = 'http://localhost:8080' } = process.env; | ||
|
||
export const waitForSandbox = async (pxe?: PXE) => { | ||
pxe = pxe ?? createPXEClient(PXE_URL); | ||
while (true) { | ||
try { | ||
await pxe!.getNodeInfo(); | ||
return true; | ||
} catch (error) { | ||
await new Promise(resolve => { | ||
setTimeout(resolve, 1000); | ||
}); | ||
} | ||
} | ||
}; | ||
|
||
// assumes sandbox is running locally, which this script does not trigger | ||
// as well as anvil. anvil can be started with yarn test:integration | ||
export const setupSandbox = async () => { | ||
const pxe = createPXEClient(PXE_URL); | ||
await waitForSandbox(pxe); | ||
return pxe; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,39 @@ | ||
import { createDebugLogger, fileURLToPath } from '@aztec/aztec.js'; | ||
import { createPXERpcServer } from '@aztec/pxe'; | ||
|
||
import Koa from 'koa'; | ||
import serve from 'koa-static'; | ||
import path, { dirname } from 'path'; | ||
|
||
import { setup } from './fixtures/utils.js'; | ||
import { browserTestSuite } from './shared/browser.js'; | ||
|
||
const { PXE_URL = '' } = process.env; | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = dirname(__filename); | ||
const PORT = 3000; | ||
const PXE_PORT = 3001; | ||
|
||
const logger = createDebugLogger('aztec:canary_aztec.js:web'); | ||
const pageLogger = createDebugLogger('aztec:canary_aztec.js:web:page'); | ||
/** | ||
* This test is a bit of a special case as it's relying on sandbox and web browser and not only on anvil and node.js. | ||
* To run the test, do the following: | ||
* 1) Build the whole repository, | ||
* 2) go to `yarn-project/aztec.js` and build the web packed package with `yarn build:web`, | ||
* 3) start anvil: `anvil`, | ||
* 4) open new terminal and optionally set the more verbose debug level: `DEBUG=aztec:*`, | ||
* 5) go to the sandbox dir `yarn-project/aztec-sandbox` and run `yarn start`, | ||
* 6) open new terminal and export the URL of PXE from Sandbox: `export PXE_URL='http://localhost:8080'`, | ||
* 7) go to `yarn-project/end-to-end` and run the test: `yarn test aztec_js_browser` | ||
* | ||
* NOTE: If you see aztec-sandbox logs spammed with unexpected logs there is probably a chrome process with a webpage | ||
* unexpectedly running in the background. Kill it with `killall chrome` | ||
*/ | ||
const setupApp = () => { | ||
|
||
const setupApp = async () => { | ||
const { pxe: pxeService } = await setup(1); | ||
let pxeURL = PXE_URL; | ||
if (!PXE_URL) { | ||
const pxeRPCServer = createPXERpcServer(pxeService); | ||
pxeRPCServer.start(PXE_PORT); | ||
pxeURL = `http://localhost:${PXE_PORT}`; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah you're right, I missed the |
||
|
||
const app = new Koa(); | ||
app.use(serve(path.resolve(__dirname, './web'))); | ||
const server = app.listen(PORT, () => { | ||
logger(`Server started at http://localhost:${PORT}`); | ||
logger(`Web Server started at http://localhost:${PORT}`); | ||
}); | ||
|
||
return server; | ||
return { server, pxeURL }; | ||
}; | ||
|
||
browserTestSuite(setupApp, pageLogger); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,19 +2,18 @@ import { | |
AccountWallet, | ||
AztecAddress, | ||
DebugLogger, | ||
GrumpkinScalar, | ||
PXE, | ||
Wallet, | ||
deployInitialSandboxAccounts, | ||
getSandboxAccountsWallets, | ||
generatePublicKey, | ||
getSchnorrAccount, | ||
} from '@aztec/aztec.js'; | ||
import { CardGameContract } from '@aztec/noir-contracts/CardGame'; | ||
|
||
import { setup } from './fixtures/utils.js'; | ||
|
||
/* eslint-disable camelcase */ | ||
|
||
const { PXE_URL } = process.env; | ||
|
||
interface Card { | ||
points: bigint; | ||
strength: bigint; | ||
|
@@ -53,6 +52,12 @@ function unwrapOptions<T>(options: NoirOption<T>[]): T[] { | |
|
||
const GAME_ID = 42; | ||
|
||
const ENCRYPTION_KEYS = [ | ||
GrumpkinScalar.fromString('2153536ff6628eee01cf4024889ff977a18d9fa61d0e414422f7681cf085c281'), | ||
GrumpkinScalar.fromString('aebd1b4be76efa44f5ee655c20bf9ea60f7ae44b9a7fd1fd9f189c7a0b0cdae'), | ||
GrumpkinScalar.fromString('0f6addf0da06c33293df974a565b03d1ab096090d907d98055a8b7f4954e120c'), | ||
]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
||
describe('e2e_card_game', () => { | ||
let pxe: PXE; | ||
let logger: DebugLogger; | ||
|
@@ -72,17 +77,28 @@ describe('e2e_card_game', () => { | |
let contractAsThirdPlayer: CardGameContract; | ||
|
||
beforeEach(async () => { | ||
// Card stats are derived from the users' private keys, so to get consistent values, we set up the | ||
// initial sandbox accounts that always use the same private keys, instead of random ones. | ||
({ pxe, logger, teardown } = await setup(0)); | ||
|
||
// Get pre-deployed account wallets if we're running against sandbox. | ||
if (PXE_URL) { | ||
wallets = await getSandboxAccountsWallets(pxe); | ||
} else { | ||
// Deploy initial wallets if we're NOT running against sandbox. | ||
wallets = await Promise.all((await deployInitialSandboxAccounts(pxe)).map(a => a.account.getWallet())); | ||
({ pxe, logger, teardown, wallets } = await setup(0)); | ||
|
||
const preRegisteredAccounts = await pxe.getRegisteredAccounts(); | ||
|
||
const toRegister = ENCRYPTION_KEYS.filter(key => { | ||
const publicKey = generatePublicKey(key); | ||
return ( | ||
preRegisteredAccounts.find(preRegisteredAccount => { | ||
return preRegisteredAccount.publicKey.equals(publicKey); | ||
}) == undefined | ||
); | ||
}); | ||
|
||
for (let i = 0; i < toRegister.length; i++) { | ||
logger(`Deploying account contract ${i}/${toRegister.length}...`); | ||
const encryptionPrivateKey = toRegister[i]; | ||
const account = getSchnorrAccount(pxe, encryptionPrivateKey, GrumpkinScalar.random()); | ||
const wallet = await account.waitDeploy({ interval: 0.1 }); | ||
wallets.push(wallet); | ||
Comment on lines
+90
to
+95
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know it's not part of this PR, but should we do this in a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably, yes. |
||
} | ||
logger('Account contracts deployed'); | ||
|
||
[firstPlayerWallet, secondPlayerWallet, thirdPlayerWallet] = wallets; | ||
[firstPlayer, secondPlayer, thirdPlayer] = wallets.map(a => a.getAddress()); | ||
await deployContract(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,27 +6,18 @@ import { setup as e2eSetup } from './fixtures/utils.js'; | |
import { cliTestSuite } from './shared/cli.js'; | ||
|
||
const HTTP_PORT = 9009; | ||
let RPC_URL = `http://localhost:${HTTP_PORT}`; | ||
const debug = createDebugLogger('aztec:e2e_cli'); | ||
|
||
let http: ReturnType<typeof startHttpRpcServer>; | ||
let pxe: PXE; | ||
let teardown: () => Promise<void>; | ||
|
||
// Use Sandbox PXE URL if we're running against sandbox | ||
const { PXE_URL } = process.env; | ||
if (PXE_URL) { | ||
RPC_URL = PXE_URL; | ||
} | ||
Comment on lines
-17
to
-20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why remove this? I think it's useful to be able to run this suite against a running server, so we don't have to recreate it every time. And it's not like it assumes it's a sandbox: it just requires a pxe. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I realise the issues with the changes I made. Should be sorted now. |
||
|
||
const testSetup = async () => { | ||
const context = await e2eSetup(2); | ||
debug(`Environment set up`); | ||
({ pxe, teardown } = context); | ||
if (!PXE_URL) { | ||
http = startHttpRpcServer(pxe, createPXERpcServer, HTTP_PORT); | ||
debug(`HTTP RPC server started in port ${HTTP_PORT}`); | ||
} | ||
http = startHttpRpcServer(pxe, createPXERpcServer, HTTP_PORT); | ||
debug(`HTTP RPC server started in port ${HTTP_PORT}`); | ||
return pxe; | ||
}; | ||
|
||
|
@@ -35,4 +26,4 @@ const testCleanup = async () => { | |
await teardown(); | ||
}; | ||
|
||
cliTestSuite('E2E CLI Test', testSetup, testCleanup, createDebugLogger('aztec:e2e_cli'), RPC_URL); | ||
cliTestSuite('E2E CLI Test', testSetup, testCleanup, createDebugLogger('aztec:e2e_cli')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about keeping this function but renaming it to
waitForPXE
..?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh, just saw we have it but as part of the e2e utils. I think it makes sense to promote it to an util here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done