From 20442d2f6e79d83c695a63bc61e66158a6e42140 Mon Sep 17 00:00:00 2001 From: Yberjon Date: Wed, 30 Oct 2024 12:54:39 +0100 Subject: [PATCH 1/3] Initial tests --- .../tests/bootloader/bootloader_test.yul | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/system-contracts/bootloader/tests/bootloader/bootloader_test.yul b/system-contracts/bootloader/tests/bootloader/bootloader_test.yul index ed506fcea..d10bc6fda 100644 --- a/system-contracts/bootloader/tests/bootloader/bootloader_test.yul +++ b/system-contracts/bootloader/tests/bootloader/bootloader_test.yul @@ -109,3 +109,68 @@ function TEST_systemLogKeys() { testing_assertEq(numberOfLayer1TxsLogKey, 6, "Invalid num layer 1 txns log key") testing_assertEq(protocolUpgradeTxHashKey, 13, "Invalid protocol upgrade txn hash log key") } + +function TEST_setTxOrigin() { + let newTxOrigin := 0 + setTxOrigin(newTxOrigin) +} + +function TEST_setGasPrice() { + let newGasPrice := 10 + setGasPrice(newGasPrice) +} + +function TEST_setPubdataInfo() { + let txPtr := TX_DESCRIPTION_BEGIN_BYTE() + let txDataOffset := mload(add(txPtr, 32)) + let innerTxDataOffset := add(txDataOffset, 32) + let newGasPerPubdata := getGasPerPubdataByteLimit(innerTxDataOffset) + let basePubdataSpent := getPubdataCounter() + + setPubdataInfo(newGasPerPubdata, basePubdataSpent) +} + +function TEST_setNewBatch() { + let prevBatchHash := mload(32) + let newTimestamp := mload(64) + let newBatchNumber := mload(96) + let baseFee := 10 + + setNewBatch(prevBatchHash, newTimestamp, newBatchNumber, baseFee) + + assertEq(baseFee, basefee(), "Invalid base fee") +} + +function TEST_setL2Block() { + let txId := 0 + + setL2Block(txId) +} + +function TEST_setL2BlockRevert() { + let txId := 1 + + testing_testWillFailWith(25) + setL2Block(txId) +} + +function TEST_setContextVal() { + let selector := {{RIGHT_PADDED_SET_GAS_PRICE}} + let value := 10 + mstore(0, selector) + mstore(4, value) + + let expected := call( + gas(), + SYSTEM_CONTEXT_ADDR(), + 0, + 0, + 36, + 0, + 0 + ) + + let returnValue := setContextVal(selector, value) + + testing_assertEq(expected, returnValue, "Invalid context value") +} \ No newline at end of file From 0c7d00b505b5b11fb9c29db310d00ebfac818c73 Mon Sep 17 00:00:00 2001 From: Yberjon Date: Sat, 2 Nov 2024 11:29:42 +0100 Subject: [PATCH 2/3] Add asserts --- .../bootloader/tests/bootloader/bootloader_test.yul | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/system-contracts/bootloader/tests/bootloader/bootloader_test.yul b/system-contracts/bootloader/tests/bootloader/bootloader_test.yul index d10bc6fda..d4546147d 100644 --- a/system-contracts/bootloader/tests/bootloader/bootloader_test.yul +++ b/system-contracts/bootloader/tests/bootloader/bootloader_test.yul @@ -113,11 +113,15 @@ function TEST_systemLogKeys() { function TEST_setTxOrigin() { let newTxOrigin := 0 setTxOrigin(newTxOrigin) + + testing_assertEq(newTxOrigin, mload(4), "Invalid Tx Origin") } function TEST_setGasPrice() { let newGasPrice := 10 setGasPrice(newGasPrice) + + testing_assertEq(newGasPrice, mload(4), "Invalid gas price") } function TEST_setPubdataInfo() { @@ -155,7 +159,7 @@ function TEST_setL2BlockRevert() { } function TEST_setContextVal() { - let selector := {{RIGHT_PADDED_SET_GAS_PRICE}} + let selector := RIGHT_PADDED_SET_GAS_PRICE_SELECTOR() let value := 10 mstore(0, selector) mstore(4, value) @@ -173,4 +177,4 @@ function TEST_setContextVal() { let returnValue := setContextVal(selector, value) testing_assertEq(expected, returnValue, "Invalid context value") -} \ No newline at end of file +} From 0ac094e813b06d6e1ffac984a74d7268345e3ccb Mon Sep 17 00:00:00 2001 From: Yberjon Date: Sun, 3 Nov 2024 18:37:49 +0100 Subject: [PATCH 3/3] Fix selector --- .../bootloader/tests/bootloader/bootloader_test.yul | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system-contracts/bootloader/tests/bootloader/bootloader_test.yul b/system-contracts/bootloader/tests/bootloader/bootloader_test.yul index d4546147d..022f20afe 100644 --- a/system-contracts/bootloader/tests/bootloader/bootloader_test.yul +++ b/system-contracts/bootloader/tests/bootloader/bootloader_test.yul @@ -159,7 +159,7 @@ function TEST_setL2BlockRevert() { } function TEST_setContextVal() { - let selector := RIGHT_PADDED_SET_GAS_PRICE_SELECTOR() + let selector := 0xbf1fe42000000000000000000000000000000000000000000000000000000000 let value := 10 mstore(0, selector) mstore(4, value)