Skip to content

Commit

Permalink
feat: TokenContract takes admin in constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
alexghr committed Sep 27, 2023
1 parent 145852e commit 977304c
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 43 deletions.
5 changes: 3 additions & 2 deletions yarn-project/end-to-end/src/canary/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,14 @@ export const browserTestSuite = (setup: () => Server, pageLogger: AztecJs.DebugL
accounts = await client.getRegisteredAccounts();
}
const [owner] = await getSandboxAccountsWallets(client);
const tx = new DeployMethod(accounts[0].publicKey, client, TokenContractAbi).send();
const tx = new DeployMethod(accounts[0].publicKey, client, TokenContractAbi, [
owner.getCompleteAddress(),
]).send();
await tx.wait();
const receipt = await tx.getReceipt();
console.log(`Contract Deployed: ${receipt.contractAddress}`);

const token = await Contract.at(receipt.contractAddress!, TokenContractAbi, owner);
await token.methods._initialize(owner.getAddress()).send().wait();
const secret = Fr.random();
const secretHash = await computeMessageSecretHash(secret);
await token.methods.mint_private(initialBalance, secretHash).send().wait();
Expand Down
3 changes: 1 addition & 2 deletions yarn-project/end-to-end/src/e2e_2_rpc_servers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ describe('e2e_2_rpc_servers', () => {

const deployTokenContract = async (initialAdminBalance: bigint, admin: AztecAddress) => {
logger(`Deploying Token contract...`);
const contract = await TokenContract.deploy(walletA).send().deployed();
expect((await contract.methods._initialize(admin).send().wait()).status).toBe(TxStatus.MINED);
const contract = await TokenContract.deploy(walletA, walletA.getCompleteAddress()).send().deployed();

if (initialAdminBalance > 0n) {
await mintTokens(contract, admin, initialAdminBalance);
Expand Down
4 changes: 1 addition & 3 deletions yarn-project/end-to-end/src/e2e_escrow_contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ describe('e2e_escrow_contract', () => {
logger(`Escrow contract deployed at ${escrowContract.address}`);

// Deploy Private Token contract and mint funds for the escrow contract
token = await TokenContract.deploy(wallet).send().deployed();

expect((await token.methods._initialize(owner).send().wait()).status).toBe(TxStatus.MINED);
token = await TokenContract.deploy(wallet, wallet.getCompleteAddress()).send().deployed();

const secret = Fr.random();
const secretHash = await computeMessageSecretHash(secret);
Expand Down
6 changes: 2 additions & 4 deletions yarn-project/end-to-end/src/e2e_lending_contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ describe('e2e_lending_contract', () => {

{
logger(`Deploying collateral asset feed contract...`);
const receipt = await waitForSuccess(TokenContract.deploy(wallet).send());
const receipt = await waitForSuccess(TokenContract.deploy(wallet, wallet.getCompleteAddress()).send());
logger(`Collateral asset deployed to ${receipt.contractAddress}`);
collateralAsset = await TokenContract.at(receipt.contractAddress!, wallet);
}

{
logger(`Deploying stable coin contract...`);
const receipt = await waitForSuccess(TokenContract.deploy(wallet).send());
const receipt = await waitForSuccess(TokenContract.deploy(wallet, wallet.getCompleteAddress()).send());
logger(`Stable coin asset deployed to ${receipt.contractAddress}`);
stableCoin = await TokenContract.at(receipt.contractAddress!, wallet);
}
Expand All @@ -69,9 +69,7 @@ describe('e2e_lending_contract', () => {
lendingContract = await LendingContract.at(receipt.contractAddress!, wallet);
}

await waitForSuccess(collateralAsset.methods._initialize(accounts[0]).send());
await waitForSuccess(collateralAsset.methods.set_minter(lendingContract.address, true).send());
await waitForSuccess(stableCoin.methods._initialize(accounts[0]).send());
await waitForSuccess(stableCoin.methods.set_minter(lendingContract.address, true).send());

return { priceFeedContract, lendingContract, collateralAsset, stableCoin };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@ describe('e2e_multiple_accounts_1_enc_key', () => {
}

logger(`Deploying Token...`);
const token = await TokenContract.deploy(wallets[0]).send().deployed();
const token = await TokenContract.deploy(wallets[0], wallets[0].getCompleteAddress()).send().deployed();
tokenAddress = token.address;
logger(`Token deployed at ${tokenAddress}`);

expect((await token.methods._initialize(accounts[0]).send().wait()).status).toBe(TxStatus.MINED);

const secret = Fr.random();
const secretHash = await computeMessageSecretHash(secret);

Expand Down
5 changes: 2 additions & 3 deletions yarn-project/end-to-end/src/e2e_sandbox_example.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,12 @@ describe('e2e_sandbox_example', () => {
const initialSupply = 1_000_000n;

logger(`Deploying token contract minting an initial ${initialSupply} tokens to Alice...`);
const contract = await TokenContract.deploy(aztecRpc).send().deployed();
const contract = await TokenContract.deploy(aztecRpc, alice).send().deployed();

// Create the contract abstraction and link to Alice's wallet for future signing
const tokenContractAlice = await TokenContract.at(contract.address, accounts[0]);

// Initialize the contract and add Bob as a minter
await tokenContractAlice.methods._initialize(alice).send().wait();
// add Bob as a minter
await tokenContractAlice.methods.set_minter(bob, true).send().wait();

logger(`Contract successfully deployed at address ${contract.address.toShortString()}`);
Expand Down
3 changes: 1 addition & 2 deletions yarn-project/end-to-end/src/e2e_token_contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,14 @@ describe('e2e_token_contract', () => {
beforeAll(async () => {
({ teardown, logger, wallets, accounts } = await setup(3));

asset = await TokenContract.deploy(wallets[0]).send().deployed();
asset = await TokenContract.deploy(wallets[0], wallets[0].getCompleteAddress()).send().deployed();
logger(`Token deployed to ${asset.address}`);
tokenSim = new TokenSimulator(
asset,
logger,
accounts.map(a => a.address),
);

await asset.methods._initialize(accounts[0].address).send().wait();
expect(await asset.methods.admin().view()).toBe(accounts[0].address.toBigInt());

asset.abi.functions.forEach(fn => {
Expand Down
9 changes: 1 addition & 8 deletions yarn-project/end-to-end/src/fixtures/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ export async function deployAndInitializeStandardizedTokenAndBridgeContracts(
});

// deploy l2 token
const deployTx = TokenContract.deploy(wallet).send();
const deployTx = TokenContract.deploy(wallet, wallet.getCompleteAddress()).send();

// deploy l2 token bridge and attach to the portal
const bridgeTx = TokenBridgeContract.deploy(wallet).send({
Expand All @@ -419,16 +419,9 @@ export async function deployAndInitializeStandardizedTokenAndBridgeContracts(
await bridge.attach(tokenPortalAddress);
const bridgeAddress = bridge.address.toString() as `0x${string}`;

// initialize l2 token
const initializeTx = token.methods._initialize(owner).send();

// initialize bridge
const initializeBridgeTx = bridge.methods._initialize(token.address).send();

// now we wait for the txs to be mined. This way we send all tx in the same rollup.
const initializeReceipt = await initializeTx.wait();
if (initializeReceipt.status !== TxStatus.MINED)
throw new Error(`Initialize token tx status is ${initializeReceipt.status}`);
if ((await token.methods.admin().view()) !== owner.toBigInt()) throw new Error(`Token admin is not ${owner}`);

const initializeBridgeReceipt = await initializeBridgeTx.wait();
Expand Down
12 changes: 4 additions & 8 deletions yarn-project/end-to-end/src/guides/dapp_testing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ describe('guides/dapp/testing', () => {
// docs:end:in-proc-sandbox
owner = await createAccount(rpc);
recipient = await createAccount(rpc);
token = await TokenContract.deploy(owner).send().deployed();
await token.methods._initialize(owner.getAddress()).send().wait();
token = await TokenContract.deploy(owner, owner.getCompleteAddress()).send().deployed();
}, 60_000);

// docs:start:stop-in-proc-sandbox
Expand Down Expand Up @@ -67,8 +66,7 @@ describe('guides/dapp/testing', () => {
rpc = createAztecRpcClient(SANDBOX_URL);
owner = await createAccount(rpc);
recipient = await createAccount(rpc);
token = await TokenContract.deploy(owner).send().deployed();
await token.methods._initialize(owner.getAddress()).send().wait();
token = await TokenContract.deploy(owner, owner.getCompleteAddress()).send().deployed();
}, 30_000);

it('increases recipient funds on mint', async () => {
Expand All @@ -92,8 +90,7 @@ describe('guides/dapp/testing', () => {
// docs:start:use-existing-wallets
rpc = createAztecRpcClient(SANDBOX_URL);
[owner, recipient] = await getSandboxAccountsWallets(rpc);
token = await TokenContract.deploy(owner).send().deployed();
await token.methods._initialize(owner.getAddress()).send().wait();
token = await TokenContract.deploy(owner, owner.getCompleteAddress()).send().deployed();
// docs:end:use-existing-wallets
}, 30_000);

Expand Down Expand Up @@ -143,8 +140,7 @@ describe('guides/dapp/testing', () => {
owner = await createAccount(rpc);
recipient = await createAccount(rpc);
testContract = await TestContract.deploy(owner).send().deployed();
token = await TokenContract.deploy(owner).send().deployed();
await token.methods._initialize(owner.getAddress()).send().wait();
token = await TokenContract.deploy(owner, owner.getCompleteAddress()).send().deployed();
const secret = Fr.random();
const secretHash = await computeMessageSecretHash(secret);
await token.methods.mint_private(100n, secretHash).send().wait();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ describe('guides/writing_an_account_contract', () => {
logger(`Deployed account contract at ${address}`);

// docs:start:account-contract-works
const token = await TokenContract.deploy(wallet).send().deployed();
const token = await TokenContract.deploy(wallet, wallet.getCompleteAddress()).send().deployed();
logger(`Deployed token contract at ${token.address}`);
await token.methods._initialize({ address }).send().wait();

const secret = Fr.random();
const secretHash = await computeMessageSecretHash(secret);
Expand Down
3 changes: 1 addition & 2 deletions yarn-project/end-to-end/src/sample-dapp/deploy.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ async function main() {
const client = createAztecRpcClient(SANDBOX_URL);
const [owner] = await getSandboxAccountsWallets(client);

const token = await Contract.deploy(client, TokenContractAbi, []).send().deployed();
await token.withWallet(owner).methods._initialize(owner.getAddress()).send().wait();
const token = await Contract.deploy(client, TokenContractAbi, [owner.getCompleteAddress()]).send().deployed();

console.log(`Token deployed at ${token.address.toString()}`);

Expand Down
3 changes: 1 addition & 2 deletions yarn-project/end-to-end/src/sample-dapp/index.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ describe('token', () => {
owner = await createAccount(rpc);
recipient = await createAccount(rpc);

token = await Contract.deploy(owner, TokenContractAbi, []).send().deployed();
await token.methods._initialize(owner.getAddress()).send().wait();
token = await Contract.deploy(owner, TokenContractAbi, [owner.getCompleteAddress()]).send().deployed();

const initialBalance = 20n;
const secret = Fr.random();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ contract Token {

// docs:start:constructor
#[aztec(private)]
fn constructor() {
fn constructor(admin: AztecAddress) {
let selector = compute_selector("_initialize((Field))");
let _callStackItem = context.call_public_function(context.this_address(), selector, [context.msg_sender()]);
let _callStackItem = context.call_public_function(context.this_address(), selector, admin.serialize());
}
// docs:end:constructor

Expand Down

0 comments on commit 977304c

Please sign in to comment.