diff --git a/prototype/.env.exemple b/prototype/.env.exemple index 32494407..bcaac2e9 100644 --- a/prototype/.env.exemple +++ b/prototype/.env.exemple @@ -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 @@ -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 \ No newline at end of file diff --git a/prototype/test/escrow.test.ts b/prototype/test/escrow.test.ts index 04b30de0..0d61cb3e 100644 --- a/prototype/test/escrow.test.ts +++ b/prototype/test/escrow.test.ts @@ -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", () => { @@ -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 @@ -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; @@ -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, @@ -167,4 +155,4 @@ describe("Escrow End to end test", () => { }) }); -}); +}); \ No newline at end of file diff --git a/prototype/utils/escrow.ts b/prototype/utils/escrow.ts index 029d894d..57c49d4c 100644 --- a/prototype/utils/escrow.ts +++ b/prototype/utils/escrow.ts @@ -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({ @@ -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, @@ -233,4 +237,3 @@ export const cancel = async (props: { console.log("Error cancel", e) } } - diff --git a/prototype/utils/starknet.ts b/prototype/utils/starknet.ts index 23ca425c..d7a33c17 100644 --- a/prototype/utils/starknet.ts +++ b/prototype/utils/starknet.ts @@ -42,4 +42,4 @@ export const connectWallet = ( } catch (e) { return undefined; } -}; +}; \ No newline at end of file