@@ -42,10 +42,10 @@ const getCumulativeGasUsed = async (tx) => {
42
42
43
43
if ( tx . deployTransaction ) {
44
44
receipt = await tx . deployTransaction . wait ( ) ;
45
- cumulativeGasUsed = receipt . cumulativeGasUsed . toNumber ( ) ;
45
+ cumulativeGasUsed = Number ( receipt . cumulativeGasUsed ) ;
46
46
} else {
47
47
receipt = await tx . wait ( ) ;
48
- cumulativeGasUsed = await receipt . cumulativeGasUsed . toNumber ( ) ;
48
+ cumulativeGasUsed = Number ( receipt . cumulativeGasUsed ) ;
49
49
}
50
50
51
51
return cumulativeGasUsed ;
@@ -61,12 +61,20 @@ describe("Gas Cost Benchmarks", () => {
61
61
} ) ;
62
62
} ;
63
63
64
- const benchmarkTransfer = async ( contractName , contractInstance , accounts ) => {
65
- const tx = await contractInstance . transferOwnership ( accounts [ 2 ] . address ) ;
66
- recordGasCost ( contractName , "transferOwnership " , await getCumulativeGasUsed ( tx ) ) ;
64
+ const benchmarkGrantRole = async ( contractName , contractInstance , accounts ) => {
65
+ const tx = await contractInstance . grantRole ( ethers . ZeroHash , accounts [ 2 ] . address ) ;
66
+ recordGasCost ( contractName , "grantRole " , await getCumulativeGasUsed ( tx ) ) ;
67
67
68
- // Revert the owner by transferring back
69
- await contractInstance . connect ( accounts [ 2 ] ) . transferOwnership ( accounts [ 0 ] . address ) ;
68
+ // Revert the change by revoking role
69
+ await contractInstance . connect ( accounts [ 0 ] ) . revokeRole ( ethers . ZeroHash , accounts [ 2 ] . address ) ;
70
+ } ;
71
+
72
+ const benchmarkRevokeRole = async ( contractName , contractInstance , accounts ) => {
73
+ // Setup by granting role
74
+ await contractInstance . connect ( accounts [ 0 ] ) . grantRole ( ethers . ZeroHash , accounts [ 2 ] . address ) ;
75
+
76
+ const tx = await contractInstance . revokeRole ( ethers . ZeroHash , accounts [ 2 ] . address ) ;
77
+ recordGasCost ( contractName , "revokeRole" , await getCumulativeGasUsed ( tx ) ) ;
70
78
} ;
71
79
72
80
const benchmarkIssue = async ( contractName , contractInstance ) => {
@@ -152,7 +160,7 @@ describe("Gas Cost Benchmarks", () => {
152
160
it ( "runs benchmark" , async ( ) => {
153
161
// Deploy & initialize document store contract
154
162
const documentStoreInstance = await DocumentStore . deploy ( contractName , Accounts [ 0 ] . address ) ;
155
- const tx = await documentStoreInstance . deployed ( ) ;
163
+ const tx = await documentStoreInstance . deploymentTransaction ( ) ;
156
164
recordGasCost ( contractName , "deployment" , await getCumulativeGasUsed ( tx ) ) ;
157
165
158
166
// const documentStoreInstance = await UpgradableDocumentStore.deploy();
@@ -163,7 +171,8 @@ describe("Gas Cost Benchmarks", () => {
163
171
// (await getCumulativeGasUsed(documentStoreInstance)) + (await getCumulativeGasUsed(initializeTx))
164
172
// );
165
173
166
- await benchmarkTransfer ( contractName , documentStoreInstance , Accounts ) ;
174
+ await benchmarkGrantRole ( contractName , documentStoreInstance , Accounts ) ;
175
+ await benchmarkRevokeRole ( contractName , documentStoreInstance , Accounts ) ;
167
176
await benchmarkIssue ( contractName , documentStoreInstance ) ;
168
177
await benchmarkBulkIssue ( contractName , documentStoreInstance ) ;
169
178
await benchmarkRevoke ( contractName , documentStoreInstance ) ;
@@ -174,7 +183,7 @@ describe("Gas Cost Benchmarks", () => {
174
183
describe ( "DocumentStoreCreator" , ( ) => {
175
184
it ( "runs benchmark" , async ( ) => {
176
185
const documentStoreCreatorInstance = await DocumentStoreCreator . deploy ( ) ;
177
- const tx = await documentStoreCreatorInstance . deployed ( ) ;
186
+ const tx = await documentStoreCreatorInstance . deploymentTransaction ( ) ;
178
187
recordGasCost ( "DocumentStoreCreator" , "deployment" , await getCumulativeGasUsed ( tx ) ) ;
179
188
} ) ;
180
189
} ) ;
0 commit comments