From f0417a7cfed2c814593e6af33cd93b756fc1bd18 Mon Sep 17 00:00:00 2001 From: Yash <72552910+kumaryash90@users.noreply.github.com> Date: Wed, 13 Sep 2023 06:05:12 +0530 Subject: [PATCH] Update benchmark tests (#19) --- gasreport.txt | 28 +++++++------- test/BaseRouterBenchmark.t.sol | 70 +++++++++++----------------------- 2 files changed, 36 insertions(+), 62 deletions(-) diff --git a/gasreport.txt b/gasreport.txt index 74a50f0..e961501 100644 --- a/gasreport.txt +++ b/gasreport.txt @@ -1,20 +1,20 @@ No files changed, compilation skipped Running 13 tests for test/BaseRouterBenchmark.t.sol:BaseRouterBenchmarkTest -[PASS] test_scenario_upgradeBuggyFunction() (gas: 394192) -[PASS] test_scenario_upgradeBuggyFunction_defaultExtension() (gas: 231369) -[PASS] test_state_addExtension() (gas: 510765) -[PASS] test_state_addExtension_tenExtensionsWithFiveFunctionsEach() (gas: 510766) -[PASS] test_state_disableFunctionInExtension() (gas: 14273) -[PASS] test_state_disableFunctionInExtension_defaultExtension() (gas: 52944) -[PASS] test_state_enableFunctionInExtension() (gas: 129843) -[PASS] test_state_enableFunctionInExtension_defaultExtension() (gas: 18840) -[PASS] test_state_initialize_oneExtensionOneFunction() (gas: 5890282) -[PASS] test_state_removeExtension() (gas: 297476) -[PASS] test_state_removeExtension_defautlExtension() (gas: 98129) -[PASS] test_state_replaceExtension() (gas: 297457) -[PASS] test_state_replaceExtension_defaultExtension() (gas: 266401) -Test result: ok. 13 passed; 0 failed; 0 skipped; finished in 3.04ms +[PASS] test_benchmark_addExtension() (gas: 510743) +[PASS] test_benchmark_deployBaseRouter() (gas: 4535467) +[PASS] test_benchmark_disableFunctionInExtension() (gas: 14256) +[PASS] test_benchmark_disableFunctionInExtension_defaultExtension() (gas: 52944) +[PASS] test_benchmark_enableFunctionInExtension() (gas: 129844) +[PASS] test_benchmark_enableFunctionInExtension_defaultExtension() (gas: 18857) +[PASS] test_benchmark_initializeBaseRouter() (gas: 5900007) +[PASS] test_benchmark_removeExtension() (gas: 297440) +[PASS] test_benchmark_removeExtension_defautlExtension() (gas: 98146) +[PASS] test_benchmark_replaceExtension() (gas: 297424) +[PASS] test_benchmark_replaceExtension_defaultExtension() (gas: 266334) +[PASS] test_benchmark_upgradeBuggyFunction() (gas: 394171) +[PASS] test_benchmark_upgradeBuggyFunction_defaultExtension() (gas: 231386) +Test result: ok. 13 passed; 0 failed; 0 skipped; finished in 3.38ms Ran 1 test suites: 13 tests passed, 0 failed, 0 skipped (13 total tests) diff --git a/test/BaseRouterBenchmark.t.sol b/test/BaseRouterBenchmark.t.sol index 5a60405..b5cfd71 100644 --- a/test/BaseRouterBenchmark.t.sol +++ b/test/BaseRouterBenchmark.t.sol @@ -90,14 +90,20 @@ contract BaseRouterBenchmarkTest is Test, IExtension { } /*/////////////////////////////////////////////////////////////// - Initialze BaseRouter + Deploy / Initialze BaseRouter //////////////////////////////////////////////////////////////*/ - function test_state_initialize_oneExtensionOneFunction() external { + function test_benchmark_deployBaseRouter() external { + Extension[] memory defaultExtensionsNew = new Extension[](1); + defaultExtensionsNew[0] = defaultExtension3; + CustomRouter routerNew = new CustomRouter(defaultExtensionsNew); + } + + function test_benchmark_initializeBaseRouter() external { // vm.pauseGasMetering(); - Extension[] memory defaultExtensions = new Extension[](1); - defaultExtensions[0] = defaultExtension3; - CustomRouter routerNew = new CustomRouter(defaultExtensions); + Extension[] memory defaultExtensionsNew = new Extension[](1); + defaultExtensionsNew[0] = defaultExtension3; + CustomRouter routerNew = new CustomRouter(defaultExtensionsNew); // vm.resumeGasMetering(); uint256 gasBefore = gasleft(); @@ -112,39 +118,7 @@ contract BaseRouterBenchmarkTest is Test, IExtension { //////////////////////////////////////////////////////////////*/ /// @notice Add an new extension. - function test_state_addExtension() public { - vm.pauseGasMetering(); - // Create Extension struct - Extension memory extension; - - // Set metadata - extension.metadata.name = "IncrementDecrement"; - extension.metadata.metadataURI = "ipfs://IncrementDecrement"; - extension.metadata.implementation = address(new IncrementDecrementGet()); - - // Set functions - extension.functions = new ExtensionFunction[](3); - - extension.functions[0] = ExtensionFunction( - IncrementDecrementGet.incrementNumber.selector, - "incrementNumber()" - ); - extension.functions[1] = ExtensionFunction( - IncrementDecrementGet.decrementNumber.selector, - "decrementNumber()" - ); - extension.functions[2] = ExtensionFunction( - IncrementDecrementGet.getNumber.selector, - "getNumber()" - ); - vm.resumeGasMetering(); - - // Call: addExtension - router.addExtension(extension); - } - - /// @notice Add an new extension. - function test_state_addExtension_tenExtensionsWithFiveFunctionsEach() public { + function test_benchmark_addExtension() public { vm.pauseGasMetering(); // Create Extension struct Extension memory extension; @@ -180,7 +154,7 @@ contract BaseRouterBenchmarkTest is Test, IExtension { //////////////////////////////////////////////////////////////*/ /// @notice Replace a default extension with a new one. - function test_state_replaceExtension_defaultExtension() public { + function test_benchmark_replaceExtension_defaultExtension() public { vm.pauseGasMetering(); // Create Extension struct to replace existing extension Extension memory updatedExtension; @@ -207,7 +181,7 @@ contract BaseRouterBenchmarkTest is Test, IExtension { /// @notice Replace a non-default extension with a new one. - function test_state_replaceExtension() public { + function test_benchmark_replaceExtension() public { vm.pauseGasMetering(); // Create Extension struct Extension memory extension; @@ -255,14 +229,14 @@ contract BaseRouterBenchmarkTest is Test, IExtension { //////////////////////////////////////////////////////////////*/ /// @notice Remove a default extension. - function test_state_removeExtension_defautlExtension() public { + function test_benchmark_removeExtension_defautlExtension() public { // Call: removeExtension router.removeExtension(defaultExtension1.metadata.name); } /// @notice Remove a non-default extension. - function test_state_removeExtension() public { + function test_benchmark_removeExtension() public { vm.pauseGasMetering(); // Create Extension struct Extension memory extension; @@ -310,13 +284,13 @@ contract BaseRouterBenchmarkTest is Test, IExtension { //////////////////////////////////////////////////////////////*/ /// @notice Disable a function in a default extension. - function test_state_disableFunctionInExtension_defaultExtension() public { + function test_benchmark_disableFunctionInExtension_defaultExtension() public { // Call: disableFunctionInExtension router.disableFunctionInExtension(defaultExtension1.metadata.name, defaultExtension1.functions[0].functionSelector); } /// @notice Disable a function in a non-default extension. - function test_state_disableFunctionInExtension() public { + function test_benchmark_disableFunctionInExtension() public { vm.pauseGasMetering(); // Create Extension struct Extension memory extension; @@ -351,7 +325,7 @@ contract BaseRouterBenchmarkTest is Test, IExtension { //////////////////////////////////////////////////////////////*/ /// @notice Enable a function in a default extension. - function test_state_enableFunctionInExtension_defaultExtension() public { + function test_benchmark_enableFunctionInExtension_defaultExtension() public { vm.pauseGasMetering(); // Call: disableFunctionInExtension router.disableFunctionInExtension(defaultExtension1.metadata.name, defaultExtension1.functions[0].functionSelector); @@ -362,7 +336,7 @@ contract BaseRouterBenchmarkTest is Test, IExtension { } /// @notice Enable a function in a non-default extension. - function test_state_enableFunctionInExtension() public { + function test_benchmark_enableFunctionInExtension() public { vm.pauseGasMetering(); // Create Extension struct Extension memory extension; @@ -404,7 +378,7 @@ contract BaseRouterBenchmarkTest is Test, IExtension { /// The following tests are for scenarios that may occur in production use of a base router. /// @notice Upgrade a buggy function in a default extension. - function test_scenario_upgradeBuggyFunction_defaultExtension() public { + function test_benchmark_upgradeBuggyFunction_defaultExtension() public { vm.pauseGasMetering(); // Disable buggy function in extension router.disableFunctionInExtension(defaultExtension1.metadata.name, defaultExtension1.functions[0].functionSelector); @@ -430,7 +404,7 @@ contract BaseRouterBenchmarkTest is Test, IExtension { } /// @notice Upgrade a buggy function in a non-default extension. - function test_scenario_upgradeBuggyFunction() public { + function test_benchmark_upgradeBuggyFunction() public { vm.pauseGasMetering(); // Add extension with buggy function Extension memory extension;