Skip to content

Commit

Permalink
Update benchmark tests (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
kumaryash90 authored Sep 13, 2023
1 parent 425bd49 commit f0417a7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 62 deletions.
28 changes: 14 additions & 14 deletions gasreport.txt
Original file line number Diff line number Diff line change
@@ -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)
70 changes: 22 additions & 48 deletions test/BaseRouterBenchmark.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit f0417a7

Please sign in to comment.