Skip to content

Commit 90d1bd3

Browse files
committed
added consecutive mint e2e test
1 parent 4f748a5 commit 90d1bd3

File tree

6 files changed

+234
-11
lines changed

6 files changed

+234
-11
lines changed

e2e/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ clean:
55
sudo rm -rf /tmp/data
66

77
test:
8-
cd tester && yarn install && yarn test
8+
cd tester && yarn install && yarn debug-test

e2e/tester/flows/burn.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { parseUnits, recoverAddress } from "viem";
1+
import { parseUnits } from "viem";
22
import ethereum from "../util/ethereum";
33
import pocket from "../util/pocket";
44
import { expect } from "chai";
@@ -16,7 +16,9 @@ type MessageSend = {
1616
};
1717

1818
export const burnFlow = async () => {
19-
it("should burn for send tx to vault with valid memo", async () => {
19+
it("should burn and return amount from vault", async () => {
20+
debug("\nTesting -- should burn and return amount from vault");
21+
2022
const fromAddress = await ethereum.getAddress();
2123
const recipientAddress = await pocket.getAddress();
2224
const amount = parseUnits("1", 6);
@@ -25,8 +27,6 @@ export const burnFlow = async () => {
2527
const recipientBeforeBalance = await pocket.getBalance(recipientAddress);
2628
const fromBeforeBalance = await ethereum.getWPOKTBalance(fromAddress);
2729

28-
expect(fromBeforeBalance).to.be.equal(amount);
29-
3030
debug("Sending transaction...");
3131
const burnTx = await ethereum.burnAndBridgeWPOKT(
3232
await ethereum.walletPromise,

e2e/tester/flows/mint.ts

Lines changed: 225 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { parseUnits } from "viem";
1+
import { TransactionReceipt, parseUnits } from "viem";
22
import ethereum from "../util/ethereum";
33
import pocket from "../util/pocket";
44
import { expect } from "chai";
55
import { findInvalidMint, findMint } from "../util/mongodb";
6-
import { MintMemo, Status } from "../types";
6+
import { Mint, MintMemo, Status } from "../types";
77
import { sleep, debug } from "../util/helpers";
88

99
type MessageSend = {
@@ -17,6 +17,8 @@ type MessageSend = {
1717

1818
export const mintFlow = async () => {
1919
it("should mint for send tx to vault with valid memo", async () => {
20+
debug("\nTesting -- should mint for send tx to vault with valid memo");
21+
2022
const signer = await pocket.signerPromise;
2123
const fromAddress = await pocket.getAddress();
2224
const recipientAddress = await ethereum.getAddress();
@@ -166,6 +168,10 @@ export const mintFlow = async () => {
166168
});
167169

168170
it("should fail mint to invalidMint for failed send tx to vault", async () => {
171+
debug(
172+
"\nTesting -- should fail mint to invalidMint for failed send tx to vault"
173+
);
174+
169175
const signer = await pocket.signerPromise;
170176
const fromAddress = await pocket.getAddress();
171177
const toAddress = pocket.VAULT_ADDRESS;
@@ -204,6 +210,10 @@ export const mintFlow = async () => {
204210
});
205211

206212
it("should return amount for send tx to vault with invalid memo", async () => {
213+
debug(
214+
"\nTesting -- should return amount for send tx to vault with invalid memo"
215+
);
216+
207217
const signer = await pocket.signerPromise;
208218
const fromAddress = await pocket.getAddress();
209219
const toAddress = pocket.VAULT_ADDRESS;
@@ -332,4 +342,217 @@ export const mintFlow = async () => {
332342

333343
debug("InvalidMint success");
334344
});
345+
346+
it("should do multiple consecutive mints", async () => {
347+
debug("\nTesting -- should do multiple consecutive mints");
348+
349+
const signer = await pocket.signerPromise;
350+
const fromAddress = await pocket.getAddress();
351+
const recipientAddress = await ethereum.getAddress();
352+
const toAddress = pocket.VAULT_ADDRESS;
353+
const amounts = [
354+
parseUnits("1", 6),
355+
parseUnits("2", 6),
356+
parseUnits("3", 6),
357+
];
358+
const fee = BigInt(10000);
359+
const startNonce = 2;
360+
361+
const memo: MintMemo = {
362+
address: recipientAddress,
363+
chain_id: ethereum.CHAIN.id.toString(),
364+
};
365+
366+
const fromBeforeBalance = await pocket.getBalance(fromAddress);
367+
const toBeforeBalance = await pocket.getBalance(toAddress);
368+
369+
debug("Sending transactions...");
370+
const sendTxs = await Promise.all(
371+
amounts.map(async (amount) =>
372+
pocket.sendPOKT(
373+
signer,
374+
toAddress,
375+
amount.toString(),
376+
JSON.stringify(memo),
377+
fee.toString()
378+
)
379+
)
380+
);
381+
382+
expect(sendTxs).to.not.be.null;
383+
expect(sendTxs.length).to.equal(amounts.length);
384+
385+
if (!sendTxs) return;
386+
387+
sendTxs.forEach((sendTx, i) => {
388+
expect(sendTx).to.not.be.null;
389+
390+
if (!sendTx) return;
391+
debug(`Transaction ${i} sent: `, sendTx.hash);
392+
});
393+
394+
const fromAfterBalance = await pocket.getBalance(fromAddress);
395+
const toAfterBalance = await pocket.getBalance(toAddress);
396+
397+
const totalAmount = amounts.reduce(
398+
(total, amount) => total + amount,
399+
BigInt(0)
400+
);
401+
402+
expect(fromAfterBalance).to.equal(
403+
fromBeforeBalance - totalAmount - BigInt(amounts.length) * fee
404+
);
405+
expect(toAfterBalance).to.equal(toBeforeBalance + totalAmount);
406+
407+
debug(`Waiting for mints to be created...`);
408+
await sleep(2000);
409+
410+
await Promise.all(
411+
sendTxs.map(async (sendTx, i) => {
412+
if (!sendTx) return;
413+
414+
const mint = await findMint(sendTx.hash);
415+
416+
expect(mint).to.not.be.null;
417+
418+
if (!mint) return;
419+
debug(`Mint ${i} created`);
420+
421+
expect(mint.height.toString()).to.equal(sendTx.height.toString());
422+
expect(mint.sender_address.toLowerCase()).to.equal(
423+
fromAddress.toLowerCase()
424+
);
425+
expect(mint.recipient_address.toLowerCase()).to.equal(
426+
recipientAddress.toLowerCase()
427+
);
428+
const amount = amounts[i];
429+
expect(mint.amount.toString()).to.equal(amount.toString());
430+
expect(mint.status).to.equal(Status.PENDING);
431+
})
432+
);
433+
434+
await sleep(12000);
435+
436+
await Promise.all(
437+
sendTxs.map(async (sendTx, i) => {
438+
if (!sendTx) return;
439+
440+
const mint = await findMint(sendTx.hash);
441+
442+
expect(mint).to.not.be.null;
443+
444+
if (!mint) return;
445+
446+
expect(mint.status).to.be.oneOf([Status.CONFIRMED, Status.SIGNED]);
447+
debug(`Mint ${i} confirmed`);
448+
})
449+
);
450+
451+
await sleep(3000);
452+
453+
const noncesToSee = sendTxs.map((_, i) => (i + startNonce).toString());
454+
455+
const sortedMints: Array<Mint | null> = [null, null, null];
456+
457+
for (let i = 0; i < sendTxs.length; i++) {
458+
const sendTx = sendTxs[i];
459+
460+
if (!sendTx) return;
461+
462+
const mint = await findMint(sendTx.hash);
463+
464+
expect(mint).to.not.be.null;
465+
466+
if (!mint) return;
467+
468+
expect(mint.status).to.equal(Status.SIGNED);
469+
debug(`Mint ${i} signed`);
470+
471+
expect(mint.signers.length).to.equal(3);
472+
expect(mint.signatures.length).to.equal(3);
473+
const nonce = mint.nonce.toString();
474+
expect(noncesToSee).to.include(nonce);
475+
noncesToSee.splice(noncesToSee.indexOf(nonce), 1);
476+
477+
const sortedIndex = parseInt(nonce) - startNonce;
478+
sortedMints[sortedIndex] = mint;
479+
}
480+
481+
const mintTxs: Array<TransactionReceipt> = [];
482+
483+
for (let i = 0; i < sortedMints.length; i++) {
484+
const mint = sortedMints[i];
485+
expect(mint).to.not.be.null;
486+
487+
if (!mint) return;
488+
489+
expect(mint.data).to.not.be.null;
490+
491+
if (!mint.data) return;
492+
493+
const beforeWPOKTBalance = await ethereum.getWPOKTBalance(
494+
recipientAddress
495+
);
496+
497+
debug(`Minting ${i} WPOKT...`);
498+
const mintTx = await ethereum.mintWPOKT(
499+
await ethereum.walletPromise,
500+
mint.data,
501+
mint.signatures
502+
);
503+
504+
expect(mintTx).to.not.be.null;
505+
506+
if (!mintTx) return;
507+
debug(`WPOKT ${i} minted: `, mintTx.transactionHash);
508+
509+
expect(mintTx.transactionHash).to.be.a("string");
510+
511+
mintTxs.push(mintTx);
512+
513+
const mintedEvent = ethereum.findMintedEvent(mintTx);
514+
515+
expect(mintedEvent).to.not.be.null;
516+
517+
if (!mintedEvent) return;
518+
519+
expect(mintedEvent.nonce.toString()).to.equal(mint.nonce.toString());
520+
expect(mintedEvent.recipient.toLowerCase()).to.equal(
521+
recipientAddress.toLowerCase()
522+
);
523+
expect(mintedEvent.amount.toString()).to.equal(mint.amount.toString());
524+
525+
const afterWPOKTBalance = await ethereum.getWPOKTBalance(
526+
recipientAddress
527+
);
528+
529+
expect(afterWPOKTBalance).to.equal(
530+
beforeWPOKTBalance + BigInt(mint.amount)
531+
);
532+
}
533+
534+
await sleep(2000);
535+
536+
await Promise.all(
537+
sortedMints.map(async (oldMint, i) => {
538+
expect(oldMint).to.not.be.null;
539+
if (!oldMint) return;
540+
541+
const mint = await findMint(oldMint.transaction_hash);
542+
543+
expect(mint).to.not.be.null;
544+
545+
if (!mint) return;
546+
547+
expect(mint.status).to.equal(Status.SUCCESS);
548+
549+
const mintTx = mintTxs[i];
550+
551+
expect(mint.mint_tx_hash.toLowerCase()).to.equal(
552+
mintTx.transactionHash.toLowerCase()
553+
);
554+
debug(`Mint ${i} success`);
555+
})
556+
);
557+
});
335558
};

e2e/tester/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"author": "dan13ram",
66
"license": "MIT",
77
"scripts": {
8-
"test": "mocha --exit -t 30000 -r ts-node/register index.ts",
9-
"debug": "DEBUG=true yarn test"
8+
"test": "mocha --exit -t 60000 -r ts-node/register index.ts",
9+
"debug-test": "DEBUG=true yarn test"
1010
},
1111
"dependencies": {
1212
"@pokt-foundation/pocketjs-provider": "^2.1.3",

e2e/tester/util/ethereum.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ const walletPromise: Promise<WalletClient<Transport, Chain, Account>> =
101101
await sendETH(
102102
defaultWalletClient,
103103
walletClient.account.address,
104-
parseUnits("1000", 18)
104+
parseUnits("10", 18)
105105
);
106106

107107
return walletClient;

e2e/tester/util/pocket.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const signerPromise = (async (): Promise<AbstractSigner> => {
8585
await sendPOKT(
8686
defaultSigner,
8787
newSigner.getAddress(),
88-
parseUnits("1000", 6).toString(),
88+
parseUnits("100", 6).toString(),
8989
"init"
9090
);
9191
return newSigner;

0 commit comments

Comments
 (0)