Skip to content

Commit

Permalink
check class hash + env
Browse files Browse the repository at this point in the history
  • Loading branch information
MSghais committed Jun 18, 2024
1 parent be6db3e commit 8fc631d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 42 deletions.
3 changes: 2 additions & 1 deletion prototype/.env.exemple
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ ACCOUNT_CLASS_HASH=0x06a2684722b20b66e140dbd6cf8b7fb3d7736a46af3efebb467dc527960
AA_PUBKEY=0x3...de
AA_PRIVATE_KEY=0x1..99
NODE_ENV=development
IS_DEPLOY_CONTRACT=true


# To run Nostr relayer, not needed
Expand All @@ -25,3 +24,5 @@ DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:$
NOSTR_RELAYER_WEBSOCKET=ws://localhost:3000

ESCROW_CLASS_HASH=0x3f70abaaeef59cc900b597d45a2c97c08abb5260c03327cce9e45d4c7a8ad0 # Sepolia
IS_DEPLOY_CONTRACT=true
REDECLARE_ACCOUNT=false # Set to true on devnet
42 changes: 15 additions & 27 deletions prototype/test/escrow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ dotenv.config();
const currentId = 1
const idToClaim = 1
const idToCancel = 1
let escrow_address = ACCOUNT_TEST_PROFILE.escrow.contract // change default address
let escrow_address:string|undefined = ACCOUNT_TEST_PROFILE.escrow.contract // change default address
let token_used_address = TOKENS_ADDRESS.DEVNET.ETH;

describe("Escrow End to end test", () => {
Expand All @@ -38,6 +38,10 @@ describe("Escrow End to end test", () => {
let escrowContract = await createEscrowAccount();

console.log("escrow address", escrowContract?.contract_address)

if(escrowContract?.contract_address) {
escrow_address=escrowContract?.contract_address
}
escrow = await prepareAndConnectContract(
escrowContract?.contract_address ?? ACCOUNT_TEST_PROFILE?.escrow?.contract, // uncomment if you recreate a contract
account
Expand All @@ -57,20 +61,10 @@ describe("Escrow End to end test", () => {
const account = new Account(provider, accountAddress0, privateKey0, "1");
const alicePublicKey = ACCOUNT_TEST_PROFILE?.alice?.nostrPublicKey;

let escrow;
if (process.env.IS_DEPLOY_CONTRACT == "true") {
let escrowContract = await createEscrowAccount();

escrow = await prepareAndConnectContract(
escrowContract?.contract_address ?? ACCOUNT_TEST_PROFILE?.escrow?.contract, // uncomment if you recreate a contract
account
);
} else {
escrow = await prepareAndConnectContract(
escrow_address ?? ACCOUNT_TEST_PROFILE?.escrow?.contract,
account
);
}
let escrow = await prepareAndConnectContract(
escrow_address ?? ACCOUNT_TEST_PROFILE?.escrow?.contract,
account
);

/** Send a note */
let amount: number = 1;
Expand Down Expand Up @@ -116,24 +110,18 @@ describe("Escrow End to end test", () => {
let privateKeyAlice = ACCOUNT_TEST_PROFILE?.alice?.nostrPrivateKey as any;
const alicePublicKey = ACCOUNT_TEST_PROFILE?.alice?.nostrPublicKey;

let escrow;
if (process.env.IS_DEPLOY_CONTRACT == "true") {
let escrowContract = await createEscrowAccount();
escrow = await prepareAndConnectContract(
escrowContract?.contract_address ?? ACCOUNT_TEST_PROFILE?.escrow?.contract, // uncomment if you recreate a contract
account
);
} else {
escrow = await prepareAndConnectContract(
let escrow= await prepareAndConnectContract(
escrow_address ?? ACCOUNT_TEST_PROFILE?.escrow?.contract,
account
);
}
/** Claim */
let timestamp = 1716285235;

let depositToClaim = await escrow.get_deposit(idToClaim)
console.log("deposit to claim",depositToClaim)
// let timestamp = new Date().getTime();

let content = `claim ${cairo.felt(currentId)}`;
let content = `claim ${cairo.felt(idToClaim)}`;
let txClaim = await claimDeposit({
escrow,
account,
Expand Down Expand Up @@ -167,4 +155,4 @@ describe("Escrow End to end test", () => {
})

});
});
});
29 changes: 16 additions & 13 deletions prototype/utils/escrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,21 @@ export const createEscrowAccount = async () => {
// const AAaccount = new Account(provider, AAcontractAddress, AAprivateKey);
/** @description uncomment this to declare your account */
// console.log("declare account");
console.log("try declare account");
const declareResponse = await account0.declare({
contract: compiledSierraAAaccount,
casm: compiledAACasm,
});
console.log("Declare deploy", declareResponse?.transaction_hash);
await provider.waitForTransaction(declareResponse?.transaction_hash);
const contractClassHash = declareResponse.class_hash;
EscrowClassHash = contractClassHash;

if(process.env.REDECLARE_ACCOUNT) {
console.log("try declare account");
const declareResponse = await account0.declare({
contract: compiledSierraAAaccount,
casm: compiledAACasm,
});
console.log("Declare deploy", declareResponse?.transaction_hash);
await provider.waitForTransaction(declareResponse?.transaction_hash);
const contractClassHash = declareResponse.class_hash;
EscrowClassHash = contractClassHash;

const nonce = await account0?.getNonce();
console.log("nonce", nonce);
const nonce = await account0?.getNonce();
console.log("nonce", nonce);
}

const { transaction_hash, contract_address } =
await account0.deployContract({
Expand Down Expand Up @@ -122,7 +124,9 @@ export const deposit = async (props: {
try {
const { escrow, account, amount, tokenAddress, timelock, alicePublicKey } = props
const depositParams = {
amount: cairo.uint256(amount), // amount int. Float need to be convert with bnToUint
amount: uint256.bnToUint256(BigInt("0x"+amount)), // amount float. cairo.uint256(amount) for Int
// Float need to be convert with bnToUint

token_address: tokenAddress, // token address
nostr_recipient: cairo.uint256(BigInt("0x" + alicePublicKey)),
timelock: timelock,
Expand Down Expand Up @@ -233,4 +237,3 @@ export const cancel = async (props: {
console.log("Error cancel", e)
}
}

2 changes: 1 addition & 1 deletion prototype/utils/starknet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ export const connectWallet = (
} catch (e) {
return undefined;
}
};
};

0 comments on commit 8fc631d

Please sign in to comment.