Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

niljs: handle failed external failed #156

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion niljs/src/utils/receipt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,23 @@ async function waitTillCompleted(
options?: { waitTillMainShard?: boolean; interval?: number },
): Promise<ProcessedReceipt[]> {
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 &&
Expand All @@ -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;
Expand Down
28 changes: 28 additions & 0 deletions niljs/test/integration/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
3 changes: 2 additions & 1 deletion niljs/test/integration/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}

Expand Down