Skip to content

Commit

Permalink
Deploy account test for Cairo 1 (keep-starknet-strange#816)
Browse files Browse the repository at this point in the history
Co-authored-by: apoorveth <[email protected]>
  • Loading branch information
apoorvsadana and apoorvsadana authored Jul 5, 2023
1 parent 7cc9225 commit a1e4a77
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/tests/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export const ACCOUNT_CONTRACT =
export const CAIRO_1_ACCOUNT_CONTRACT =
"0x0000000000000000000000000000000000000000000000000000000000000004";

export const CAIRO_1_ACCOUNT_CONTRACT_CLASS_HASH =
"0x35ccefcf9d5656da623468e27e682271cd327af196785df99e7fee1436b6276";

// https://github.com/keep-starknet-strange/madara/blob/main/crates/node/src/chain_spec.rs#L185-L186
export const ACCOUNT_CONTRACT_CLASS_HASH =
"0x0279d77db761fba82e0054125a6fdb5f6baa6286fa3fb73450cc44d193c2d37f";
Expand Down
42 changes: 42 additions & 0 deletions tests/tests/test-rpc/test-starknet-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
CAIRO_1_ACCOUNT_CONTRACT,
ERC20_CAIRO_1_CASM,
ERC20_CAIRO_1_SIERRA,
CAIRO_1_ACCOUNT_CONTRACT_CLASS_HASH,
} from "../constants";
import { Block, InvokeTransaction } from "./types";
import { assert, numberToHex } from "@polkadot/util";
Expand Down Expand Up @@ -2012,6 +2013,47 @@ describeDevMadara("Starknet RPC", (context) => {
});

describe("Cairo 1 full flow", async () => {
it("should deploy a Cairo 1 account", async () => {
const CONSTRUCTOR_CALLDATA = ["0x123"];
const accountAddress = hash.calculateContractAddressFromHash(
SALT,
CAIRO_1_ACCOUNT_CONTRACT_CLASS_HASH,
CONSTRUCTOR_CALLDATA,
0
);

const account = new Account(
providerRPC,
accountAddress,
SIGNER_PRIVATE,
"1"
);

// transfer native token to allow deployment
await rpcTransfer(
providerRPC,
ARGENT_CONTRACT_NONCE,
accountAddress,
"0xfffffffffffffffffffffffff"
);
await jumpBlocks(context, 1);

// deploy the account
await account.deploySelf(
{
classHash: CAIRO_1_ACCOUNT_CONTRACT_CLASS_HASH,
addressSalt: SALT,
constructorCalldata: CONSTRUCTOR_CALLDATA,
},
{ maxFee: "123456" }
);
await jumpBlocks(context, 1);

expect(await providerRPC.getClassHashAt(accountAddress)).to.be.equal(
CAIRO_1_ACCOUNT_CONTRACT_CLASS_HASH
);
});

it("should declare and deploy erc20 contract then transfer some tokens", async () => {
const account = new Account(
providerRPC,
Expand Down

0 comments on commit a1e4a77

Please sign in to comment.