Skip to content

Commit

Permalink
feat: fix and add proper UDC tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvkelawala committed Oct 31, 2022
1 parent b65dc65 commit d96cc53
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 22 deletions.
20 changes: 1 addition & 19 deletions __tests__/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,6 @@ describe('deploy and test Wallet', () => {
await provider.waitForTransaction(dappResponse.transaction_hash);
});

test('UDC Deploy', async () => {
// only work on testnet
const deployment = await account.deploy({
classHash: '0x6ad13d6c3f382bdc7d337a3928528e974b76c21153ff25a946d2c4f26ef1c6b',
callData: [
'0xb3e8b4bd1906e46f4b9ce2d0cbdcf747409ab506469287587b23130a600535',
'0x2dd76e7ad84dbed81c314ffe5e7a7cacfb8f4836f01af4e913f275f89a3de1a',
'0x2',
'0x46a1aa85bb0e68cd29fadbc81791208ddebee17886f075935e5b72f4aa898aa',
'0x46a1aa85bb0e68cd29fadbc81791208ddebee17886f075935e5b72f4aa898aa',
],
salt: '123',
unique: false,
});

expect(deployment).toHaveProperty('transaction_hash');
});

test('estimate fee', async () => {
const { overall_fee } = await account.estimateInvokeFee({
contractAddress: erc20Address,
Expand Down Expand Up @@ -163,7 +145,7 @@ describe('deploy and test Wallet', () => {
expect(res).toHaveProperty('overall_fee');
});

test('Declare Account contract', async () => {
test('Declare ERC20 contract', async () => {
const declareTx = await account.declare({
contract: compiledErc20,
classHash: '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a',
Expand Down
30 changes: 30 additions & 0 deletions __tests__/udc.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { encodeShortString } from '../src/utils/shortString';
import { IS_DEVNET, compiledErc20, getTestAccount, getTestProvider } from './fixtures';

describe('Declare and UDC Deploy Flow', () => {
const provider = getTestProvider();
const account = getTestAccount(provider);
const erc20ClassHash = '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a';

test('ERC20 Declare', async () => {
const declareTx = await account.declare({
classHash: erc20ClassHash,
contract: compiledErc20,
});

expect(declareTx).toHaveProperty('class_hash');
expect(declareTx.class_hash).toEqual(erc20ClassHash);
});

test('UDC Deploy', async () => {
const deployment = await account.deploy({
classHash: erc20ClassHash,
callData: [encodeShortString('Token'), encodeShortString('ERC20'), account.address],
salt: '123',
unique: true, // Using true here so as not to clash with normal erc20 deploy in account and provider test
isDevnet: IS_DEVNET,
});

expect(deployment).toHaveProperty('transaction_hash');
});
});
10 changes: 8 additions & 2 deletions src/account/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,19 @@ export class Account extends Provider implements AccountInterface {
}

public async deploy(
{ classHash, salt, unique = true, callData = [] }: UniversalDeployerContractPayload,
{
classHash,
salt,
unique = true,
callData = [],
isDevnet = false,
}: UniversalDeployerContractPayload,
transactionsDetail: InvocationsDetails = {}
): Promise<any> {
const compiledCallData = compileCalldata(callData);
return this.execute(
{
contractAddress: UDC.ADDRESS,
contractAddress: isDevnet ? UDC.ADDRESS_DEVNET : UDC.ADDRESS,
entrypoint: UDC.ENTRYPOINT,
calldata: [
classHash,
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export enum TransactionHashPrefix {
export const UDC = {
ADDRESS: '0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf',
ENTRYPOINT: 'deployContract',
ADDRESS_DEVNET: '0x25fcb74260022bd8ed7e8d542408941826b53345e478b8303d6f31744838a36',
};

/**
Expand Down
3 changes: 2 additions & 1 deletion src/types/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export type UniversalDeployerContractPayload = {
classHash: BigNumberish;
salt: string;
unique: boolean;
callData: RawArgs;
callData?: RawArgs;
isDevnet?: boolean;
};

export type DeployContractPayload = {
Expand Down

0 comments on commit d96cc53

Please sign in to comment.