-
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.
refactor: replace private_token in sample_dapp e2e
- Loading branch information
Showing
5 changed files
with
63 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,11 @@ | ||
import { Contract } from '@aztec/aztec.js'; | ||
import { | ||
PrivateTokenContractAbi as PrivateTokenArtifact, | ||
PublicTokenContractAbi as PublicTokenArtifact, | ||
} from '@aztec/noir-contracts/artifacts'; | ||
import { TokenContractAbi } from '@aztec/noir-contracts/artifacts'; | ||
|
||
import { readFileSync } from 'fs'; | ||
|
||
// docs:start:get-tokens | ||
export async function getPrivateToken(client) { | ||
export async function getToken(client) { | ||
const addresses = JSON.parse(readFileSync('addresses.json')); | ||
return Contract.at(addresses.privateToken, PrivateTokenArtifact, client); | ||
} | ||
|
||
export async function getPublicToken(client) { | ||
const addresses = JSON.parse(readFileSync('addresses.json')); | ||
return Contract.at(addresses.publicToken, PublicTokenArtifact, client); | ||
return Contract.at(addresses.token, TokenContractAbi, client); | ||
} | ||
// docs:end:get-tokens |
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,25 +1,36 @@ | ||
import { createSandbox } from '@aztec/aztec-sandbox'; | ||
import { Contract, createAccount } from '@aztec/aztec.js'; | ||
import { PrivateTokenContractAbi as PrivateTokenArtifact } from '@aztec/noir-contracts/artifacts'; | ||
import { Contract, Fr, computeMessageSecretHash, createAccount } from '@aztec/aztec.js'; | ||
import { TokenContractAbi } from '@aztec/noir-contracts/artifacts'; | ||
|
||
describe('private token', () => { | ||
describe('token', () => { | ||
// docs:start:setup | ||
let rpc, stop, owner, recipient, token; | ||
beforeAll(async () => { | ||
({ rpcServer: rpc, stop } = await createSandbox()); | ||
owner = await createAccount(rpc); | ||
recipient = await createAccount(rpc); | ||
token = await Contract.deploy(owner, PrivateTokenArtifact, [100n, owner.getAddress()]).send().deployed(); | ||
|
||
token = await Contract.deploy(owner, TokenContractAbi, []).send().deployed(); | ||
await token.methods._initialize({ address: owner.getAddress() }).send().wait(); | ||
|
||
const initialBalance = 20n; | ||
const secret = Fr.random(); | ||
const secretHash = await computeMessageSecretHash(secret); | ||
await token.methods.mint_private(initialBalance, secretHash).send().wait(); | ||
await token.methods.redeem_shield({ address: owner.getAddress() }, initialBalance, secret).send().wait(); | ||
}, 60_000); | ||
|
||
afterAll(() => stop()); | ||
// docs:end:setup | ||
|
||
// docs:start:test | ||
it('increases recipient funds on transfer', async () => { | ||
expect(await token.methods.getBalance(recipient.getAddress()).view()).toEqual(0n); | ||
await token.methods.transfer(20n, recipient.getAddress()).send().wait(); | ||
expect(await token.methods.getBalance(recipient.getAddress()).view()).toEqual(20n); | ||
expect(await token.methods.balance_of_private({ address: recipient.getAddress() }).view()).toEqual(0n); | ||
await token.methods | ||
.transfer({ address: owner.getAddress() }, { address: recipient.getAddress() }, 20n, 0) | ||
.send() | ||
.wait(); | ||
expect(await token.methods.balance_of_private({ address: recipient.getAddress() }).view()).toEqual(20n); | ||
}); | ||
// docs:end:test | ||
}); |