From bf9e2c60b79df29ad2297a862ac7a69bc1c79b22 Mon Sep 17 00:00:00 2001 From: Simonas Narbutas Date: Thu, 1 Feb 2024 14:01:10 +0200 Subject: [PATCH 1/2] PM-1135: paymentGenerator run indefinitely --- src/paymentGenerator.ts | 71 +++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 28 deletions(-) diff --git a/src/paymentGenerator.ts b/src/paymentGenerator.ts index 4b416f4..e9f28db 100644 --- a/src/paymentGenerator.ts +++ b/src/paymentGenerator.ts @@ -6,9 +6,28 @@ export async function paymentGenerator( receivers: string[], noTransactions: number, timeDelayMS: number +) { + if (noTransactions === -1) { + while (true) { + const receiver = receivers[Math.floor(Math.random() * receivers.length)]; + await processTransaction(network, deployerAccount, receiver, timeDelayMS); + } + } else { + for (let i = 0; i < noTransactions; i++) { + const receiver = receivers[Math.floor(Math.random() * receivers.length)]; + await processTransaction(network, deployerAccount, receiver, timeDelayMS); + } + } +} +async function processTransaction( + network: string, + deployerAccount: string, + receiver: string, + timeDelayMS: number ) { const client = new Client({ network: 'testnet' }); let sender_public = client.derivePublicKey(deployerAccount) + console.log("receiver: ", receiver); const query = `query MyQuery { account(publicKey: "${sender_public}") { inferredNonce @@ -24,32 +43,28 @@ export async function paymentGenerator( }), }) let inferred_nonce = parseInt((await response.json()).data.account.inferredNonce) - for (let i = 0; i < noTransactions; i++) { - const receiver = receivers[Math.floor(Math.random() * receivers.length)] - console.log("receiver: ", receiver) - let signedPayment = client.signPayment( - { - to: receiver, - from: sender_public, - amount: 1500000, - fee: 2000000000, - nonce: inferred_nonce + i - }, - deployerAccount - ); - const query_pay = `mutation MyMutation { - sendPayment(input: {fee: 2000000000, amount: "1500000", to: "${receiver}", from: "${sender_public}", nonce: "${inferred_nonce + i}"}, signature: {field: "${signedPayment.signature.field}", scalar: "${signedPayment.signature.scalar}"})}` - await fetch(network, { - method: "POST", - headers: { - "Content-Type": "application/json" - }, - body: JSON.stringify({ - query: query_pay - }), - }) - .then(r => r.json()) - .then(data => console.log("data returned:", data)) - await new Promise(r => setTimeout(r, timeDelayMS)); - } + let signedPayment = client.signPayment( + { + to: receiver, + from: sender_public, + amount: 1500000, + fee: 2000000000, + nonce: inferred_nonce + }, + deployerAccount + ); + const query_pay = `mutation MyMutation { + sendPayment(input: {fee: 2000000000, amount: "1500000", to: "${receiver}", from: "${sender_public}", nonce: "${inferred_nonce}"}, signature: {field: "${signedPayment.signature.field}", scalar: "${signedPayment.signature.scalar}"})}`; + await fetch(network, { + method: "POST", + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify({ + query: query_pay + }), + }) + .then(r => r.json()) + .then(data => console.log("data returned:", data)); + await new Promise(r => setTimeout(r, timeDelayMS)); } From 91fa2e3fda146aa91ccc6fa9df8157e82cc1fc39 Mon Sep 17 00:00:00 2001 From: Simonas Narbutas Date: Thu, 1 Feb 2024 15:02:51 +0200 Subject: [PATCH 2/2] PM-1135: zkAppGenerator run indefinitely --- src/zkAppGenerator.ts | 68 ++++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 26 deletions(-) diff --git a/src/zkAppGenerator.ts b/src/zkAppGenerator.ts index 22848fd..442a95e 100644 --- a/src/zkAppGenerator.ts +++ b/src/zkAppGenerator.ts @@ -9,16 +9,35 @@ import { export async function zkAppGenerator( network: string, deployerAccount: string, - walletList: string[], + receivers: string[], noTransactions: number, timeDelayMS: number +) { + if (noTransactions === -1) { + while (true) { + const receiver = receivers[Math.floor(Math.random() * receivers.length)]; + await processZKTransaction(network, deployerAccount, receiver, timeDelayMS); + } + } else { + for (let i = 0; i < noTransactions; i++) { + const receiver = receivers[Math.floor(Math.random() * receivers.length)]; + await processZKTransaction(network, deployerAccount, receiver, timeDelayMS); + } + } +} + +async function processZKTransaction( + network: string, + deployerAccount: string, + receiver: string, + timeDelayMS: number ) { const devNet = Mina.Network( network ); Mina.setActiveInstance(devNet); - const deployerPrivKey = PrivateKey.fromBase58(deployerAccount); // + const deployerPrivKey = PrivateKey.fromBase58(deployerAccount); const deployerPubKey = deployerPrivKey.toPublicKey(); console.log('Sender public key:', deployerPubKey.toBase58().toString()); const query = `query MyQuery { @@ -37,34 +56,31 @@ export async function zkAppGenerator( }) let inferred_nonce = parseInt((await response.json()).data.account.inferredNonce) - for (let i = 0; i < noTransactions; i++) { - let receiver = walletList[Math.floor(Math.random() * walletList.length)] - const toUserPublicKey = PublicKey.fromBase58(receiver); - console.log('Receiver public key:', toUserPublicKey.toBase58().toString()); + const toUserPublicKey = PublicKey.fromBase58(receiver); + console.log('Receiver public key:', toUserPublicKey.toBase58().toString()); - const MINA = 1e9; - const amount = 1 * MINA; + const MINA = 1e9; + const amount = 1 * MINA; - let memo = 'Test ZKApp to Receiver'; - const transactionFee = 2 * MINA; + let memo = 'Test ZKApp to Receiver'; + const transactionFee = 2 * MINA; - console.log('amount:', amount); - const tx = await Mina.transaction({ sender: deployerPubKey, fee: transactionFee, memo: memo, nonce: inferred_nonce + i }, () => { - let accountUpdate; - accountUpdate = AccountUpdate.createSigned(deployerPubKey); - accountUpdate.send({ to: toUserPublicKey, amount: UInt64.from(amount) }); - }); - await tx.prove(); - console.log('tx.toPretty() : ' + JSON.stringify(tx.toPretty())); + console.log('amount:', amount); + const tx = await Mina.transaction({ sender: deployerPubKey, fee: transactionFee, memo: memo, nonce: inferred_nonce }, () => { + let accountUpdate; + accountUpdate = AccountUpdate.createSigned(deployerPubKey); + accountUpdate.send({ to: toUserPublicKey, amount: UInt64.from(amount) }); + }); + await tx.prove(); + console.log('tx.toPretty() : ' + JSON.stringify(tx.toPretty())); - const res = await tx.sign([deployerPrivKey]).send(); + const res = await tx.sign([deployerPrivKey]).send(); - console.log('res : ' + JSON.stringify(res)); - const hash = await res.hash(); + console.log('res : ' + JSON.stringify(res)); + const hash = await res.hash(); - if (hash == null) { - console.log('error sending transaction (see above)'); - } - await new Promise(r => setTimeout(r, timeDelayMS)); + if (hash == null) { + console.log('error sending transaction (see above)'); } -} \ No newline at end of file + await new Promise(r => setTimeout(r, timeDelayMS)); +}