|
| 1 | +// End-to-end test for the scaffolded Counter contract. |
| 2 | +// |
| 3 | +// Copied into the scaffolded workspace at test time by ../test.ts, then executed with |
| 4 | +// `node --test`. Runs from inside the workspace so that: |
| 5 | +// - `./artifacts/Counter.js` resolves to the codegen'd bindings (and its types flow). |
| 6 | +// - `@aztec/*` imports resolve via the workspace's `node_modules` symlink to the |
| 7 | +// installed Aztec toolchain — i.e. the same packages a real user would have. |
| 8 | +// |
| 9 | +// The test expects an `aztec start --local-network` node reachable at NODE_URL. It uses the |
| 10 | +// pre-funded test0 account that local-network already deployed, stands up an in-process |
| 11 | +// EmbeddedWallet + PXE, deploys a fresh Counter, and exercises a full round trip through |
| 12 | +// the codegen'd bindings (send + simulate). |
| 13 | + |
| 14 | +import test from 'node:test'; |
| 15 | +import assert from 'node:assert/strict'; |
| 16 | + |
| 17 | +import { getInitialTestAccountsData } from '@aztec/accounts/testing'; |
| 18 | +import { EmbeddedWallet } from '@aztec/wallets/embedded'; |
| 19 | + |
| 20 | +import { CounterContract } from './artifacts/Counter.ts'; |
| 21 | + |
| 22 | +const NODE_URL = process.env.NODE_URL ?? 'http://localhost:8080'; |
| 23 | +const INITIAL_COUNTER_VALUE = 0n; |
| 24 | + |
| 25 | +test('Counter deploys and increments through codegen bindings', async () => { |
| 26 | + const wallet = await EmbeddedWallet.create(NODE_URL, { ephemeral: true }); |
| 27 | + |
| 28 | + const [test0] = await getInitialTestAccountsData(); |
| 29 | + await wallet.createSchnorrAccount(test0.secret, test0.salt, test0.signingKey); |
| 30 | + const owner = test0.address; |
| 31 | + |
| 32 | + const { contract: counter } = await CounterContract.deploy(wallet, INITIAL_COUNTER_VALUE, owner).send({ |
| 33 | + from: owner, |
| 34 | + }); |
| 35 | + |
| 36 | + const initial = await counter.methods.get_counter(owner).simulate({ from: owner }); |
| 37 | + assert.equal(initial.result, INITIAL_COUNTER_VALUE, 'counter value just after deploy'); |
| 38 | + |
| 39 | + await counter.methods.increment(owner).send({ from: owner }); |
| 40 | + |
| 41 | + const afterIncrement = await counter.methods.get_counter(owner).simulate({ from: owner }); |
| 42 | + assert.equal(afterIncrement.result, INITIAL_COUNTER_VALUE + 1n, 'counter value after increment'); |
| 43 | +}); |
0 commit comments