Skip to content

Commit

Permalink
fix contents claim for finalize event and claim params
Browse files Browse the repository at this point in the history
  • Loading branch information
MSghais committed Jun 17, 2024
1 parent 95df39a commit cfc7336
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 58 deletions.
4 changes: 2 additions & 2 deletions prototype/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const ACCOUNT_TEST_PROFILE = {
pubkey: "",
strkKey: "",
// nostrPk: "5b2b830f2778075ab3befb5a48c9d8138aef017fab2b26b5c31a2742a901afcc",
nostrPk:"5b2b830f2778075ab3befb5a48c9d8138aef017fab2b26b5c31a2742a901afcc",
nostrPublicKey:"5b2b830f2778075ab3befb5a48c9d8138aef017fab2b26b5c31a2742a901afcc",
nostrPrivateKey: "59a772c0e643e4e2be5b8bac31b2ab5c5582b03a84444c81d6e2eec34a5e6c35",
// contract:"0x261d2434b2583293b7dd2048cb9c0984e262ed0a3eb70a19ed4eac6defef8b1",
contract:
Expand Down Expand Up @@ -32,7 +32,7 @@ export const ACCOUNT_TEST_PROFILE = {
/*** Dummy data */
nostrPrivateKey:"70aca2a9ab722bd56a9a1aadae7f39bc747c7d6735a04d677e0bc5dbefa71d47",

nostrPk:"d6f1cf53f9f52d876505164103b1e25811ec4226a17c7449576ea48b00578171",
nostrPublicKey:"d6f1cf53f9f52d876505164103b1e25811ec4226a17c7449576ea48b00578171",
// nostrPk:"d6f1cf53f9f52d876505164103b1e25811ec4226a17c7449576ea48b00578171",

contract:
Expand Down
113 changes: 57 additions & 56 deletions prototype/test/escrow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,26 @@ describe("Escrow End to end test", () => {
// let { privateKey: pkBob, publicKey: bobPublicKey } = generateKeypair();

let pkBob = stringToUint8Array(ACCOUNT_TEST_PROFILE?.bob?.nostrPrivateKey);
const bobPublicKey = ACCOUNT_TEST_PROFILE?.bob?.nostrPk;
const bobPublicKey = ACCOUNT_TEST_PROFILE?.bob?.nostrPublicKey;
console.log("privateKey Bob", new Buffer(pkBob).toString("hex"));
console.log("bobPublicKey", bobPublicKey);

/** @TODO Alice account key */
// Nostr account
// let { privateKey: pkAlice, publicKey: alicePublicKey } = generateKeypair();
// let { privateKey: privateKeyAlice, publicKey: alicePublicKey } = generateKeypair();

let pkAlice = stringToUint8Array(
ACCOUNT_TEST_PROFILE?.alice?.nostrPrivateKey
);
const alicePublicKey = ACCOUNT_TEST_PROFILE?.alice?.nostrPk;
console.log("pkAlice", new Buffer(pkAlice).toString("hex"));
// let privateKeyAlice = stringToUint8Array(
// ACCOUNT_TEST_PROFILE?.alice?.nostrPrivateKey
// );
let privateKeyAlice = ACCOUNT_TEST_PROFILE?.alice?.nostrPrivateKey as any;

console.log("ACCOUNT_TEST_PROFILE?.alice?.nostrPrivateKey", ACCOUNT_TEST_PROFILE?.alice?.nostrPrivateKey);

const alicePublicKey = ACCOUNT_TEST_PROFILE?.alice?.nostrPublicKey;
console.log("alicePublicKey", alicePublicKey);

let escrow;
let token_used_address=TOKENS_ADDRESS.DEVNET.ETH;
let token_used_address = TOKENS_ADDRESS.DEVNET.ETH;

if (process.env.IS_DEPLOY_CONTRACT == "true") {
let accountBob = await createEscrowAccount();
Expand All @@ -85,47 +88,48 @@ describe("Escrow End to end test", () => {

/** Deposit */

let firstId=1
let firstId = 1
let currentId = 1; //
let nextId = currentId // await escrow.get_next_deposit_id(); // function need to be made?
console.log("nextId",nextId)

let depositCurrentId = await escrow.get_deposit(currentId)
console.log("depositCurrentId",depositCurrentId)

const depositParams = {
amount: cairo.uint256(amount), // amount int. Float need to be convert with bnToUint
// amount: uint256.bnToUint256(BigInt(amount)), // amount
token_address: strkToken?.address, // token address
// nostr_recipient: uint256.bnToUint256(BigInt("0x" + alicePublicKey)),
nostr_recipient: cairo.uint256(BigInt("0x"+alicePublicKey)),
timelock: 100,
};

expect(cairo.uint256(depositCurrentId?.amount)).to.deep.eq(depositParams?.amount)
// console.log("try approve escrow erc20")

let txApprove = await strkToken.approve(escrow?.address, depositParams?.amount)

await account?.waitForTransaction(txApprove?.transaction_hash)
// Need an approve before
console.log("deposit amount")

let txDeposit = await escrow.deposit(depositParams?.amount,
depositParams?.token_address,
depositParams?.nostr_recipient,
depositParams?.timelock,

);
console.log("txDeposit",txDeposit)
console.log("nextId", nextId)

// let depositCurrentId = await escrow.get_deposit(currentId)
// console.log("depositCurrentId",depositCurrentId)

// const depositParams = {
// amount: cairo.uint256(amount), // amount int. Float need to be convert with bnToUint
// // amount: uint256.bnToUint256(BigInt(amount)), // amount
// token_address: strkToken?.address, // token address
// // nostr_recipient: uint256.bnToUint256(BigInt("0x" + alicePublicKey)),
// nostr_recipient: cairo.uint256(BigInt("0x"+alicePublicKey)),
// timelock: 100,
// };

await account?.waitForTransaction(txDeposit?.transaction_hash);
// expect(cairo.uint256(depositCurrentId?.amount)).to.deep.eq(depositParams?.amount)
// // console.log("try approve escrow erc20")

currentId++;
// let txApprove = await strkToken.approve(escrow?.address, depositParams?.amount)

// await account?.waitForTransaction(txApprove?.transaction_hash)
// // Need an approve before
// console.log("deposit amount")

// let txDeposit = await escrow.deposit(depositParams?.amount,
// depositParams?.token_address,
// depositParams?.nostr_recipient,
// depositParams?.timelock,

// );
// console.log("txDeposit",txDeposit)

// await account?.waitForTransaction(txDeposit?.transaction_hash);

// currentId++;

/** Claim */
let timestamp = new Date().getTime();
let content = cairo.felt(currentId);
// let timestamp = new Date().getTime();
let timestamp=1716285235;
let content = `claim ${cairo.felt(currentId)}`;
// let content =String(currentId)

console.log("content event", content);
Expand All @@ -137,37 +141,34 @@ describe("Escrow End to end test", () => {
content: content,
created_at: timestamp,
},
pkAlice
privateKeyAlice
);

console.log(
"event",
event
);
const signature = event.sig;
const signatureR = signature.slice(0, signature.length / 2);
const signatureS = signature.slice(signature.length / 2);
const signatureR = "0x" + signature.slice(0, signature.length / 2);
const signatureS = "0x" + signature.slice(signature.length / 2);
console.log("signature", signature);
console.log("signatureR", signatureR);
console.log("signatureS", signatureS);

if (signature) {
// let public_key=uint256.bnToUint256(BigInt("0x" + alicePublicKey))
let public_key=cairo.uint256(BigInt("0x" + alicePublicKey))
expect(depositCurrentId?.recipient).to.eq(BigInt("0x" + alicePublicKey))
let public_key = cairo.uint256(BigInt("0x" + alicePublicKey))
// expect(depositCurrentId?.recipient).to.eq(BigInt("0x" + alicePublicKey))
const claimParams = {
public_key: public_key,
created_at: timestamp,
kind: 1,
tags: byteArray.byteArrayFromString("[]"), // tags
content: content, // currentId in felt
// content: content, // currentId in felt
content:cairo.felt(currentId),
signature: {
// r: BigInt("0x"+signatureR),
// s: BigInt("0x"+signatureS),
// r: uint256.bnToUint256(BigInt("0x"+signatureR)),
// s: uint256.bnToUint256(BigInt("0x"+signatureS)),
r: cairo.uint256(BigInt("0x" + signatureR)),
s: cairo.uint256(BigInt("0x" + signatureS)),
r: cairo.uint256(signatureR),
s: cairo.uint256(signatureS),
},
};

Expand Down

0 comments on commit cfc7336

Please sign in to comment.