-
Notifications
You must be signed in to change notification settings - Fork 43
Feature/nil bridge unit tests #950
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
Open
defistar
wants to merge
13
commits into
main
Choose a base branch
from
feature/nil-bridge-unit-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
cfb23d0
feat: hardhat tests for nil-bridge contracts - setup fixture
defistar 3814d66
feat: setup fixture for l2-bridge unit test
defistar 513f708
feat: add logging to the eth-bridge on l2 hardhat test - setupfixture
defistar bccc503
fix: set privateKey config for unit test
defistar 73a3dd8
fix: setup all environment variables needed for l2 bridge unit tests
defistar 5500bb4
fix: selfDeploy all smartAccount creation activity in L2Bridge Unit test
defistar 3b70188
fix prepareNilSmartAccountsForUnitTest
07b95fc
feat: setup fixture enhancement for nil-hardhat unit tests
defistar 1bac5ff
fix: generateL2RelayMessage for EthBriding test
defistar 53f91a0
feat: setuptestFixture for L2BridgeContracts and ETHBridge UnitTest
defistar a62c2b3
fix: add new-line in run_tests script
defistar 7653062
fix: revert grant-relayer role local changes
defistar 6282383
fix: remove obselete code comment in hardhat config of rollup-bridge-…
defistar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import { expect } from "chai"; | ||
| import "@nomicfoundation/hardhat-ethers"; | ||
| import { | ||
| ProcessedReceipt, | ||
| } from "@nilfoundation/niljs"; | ||
| import "dotenv/config"; | ||
| import type { Abi } from "abitype"; | ||
| import { encodeFunctionData } from "viem"; | ||
| import { generateL2RelayMessage } from "./generate-l2-relay-message"; | ||
| import { bigIntReplacer } from "../../deploy/config/config-helper"; | ||
| import { L2BridgeTestFixtureResult, setupL2BridgeTestFixture } from "./l2-bridge-test-fixture"; | ||
|
|
||
| const l1EthBridgeAddress = '0x0001e0d8f4De4E838a66963f406Fa826cCaCA322'; | ||
|
|
||
| describe("L2BridgeMessenger Contract", () => { | ||
| it("Should accept the (ETHDeposit) message relayed by relayer", async () => { | ||
|
|
||
| const l2BridgeTestFixture: L2BridgeTestFixtureResult = await setupL2BridgeTestFixture(); | ||
|
|
||
| // Relay DepositMessage to L2 | ||
| const depositorAddressValue = "0xc8d5559BA22d11B0845215a781ff4bF3CCa0EF89"; | ||
| const depositAmountValue = "1000000000000"; | ||
| const l2DepositRecipientValue = l2BridgeTestFixture.depositRecipientSmartAccount.address; | ||
| const l2FeeRefundAddressValue = l2BridgeTestFixture.feeRefundSmartAccount.address; | ||
|
|
||
| try { | ||
| const messageSender = l1EthBridgeAddress; | ||
| const messageTarget = l2BridgeTestFixture.l2ETHBridgeProxyAddress; | ||
| const messageType = "1"; | ||
| const messageCreatedAt = Math.floor(Date.now() / 1000); | ||
| const messageExpiryTime = Math.floor(Date.now() / 1000) + 10000; | ||
| const ethDepositRelayMessage = generateL2RelayMessage(depositorAddressValue, depositAmountValue, l2DepositRecipientValue, l2FeeRefundAddressValue); | ||
| const nilGasLimit = "1000000"; | ||
| const maxFeePerGas = "27500000"; | ||
| const maxPriorityFeePerGas = "1250000"; | ||
| const feeCredit = "27500000000000"; | ||
| const messageNonce = 0; | ||
|
|
||
| // Dynamically load artifacts | ||
| const L2BridgeMessengerJson = await import("../../artifacts/contracts/bridge/l2/L2BridgeMessenger.sol/L2BridgeMessenger.json"); | ||
|
|
||
| if (!L2BridgeMessengerJson || !L2BridgeMessengerJson.default || !L2BridgeMessengerJson.default.abi || !L2BridgeMessengerJson.default.bytecode) { | ||
| throw Error(`Invalid L2BridgeMessengerJson ABI`); | ||
| } | ||
|
|
||
| const relayMessage = encodeFunctionData({ | ||
| abi: L2BridgeMessengerJson.default.abi as Abi, | ||
| functionName: "relayMessage", | ||
| args: [messageSender, messageTarget, messageType, messageNonce, ethDepositRelayMessage, messageExpiryTime], | ||
| }); | ||
|
|
||
| console.log(`generated message to relay on L2BridgeMessenger: ${relayMessage}`); | ||
|
|
||
| const relayEthDepositMessageResponse = await l2BridgeTestFixture.ownerSmartAccount.sendTransaction({ | ||
| to: l2BridgeTestFixture.l2BridgeMessengerProxyAddress as `0x${string}`, | ||
| data: relayMessage, | ||
| feeCredit: BigInt(feeCredit), | ||
| maxFeePerGas: BigInt(maxFeePerGas), | ||
| maxPriorityFeePerGas: BigInt(maxPriorityFeePerGas) | ||
| }); | ||
|
|
||
| console.log(`relayMessage transaction was done and awaiting for ProcessedReceipt`); | ||
|
|
||
| const relayEthDepositMessageTxnReceipts: ProcessedReceipt[] = await relayEthDepositMessageResponse.wait(); | ||
|
|
||
| const relayedEthDepositMessageTxnReceipt: ProcessedReceipt = relayEthDepositMessageTxnReceipts[0] as ProcessedReceipt; | ||
|
|
||
| const outputReceipts: ProcessedReceipt[] = relayedEthDepositMessageTxnReceipt.outputReceipts as ProcessedReceipt[]; | ||
|
|
||
| console.log(`outputReceipt is: ${JSON.stringify(outputReceipts, bigIntReplacer, 2)}`) | ||
|
|
||
| const outputReceipt: ProcessedReceipt = outputReceipts[0] as ProcessedReceipt; | ||
|
|
||
| console.log(`outputReceipt extracted as: ${JSON.stringify(outputReceipt, bigIntReplacer, 2)}`); | ||
|
|
||
| // check the first element in the ProcessedReceipt and verify if it is successful | ||
| if (!outputReceipt.success) { | ||
| console.error(`Failed to relay message | ||
| on the L2BridgeMessenger contract: ${l2BridgeTestFixture.l2BridgeMessengerProxyAddress}`); | ||
| } else { | ||
| console.log(`successfully relayed EthDepositMessage on to L2BridgeMessenger with transactionReceipt: ${JSON.stringify(relayEthDepositMessageTxnReceipts[0], bigIntReplacer, 2)}`); | ||
| } | ||
| } catch (err) { | ||
| console.error(`Failed to relay ethBridge message on to L2BridgeMessenger: ${JSON.stringify(err)}`); | ||
| } | ||
| }); | ||
| }); |
29 changes: 29 additions & 0 deletions
29
rollup-bridge-contracts/test/hardhat/generate-l2-relay-message.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { ethers } from "ethers"; | ||
|
|
||
| // npx ts-node test/hardhat/generate-l2-relay-message.ts | ||
| export const generateL2RelayMessage = (depositorAddress: String, depositAmount: String, l2DepositRecipient: String, l2FeeRefundAddress: String): String => { | ||
| const abi = [ | ||
| "function finaliseETHDeposit(address depositorAddress, uint256 depositAmount, address l2DepositRecipient, address l2FeeRefundAddress)" | ||
| ]; | ||
|
|
||
| const iface = new ethers.Interface(abi); | ||
|
|
||
| console.log(`about to generate depositMessage Data`); | ||
|
|
||
| const depositMessage = iface.encodeFunctionData( | ||
| "finaliseETHDeposit", | ||
| [depositorAddress, depositAmount, l2DepositRecipient, l2FeeRefundAddress] | ||
| ); | ||
|
|
||
| console.log(depositMessage); | ||
|
|
||
| return depositMessage; | ||
| } | ||
|
|
||
|
|
||
| // const depositorAddressValue = "0xc8d5559BA22d11B0845215a781ff4bF3CCa0EF89"; | ||
| // const depositAmountValue = "1000000000000"; | ||
| // const l2DepositRecipientValue = "0x0001D3A5b915Bc99542a9430423cDe75Bd7F7aC7"; | ||
| // const l2FeeRefundAddressValue = "0x000131b12EBeb7A34e1a47d402137df6De7b08Ae"; | ||
|
|
||
| // generateL2RelayMessage(depositorAddressValue, depositAmountValue, l2DepositRecipientValue, l2FeeRefundAddressValue); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does
PRIVATE_KEYenvironment variable used by any another scripts?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@akokoshn this is used in the function to create a new smart-account
we are in midst of getting rid of this variable and create new key-pair for unit tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will be removed in the new PR coming up soon this week @akokoshn