-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
92 additions
and
111 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,57 @@ | ||
# Run locally from end-to-end folder while running anvil and sandbox with: | ||
# PATH=$PATH:../node_modules/.bin ./src/guides/up_quick_start.sh | ||
alias aztec-wallet='node --no-warnings ../cli-wallet/dest/bin/index.js' | ||
|
||
set -eux | ||
|
||
# docs:start:declare-accounts | ||
ACCOUNTS=$(aztec-cli get-accounts --json | jq -r '.[].address') | ||
ALICE=$(echo "$ACCOUNTS" | sed -n 1p) | ||
BOB=$(echo "$ACCOUNTS" | sed -n 2p) | ||
ALICE_PRIVATE_KEY="0x2153536ff6628eee01cf4024889ff977a18d9fa61d0e414422f7681cf085c281" | ||
aztec-wallet create-account -a alice | ||
aztec-wallet create-account -a bob | ||
# docs:end:declare-accounts | ||
|
||
# docs:start:deploy | ||
CONTRACT=$(aztec-cli deploy TokenContractArtifact --private-key $ALICE_PRIVATE_KEY --salt 0 --args $ALICE "TokenName" "TKN" 18 --json | jq -r '.address') | ||
echo "Deployed contract at $CONTRACT" | ||
aztec-cli check-deploy --contract-address $CONTRACT | ||
DEPLOY_OUTPUT=$(aztec-wallet deploy ../noir-contracts.js/artifacts/token_contract-Token.json --args accounts:alice Test TST 18 -f alice) | ||
TOKEN_ADDRESS=$(echo "$DEPLOY_OUTPUT" | grep -oE 'Contract deployed at 0x[0-9a-fA-F]+' | cut -d ' ' -f4) | ||
echo "Deployed contract at $TOKEN_ADDRESS" | ||
aztec get-contract-data $TOKEN_ADDRESS | ||
# docs:end:deploy | ||
|
||
# docs:start:mint-private | ||
SECRET="0x29bf6afaf29f61cbcf2a4fa7da97be481fb418dc08bdab5338839974beb7b49f" | ||
SECRET_HASH="0x0921759afa747c9073f75df9688a17d271cef0d6ec51eacf70e112402c4db6cd" | ||
MINT_AMOUNT=69 | ||
aztec-wallet create-secret -a shield | ||
|
||
MINT_PRIVATE_OUTPUT=$(aztec-cli send mint_private \ | ||
--args 1000 $SECRET_HASH \ | ||
--contract-artifact TokenContractArtifact \ | ||
--contract-address $CONTRACT \ | ||
--private-key $ALICE_PRIVATE_KEY) | ||
aztec-wallet send mint_private -ca last --args $MINT_AMOUNT secrets:shield:hash -f alice | ||
|
||
MINT_PRIVATE_TX_HASH=$(echo "$MINT_PRIVATE_OUTPUT" | grep "Transaction hash:" | awk '{print $NF}') | ||
aztec-wallet add-note TransparentNote pending_shields -ca last -t last -a alice -b $MINT_AMOUNT secrets:shield:hash | ||
|
||
aztec-cli add-note \ | ||
$ALICE $CONTRACT 5 84114971101151129711410111011678111116101 $MINT_PRIVATE_TX_HASH \ | ||
--note 1000 $SECRET_HASH | ||
|
||
aztec-cli send redeem_shield \ | ||
--args $ALICE 1000 $SECRET \ | ||
--contract-artifact TokenContractArtifact \ | ||
--contract-address $CONTRACT \ | ||
--private-key $ALICE_PRIVATE_KEY | ||
aztec-wallet send redeem_shield -ca last --args accounts:alice $MINT_AMOUNT secrets:shield -f alice | ||
# docs:end:mint-private | ||
|
||
# docs:start:get-balance | ||
aztec-cli call balance_of_private \ | ||
--args $ALICE \ | ||
--contract-artifact TokenContractArtifact \ | ||
--contract-address $CONTRACT | ||
ALICE_BALANCE=$(aztec-wallet simulate balance_of_private -ca last --args accounts:alice -f alice) | ||
if ! echo $ALICE_BALANCE | grep -q $MINT_AMOUNT; then | ||
echo "Incorrect Alice balance after transaction (expected $MINT_AMOUNT but got $ALICE_BALANCE)" | ||
exit 1 | ||
fi | ||
# docs:end:get-balance | ||
|
||
# docs:start:transfer | ||
aztec-cli send transfer \ | ||
--args $ALICE $BOB 500 0 \ | ||
--contract-artifact TokenContractArtifact \ | ||
--contract-address $CONTRACT \ | ||
--private-key $ALICE_PRIVATE_KEY | ||
|
||
aztec-cli call balance_of_private \ | ||
--args $ALICE \ | ||
--contract-artifact TokenContractArtifact \ | ||
--contract-address $CONTRACT | ||
TRANSFER_AMOUNT=42 | ||
|
||
aztec-cli call balance_of_private \ | ||
--args $BOB \ | ||
--contract-artifact TokenContractArtifact \ | ||
--contract-address $CONTRACT | ||
aztec-wallet send transfer -ca last --args accounts:bob $TRANSFER_AMOUNT -f alice | ||
# docs:end:transfer | ||
|
||
aztec-cli get-logs | ||
aztec get-logs | ||
|
||
# Test end result | ||
BOB_BALANCE=$(aztec-cli call balance_of_private --args $BOB --contract-artifact TokenContractArtifact --contract-address $CONTRACT) | ||
if ! echo $BOB_BALANCE | grep -q 500; then | ||
echo "Incorrect Bob balance after transaction (expected 500 but got $BOB_BALANCE)" | ||
ALICE_BALANCE=$(aztec-wallet simulate balance_of_private -ca last --args accounts:alice -f alice) | ||
if ! echo $ALICE_BALANCE | grep -q 27; then | ||
echo "Incorrect Alice balance after transaction (expected 27 but got $ALICE_BALANCE)" | ||
exit 1 | ||
fi | ||
|
||
BOB_BALANCE=$(aztec-wallet simulate balance_of_private -ca last --args accounts:bob -f bob) | ||
if ! echo $BOB_BALANCE | grep -q 42; then | ||
echo "Incorrect Bob balance after transaction (expected 42 but got $BOB_BALANCE)" | ||
exit 1 | ||
fi |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,46 @@ | ||
import { createAccount } from '@aztec/accounts/testing'; | ||
import { Contract, ExtendedNote, Fr, Note, computeSecretHash, createPXEClient, waitForPXE } from '@aztec/aztec.js'; | ||
import { TokenContractArtifact } from '@aztec/noir-contracts.js/Token'; | ||
import { TokenContract, TokenContractArtifact } from '@aztec/noir-contracts.js/Token'; | ||
|
||
const { PXE_URL = 'http://localhost:8080', ETHEREUM_HOST = 'http://localhost:8545' } = process.env; | ||
|
||
describe('token', () => { | ||
// docs:start:setup | ||
let owner, recipient, token; | ||
beforeAll(async () => { | ||
const pxe = createPXEClient(PXE_URL); | ||
await waitForPXE(pxe); | ||
owner = await createAccount(pxe); | ||
recipient = await createAccount(pxe); | ||
console.log('FINE') | ||
// beforeAll(async () => { | ||
// const pxe = createPXEClient(PXE_URL); | ||
// await waitForPXE(pxe); | ||
// owner = await createAccount(pxe); | ||
// recipient = await createAccount(pxe); | ||
|
||
token = await Contract.deploy(owner, TokenContractArtifact, [owner.getCompleteAddress(), 'TokenName', 'TKN', 18]) | ||
.send() | ||
.deployed(); | ||
// token = await TokenContract.deploy(owner, owner.getAddress(), 'TokenName', 'TKN', 18).send().deployed(); | ||
|
||
const initialBalance = 20n; | ||
const secret = Fr.random(); | ||
const secretHash = await computeSecretHash(secret); | ||
const receipt = await token.methods.mint_private(initialBalance, secretHash).send().wait(); | ||
// const initialBalance = 69n; | ||
// const secret = Fr.random(); | ||
// const secretHash = await computeSecretHash(secret); | ||
// const receipt = await token.methods.mint_private(initialBalance, secretHash).send().wait(); | ||
|
||
const storageSlot = token.artifact.storageLayout['pending_shields'].slot; | ||
const noteTypeId = token.artifact.notes['TransparentNote'].id; | ||
const note = new Note([new Fr(initialBalance), secretHash]); | ||
const extendedNote = new ExtendedNote( | ||
note, | ||
owner.getAddress(), | ||
token.address, | ||
storageSlot, | ||
noteTypeId, | ||
receipt.txHash, | ||
); | ||
await pxe.addNote(extendedNote); | ||
// const note = new Note([new Fr(initialBalance), secretHash]); | ||
// const extendedNote = new ExtendedNote( | ||
// note, | ||
// owner.getAddress(), | ||
// token.address, | ||
// TokenContract.storage.pending_shields.slot, | ||
// TokenContract.notes.TransparentNote.id, | ||
// receipt.txHash, | ||
// ); | ||
// await pxe.addNote(extendedNote, owner.getAddress()); | ||
|
||
await token.methods.redeem_shield({ address: owner.getAddress() }, initialBalance, secret).send().wait(); | ||
}, 120_000); | ||
// docs:end:setup | ||
// await token.methods.redeem_shield(owner.getAddress(), initialBalance, secret).send().wait(); | ||
// }, 120_000); | ||
// // docs:end:setup | ||
|
||
// docs:start:test | ||
it('increases recipient funds on transfer', async () => { | ||
expect(await token.methods.balance_of_private(recipient.getAddress()).simulate()).toEqual(0n); | ||
await token.methods.transfer(owner.getAddress(), recipient.getAddress(), 20n, 0).send().wait(); | ||
expect(await token.methods.balance_of_private(recipient.getAddress()).simulate()).toEqual(20n); | ||
}, 30_000); | ||
// docs:end:test | ||
// // docs:start:test | ||
// it('increases recipient funds on transfer', async () => { | ||
// expect(await token.methods.balance_of_private(recipient.getAddress()).simulate()).toEqual(0n); | ||
// await token.methods.transfer(recipient.getAddress(), 20n).send().wait(); | ||
// expect(await token.methods.balance_of_private(recipient.getAddress()).simulate()).toEqual(20n); | ||
// }, 30_000); | ||
// // docs:end:test | ||
}); |
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