-
Notifications
You must be signed in to change notification settings - Fork 307
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
feat: nuking Pokeable
contract
#2939
Changes from 10 commits
d1f2e99
a2361e1
c46c176
9addbb8
2785b2f
43e167b
2f05b6d
db89ff3
85d8d1a
1aedc9b
5c64d1f
cc975b8
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 |
---|---|---|
@@ -1,63 +1,46 @@ | ||
import { AztecAddress, SignerlessWallet, Wallet } from '@aztec/aztec.js'; | ||
import { SignerlessWallet, Wallet } from '@aztec/aztec.js'; | ||
import { CircuitsWasm, Fr } from '@aztec/circuits.js'; | ||
import { siloNullifier } from '@aztec/circuits.js/abis'; | ||
import { DebugLogger } from '@aztec/foundation/log'; | ||
import { PokeableTokenContract } from '@aztec/noir-contracts/types'; | ||
import { AztecNode, CompleteAddress, PXE, TxStatus } from '@aztec/types'; | ||
import { TestContract } from '@aztec/noir-contracts/types'; | ||
import { AztecNode, PXE, TxStatus } from '@aztec/types'; | ||
|
||
import { expectsNumOfEncryptedLogsInTheLastBlockToBe, setup } from './fixtures/utils.js'; | ||
import { setup } from './fixtures/utils.js'; | ||
|
||
describe('e2e_non_contract_account', () => { | ||
let aztecNode: AztecNode | undefined; | ||
let pxe: PXE; | ||
let wallet: Wallet; | ||
let sender: AztecAddress; | ||
let recipient: AztecAddress; | ||
let pokerWallet: Wallet; | ||
let nonContractAccountWallet: Wallet; | ||
let teardown: () => Promise<void>; | ||
|
||
let logger: DebugLogger; | ||
|
||
let contract: PokeableTokenContract; | ||
|
||
const initialBalance = 987n; | ||
let contract: TestContract; | ||
|
||
beforeEach(async () => { | ||
let accounts: CompleteAddress[]; | ||
({ teardown, aztecNode, pxe, accounts, wallet, logger } = await setup(2)); | ||
sender = accounts[0].address; | ||
recipient = accounts[1].address; | ||
pokerWallet = new SignerlessWallet(pxe); | ||
let wallet: Wallet; | ||
({ teardown, aztecNode, pxe, wallet, logger } = await setup(1)); | ||
nonContractAccountWallet = new SignerlessWallet(pxe); | ||
|
||
logger(`Deploying L2 contract...`); | ||
const tx = PokeableTokenContract.deploy(pxe, initialBalance, sender, recipient).send(); | ||
await tx.isMined({ interval: 0.1 }); | ||
const receipt = await tx.getReceipt(); | ||
expect(receipt.status).toEqual(TxStatus.MINED); | ||
contract = await TestContract.deploy(wallet).send().deployed(); | ||
logger('L2 contract deployed'); | ||
contract = await PokeableTokenContract.at(receipt.contractAddress!, wallet); | ||
}, 100_000); | ||
|
||
afterEach(() => teardown()); | ||
|
||
const expectBalance = async (owner: AztecAddress, expectedBalance: bigint) => { | ||
const balance = await contract.methods.getBalance(owner).view({ from: owner }); | ||
logger(`Account ${owner} balance: ${balance}`); | ||
expect(balance).toBe(expectedBalance); | ||
}; | ||
|
||
it('Arbitrary non-contract account can call a private function on a contract', async () => { | ||
await expectBalance(sender, initialBalance); | ||
await expectBalance(recipient, 0n); | ||
await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 1); | ||
|
||
const contractWithNoContractWallet = await PokeableTokenContract.at(contract.address, pokerWallet); | ||
const contractWithNoContractWallet = await TestContract.at(contract.address, nonContractAccountWallet); | ||
|
||
// Send transaction as poker (arbitrary non-contract account) | ||
await contractWithNoContractWallet.methods.poke(sender, recipient).send().wait({ interval: 0.1 }); | ||
// Send transaction as arbitrary non-contract account | ||
const nullifier = new Fr(940); | ||
const receipt = await contractWithNoContractWallet.methods.emit_nullifier(nullifier).send().wait({ interval: 0.1 }); | ||
expect(receipt.status).toBe(TxStatus.MINED); | ||
|
||
// Initial balance should be fully transferred to the recipient | ||
await expectBalance(sender, 0n); | ||
await expectBalance(recipient, initialBalance); | ||
const tx = await aztecNode!.getTx(receipt.txHash); | ||
const expectedSiloedNullifier = siloNullifier(await CircuitsWasm.get(), contract.address, nullifier); | ||
const siloedNullifier = tx!.newNullifiers[1]; | ||
|
||
await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 1); | ||
expect(siloedNullifier.equals(expectedSiloedNullifier)).toBeTruthy(); | ||
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 not 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. It didn't work and I assume it was because TS was comparing object identity and not its values. |
||
}, 120_000); | ||
}); |
This file was deleted.
This file was deleted.
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.
Should probably have a note on what is used as
msg_sender
. Not sure if @iAmMichaelConnor figured out what he desired the value to be? 👀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.
Mike's response in my DMs: