-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: nuking
Pokeable
contract (#2939)
Fixes #2938 + fixed the camel case naming in the `Test` contract
- Loading branch information
Showing
15 changed files
with
77 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 21 additions & 38 deletions
59
yarn-project/end-to-end/src/e2e_non_contract_account.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}, 120_000); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
yarn-project/noir-contracts/src/contracts/pokeable_token_contract/Nargo.toml
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.