did:cow, a proposal for an ID resolution method with most of the convenience of did:plc/did:web and the robustness of a public blockchain
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

use normal forge tooling for gas estimation

+16 -37
+15
.gas-snapshot
··· 1 + CowRegistryUpdateTest:test_updateController_plc1() (gas: 76855) 2 + CowRegistryUpdateTest:test_updateController_plc2() (gas: 76898) 3 + CowRegistryUpdateTest:test_updateController_rejectsNonController() (gas: 71387) 4 + CowRegistryUpdateTest:test_updateController_web_long() (gas: 126007) 5 + CowRegistryUpdateTest:test_updateController_web_medium() (gas: 76874) 6 + CowRegistryUpdateTest:test_updateController_web_short() (gas: 76836) 7 + CowRegistryUpdateTest:test_updateController_web_verylong() (gas: 150809) 8 + CowRegistryUpdateTest:test_updateWrappedDID_plc1_to_plc2() (gas: 80575) 9 + CowRegistryUpdateTest:test_updateWrappedDID_plc2_to_plc1() (gas: 80530) 10 + CowRegistryUpdateTest:test_updateWrappedDID_rejectsAfterDeactivation() (gas: 57084) 11 + CowRegistryUpdateTest:test_updateWrappedDID_rejectsNonController() (gas: 74148) 12 + CowRegistryUpdateTest:test_updateWrappedDID_web_long() (gas: 130099) 13 + CowRegistryUpdateTest:test_updateWrappedDID_web_medium() (gas: 80508) 14 + CowRegistryUpdateTest:test_updateWrappedDID_web_short() (gas: 80554) 15 + CowRegistryUpdateTest:test_updateWrappedDID_web_verylong() (gas: 155057)
+1 -37
test/CowRegistry.t.sol
··· 1 1 // SPDX-License-Identifier: MIT 2 - pragma solidity ^0.8.0; 2 + pragma solidity 0.8.28; 3 3 4 4 import "forge-std/Test.sol"; 5 5 import "../src/CowRegistry.sol"; ··· 37 37 bytes32 cowHash = _init(controller1, plcDID1); 38 38 39 39 vm.prank(controller1); 40 - uint256 gasBefore = gasleft(); 41 40 registry.updateWrappedDIDByHash(cowHash, plcDID2); 42 - uint256 gasUsed = gasBefore - gasleft(); 43 41 44 42 (, string memory did) = registry.cows(cowHash); 45 43 assertEq(did, plcDID2); 46 - emit log_named_uint("gas updateWrappedDID plc1->plc2", gasUsed); 47 44 } 48 45 49 46 function test_updateWrappedDID_plc2_to_plc1() public { 50 47 bytes32 cowHash = _init(controller2, plcDID2); 51 48 52 49 vm.prank(controller2); 53 - uint256 gasBefore = gasleft(); 54 50 registry.updateWrappedDIDByHash(cowHash, plcDID1); 55 - uint256 gasUsed = gasBefore - gasleft(); 56 51 57 52 (, string memory did) = registry.cows(cowHash); 58 53 assertEq(did, plcDID1); 59 - emit log_named_uint("gas updateWrappedDID plc2->plc1", gasUsed); 60 54 } 61 55 62 56 // ------------------------------------------------------------------------- ··· 67 61 bytes32 cowHash = _init(controller1, plcDID1); 68 62 69 63 vm.prank(controller1); 70 - uint256 gasBefore = gasleft(); 71 64 registry.updateWrappedDIDByHash(cowHash, webDIDShort); 72 - uint256 gasUsed = gasBefore - gasleft(); 73 65 74 66 (, string memory did) = registry.cows(cowHash); 75 67 assertEq(did, webDIDShort); 76 - emit log_named_uint("gas updateWrappedDID web short (12 chars)", gasUsed); 77 68 } 78 69 79 70 function test_updateWrappedDID_web_medium() public { 80 71 bytes32 cowHash = _init(controller1, plcDID1); 81 72 82 73 vm.prank(controller1); 83 - uint256 gasBefore = gasleft(); 84 74 registry.updateWrappedDIDByHash(cowHash, webDIDMedium); 85 - uint256 gasUsed = gasBefore - gasleft(); 86 75 87 76 (, string memory did) = registry.cows(cowHash); 88 77 assertEq(did, webDIDMedium); 89 - emit log_named_uint("gas updateWrappedDID web medium (19 chars)", gasUsed); 90 78 } 91 79 92 80 function test_updateWrappedDID_web_long() public { 93 81 bytes32 cowHash = _init(controller1, plcDID1); 94 82 95 83 vm.prank(controller1); 96 - uint256 gasBefore = gasleft(); 97 84 registry.updateWrappedDIDByHash(cowHash, webDIDLong); 98 - uint256 gasUsed = gasBefore - gasleft(); 99 85 100 86 (, string memory did) = registry.cows(cowHash); 101 87 assertEq(did, webDIDLong); 102 - emit log_named_uint("gas updateWrappedDID web long (50 chars)", gasUsed); 103 88 } 104 89 105 90 function test_updateWrappedDID_web_verylong() public { 106 91 bytes32 cowHash = _init(controller1, plcDID1); 107 92 108 93 vm.prank(controller1); 109 - uint256 gasBefore = gasleft(); 110 94 registry.updateWrappedDIDByHash(cowHash, webDIDVeryLong); 111 - uint256 gasUsed = gasBefore - gasleft(); 112 95 113 96 (, string memory did) = registry.cows(cowHash); 114 97 assertEq(did, webDIDVeryLong); 115 - emit log_named_uint("gas updateWrappedDID web very long (79 chars)", gasUsed); 116 98 } 117 99 118 100 // ------------------------------------------------------------------------- ··· 123 105 bytes32 cowHash = _init(controller1, plcDID1); 124 106 125 107 vm.prank(controller1); 126 - uint256 gasBefore = gasleft(); 127 108 registry.updateControllerByHash(cowHash, controller2); 128 - uint256 gasUsed = gasBefore - gasleft(); 129 109 130 110 (address ctrl, ) = registry.cows(cowHash); 131 111 assertEq(ctrl, controller2); 132 - emit log_named_uint("gas updateController plc1 ctrl1->ctrl2", gasUsed); 133 112 } 134 113 135 114 function test_updateController_plc2() public { 136 115 bytes32 cowHash = _init(controller2, plcDID2); 137 116 138 117 vm.prank(controller2); 139 - uint256 gasBefore = gasleft(); 140 118 registry.updateControllerByHash(cowHash, controller1); 141 - uint256 gasUsed = gasBefore - gasleft(); 142 119 143 120 (address ctrl, ) = registry.cows(cowHash); 144 121 assertEq(ctrl, controller1); 145 - emit log_named_uint("gas updateController plc2 ctrl2->ctrl1", gasUsed); 146 122 } 147 123 148 124 // ------------------------------------------------------------------------- ··· 153 129 bytes32 cowHash = _init(controller1, webDIDShort); 154 130 155 131 vm.prank(controller1); 156 - uint256 gasBefore = gasleft(); 157 132 registry.updateControllerByHash(cowHash, controller2); 158 - uint256 gasUsed = gasBefore - gasleft(); 159 133 160 134 (address ctrl, ) = registry.cows(cowHash); 161 135 assertEq(ctrl, controller2); 162 - emit log_named_uint("gas updateController web short (12 chars)", gasUsed); 163 136 } 164 137 165 138 function test_updateController_web_medium() public { 166 139 bytes32 cowHash = _init(controller1, webDIDMedium); 167 140 168 141 vm.prank(controller1); 169 - uint256 gasBefore = gasleft(); 170 142 registry.updateControllerByHash(cowHash, controller2); 171 - uint256 gasUsed = gasBefore - gasleft(); 172 143 173 144 (address ctrl, ) = registry.cows(cowHash); 174 145 assertEq(ctrl, controller2); 175 - emit log_named_uint("gas updateController web medium (19 chars)", gasUsed); 176 146 } 177 147 178 148 function test_updateController_web_long() public { 179 149 bytes32 cowHash = _init(controller1, webDIDLong); 180 150 181 151 vm.prank(controller1); 182 - uint256 gasBefore = gasleft(); 183 152 registry.updateControllerByHash(cowHash, controller2); 184 - uint256 gasUsed = gasBefore - gasleft(); 185 153 186 154 (address ctrl, ) = registry.cows(cowHash); 187 155 assertEq(ctrl, controller2); 188 - emit log_named_uint("gas updateController web long (50 chars)", gasUsed); 189 156 } 190 157 191 158 function test_updateController_web_verylong() public { 192 159 bytes32 cowHash = _init(controller1, webDIDVeryLong); 193 160 194 161 vm.prank(controller1); 195 - uint256 gasBefore = gasleft(); 196 162 registry.updateControllerByHash(cowHash, controller2); 197 - uint256 gasUsed = gasBefore - gasleft(); 198 163 199 164 (address ctrl, ) = registry.cows(cowHash); 200 165 assertEq(ctrl, controller2); 201 - emit log_named_uint("gas updateController web very long (79 chars)", gasUsed); 202 166 } 203 167 204 168 // -------------------------------------------------------------------------