From f0944c0e8775984cb2c446249dea110aedef55fa Mon Sep 17 00:00:00 2001 From: rolaman Date: Wed, 5 Feb 2025 18:17:28 +0300 Subject: [PATCH] niljs: waitTillMainShard default set to false --- niljs/src/utils/receipt.ts | 9 ++++++++- niljs/test/integration/deploy.test.ts | 28 +++++++++++++++++++++++++++ niljs/test/integration/helpers.ts | 3 ++- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/niljs/src/utils/receipt.ts b/niljs/src/utils/receipt.ts index 236799186..36c1f437f 100644 --- a/niljs/src/utils/receipt.ts +++ b/niljs/src/utils/receipt.ts @@ -18,17 +18,23 @@ async function waitTillCompleted( options?: { waitTillMainShard?: boolean; interval?: number }, ): Promise { const interval = options?.interval || 1000; - const waitTillMainShard = options?.waitTillMainShard || true; + const waitTillMainShard = options?.waitTillMainShard || false; const receipts: ProcessedReceipt[] = []; const hashes: [Hex][] = [[hash]]; let cur = 0; while (cur !== hashes.length) { const [hash] = hashes[cur]; const receipt = await client.getTransactionReceiptByHash(hash); + if (!receipt) { await new Promise((resolve) => setTimeout(resolve, interval)); continue; } + + if (hashes.length === 1 && receipt.flags.some((x) => x === "External") && !receipt.success) { + return [receipt]; + } + if ( receipt.outTransactions !== null && receipt.outputReceipts && @@ -37,6 +43,7 @@ async function waitTillCompleted( await new Promise((resolve) => setTimeout(resolve, interval)); continue; } + if (waitTillMainShard && receipt.shardId !== 0 && !receipt.includedInMain) { await new Promise((resolve) => setTimeout(resolve, interval)); continue; diff --git a/niljs/test/integration/deploy.test.ts b/niljs/test/integration/deploy.test.ts index ec82ab384..133778710 100644 --- a/niljs/test/integration/deploy.test.ts +++ b/niljs/test/integration/deploy.test.ts @@ -78,3 +78,31 @@ test("External deployment", async ({ expect }) => { expect(code).toBeDefined(); expect(code.length).toBeGreaterThan(10); }); + +test("External failed deployment", async ({ expect }) => { + const chainId = await client.chainId(); + const gasPrice = await client.getGasPrice(1); + + const pubKey = generatePublicKey(); + const deploymentTransaction = externalDeploymentTransaction( + { + salt: 100n, + shard: 1, + bytecode: SmartAccountV1.code, + abi: SmartAccountV1.abi, + args: [pubKey], + feeCredit: 1000000n * gasPrice, + }, + chainId, + ); + const addr = bytesToHex(deploymentTransaction.to); + expect(addr).toBeDefined(); + + await topUpTest(addr, "NIL", 50_000_000); + + const hash = await deploymentTransaction.send(client); + + const receipts = await waitTillCompleted(client, hash); + + expect(receipts.some((receipt) => !receipt.success)).toBe(true); +}); diff --git a/niljs/test/integration/helpers.ts b/niljs/test/integration/helpers.ts index e6f68b0f4..f7d71cf78 100644 --- a/niljs/test/integration/helpers.ts +++ b/niljs/test/integration/helpers.ts @@ -35,12 +35,13 @@ export function generatePublicKey() { return getPublicKey(generateRandomPrivateKey()); } -export async function topUpTest(address: Hex, token = "NIL") { +export async function topUpTest(address: Hex, token = "NIL", amount = 1e18) { await topUp({ address, rpcEndpoint: testEnv.endpoint, faucetEndpoint: testEnv.faucetServiceEndpoint, token, + amount, }); }