Skip to content

Commit

Permalink
Rename contract create to at in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
spalladino committed Aug 15, 2023
1 parent 99c0846 commit 4e9f49f
Show file tree
Hide file tree
Showing 22 changed files with 36 additions and 47 deletions.
4 changes: 2 additions & 2 deletions docs/src/code_examples/sandbox_example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ await viewUnencryptedLogs();
////////////// QUERYING THE TOKEN BALANCE FOR EACH ACCOUNT //////////////

// Create the contract abstraction and link to Alice's wallet for future signing
const tokenContractAlice = await PrivateTokenContract.create(
const tokenContractAlice = await PrivateTokenContract.at(
receipt.contractAddress!,
await accounts[0].getWallet()
);

// Bob wants to mint some funds, the contract is already deployed, create an abstraction and link it his wallet
const tokenContractBob = await PrivateTokenContract.create(
const tokenContractBob = await PrivateTokenContract.at(
receipt.contractAddress!,
await accounts[1].getWallet()
);
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ async function main() {
PrivateKey.fromString(options.privateKey),
accountCreationSalt,
);
const contract = await Contract.create(contractAddress, contractAbi, wallet);
const contract = await Contract.at(contractAddress, contractAbi, wallet);
const tx = contract.methods[functionName](...functionArgs).send();
await tx.isMined();
log('\nTransaction has been mined');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async function deployZKContract(owner: AztecAddress) {
logger('Deploying L2 contract...');
const tx = PrivateTokenContract.deploy(aztecRpcClient, INITIAL_BALANCE, owner).send();
const receipt = await tx.getReceipt();
const contract = await PrivateTokenContract.create(receipt.contractAddress!, wallet);
const contract = await PrivateTokenContract.at(receipt.contractAddress!, wallet);
await tx.isMined();
logger('L2 contract deployed');
return contract;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ async function deployAllContracts(owner: AztecAddress) {
const tx = UniswapContract.deploy(aztecRpcClient).send({ portalContract: uniswapPortalAddress });
await tx.isMined({ interval: 0.5 });
const receipt = await tx.getReceipt();
const uniswapL2Contract = await UniswapContract.create(receipt.contractAddress!, wallet);
const uniswapL2Contract = await UniswapContract.at(receipt.contractAddress!, wallet);
await uniswapL2Contract.attach(uniswapPortalAddress);

await uniswapPortal.write.initialize(
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec-sandbox/src/examples/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export async function deployAndInitializeNonNativeL2TokenContracts(
});
await tx.isMined({ interval: 0.1 });
const receipt = await tx.getReceipt();
const l2Contract = await NonNativeTokenContract.create(receipt.contractAddress!, wallet);
const l2Contract = await NonNativeTokenContract.at(receipt.contractAddress!, wallet);
await l2Contract.attach(tokenPortalAddress);
const l2TokenAddress = l2Contract.address.toString() as `0x${string}`;

Expand Down
4 changes: 2 additions & 2 deletions yarn-project/aztec.js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ console.log(`Contract address: ${receipt.contractAddress}`);
```typescript
import { Contract } from '@aztec/aztec.js';

const contract = await Contract.create(contractAddress, contractAbi, aztecRpcServer);
const contract = await Contract.at(contractAddress, contractAbi, aztecRpcServer);
const tx = contract.methods
.transfer(amount, recipientAddress))
.send({ origin: senderAddress });
Expand All @@ -36,7 +36,7 @@ console.log(`Transferred ${amount} to ${recipientAddress}!`);
```typescript
import { Contract } from '@aztec/aztec.js';

const contract = await Contract.create(contractAddress, contractAbi, aztecRpcServer);
const contract = await Contract.at(contractAddress, contractAbi, aztecRpcServer);
const balance = contract.methods
.getBalance(accountPublicKey))
.view({ from: accountAddress });
Expand Down
10 changes: 5 additions & 5 deletions yarn-project/aztec.js/src/contract/contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe('Contract Class', () => {
});

it('should create and send a contract method tx', async () => {
const fooContract = await Contract.create(contractAddress, defaultAbi, wallet);
const fooContract = await Contract.at(contractAddress, defaultAbi, wallet);
const param0 = 12;
const param1 = 345n;
const sentTx = fooContract.methods.bar(param0, param1).send({
Expand All @@ -121,7 +121,7 @@ describe('Contract Class', () => {
});

it('should call view on an unconstrained function', async () => {
const fooContract = await Contract.create(contractAddress, defaultAbi, wallet);
const fooContract = await Contract.at(contractAddress, defaultAbi, wallet);
const result = await fooContract.methods.qux(123n).view({
from: account,
});
Expand All @@ -131,19 +131,19 @@ describe('Contract Class', () => {
});

it('should not call create on an unconstrained function', async () => {
const fooContract = await Contract.create(contractAddress, defaultAbi, wallet);
const fooContract = await Contract.at(contractAddress, defaultAbi, wallet);
await expect(fooContract.methods.qux().create({ origin: account })).rejects.toThrow();
});

it('should not call view on a secret or open function', async () => {
const fooContract = await Contract.create(contractAddress, defaultAbi, wallet);
const fooContract = await Contract.at(contractAddress, defaultAbi, wallet);
expect(() => fooContract.methods.bar().view()).toThrow();
expect(() => fooContract.methods.baz().view()).toThrow();
});

it('should add contract and dependencies to aztec rpc', async () => {
const entry = randomDeployContract();
const contract = await Contract.create(entry.address, entry.abi, wallet);
const contract = await Contract.at(entry.address, entry.abi, wallet);

{
await contract.attach(entry.portalContract);
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/src/contract/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class Contract extends ContractBase {
* @param wallet - The wallet to use when interacting with the contract.
* @returns A promise that resolves to a new Contract instance.
*/
public static async create(address: AztecAddress, abi: ContractAbi, wallet: Wallet): Promise<Contract> {
public static async at(address: AztecAddress, abi: ContractAbi, wallet: Wallet): Promise<Contract> {
if (!(await isContractDeployed(wallet, address))) {
throw new Error('Contract ' + address.toString() + ' is not deployed');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ export class DeploySentTx<TContract extends ContractBase = Contract> extends Sen
const contractWallet = wallet ?? (isWallet(this.arc) && this.arc);
if (!contractWallet) throw new Error(`A wallet is required for creating a contract instance`);
if (!address) throw new Error(`Contract address is missing from transaction receipt`);
return Contract.create(address, this.abi, contractWallet) as Promise<TContract>;
return Contract.at(address, this.abi, contractWallet) as Promise<TContract>;
}
}
7 changes: 2 additions & 5 deletions yarn-project/canary/src/uniswap_trade_on_l1_from_l2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ async function deployAllContracts(
});
await tx.isMined();
const receipt = await tx.getReceipt();
const uniswapL2Contract = await UniswapContract.create(receipt.contractAddress!, wallet);
const uniswapL2Contract = await UniswapContract.at(receipt.contractAddress!, wallet);
await uniswapL2Contract.attach(uniswapPortalAddress);

await uniswapPortal.write.initialize(
Expand All @@ -136,10 +136,7 @@ async function deployAllContracts(
};
}

const getL2BalanceOf = async (
owner: AztecAddress,
l2Contract: NonNativeTokenContract
) => {
const getL2BalanceOf = async (owner: AztecAddress, l2Contract: NonNativeTokenContract) => {
return await l2Contract.methods.getBalance(owner).view({ from: owner });
};

Expand Down
2 changes: 1 addition & 1 deletion yarn-project/canary/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export async function deployAndInitializeNonNativeL2TokenContracts(
});
await tx.isMined();
const receipt = await tx.getReceipt();
const l2Contract = await NonNativeTokenContract.create(receipt.contractAddress!, wallet);
const l2Contract = await NonNativeTokenContract.at(receipt.contractAddress!, wallet);
await l2Contract.attach(tokenPortalAddress);
const l2TokenAddress = l2Contract.address.toString() as `0x${string}`;

Expand Down
8 changes: 4 additions & 4 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 @@ -70,7 +70,7 @@ describe('e2e_2_rpc_servers', () => {
await awaitUserSynchronised(wallet, owner);

// Then check the balance
const contractWithWallet = await PrivateTokenContract.create(tokenAddress, wallet);
const contractWithWallet = await PrivateTokenContract.at(tokenAddress, wallet);
const balance = await contractWithWallet.methods.getBalance(owner).view({ from: owner });
logger(`Account ${owner} balance: ${balance}`);
expect(balance).toBe(expectedBalance);
Expand Down Expand Up @@ -118,7 +118,7 @@ describe('e2e_2_rpc_servers', () => {
await expectUnencryptedLogsFromLastBlockToBe(aztecNode, ['Balance set in constructor']);

// Transfer funds from A to B via RPC server A
const contractWithWalletA = await PrivateTokenContract.create(tokenAddress, walletA);
const contractWithWalletA = await PrivateTokenContract.at(tokenAddress, walletA);
const txAToB = contractWithWalletA.methods.transfer(transferAmount1, userA, userB).send({ origin: userA });

await txAToB.isMined({ interval: 0.1 });
Expand All @@ -133,7 +133,7 @@ describe('e2e_2_rpc_servers', () => {
await expectUnencryptedLogsFromLastBlockToBe(aztecNode, ['Coins transferred']);

// Transfer funds from B to A via RPC server B
const contractWithWalletB = await PrivateTokenContract.create(tokenAddress, walletB);
const contractWithWalletB = await PrivateTokenContract.at(tokenAddress, walletB);
const txBToA = contractWithWalletB.methods.transfer(transferAmount2, userB, userA).send({ origin: userB });

await txBToA.isMined({ interval: 0.1 });
Expand Down Expand Up @@ -186,7 +186,7 @@ describe('e2e_2_rpc_servers', () => {

const newValueToSet = 256n;

const childContractWithWalletB = await ChildContract.create(childAddress, walletB);
const childContractWithWalletB = await ChildContract.at(childAddress, walletB);
const tx = childContractWithWalletB.methods.pubStoreValue(newValueToSet).send({ origin: userB });
await tx.isMined({ interval: 0.1 });

Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/e2e_account_contracts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function itShouldBehaveLikeAnAccountContract(getAccountContract: (encryptionKey:
getAccountContract(PrivateKey.random()),
accountAddress,
).getWallet();
const childWithInvalidWallet = await ChildContract.create(child.address, invalidWallet);
const childWithInvalidWallet = await ChildContract.at(child.address, invalidWallet);
await expect(childWithInvalidWallet.methods.value(42).simulate()).rejects.toThrowError(
/could not satisfy all constraints/,
);
Expand Down
12 changes: 2 additions & 10 deletions yarn-project/end-to-end/src/e2e_aztec_js_browser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,7 @@ conditionalDescribe()('e2e_aztec.js_browser', () => {
const client = createAztecRpcClient(rpcUrl!, mustSucceedFetch);
const [owner] = await client.getAccounts();
const wallet = await getUnsafeSchnorrWallet(client, owner, privateKey);
const contract = await Contract.create(
AztecAddress.fromString(contractAddress),
PrivateTokenContractAbi,
wallet,
);
const contract = await Contract.at(AztecAddress.fromString(contractAddress), PrivateTokenContractAbi, wallet);
const balance = await contract.methods.getBalance(owner).view({ from: owner });
return balance;
},
Expand Down Expand Up @@ -180,11 +176,7 @@ conditionalDescribe()('e2e_aztec.js_browser', () => {
console.log(`Created 2nd Account: ${receiver.toString()}`);
const [owner] = await client.getAccounts();
const wallet = await getUnsafeSchnorrWallet(client, owner, privateKey);
const contract = await Contract.create(
AztecAddress.fromString(contractAddress),
PrivateTokenContractAbi,
wallet,
);
const contract = await Contract.at(AztecAddress.fromString(contractAddress), PrivateTokenContractAbi, wallet);
await contract.methods.transfer(transferAmount, owner, receiver).send({ origin: owner }).wait();
console.log(`Transfered ${transferAmount} tokens to new Account`);
return await contract.methods.getBalance(receiver).view({ from: receiver });
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/e2e_cheat_codes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ describe('e2e_cheat_codes', () => {
const tx = LendingContract.deploy(aztecRpcServer).send();
await tx.isMined({ interval: 0.1 });
const receipt = await tx.getReceipt();
const contract = await LendingContract.create(receipt.contractAddress!, wallet);
const contract = await LendingContract.at(receipt.contractAddress!, wallet);

// now update time:
const timestamp = await cc.l1.timestamp();
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/e2e_lending_contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('e2e_lending_contract', () => {
await tx.isMined({ interval: 0.1 });
const txReceipt = await tx.getReceipt();
logger(`L2 contract deployed at ${receipt.contractAddress}`);
contract = await LendingContract.create(receipt.contractAddress!, wallet);
contract = await LendingContract.at(receipt.contractAddress!, wallet);
return { contract, tx, txReceipt };
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('e2e_multiple_accounts_1_enc_key', () => {
const owner = accounts[userIndex];

// Then check the balance
const contractWithWallet = await PrivateTokenContract.create(privateTokenAddress, wallet);
const contractWithWallet = await PrivateTokenContract.at(privateTokenAddress, wallet);
const balance = await contractWithWallet.methods.getBalance(owner).view({ from: owner });
logger(`Account ${owner} balance: ${balance}`);
expect(balance).toBe(expectedBalance);
Expand All @@ -84,7 +84,7 @@ describe('e2e_multiple_accounts_1_enc_key', () => {
const sender = accounts[senderIndex];
const receiver = accounts[receiverIndex];

const contractWithWallet = await PrivateTokenContract.create(privateTokenAddress, wallets[senderIndex]);
const contractWithWallet = await PrivateTokenContract.at(privateTokenAddress, wallets[senderIndex]);

const tx = contractWithWallet.methods.transfer(transferAmount, sender, receiver).send({ origin: sender });
await tx.isMined({ interval: 0.1 });
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/e2e_nested_contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('e2e_nested_contract', () => {
await tx.isMined({ interval: 0.1 });

const receipt = await tx.getReceipt();
const contract = await Contract.create(receipt.contractAddress!, abi, wallet);
const contract = await Contract.at(receipt.contractAddress!, abi, wallet);
logger(`L2 contract ${abi.name} deployed at ${contract.address}`);
return contract;
};
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/end-to-end/src/e2e_non_contract_account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('e2e_non_contract_account', () => {
const minedReceipt = await tx.getReceipt();
expect(minedReceipt.status).toEqual(TxStatus.MINED);
logger('L2 contract deployed');
contract = await PokeableTokenContract.create(receipt.contractAddress!, wallet);
contract = await PokeableTokenContract.at(receipt.contractAddress!, wallet);
}, 100_000);

afterEach(async () => {
Expand All @@ -56,7 +56,7 @@ describe('e2e_non_contract_account', () => {
await expectBalance(recipient, 0n);
await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 1);

const contractWithNoContractWallet = await PokeableTokenContract.create(contract.address, pokerWallet);
const contractWithNoContractWallet = await PokeableTokenContract.at(contract.address, pokerWallet);

// Send transaction as poker (arbitrary non-contract account)
await contractWithNoContractWallet.methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('e2e_pending_commitments_contract', () => {
await tx.isMined({ interval: 0.1 });
await tx.getReceipt();
logger('L2 contract deployed');
contract = await PendingCommitmentsContract.create(receipt.contractAddress!, wallet);
contract = await PendingCommitmentsContract.at(receipt.contractAddress!, wallet);
return contract;
};

Expand Down
4 changes: 2 additions & 2 deletions yarn-project/end-to-end/src/fixtures/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ export async function deployL2Contracts(wallet: Wallet, abis: ContractAbi[]) {
const contracts = zipWith(
abis,
receipts,
async (abi, receipt) => await Contract.create(receipt!.contractAddress!, abi!, wallet),
async (abi, receipt) => await Contract.at(receipt!.contractAddress!, abi!, wallet),
);
contracts.forEach(async c => logger(`L2 contract ${(await c).abi.name} deployed at ${(await c).address}`));
return contracts;
Expand Down Expand Up @@ -374,7 +374,7 @@ export async function deployAndInitializeNonNativeL2TokenContracts(
await tx.isMined({ interval: 0.1 });
const receipt = await tx.getReceipt();
if (receipt.status !== TxStatus.MINED) throw new Error(`Tx status is ${receipt.status}`);
const l2Contract = await NonNativeTokenContract.create(receipt.contractAddress!, wallet);
const l2Contract = await NonNativeTokenContract.at(receipt.contractAddress!, wallet);
await l2Contract.attach(tokenPortalAddress);
const l2TokenAddress = l2Contract.address.toString() as `0x${string}`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ describe('uniswap_trade_on_l1_from_l2', () => {
await tx.isMined({ interval: 0.1 });
const receipt = await tx.getReceipt();
expect(receipt.status).toEqual(TxStatus.MINED);
uniswapL2Contract = await UniswapContract.create(receipt.contractAddress!, wallet);
uniswapL2Contract = await UniswapContract.at(receipt.contractAddress!, wallet);
await uniswapL2Contract.attach(uniswapPortalAddress);

await uniswapPortal.write.initialize(
Expand Down

0 comments on commit 4e9f49f

Please sign in to comment.