Skip to content

Commit

Permalink
test: inline compiled contract variables
Browse files Browse the repository at this point in the history
  • Loading branch information
penovicp committed Oct 7, 2024
1 parent d8639e5 commit 55e28bc
Show file tree
Hide file tree
Showing 16 changed files with 203 additions and 263 deletions.
9 changes: 3 additions & 6 deletions __tests__/account.outsideExecution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ import { getSelectorFromName } from '../src/utils/hash';
import { getDecimalString } from '../src/utils/num';
import { contracts, getTestAccount, getTestProvider } from './config/fixtures';

const compiledErc20OZ = contracts.Erc20OZ.sierra;
const compiledArgentX4Account = contracts.ArgentX4Account.sierra;

describe('Account and OutsideExecution', () => {
const ethAddress = '0x49D36570D4E46F48E99674BD3FCC84644DDD6B96F7C741B1562B82F9E004DC7';
const provider = new Provider(getTestProvider());
Expand All @@ -37,19 +34,19 @@ describe('Account and OutsideExecution', () => {
const targetPubK = ec.starkCurve.getStarkKey(targetPK);
// For ERC20 transfer outside call
const recipientAccount = executorAccount;
const ethContract = new Contract(compiledErc20OZ.abi, ethAddress, provider);
const ethContract = new Contract(contracts.Erc20OZ.sierra.abi, ethAddress, provider);

beforeAll(async () => {
// Deploy the SNIP-9 signer account (ArgentX v 0.4.0, using SNIP-9 v2):
const calldataAX = new CallData(compiledArgentX4Account.abi);
const calldataAX = new CallData(contracts.ArgentX4Account.sierra.abi);
const axSigner = new CairoCustomEnum({ Starknet: { pubkey: targetPubK } });
const axGuardian = new CairoOption<unknown>(CairoOptionVariant.None);
const constructorAXCallData = calldataAX.compile('constructor', {
owner: axSigner,
guardian: axGuardian,
});
const response = await executorAccount.declareAndDeploy({
contract: compiledArgentX4Account,
contract: contracts.ArgentX4Account.sierra,
classHash: '0x36078334509b514626504edc9fb252328d1a240e4e948bef8d0c08dff45927f',
compiledClassHash: '0x7a663375245780bd307f56fde688e33e5c260ab02b76741a57711c5b60d47f6',
constructorCalldata: constructorAXCallData,
Expand Down
25 changes: 8 additions & 17 deletions __tests__/account.starknetId.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,6 @@ import { contracts, getTestAccount, getTestProvider } from './config/fixtures';

const { hexToDecimalString } = num;

const compiledNaming = contracts.starknetId.Naming.sierra;
const compiledNamingCasm = contracts.starknetId.Naming.casm;
const compiledPricing = contracts.starknetId.Pricing.sierra;
const compiledPricingCasm = contracts.starknetId.Pricing.casm;
const compiledSidMulticall = contracts.starknetId.SidMulticall.sierra;
const compiledSidMulticallCasm = contracts.starknetId.SidMulticall.casm;
const compiledStarknetId = contracts.starknetId.StarknetId.sierra;
const compiledStarknetIdCasm = contracts.starknetId.StarknetId.casm;

describe('deploy and test Wallet', () => {
const provider = new Provider(getTestProvider());
const account = getTestAccount(provider);
Expand All @@ -23,32 +14,32 @@ describe('deploy and test Wallet', () => {
beforeAll(async () => {
// Deploy Starknet id contract
const idResponse = await account.declareAndDeploy({
contract: compiledStarknetId,
casm: compiledStarknetIdCasm,
contract: contracts.starknetId.StarknetId.sierra,
casm: contracts.starknetId.StarknetId.casm,
constructorCalldata: [account.address, 0],
});
identityAddress = idResponse.deploy.contract_address;

// Deploy pricing contract
const pricingResponse = await account.declareAndDeploy({
contract: compiledPricing,
casm: compiledPricingCasm,
contract: contracts.starknetId.Pricing.sierra,
casm: contracts.starknetId.Pricing.casm,
constructorCalldata: [devnetERC20Address],
});
const pricingAddress = pricingResponse.deploy.contract_address;

// Deploy naming contract
const namingResponse = await account.declareAndDeploy({
contract: compiledNaming,
casm: compiledNamingCasm,
contract: contracts.starknetId.Naming.sierra,
casm: contracts.starknetId.Naming.casm,
constructorCalldata: [identityAddress, pricingAddress, 0, account.address],
});
namingAddress = namingResponse.deploy.contract_address;

// Deploy multicall contract
const multicallResponse = await account.declareAndDeploy({
contract: compiledSidMulticall,
casm: compiledSidMulticallCasm,
contract: contracts.starknetId.SidMulticall.sierra,
casm: contracts.starknetId.SidMulticall.casm,
});
multicallAddress = multicallResponse.deploy.contract_address;

Expand Down
62 changes: 28 additions & 34 deletions __tests__/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ const { randomAddress } = stark;
const { uint256 } = cairo;
const { Signature } = ec.starkCurve;

const compiledErc20 = contracts.Erc20;
const compiledOpenZeppelinAccount = contracts.OpenZeppelinAccount;
const compiledTestDapp = contracts.TestDapp;
const compiledHelloSierra = contracts.HelloSierra.sierra;
const compiledHelloSierraCasm = contracts.HelloSierra.casm;

describe('deploy and test Wallet', () => {
const provider = new Provider(getTestProvider());
const account = getTestAccount(provider);
Expand All @@ -53,7 +47,7 @@ describe('deploy and test Wallet', () => {
expect(account).toBeInstanceOf(Account);

dd = await account.declareAndDeploy({
contract: compiledErc20,
contract: contracts.Erc20,
constructorCalldata: [
encodeShortString('Token'),
encodeShortString('ERC20'),
Expand All @@ -62,17 +56,17 @@ describe('deploy and test Wallet', () => {
});

erc20Address = dd.deploy.contract_address;
erc20 = new Contract(compiledErc20.abi, erc20Address, provider);
erc20 = new Contract(contracts.Erc20.abi, erc20Address, provider);

const { balance } = await erc20.balanceOf(account.address);
expect(BigInt(balance.low).toString()).toStrictEqual(BigInt(1000).toString());

const dappResponse = await account.declareAndDeploy({
contract: compiledTestDapp,
contract: contracts.TestDapp,
classHash: '0x04367b26fbb92235e8d1137d19c080e6e650a6889ded726d00658411cc1046f5',
});

dapp = new Contract(compiledTestDapp.abi, dappResponse.deploy.contract_address!, provider);
dapp = new Contract(contracts.TestDapp.abi, dappResponse.deploy.contract_address!, provider);
});

xtest('validate TS for redeclare - skip testing', async () => {
Expand Down Expand Up @@ -123,7 +117,7 @@ describe('deploy and test Wallet', () => {

// declare account
const declareAccount = await account.declareIfNot({
contract: compiledOpenZeppelinAccount,
contract: contracts.OpenZeppelinAccount,
});
const accountClassHash = declareAccount.class_hash;

Expand Down Expand Up @@ -252,7 +246,7 @@ describe('deploy and test Wallet', () => {
const invocation = await provider.prepareInvocations([
{
type: TransactionType.DECLARE,
contract: compiledErc20,
contract: contracts.Erc20,
},
]);
if (invocation.length) {
Expand All @@ -266,8 +260,8 @@ describe('deploy and test Wallet', () => {
const invocation = await provider.prepareInvocations([
{
type: TransactionType.DECLARE,
contract: compiledHelloSierra,
casm: compiledHelloSierraCasm,
contract: contracts.HelloSierra.sierra,
casm: contracts.HelloSierra.casm,
},
]);

Expand Down Expand Up @@ -313,7 +307,7 @@ describe('deploy and test Wallet', () => {
});
test('simulate DEPLOY_ACCOUNT - Cairo 0 Account', async () => {
const declareAccount = await account.declareIfNot({
contract: compiledOpenZeppelinAccount,
contract: contracts.OpenZeppelinAccount,
});
const accountClassHash = declareAccount.class_hash;
if (declareAccount.transaction_hash) {
Expand Down Expand Up @@ -482,7 +476,7 @@ describe('deploy and test Wallet', () => {

test('Declare ERC20 contract', async () => {
const declareTx = await account.declareIfNot({
contract: compiledErc20,
contract: contracts.Erc20,
classHash: '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a',
});
if (declareTx.transaction_hash) {
Expand All @@ -495,7 +489,7 @@ describe('deploy and test Wallet', () => {
describe('Declare and UDC Deploy Flow', () => {
test('ERC20 Declare', async () => {
const declareTx = await account.declareIfNot({
contract: compiledErc20,
contract: contracts.Erc20,
});

if (declareTx.transaction_hash) {
Expand Down Expand Up @@ -587,7 +581,7 @@ describe('deploy and test Wallet', () => {

beforeAll(async () => {
const declareAccount = await account.declareIfNot({
contract: compiledOpenZeppelinAccount,
contract: contracts.OpenZeppelinAccount,
});
accountClassHash = declareAccount.class_hash;
if (declareAccount.transaction_hash) {
Expand Down Expand Up @@ -707,8 +701,8 @@ describe('deploy and test Wallet', () => {
});

const hashes = extractContractHashes({
contract: compiledHelloSierra,
casm: compiledHelloSierraCasm,
contract: contracts.HelloSierra.sierra,
casm: contracts.HelloSierra.casm,
});

const isDeclaredCairo1 = await account.isClassDeclared({ classHash: hashes.classHash });
Expand Down Expand Up @@ -745,7 +739,7 @@ describe('deploy and test Wallet', () => {
// Cairo 0
type: TransactionType.DECLARE,
payload: {
contract: compiledErc20,
contract: contracts.Erc20,
classHash: '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a',
},
},
Expand All @@ -756,8 +750,8 @@ describe('deploy and test Wallet', () => {
{
// Cairo 1.1.0, if declared estimate error with can't redeclare same contract
type: TransactionType.DECLARE,
contract: compiledHelloSierra,
casm: compiledHelloSierraCasm,
contract: contracts.HelloSierra.sierra,
casm: contracts.HelloSierra.casm,
},
]
: []),
Expand Down Expand Up @@ -800,15 +794,15 @@ describe('deploy and test Wallet', () => {
// Cairo 0
type: TransactionType.DECLARE,
payload: {
contract: compiledErc20,
contract: contracts.Erc20,
classHash: '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a',
},
},
{
// Cairo 1.1.0, if declared estimate error with can't redeclare same contract
type: TransactionType.DECLARE,
contract: compiledHelloSierra,
casm: compiledHelloSierraCasm,
contract: contracts.HelloSierra.sierra,
casm: contracts.HelloSierra.casm,
},
]);

Expand All @@ -825,8 +819,8 @@ describe('deploy and test Wallet', () => {
// TODO @dhruvkelawala check expectation for feeTransactionVersion
// Cairo 1 contract
const ddc1: DeclareDeployUDCResponse = await account.declareAndDeploy({
contract: compiledHelloSierra,
casm: compiledHelloSierraCasm,
contract: contracts.HelloSierra.sierra,
casm: contracts.HelloSierra.casm,
});

// const innerInvokeEstFeeSpy = jest.spyOn(account.signer, 'signTransaction');
Expand All @@ -851,21 +845,21 @@ describe('unit', () => {

test('declareIfNot', async () => {
const declare = await account.declareIfNot({
contract: compiledHelloSierra,
casm: compiledHelloSierraCasm,
contract: contracts.HelloSierra.sierra,
casm: contracts.HelloSierra.casm,
});
expect(declare).toMatchSchemaRef('DeclareContractResponse');

await expect(
account.declare({
contract: compiledHelloSierra,
casm: compiledHelloSierraCasm,
contract: contracts.HelloSierra.sierra,
casm: contracts.HelloSierra.casm,
})
).rejects.toThrow();

const redeclare = await account.declareIfNot({
contract: compiledHelloSierra,
casm: compiledHelloSierraCasm,
contract: contracts.HelloSierra.sierra,
casm: contracts.HelloSierra.casm,
});
expect(redeclare.class_hash).toBe(declare.class_hash);
});
Expand Down
38 changes: 17 additions & 21 deletions __tests__/cairo1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ const { uint256, tuple, isCairo1Abi } = cairo;
const { toHex } = num;
const { starknetKeccak } = selector;

const compiledComplexSierra = contracts.ComplexSierra;
const compiledC1Account = contracts.C1Account.sierra;
const compiledC1AccountCasm = contracts.C1Account.casm;
const compiledHelloSierra = contracts.HelloSierra.sierra;
const compiledHelloSierraCasm = contracts.HelloSierra.casm;
const compiledOnlyConstructorSierra = contracts.OnlyConstructor.sierra;
const compiledOnlyConstructorCasm = contracts.OnlyConstructor.casm;

describeIfDevnet('Cairo 1 Devnet', () => {
describe('API & Contract interactions', () => {
const provider = getTestProvider();
Expand All @@ -49,20 +41,24 @@ describeIfDevnet('Cairo 1 Devnet', () => {

beforeAll(async () => {
dd = await account.declareAndDeploy({
contract: compiledHelloSierra,
casm: compiledHelloSierraCasm,
contract: contracts.HelloSierra.sierra,
casm: contracts.HelloSierra.casm,
});

cairo1Contract = new Contract(compiledHelloSierra.abi, dd.deploy.contract_address, account);
cairo1Contract = new Contract(
contracts.HelloSierra.sierra.abi,
dd.deploy.contract_address,
account
);

const ddOnlyConstructor = await account.declareAndDeploy({
contract: compiledOnlyConstructorSierra,
casm: compiledOnlyConstructorCasm,
contract: contracts.OnlyConstructor.sierra,
casm: contracts.OnlyConstructor.casm,
constructorCalldata: [101, account.address],
});

onlyConstructorContract = new Contract(
compiledOnlyConstructorSierra.abi,
contracts.OnlyConstructor.sierra.abi,
ddOnlyConstructor.deploy.contract_address,
account
);
Expand All @@ -81,8 +77,8 @@ describeIfDevnet('Cairo 1 Devnet', () => {

test('ContractFactory on Cairo1', async () => {
const c1CFactory = new ContractFactory({
compiledContract: compiledHelloSierra,
casm: compiledHelloSierraCasm,
compiledContract: contracts.HelloSierra.sierra,
casm: contracts.HelloSierra.casm,
account,
});
const cfContract = await c1CFactory.deploy();
Expand All @@ -95,12 +91,12 @@ describeIfDevnet('Cairo 1 Devnet', () => {

await account.declare({
contract: cc0 as CompiledSierra,
casm: compiledHelloSierraCasm,
casm: contracts.HelloSierra.casm,
});

await account.declare({
contract: cc0_1 as CompiledSierra,
casm: compiledHelloSierraCasm,
casm: contracts.HelloSierra.casm,
});
});

Expand Down Expand Up @@ -436,7 +432,7 @@ describeIfDevnet('Cairo 1 Devnet', () => {
],
];

const contractCallData: CallData = new CallData(compiledComplexSierra.abi);
const contractCallData: CallData = new CallData(contracts.ComplexSierra.abi);
const callDataFromObject: Calldata = contractCallData.compile('constructor', myRawArgsObject);
const callDataFromArray: Calldata = contractCallData.compile('constructor', myRawArgsArray);
const expectedResult = [
Expand Down Expand Up @@ -526,8 +522,8 @@ describeIfDevnet('Cairo 1 Devnet', () => {

// declare account
const declareAccount = await account.declareIfNot({
contract: compiledC1Account,
casm: compiledC1AccountCasm,
contract: contracts.C1Account.sierra,
casm: contracts.C1Account.casm,
});
if (declareAccount.transaction_hash) {
await account.waitForTransaction(declareAccount.transaction_hash);
Expand Down
Loading

0 comments on commit 55e28bc

Please sign in to comment.