From 8ec455cddfd27f31cdab16ae9d2e96d791bea995 Mon Sep 17 00:00:00 2001 From: Shubham Yadav Date: Sun, 30 Jul 2023 21:29:09 +0100 Subject: [PATCH 1/2] Using Given, When, Then keywords on the branching trees (cherry picked from commit d365705bfdbda3334409bc5b5a2b1821e22aac32) --- .../protocol-fees/protocolFees.tree | 4 +-- .../set-protocol-fee/setProtocolFee.t.sol | 6 ++--- .../set-protocol-fee/setProtocolFee.tree | 14 +++++----- .../toggle-flash-asset/toggleFlashAsset.t.sol | 6 ++--- .../toggle-flash-asset/toggleFlashAsset.tree | 14 +++++----- .../transfer-admin/transferAdmin.t.sol | 8 +++--- .../transfer-admin/transferAdmin.tree | 26 +++++++++---------- .../comptroller/flash-fee/flashFee.tree | 4 +-- .../set-flash-fee/setFlashFee.t.sol | 6 ++--- .../set-flash-fee/setFlashFee.tree | 14 +++++----- 10 files changed, 51 insertions(+), 51 deletions(-) diff --git a/test/integration/concrete/comptroller/protocol-fees/protocolFees.tree b/test/integration/concrete/comptroller/protocol-fees/protocolFees.tree index 1d2e6949b..2f0c6c186 100644 --- a/test/integration/concrete/comptroller/protocol-fees/protocolFees.tree +++ b/test/integration/concrete/comptroller/protocol-fees/protocolFees.tree @@ -1,5 +1,5 @@ protocolFees.t.sol ├── when the protocol fee has not been set -│ └── it should return zero +│ └── then should return zero └── when the protocol fee has been set - └── it should return the correct protocol fee + └── then should return the correct protocol fee diff --git a/test/integration/concrete/comptroller/set-protocol-fee/setProtocolFee.t.sol b/test/integration/concrete/comptroller/set-protocol-fee/setProtocolFee.t.sol index fd65bc4ee..0ebbdb583 100644 --- a/test/integration/concrete/comptroller/set-protocol-fee/setProtocolFee.t.sol +++ b/test/integration/concrete/comptroller/set-protocol-fee/setProtocolFee.t.sol @@ -18,11 +18,11 @@ contract SetProtocolFee_Integration_Concrete_Test is Integration_Test { } /// @dev The Admin is the default caller in the comptroller tests. - modifier whenCallerAdmin() { + modifier givenCallerAdmin() { _; } - function test_SetProtocolFee_SameFee() external whenCallerAdmin { + function test_SetProtocolFee_SameFee() external givenCallerAdmin { // Expect the relevant event to be emitted. vm.expectEmit({ emitter: address(comptroller) }); emit SetProtocolFee({ admin: users.admin, asset: dai, oldProtocolFee: ZERO, newProtocolFee: ZERO }); @@ -40,7 +40,7 @@ contract SetProtocolFee_Integration_Concrete_Test is Integration_Test { _; } - function test_SetProtocolFee() external whenCallerAdmin whenNewFee { + function test_SetProtocolFee() external givenCallerAdmin whenNewFee { UD60x18 newProtocolFee = defaults.FLASH_FEE(); // Expect the relevant event to be emitted. diff --git a/test/integration/concrete/comptroller/set-protocol-fee/setProtocolFee.tree b/test/integration/concrete/comptroller/set-protocol-fee/setProtocolFee.tree index 7bd610ee8..d62c0e71f 100644 --- a/test/integration/concrete/comptroller/set-protocol-fee/setProtocolFee.tree +++ b/test/integration/concrete/comptroller/set-protocol-fee/setProtocolFee.tree @@ -1,11 +1,11 @@ setProtocolFee.t.sol -├── when the caller is not the admin -│ └── it should revert -└── when the caller is the admin +├── given the caller is not the admin +│ └── then should revert +└── given the caller is the admin ├── when the new protocol fee is the same as the current protocol fee - │ ├── it should re-set the protocol fee - │ └── it should emit a {SetProtocolFee} event + │ ├── then should re-set the protocol fee + │ └── and should emit a {SetProtocolFee} event └── when the new protocol fee is not the same as the current protocol fee - ├── it should set the new protocol fee - └── it should emit a {SetProtocolFee} event + ├── then should set the new protocol fee + └── and should emit a {SetProtocolFee} event diff --git a/test/integration/concrete/comptroller/toggle-flash-asset/toggleFlashAsset.t.sol b/test/integration/concrete/comptroller/toggle-flash-asset/toggleFlashAsset.t.sol index ca023d248..9e8a0fba9 100644 --- a/test/integration/concrete/comptroller/toggle-flash-asset/toggleFlashAsset.t.sol +++ b/test/integration/concrete/comptroller/toggle-flash-asset/toggleFlashAsset.t.sol @@ -16,11 +16,11 @@ contract ToggleFlashAsset_Integration_Concrete_Test is Integration_Test { } /// @dev The admin is the default caller in the comptroller tests. - modifier whenCallerAdmin() { + modifier givenCallerAdmin() { _; } - function test_ToggleFlashAsset_FlagNotEnabled() external whenCallerAdmin { + function test_ToggleFlashAsset_FlagNotEnabled() external givenCallerAdmin { // Expect the relevant event to be emitted. vm.expectEmit({ emitter: address(comptroller) }); emit ToggleFlashAsset({ admin: users.admin, asset: dai, newFlag: true }); @@ -38,7 +38,7 @@ contract ToggleFlashAsset_Integration_Concrete_Test is Integration_Test { _; } - function test_ToggleFlashAsset() external whenCallerAdmin whenFlagEnabled { + function test_ToggleFlashAsset() external givenCallerAdmin whenFlagEnabled { // Expect the relevant event to be emitted. vm.expectEmit({ emitter: address(comptroller) }); emit ToggleFlashAsset({ admin: users.admin, asset: dai, newFlag: false }); diff --git a/test/integration/concrete/comptroller/toggle-flash-asset/toggleFlashAsset.tree b/test/integration/concrete/comptroller/toggle-flash-asset/toggleFlashAsset.tree index 7b81e86cb..756a74f3a 100644 --- a/test/integration/concrete/comptroller/toggle-flash-asset/toggleFlashAsset.tree +++ b/test/integration/concrete/comptroller/toggle-flash-asset/toggleFlashAsset.tree @@ -1,10 +1,10 @@ toggleFlashAsset.t.sol -├── when the caller is not the admin -│ └── it should revert -└── when the caller is the admin +├── given the caller is not the admin +│ └── then should revert +└── given the caller is the admin ├── when the flag is not enabled - │ ├── it should toggle the flash asset - │ └── it should emit a {ToggleFlashAsset} event + │ ├── then should toggle the flash asset + │ └── and should emit a {ToggleFlashAsset} event └── when the flag is enabled - ├── it should toggle the flash asset - └── it should emit a {ToggleFlashAsset} event + ├── then should toggle the flash asset + └── and should emit a {ToggleFlashAsset} event diff --git a/test/unit/concrete/adminable/transfer-admin/transferAdmin.t.sol b/test/unit/concrete/adminable/transfer-admin/transferAdmin.t.sol index 16bb5e4de..8c23afcef 100644 --- a/test/unit/concrete/adminable/transfer-admin/transferAdmin.t.sol +++ b/test/unit/concrete/adminable/transfer-admin/transferAdmin.t.sol @@ -15,11 +15,11 @@ contract TransferAdmin_Unit_Concrete_Test is Adminable_Unit_Shared_Test { adminableMock.transferAdmin(users.eve); } - modifier whenCallerAdmin() { + modifier givenCallerAdmin() { _; } - function test_TransferAdmin_SameAdmin() external whenCallerAdmin { + function test_TransferAdmin_SameAdmin() external givenCallerAdmin { // Expect the relevant event to be emitted. vm.expectEmit({ emitter: address(adminableMock) }); emit TransferAdmin({ oldAdmin: users.admin, newAdmin: users.admin }); @@ -33,7 +33,7 @@ contract TransferAdmin_Unit_Concrete_Test is Adminable_Unit_Shared_Test { assertEq(actualAdmin, expectedAdmin, "admin"); } - function test_TransferAdmin_ZeroAddress() external whenCallerAdmin { + function test_TransferAdmin_ZeroAddress() external givenCallerAdmin { // Expect the relevant event to be emitted. vm.expectEmit({ emitter: address(adminableMock) }); emit TransferAdmin({ oldAdmin: users.admin, newAdmin: address(0) }); @@ -51,7 +51,7 @@ contract TransferAdmin_Unit_Concrete_Test is Adminable_Unit_Shared_Test { _; } - function test_TransferAdmin_NewAdmin() external whenCallerAdmin whenNotZeroAddress { + function test_TransferAdmin_NewAdmin() external givenCallerAdmin whenNotZeroAddress { // Expect the relevant event to be emitted. vm.expectEmit({ emitter: address(adminableMock) }); emit TransferAdmin({ oldAdmin: users.admin, newAdmin: users.alice }); diff --git a/test/unit/concrete/adminable/transfer-admin/transferAdmin.tree b/test/unit/concrete/adminable/transfer-admin/transferAdmin.tree index 2947f6ba7..4ae70d4b2 100644 --- a/test/unit/concrete/adminable/transfer-admin/transferAdmin.tree +++ b/test/unit/concrete/adminable/transfer-admin/transferAdmin.tree @@ -1,14 +1,14 @@ transferAdmin.t.sol -├── when the caller is not the admin -│ └── it should revert -└── when the caller is the admin - ├── when the admin is the same as the current admin - │ ├── it should re-set the admin - │ └── it should emit a {TransferAdmin} event - └── when the admin is not the same as the current admin - ├── when the admin is the zero address - │ ├── it should set the admin to the zero address - │ └── it should emit a {TransferAdmin} - └── when the admin is not the zero address - ├── it should set the new admin - └── it should emit a {TransferAdmin} event and set the new admin +├── given the caller is not the admin +│ └── then should revert +└── given the caller is the admin + ├── when new admin is same as current admin + │ ├── then should re-set the admin + │ └── and should emit a {TransferAdmin} event + └── when new admin is not same as current admin + ├── when the new admin is the zero address + │ ├── then should set the admin to the zero address + │ └── and should emit a {TransferAdmin} + └── when the new admin is not the zero address + ├── then should set the new admin + └── and should emit a {TransferAdmin} event and set the new admin diff --git a/test/unit/concrete/comptroller/flash-fee/flashFee.tree b/test/unit/concrete/comptroller/flash-fee/flashFee.tree index 8d58642ea..f30a8b730 100644 --- a/test/unit/concrete/comptroller/flash-fee/flashFee.tree +++ b/test/unit/concrete/comptroller/flash-fee/flashFee.tree @@ -1,5 +1,5 @@ flashFee.t.sol ├── when the flash fee has not been set -│ └── it should return zero +│ └── then should return zero └── when the flash fee has been set - └── it should return the correct flash fee + └── then should return the correct flash fee diff --git a/test/unit/concrete/comptroller/set-flash-fee/setFlashFee.t.sol b/test/unit/concrete/comptroller/set-flash-fee/setFlashFee.t.sol index 028e04f0d..f86f3d169 100644 --- a/test/unit/concrete/comptroller/set-flash-fee/setFlashFee.t.sol +++ b/test/unit/concrete/comptroller/set-flash-fee/setFlashFee.t.sol @@ -24,11 +24,11 @@ contract SetFlashFee_Unit_Concrete_Test is Comptroller_Unit_Concrete_Test { } /// @dev The admin is the default caller in the comptroller tests. - modifier whenCallerAdmin() { + modifier givenCallerAdmin() { _; } - function test_SetFlashFee_SameFee() external whenCallerAdmin { + function test_SetFlashFee_SameFee() external givenCallerAdmin { // Expect the relevant event to be emitted. vm.expectEmit({ emitter: address(comptroller) }); emit SetFlashFee({ admin: users.admin, oldFlashFee: ZERO, newFlashFee: ZERO }); @@ -47,7 +47,7 @@ contract SetFlashFee_Unit_Concrete_Test is Comptroller_Unit_Concrete_Test { _; } - function test_SetFlashFee() external whenCallerAdmin whenNewFee { + function test_SetFlashFee() external givenCallerAdmin whenNewFee { UD60x18 newFlashFee = defaults.FLASH_FEE(); // Expect the relevant event to be emitted. diff --git a/test/unit/concrete/comptroller/set-flash-fee/setFlashFee.tree b/test/unit/concrete/comptroller/set-flash-fee/setFlashFee.tree index 9f97bbefd..36961bb15 100644 --- a/test/unit/concrete/comptroller/set-flash-fee/setFlashFee.tree +++ b/test/unit/concrete/comptroller/set-flash-fee/setFlashFee.tree @@ -1,10 +1,10 @@ setFlashFee.t.sol -├── when the caller is not the admin -│ └── it should revert -└── when the caller is the admin +├── given the caller is not the admin +│ └── then should revert +└── given the caller is the admin ├── when the new flash fee is the same as the current flash fee - │ ├── it should re-set the flash fee - │ └── it should emit a {SetFlashFee} event + │ ├── then should re-set the flash fee + │ └── and should emit a {SetFlashFee} event └── when the new flash fee is not the same as the current flash fee - ├── it should set the new flash fee - └── it should emit a {SetFlashFee} event + ├── then should set the new flash fee + └── and should emit a {SetFlashFee} event From ef22a65a20b4ffcab16b85796476518ed803afb3 Mon Sep 17 00:00:00 2001 From: Paul Razvan Berg Date: Mon, 31 Jul 2023 15:22:34 +0300 Subject: [PATCH 2/2] test: use "it" for test nodes --- .../comptroller/protocol-fees/protocolFees.tree | 4 ++-- .../set-protocol-fee/setProtocolFee.tree | 10 +++++----- .../toggle-flash-asset/toggleFlashAsset.tree | 10 +++++----- .../adminable/transfer-admin/transferAdmin.tree | 14 +++++++------- .../concrete/comptroller/flash-fee/flashFee.tree | 4 ++-- .../comptroller/set-flash-fee/setFlashFee.tree | 10 +++++----- 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/test/integration/concrete/comptroller/protocol-fees/protocolFees.tree b/test/integration/concrete/comptroller/protocol-fees/protocolFees.tree index 2f0c6c186..1d2e6949b 100644 --- a/test/integration/concrete/comptroller/protocol-fees/protocolFees.tree +++ b/test/integration/concrete/comptroller/protocol-fees/protocolFees.tree @@ -1,5 +1,5 @@ protocolFees.t.sol ├── when the protocol fee has not been set -│ └── then should return zero +│ └── it should return zero └── when the protocol fee has been set - └── then should return the correct protocol fee + └── it should return the correct protocol fee diff --git a/test/integration/concrete/comptroller/set-protocol-fee/setProtocolFee.tree b/test/integration/concrete/comptroller/set-protocol-fee/setProtocolFee.tree index d62c0e71f..0d13e7454 100644 --- a/test/integration/concrete/comptroller/set-protocol-fee/setProtocolFee.tree +++ b/test/integration/concrete/comptroller/set-protocol-fee/setProtocolFee.tree @@ -1,11 +1,11 @@ setProtocolFee.t.sol ├── given the caller is not the admin -│ └── then should revert +│ └── it should revert └── given the caller is the admin ├── when the new protocol fee is the same as the current protocol fee - │ ├── then should re-set the protocol fee - │ └── and should emit a {SetProtocolFee} event + │ ├── it should re-set the protocol fee + │ └── it should emit a {SetProtocolFee} event └── when the new protocol fee is not the same as the current protocol fee - ├── then should set the new protocol fee - └── and should emit a {SetProtocolFee} event + ├── it should set the new protocol fee + └── it should emit a {SetProtocolFee} event diff --git a/test/integration/concrete/comptroller/toggle-flash-asset/toggleFlashAsset.tree b/test/integration/concrete/comptroller/toggle-flash-asset/toggleFlashAsset.tree index 756a74f3a..cf70df206 100644 --- a/test/integration/concrete/comptroller/toggle-flash-asset/toggleFlashAsset.tree +++ b/test/integration/concrete/comptroller/toggle-flash-asset/toggleFlashAsset.tree @@ -1,10 +1,10 @@ toggleFlashAsset.t.sol ├── given the caller is not the admin -│ └── then should revert +│ └── it should revert └── given the caller is the admin ├── when the flag is not enabled - │ ├── then should toggle the flash asset - │ └── and should emit a {ToggleFlashAsset} event + │ ├── it should toggle the flash asset + │ └── it should emit a {ToggleFlashAsset} event └── when the flag is enabled - ├── then should toggle the flash asset - └── and should emit a {ToggleFlashAsset} event + ├── it should toggle the flash asset + └── it should emit a {ToggleFlashAsset} event diff --git a/test/unit/concrete/adminable/transfer-admin/transferAdmin.tree b/test/unit/concrete/adminable/transfer-admin/transferAdmin.tree index 4ae70d4b2..3c0e4a406 100644 --- a/test/unit/concrete/adminable/transfer-admin/transferAdmin.tree +++ b/test/unit/concrete/adminable/transfer-admin/transferAdmin.tree @@ -1,14 +1,14 @@ transferAdmin.t.sol ├── given the caller is not the admin -│ └── then should revert +│ └── it should revert └── given the caller is the admin ├── when new admin is same as current admin - │ ├── then should re-set the admin - │ └── and should emit a {TransferAdmin} event + │ ├── it should re-set the admin + │ └── it should emit a {TransferAdmin} event └── when new admin is not same as current admin ├── when the new admin is the zero address - │ ├── then should set the admin to the zero address - │ └── and should emit a {TransferAdmin} + │ ├── it should set the admin to the zero address + │ └── it should emit a {TransferAdmin} └── when the new admin is not the zero address - ├── then should set the new admin - └── and should emit a {TransferAdmin} event and set the new admin + ├── it should set the new admin + └── it should emit a {TransferAdmin} event and set the new admin diff --git a/test/unit/concrete/comptroller/flash-fee/flashFee.tree b/test/unit/concrete/comptroller/flash-fee/flashFee.tree index f30a8b730..8d58642ea 100644 --- a/test/unit/concrete/comptroller/flash-fee/flashFee.tree +++ b/test/unit/concrete/comptroller/flash-fee/flashFee.tree @@ -1,5 +1,5 @@ flashFee.t.sol ├── when the flash fee has not been set -│ └── then should return zero +│ └── it should return zero └── when the flash fee has been set - └── then should return the correct flash fee + └── it should return the correct flash fee diff --git a/test/unit/concrete/comptroller/set-flash-fee/setFlashFee.tree b/test/unit/concrete/comptroller/set-flash-fee/setFlashFee.tree index 36961bb15..6f4c00c60 100644 --- a/test/unit/concrete/comptroller/set-flash-fee/setFlashFee.tree +++ b/test/unit/concrete/comptroller/set-flash-fee/setFlashFee.tree @@ -1,10 +1,10 @@ setFlashFee.t.sol ├── given the caller is not the admin -│ └── then should revert +│ └── it should revert └── given the caller is the admin ├── when the new flash fee is the same as the current flash fee - │ ├── then should re-set the flash fee - │ └── and should emit a {SetFlashFee} event + │ ├── it should re-set the flash fee + │ └── it should emit a {SetFlashFee} event └── when the new flash fee is not the same as the current flash fee - ├── then should set the new flash fee - └── and should emit a {SetFlashFee} event + ├── it should set the new flash fee + └── it should emit a {SetFlashFee} event