Skip to content

Commit

Permalink
fix: minor typos
Browse files Browse the repository at this point in the history
  • Loading branch information
dbale-altoros committed Jan 15, 2025
1 parent 46c9196 commit 43d5045
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/rules/gas-consumption/gas-struct-packing.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ This rule accepts a string option of rule severity. Must be one of "error", "war

### Notes
- This rule assumes all UserDefinedTypeName take a new slot. (beware of Enums inside Structs)
- Simple cases like a struct with three addresses might be reported as false positive. (needs to be fixed)
- [source 1](https://coinsbench.com/comprehensive-guide-tips-and-tricks-for-gas-optimization-in-solidity-5380db734404) of the rule initiative (Variable Packing)
- [source 2](https://www.rareskills.io/post/gas-optimization?postId=c9db474a-ff97-4fa3-a51d-fe13ccb8fe3b#viewer-f8m1r) of the rule initiative

Expand Down
3 changes: 3 additions & 0 deletions lib/rules/gas-consumption/gas-struct-packing.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const meta = {
{
note: 'This rule assumes all UserDefinedTypeName take a new slot. (beware of Enums inside Structs) ',
},
{
note: 'Simple cases like a struct with three addresses might be reported as false positive. (needs to be fixed)',
},
{
note: '[source 1](https://coinsbench.com/comprehensive-guide-tips-and-tricks-for-gas-optimization-in-solidity-5380db734404) of the rule initiative (Variable Packing)',
},
Expand Down
3 changes: 2 additions & 1 deletion solhint.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,14 @@ function executeMainActionLogic() {

const customConfig = program.opts().config
if (customConfig && !fs.existsSync(customConfig)) {
console.error(`Config file "${customConfig}" couldnt be found.`)
console.error(`Config file "${customConfig}" couldn't be found.`)
process.exit(EXIT_CODES.BAD_OPTIONS)
}

let reports
try {
const reportLists = program.args.filter(_.isString).map(processPath)
// console.log('reportLists :>> ', reportLists)
reports = _.flatten(reportLists)
} catch (e) {
console.error(e)
Expand Down
24 changes: 23 additions & 1 deletion test/rules/gas-consumption/gas-struct-packing.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ const assert = require('assert')
const linter = require('../../../lib/index')
const TEST_CASES = require('../../fixtures/gas-consumption/gas-struct-packing-data')

// const { contractWith, multiLine } = require('../../common/contract-builder')

const replaceErrorMsg = (variableName) => {
const errMsg = `GC: For [ ${variableName} ] struct, packing seems inefficient. Try rearranging to achieve 32bytes slots`
return errMsg
}

describe('Linter - gas-struct-packingone', () => {
describe('Linter - gas-struct-packing', () => {
for (const contract of TEST_CASES.contractStructsInefficient) {
it(`should raise error for ${contract.name}`, () => {
const code = contract.code
Expand All @@ -30,4 +32,24 @@ describe('Linter - gas-struct-packingone', () => {
assert.equal(report.errorCount, 0)
})
}

// it(`should NOT raise error for `, () => {
// const code = contractWith(
// multiLine(
// // // Large Types Followed by Small Types
// 'struct MyStruct2 {',
// ' address addr1;',
// ' address addr2;',
// ' address addr3;',
// '}'
// )
// )
// const report = linter.processStr(code, {
// rules: { 'gas-struct-packing': 'error' },
// })

// console.log(report)

// // assert.equal(report.errorCount, 0)
// })
})

0 comments on commit 43d5045

Please sign in to comment.